| 429 | } |
| 430 | |
| 431 | int AFVTBDecoder::process_extra_data(IAFPacket *pPacket) |
| 432 | { |
| 433 | if (pPacket == nullptr || pPacket->getInfo().extra_data == nullptr) { |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | Stream_meta *meta = ((Stream_meta *) (*(mPInMeta))); |
| 438 | |
| 439 | if (meta->extradata_size == pPacket->getInfo().extra_data_size) { |
| 440 | if (memcmp(pPacket->getInfo().extra_data, meta->extradata, meta->extradata_size) == 0) { |
| 441 | return 0; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if (meta->extradata) { |
| 446 | free(meta->extradata); |
| 447 | } |
| 448 | |
| 449 | meta->extradata = static_cast<uint8_t *>(av_malloc(pPacket->getInfo().extra_data_size + AV_INPUT_BUFFER_PADDING_SIZE)); |
| 450 | meta->extradata_size = pPacket->getInfo().extra_data_size; |
| 451 | memcpy(meta->extradata, pPacket->getInfo().extra_data, pPacket->getInfo().extra_data_size); |
| 452 | unique_ptr<bitStreamParser> parser = unique_ptr<bitStreamParser>(new bitStreamParser()); |
| 453 | int ret = parser->init(meta); |
| 454 | parser->parser(pPacket->getData(), pPacket->getSize()); |
| 455 | parser->getPictureSize(meta->width, meta->height); |
| 456 | |
| 457 | if (mParser) { |
| 458 | mParser = move(parser); |
| 459 | } |
| 460 | |
| 461 | CM_NULLABLE CMVideoFormatDescriptionRef videoFormatDesRef{nullptr}; |
| 462 | CM_NULLABLE CFDictionaryRef decoder_spec{nullptr}; |
| 463 | int rv = createVideoFormatDesc(pPacket->getInfo().extra_data, pPacket->getInfo().extra_data_size, meta->width, meta->height, |
| 464 | decoder_spec, videoFormatDesRef); |
| 465 | /* |
| 466 | there are some bugs when reuse on iOS 14.x,eg h264 main profile to high profile |
| 467 | */ |
| 468 | bool canReuse = true; |
| 469 | #if TARGET_OS_IPHONE |
| 470 | if (Cicada::GetIosVersion() >= 14.0 /* && Cicada::GetIosVersion() < 15.0*/) { |
| 471 | if (meta->codec == AF_CODEC_ID_H264 || meta->codec == AF_CODEC_ID_HEVC) { |
| 472 | canReuse = false; |
| 473 | } |
| 474 | } |
| 475 | #endif |
| 476 | |
| 477 | if (rv == 0) { |
| 478 | if (!canReuse || !VTDecompressionSessionCanAcceptFormatDescription(mVTDecompressSessionRef, videoFormatDesRef)) { |
| 479 | flushReorderQueue(); |
| 480 | close_decoder(); |
| 481 | mVideoFormatDesRef = videoFormatDesRef; |
| 482 | mDecoder_spec = decoder_spec; |
| 483 | rv = init_decoder_internal(); |
| 484 | |
| 485 | if (rv < 0) { |
| 486 | return -EINVAL; |
| 487 | } |
| 488 | } else { |
nothing calls this directly
no test coverage detected