* When duplicating a stream, the demuxer has already set the extradata, profile, and * level of the par. Keep in mind that this function will not be invoked since the * profile and level are set. * * When utilizing an encoder, such as libx264, to encode a stream, the extradata in * par->extradata contains the SPS, which includes profile and level information. * However, the profile and level
| 511 | * the extradata will remain empty. |
| 512 | */ |
| 513 | static int parse_profile_level(AVFormatContext *s, AVCodecParameters *par) |
| 514 | { |
| 515 | int ret = 0; |
| 516 | const uint8_t *r = par->extradata, *r1, *end = par->extradata + par->extradata_size; |
| 517 | H264SPS seq, *const sps = &seq; |
| 518 | uint32_t state; |
| 519 | WHIPContext *whip = s->priv_data; |
| 520 | |
| 521 | if (par->codec_id != AV_CODEC_ID_H264) |
| 522 | return ret; |
| 523 | |
| 524 | if (par->profile != AV_PROFILE_UNKNOWN && par->level != AV_LEVEL_UNKNOWN) |
| 525 | return ret; |
| 526 | |
| 527 | if (!par->extradata || par->extradata_size <= 0) { |
| 528 | av_log(whip, AV_LOG_ERROR, "Unable to parse profile from empty extradata=%p, size=%d\n", |
| 529 | par->extradata, par->extradata_size); |
| 530 | return AVERROR(EINVAL); |
| 531 | } |
| 532 | |
| 533 | while (1) { |
| 534 | r = avpriv_find_start_code(r, end, &state); |
| 535 | if (r >= end) |
| 536 | break; |
| 537 | |
| 538 | r1 = ff_nal_find_startcode(r, end); |
| 539 | if ((state & 0x1f) == H264_NAL_SPS) { |
| 540 | ret = ff_avc_decode_sps(sps, r, r1 - r); |
| 541 | if (ret < 0) { |
| 542 | av_log(whip, AV_LOG_ERROR, "Failed to decode SPS, state=%x, size=%d\n", |
| 543 | state, (int)(r1 - r)); |
| 544 | return ret; |
| 545 | } |
| 546 | |
| 547 | av_log(whip, AV_LOG_VERBOSE, "Parse profile=%d, level=%d from SPS\n", |
| 548 | sps->profile_idc, sps->level_idc); |
| 549 | par->profile = sps->profile_idc; |
| 550 | par->level = sps->level_idc; |
| 551 | } |
| 552 | |
| 553 | r = r1; |
| 554 | } |
| 555 | |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Parses video SPS/PPS from the extradata of codecpar and checks the codec. |
no test coverage detected