History

libavformat/rtpdec_opus: add fmtp parsing of sprop-maxcapturerate

Erik Linge committed 4 years ago

Commit f5663921 parent 2a180c71 file · +34 −0Browse files

Unified · Split

libavformat/rtpdec_opus.c+34−0
@@ -1,6 +1,7 @@
11 /*
22 * RTP Depacketization of Opus, RFC 7587
33 * Copyright (c) 2025 Jonathan Baudanza <jon@jonb.org>
4+ * Copyright (c) 2022 Erik Linge
45 *
56 * This file is part of FFmpeg.
67 *
@@ -21,6 +22,7 @@ · 14 unmodified lines
2122
2223 #include "libavcodec/bytestream.h"
2324 #include "libavutil/mem.h"
25+#include "libavutil/avstring.h"
2426 #include "rtpdec_formats.h"
2527 #include "internal.h"
2628
@@ -108,10 +110,42 @@ static int opus_parse_packet(AVFormatContext *ctx, PayloadContext *data, · 81 unmodified lines
108110 return 0;
109111 }
110112
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+
111144 const RTPDynamicProtocolHandler ff_opus_dynamic_handler = {
112145 .enc_name = "opus",
113146 .codec_type = AVMEDIA_TYPE_AUDIO,
114147 .codec_id = AV_CODEC_ID_OPUS,
115148 .parse_packet = opus_parse_packet,
116149 .init = opus_init,
150+ .parse_sdp_a_line = opus_parse_sdp_line,
117151 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t