diff options
author | Xiang, Haihao <haihao.xiang@intel.com> | 2011-05-10 12:49:54 +0800 |
---|---|---|
committer | Xiang, Haihao <haihao.xiang@intel.com> | 2011-05-10 14:17:20 +0800 |
commit | 87a90c604eafc960aa702b059d11949cf10e69ba (patch) | |
tree | f1129dbf21bd9df7468b002f1738ce6bc4723ce3 /i965_drv_video/i965_encoder.c | |
parent | f159aca32479e89c28291d6605b52e2e07daf923 (diff) |
i965_drv_video: create media_state per context
Also clean up some codes
Diffstat (limited to 'i965_drv_video/i965_encoder.c')
-rw-r--r-- | i965_drv_video/i965_encoder.c | 350 |
1 files changed, 22 insertions, 328 deletions
diff --git a/i965_drv_video/i965_encoder.c b/i965_drv_video/i965_encoder.c index cb21344..09cef6f 100644 --- a/i965_drv_video/i965_encoder.c +++ b/i965_drv_video/i965_encoder.c @@ -40,346 +40,40 @@ #include "i965_drv_video.h" #include "i965_encoder.h" -extern void i965_reference_buffer_store(struct buffer_store **ptr, - struct buffer_store *buffer_store); -extern void i965_release_buffer_store(struct buffer_store **ptr); - -static VAStatus i965_encoder_render_squence_parameter_buffer(VADriverContextP ctx, - struct object_context *obj_context, - struct object_buffer *obj_buffer) -{ - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); - i965_release_buffer_store(&obj_context->encode_state.seq_param); - i965_reference_buffer_store(&obj_context->encode_state.seq_param, - obj_buffer->buffer_store); - - return VA_STATUS_SUCCESS; -} - - -static VAStatus i965_encoder_render_picture_parameter_buffer(VADriverContextP ctx, - struct object_context *obj_context, - struct object_buffer *obj_buffer) -{ - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); - i965_release_buffer_store(&obj_context->encode_state.pic_param); - i965_reference_buffer_store(&obj_context->encode_state.pic_param, - obj_buffer->buffer_store); - - return VA_STATUS_SUCCESS; -} - -static VAStatus i965_encoder_render_slice_parameter_buffer(VADriverContextP ctx, - struct object_context *obj_context, - struct object_buffer *obj_buffer) -{ - if (obj_context->encode_state.num_slice_params == obj_context->encode_state.max_slice_params) { - obj_context->encode_state.slice_params = realloc(obj_context->encode_state.slice_params, - (obj_context->encode_state.max_slice_params + NUM_SLICES) * sizeof(*obj_context->encode_state.slice_params)); - memset(obj_context->encode_state.slice_params + obj_context->encode_state.max_slice_params, 0, NUM_SLICES * sizeof(*obj_context->encode_state.slice_params)); - obj_context->encode_state.max_slice_params += NUM_SLICES; - } - - i965_release_buffer_store(&obj_context->encode_state.slice_params[obj_context->encode_state.num_slice_params]); - i965_reference_buffer_store(&obj_context->encode_state.slice_params[obj_context->encode_state.num_slice_params], - obj_buffer->buffer_store); - obj_context->encode_state.num_slice_params++; - - return VA_STATUS_SUCCESS; -} - -static void i965_encoder_render_picture_control_buffer(VADriverContextP ctx, - struct object_context *obj_context, - struct object_buffer *obj_buffer) -{ - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); - i965_release_buffer_store(&obj_context->encode_state.pic_control); - i965_reference_buffer_store(&obj_context->encode_state.pic_control, - obj_buffer->buffer_store); -} - -static void i965_encoder_render_qmatrix_buffer(VADriverContextP ctx, - struct object_context *obj_context, - struct object_buffer *obj_buffer) -{ - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); - i965_release_buffer_store(&obj_context->encode_state.q_matrix); - i965_reference_buffer_store(&obj_context->encode_state.iq_matrix, - obj_buffer->buffer_store); -} - -static void i965_encoder_render_iqmatrix_buffer(VADriverContextP ctx, - struct object_context *obj_context, - struct object_buffer *obj_buffer) -{ - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); - i965_release_buffer_store(&obj_context->encode_state.iq_matrix); - i965_reference_buffer_store(&obj_context->encode_state.iq_matrix, - obj_buffer->buffer_store); -} - -VAStatus i965_encoder_create_context(VADriverContextP ctx, - VAConfigID config_id, - int picture_width, - int picture_height, - int flag, - VASurfaceID *render_targets, - int num_render_targets, - struct object_context *obj_context) -{ - struct i965_driver_data *i965 = i965_driver_data(ctx); - struct object_config *obj_config = CONFIG(config_id); - VAStatus vaStatus = VA_STATUS_SUCCESS; - - - if (NULL == obj_config) { - vaStatus = VA_STATUS_ERROR_INVALID_CONFIG; - return vaStatus; - } - - if (NULL == obj_context) { - vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; - return vaStatus; - } - - if( VAProfileH264Baseline != obj_config->profile || - VAEntrypointEncSlice != obj_config->entrypoint) { - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - return vaStatus; - } - - /*encdoe_state init */ - obj_context->encode_state.current_render_target = VA_INVALID_ID; - obj_context->encode_state.max_slice_params = NUM_SLICES; - obj_context->encode_state.slice_params = calloc(obj_context->encode_state.max_slice_params, - sizeof(*obj_context->encode_state.slice_params)); - - return vaStatus; -} - - -VAStatus i965_encoder_begin_picture(VADriverContextP ctx, - VAContextID context, - VASurfaceID render_target) -{ - struct i965_driver_data *i965 = i965_driver_data(ctx); - struct object_context *obj_context = CONTEXT(context); - struct object_surface *obj_surface = SURFACE(render_target); - struct object_config *obj_config; - VAContextID config; - VAStatus vaStatus; - - assert(obj_context); - assert(obj_surface); - - config = obj_context->config_id; - obj_config = CONFIG(config); - assert(obj_config); - - if( VAProfileH264Baseline != obj_config->profile || - VAEntrypointEncSlice != obj_config->entrypoint){ - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - }else{ - vaStatus = VA_STATUS_SUCCESS; - } - - obj_context->encode_state.current_render_target = render_target; /*This is input new frame*/ - - return vaStatus; -} - -VAStatus i965_encoder_render_picture(VADriverContextP ctx, - VAContextID context, - VABufferID *buffers, - int num_buffers) -{ - struct i965_driver_data *i965 = i965_driver_data(ctx); - struct object_context *obj_context = CONTEXT(context); - struct object_config *obj_config; - VAContextID config; - VAStatus vaStatus; - int i; - - assert(obj_context); - config = obj_context->config_id; - obj_config = CONFIG(config); - assert(obj_config); - - - for (i = 0; i < num_buffers; i++) { - struct object_buffer *obj_buffer = BUFFER(buffers[i]); - assert(obj_buffer); - - switch (obj_buffer->type) { - case VAEncSequenceParameterBufferType: - i965_encoder_render_squence_parameter_buffer(ctx, obj_context, obj_buffer); - break; - - case VAEncPictureParameterBufferType: - i965_encoder_render_picture_parameter_buffer(ctx, obj_context, obj_buffer); - break; - - case VAEncSliceParameterBufferType: - i965_encoder_render_slice_parameter_buffer(ctx, obj_context, obj_buffer); - break; - - case VAPictureParameterBufferType: - i965_encoder_render_picture_control_buffer(ctx, obj_context, obj_buffer); - break; - - case VAQMatrixBufferType: - i965_encoder_render_qmatrix_buffer(ctx, obj_context, obj_buffer); - break; - - case VAIQMatrixBufferType: - i965_encoder_render_iqmatrix_buffer(ctx, obj_context, obj_buffer); - break; - - default: - break; - } - } - - vaStatus = VA_STATUS_SUCCESS; - return vaStatus; -} - -static VAStatus +static void gen6_encoder_end_picture(VADriverContextP ctx, - VAContextID context, - struct mfc_encode_state *encode_state) + VAProfile profile, + union codec_state *codec_state, + struct hw_context *hw_context) { + struct gen6_encoder_context *gen6_encoder_context = (struct gen6_encoder_context *)hw_context; + struct encode_state *encode_state = &codec_state->enc; VAStatus vaStatus; - vaStatus = gen6_vme_media_pipeline(ctx, context, encode_state); + vaStatus = gen6_vme_pipeline(ctx, profile, encode_state, gen6_encoder_context); if (vaStatus == VA_STATUS_SUCCESS) - vaStatus = gen6_mfc_pipeline(ctx, context, encode_state); - - return vaStatus; + gen6_mfc_pipeline(ctx, profile, encode_state, gen6_encoder_context); } - -VAStatus i965_encoder_end_picture(VADriverContextP ctx, VAContextID context) +static void +gen6_encoder_context_destroy(void *hw_context) { - struct i965_driver_data *i965 = i965_driver_data(ctx); - struct object_context *obj_context = CONTEXT(context); - struct object_config *obj_config; - VAContextID config; - VAStatus vaStatus; - int i; - - assert(obj_context); - config = obj_context->config_id; - obj_config = CONFIG(config); - assert(obj_config); - - assert(obj_context->encode_state.pic_param); - assert(obj_context->encode_state.num_slice_params >= 1); - - if (IS_GEN6(i965->intel.device_id)) { - vaStatus = gen6_encoder_end_picture(ctx, context, &(obj_context->encode_state)); - } else { - /* add for other chipset */ - assert(0); - } + struct gen6_encoder_context *gen6_encoder_context = (struct gen6_encoder_context *)hw_context; - obj_context->encode_state.current_render_target = VA_INVALID_SURFACE; - obj_context->encode_state.num_slice_params = 0; - i965_release_buffer_store(&obj_context->encode_state.pic_param); - - for (i = 0; i < obj_context->encode_state.num_slice_params; i++) { - i965_release_buffer_store(&obj_context->encode_state.slice_params[i]); - } - - return VA_STATUS_SUCCESS; + gen6_mfc_context_destroy(&gen6_encoder_context->mfc_context); + gen6_vme_context_destroy(&gen6_encoder_context->vme_context); + free(gen6_encoder_context); } - -void i965_encoder_destroy_context(struct object_heap *heap, struct object_base *obj) +struct hw_context * +gen6_enc_hw_context_init(VADriverContextP ctx, VAProfile profile) { - struct object_context *obj_context = (struct object_context *)obj; - - assert(obj_context->encode_state.num_slice_params <= obj_context->encode_state.max_slice_params); - - i965_release_buffer_store(&obj_context->encode_state.pic_param); - i965_release_buffer_store(&obj_context->encode_state.seq_param); - - free(obj_context->render_targets); - object_heap_free(heap, obj); -} - -Bool i965_encoder_init(VADriverContextP ctx) -{ - struct i965_driver_data *i965 = i965_driver_data(ctx); - - if (IS_GEN6(i965->intel.device_id)) { - gen6_vme_init(ctx); - } - - return True; -} - -Bool i965_encoder_terminate(VADriverContextP ctx) -{ - struct i965_driver_data *i965 = i965_driver_data(ctx); - struct gen6_media_state *media_state = &i965->gen6_media_state; - struct gen6_mfc_bcs_state *bcs_state = &i965->gen6_mfc_bcs_state; - int i; - - if (IS_GEN6(i965->intel.device_id)) { - gen6_vme_terminate(ctx); - } - - for (i = 0; i < MAX_MEDIA_SURFACES_GEN6; i++) { - dri_bo_unreference(media_state->surface_state[i].bo); - media_state->surface_state[i].bo = NULL; - } - - dri_bo_unreference(media_state->idrt.bo); - media_state->idrt.bo = NULL; - - dri_bo_unreference(media_state->binding_table.bo); - media_state->binding_table.bo = NULL; - - dri_bo_unreference(media_state->curbe.bo); - media_state->curbe.bo = NULL; - - dri_bo_unreference(media_state->vme_output.bo); - media_state->vme_output.bo = NULL; - - dri_bo_unreference(media_state->vme_state.bo); - media_state->vme_state.bo = NULL; - - dri_bo_unreference(bcs_state->post_deblocking_output.bo); - bcs_state->post_deblocking_output.bo = NULL; - - dri_bo_unreference(bcs_state->pre_deblocking_output.bo); - bcs_state->pre_deblocking_output.bo = NULL; - - dri_bo_unreference(bcs_state->uncompressed_picture_source.bo); - bcs_state->uncompressed_picture_source.bo = NULL; - - dri_bo_unreference(bcs_state->mfc_indirect_pak_bse_object.bo); - bcs_state->mfc_indirect_pak_bse_object.bo = NULL; - - for (i = 0; i < NUM_MFC_DMV_BUFFERS; i++){ - dri_bo_unreference(bcs_state->direct_mv_buffers[i].bo); - bcs_state->direct_mv_buffers[i].bo = NULL; - } - - dri_bo_unreference(bcs_state->intra_row_store_scratch_buffer.bo); - bcs_state->intra_row_store_scratch_buffer.bo = NULL; - - dri_bo_unreference(bcs_state->deblocking_filter_row_store_scratch_buffer.bo); - bcs_state->deblocking_filter_row_store_scratch_buffer.bo = NULL; + struct gen6_encoder_context *gen6_encoder_context = calloc(1, sizeof(struct gen6_encoder_context)); - dri_bo_unreference(bcs_state->bsd_mpc_row_store_scratch_buffer.bo); - bcs_state->bsd_mpc_row_store_scratch_buffer.bo = NULL; + gen6_encoder_context->base.destroy = gen6_encoder_context_destroy; + gen6_encoder_context->base.run = gen6_encoder_end_picture; + gen6_vme_context_init(ctx, &gen6_encoder_context->vme_context); + gen6_mfc_context_init(ctx, &gen6_encoder_context->mfc_context); - return True; + return (struct hw_context *)gen6_encoder_context; } |