1 /*
2 * Copyright (c) 2018, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #include "test_data_encode.h"
23
24 using namespace std;
25
HevcEncBufs()26 HevcEncBufs::HevcEncBufs()
27 {
28 m_sps = make_shared<VAEncSequenceParameterBufferHEVC>();
29 memset(m_sps.get(), 0, sizeof(VAEncSequenceParameterBufferHEVC));
30
31 m_sps->general_profile_idc = 0x1;
32 m_sps->general_level_idc = 0x5a;
33 m_sps->intra_period = 0x5;
34 m_sps->intra_idr_period = 0xffffffff;
35 m_sps->ip_period = 0x2;
36 m_sps->bits_per_second = 0x190;
37 m_sps->pic_width_in_luma_samples = 0x140;
38 m_sps->pic_height_in_luma_samples = 0xf0;
39 m_sps->seq_fields.value = 0xc801;
40 m_sps->log2_diff_max_min_luma_coding_block_size = 0x2;
41 m_sps->log2_diff_max_min_transform_block_size = 0x3;
42 m_sps->max_transform_hierarchy_depth_inter = 0x2;
43 m_sps->max_transform_hierarchy_depth_intra = 0x2;
44 m_sps->pcm_sample_bit_depth_luma_minus1 = 0x7;
45 m_sps->pcm_sample_bit_depth_chroma_minus1 = 0x7;
46
47 m_pps = make_shared<VAEncPictureParameterBufferHEVC>();
48 memset(m_pps.get(), 0, sizeof(VAEncPictureParameterBufferHEVC));
49
50 m_slc = make_shared<VAEncSliceParameterBufferHEVC>();
51 memset(m_slc.get(), 0, sizeof(VAEncSliceParameterBufferHEVC));
52
53 for (auto i = 0; i < 15; i++)
54 {
55 m_pps->reference_frames[i].picture_id = 0xffffffff;
56 m_pps->reference_frames[i].flags = 0x1;
57 }
58
59 for (auto i = 0; i < 15; i++)
60 {
61 m_slc->ref_pic_list0[i].picture_id = 0xffffffff;
62 m_slc->ref_pic_list0[i].flags = 0x1;
63 m_slc->ref_pic_list1[i].picture_id = 0xffffffff;
64 m_slc->ref_pic_list1[i].flags = 0x1;
65 }
66
67 m_pps->column_width_minus1[0] = 0x9;
68 m_pps->row_height_minus1[0] = 0x7;
69 m_pps->pic_fields.value = 0x215;
70 m_pps->diff_cu_qp_delta_depth = 0x2;
71 m_slc->num_ctu_in_slice = 0x50;
72 m_slc->max_num_merge_cand = 0x5;
73 m_slc->slice_beta_offset_div2 = 0x2;
74 m_slc->slice_fields.value = 0x2010;
75 }
76
AvcEncBufs()77 AvcEncBufs::AvcEncBufs()
78 {
79 m_sps = make_shared<VAEncSequenceParameterBufferH264>();
80 memset(m_sps.get(), 0, sizeof(VAEncSequenceParameterBufferH264));
81
82 m_sps->level_idc = 0x33;
83 m_sps->intra_period = 0x1f;
84 m_sps->intra_idr_period = 0x3d;
85 m_sps->ip_period = 0x2;
86 m_sps->bits_per_second = 0x4c4b40;
87 m_sps->max_num_ref_frames = 0x10;
88 m_sps->picture_width_in_mbs = 0x14;
89 m_sps->picture_height_in_mbs = 0xf;
90 m_sps->seq_fields.value = 0x3105;
91
92 m_pps = make_shared<VAEncPictureParameterBufferH264>();
93 memset(m_pps.get(), 0, sizeof(VAEncPictureParameterBufferH264));
94
95 m_slc = make_shared<VAEncSliceParameterBufferH264>();
96 memset(m_slc.get(), 0, sizeof(VAEncSliceParameterBufferH264));
97
98 for (auto i = 0; i < 16; i++)
99 {
100 m_pps->ReferenceFrames[i].picture_id = 0xffffffff;
101 m_pps->ReferenceFrames[i].flags = 0x1;
102 }
103
104 for (auto i = 0; i < 32; i++)
105 {
106 m_slc->RefPicList0[i].picture_id = 0xffffffff;
107 m_slc->RefPicList0[i].flags = 0x1;
108 m_slc->RefPicList1[i].picture_id = 0xffffffff;
109 m_slc->RefPicList1[i].flags = 0x1;
110 }
111 m_slc->direct_spatial_mv_pred_flag = 0x1;
112 m_slc->num_ref_idx_active_override_flag = 0x1;
113 m_slc->cabac_init_idc = 0x1;
114 m_slc->slice_alpha_c0_offset_div2 = 0x2;
115 m_slc->slice_beta_offset_div2 = 0x2;
116 m_slc->num_macroblocks = 0x12c;
117 }
118
EncTestDataHEVC(FeatureID testFeatureID)119 EncTestDataHEVC::EncTestDataHEVC(FeatureID testFeatureID)
120 {
121 m_featureId = testFeatureID;
122 m_picWidth = 320;
123 m_picHeight = 240;
124 m_surfacesNum = 1+15 ; // 1 raw data, 8 references.
125
126 m_confAttrib.resize(1);
127 m_confAttrib[0].type = VAConfigAttribRateControl;
128 m_confAttrib[0].value = VA_RC_CQP;
129
130 m_surfAttrib.resize(1);
131 m_surfAttrib[0].type = VASurfaceAttribPixelFormat;
132 m_surfAttrib[0].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
133 m_surfAttrib[0].value.type = VAGenericValueTypePointer;
134 m_surfAttrib[0].value.value.i = VA_FOURCC_NV12;
135
136 m_resources.resize(m_surfacesNum);
137 InitCompBuffers();
138 vector<EncFrameDataHEVC> ¤tArray = m_frameArray;
139 m_num_frames = currentArray.size();
140 m_compBufs.resize(m_num_frames);
141
142 m_packedsps.type = VAEncPackedHeaderSequence;
143 m_packedsps.bit_length = 4 * 8;
144 m_packedsps.has_emulation_bytes = 0;
145 m_packedpps.type = VAEncPackedHeaderPicture;
146 m_packedpps.bit_length = 4 * 8;
147 m_packedpps.has_emulation_bytes = 0;
148 m_packedsh.type = VAEncPackedHeaderSlice;
149 m_packedsh.bit_length = 4 * 8;
150 m_packedsh.has_emulation_bytes = 0;
151
152 for (uint32_t i = 0; i < m_num_frames; i++)
153 {
154 m_compBufs[i].resize(12);
155 // BS buffer
156 m_compBufs[i][0] = { VAEncCodedBufferType , (m_picWidth * m_picHeight * 3) >> 1 , nullptr , 0 };
157 // Parameters buffer SPS, PPS, SliceHeader
158 m_compBufs[i][1] = { VAEncSequenceParameterBufferType , (uint32_t)currentArray[i].spsData.size() , ¤tArray[i].spsData[0] , 0 };
159 m_compBufs[i][2] = { VAEncPictureParameterBufferType , (uint32_t)currentArray[i].ppsData.size() , ¤tArray[i].ppsData[0] , 0 };
160 m_compBufs[i][3] = { VAEncSliceParameterBufferType , (uint32_t)currentArray[i].sliceData.size(), ¤tArray[i].sliceData[0], 0 };
161
162 // Packed VPS, SPS, PPS, SliceHeader, we fix all the data length as 4bytes.
163 m_compBufs[i][4] = { VAEncPackedHeaderParameterBufferType , (uint32_t)sizeof(m_packedsps) , (void *)&m_packedsps , 0 };
164 m_compBufs[i][5] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
165 m_compBufs[i][6] = { VAEncPackedHeaderParameterBufferType , (uint32_t)sizeof(m_packedsps) , (void *)&m_packedsps , 0 };
166 m_compBufs[i][7] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
167 m_compBufs[i][8] = { VAEncPackedHeaderParameterBufferType , (uint32_t)sizeof(m_packedpps) , (void *)&m_packedpps , 0 };
168 m_compBufs[i][9] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
169 m_compBufs[i][10] = { VAEncPackedHeaderParameterBufferType , (uint32_t)sizeof(m_packedsh) , (void *)&m_packedsh , 0 };
170 m_compBufs[i][11] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
171
172 }
173 }
174
InitCompBuffers()175 void EncTestDataHEVC::InitCompBuffers()
176 {
177 m_frameArray.resize(ENC_FRAME_NUM);
178 m_pBufs = make_shared<HevcEncBufs>();
179
180 for (auto i = 0; i < ENC_FRAME_NUM; i++)
181 {
182 m_frameArray[i].spsData.assign((char*)m_pBufs->GetSpsBuf() , (char*)m_pBufs->GetSpsBuf() + m_pBufs->GetSpsSize());
183 m_frameArray[i].ppsData.assign((char*)m_pBufs->GetPpsBuf() , (char*)m_pBufs->GetPpsBuf() + m_pBufs->GetPpsSize());
184 m_frameArray[i].sliceData.assign((char*)m_pBufs->GetSlcBuf(), (char*)m_pBufs->GetSlcBuf() + m_pBufs->GetSlcSize());
185 }
186 }
UpdateCompBuffers(int frameId)187 void EncTestDataHEVC::UpdateCompBuffers(int frameId)
188 {
189 VAEncPictureParameterBufferHEVC *pps = (VAEncPictureParameterBufferHEVC*)&m_frameArray[frameId].ppsData[0];
190 VAEncSliceParameterBufferHEVC *slc = (VAEncSliceParameterBufferHEVC*)&m_frameArray[frameId].sliceData[0];
191 pps->coded_buf = m_compBufs[frameId][0].bufID;
192 pps->decoded_curr_pic.picture_id = m_resources[frameId];
193
194 if (frameId == 0) // I frame
195 {
196 pps->decoded_curr_pic.pic_order_cnt = 0x0;
197 pps->pic_init_qp = 0xf;
198 slc->slice_type = 0x2;
199 }
200 else if (frameId == 1) // NoDelay B frame
201 {
202 pps->decoded_curr_pic.pic_order_cnt = 0x2;
203 pps->reference_frames[0].flags = 0x0;
204 pps->reference_frames[0].picture_id = m_resources[0];
205 pps->reference_frames[0].pic_order_cnt = 0x0;
206 pps->pic_init_qp = 0x19;
207 pps->pic_fields.value = 0x210;
208
209 slc->slice_type = 0x0;
210 slc->ref_pic_list0[0].picture_id = m_resources[0];
211 slc->ref_pic_list0[0].flags = 0x0;
212 slc->ref_pic_list0[0].pic_order_cnt = 0x0;
213 slc->ref_pic_list1[0].picture_id = m_resources[0];
214 slc->ref_pic_list1[0].flags = 0x0;
215 slc->ref_pic_list1[0].pic_order_cnt = 0x0;
216 }
217 else if (frameId == 2) // B frame
218 {
219 pps->decoded_curr_pic.pic_order_cnt = 0x1;
220 pps->reference_frames[0].flags = 0x0;
221 pps->reference_frames[0].picture_id = m_resources[0];
222 pps->reference_frames[0].pic_order_cnt = 0x0;
223 pps->reference_frames[1].flags = 0x0;
224 pps->reference_frames[1].picture_id = m_resources[1];
225 pps->reference_frames[1].pic_order_cnt = 0x2;
226 pps->pic_init_qp = 0x19;
227 pps->pic_fields.value = 0x200;
228 slc->slice_type = 0x0;
229 slc->ref_pic_list0[0].picture_id = m_resources[0];
230 slc->ref_pic_list0[0].flags = 0x0;
231 slc->ref_pic_list1[0].pic_order_cnt = 0x0;
232 slc->ref_pic_list1[0].picture_id = m_resources[1];
233 slc->ref_pic_list1[0].flags = 0x0;
234 slc->ref_pic_list1[0].pic_order_cnt = 0x2;
235 }
236 }
237
EncTestDataAVC(FeatureID testFeatureID)238 EncTestDataAVC::EncTestDataAVC(FeatureID testFeatureID)
239 {
240 m_featureId = testFeatureID;
241 m_picWidth = 320;
242 m_picHeight = 240;
243 m_surfacesNum = 1 + 15; // 1 raw data, 8 references.
244
245 m_confAttrib.resize(1);
246 m_confAttrib[0].type = VAConfigAttribRateControl;
247 m_confAttrib[0].value = VA_RC_CQP;
248
249 m_surfAttrib.resize(1);
250 m_surfAttrib[0].type = VASurfaceAttribPixelFormat;
251 m_surfAttrib[0].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
252 m_surfAttrib[0].value.type = VAGenericValueTypePointer;
253 m_surfAttrib[0].value.value.i = VA_FOURCC_NV12;
254
255 m_resources.resize(m_surfacesNum);
256 InitCompBuffers();
257 vector<EncFrameDataAVC> ¤tArray = m_frameArray;
258 m_num_frames = currentArray.size();
259 m_compBufs.resize(m_num_frames);
260
261 m_packedsps.type = VAEncPackedHeaderSequence;
262 m_packedsps.bit_length = 4 * 8;
263 m_packedsps.has_emulation_bytes = 0;
264 m_packedpps.type = VAEncPackedHeaderPicture;
265 m_packedpps.bit_length = 4 * 8;
266 m_packedpps.has_emulation_bytes = 0;
267 m_packedsh.type = VAEncPackedHeaderSlice;
268 m_packedsh.bit_length = 4 * 8;
269 m_packedsh.has_emulation_bytes = 0;
270
271 for (uint32_t i = 0; i < m_num_frames; i++)
272 {
273 m_compBufs[i].resize(12);
274 // BS buffer
275 m_compBufs[i][0] = { VAEncCodedBufferType , (m_picWidth * m_picHeight * 3) >> 1 , nullptr , 0 };
276 // Parameters buffer SPS, PPS, SliceHeader
277 m_compBufs[i][1] = { VAEncSequenceParameterBufferType , (uint32_t)currentArray[i].spsData.size() , ¤tArray[i].spsData[0] , 0 };
278 m_compBufs[i][2] = { VAEncPictureParameterBufferType , (uint32_t)currentArray[i].ppsData.size() , ¤tArray[i].ppsData[0] , 0 };
279 m_compBufs[i][3] = { VAEncSliceParameterBufferType , (uint32_t)currentArray[i].sliceData.size(), ¤tArray[i].sliceData[0], 0 };
280 // In fact, AVC doesn't need VPS, just add here for future improvement if we can merge it with HEVC.
281 // Packed VPS, SPS, PPS, SliceHeader, we fix all the data length as 4bytes.
282 m_compBufs[i][4] = { VAEncPackedHeaderParameterBufferType, (uint32_t)sizeof(m_packedsps) , (void *)&m_packedsps , 0 };
283 m_compBufs[i][5] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
284 m_compBufs[i][6] = { VAEncPackedHeaderParameterBufferType, (uint32_t)sizeof(m_packedsps) , (void *)&m_packedsps , 0 };
285 m_compBufs[i][7] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
286 m_compBufs[i][8] = { VAEncPackedHeaderParameterBufferType, (uint32_t)sizeof(m_packedpps) , (void *)&m_packedpps , 0 };
287 m_compBufs[i][9] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
288 m_compBufs[i][10] = { VAEncPackedHeaderParameterBufferType, (uint32_t)sizeof(m_packedsh) , (void *)&m_packedsh , 0 };
289 m_compBufs[i][11] = { VAEncPackedHeaderDataBufferType , 4 , (void *)&m_headerData[0] , 0 };
290 }
291 }
292
InitCompBuffers()293 void EncTestDataAVC::InitCompBuffers()
294 {
295 m_frameArray.resize(3);
296 m_pBufs = make_shared<AvcEncBufs>();
297
298 for (auto i = 0; i < ENC_FRAME_NUM; i++)
299 {
300 m_frameArray[i].spsData.assign((char*)m_pBufs->GetSpsBuf() , (char*)m_pBufs->GetSpsBuf() + m_pBufs->GetSpsSize());
301 m_frameArray[i].ppsData.assign((char*)m_pBufs->GetPpsBuf() , (char*)m_pBufs->GetPpsBuf() + m_pBufs->GetPpsSize());
302 m_frameArray[i].sliceData.assign((char*)m_pBufs->GetSlcBuf(), (char*)m_pBufs->GetSlcBuf() + m_pBufs->GetSlcSize());
303 }
304 }
305
UpdateCompBuffers(int frameId)306 void EncTestDataAVC::UpdateCompBuffers(int frameId)
307 {
308 VAEncPictureParameterBufferH264 *pps = (VAEncPictureParameterBufferH264*)&m_frameArray[frameId].ppsData[0];
309 VAEncSliceParameterBufferH264 *slc = (VAEncSliceParameterBufferH264*)&m_frameArray[frameId].sliceData[0];
310 pps->coded_buf = m_compBufs[frameId][0].bufID;
311 pps->CurrPic.picture_id = m_resources[frameId];
312
313 if (frameId==0)
314 {
315 pps->CurrPic.BottomFieldOrderCnt = 0x1;
316 pps->pic_init_qp = 0x1c;
317 pps->pic_fields.value = 0x30b;
318 slc->slice_type = 0x7;
319 }
320 else if (frameId == 1)
321 {
322 pps->CurrPic.frame_idx = 0x1;
323 pps->CurrPic.TopFieldOrderCnt = 0x4;
324 pps->CurrPic.BottomFieldOrderCnt = 0x5;
325 pps->ReferenceFrames[0].picture_id = m_resources[0];
326 pps->ReferenceFrames[0].flags = 0x8;
327 pps->ReferenceFrames[0].TopFieldOrderCnt = 0x0;
328 pps->ReferenceFrames[0].BottomFieldOrderCnt = 0x1;
329 pps->frame_num = 0x1;
330 pps->pic_fields.value = 0x30a;
331 slc->idr_pic_id = 0x1;
332 slc->slice_type = 0x0;
333 slc->pic_order_cnt_lsb = 0x4;
334 slc->RefPicList0[0].picture_id = m_resources[0];
335 slc->RefPicList0[0].flags = 0x8;
336 slc->RefPicList0[0].TopFieldOrderCnt = 0x0;
337 slc->RefPicList0[0].BottomFieldOrderCnt = 0x1;
338 }
339 else if (frameId == 2)
340 {
341 pps->CurrPic.frame_idx = 0x1;
342 pps->CurrPic.TopFieldOrderCnt = 0x2;
343 pps->CurrPic.BottomFieldOrderCnt = 0x3;
344 pps->ReferenceFrames[0].picture_id = m_resources[0];
345 pps->ReferenceFrames[0].flags = 0x8;
346 pps->ReferenceFrames[0].TopFieldOrderCnt = 0x0;
347 pps->ReferenceFrames[0].BottomFieldOrderCnt = 0x1;
348 pps->ReferenceFrames[1].picture_id = m_resources[1];
349 pps->ReferenceFrames[1].frame_idx = 0x1;
350 pps->ReferenceFrames[1].flags = 0x8;
351 pps->ReferenceFrames[1].TopFieldOrderCnt = 0x4;
352 pps->ReferenceFrames[1].BottomFieldOrderCnt = 0x5;
353 pps->frame_num = 0x1;
354 pps->pic_fields.value = 0x308;
355 slc->slice_type = 0x1;
356 slc->idr_pic_id = 0x1;
357 slc->pic_order_cnt_lsb = 0x2;
358 slc->RefPicList0[0].picture_id = m_resources[0];
359 slc->RefPicList0[0].flags = 0x8;
360 slc->RefPicList0[0].TopFieldOrderCnt = 0x0;
361 slc->RefPicList0[0].BottomFieldOrderCnt = 0x1;
362 slc->RefPicList1[0].picture_id = m_resources[1];
363 slc->RefPicList1[0].frame_idx = 0x1;
364 slc->RefPicList1[0].flags = 0x8;
365 slc->RefPicList1[0].TopFieldOrderCnt = 0x4;
366 slc->RefPicList1[0].BottomFieldOrderCnt = 0x5;
367 }
368 }
369