VAStatus vlVaBeginPicture(VADriverContextP ctx, VAContextID context_id, VASurfaceID render_target) { vlVaDriver *drv; vlVaContext *context; vlVaSurface *surf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; mtx_lock(&drv->mutex); context = handle_table_get(drv->htab, context_id); if (!context) { mtx_unlock(&drv->mutex); return VA_STATUS_ERROR_INVALID_CONTEXT; } if (u_reduce_video_profile(context->templat.profile) == PIPE_VIDEO_FORMAT_MPEG12) { context->desc.mpeg12.intra_matrix = NULL; context->desc.mpeg12.non_intra_matrix = NULL; } surf = handle_table_get(drv->htab, render_target); mtx_unlock(&drv->mutex); if (!surf || !surf->buffer) return VA_STATUS_ERROR_INVALID_SURFACE; context->target_id = render_target; surf->ctx = context_id; context->target = surf->buffer; context->mjpeg.sampling_factor = 0; if (!context->decoder) { /* VPP */ if (context->templat.profile == PIPE_VIDEO_PROFILE_UNKNOWN && context->target->buffer_format != PIPE_FORMAT_B8G8R8A8_UNORM && context->target->buffer_format != PIPE_FORMAT_R8G8B8A8_UNORM && context->target->buffer_format != PIPE_FORMAT_B8G8R8X8_UNORM && context->target->buffer_format != PIPE_FORMAT_R8G8B8X8_UNORM && context->target->buffer_format != PIPE_FORMAT_NV12 && context->target->buffer_format != PIPE_FORMAT_P016) return VA_STATUS_ERROR_UNIMPLEMENTED; return VA_STATUS_SUCCESS; } if (context->decoder->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE) context->needs_begin_frame = true; return VA_STATUS_SUCCESS; }
VAStatus vlVaSyncSurface(VADriverContextP ctx, VASurfaceID render_target) { vlVaDriver *drv; vlVaContext *context; vlVaSurface *surf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; pipe_mutex_lock(drv->mutex); surf = handle_table_get(drv->htab, render_target); if (!surf || !surf->buffer) { pipe_mutex_unlock(drv->mutex); return VA_STATUS_ERROR_INVALID_SURFACE; } if (!surf->feedback) { // No outstanding operation: nothing to do. pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; } context = handle_table_get(drv->htab, surf->ctx); if (!context) { pipe_mutex_unlock(drv->mutex); return VA_STATUS_ERROR_INVALID_CONTEXT; } if (context->decoder->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE) { int frame_diff; if (context->desc.h264enc.frame_num_cnt >= surf->frame_num_cnt) frame_diff = context->desc.h264enc.frame_num_cnt - surf->frame_num_cnt; else frame_diff = 0xFFFFFFFF - surf->frame_num_cnt + 1 + context->desc.h264enc.frame_num_cnt; if ((frame_diff == 0) && (surf->force_flushed == false) && (context->desc.h264enc.frame_num_cnt % 2 != 0)) { context->decoder->flush(context->decoder); context->first_single_submitted = true; } context->decoder->get_feedback(context->decoder, surf->feedback, &(surf->coded_buf->coded_size)); surf->feedback = NULL; } pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id) { vlVaDriver *drv; vlVaConfig *config; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; pipe_mutex_lock(drv->mutex); config = handle_table_get(drv->htab, config_id); if (!config) return VA_STATUS_ERROR_INVALID_CONFIG; FREE(config); handle_table_remove(drv->htab, config_id); pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; }
VAStatus vlVaUnmapBuffer(VADriverContextP ctx, VABufferID buf_id) { vlVaDriver *drv; vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(drv->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; if (buf->export_refcount > 0) return VA_STATUS_ERROR_INVALID_BUFFER; if (buf->derived_surface.resource) { if (!buf->derived_surface.transfer) return VA_STATUS_ERROR_INVALID_BUFFER; pipe_buffer_unmap(drv->pipe, buf->derived_surface.transfer); buf->derived_surface.transfer = NULL; } return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buf_id) { vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; if (buf->derived_surface.resource) { if (buf->export_refcount > 0) return VA_STATUS_ERROR_INVALID_BUFFER; pipe_resource_reference(&buf->derived_surface.resource, NULL); } FREE(buf->data); FREE(buf); handle_table_remove(VL_VA_DRIVER(ctx)->htab, buf_id); return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroySurfaces(VADriverContextP ctx, VASurfaceID *surface_list, int num_surfaces) { vlVaDriver *drv; int i; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); pipe_mutex_lock(drv->mutex); for (i = 0; i < num_surfaces; ++i) { vlVaSurface *surf = handle_table_get(drv->htab, surface_list[i]); if (!surf) { pipe_mutex_unlock(drv->mutex); return VA_STATUS_ERROR_INVALID_SURFACE; } if (surf->buffer) surf->buffer->destroy(surf->buffer); util_dynarray_fini(&surf->subpics); FREE(surf); handle_table_remove(drv->htab, surface_list[i]); } pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; }
VAStatus vlVaReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id) { vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; if (buf->export_refcount == 0) return VA_STATUS_ERROR_INVALID_BUFFER; if (--buf->export_refcount == 0) { VABufferInfo * const buf_info = &buf->export_state; switch (buf_info->mem_type) { case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: close((intptr_t)buf_info->handle); break; default: return VA_STATUS_ERROR_INVALID_BUFFER; } buf_info->mem_type = 0; } return VA_STATUS_SUCCESS; }
VAStatus vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id, unsigned int num_elements) { vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; if (buf->derived_surface.resource) return VA_STATUS_ERROR_INVALID_BUFFER; buf->data = REALLOC(buf->data, buf->size * buf->num_elements, buf->size * num_elements); buf->num_elements = num_elements; if (!buf->data) return VA_STATUS_ERROR_ALLOCATION_FAILED; return VA_STATUS_SUCCESS; }
VAStatus vlVaQueryVideoProcPipelineCaps(VADriverContextP ctx, VAContextID context, VABufferID *filters, unsigned int num_filters, VAProcPipelineCaps *pipeline_cap) { unsigned int i = 0; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; if (!pipeline_cap) return VA_STATUS_ERROR_INVALID_PARAMETER; if (num_filters && !filters) return VA_STATUS_ERROR_INVALID_PARAMETER; pipeline_cap->pipeline_flags = 0; pipeline_cap->filter_flags = 0; pipeline_cap->num_forward_references = 0; pipeline_cap->num_backward_references = 0; pipeline_cap->num_input_color_standards = 1; pipeline_cap->input_color_standards = vpp_input_color_standards; pipeline_cap->num_output_color_standards = 1; pipeline_cap->output_color_standards = vpp_output_color_standards; for (i = 0; i < num_filters; i++) { vlVaBuffer *buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, filters[i]); if (!buf || buf->type >= VABufferTypeMax) return VA_STATUS_ERROR_INVALID_BUFFER; } return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroyContext(VADriverContextP ctx, VAContextID context_id) { vlVaDriver *drv; vlVaContext *context; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); context = handle_table_get(drv->htab, context_id); if (context->decoder) { if (u_reduce_video_profile(context->decoder->profile) == PIPE_VIDEO_FORMAT_MPEG4_AVC) { FREE(context->desc.h264.pps->sps); FREE(context->desc.h264.pps); } if (u_reduce_video_profile(context->decoder->profile) == PIPE_VIDEO_FORMAT_HEVC) { FREE(context->desc.h265.pps->sps); FREE(context->desc.h265.pps); } context->decoder->destroy(context->decoder); } FREE(context); handle_table_remove(drv->htab, context_id); return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buf_id) { vlVaDriver *drv; vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); mtx_lock(&drv->mutex); buf = handle_table_get(drv->htab, buf_id); if (!buf) { mtx_unlock(&drv->mutex); return VA_STATUS_ERROR_INVALID_BUFFER; } if (buf->derived_surface.resource) pipe_resource_reference(&buf->derived_surface.resource, NULL); FREE(buf->data); FREE(buf); handle_table_remove(VL_VA_DRIVER(ctx)->htab, buf_id); mtx_unlock(&drv->mutex); return VA_STATUS_SUCCESS; }
VAStatus vlVaBeginPicture(VADriverContextP ctx, VAContextID context_id, VASurfaceID render_target) { vlVaDriver *drv; vlVaContext *context; vlVaSurface *surf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; pipe_mutex_lock(drv->mutex); context = handle_table_get(drv->htab, context_id); if (!context) { pipe_mutex_unlock(drv->mutex); return VA_STATUS_ERROR_INVALID_CONTEXT; } surf = handle_table_get(drv->htab, render_target); pipe_mutex_unlock(drv->mutex); if (!surf || !surf->buffer) return VA_STATUS_ERROR_INVALID_SURFACE; context->target = surf->buffer; if (!context->decoder) { /* VPP */ if (context->templat.profile == PIPE_VIDEO_PROFILE_UNKNOWN && context->target->buffer_format != PIPE_FORMAT_B8G8R8A8_UNORM && context->target->buffer_format != PIPE_FORMAT_R8G8B8A8_UNORM && context->target->buffer_format != PIPE_FORMAT_B8G8R8X8_UNORM && context->target->buffer_format != PIPE_FORMAT_R8G8B8X8_UNORM && context->target->buffer_format != PIPE_FORMAT_NV12) return VA_STATUS_ERROR_UNIMPLEMENTED; return VA_STATUS_SUCCESS; } if (context->decoder->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE) context->decoder->begin_frame(context->decoder, context->target, &context->desc.base); return VA_STATUS_SUCCESS; }
static struct pipe_video_buffer * vlVaApplyDeint(vlVaDriver *drv, vlVaContext *context, VAProcPipelineParameterBuffer *param, struct pipe_video_buffer *current, unsigned field) { vlVaSurface *prevprev, *prev, *next; if (param->num_forward_references < 1 || param->num_backward_references < 2) return current; prevprev = handle_table_get(drv->htab, param->backward_references[1]); prev = handle_table_get(drv->htab, param->backward_references[0]); next = handle_table_get(drv->htab, param->forward_references[0]); if (!prevprev || !prev || !next) return current; if (context->deint && (context->deint->video_width != current->width || context->deint->video_height != current->height)) { vl_deint_filter_cleanup(context->deint); FREE(context->deint); context->deint = NULL; } if (!context->deint) { context->deint = MALLOC(sizeof(struct vl_deint_filter)); if (!vl_deint_filter_init(context->deint, drv->pipe, current->width, current->height, false, false)) { FREE(context->deint); context->deint = NULL; return current; } } if (!vl_deint_filter_check_buffers(context->deint, prevprev->buffer, prev->buffer, current, next->buffer)) return current; vl_deint_filter_render(context->deint, prevprev->buffer, prev->buffer, current, next->buffer, field); return context->deint->video_buffer; }
void vlVaGetReferenceFrame(vlVaDriver *drv, VASurfaceID surface_id, struct pipe_video_buffer **ref_frame) { vlVaSurface *surf = handle_table_get(drv->htab, surface_id); if (surf) *ref_frame = surf->buffer; else *ref_frame = NULL; }
struct stw_context * stw_lookup_context_locked( UINT_PTR dhglrc ) { if (dhglrc == 0) return NULL; if (stw_dev == NULL) return NULL; return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc); }
VAStatus vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff) { vlVaDriver *drv; vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; if (!pbuff) return VA_STATUS_ERROR_INVALID_PARAMETER; mtx_lock(&drv->mutex); buf = handle_table_get(drv->htab, buf_id); if (!buf || buf->export_refcount > 0) { mtx_unlock(&drv->mutex); return VA_STATUS_ERROR_INVALID_BUFFER; } if (buf->derived_surface.resource) { struct pipe_resource *resource; struct pipe_box box = {}; resource = buf->derived_surface.resource; box.width = resource->width0; box.height = resource->height0; box.depth = resource->depth0; *pbuff = drv->pipe->transfer_map(drv->pipe, resource, 0, PIPE_TRANSFER_WRITE, &box, &buf->derived_surface.transfer); mtx_unlock(&drv->mutex); if (!buf->derived_surface.transfer || !*pbuff) return VA_STATUS_ERROR_INVALID_BUFFER; if (buf->type == VAEncCodedBufferType) { ((VACodedBufferSegment*)buf->data)->buf = *pbuff; ((VACodedBufferSegment*)buf->data)->size = buf->coded_size; ((VACodedBufferSegment*)buf->data)->next = NULL; *pbuff = buf->data; } } else { mtx_unlock(&drv->mutex); *pbuff = buf->data; } return VA_STATUS_SUCCESS; }
void* vlGetDataHTAB(vlHandle handle) { assert(handle); #ifdef VL_HANDLES void *data = NULL; pipe_mutex_lock(htab_lock); if (htab) data = handle_table_get(htab, handle); pipe_mutex_unlock(htab_lock); return data; #else return (void*)handle; #endif }
VAStatus vlVaQueryVideoProcPipelineCaps(VADriverContextP ctx, VAContextID context, VABufferID *filters, unsigned int num_filters, VAProcPipelineCaps *pipeline_cap) { unsigned int i = 0; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; if (!pipeline_cap) return VA_STATUS_ERROR_INVALID_PARAMETER; if (num_filters && !filters) return VA_STATUS_ERROR_INVALID_PARAMETER; pipeline_cap->pipeline_flags = 0; pipeline_cap->filter_flags = 0; pipeline_cap->num_forward_references = 0; pipeline_cap->num_backward_references = 0; pipeline_cap->num_input_color_standards = ARRAY_SIZE(vpp_input_color_standards); pipeline_cap->input_color_standards = vpp_input_color_standards; pipeline_cap->num_output_color_standards = ARRAY_SIZE(vpp_output_color_standards); pipeline_cap->output_color_standards = vpp_output_color_standards; for (i = 0; i < num_filters; i++) { vlVaBuffer *buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, filters[i]); VAProcFilterParameterBufferBase *filter; if (!buf || buf->type != VAProcFilterParameterBufferType) return VA_STATUS_ERROR_INVALID_BUFFER; filter = buf->data; switch (filter->type) { case VAProcFilterDeinterlacing: { VAProcFilterParameterBufferDeinterlacing *deint = buf->data; if (deint->algorithm == VAProcDeinterlacingMotionAdaptive) { pipeline_cap->num_forward_references = 1; pipeline_cap->num_backward_references = 2; } break; } default: return VA_STATUS_ERROR_UNIMPLEMENTED; } } return VA_STATUS_SUCCESS; }
VAStatus vlVaEndPicture(VADriverContextP ctx, VAContextID context_id) { vlVaDriver *drv; vlVaContext *context; vlVaBuffer *coded_buf; unsigned int coded_size; void *feedback; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; pipe_mutex_lock(drv->mutex); context = handle_table_get(drv->htab, context_id); pipe_mutex_unlock(drv->mutex); if (!context) return VA_STATUS_ERROR_INVALID_CONTEXT; if (!context->decoder) { if (context->templat.profile != PIPE_VIDEO_PROFILE_UNKNOWN) return VA_STATUS_ERROR_INVALID_CONTEXT; /* VPP */ return VA_STATUS_SUCCESS; } context->mpeg4.frame_num++; if (context->decoder->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE) { coded_buf = context->coded_buf; getEncParamPreset(context); context->decoder->begin_frame(context->decoder, context->target, &context->desc.base); context->decoder->encode_bitstream(context->decoder, context->target, coded_buf->derived_surface.resource, &feedback); context->decoder->end_frame(context->decoder, context->target, &context->desc.base); context->decoder->flush(context->decoder); context->decoder->get_feedback(context->decoder, feedback, &coded_size); coded_buf->coded_size = coded_size; } else context->decoder->end_frame(context->decoder, context->target, &context->desc.base); return VA_STATUS_SUCCESS; }
VAStatus vlVaUnmapBuffer(VADriverContextP ctx, VABufferID buf_id) { vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; /* Nothing to do here */ return VA_STATUS_SUCCESS; }
VAStatus vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff) { vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; *pbuff = buf->data; return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroyImage(VADriverContextP ctx, VAImageID image) { VAImage *vaimage; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; vaimage = handle_table_get(VL_VA_DRIVER(ctx)->htab, image); if (!vaimage) return VA_STATUS_ERROR_INVALID_IMAGE; handle_table_remove(VL_VA_DRIVER(ctx)->htab, image); FREE(vaimage); return vlVaDestroyBuffer(ctx, vaimage->buf); }
VAStatus vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buf_id) { vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; FREE(buf->data); FREE(buf); return VA_STATUS_SUCCESS; }
VAStatus vlVaBufferInfo(VADriverContextP ctx, VABufferID buf_id, VABufferType *type, unsigned int *size, unsigned int *num_elements) { vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id); if (!buf) return VA_STATUS_ERROR_INVALID_BUFFER; *type = buf->type; *size = buf->size; *num_elements = buf->num_elements; return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroyContext(VADriverContextP ctx, VAContextID context_id) { vlVaDriver *drv; vlVaContext *context; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); pipe_mutex_lock(drv->mutex); context = handle_table_get(drv->htab, context_id); if (!context) { pipe_mutex_unlock(drv->mutex); return VA_STATUS_ERROR_INVALID_CONTEXT; } if (context->decoder) { if (context->desc.base.entry_point != PIPE_VIDEO_ENTRYPOINT_ENCODE) { if (u_reduce_video_profile(context->decoder->profile) == PIPE_VIDEO_FORMAT_MPEG4_AVC) { FREE(context->desc.h264.pps->sps); FREE(context->desc.h264.pps); } if (u_reduce_video_profile(context->decoder->profile) == PIPE_VIDEO_FORMAT_HEVC) { FREE(context->desc.h265.pps->sps); FREE(context->desc.h265.pps); } } context->decoder->destroy(context->decoder); } if (context->deint) { vl_deint_filter_cleanup(context->deint); FREE(context->deint); } FREE(context); handle_table_remove(drv->htab, context_id); pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; }
static VAStatus handleVAEncPictureParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf) { VAEncPictureParameterBufferH264 *h264; vlVaBuffer *coded_buf; h264 = buf->data; context->desc.h264enc.frame_num = h264->frame_num; context->desc.h264enc.not_referenced = false; context->desc.h264enc.is_idr = (h264->pic_fields.bits.idr_pic_flag == 1); context->desc.h264enc.pic_order_cnt = h264->CurrPic.TopFieldOrderCnt / 2; if (context->desc.h264enc.is_idr) context->desc.h264enc.i_remain = 1; else context->desc.h264enc.i_remain = 0; context->desc.h264enc.p_remain = context->desc.h264enc.gop_size - context->desc.h264enc.gop_cnt - context->desc.h264enc.i_remain; coded_buf = handle_table_get(drv->htab, h264->coded_buf); if (!coded_buf->derived_surface.resource) coded_buf->derived_surface.resource = pipe_buffer_create(drv->pipe->screen, PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM, coded_buf->size); context->coded_buf = coded_buf; context->desc.h264enc.frame_idx[h264->CurrPic.picture_id] = h264->frame_num; if (context->desc.h264enc.is_idr) context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_IDR; else context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_P; context->desc.h264enc.quant_i_frames = h264->pic_init_qp; context->desc.h264enc.quant_b_frames = h264->pic_init_qp; context->desc.h264enc.quant_p_frames = h264->pic_init_qp; context->desc.h264enc.frame_num_cnt++; context->desc.h264enc.gop_cnt++; if (context->desc.h264enc.gop_cnt == context->desc.h264enc.gop_size) context->desc.h264enc.gop_cnt = 0; return VA_STATUS_SUCCESS; }
VAStatus vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff) { vlVaDriver *drv; vlVaBuffer *buf; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; if (!pbuff) return VA_STATUS_ERROR_INVALID_PARAMETER; pipe_mutex_lock(drv->mutex); buf = handle_table_get(drv->htab, buf_id); if (!buf || buf->export_refcount > 0) { pipe_mutex_unlock(drv->mutex); return VA_STATUS_ERROR_INVALID_BUFFER; } if (buf->derived_surface.resource) { *pbuff = pipe_buffer_map(drv->pipe, buf->derived_surface.resource, PIPE_TRANSFER_WRITE, &buf->derived_surface.transfer); pipe_mutex_unlock(drv->mutex); if (!buf->derived_surface.transfer || !*pbuff) return VA_STATUS_ERROR_INVALID_BUFFER; } else { pipe_mutex_unlock(drv->mutex); *pbuff = buf->data; } return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroyImage(VADriverContextP ctx, VAImageID image) { vlVaDriver *drv; VAImage *vaimage; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); pipe_mutex_lock(drv->mutex); vaimage = handle_table_get(drv->htab, image); if (!vaimage) { pipe_mutex_unlock(drv->mutex); return VA_STATUS_ERROR_INVALID_IMAGE; } handle_table_remove(VL_VA_DRIVER(ctx)->htab, image); pipe_mutex_unlock(drv->mutex); FREE(vaimage); return vlVaDestroyBuffer(ctx, vaimage->buf); }
VAStatus vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile, VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs) { vlVaDriver *drv; vlVaConfig *config; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); if (!drv) return VA_STATUS_ERROR_INVALID_CONTEXT; pipe_mutex_lock(drv->mutex); config = handle_table_get(drv->htab, config_id); pipe_mutex_unlock(drv->mutex); if (!config) return VA_STATUS_ERROR_INVALID_CONFIG; *profile = PipeToProfile(config->profile); if (config->profile == PIPE_VIDEO_PROFILE_UNKNOWN) { *entrypoint = VAEntrypointVideoProc; *num_attribs = 0; return VA_STATUS_SUCCESS; } *entrypoint = config->entrypoint; *num_attribs = 1; attrib_list[0].type = VAConfigAttribRTFormat; attrib_list[0].value = config->rt_format; return VA_STATUS_SUCCESS; }
VAStatus vlVaDestroySurfaces(VADriverContextP ctx, VASurfaceID *surface_list, int num_surfaces) { vlVaDriver *drv; int i; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; drv = VL_VA_DRIVER(ctx); for (i = 0; i < num_surfaces; ++i) { vlVaSurface *surf = handle_table_get(drv->htab, surface_list[i]); if (surf->buffer) surf->buffer->destroy(surf->buffer); if(surf->fence) drv->pipe->screen->fence_reference(drv->pipe->screen, &surf->fence, NULL); util_dynarray_fini(&surf->subpics); FREE(surf); handle_table_remove(drv->htab, surface_list[i]); } return VA_STATUS_SUCCESS; }