* Parses video SPS/PPS from the extradata of codecpar and checks the codec. * Currently only supports video(h264) and audio(opus). Note that only baseline * and constrained baseline profiles of h264 are supported. * * If the profile is less than 0, the function considers the profile as baseline. * It may need to parse the profile from SPS/PPS. This situation occurs when ingesting * desktop a
| 578 | * in the future. Further research is needed to resolve the problem. |
| 579 | */ |
| 580 | static int parse_codec(AVFormatContext *s) |
| 581 | { |
| 582 | int i, ret = 0; |
| 583 | WHIPContext *whip = s->priv_data; |
| 584 | |
| 585 | for (i = 0; i < s->nb_streams; i++) { |
| 586 | AVCodecParameters *par = s->streams[i]->codecpar; |
| 587 | switch (par->codec_type) { |
| 588 | case AVMEDIA_TYPE_VIDEO: |
| 589 | whip->video_par = par; |
| 590 | |
| 591 | if (par->video_delay > 0) { |
| 592 | av_log(whip, AV_LOG_ERROR, "Unsupported B frames by RTC\n"); |
| 593 | return AVERROR_PATCHWELCOME; |
| 594 | } |
| 595 | |
| 596 | if ((ret = parse_profile_level(s, par)) < 0) { |
| 597 | av_log(whip, AV_LOG_ERROR, "Failed to parse SPS/PPS from extradata\n"); |
| 598 | return AVERROR(EINVAL); |
| 599 | } |
| 600 | |
| 601 | if (par->profile == AV_PROFILE_UNKNOWN) { |
| 602 | av_log(whip, AV_LOG_WARNING, "No profile found in extradata, consider baseline\n"); |
| 603 | return AVERROR(EINVAL); |
| 604 | } |
| 605 | if (par->level == AV_LEVEL_UNKNOWN) { |
| 606 | av_log(whip, AV_LOG_WARNING, "No level found in extradata, consider 3.1\n"); |
| 607 | return AVERROR(EINVAL); |
| 608 | } |
| 609 | break; |
| 610 | case AVMEDIA_TYPE_AUDIO: |
| 611 | whip->audio_par = par; |
| 612 | |
| 613 | if (par->ch_layout.nb_channels != 2) { |
| 614 | av_log(whip, AV_LOG_ERROR, "Unsupported audio channels %d by RTC, choose stereo\n", |
| 615 | par->ch_layout.nb_channels); |
| 616 | return AVERROR_PATCHWELCOME; |
| 617 | } |
| 618 | |
| 619 | if (par->sample_rate != 48000) { |
| 620 | av_log(whip, AV_LOG_ERROR, "Unsupported audio sample rate %d by RTC, choose 48000\n", par->sample_rate); |
| 621 | return AVERROR_PATCHWELCOME; |
| 622 | } |
| 623 | break; |
| 624 | default: |
| 625 | av_unreachable("already checked via FF_OFMT flags"); |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | return ret; |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * Generate SDP offer according to the codec parameters, DTLS and ICE information. |
no test coverage detected