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