| 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_decode.h" |
| 23 |
|
| 24 |
using namespace std; |
| 25 |
|
| 26 |
DecBufHEVC::DecBufHEVC() |
| 27 |
{ |
| 28 |
m_pps = make_shared<VAPictureParameterBufferHEVC>(); |
| 29 |
memset(m_pps.get(), 0, sizeof(VAPictureParameterBufferHEVC)); |
| 30 |
|
| 31 |
for (auto i = 0; i < 15; i++) |
| 32 |
{ |
| 33 |
m_pps->ReferenceFrames[i].picture_id = 0xffffffff; |
| 34 |
m_pps->ReferenceFrames[i].flags = 0x1; |
| 35 |
} |
| 36 |
m_pps->pic_width_in_luma_samples = 0x40; |
| 37 |
m_pps->pic_height_in_luma_samples = 0x40; |
| 38 |
m_pps->pic_fields.value = 0x20441; |
| 39 |
m_pps->sps_max_dec_pic_buffering_minus1 = 0x3; |
| 40 |
m_pps->pcm_sample_bit_depth_luma_minus1 = 0xff; |
| 41 |
m_pps->pcm_sample_bit_depth_chroma_minus1 = 0xff; |
| 42 |
m_pps->log2_diff_max_min_luma_coding_block_size = 0x2; |
| 43 |
m_pps->log2_diff_max_min_transform_block_size = 0x3; |
| 44 |
m_pps->log2_min_pcm_luma_coding_block_size_minus3 = 0xfd; |
| 45 |
m_pps->max_transform_hierarchy_depth_intra = 0x2; |
| 46 |
m_pps->max_transform_hierarchy_depth_inter = 0x2; |
| 47 |
m_pps->slice_parsing_fields.value = 0x3907; |
| 48 |
m_pps->log2_max_pic_order_cnt_lsb_minus4 = 0x2; |
| 49 |
m_pps->num_short_term_ref_pic_sets = 0x4; |
| 50 |
m_pps->num_ref_idx_l0_default_active_minus1 = 0x2; |
| 51 |
|
| 52 |
m_slc = make_shared<VASliceParameterBufferHEVC>(); |
| 53 |
memset(m_slc.get(), 0, sizeof(VASliceParameterBufferHEVC)); |
| 54 |
|
| 55 |
m_slc->slice_data_size = 0x10; |
| 56 |
m_slc->slice_data_byte_offset = 0x7; |
| 57 |
for (auto i = 0; i < 15; i++) |
| 58 |
{ |
| 59 |
m_slc->RefPicList[0][i] = 0xff; |
| 60 |
m_slc->RefPicList[1][i] = 0xff; |
| 61 |
} |
| 62 |
m_slc->LongSliceFlags.value = 0x1009; |
| 63 |
m_slc->collocated_ref_idx = 0xff; |
| 64 |
m_slc->num_ref_idx_l0_active_minus1 = 0xff; |
| 65 |
m_slc->num_ref_idx_l1_active_minus1 = 0xff; |
| 66 |
m_slc->five_minus_max_num_merge_cand = 0x5; |
| 67 |
|
| 68 |
m_bitstream.assign({ |
| 69 |
0x00, 0x00, 0x01, 0x26, 0x01, 0xaf, 0x1d, 0x80, 0xa3, 0xf3, 0xe6, 0x0b, 0x57, 0xd0, 0x9f, 0xf9}); |
| 70 |
} |
| 71 |
|
| 72 |
DecBufAVC::DecBufAVC() |
| 73 |
{ |
| 74 |
m_pps = make_shared<VAPictureParameterBufferH264>(); |
| 75 |
memset(m_pps.get(), 0, sizeof(VAPictureParameterBufferH264)); |
| 76 |
|
| 77 |
m_pps->CurrPic.flags = 0x8; |
| 78 |
for (auto i = 0; i < 16; i++) |
| 79 |
{ |
| 80 |
m_pps->ReferenceFrames[i].picture_id = 0xffffffff; |
| 81 |
m_pps->ReferenceFrames[i].flags = 0x1; |
| 82 |
} |
| 83 |
m_pps->picture_width_in_mbs_minus1 = 0x27; |
| 84 |
m_pps->picture_height_in_mbs_minus1 = 0x1d; |
| 85 |
m_pps->num_ref_frames = 0x2; |
| 86 |
m_pps->seq_fields.value = 0x451; |
| 87 |
m_pps->pic_fields.value = 0x519; |
| 88 |
|
| 89 |
m_slc = make_shared<VASliceParameterBufferH264>(); |
| 90 |
memset(m_slc.get(), 0, sizeof(VASliceParameterBufferH264)); |
| 91 |
|
| 92 |
m_slc->slice_data_size = 0x10; |
| 93 |
m_slc->slice_data_bit_offset = 0x24; |
| 94 |
m_slc->slice_type = 0x2; |
| 95 |
for (auto i = 0; i < 32; i++) |
| 96 |
{ |
| 97 |
m_slc->RefPicList0[i].picture_id = 0xffffffff; |
| 98 |
m_slc->RefPicList0[i].flags = 0x1; |
| 99 |
m_slc->RefPicList1[i].picture_id = 0xffffffff; |
| 100 |
m_slc->RefPicList1[i].flags = 0x1; |
| 101 |
} |
| 102 |
|
| 103 |
m_bitstream.assign({ |
| 104 |
0x00, 0x00, 0x01, 0x02, 0x01, 0xd0, 0x11, 0xff, 0xd4, 0x43, 0x02, 0x0e, 0x40, 0x92, 0xf9, 0x84}); |
| 105 |
} |
| 106 |
|
| 107 |
DecTestDataHEVC::DecTestDataHEVC(FeatureID testFeatureID, bool bInShortFormat) |
| 108 |
{ |
| 109 |
m_bShortFormat = bInShortFormat; |
| 110 |
m_picWidth = 64; |
| 111 |
m_picHeight = 64; |
| 112 |
m_surfacesNum = 32; |
| 113 |
m_featureId = testFeatureID; |
| 114 |
|
| 115 |
m_confAttrib.resize(1); |
| 116 |
m_confAttrib[0].type = VAConfigAttribDecSliceMode; |
| 117 |
m_confAttrib[0].value = (m_bShortFormat) ? VA_DEC_SLICE_MODE_BASE:VA_DEC_SLICE_MODE_NORMAL; |
| 118 |
|
| 119 |
m_resources.resize(m_surfacesNum); |
| 120 |
InitCompBuffers(); |
| 121 |
|
| 122 |
vector<DecFrameDataHEVC> ¤tArray = (m_bShortFormat) ? m_frameArray : m_frameArrayLong; |
| 123 |
m_num_frames = currentArray.size(); |
| 124 |
|
| 125 |
m_compBufs.resize(m_num_frames); |
| 126 |
for (uint32_t i = 0; i < m_num_frames; i++) // Set for each frame |
| 127 |
{ |
| 128 |
m_compBufs[i].resize(3); |
| 129 |
// Need one Picture Parameters for all the slices. |
| 130 |
m_compBufs[i][0] = { VAPictureParameterBufferType, (uint32_t)currentArray[i].picParam.size(), ¤tArray[i].picParam[0], 0 }; |
| 131 |
// Due to driver limiation, we just send all the slice data in one buffer. |
| 132 |
m_compBufs[i][1] = { VASliceParameterBufferType , (uint32_t)currentArray[i].slcParam.size(), ¤tArray[i].slcParam[0], 0 }; |
| 133 |
m_compBufs[i][2] = { VASliceDataBufferType , (uint32_t)currentArray[i].bsData.size() , ¤tArray[i].bsData[0] , 0 }; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
DecTestDataAVC::DecTestDataAVC(FeatureID testFeatureID, bool bInShortFormat) |
| 138 |
{ |
| 139 |
m_bShortFormat = bInShortFormat; |
| 140 |
m_picWidth = 64; |
| 141 |
m_picHeight = 64; |
| 142 |
m_surfacesNum = 32; |
| 143 |
m_featureId = testFeatureID; |
| 144 |
|
| 145 |
m_confAttrib.resize(1); |
| 146 |
m_confAttrib[0].type = VAConfigAttribDecSliceMode; |
| 147 |
m_confAttrib[0].value = (m_bShortFormat) ? VA_DEC_SLICE_MODE_BASE:VA_DEC_SLICE_MODE_NORMAL; |
| 148 |
|
| 149 |
m_resources.resize(m_surfacesNum); |
| 150 |
InitCompBuffers(); |
| 151 |
|
| 152 |
vector<DecFrameDataAVC> ¤tArray = m_bShortFormat ? m_frameArray : m_frameArrayLong; |
| 153 |
m_num_frames = currentArray.size(); |
| 154 |
|
| 155 |
m_compBufs.resize(m_num_frames); |
| 156 |
for (uint32_t i = 0; i < m_num_frames; i++) // Set for each frame |
| 157 |
{ |
| 158 |
m_compBufs[i].resize(3); |
| 159 |
// Need one Picture Parameters for all the slices. |
| 160 |
m_compBufs[i][0] = { VAPictureParameterBufferType, (uint32_t)currentArray[i].picParam.size(), ¤tArray[i].picParam[0], 0 }; |
| 161 |
// Due to driver limiation, we just send all the slice data in one buffer. |
| 162 |
m_compBufs[i][1] = { VASliceParameterBufferType , (uint32_t)currentArray[i].slcParam.size(), ¤tArray[i].slcParam[0], 0 }; |
| 163 |
m_compBufs[i][2] = { VASliceDataBufferType , (uint32_t)currentArray[i].bsData.size() , ¤tArray[i].bsData[0] , 0 }; |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
void DecTestDataHEVC::InitCompBuffers() |
| 168 |
{ |
| 169 |
m_frameArrayLong.resize(DEC_FRAME_NUM); |
| 170 |
m_pBufs = make_shared<DecBufHEVC>(); |
| 171 |
for (auto i = 0; i < DEC_FRAME_NUM; i++) |
| 172 |
{ |
| 173 |
m_frameArrayLong[i].picParam.assign((char*)m_pBufs->GetPpsBuf(), (char*)m_pBufs->GetPpsBuf() + m_pBufs->GetPpsSize()); |
| 174 |
m_frameArrayLong[i].slcParam.assign((char*)m_pBufs->GetSlcBuf(), (char*)m_pBufs->GetSlcBuf() + m_pBufs->GetSlcSize()); |
| 175 |
m_frameArrayLong[i].bsData.assign((char*)m_pBufs->GetBsBuf() , (char*)m_pBufs->GetBsBuf() + m_pBufs->GetBsSize()); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
void DecTestDataAVC::InitCompBuffers() |
| 180 |
{ |
| 181 |
m_frameArrayLong.resize(DEC_FRAME_NUM); |
| 182 |
m_pBufs = make_shared<DecBufAVC>(); |
| 183 |
for (auto i = 0; i < DEC_FRAME_NUM; i++) |
| 184 |
{ |
| 185 |
m_frameArrayLong[i].picParam.assign((char*)m_pBufs->GetPpsBuf(), (char*)m_pBufs->GetPpsBuf() + m_pBufs->GetPpsSize()); |
| 186 |
m_frameArrayLong[i].slcParam.assign((char*)m_pBufs->GetSlcBuf(), (char*)m_pBufs->GetSlcBuf() + m_pBufs->GetSlcSize()); |
| 187 |
m_frameArrayLong[i].bsData.assign((char*)m_pBufs->GetBsBuf() , (char*)m_pBufs->GetBsBuf() + m_pBufs->GetBsSize()); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
void DecTestDataHEVC::UpdateCompBuffers(int frameId) |
| 192 |
{ |
| 193 |
auto ¤tArray = (m_bShortFormat) ? m_frameArray : m_frameArrayLong; |
| 194 |
auto *pps = (VAPictureParameterBufferHEVC *)¤tArray[frameId].picParam[0]; |
| 195 |
auto *slc = (VASliceParameterBufferHEVC *)¤tArray[frameId].slcParam[0]; |
| 196 |
auto &bitstream = currentArray[frameId].bsData; |
| 197 |
|
| 198 |
pps->CurrPic.picture_id = m_resources[frameId]; |
| 199 |
switch (frameId) |
| 200 |
{ |
| 201 |
case 1: |
| 202 |
pps->ReferenceFrames[0].picture_id = m_resources[0]; |
| 203 |
pps->CurrPic.pic_order_cnt = 0x2; |
| 204 |
pps->ReferenceFrames[0].flags = 0x10; |
| 205 |
pps->slice_parsing_fields.value = 0x107; |
| 206 |
pps->st_rps_bits = 0x9; |
| 207 |
slc->slice_data_byte_offset = 0x9; |
| 208 |
slc->RefPicList[0][0] = 0; |
| 209 |
slc->RefPicList[1][0] = 0; |
| 210 |
slc->LongSliceFlags.value = 0x1401; |
| 211 |
slc->collocated_ref_idx = 0; |
| 212 |
slc->num_ref_idx_l0_active_minus1 = 0; |
| 213 |
slc->num_ref_idx_l1_active_minus1 = 0; |
| 214 |
slc->five_minus_max_num_merge_cand = 0; |
| 215 |
bitstream.assign({ |
| 216 |
0x00, 0x00, 0x01, 0x02, 0x01, 0xd0, 0x09, 0x7e, 0x10, 0xc2, 0x0e, 0xc0, 0xfd, 0xb5, 0xce, 0x30}); |
| 217 |
break; |
| 218 |
case 2: |
| 219 |
pps->ReferenceFrames[0].picture_id = m_resources[0]; |
| 220 |
pps->ReferenceFrames[1].picture_id = m_resources[1]; |
| 221 |
pps->CurrPic.pic_order_cnt = 0x1; |
| 222 |
pps->ReferenceFrames[0].flags = 0x10; |
| 223 |
pps->slice_parsing_fields.value = 0x107; |
| 224 |
pps->st_rps_bits = 0xa; |
| 225 |
pps->ReferenceFrames[1].pic_order_cnt = 0x2; |
| 226 |
pps->ReferenceFrames[1].flags = 0x20; |
| 227 |
slc->slice_data_byte_offset = 0xa; |
| 228 |
slc->RefPicList[0][0] = 0; |
| 229 |
slc->RefPicList[1][0] = 0x1; |
| 230 |
slc->LongSliceFlags.value = 0x1401; |
| 231 |
slc->collocated_ref_idx = 0; |
| 232 |
slc->num_ref_idx_l0_active_minus1 = 0; |
| 233 |
slc->num_ref_idx_l1_active_minus1 = 0; |
| 234 |
slc->five_minus_max_num_merge_cand = 0; |
| 235 |
bitstream.assign({ |
| 236 |
0x00, 0x00, 0x01, 0x02, 0x01, 0xd0, 0x11, 0xff, 0xd4, 0x43, 0x02, 0x0e, 0x40, 0x92, 0xf9, 0x84}); |
| 237 |
break; |
| 238 |
default: |
| 239 |
break; |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
void DecTestDataAVC::UpdateCompBuffers(int frameId) |
| 244 |
{ |
| 245 |
auto ¤tArray = m_bShortFormat ? m_frameArray : m_frameArrayLong; |
| 246 |
auto *pps = (VAPictureParameterBufferH264 *)¤tArray[frameId].picParam[0]; |
| 247 |
auto *slc = (VASliceParameterBufferH264 *)¤tArray[frameId].slcParam[0]; |
| 248 |
|
| 249 |
pps->CurrPic.picture_id = m_resources[frameId]; |
| 250 |
switch (frameId) |
| 251 |
{ |
| 252 |
case 1: |
| 253 |
pps->ReferenceFrames[0].picture_id = m_resources[0]; |
| 254 |
slc->RefPicList0[0].picture_id = m_resources[0]; |
| 255 |
slc->RefPicList1[0].picture_id = m_resources[0]; |
| 256 |
pps->CurrPic.frame_idx = 0x1; |
| 257 |
pps->CurrPic.TopFieldOrderCnt = 0x6; |
| 258 |
pps->CurrPic.BottomFieldOrderCnt = 0x6; |
| 259 |
pps->ReferenceFrames[0].flags = 0x8; |
| 260 |
pps->frame_num = 0x1; |
| 261 |
slc->slice_data_bit_offset = 0x23; |
| 262 |
slc->slice_type = 0; |
| 263 |
slc->RefPicList0[0].flags = 0x8; |
| 264 |
break; |
| 265 |
case 2: |
| 266 |
pps->ReferenceFrames[0].picture_id = m_resources[0]; |
| 267 |
pps->ReferenceFrames[1].picture_id = m_resources[1]; |
| 268 |
slc->RefPicList0[0].picture_id = m_resources[0]; |
| 269 |
slc->RefPicList1[0].picture_id = m_resources[1]; |
| 270 |
pps->CurrPic.frame_idx = 0x2; |
| 271 |
pps->CurrPic.flags = 0; |
| 272 |
pps->CurrPic.TopFieldOrderCnt = 0x2; |
| 273 |
pps->CurrPic.BottomFieldOrderCnt = 0x2; |
| 274 |
pps->ReferenceFrames[1].frame_idx = 0x1; |
| 275 |
pps->ReferenceFrames[1].flags = 0x8; |
| 276 |
pps->ReferenceFrames[1].TopFieldOrderCnt = 0x6; |
| 277 |
pps->ReferenceFrames[1].BottomFieldOrderCnt = 0x6; |
| 278 |
pps->pic_fields.value = 0x119; |
| 279 |
pps->frame_num = 0x2; |
| 280 |
slc->slice_data_bit_offset = 0x24; |
| 281 |
slc->slice_type = 0x1; |
| 282 |
slc->direct_spatial_mv_pred_flag = 0x1; |
| 283 |
slc->RefPicList0[0].flags = 0x8; |
| 284 |
slc->RefPicList1[0].frame_idx = 0x1; |
| 285 |
slc->RefPicList1[0].flags = 0x8; |
| 286 |
slc->RefPicList1[0].TopFieldOrderCnt = 0x6; |
| 287 |
slc->RefPicList1[0].BottomFieldOrderCnt = 0x6; |
| 288 |
break; |
| 289 |
default: |
| 290 |
break; |
| 291 |
} |
| 292 |
} |