Path: blob/21.2-virgl/src/gallium/frontends/va/picture_h264.c
4561 views
/**************************************************************************1*2* Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.3* Copyright 2014 Advanced Micro Devices, Inc.4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the8* "Software"), to deal in the Software without restriction, including9* without limitation the rights to use, copy, modify, merge, publish,10* distribute, sub license, and/or sell copies of the Software, and to11* permit persons to whom the Software is furnished to do so, subject to12* the following conditions:13*14* The above copyright notice and this permission notice (including the15* next paragraph) shall be included in all copies or substantial portions16* of the Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS19* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF20* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.21* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR22* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,23* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE24* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.25*26**************************************************************************/2728#include "util/u_video.h"29#include "va_private.h"3031static void resetReferencePictureDesc(struct pipe_h264_picture_desc *h264,32unsigned int i)33{34h264->ref[i] = NULL;35h264->frame_num_list[i] = 0;36h264->is_long_term[i] = 0;37h264->top_is_reference[i] = 0;38h264->bottom_is_reference[i] = 0;39h264->field_order_cnt_list[i][0] = 0;40h264->field_order_cnt_list[i][1] = 0;41}4243void vlVaHandlePictureParameterBufferH264(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)44{45VAPictureParameterBufferH264 *h264 = buf->data;46unsigned int top_or_bottom_field;47unsigned i;4849assert(buf->size >= sizeof(VAPictureParameterBufferH264) && buf->num_elements == 1);50context->desc.h264.slice_count = 0;51/*CurrPic*/52context->desc.h264.field_order_cnt[0] = h264->CurrPic.TopFieldOrderCnt;53context->desc.h264.field_order_cnt[1] = h264->CurrPic.BottomFieldOrderCnt;54/*ReferenceFrames[16]*/55/*picture_width_in_mbs_minus1*/56/*picture_height_in_mbs_minus1*/57/*bit_depth_luma_minus8*/58/*bit_depth_chroma_minus8*/59context->desc.h264.num_ref_frames = h264->num_ref_frames;60/*chroma_format_idc*/61/*residual_colour_transform_flag*/62/*gaps_in_frame_num_value_allowed_flag*/63context->desc.h264.pps->sps->frame_mbs_only_flag =64h264->seq_fields.bits.frame_mbs_only_flag;65context->desc.h264.pps->sps->mb_adaptive_frame_field_flag =66h264->seq_fields.bits.mb_adaptive_frame_field_flag;67context->desc.h264.pps->sps->direct_8x8_inference_flag =68h264->seq_fields.bits.direct_8x8_inference_flag;69/*MinLumaBiPredSize8x8*/70context->desc.h264.pps->sps->log2_max_frame_num_minus4 =71h264->seq_fields.bits.log2_max_frame_num_minus4;72context->desc.h264.pps->sps->pic_order_cnt_type =73h264->seq_fields.bits.pic_order_cnt_type;74context->desc.h264.pps->sps->log2_max_pic_order_cnt_lsb_minus4 =75h264->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4;76context->desc.h264.pps->sps->delta_pic_order_always_zero_flag =77h264->seq_fields.bits.delta_pic_order_always_zero_flag;78/*num_slice_groups_minus1*/79/*slice_group_map_type*/80/*slice_group_change_rate_minus1*/81context->desc.h264.pps->pic_init_qp_minus26 =82h264->pic_init_qp_minus26;83/*pic_init_qs_minus26*/84context->desc.h264.pps->chroma_qp_index_offset =85h264->chroma_qp_index_offset;86context->desc.h264.pps->second_chroma_qp_index_offset =87h264->second_chroma_qp_index_offset;88context->desc.h264.pps->entropy_coding_mode_flag =89h264->pic_fields.bits.entropy_coding_mode_flag;90context->desc.h264.pps->weighted_pred_flag =91h264->pic_fields.bits.weighted_pred_flag;92context->desc.h264.pps->weighted_bipred_idc =93h264->pic_fields.bits.weighted_bipred_idc;94context->desc.h264.pps->transform_8x8_mode_flag =95h264->pic_fields.bits.transform_8x8_mode_flag;96context->desc.h264.field_pic_flag =97h264->pic_fields.bits.field_pic_flag;98context->desc.h264.pps->constrained_intra_pred_flag =99h264->pic_fields.bits.constrained_intra_pred_flag;100context->desc.h264.pps->bottom_field_pic_order_in_frame_present_flag =101h264->pic_fields.bits.pic_order_present_flag;102context->desc.h264.pps->deblocking_filter_control_present_flag =103h264->pic_fields.bits.deblocking_filter_control_present_flag;104context->desc.h264.pps->redundant_pic_cnt_present_flag =105h264->pic_fields.bits.redundant_pic_cnt_present_flag;106/*reference_pic_flag*/107context->desc.h264.frame_num = h264->frame_num;108context->desc.h264.is_reference = h264->pic_fields.bits.reference_pic_flag;109context->desc.h264.bottom_field_flag =110h264->pic_fields.bits.field_pic_flag &&111(h264->CurrPic.flags & VA_PICTURE_H264_BOTTOM_FIELD) != 0;112113if (!context->decoder && context->desc.h264.num_ref_frames > 0)114context->templat.max_references = MIN2(context->desc.h264.num_ref_frames, 16);115116for (i = 0; i < context->templat.max_references; ++i) {117if ((h264->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID) ||118(h264->ReferenceFrames[i].picture_id == VA_INVALID_SURFACE)) {119resetReferencePictureDesc(&context->desc.h264, i);120break;121}122123vlVaGetReferenceFrame(drv, h264->ReferenceFrames[i].picture_id, &context->desc.h264.ref[i]);124context->desc.h264.frame_num_list[i] = h264->ReferenceFrames[i].frame_idx;125126top_or_bottom_field = h264->ReferenceFrames[i].flags &127(VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD);128context->desc.h264.is_long_term[i] = (h264->ReferenceFrames[i].flags &129(VA_PICTURE_H264_SHORT_TERM_REFERENCE |130VA_PICTURE_H264_LONG_TERM_REFERENCE)) !=131VA_PICTURE_H264_SHORT_TERM_REFERENCE;132context->desc.h264.top_is_reference[i] =133!context->desc.h264.is_long_term[i] ||134!!(h264->ReferenceFrames[i].flags & VA_PICTURE_H264_TOP_FIELD);135context->desc.h264.bottom_is_reference[i] =136!context->desc.h264.is_long_term[i] ||137!!(h264->ReferenceFrames[i].flags & VA_PICTURE_H264_BOTTOM_FIELD);138context->desc.h264.field_order_cnt_list[i][0] =139top_or_bottom_field != VA_PICTURE_H264_BOTTOM_FIELD ?140h264->ReferenceFrames[i].TopFieldOrderCnt: INT_MAX;141context->desc.h264.field_order_cnt_list[i][1] =142top_or_bottom_field != VA_PICTURE_H264_TOP_FIELD ?143h264->ReferenceFrames[i].BottomFieldOrderCnt: INT_MAX;144}145146/* Make sure remaining elements are clean */147for (; i < 16; ++i)148resetReferencePictureDesc(&context->desc.h264, i);149}150151void vlVaHandleIQMatrixBufferH264(vlVaContext *context, vlVaBuffer *buf)152{153VAIQMatrixBufferH264 *h264 = buf->data;154155assert(buf->size >= sizeof(VAIQMatrixBufferH264) && buf->num_elements == 1);156memcpy(&context->desc.h264.pps->ScalingList4x4, h264->ScalingList4x4, 6 * 16);157memcpy(&context->desc.h264.pps->ScalingList8x8, h264->ScalingList8x8, 2 * 64);158}159160void vlVaHandleSliceParameterBufferH264(vlVaContext *context, vlVaBuffer *buf)161{162VASliceParameterBufferH264 *h264 = buf->data;163164assert(buf->size >= sizeof(VASliceParameterBufferH264) && buf->num_elements == 1);165context->desc.h264.slice_count += buf->num_elements;166context->desc.h264.num_ref_idx_l0_active_minus1 =167h264->num_ref_idx_l0_active_minus1;168context->desc.h264.num_ref_idx_l1_active_minus1 =169h264->num_ref_idx_l1_active_minus1;170}171172173