Unified · Split
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | * RTP Depacketization of Opus, RFC 7587 |
| 3 | 3 | * Copyright (c) 2025 Jonathan Baudanza <jon@jonb.org> |
| 4 | + * Copyright (c) 2022 Erik Linge | |
| 4 | 5 | * |
| 5 | 6 | * This file is part of FFmpeg. |
| 6 | 7 | * |
| @@ -21,6 +22,7 @@ · 14 unmodified lines | ||
| 21 | 22 | |
| 22 | 23 | #include "libavcodec/bytestream.h" |
| 23 | 24 | #include "libavutil/mem.h" |
| 25 | +#include "libavutil/avstring.h" | |
| 24 | 26 | #include "rtpdec_formats.h" |
| 25 | 27 | #include "internal.h" |
| 26 | 28 | |
| @@ -108,10 +110,42 @@ static int opus_parse_packet(AVFormatContext *ctx, PayloadContext *data, · 81 unmodified lines | ||
| 108 | 110 | return 0; |
| 109 | 111 | } |
| 110 | 112 | |
| 113 | +static int parse_fmtp(AVFormatContext *s, | |
| 114 | + AVStream *stream, PayloadContext *data, | |
| 115 | + const char *attr, const char *value) | |
| 116 | +{ | |
| 117 | + if (!strcmp(attr, "sprop-maxcapturerate")) { | |
| 118 | + int rate = atoi(value); | |
| 119 | + if (rate < 8000 || rate > 48000) { | |
| 120 | + av_log(s, AV_LOG_ERROR, | |
| 121 | + "fmtp field 'sprop-maxcapturerate' must be between 8000 to 48000 (provided value: %s)", | |
| 122 | + value); | |
| 123 | + return AVERROR_INVALIDDATA; | |
| 124 | + } | |
| 125 | + stream->codecpar->sample_rate = rate; | |
| 126 | + } | |
| 127 | + return 0; | |
| 128 | +} | |
| 129 | + | |
| 130 | +static int opus_parse_sdp_line(AVFormatContext *s, int st_index, | |
| 131 | + PayloadContext *data, const char *line) | |
| 132 | +{ | |
| 133 | + const char *p; | |
| 134 | + | |
| 135 | + if (st_index < 0) | |
| 136 | + return 0; | |
| 137 | + | |
| 138 | + if (av_strstart(line, "fmtp:", &p)) { | |
| 139 | + return ff_parse_fmtp(s, s->streams[st_index], data, p, parse_fmtp); | |
| 140 | + } | |
| 141 | + return 0; | |
| 142 | +} | |
| 143 | + | |
| 111 | 144 | const RTPDynamicProtocolHandler ff_opus_dynamic_handler = { |
| 112 | 145 | .enc_name = "opus", |
| 113 | 146 | .codec_type = AVMEDIA_TYPE_AUDIO, |
| 114 | 147 | .codec_id = AV_CODEC_ID_OPUS, |
| 115 | 148 | .parse_packet = opus_parse_packet, |
| 116 | 149 | .init = opus_init, |
| 150 | + .parse_sdp_a_line = opus_parse_sdp_line, | |
| 117 | 151 | }; |