[FFmpeg-devel] [PATCH 1/2] rtpdec: add fmtp parsing of sprop-maxcapturerate for opus
Tristan Matthews
httamt at protonmail.com
Thu May 22 22:55:42 EEST 2025
Hi,
On Monday, May 5th, 2025 at 4:07 PM, Marvin Scholz <epirat07 at gmail.com> wrote:
> From: Erik Linge erikli at axis.com
>
>
> Co-authored-by: Marvin Scholz epirat07 at gmail.com
>
> Signed-off-by: Marvin Scholz epirat07 at gmail.com
>
> ---
> libavformat/Makefile | 1 +
> libavformat/rtpdec.c | 8 +----
> libavformat/rtpdec_formats.h | 1 +
> libavformat/rtpdec_opus.c | 62 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 65 insertions(+), 7 deletions(-)
> create mode 100644 libavformat/rtpdec_opus.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 6c9992adab..ee68345858 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -62,6 +62,7 @@ OBJS-$(CONFIG_RTPDEC) += rdt.o \
> rtpdec_mpeg12.o \
> rtpdec_mpeg4.o \
> rtpdec_mpegts.o \
> + rtpdec_opus.o \
> rtpdec_qcelp.o \
> rtpdec_qdm2.o \
> rtpdec_qt.o \
> diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
> index a7d5a79a83..10e9502ae2 100644
> --- a/libavformat/rtpdec.c
> +++ b/libavformat/rtpdec.c
> @@ -61,12 +61,6 @@ static const RTPDynamicProtocolHandler speex_dynamic_handler = {
> .codec_id = AV_CODEC_ID_SPEEX,
> };
>
> -static const RTPDynamicProtocolHandler opus_dynamic_handler = {
> - .enc_name = "opus",
> - .codec_type = AVMEDIA_TYPE_AUDIO,
> - .codec_id = AV_CODEC_ID_OPUS,
> -};
> -
> static const RTPDynamicProtocolHandler t140_dynamic_handler = { /* RFC 4103 */
> .enc_name = "t140",
> .codec_type = AVMEDIA_TYPE_SUBTITLE,
> @@ -110,6 +104,7 @@ static const RTPDynamicProtocolHandler *const rtp_dynamic_protocol_handler_list[
> &ff_mpegts_dynamic_handler,
> &ff_ms_rtp_asf_pfa_handler,
> &ff_ms_rtp_asf_pfv_handler,
> + &ff_opus_dynamic_handler,
> &ff_qcelp_dynamic_handler,
> &ff_qdm2_dynamic_handler,
> &ff_qt_rtp_aud_handler,
> @@ -125,7 +120,6 @@ static const RTPDynamicProtocolHandler const rtp_dynamic_protocol_handler_list[
> &ff_vp9_dynamic_handler,
> &gsm_dynamic_handler,
> &l24_dynamic_handler,
> - &opus_dynamic_handler,
> &realmedia_mp3_dynamic_handler,
> &speex_dynamic_handler,
> &t140_dynamic_handler,
> diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h
> index 72a8f16a90..1ff2a72d2a 100644
> --- a/libavformat/rtpdec_formats.h
> +++ b/libavformat/rtpdec_formats.h
> @@ -77,6 +77,7 @@ extern const RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler;
> extern const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler;
> extern const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfa_handler;
> extern const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler;
> +extern const RTPDynamicProtocolHandler ff_opus_dynamic_handler;
> extern const RTPDynamicProtocolHandler ff_qcelp_dynamic_handler;
> extern const RTPDynamicProtocolHandler ff_qdm2_dynamic_handler;
> extern const RTPDynamicProtocolHandler ff_qt_rtp_aud_handler;
> diff --git a/libavformat/rtpdec_opus.c b/libavformat/rtpdec_opus.c
> new file mode 100644
> index 0000000000..60ff2244b6
> --- /dev/null
> +++ b/libavformat/rtpdec_opus.c
> @@ -0,0 +1,62 @@
> +/
> + * RTP OPUS Depacketizer, RFC 7587
> + * Copyright (c) 2022 Erik Linge
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "avformat.h"
> +#include "rtpdec_formats.h"
> +#include "libavutil/avstring.h"
> +
> +static int parse_fmtp(AVFormatContext *s,
> + AVStream *stream, PayloadContext *data,
> + const char *attr, const char *value)
> +{
> + if (!strcmp(attr, "sprop-maxcapturerate")) {
> + int rate = atoi(value);
> + if (rate < 8000 || rate > 48000) {
>
> + av_log(s, AV_LOG_ERROR,
> + "fmtp field 'sprop-maxcapturerate' must be between 8000 to 48000 (provided value: %s)",
> + value);
> + return AVERROR_INVALIDDATA;
> + }
> + stream->codecpar->sample_rate = rate;
>
> + }
> + return 0;
> +}
> +
> +static int opus_parse_sdp_line(AVFormatContext *s, int st_index,
> + PayloadContext *data, const char *line)
> +{
> + const char *p;
> +
> + if (st_index < 0)
> + return 0;
> +
> + if (av_strstart(line, "fmtp:", &p)) {
> + return ff_parse_fmtp(s, s->streams[st_index], data, p, parse_fmtp);
>
> + }
> + return 0;
> +}
> +
> +const RTPDynamicProtocolHandler ff_opus_dynamic_handler = {
> + .enc_name = "opus",
> + .codec_type = AVMEDIA_TYPE_AUDIO,
> + .codec_id = AV_CODEC_ID_OPUS,
> + .parse_sdp_a_line = opus_parse_sdp_line,
> +};
> --
> 2.39.5 (Apple Git-154)
LGTM.
Best,
Tristan
More information about the ffmpeg-devel
mailing list