17ec681f3Smrg /************************************************************************** 27ec681f3Smrg * 37ec681f3Smrg * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian. 47ec681f3Smrg * Copyright 2014 Advanced Micro Devices, Inc. 57ec681f3Smrg * All Rights Reserved. 67ec681f3Smrg * 77ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 87ec681f3Smrg * copy of this software and associated documentation files (the 97ec681f3Smrg * "Software"), to deal in the Software without restriction, including 107ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish, 117ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to 127ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to 137ec681f3Smrg * the following conditions: 147ec681f3Smrg * 157ec681f3Smrg * The above copyright notice and this permission notice (including the 167ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions 177ec681f3Smrg * of the Software. 187ec681f3Smrg * 197ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 207ec681f3Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 217ec681f3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 227ec681f3Smrg * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR 237ec681f3Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 247ec681f3Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 257ec681f3Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 267ec681f3Smrg * 277ec681f3Smrg **************************************************************************/ 287ec681f3Smrg 297ec681f3Smrg#include "util/u_video.h" 307ec681f3Smrg#include "va_private.h" 317ec681f3Smrg 327ec681f3Smrgstatic void resetReferencePictureDesc(struct pipe_h264_picture_desc *h264, 337ec681f3Smrg unsigned int i) 347ec681f3Smrg{ 357ec681f3Smrg h264->ref[i] = NULL; 367ec681f3Smrg h264->frame_num_list[i] = 0; 377ec681f3Smrg h264->is_long_term[i] = 0; 387ec681f3Smrg h264->top_is_reference[i] = 0; 397ec681f3Smrg h264->bottom_is_reference[i] = 0; 407ec681f3Smrg h264->field_order_cnt_list[i][0] = 0; 417ec681f3Smrg h264->field_order_cnt_list[i][1] = 0; 427ec681f3Smrg} 437ec681f3Smrg 447ec681f3Smrgvoid vlVaHandlePictureParameterBufferH264(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf) 457ec681f3Smrg{ 467ec681f3Smrg VAPictureParameterBufferH264 *h264 = buf->data; 477ec681f3Smrg unsigned int top_or_bottom_field; 487ec681f3Smrg unsigned i; 497ec681f3Smrg 507ec681f3Smrg assert(buf->size >= sizeof(VAPictureParameterBufferH264) && buf->num_elements == 1); 517ec681f3Smrg context->desc.h264.slice_count = 0; 527ec681f3Smrg /*CurrPic*/ 537ec681f3Smrg context->desc.h264.field_order_cnt[0] = h264->CurrPic.TopFieldOrderCnt; 547ec681f3Smrg context->desc.h264.field_order_cnt[1] = h264->CurrPic.BottomFieldOrderCnt; 557ec681f3Smrg /*ReferenceFrames[16]*/ 567ec681f3Smrg /*picture_width_in_mbs_minus1*/ 577ec681f3Smrg /*picture_height_in_mbs_minus1*/ 587ec681f3Smrg /*bit_depth_luma_minus8*/ 597ec681f3Smrg /*bit_depth_chroma_minus8*/ 607ec681f3Smrg context->desc.h264.num_ref_frames = h264->num_ref_frames; 617ec681f3Smrg /*chroma_format_idc*/ 627ec681f3Smrg /*residual_colour_transform_flag*/ 637ec681f3Smrg /*gaps_in_frame_num_value_allowed_flag*/ 647ec681f3Smrg context->desc.h264.pps->sps->frame_mbs_only_flag = 657ec681f3Smrg h264->seq_fields.bits.frame_mbs_only_flag; 667ec681f3Smrg context->desc.h264.pps->sps->mb_adaptive_frame_field_flag = 677ec681f3Smrg h264->seq_fields.bits.mb_adaptive_frame_field_flag; 687ec681f3Smrg context->desc.h264.pps->sps->direct_8x8_inference_flag = 697ec681f3Smrg h264->seq_fields.bits.direct_8x8_inference_flag; 707ec681f3Smrg /*MinLumaBiPredSize8x8*/ 717ec681f3Smrg context->desc.h264.pps->sps->log2_max_frame_num_minus4 = 727ec681f3Smrg h264->seq_fields.bits.log2_max_frame_num_minus4; 737ec681f3Smrg context->desc.h264.pps->sps->pic_order_cnt_type = 747ec681f3Smrg h264->seq_fields.bits.pic_order_cnt_type; 757ec681f3Smrg context->desc.h264.pps->sps->log2_max_pic_order_cnt_lsb_minus4 = 767ec681f3Smrg h264->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4; 777ec681f3Smrg context->desc.h264.pps->sps->delta_pic_order_always_zero_flag = 787ec681f3Smrg h264->seq_fields.bits.delta_pic_order_always_zero_flag; 797ec681f3Smrg /*num_slice_groups_minus1*/ 807ec681f3Smrg /*slice_group_map_type*/ 817ec681f3Smrg /*slice_group_change_rate_minus1*/ 827ec681f3Smrg context->desc.h264.pps->pic_init_qp_minus26 = 837ec681f3Smrg h264->pic_init_qp_minus26; 847ec681f3Smrg /*pic_init_qs_minus26*/ 857ec681f3Smrg context->desc.h264.pps->chroma_qp_index_offset = 867ec681f3Smrg h264->chroma_qp_index_offset; 877ec681f3Smrg context->desc.h264.pps->second_chroma_qp_index_offset = 887ec681f3Smrg h264->second_chroma_qp_index_offset; 897ec681f3Smrg context->desc.h264.pps->entropy_coding_mode_flag = 907ec681f3Smrg h264->pic_fields.bits.entropy_coding_mode_flag; 917ec681f3Smrg context->desc.h264.pps->weighted_pred_flag = 927ec681f3Smrg h264->pic_fields.bits.weighted_pred_flag; 937ec681f3Smrg context->desc.h264.pps->weighted_bipred_idc = 947ec681f3Smrg h264->pic_fields.bits.weighted_bipred_idc; 957ec681f3Smrg context->desc.h264.pps->transform_8x8_mode_flag = 967ec681f3Smrg h264->pic_fields.bits.transform_8x8_mode_flag; 977ec681f3Smrg context->desc.h264.field_pic_flag = 987ec681f3Smrg h264->pic_fields.bits.field_pic_flag; 997ec681f3Smrg context->desc.h264.pps->constrained_intra_pred_flag = 1007ec681f3Smrg h264->pic_fields.bits.constrained_intra_pred_flag; 1017ec681f3Smrg context->desc.h264.pps->bottom_field_pic_order_in_frame_present_flag = 1027ec681f3Smrg h264->pic_fields.bits.pic_order_present_flag; 1037ec681f3Smrg context->desc.h264.pps->deblocking_filter_control_present_flag = 1047ec681f3Smrg h264->pic_fields.bits.deblocking_filter_control_present_flag; 1057ec681f3Smrg context->desc.h264.pps->redundant_pic_cnt_present_flag = 1067ec681f3Smrg h264->pic_fields.bits.redundant_pic_cnt_present_flag; 1077ec681f3Smrg /*reference_pic_flag*/ 1087ec681f3Smrg context->desc.h264.frame_num = h264->frame_num; 1097ec681f3Smrg context->desc.h264.is_reference = h264->pic_fields.bits.reference_pic_flag; 1107ec681f3Smrg context->desc.h264.bottom_field_flag = 1117ec681f3Smrg h264->pic_fields.bits.field_pic_flag && 1127ec681f3Smrg (h264->CurrPic.flags & VA_PICTURE_H264_BOTTOM_FIELD) != 0; 1137ec681f3Smrg 1147ec681f3Smrg if (!context->decoder && context->desc.h264.num_ref_frames > 0) 1157ec681f3Smrg context->templat.max_references = MIN2(context->desc.h264.num_ref_frames, 16); 1167ec681f3Smrg 1177ec681f3Smrg for (i = 0; i < context->templat.max_references; ++i) { 1187ec681f3Smrg if ((h264->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID) || 1197ec681f3Smrg (h264->ReferenceFrames[i].picture_id == VA_INVALID_SURFACE)) { 1207ec681f3Smrg resetReferencePictureDesc(&context->desc.h264, i); 1217ec681f3Smrg break; 1227ec681f3Smrg } 1237ec681f3Smrg 1247ec681f3Smrg vlVaGetReferenceFrame(drv, h264->ReferenceFrames[i].picture_id, &context->desc.h264.ref[i]); 1257ec681f3Smrg context->desc.h264.frame_num_list[i] = h264->ReferenceFrames[i].frame_idx; 1267ec681f3Smrg 1277ec681f3Smrg top_or_bottom_field = h264->ReferenceFrames[i].flags & 1287ec681f3Smrg (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD); 1297ec681f3Smrg context->desc.h264.is_long_term[i] = (h264->ReferenceFrames[i].flags & 1307ec681f3Smrg (VA_PICTURE_H264_SHORT_TERM_REFERENCE | 1317ec681f3Smrg VA_PICTURE_H264_LONG_TERM_REFERENCE)) != 1327ec681f3Smrg VA_PICTURE_H264_SHORT_TERM_REFERENCE; 1337ec681f3Smrg context->desc.h264.top_is_reference[i] = 1347ec681f3Smrg !context->desc.h264.is_long_term[i] || 1357ec681f3Smrg !!(h264->ReferenceFrames[i].flags & VA_PICTURE_H264_TOP_FIELD); 1367ec681f3Smrg context->desc.h264.bottom_is_reference[i] = 1377ec681f3Smrg !context->desc.h264.is_long_term[i] || 1387ec681f3Smrg !!(h264->ReferenceFrames[i].flags & VA_PICTURE_H264_BOTTOM_FIELD); 1397ec681f3Smrg context->desc.h264.field_order_cnt_list[i][0] = 1407ec681f3Smrg top_or_bottom_field != VA_PICTURE_H264_BOTTOM_FIELD ? 1417ec681f3Smrg h264->ReferenceFrames[i].TopFieldOrderCnt: INT_MAX; 1427ec681f3Smrg context->desc.h264.field_order_cnt_list[i][1] = 1437ec681f3Smrg top_or_bottom_field != VA_PICTURE_H264_TOP_FIELD ? 1447ec681f3Smrg h264->ReferenceFrames[i].BottomFieldOrderCnt: INT_MAX; 1457ec681f3Smrg } 1467ec681f3Smrg 1477ec681f3Smrg /* Make sure remaining elements are clean */ 1487ec681f3Smrg for (; i < 16; ++i) 1497ec681f3Smrg resetReferencePictureDesc(&context->desc.h264, i); 1507ec681f3Smrg} 1517ec681f3Smrg 1527ec681f3Smrgvoid vlVaHandleIQMatrixBufferH264(vlVaContext *context, vlVaBuffer *buf) 1537ec681f3Smrg{ 1547ec681f3Smrg VAIQMatrixBufferH264 *h264 = buf->data; 1557ec681f3Smrg 1567ec681f3Smrg assert(buf->size >= sizeof(VAIQMatrixBufferH264) && buf->num_elements == 1); 1577ec681f3Smrg memcpy(&context->desc.h264.pps->ScalingList4x4, h264->ScalingList4x4, 6 * 16); 1587ec681f3Smrg memcpy(&context->desc.h264.pps->ScalingList8x8, h264->ScalingList8x8, 2 * 64); 1597ec681f3Smrg} 1607ec681f3Smrg 1617ec681f3Smrgvoid vlVaHandleSliceParameterBufferH264(vlVaContext *context, vlVaBuffer *buf) 1627ec681f3Smrg{ 1637ec681f3Smrg VASliceParameterBufferH264 *h264 = buf->data; 1647ec681f3Smrg 1657ec681f3Smrg assert(buf->size >= sizeof(VASliceParameterBufferH264) && buf->num_elements == 1); 1667ec681f3Smrg context->desc.h264.slice_count += buf->num_elements; 1677ec681f3Smrg context->desc.h264.num_ref_idx_l0_active_minus1 = 1687ec681f3Smrg h264->num_ref_idx_l0_active_minus1; 1697ec681f3Smrg context->desc.h264.num_ref_idx_l1_active_minus1 = 1707ec681f3Smrg h264->num_ref_idx_l1_active_minus1; 1717ec681f3Smrg} 172