| 1 |
/* |
| 2 |
* Copyright (C) 2013-2021 Jean-Luc Barrière |
| 3 |
* Copyright (C) 2005-2014 Team Kodi (https://kodi.tv) |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSE.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "ES_h264.h" |
| 10 |
#include "bitstream.h" |
| 11 |
#include "debug.h" |
| 12 |
|
| 13 |
#include <cstring> // for memset memcpy |
| 14 |
|
| 15 |
using namespace TSDemux; |
| 16 |
|
| 17 |
static const int h264_lev2cpbsize[][2] = |
| 18 |
{ |
| 19 |
{10, 175}, |
| 20 |
{11, 500}, |
| 21 |
{12, 1000}, |
| 22 |
{13, 2000}, |
| 23 |
{20, 2000}, |
| 24 |
{21, 4000}, |
| 25 |
{22, 4000}, |
| 26 |
{30, 10000}, |
| 27 |
{31, 14000}, |
| 28 |
{32, 20000}, |
| 29 |
{40, 25000}, |
| 30 |
{41, 62500}, |
| 31 |
{42, 62500}, |
| 32 |
{50, 135000}, |
| 33 |
{51, 240000}, |
| 34 |
{-1, -1}, |
| 35 |
}; |
| 36 |
|
| 37 |
ES_h264::ES_h264(uint16_t pes_pid) |
| 38 |
: ElementaryStream(pes_pid) |
| 39 |
{ |
| 40 |
m_Height = 0; |
| 41 |
m_Width = 0; |
| 42 |
m_FpsScale = 0; |
| 43 |
m_vbvDelay = -1; |
| 44 |
m_vbvSize = 0; |
| 45 |
m_PixelAspect.den = 1; |
| 46 |
m_PixelAspect.num = 0; |
| 47 |
m_DTS = 0; |
| 48 |
m_PTS = 0; |
| 49 |
m_Interlaced = false; |
| 50 |
es_alloc_init = 240000; |
| 51 |
Reset(); |
| 52 |
} |
| 53 |
|
| 54 |
ES_h264::~ES_h264() |
| 55 |
{ |
| 56 |
} |
| 57 |
|
| 58 |
void ES_h264::Parse(STREAM_PKT* pkt) |
| 59 |
{ |
| 60 |
size_t frame_ptr = es_consumed; |
| 61 |
size_t p = es_parsed; |
| 62 |
uint32_t startcode = m_StartCode; |
| 63 |
bool frameComplete = false; |
| 64 |
|
| 65 |
while ((p + 3) < es_len) |
| 66 |
{ |
| 67 |
if ((startcode & 0xffffff00) == 0x00000100) |
| 68 |
{ |
| 69 |
if (Parse_H264(startcode, p, frameComplete) < 0) |
| 70 |
{ |
| 71 |
break; |
| 72 |
} |
| 73 |
} |
| 74 |
startcode = startcode << 8 | es_buf[p++]; |
| 75 |
} |
| 76 |
es_parsed = p; |
| 77 |
m_StartCode = startcode; |
| 78 |
|
| 79 |
if (frameComplete) |
| 80 |
{ |
| 81 |
if (!m_NeedSPS && !m_NeedIFrame) |
| 82 |
{ |
| 83 |
double PAR = (double)m_PixelAspect.num/(double)m_PixelAspect.den; |
| 84 |
double DAR = (PAR * m_Width) / m_Height; |
| 85 |
//DBG(DEMUX_DBG_PARSE, "H.264 SPS: PAR %i:%i\n", m_PixelAspect.num, m_PixelAspect.den); |
| 86 |
//DBG(DEMUX_DBG_PARSE, "H.264 SPS: DAR %.2f\n", DAR); |
| 87 |
|
| 88 |
uint64_t duration; |
| 89 |
if (c_dts != PTS_UNSET && p_dts != PTS_UNSET && c_dts > p_dts) |
| 90 |
duration = c_dts - p_dts; |
| 91 |
else |
| 92 |
duration = static_cast<int>(Rescale(40000, PTS_TIME_BASE, RESCALE_TIME_BASE)); |
| 93 |
|
| 94 |
bool streamChange = false; |
| 95 |
if (es_frame_valid) |
| 96 |
{ |
| 97 |
if (m_FpsScale == 0) |
| 98 |
m_FpsScale = static_cast<int>(Rescale(duration, RESCALE_TIME_BASE, PTS_TIME_BASE)); |
| 99 |
streamChange = SetVideoInformation(m_FpsScale, RESCALE_TIME_BASE, m_Height, m_Width, static_cast<float>(DAR), m_Interlaced); |
| 100 |
} |
| 101 |
|
| 102 |
pkt->pid = pid; |
| 103 |
pkt->size = es_consumed - frame_ptr; |
| 104 |
pkt->data = &es_buf[frame_ptr]; |
| 105 |
pkt->dts = m_DTS; |
| 106 |
pkt->pts = m_PTS; |
| 107 |
pkt->duration = duration; |
| 108 |
pkt->streamChange = streamChange; |
| 109 |
} |
| 110 |
m_StartCode = 0xffffffff; |
| 111 |
es_parsed = es_consumed; |
| 112 |
es_found_frame = false; |
| 113 |
es_frame_valid = true; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
void ES_h264::Reset() |
| 118 |
{ |
| 119 |
ElementaryStream::Reset(); |
| 120 |
m_StartCode = 0xffffffff; |
| 121 |
m_NeedIFrame = true; |
| 122 |
m_NeedSPS = true; |
| 123 |
m_NeedPPS = true; |
| 124 |
memset(&m_streamData, 0, sizeof(m_streamData)); |
| 125 |
} |
| 126 |
|
| 127 |
int ES_h264::Parse_H264(uint32_t startcode, int buf_ptr, bool &complete) |
| 128 |
{ |
| 129 |
int len = es_len - buf_ptr; |
| 130 |
uint8_t *buf = es_buf + buf_ptr; |
| 131 |
|
| 132 |
switch(startcode & 0x9f) |
| 133 |
{ |
| 134 |
case 1: |
| 135 |
case 2: |
| 136 |
case 3: |
| 137 |
case 4: |
| 138 |
case 5: |
| 139 |
{ |
| 140 |
if (m_NeedSPS || m_NeedPPS) |
| 141 |
{ |
| 142 |
es_found_frame = true; |
| 143 |
return 0; |
| 144 |
} |
| 145 |
// need at least 32 bytes for parsing nal |
| 146 |
if (len < 32) |
| 147 |
return -1; |
| 148 |
h264_private::VCL_NAL vcl; |
| 149 |
memset(&vcl, 0, sizeof(h264_private::VCL_NAL)); |
| 150 |
vcl.nal_ref_idc = startcode & 0x60; |
| 151 |
vcl.nal_unit_type = startcode & 0x1F; |
| 152 |
if (!Parse_SLH(buf, len, vcl)) |
| 153 |
return 0; |
| 154 |
|
| 155 |
// check for the beginning of a new access unit |
| 156 |
if (es_found_frame && IsFirstVclNal(vcl)) |
| 157 |
{ |
| 158 |
complete = true; |
| 159 |
es_consumed = buf_ptr - 4; |
| 160 |
return -1; |
| 161 |
} |
| 162 |
|
| 163 |
if (!es_found_frame) |
| 164 |
{ |
| 165 |
if (buf_ptr - 4 >= (int)es_pts_pointer) |
| 166 |
{ |
| 167 |
m_DTS = c_dts; |
| 168 |
m_PTS = c_pts; |
| 169 |
} |
| 170 |
else |
| 171 |
{ |
| 172 |
m_DTS = p_dts; |
| 173 |
m_PTS = p_pts; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
m_streamData.vcl_nal = vcl; |
| 178 |
es_found_frame = true; |
| 179 |
break; |
| 180 |
} |
| 181 |
|
| 182 |
case NAL_SEI: |
| 183 |
if (es_found_frame) |
| 184 |
{ |
| 185 |
complete = true; |
| 186 |
es_consumed = buf_ptr - 4; |
| 187 |
return -1; |
| 188 |
} |
| 189 |
break; |
| 190 |
|
| 191 |
case NAL_SPS: |
| 192 |
{ |
| 193 |
if (es_found_frame) |
| 194 |
{ |
| 195 |
complete = true; |
| 196 |
es_consumed = buf_ptr - 4; |
| 197 |
return -1; |
| 198 |
} |
| 199 |
// TODO: how big is SPS? |
| 200 |
if (len < 256) |
| 201 |
return -1; |
| 202 |
if (!Parse_SPS(buf, len)) |
| 203 |
return 0; |
| 204 |
|
| 205 |
m_NeedSPS = false; |
| 206 |
break; |
| 207 |
} |
| 208 |
|
| 209 |
case NAL_PPS: |
| 210 |
{ |
| 211 |
if (es_found_frame) |
| 212 |
{ |
| 213 |
complete = true; |
| 214 |
es_consumed = buf_ptr - 4; |
| 215 |
return -1; |
| 216 |
} |
| 217 |
// TODO: how big is PPS |
| 218 |
if (len < 64) |
| 219 |
return -1; |
| 220 |
if (!Parse_PPS(buf, len)) |
| 221 |
return 0; |
| 222 |
m_NeedPPS = false; |
| 223 |
break; |
| 224 |
} |
| 225 |
|
| 226 |
case NAL_AUD: |
| 227 |
if (es_found_frame && (p_pts != PTS_UNSET)) |
| 228 |
{ |
| 229 |
complete = true; |
| 230 |
es_consumed = buf_ptr - 4; |
| 231 |
return -1; |
| 232 |
} |
| 233 |
break; |
| 234 |
|
| 235 |
case NAL_END_SEQ: |
| 236 |
if (es_found_frame) |
| 237 |
{ |
| 238 |
complete = true; |
| 239 |
es_consumed = buf_ptr; |
| 240 |
return -1; |
| 241 |
} |
| 242 |
break; |
| 243 |
|
| 244 |
case 13: |
| 245 |
case 14: |
| 246 |
case 15: |
| 247 |
case 16: |
| 248 |
case 17: |
| 249 |
case 18: |
| 250 |
if (es_found_frame) |
| 251 |
{ |
| 252 |
complete = true; |
| 253 |
es_consumed = buf_ptr - 4; |
| 254 |
return -1; |
| 255 |
} |
| 256 |
break; |
| 257 |
|
| 258 |
default: |
| 259 |
break; |
| 260 |
} |
| 261 |
|
| 262 |
return 0; |
| 263 |
} |
| 264 |
|
| 265 |
bool ES_h264::Parse_PPS(uint8_t *buf, int len) |
| 266 |
{ |
| 267 |
CBitstream bs(buf, len*8); |
| 268 |
|
| 269 |
int pps_id = bs.readGolombUE(); |
| 270 |
int sps_id = bs.readGolombUE(); |
| 271 |
m_streamData.pps[pps_id].sps = sps_id; |
| 272 |
bs.readBits1(); |
| 273 |
m_streamData.pps[pps_id].pic_order_present_flag = bs.readBits1(); |
| 274 |
return true; |
| 275 |
} |
| 276 |
|
| 277 |
bool ES_h264::Parse_SLH(uint8_t *buf, int len, h264_private::VCL_NAL &vcl) |
| 278 |
{ |
| 279 |
CBitstream bs(buf, len*8); |
| 280 |
|
| 281 |
bs.readGolombUE(); /* first_mb_in_slice */ |
| 282 |
int slice_type = bs.readGolombUE(); |
| 283 |
|
| 284 |
if (slice_type > 4) |
| 285 |
slice_type -= 5; /* Fixed slice type per frame */ |
| 286 |
|
| 287 |
switch (slice_type) |
| 288 |
{ |
| 289 |
case 0: |
| 290 |
break; |
| 291 |
case 1: |
| 292 |
break; |
| 293 |
case 2: |
| 294 |
m_NeedIFrame = false; |
| 295 |
break; |
| 296 |
default: |
| 297 |
return false; |
| 298 |
} |
| 299 |
|
| 300 |
int pps_id = bs.readGolombUE(); |
| 301 |
int sps_id = m_streamData.pps[pps_id].sps; |
| 302 |
if (m_streamData.sps[sps_id].cbpsize == 0) |
| 303 |
return false; |
| 304 |
|
| 305 |
m_vbvSize = m_streamData.sps[sps_id].cbpsize; |
| 306 |
m_vbvDelay = -1; |
| 307 |
|
| 308 |
vcl.pic_parameter_set_id = pps_id; |
| 309 |
vcl.frame_num = bs.readBits(m_streamData.sps[sps_id].log2_max_frame_num); |
| 310 |
if (!m_streamData.sps[sps_id].frame_mbs_only_flag) |
| 311 |
{ |
| 312 |
vcl.field_pic_flag = bs.readBits1(); |
| 313 |
// interlaced |
| 314 |
if (vcl.field_pic_flag) |
| 315 |
m_Interlaced = true; |
| 316 |
} |
| 317 |
if (vcl.field_pic_flag) |
| 318 |
vcl.bottom_field_flag = bs.readBits1(); |
| 319 |
|
| 320 |
if (vcl.nal_unit_type == 5) |
| 321 |
vcl.idr_pic_id = bs.readGolombUE(); |
| 322 |
if (m_streamData.sps[sps_id].pic_order_cnt_type == 0) |
| 323 |
{ |
| 324 |
vcl.pic_order_cnt_lsb = bs.readBits(m_streamData.sps[sps_id].log2_max_pic_order_cnt_lsb); |
| 325 |
if(m_streamData.pps[pps_id].pic_order_present_flag && !vcl.field_pic_flag) |
| 326 |
vcl.delta_pic_order_cnt_bottom = bs.readGolombSE(); |
| 327 |
} |
| 328 |
if(m_streamData.sps[sps_id].pic_order_cnt_type == 1 && |
| 329 |
!m_streamData.sps[sps_id].delta_pic_order_always_zero_flag ) |
| 330 |
{ |
| 331 |
vcl.delta_pic_order_cnt_0 = bs.readGolombSE(); |
| 332 |
if(m_streamData.pps[pps_id].pic_order_present_flag && !vcl.field_pic_flag ) |
| 333 |
vcl.delta_pic_order_cnt_1 = bs.readGolombSE(); |
| 334 |
} |
| 335 |
|
| 336 |
vcl.pic_order_cnt_type = m_streamData.sps[sps_id].pic_order_cnt_type; |
| 337 |
|
| 338 |
return true; |
| 339 |
} |
| 340 |
|
| 341 |
bool ES_h264::Parse_SPS(uint8_t *buf, int len) |
| 342 |
{ |
| 343 |
CBitstream bs(buf, len*8); |
| 344 |
unsigned int tmp, frame_mbs_only; |
| 345 |
int cbpsize = -1; |
| 346 |
|
| 347 |
int profile_idc = bs.readBits(8); |
| 348 |
/* constraint_set0_flag = bs.readBits1(); */ |
| 349 |
/* constraint_set1_flag = bs.readBits1(); */ |
| 350 |
/* constraint_set2_flag = bs.readBits1(); */ |
| 351 |
/* constraint_set3_flag = bs.readBits1(); */ |
| 352 |
/* reserved = bs.readBits(4); */ |
| 353 |
bs.skipBits(8); |
| 354 |
int level_idc = bs.readBits(8); |
| 355 |
unsigned int seq_parameter_set_id = bs.readGolombUE(9); |
| 356 |
|
| 357 |
unsigned int i = 0; |
| 358 |
while (h264_lev2cpbsize[i][0] != -1) |
| 359 |
{ |
| 360 |
if (h264_lev2cpbsize[i][0] >= level_idc) |
| 361 |
{ |
| 362 |
cbpsize = h264_lev2cpbsize[i][1]; |
| 363 |
break; |
| 364 |
} |
| 365 |
i++; |
| 366 |
} |
| 367 |
if (cbpsize < 0) |
| 368 |
return false; |
| 369 |
|
| 370 |
memset(&m_streamData.sps[seq_parameter_set_id], 0, sizeof(h264_private::SPS)); |
| 371 |
m_streamData.sps[seq_parameter_set_id].cbpsize = cbpsize * 125; /* Convert from kbit to bytes */ |
| 372 |
|
| 373 |
if( profile_idc == 100 || profile_idc == 110 || |
| 374 |
profile_idc == 122 || profile_idc == 244 || profile_idc == 44 || |
| 375 |
profile_idc == 83 || profile_idc == 86 || profile_idc == 118 || |
| 376 |
profile_idc == 128 ) |
| 377 |
{ |
| 378 |
int chroma_format_idc = bs.readGolombUE(9); /* chroma_format_idc */ |
| 379 |
if(chroma_format_idc == 3) |
| 380 |
bs.skipBits(1); /* residual_colour_transform_flag */ |
| 381 |
bs.readGolombUE(); /* bit_depth_luma - 8 */ |
| 382 |
bs.readGolombUE(); /* bit_depth_chroma - 8 */ |
| 383 |
bs.skipBits(1); /* transform_bypass */ |
| 384 |
if (bs.readBits1()) /* seq_scaling_matrix_present */ |
| 385 |
{ |
| 386 |
for (int i = 0; i < ((chroma_format_idc != 3) ? 8 : 12); i++) |
| 387 |
{ |
| 388 |
if (bs.readBits1()) /* seq_scaling_list_present */ |
| 389 |
{ |
| 390 |
int last = 8, next = 8, size = (i<6) ? 16 : 64; |
| 391 |
for (int j = 0; j < size; j++) |
| 392 |
{ |
| 393 |
if (next) |
| 394 |
next = (last + bs.readGolombSE()) & 0xff; |
| 395 |
last = !next ? last: next; |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
int log2_max_frame_num_minus4 = bs.readGolombUE(); /* log2_max_frame_num - 4 */ |
| 403 |
m_streamData.sps[seq_parameter_set_id].log2_max_frame_num = log2_max_frame_num_minus4 + 4; |
| 404 |
int pic_order_cnt_type = bs.readGolombUE(9); |
| 405 |
m_streamData.sps[seq_parameter_set_id].pic_order_cnt_type = pic_order_cnt_type; |
| 406 |
if (pic_order_cnt_type == 0) |
| 407 |
{ |
| 408 |
int log2_max_pic_order_cnt_lsb_minus4 = bs.readGolombUE(); /* log2_max_poc_lsb - 4 */ |
| 409 |
m_streamData.sps[seq_parameter_set_id].log2_max_pic_order_cnt_lsb = log2_max_pic_order_cnt_lsb_minus4 + 4; |
| 410 |
} |
| 411 |
else if (pic_order_cnt_type == 1) |
| 412 |
{ |
| 413 |
m_streamData.sps[seq_parameter_set_id].delta_pic_order_always_zero_flag = bs.readBits1(); |
| 414 |
bs.readGolombSE(); /* offset_for_non_ref_pic */ |
| 415 |
bs.readGolombSE(); /* offset_for_top_to_bottom_field */ |
| 416 |
tmp = bs.readGolombUE(); /* num_ref_frames_in_pic_order_cnt_cycle */ |
| 417 |
for (unsigned int i = 0; i < tmp; i++) |
| 418 |
bs.readGolombSE(); /* offset_for_ref_frame[i] */ |
| 419 |
} |
| 420 |
else if(pic_order_cnt_type != 2) |
| 421 |
{ |
| 422 |
/* Illegal poc */ |
| 423 |
return false; |
| 424 |
} |
| 425 |
|
| 426 |
bs.readGolombUE(9); /* ref_frames */ |
| 427 |
bs.skipBits(1); /* gaps_in_frame_num_allowed */ |
| 428 |
m_Width /* mbs */ = bs.readGolombUE() + 1; |
| 429 |
m_Height /* mbs */ = bs.readGolombUE() + 1; |
| 430 |
frame_mbs_only = bs.readBits1(); |
| 431 |
m_streamData.sps[seq_parameter_set_id].frame_mbs_only_flag = frame_mbs_only; |
| 432 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: pic_width: %u mbs\n", (unsigned) m_Width); |
| 433 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: pic_height: %u mbs\n", (unsigned) m_Height); |
| 434 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: frame only flag: %d\n", frame_mbs_only); |
| 435 |
|
| 436 |
m_Width *= 16; |
| 437 |
m_Height *= 16 * (2-frame_mbs_only); |
| 438 |
|
| 439 |
if (!frame_mbs_only) |
| 440 |
{ |
| 441 |
if (bs.readBits1()) /* mb_adaptive_frame_field_flag */ |
| 442 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: MBAFF\n"); |
| 443 |
} |
| 444 |
bs.skipBits(1); /* direct_8x8_inference_flag */ |
| 445 |
if (bs.readBits1()) /* frame_cropping_flag */ |
| 446 |
{ |
| 447 |
uint32_t crop_left = bs.readGolombUE(); |
| 448 |
uint32_t crop_right = bs.readGolombUE(); |
| 449 |
uint32_t crop_top = bs.readGolombUE(); |
| 450 |
uint32_t crop_bottom = bs.readGolombUE(); |
| 451 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: cropping %d %d %d %d\n", crop_left, crop_top, crop_right, crop_bottom); |
| 452 |
|
| 453 |
m_Width -= 2*(crop_left + crop_right); |
| 454 |
if (frame_mbs_only) |
| 455 |
m_Height -= 2*(crop_top + crop_bottom); |
| 456 |
else |
| 457 |
m_Height -= 4*(crop_top + crop_bottom); |
| 458 |
} |
| 459 |
|
| 460 |
/* VUI parameters */ |
| 461 |
m_PixelAspect.num = 0; |
| 462 |
if (bs.readBits1()) /* vui_parameters_present flag */ |
| 463 |
{ |
| 464 |
if (bs.readBits1()) /* aspect_ratio_info_present */ |
| 465 |
{ |
| 466 |
uint32_t aspect_ratio_idc = bs.readBits(8); |
| 467 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: aspect_ratio_idc %d\n", aspect_ratio_idc); |
| 468 |
|
| 469 |
if (aspect_ratio_idc == 255 /* Extended_SAR */) |
| 470 |
{ |
| 471 |
m_PixelAspect.num = bs.readBits(16); /* sar_width */ |
| 472 |
m_PixelAspect.den = bs.readBits(16); /* sar_height */ |
| 473 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: -> sar %dx%d\n", m_PixelAspect.num, m_PixelAspect.den); |
| 474 |
} |
| 475 |
else |
| 476 |
{ |
| 477 |
static const mpeg_rational_t aspect_ratios[] = |
| 478 |
{ /* page 213: */ |
| 479 |
/* 0: unknown */ |
| 480 |
{0, 1}, |
| 481 |
/* 1...16: */ |
| 482 |
{ 1, 1}, {12, 11}, {10, 11}, {16, 11}, { 40, 33}, {24, 11}, {20, 11}, {32, 11}, |
| 483 |
{80, 33}, {18, 11}, {15, 11}, {64, 33}, {160, 99}, { 4, 3}, { 3, 2}, { 2, 1} |
| 484 |
}; |
| 485 |
|
| 486 |
if (aspect_ratio_idc < sizeof(aspect_ratios)/sizeof(aspect_ratios[0])) |
| 487 |
{ |
| 488 |
memcpy(&m_PixelAspect, &aspect_ratios[aspect_ratio_idc], sizeof(mpeg_rational_t)); |
| 489 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: PAR %d / %d\n", m_PixelAspect.num, m_PixelAspect.den); |
| 490 |
} |
| 491 |
else |
| 492 |
{ |
| 493 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: aspect_ratio_idc out of range !\n"); |
| 494 |
} |
| 495 |
} |
| 496 |
} |
| 497 |
if (bs.readBits1()) // overscan |
| 498 |
{ |
| 499 |
bs.readBits1(); // overscan_appropriate_flag |
| 500 |
} |
| 501 |
if (bs.readBits1()) // video_signal_type_present_flag |
| 502 |
{ |
| 503 |
bs.readBits(3); // video_format |
| 504 |
bs.readBits1(); // video_full_range_flag |
| 505 |
if (bs.readBits1()) // colour_description_present_flag |
| 506 |
{ |
| 507 |
bs.readBits(8); // colour_primaries |
| 508 |
bs.readBits(8); // transfer_characteristics |
| 509 |
bs.readBits(8); // matrix_coefficients |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
if (bs.readBits1()) // chroma_loc_info_present_flag |
| 514 |
{ |
| 515 |
bs.readGolombUE(); // chroma_sample_loc_type_top_field |
| 516 |
bs.readGolombUE(); // chroma_sample_loc_type_bottom_field |
| 517 |
} |
| 518 |
|
| 519 |
if (bs.readBits1()) // timing_info_present_flag |
| 520 |
{ |
| 521 |
// uint32_t num_units_in_tick = bs.readBits(32); |
| 522 |
// uint32_t time_scale = bs.readBits(32); |
| 523 |
// int fixed_frame_rate = bs.readBits1(); |
| 524 |
// if (num_units_in_tick > 0) |
| 525 |
// m_FPS = time_scale / (num_units_in_tick * 2); |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
DBG(DEMUX_DBG_PARSE, "H.264 SPS: -> video size %dx%d, aspect %d:%d\n", m_Width, m_Height, m_PixelAspect.num, m_PixelAspect.den); |
| 530 |
return true; |
| 531 |
} |
| 532 |
|
| 533 |
bool ES_h264::IsFirstVclNal(h264_private::VCL_NAL &vcl) |
| 534 |
{ |
| 535 |
if (m_streamData.vcl_nal.frame_num != vcl.frame_num) |
| 536 |
return true; |
| 537 |
|
| 538 |
if (m_streamData.vcl_nal.pic_parameter_set_id != vcl.pic_parameter_set_id) |
| 539 |
return true; |
| 540 |
|
| 541 |
if (m_streamData.vcl_nal.field_pic_flag != vcl.field_pic_flag) |
| 542 |
return true; |
| 543 |
|
| 544 |
if (m_streamData.vcl_nal.field_pic_flag && vcl.field_pic_flag) |
| 545 |
{ |
| 546 |
if (m_streamData.vcl_nal.bottom_field_flag != vcl.bottom_field_flag) |
| 547 |
return true; |
| 548 |
} |
| 549 |
|
| 550 |
if (m_streamData.vcl_nal.nal_ref_idc == 0 || vcl.nal_ref_idc == 0) |
| 551 |
{ |
| 552 |
if (m_streamData.vcl_nal.nal_ref_idc != vcl.nal_ref_idc) |
| 553 |
return true; |
| 554 |
} |
| 555 |
|
| 556 |
if (m_streamData.vcl_nal.pic_order_cnt_type == 0 && vcl.pic_order_cnt_type == 0) |
| 557 |
{ |
| 558 |
if (m_streamData.vcl_nal.pic_order_cnt_lsb != vcl.pic_order_cnt_lsb) |
| 559 |
return true; |
| 560 |
if (m_streamData.vcl_nal.delta_pic_order_cnt_bottom != vcl.delta_pic_order_cnt_bottom) |
| 561 |
return true; |
| 562 |
} |
| 563 |
|
| 564 |
if (m_streamData.vcl_nal.pic_order_cnt_type == 1 && vcl.pic_order_cnt_type == 1) |
| 565 |
{ |
| 566 |
if (m_streamData.vcl_nal.delta_pic_order_cnt_0 != vcl.delta_pic_order_cnt_0) |
| 567 |
return true; |
| 568 |
if (m_streamData.vcl_nal.delta_pic_order_cnt_1 != vcl.delta_pic_order_cnt_1) |
| 569 |
return true; |
| 570 |
} |
| 571 |
|
| 572 |
if (m_streamData.vcl_nal.nal_unit_type == 5 || vcl.nal_unit_type == 5) |
| 573 |
{ |
| 574 |
if (m_streamData.vcl_nal.nal_unit_type != vcl.nal_unit_type) |
| 575 |
return true; |
| 576 |
} |
| 577 |
|
| 578 |
if (m_streamData.vcl_nal.nal_unit_type == 5 && vcl.nal_unit_type == 5) |
| 579 |
{ |
| 580 |
if (m_streamData.vcl_nal.idr_pic_id != vcl.idr_pic_id) |
| 581 |
return true; |
| 582 |
} |
| 583 |
return false; |
| 584 |
} |