1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2014 Advanced Micro Devices, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "vl/vl_zscan.h" 29bf215546Sopenharmony_ci#include "va_private.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_civoid vlVaHandlePictureParameterBufferHEVC(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf) 32bf215546Sopenharmony_ci{ 33bf215546Sopenharmony_ci VAPictureParameterBufferHEVC *hevc = buf->data; 34bf215546Sopenharmony_ci unsigned i; 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci assert(buf->size >= sizeof(VAPictureParameterBufferHEVC) && buf->num_elements == 1); 37bf215546Sopenharmony_ci context->desc.h265.pps->sps->chroma_format_idc = hevc->pic_fields.bits.chroma_format_idc; 38bf215546Sopenharmony_ci context->desc.h265.pps->sps->separate_colour_plane_flag = 39bf215546Sopenharmony_ci hevc->pic_fields.bits.separate_colour_plane_flag; 40bf215546Sopenharmony_ci context->desc.h265.pps->sps->pic_width_in_luma_samples = hevc->pic_width_in_luma_samples; 41bf215546Sopenharmony_ci context->desc.h265.pps->sps->pic_height_in_luma_samples = hevc->pic_height_in_luma_samples; 42bf215546Sopenharmony_ci context->desc.h265.pps->sps->bit_depth_luma_minus8 = hevc->bit_depth_luma_minus8; 43bf215546Sopenharmony_ci context->desc.h265.pps->sps->bit_depth_chroma_minus8 = hevc->bit_depth_chroma_minus8; 44bf215546Sopenharmony_ci context->desc.h265.pps->sps->log2_max_pic_order_cnt_lsb_minus4 = 45bf215546Sopenharmony_ci hevc->log2_max_pic_order_cnt_lsb_minus4; 46bf215546Sopenharmony_ci context->desc.h265.pps->sps->sps_max_dec_pic_buffering_minus1 = 47bf215546Sopenharmony_ci hevc->sps_max_dec_pic_buffering_minus1; 48bf215546Sopenharmony_ci context->desc.h265.pps->sps->log2_min_luma_coding_block_size_minus3 = 49bf215546Sopenharmony_ci hevc->log2_min_luma_coding_block_size_minus3; 50bf215546Sopenharmony_ci context->desc.h265.pps->sps->log2_diff_max_min_luma_coding_block_size = 51bf215546Sopenharmony_ci hevc->log2_diff_max_min_luma_coding_block_size; 52bf215546Sopenharmony_ci context->desc.h265.pps->sps->log2_min_transform_block_size_minus2 = 53bf215546Sopenharmony_ci hevc->log2_min_transform_block_size_minus2; 54bf215546Sopenharmony_ci context->desc.h265.pps->sps->log2_diff_max_min_transform_block_size = 55bf215546Sopenharmony_ci hevc->log2_diff_max_min_transform_block_size; 56bf215546Sopenharmony_ci context->desc.h265.pps->sps->max_transform_hierarchy_depth_inter = 57bf215546Sopenharmony_ci hevc->max_transform_hierarchy_depth_inter; 58bf215546Sopenharmony_ci context->desc.h265.pps->sps->max_transform_hierarchy_depth_intra = 59bf215546Sopenharmony_ci hevc->max_transform_hierarchy_depth_intra; 60bf215546Sopenharmony_ci context->desc.h265.pps->sps->scaling_list_enabled_flag = 61bf215546Sopenharmony_ci hevc->pic_fields.bits.scaling_list_enabled_flag; 62bf215546Sopenharmony_ci context->desc.h265.pps->sps->amp_enabled_flag = hevc->pic_fields.bits.amp_enabled_flag; 63bf215546Sopenharmony_ci context->desc.h265.pps->sps->sample_adaptive_offset_enabled_flag = 64bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.sample_adaptive_offset_enabled_flag; 65bf215546Sopenharmony_ci context->desc.h265.pps->sps->pcm_enabled_flag = hevc->pic_fields.bits.pcm_enabled_flag; 66bf215546Sopenharmony_ci if (hevc->pic_fields.bits.pcm_enabled_flag == 1) { 67bf215546Sopenharmony_ci context->desc.h265.pps->sps->pcm_sample_bit_depth_luma_minus1 = 68bf215546Sopenharmony_ci hevc->pcm_sample_bit_depth_luma_minus1; 69bf215546Sopenharmony_ci context->desc.h265.pps->sps->pcm_sample_bit_depth_chroma_minus1 = 70bf215546Sopenharmony_ci hevc->pcm_sample_bit_depth_chroma_minus1; 71bf215546Sopenharmony_ci context->desc.h265.pps->sps->log2_min_pcm_luma_coding_block_size_minus3 = 72bf215546Sopenharmony_ci hevc->log2_min_pcm_luma_coding_block_size_minus3; 73bf215546Sopenharmony_ci context->desc.h265.pps->sps->log2_diff_max_min_pcm_luma_coding_block_size = 74bf215546Sopenharmony_ci hevc->log2_diff_max_min_pcm_luma_coding_block_size; 75bf215546Sopenharmony_ci context->desc.h265.pps->sps->pcm_loop_filter_disabled_flag = 76bf215546Sopenharmony_ci hevc->pic_fields.bits.pcm_loop_filter_disabled_flag; 77bf215546Sopenharmony_ci } 78bf215546Sopenharmony_ci context->desc.h265.pps->sps->num_short_term_ref_pic_sets = hevc->num_short_term_ref_pic_sets; 79bf215546Sopenharmony_ci context->desc.h265.pps->sps->long_term_ref_pics_present_flag = 80bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.long_term_ref_pics_present_flag; 81bf215546Sopenharmony_ci context->desc.h265.pps->sps->num_long_term_ref_pics_sps = hevc->num_long_term_ref_pic_sps; 82bf215546Sopenharmony_ci context->desc.h265.pps->sps->sps_temporal_mvp_enabled_flag = 83bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.sps_temporal_mvp_enabled_flag; 84bf215546Sopenharmony_ci context->desc.h265.pps->sps->strong_intra_smoothing_enabled_flag = 85bf215546Sopenharmony_ci hevc->pic_fields.bits.strong_intra_smoothing_enabled_flag; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci context->desc.h265.pps->dependent_slice_segments_enabled_flag = 88bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.dependent_slice_segments_enabled_flag; 89bf215546Sopenharmony_ci context->desc.h265.pps->output_flag_present_flag = 90bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.output_flag_present_flag; 91bf215546Sopenharmony_ci context->desc.h265.pps->num_extra_slice_header_bits = hevc->num_extra_slice_header_bits; 92bf215546Sopenharmony_ci context->desc.h265.pps->sign_data_hiding_enabled_flag = 93bf215546Sopenharmony_ci hevc->pic_fields.bits.sign_data_hiding_enabled_flag; 94bf215546Sopenharmony_ci context->desc.h265.pps->cabac_init_present_flag = 95bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.cabac_init_present_flag; 96bf215546Sopenharmony_ci context->desc.h265.pps->num_ref_idx_l0_default_active_minus1 = 97bf215546Sopenharmony_ci hevc->num_ref_idx_l0_default_active_minus1; 98bf215546Sopenharmony_ci context->desc.h265.pps->num_ref_idx_l1_default_active_minus1 = 99bf215546Sopenharmony_ci hevc->num_ref_idx_l1_default_active_minus1; 100bf215546Sopenharmony_ci context->desc.h265.pps->init_qp_minus26 = hevc->init_qp_minus26; 101bf215546Sopenharmony_ci context->desc.h265.pps->constrained_intra_pred_flag = 102bf215546Sopenharmony_ci hevc->pic_fields.bits.constrained_intra_pred_flag; 103bf215546Sopenharmony_ci context->desc.h265.pps->transform_skip_enabled_flag = 104bf215546Sopenharmony_ci hevc->pic_fields.bits.transform_skip_enabled_flag; 105bf215546Sopenharmony_ci context->desc.h265.pps->cu_qp_delta_enabled_flag = 106bf215546Sopenharmony_ci hevc->pic_fields.bits.cu_qp_delta_enabled_flag; 107bf215546Sopenharmony_ci context->desc.h265.pps->diff_cu_qp_delta_depth = hevc->diff_cu_qp_delta_depth; 108bf215546Sopenharmony_ci context->desc.h265.pps->pps_cb_qp_offset = hevc->pps_cb_qp_offset; 109bf215546Sopenharmony_ci context->desc.h265.pps->pps_cr_qp_offset = hevc->pps_cr_qp_offset; 110bf215546Sopenharmony_ci context->desc.h265.pps->pps_slice_chroma_qp_offsets_present_flag = 111bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.pps_slice_chroma_qp_offsets_present_flag; 112bf215546Sopenharmony_ci context->desc.h265.pps->weighted_pred_flag = hevc->pic_fields.bits.weighted_pred_flag; 113bf215546Sopenharmony_ci context->desc.h265.pps->weighted_bipred_flag = hevc->pic_fields.bits.weighted_bipred_flag; 114bf215546Sopenharmony_ci context->desc.h265.pps->transquant_bypass_enabled_flag = 115bf215546Sopenharmony_ci hevc->pic_fields.bits.transquant_bypass_enabled_flag; 116bf215546Sopenharmony_ci context->desc.h265.pps->tiles_enabled_flag = hevc->pic_fields.bits.tiles_enabled_flag; 117bf215546Sopenharmony_ci context->desc.h265.pps->entropy_coding_sync_enabled_flag = 118bf215546Sopenharmony_ci hevc->pic_fields.bits.entropy_coding_sync_enabled_flag; 119bf215546Sopenharmony_ci if (hevc->pic_fields.bits.tiles_enabled_flag == 1) { 120bf215546Sopenharmony_ci context->desc.h265.pps->num_tile_columns_minus1 = hevc->num_tile_columns_minus1; 121bf215546Sopenharmony_ci context->desc.h265.pps->num_tile_rows_minus1 = hevc->num_tile_rows_minus1; 122bf215546Sopenharmony_ci for (i = 0 ; i < 19 ; i++) 123bf215546Sopenharmony_ci context->desc.h265.pps->column_width_minus1[i] = hevc->column_width_minus1[i]; 124bf215546Sopenharmony_ci for (i = 0 ; i < 21 ; i++) 125bf215546Sopenharmony_ci context->desc.h265.pps->row_height_minus1[i] = hevc->row_height_minus1[i]; 126bf215546Sopenharmony_ci context->desc.h265.pps->loop_filter_across_tiles_enabled_flag = 127bf215546Sopenharmony_ci hevc->pic_fields.bits.loop_filter_across_tiles_enabled_flag; 128bf215546Sopenharmony_ci } 129bf215546Sopenharmony_ci context->desc.h265.pps->pps_loop_filter_across_slices_enabled_flag = 130bf215546Sopenharmony_ci hevc->pic_fields.bits.pps_loop_filter_across_slices_enabled_flag; 131bf215546Sopenharmony_ci context->desc.h265.pps->deblocking_filter_override_enabled_flag = 132bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.deblocking_filter_override_enabled_flag; 133bf215546Sopenharmony_ci context->desc.h265.pps->pps_deblocking_filter_disabled_flag = 134bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.pps_disable_deblocking_filter_flag; 135bf215546Sopenharmony_ci context->desc.h265.pps->pps_beta_offset_div2 = hevc->pps_beta_offset_div2; 136bf215546Sopenharmony_ci context->desc.h265.pps->pps_tc_offset_div2 = hevc->pps_tc_offset_div2; 137bf215546Sopenharmony_ci context->desc.h265.pps->lists_modification_present_flag = 138bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.lists_modification_present_flag; 139bf215546Sopenharmony_ci context->desc.h265.pps->log2_parallel_merge_level_minus2 = 140bf215546Sopenharmony_ci hevc->log2_parallel_merge_level_minus2; 141bf215546Sopenharmony_ci context->desc.h265.pps->slice_segment_header_extension_present_flag = 142bf215546Sopenharmony_ci hevc->slice_parsing_fields.bits.slice_segment_header_extension_present_flag; 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci context->desc.h265.IDRPicFlag = hevc->slice_parsing_fields.bits.IdrPicFlag; 145bf215546Sopenharmony_ci context->desc.h265.RAPPicFlag = hevc->slice_parsing_fields.bits.RapPicFlag; 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci context->desc.h265.CurrPicOrderCntVal = hevc->CurrPic.pic_order_cnt; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci for (i = 0 ; i < 8 ; i++) { 150bf215546Sopenharmony_ci context->desc.h265.RefPicSetStCurrBefore[i] = 0xFF; 151bf215546Sopenharmony_ci context->desc.h265.RefPicSetStCurrAfter[i] = 0xFF; 152bf215546Sopenharmony_ci context->desc.h265.RefPicSetLtCurr[i] = 0xFF; 153bf215546Sopenharmony_ci } 154bf215546Sopenharmony_ci context->desc.h265.NumPocStCurrBefore = 0; 155bf215546Sopenharmony_ci context->desc.h265.NumPocStCurrAfter = 0; 156bf215546Sopenharmony_ci context->desc.h265.NumPocLtCurr = 0; 157bf215546Sopenharmony_ci unsigned int iBefore = 0; 158bf215546Sopenharmony_ci unsigned int iAfter = 0; 159bf215546Sopenharmony_ci unsigned int iCurr = 0; 160bf215546Sopenharmony_ci for (i = 0 ; i < 15 ; i++) { 161bf215546Sopenharmony_ci context->desc.h265.PicOrderCntVal[i] = hevc->ReferenceFrames[i].pic_order_cnt; 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci vlVaGetReferenceFrame(drv, hevc->ReferenceFrames[i].picture_id, &context->desc.h265.ref[i]); 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci if ((hevc->ReferenceFrames[i].flags & VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE) && (iBefore < 8)) { 166bf215546Sopenharmony_ci context->desc.h265.RefPicSetStCurrBefore[iBefore++] = i; 167bf215546Sopenharmony_ci context->desc.h265.NumPocStCurrBefore++; 168bf215546Sopenharmony_ci } 169bf215546Sopenharmony_ci if ((hevc->ReferenceFrames[i].flags & VA_PICTURE_HEVC_RPS_ST_CURR_AFTER) && (iAfter < 8)) { 170bf215546Sopenharmony_ci context->desc.h265.RefPicSetStCurrAfter[iAfter++] = i; 171bf215546Sopenharmony_ci context->desc.h265.NumPocStCurrAfter++; 172bf215546Sopenharmony_ci } 173bf215546Sopenharmony_ci if ((hevc->ReferenceFrames[i].flags & VA_PICTURE_HEVC_RPS_LT_CURR) && (iCurr < 8)) { 174bf215546Sopenharmony_ci context->desc.h265.RefPicSetLtCurr[iCurr++] = i; 175bf215546Sopenharmony_ci context->desc.h265.NumPocLtCurr++; 176bf215546Sopenharmony_ci } 177bf215546Sopenharmony_ci } 178bf215546Sopenharmony_ci context->desc.h265.pps->st_rps_bits = hevc->st_rps_bits; 179bf215546Sopenharmony_ci context->desc.h265.UseStRpsBits = true; 180bf215546Sopenharmony_ci} 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_civoid vlVaHandleIQMatrixBufferHEVC(vlVaContext *context, vlVaBuffer *buf) 183bf215546Sopenharmony_ci{ 184bf215546Sopenharmony_ci VAIQMatrixBufferHEVC *h265 = buf->data; 185bf215546Sopenharmony_ci int i, j; 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci assert(buf->size >= sizeof(VAIQMatrixBufferHEVC) && buf->num_elements == 1); 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci for (i = 0; i < 6; i++) { 190bf215546Sopenharmony_ci for (j = 0; j < 16; j++) 191bf215546Sopenharmony_ci context->desc.h265.pps->sps->ScalingList4x4[i][j] = 192bf215546Sopenharmony_ci h265->ScalingList4x4[i][vl_zscan_h265_up_right_diagonal_16[j]]; 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci for (j = 0; j < 64; j++) { 195bf215546Sopenharmony_ci context->desc.h265.pps->sps->ScalingList8x8[i][j] = 196bf215546Sopenharmony_ci h265->ScalingList8x8[i][vl_zscan_h265_up_right_diagonal[j]]; 197bf215546Sopenharmony_ci context->desc.h265.pps->sps->ScalingList16x16[i][j] = 198bf215546Sopenharmony_ci h265->ScalingList16x16[i][vl_zscan_h265_up_right_diagonal[j]]; 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci if (i < 2) 201bf215546Sopenharmony_ci context->desc.h265.pps->sps->ScalingList32x32[i][j] = 202bf215546Sopenharmony_ci h265->ScalingList32x32[i][vl_zscan_h265_up_right_diagonal[j]]; 203bf215546Sopenharmony_ci } 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_ci context->desc.h265.pps->sps->ScalingListDCCoeff16x16[i] = 206bf215546Sopenharmony_ci h265->ScalingListDC16x16[i]; 207bf215546Sopenharmony_ci if (i < 2) 208bf215546Sopenharmony_ci context->desc.h265.pps->sps->ScalingListDCCoeff32x32[i] = 209bf215546Sopenharmony_ci h265->ScalingListDC32x32[i]; 210bf215546Sopenharmony_ci } 211bf215546Sopenharmony_ci} 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_civoid vlVaHandleSliceParameterBufferHEVC(vlVaContext *context, vlVaBuffer *buf) 214bf215546Sopenharmony_ci{ 215bf215546Sopenharmony_ci VASliceParameterBufferHEVC *h265 = buf->data; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci assert(buf->size >= sizeof(VASliceParameterBufferHEVC) && buf->num_elements == 1); 218bf215546Sopenharmony_ci for (int i = 0 ; i < 2 ; i++) { 219bf215546Sopenharmony_ci for (int j = 0 ; j < 15 ; j++) 220bf215546Sopenharmony_ci context->desc.h265.RefPicList[i][j] = h265->RefPicList[i][j]; 221bf215546Sopenharmony_ci } 222bf215546Sopenharmony_ci context->desc.h265.UseRefPicList = true; 223bf215546Sopenharmony_ci} 224