From patchwork Sat Dec 4 17:32:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31959 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2267757iog; Sat, 4 Dec 2021 09:33:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoXTdYwHoEca4UWNL2Mrrdu0v5R5BGewNykIhUryhbb6V9PGubNgLb4bKUcaTarf52O/dt X-Received: by 2002:a05:6402:60c:: with SMTP id n12mr37845625edv.17.1638639203855; Sat, 04 Dec 2021 09:33:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638639203; cv=none; d=google.com; s=arc-20160816; b=0AVoWzBybdiKzpJlVbi8OF1ul8Cpt7jHK5d/lamCoQxE4oq8Sv5oWd+W8HliBQzc/0 kfdp7LgbQtD1lSLoHcDLJ12X+hcYG4fz0Tx0Pt6lwqvD3pCuqpJde4lJ7WOf7fCWQiF+ /yZ94MIAr24Hex1GUXwvmbJ8uciwKWOBf2C0GsPGsXxmvnjuYQzRMweMAwWbGZSN245l EYnnDuchJy4geft2C8lQjkqZfwTTYvcVP18IVbV+OxncW8iPTEzQvhApzE8tNKl1JvO1 kMNI7kDHJILHUaRhHgMr5KvydPPuFCW9j8WodojZFIAu4+ZvUIZBUoKABRNHsk5CYnXL a5Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=kMfuCqEdU2fzdRHxdjdM69Ew1dBgB1nNsJA93I125mA=; b=kTWTEGLNGJ+zIlvbwR9upwjnCAxRWHl0IZ/FTg2+tjP9c7qVw6d962JSARO21F8lXE wUbP3dzjq/b719Il2FNcAxH1JdwHmmG0UXj1wK7dS0MkrE1gKqmU1rApkPzh4YUZx1Ca 9RgkGTO0Mhu7JhsNXIBffIu1CTb/0BFjGkP9UmDm/Nio37tQLekolqS9NMURJZcAaCBJ EBvlBEdFrij3T2rXUtjieJE/S5Bw29E0U5CAJbokHvAPCsPiQOIDALsyyHVct5HDZsb3 INIEiS+90Yw+MdxEiUg9Co6OhEYS31ShKY3FHV1Zx7sS162Bx2Mufk+G4anAmIOpK/Zy zJTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e13si13173110edz.50.2021.12.04.09.33.22; Sat, 04 Dec 2021 09:33:23 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6ABF068AAA0; Sat, 4 Dec 2021 19:33:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40686680CB2 for ; Sat, 4 Dec 2021 19:33:11 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A396B24017E for ; Sat, 4 Dec 2021 18:33:10 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id lTbHEZ1X1Tgj for ; Sat, 4 Dec 2021 18:33:09 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2CBF4240179 for ; Sat, 4 Dec 2021 18:33:09 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1794C3A0631; Sat, 4 Dec 2021 18:33:09 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Dec 2021 18:32:58 +0100 Message-Id: <20211204173300.5742-1-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavf/sdp: add const qualifiers where appropriate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: u9QykxIEABRj Declares that these structs are read-only for this code. --- libavformat/internal.h | 2 +- libavformat/rtp.c | 4 ++-- libavformat/rtp.h | 4 ++-- libavformat/sdp.c | 21 +++++++++++---------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index 20e93d9267..528ff7e017 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -546,7 +546,7 @@ uint64_t ff_parse_ntp_time(uint64_t ntp_ts); * @param fmt the AVFormatContext, which might contain options modifying * the generated SDP */ -void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, +void ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx, const char *dest_addr, const char *dest_type, int port, int ttl, AVFormatContext *fmt); diff --git a/libavformat/rtp.c b/libavformat/rtp.c index 38e234391b..c536a6f082 100644 --- a/libavformat/rtp.c +++ b/libavformat/rtp.c @@ -87,8 +87,8 @@ int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type) return -1; } -int ff_rtp_get_payload_type(AVFormatContext *fmt, - AVCodecParameters *par, int idx) +int ff_rtp_get_payload_type(const AVFormatContext *fmt, + const AVCodecParameters *par, int idx) { int i; const AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL; diff --git a/libavformat/rtp.h b/libavformat/rtp.h index 389b824223..0c0e6089d7 100644 --- a/libavformat/rtp.h +++ b/libavformat/rtp.h @@ -38,8 +38,8 @@ * @param idx The stream index * @return The payload type (the 'PT' field in the RTP header). */ -int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecParameters *par, - int idx); +int ff_rtp_get_payload_type(const AVFormatContext *fmt, + const AVCodecParameters *par, int idx); /** * Initialize a codec context based on the payload type. diff --git a/libavformat/sdp.c b/libavformat/sdp.c index a41c2cf655..ec5f7b763d 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -151,7 +151,7 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) } #define MAX_PSET_SIZE 1024 -static char *extradata2psets(AVFormatContext *s, AVCodecParameters *par) +static char *extradata2psets(AVFormatContext *s, const AVCodecParameters *par) { char *psets, *p; const uint8_t *r; @@ -223,7 +223,7 @@ static char *extradata2psets(AVFormatContext *s, AVCodecParameters *par) return psets; } -static char *extradata2psets_hevc(AVCodecParameters *par) +static char *extradata2psets_hevc(const AVCodecParameters *par) { char *psets; uint8_t *extradata = par->extradata; @@ -324,7 +324,7 @@ err: return NULL; } -static char *extradata2config(AVFormatContext *s, AVCodecParameters *par) +static char *extradata2config(AVFormatContext *s, const AVCodecParameters *par) { char *config; @@ -345,7 +345,7 @@ static char *extradata2config(AVFormatContext *s, AVCodecParameters *par) return config; } -static char *xiph_extradata2config(AVFormatContext *s, AVCodecParameters *par) +static char *xiph_extradata2config(AVFormatContext *s, const AVCodecParameters *par) { uint8_t *config; char *encoded_config; @@ -415,7 +415,7 @@ xiph_fail: return NULL; } -static int latm_context2profilelevel(AVCodecParameters *par) +static int latm_context2profilelevel(const AVCodecParameters *par) { /* MP4A-LATM * The RTP payload format specification is described in RFC 3016 @@ -444,7 +444,7 @@ static int latm_context2profilelevel(AVCodecParameters *par) return profile_level; } -static char *latm_context2config(AVFormatContext *s, AVCodecParameters *par) +static char *latm_context2config(AVFormatContext *s, const AVCodecParameters *par) { /* MP4A-LATM * The RTP payload format specification is described in RFC 3016 @@ -480,10 +480,11 @@ static char *latm_context2config(AVFormatContext *s, AVCodecParameters *par) return config; } -static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int payload_type, AVFormatContext *fmt) +static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st, + int payload_type, AVFormatContext *fmt) { char *config = NULL; - AVCodecParameters *p = st->codecpar; + const AVCodecParameters *p = st->codecpar; switch (p->codec_id) { case AV_CODEC_ID_DIRAC: @@ -765,11 +766,11 @@ static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int return buff; } -void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, +void ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx, const char *dest_addr, const char *dest_type, int port, int ttl, AVFormatContext *fmt) { - AVCodecParameters *p = st->codecpar; + const AVCodecParameters *p = st->codecpar; const char *type; int payload_type; From patchwork Sat Dec 4 17:32:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31958 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2267925iog; Sat, 4 Dec 2021 09:33:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+h9XBTc7FgjJ97lmvbt9P8LvvPBVaNz8qGGRGkKrBW/gSvVlsy1oxLK/PjSzvP60jdFwv X-Received: by 2002:a17:907:720b:: with SMTP id dr11mr33256867ejc.93.1638639214595; Sat, 04 Dec 2021 09:33:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638639214; cv=none; d=google.com; s=arc-20160816; b=PyrjR+5d+x3Un3uTymx0jDQH6eiMO9Gzg1Uq7ras9LgOuRgV0t1hZZwtfkw11ssEYq IPU4RBRbQtmETDzAbpMramX7NpSG0k//IDEibr5oOiEFsP2mZgWpG2mc29A5aObgNd/V 6H/+8Bq7fcK50dI7972v9p+QfnDo+Ke9vLORR+MCWXka+JZw079NWUuQQ8cLAZYEMV2m oLfUeQm+VlnSMdqK5DJPvIFvR33YS8hteHHymxBF1UNX0EgCs6OnLITYXMWUGg52dtKJ GKKENoRaH3miIZGbu4zAhXP+36caASkF9uGsLtkL0RQrsZ5LZ0Lxmm5MuEL1zJyqRnLI 6KkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=vqfjFkmmdy1jU+cpO2kWQ5AxWgtKS/dzmj9/grzL5OI=; b=PKKppgNsWw1nlGyBjO4WhdBkYu9mZ1Rd6bfJh2fe1kRI20NqnESq7T2IUyOav9l/SY FS59hhvtjRGfFVAY34V1uoqBANplY3wwx6NTjno7mGbSApceeSzkdlB+l5/DjGhfcYMW JcNEnpym8xQEP0EfpmedtXeLiq8vKhJPgR5pttOSt1qxAPBouUXbncxhnpO3fkdlxN0/ qlFcN3tGnKZgUZXQqfB4odHKRPbPzheuoQv9IGPSyV7hX+RdNL6AqtwvZagq6tixuLDF JpPOgV/WFdvZAYuNJCE5z/uHK+WXaeIT6QpxUJsgDozyGWs6AooA4oorFYLw2jMXSN+A gk0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w26si10026941edl.90.2021.12.04.09.33.34; Sat, 04 Dec 2021 09:33:34 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8103368AE3E; Sat, 4 Dec 2021 19:33:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7A9DA680CB2 for ; Sat, 4 Dec 2021 19:33:11 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 20181240179 for ; Sat, 4 Dec 2021 18:33:11 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id UWJQVtVooKyt for ; Sat, 4 Dec 2021 18:33:09 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 36F8224017A for ; Sat, 4 Dec 2021 18:33:09 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1C1813A067C; Sat, 4 Dec 2021 18:33:09 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Dec 2021 18:32:59 +0100 Message-Id: <20211204173300.5742-2-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211204173300.5742-1-anton@khirnov.net> References: <20211204173300.5742-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavf/sdp: reindent switch() according to our conventions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 5CwmS5UYK2t/ --- libavformat/sdp.c | 504 +++++++++++++++++++++++----------------------- 1 file changed, 252 insertions(+), 252 deletions(-) diff --git a/libavformat/sdp.c b/libavformat/sdp.c index ec5f7b763d..1cdd21c97b 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -487,278 +487,278 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st const AVCodecParameters *p = st->codecpar; switch (p->codec_id) { - case AV_CODEC_ID_DIRAC: - av_strlcatf(buff, size, "a=rtpmap:%d VC2/90000\r\n", payload_type); - break; - case AV_CODEC_ID_H264: { - int mode = 1; - if (fmt && fmt->oformat && fmt->oformat->priv_class && - av_opt_flag_is_set(fmt->priv_data, "rtpflags", "h264_mode0")) - mode = 0; - if (p->extradata_size) { - config = extradata2psets(fmt, p); - } - av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n" - "a=fmtp:%d packetization-mode=%d%s\r\n", - payload_type, - payload_type, mode, config ? config : ""); - break; + case AV_CODEC_ID_DIRAC: + av_strlcatf(buff, size, "a=rtpmap:%d VC2/90000\r\n", payload_type); + break; + case AV_CODEC_ID_H264: { + int mode = 1; + if (fmt && fmt->oformat && fmt->oformat->priv_class && + av_opt_flag_is_set(fmt->priv_data, "rtpflags", "h264_mode0")) + mode = 0; + if (p->extradata_size) { + config = extradata2psets(fmt, p); } - case AV_CODEC_ID_H261: - { - const char *pic_fmt = NULL; - /* only QCIF and CIF are specified as supported in RFC 4587 */ - if (p->width == 176 && p->height == 144) - pic_fmt = "QCIF=1"; - else if (p->width == 352 && p->height == 288) - pic_fmt = "CIF=1"; - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d H261/90000\r\n", payload_type); - if (pic_fmt) - av_strlcatf(buff, size, "a=fmtp:%d %s\r\n", payload_type, pic_fmt); - break; + av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n" + "a=fmtp:%d packetization-mode=%d%s\r\n", + payload_type, + payload_type, mode, config ? config : ""); + break; + } + case AV_CODEC_ID_H261: + { + const char *pic_fmt = NULL; + /* only QCIF and CIF are specified as supported in RFC 4587 */ + if (p->width == 176 && p->height == 144) + pic_fmt = "QCIF=1"; + else if (p->width == 352 && p->height == 288) + pic_fmt = "CIF=1"; + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d H261/90000\r\n", payload_type); + if (pic_fmt) + av_strlcatf(buff, size, "a=fmtp:%d %s\r\n", payload_type, pic_fmt); + break; + } + case AV_CODEC_ID_H263: + case AV_CODEC_ID_H263P: + /* a=framesize is required by 3GPP TS 26.234 (PSS). It + * actually specifies the maximum video size, but we only know + * the current size. This is required for playback on Android + * stagefright and on Samsung bada. */ + if (!fmt || !fmt->oformat->priv_class || + !av_opt_flag_is_set(fmt->priv_data, "rtpflags", "rfc2190") || + p->codec_id == AV_CODEC_ID_H263P) + av_strlcatf(buff, size, "a=rtpmap:%d H263-2000/90000\r\n" + "a=framesize:%d %d-%d\r\n", + payload_type, + payload_type, p->width, p->height); + break; + case AV_CODEC_ID_HEVC: + if (p->extradata_size) + config = extradata2psets_hevc(p); + av_strlcatf(buff, size, "a=rtpmap:%d H265/90000\r\n", payload_type); + if (config) + av_strlcatf(buff, size, "a=fmtp:%d %s\r\n", + payload_type, config); + break; + case AV_CODEC_ID_MPEG4: + if (p->extradata_size) { + config = extradata2config(fmt, p); } - case AV_CODEC_ID_H263: - case AV_CODEC_ID_H263P: - /* a=framesize is required by 3GPP TS 26.234 (PSS). It - * actually specifies the maximum video size, but we only know - * the current size. This is required for playback on Android - * stagefright and on Samsung bada. */ - if (!fmt || !fmt->oformat->priv_class || - !av_opt_flag_is_set(fmt->priv_data, "rtpflags", "rfc2190") || - p->codec_id == AV_CODEC_ID_H263P) - av_strlcatf(buff, size, "a=rtpmap:%d H263-2000/90000\r\n" - "a=framesize:%d %d-%d\r\n", - payload_type, - payload_type, p->width, p->height); - break; - case AV_CODEC_ID_HEVC: - if (p->extradata_size) - config = extradata2psets_hevc(p); - av_strlcatf(buff, size, "a=rtpmap:%d H265/90000\r\n", payload_type); - if (config) - av_strlcatf(buff, size, "a=fmtp:%d %s\r\n", - payload_type, config); - break; - case AV_CODEC_ID_MPEG4: + av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n" + "a=fmtp:%d profile-level-id=1%s\r\n", + payload_type, + payload_type, config ? config : ""); + break; + case AV_CODEC_ID_AAC: + if (fmt && fmt->oformat && fmt->oformat->priv_class && + av_opt_flag_is_set(fmt->priv_data, "rtpflags", "latm")) { + config = latm_context2config(fmt, p); + if (!config) + return NULL; + av_strlcatf(buff, size, "a=rtpmap:%d MP4A-LATM/%d/%d\r\n" + "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n", + payload_type, p->sample_rate, p->channels, + payload_type, latm_context2profilelevel(p), config); + } else { if (p->extradata_size) { config = extradata2config(fmt, p); - } - av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n" - "a=fmtp:%d profile-level-id=1%s\r\n", - payload_type, - payload_type, config ? config : ""); - break; - case AV_CODEC_ID_AAC: - if (fmt && fmt->oformat && fmt->oformat->priv_class && - av_opt_flag_is_set(fmt->priv_data, "rtpflags", "latm")) { - config = latm_context2config(fmt, p); - if (!config) - return NULL; - av_strlcatf(buff, size, "a=rtpmap:%d MP4A-LATM/%d/%d\r\n" - "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n", - payload_type, p->sample_rate, p->channels, - payload_type, latm_context2profilelevel(p), config); } else { - if (p->extradata_size) { - config = extradata2config(fmt, p); - } else { - /* FIXME: maybe we can forge config information based on the - * codec parameters... - */ - av_log(fmt, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); - return NULL; - } - if (!config) { - return NULL; - } - av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" - "a=fmtp:%d profile-level-id=1;" - "mode=AAC-hbr;sizelength=13;indexlength=3;" - "indexdeltalength=3%s\r\n", - payload_type, p->sample_rate, p->channels, - payload_type, config); - } - break; - case AV_CODEC_ID_PCM_S16BE: - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d L16/%d/%d\r\n", - payload_type, - p->sample_rate, p->channels); - break; - case AV_CODEC_ID_PCM_S24BE: - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d L24/%d/%d\r\n", - payload_type, - p->sample_rate, p->channels); - break; - case AV_CODEC_ID_PCM_MULAW: - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d PCMU/%d/%d\r\n", - payload_type, - p->sample_rate, p->channels); - break; - case AV_CODEC_ID_PCM_ALAW: - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d PCMA/%d/%d\r\n", - payload_type, - p->sample_rate, p->channels); - break; - case AV_CODEC_ID_AMR_NB: - av_strlcatf(buff, size, "a=rtpmap:%d AMR/%d/%d\r\n" - "a=fmtp:%d octet-align=1\r\n", - payload_type, p->sample_rate, p->channels, - payload_type); - break; - case AV_CODEC_ID_AMR_WB: - av_strlcatf(buff, size, "a=rtpmap:%d AMR-WB/%d/%d\r\n" - "a=fmtp:%d octet-align=1\r\n", - payload_type, p->sample_rate, p->channels, - payload_type); - break; - case AV_CODEC_ID_VORBIS: - if (p->extradata_size) - config = xiph_extradata2config(fmt, p); - else - av_log(fmt, AV_LOG_ERROR, "Vorbis configuration info missing\n"); - if (!config) - return NULL; - - av_strlcatf(buff, size, "a=rtpmap:%d vorbis/%d/%d\r\n" - "a=fmtp:%d configuration=%s\r\n", - payload_type, p->sample_rate, p->channels, - payload_type, config); - break; - case AV_CODEC_ID_THEORA: { - const char *pix_fmt; - switch (p->format) { - case AV_PIX_FMT_YUV420P: - pix_fmt = "YCbCr-4:2:0"; - break; - case AV_PIX_FMT_YUV422P: - pix_fmt = "YCbCr-4:2:2"; - break; - case AV_PIX_FMT_YUV444P: - pix_fmt = "YCbCr-4:4:4"; - break; - default: - av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); + /* FIXME: maybe we can forge config information based on the + * codec parameters... + */ + av_log(fmt, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); return NULL; } - - if (p->extradata_size) - config = xiph_extradata2config(fmt, p); - else - av_log(fmt, AV_LOG_ERROR, "Theora configuration info missing\n"); - if (!config) - return NULL; - - av_strlcatf(buff, size, "a=rtpmap:%d theora/90000\r\n" - "a=fmtp:%d delivery-method=inline; " - "width=%d; height=%d; sampling=%s; " - "configuration=%s\r\n", - payload_type, payload_type, - p->width, p->height, pix_fmt, config); - break; - } - case AV_CODEC_ID_BITPACKED: - case AV_CODEC_ID_RAWVIDEO: { - const char *pix_fmt; - int bit_depth = 8; - - switch (p->format) { - case AV_PIX_FMT_UYVY422: - pix_fmt = "YCbCr-4:2:2"; - break; - case AV_PIX_FMT_YUV422P10: - pix_fmt = "YCbCr-4:2:2"; - bit_depth = 10; - break; - case AV_PIX_FMT_YUV420P: - pix_fmt = "YCbCr-4:2:0"; - break; - case AV_PIX_FMT_RGB24: - pix_fmt = "RGB"; - break; - case AV_PIX_FMT_BGR24: - pix_fmt = "BGR"; - break; - default: - av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); + if (!config) { return NULL; } - - av_strlcatf(buff, size, "a=rtpmap:%d raw/90000\r\n" - "a=fmtp:%d sampling=%s; " - "width=%d; height=%d; " - "depth=%d\r\n", - payload_type, payload_type, - pix_fmt, p->width, p->height, bit_depth); - break; + av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" + "a=fmtp:%d profile-level-id=1;" + "mode=AAC-hbr;sizelength=13;indexlength=3;" + "indexdeltalength=3%s\r\n", + payload_type, p->sample_rate, p->channels, + payload_type, config); } + break; + case AV_CODEC_ID_PCM_S16BE: + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d L16/%d/%d\r\n", + payload_type, + p->sample_rate, p->channels); + break; + case AV_CODEC_ID_PCM_S24BE: + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d L24/%d/%d\r\n", + payload_type, + p->sample_rate, p->channels); + break; + case AV_CODEC_ID_PCM_MULAW: + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d PCMU/%d/%d\r\n", + payload_type, + p->sample_rate, p->channels); + break; + case AV_CODEC_ID_PCM_ALAW: + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d PCMA/%d/%d\r\n", + payload_type, + p->sample_rate, p->channels); + break; + case AV_CODEC_ID_AMR_NB: + av_strlcatf(buff, size, "a=rtpmap:%d AMR/%d/%d\r\n" + "a=fmtp:%d octet-align=1\r\n", + payload_type, p->sample_rate, p->channels, + payload_type); + break; + case AV_CODEC_ID_AMR_WB: + av_strlcatf(buff, size, "a=rtpmap:%d AMR-WB/%d/%d\r\n" + "a=fmtp:%d octet-align=1\r\n", + payload_type, p->sample_rate, p->channels, + payload_type); + break; + case AV_CODEC_ID_VORBIS: + if (p->extradata_size) + config = xiph_extradata2config(fmt, p); + else + av_log(fmt, AV_LOG_ERROR, "Vorbis configuration info missing\n"); + if (!config) + return NULL; - case AV_CODEC_ID_VP8: - av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n", - payload_type); - break; - case AV_CODEC_ID_VP9: - av_strlcatf(buff, size, "a=rtpmap:%d VP9/90000\r\n", - payload_type); - break; - case AV_CODEC_ID_MJPEG: - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d JPEG/90000\r\n", - payload_type); + av_strlcatf(buff, size, "a=rtpmap:%d vorbis/%d/%d\r\n" + "a=fmtp:%d configuration=%s\r\n", + payload_type, p->sample_rate, p->channels, + payload_type, config); + break; + case AV_CODEC_ID_THEORA: { + const char *pix_fmt; + switch (p->format) { + case AV_PIX_FMT_YUV420P: + pix_fmt = "YCbCr-4:2:0"; break; - case AV_CODEC_ID_ADPCM_G722: - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d G722/%d/%d\r\n", - payload_type, - 8000, p->channels); + case AV_PIX_FMT_YUV422P: + pix_fmt = "YCbCr-4:2:2"; break; - case AV_CODEC_ID_ADPCM_G726: { - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d AAL2-G726-%d/%d\r\n", - payload_type, - p->bits_per_coded_sample*8, - p->sample_rate); + case AV_PIX_FMT_YUV444P: + pix_fmt = "YCbCr-4:4:4"; break; + default: + av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); + return NULL; } - case AV_CODEC_ID_ADPCM_G726LE: { - if (payload_type >= RTP_PT_PRIVATE) - av_strlcatf(buff, size, "a=rtpmap:%d G726-%d/%d\r\n", - payload_type, - p->bits_per_coded_sample*8, - p->sample_rate); + + if (p->extradata_size) + config = xiph_extradata2config(fmt, p); + else + av_log(fmt, AV_LOG_ERROR, "Theora configuration info missing\n"); + if (!config) + return NULL; + + av_strlcatf(buff, size, "a=rtpmap:%d theora/90000\r\n" + "a=fmtp:%d delivery-method=inline; " + "width=%d; height=%d; sampling=%s; " + "configuration=%s\r\n", + payload_type, payload_type, + p->width, p->height, pix_fmt, config); + break; + } + case AV_CODEC_ID_BITPACKED: + case AV_CODEC_ID_RAWVIDEO: { + const char *pix_fmt; + int bit_depth = 8; + + switch (p->format) { + case AV_PIX_FMT_UYVY422: + pix_fmt = "YCbCr-4:2:2"; break; - } - case AV_CODEC_ID_ILBC: - av_strlcatf(buff, size, "a=rtpmap:%d iLBC/%d\r\n" - "a=fmtp:%d mode=%d\r\n", - payload_type, p->sample_rate, - payload_type, p->block_align == 38 ? 20 : 30); + case AV_PIX_FMT_YUV422P10: + pix_fmt = "YCbCr-4:2:2"; + bit_depth = 10; break; - case AV_CODEC_ID_SPEEX: - av_strlcatf(buff, size, "a=rtpmap:%d speex/%d\r\n", - payload_type, p->sample_rate); + case AV_PIX_FMT_YUV420P: + pix_fmt = "YCbCr-4:2:0"; break; - case AV_CODEC_ID_OPUS: - /* The opus RTP draft says that all opus streams MUST be declared - as stereo, to avoid negotiation failures. The actual number of - channels can change on a packet-by-packet basis. The number of - channels a receiver prefers to receive or a sender plans to send - can be declared via fmtp parameters (both default to mono), but - receivers MUST be able to receive and process stereo packets. */ - av_strlcatf(buff, size, "a=rtpmap:%d opus/48000/2\r\n", - payload_type); - if (p->channels == 2) { - av_strlcatf(buff, size, "a=fmtp:%d sprop-stereo=1\r\n", - payload_type); - } + case AV_PIX_FMT_RGB24: + pix_fmt = "RGB"; break; - default: - /* Nothing special to do here... */ + case AV_PIX_FMT_BGR24: + pix_fmt = "BGR"; break; + default: + av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); + return NULL; + } + + av_strlcatf(buff, size, "a=rtpmap:%d raw/90000\r\n" + "a=fmtp:%d sampling=%s; " + "width=%d; height=%d; " + "depth=%d\r\n", + payload_type, payload_type, + pix_fmt, p->width, p->height, bit_depth); + break; + } + + case AV_CODEC_ID_VP8: + av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n", + payload_type); + break; + case AV_CODEC_ID_VP9: + av_strlcatf(buff, size, "a=rtpmap:%d VP9/90000\r\n", + payload_type); + break; + case AV_CODEC_ID_MJPEG: + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d JPEG/90000\r\n", + payload_type); + break; + case AV_CODEC_ID_ADPCM_G722: + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d G722/%d/%d\r\n", + payload_type, + 8000, p->channels); + break; + case AV_CODEC_ID_ADPCM_G726: { + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d AAL2-G726-%d/%d\r\n", + payload_type, + p->bits_per_coded_sample*8, + p->sample_rate); + break; + } + case AV_CODEC_ID_ADPCM_G726LE: { + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d G726-%d/%d\r\n", + payload_type, + p->bits_per_coded_sample*8, + p->sample_rate); + break; + } + case AV_CODEC_ID_ILBC: + av_strlcatf(buff, size, "a=rtpmap:%d iLBC/%d\r\n" + "a=fmtp:%d mode=%d\r\n", + payload_type, p->sample_rate, + payload_type, p->block_align == 38 ? 20 : 30); + break; + case AV_CODEC_ID_SPEEX: + av_strlcatf(buff, size, "a=rtpmap:%d speex/%d\r\n", + payload_type, p->sample_rate); + break; + case AV_CODEC_ID_OPUS: + /* The opus RTP draft says that all opus streams MUST be declared + as stereo, to avoid negotiation failures. The actual number of + channels can change on a packet-by-packet basis. The number of + channels a receiver prefers to receive or a sender plans to send + can be declared via fmtp parameters (both default to mono), but + receivers MUST be able to receive and process stereo packets. */ + av_strlcatf(buff, size, "a=rtpmap:%d opus/48000/2\r\n", + payload_type); + if (p->channels == 2) { + av_strlcatf(buff, size, "a=fmtp:%d sprop-stereo=1\r\n", + payload_type); + } + break; + default: + /* Nothing special to do here... */ + break; } av_free(config); From patchwork Sat Dec 4 17:33:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31960 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2268106iog; Sat, 4 Dec 2021 09:33:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJypqmV14I8UYAupoVI8YhRGmgWqbkb4mI5eVnCIieRP66upLdNdll5wbe/dEFZ5DQhRwRPo X-Received: by 2002:a17:906:d54c:: with SMTP id cr12mr32329540ejc.56.1638639225253; Sat, 04 Dec 2021 09:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638639225; cv=none; d=google.com; s=arc-20160816; b=AttaaD62wjBGhOPEDC/fXcTqwvf/SNN3aNubWRo8olNZ5qT51mPNvZ//lvpFntNoRp YQsVotFg8UZuumVpKdg5ifcAkbbA74u5SkPurzovAPJ8WXyqAOohViZiWcV2rjd/96LZ oZwDal0aQk1ED3aJk6p/Q4TDjdhBj/+cCZL9zJ1b0YbUV9pMLkdDfH0cEOSOVRRs9rad ugWt28oRJm6nmd5oZ5iJoacl6Q2zGQIUHbV61cTIEhFwjI3dYaEfXHdHYQ2oex3x+elD qpquSWAxj2+tzSI8AGeCmfvhSnoQJ5Q//Lx9W8+AVbDm2HBnIHzlLvjae/ixSUMXEylT kKzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=3nXbg5fKDm3uBmFlJBKNG4pY5LnandZK3wwoP8QZQdU=; b=BaBCqedIu6LCxFm2GFBM/GmPB2JcR/2+Z6ytecU4GcYQjQuzHzWl0s0w5dvF/RPF28 FwvSUqG4pdynSYWJ7Bb8/2TYb6tTBCodj2ZBO/VXKftJZuVdbljDS9Yare45wJ6xtB3Q N6iDy8l9N7MU6kwTce3iTHJfm7Fg6/gRjVTeobh/aImNly753W8BPRqIDxc2WD3Yj4pp 0hcI1h8/Uq/lRj8izi192i8jij2d8gFThty3/mDbjD9BkRBoXnO9OtV6yO87ZPYioeTu WKEhpEPvhV4zuzh/GECnO8zc6dbw3C3YRsy8G4kZO0JwXH6w5K6qDveTUbdRlqvqytzn 6fAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id rk27si8769072ejb.268.2021.12.04.09.33.44; Sat, 04 Dec 2021 09:33:45 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 955F868AE57; Sat, 4 Dec 2021 19:33:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 47A4A68AAA0 for ; Sat, 4 Dec 2021 19:33:12 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B56A924017A for ; Sat, 4 Dec 2021 18:33:11 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id sZfL-UUNjR1w for ; Sat, 4 Dec 2021 18:33:10 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6E58224017C for ; Sat, 4 Dec 2021 18:33:09 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 20A7A3A073E; Sat, 4 Dec 2021 18:33:09 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Dec 2021 18:33:00 +0100 Message-Id: <20211204173300.5742-3-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211204173300.5742-1-anton@khirnov.net> References: <20211204173300.5742-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavf/sdp: add more thorough error handling X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: w1Qn7seGoQJT Return error codes when constructing a stream config fails, rather than just disregarding the failure and continuing. Propagate the error codes from av_sdp_create(). --- libavformat/internal.h | 7 +- libavformat/sdp.c | 189 +++++++++++++++++++++++++---------------- 2 files changed, 120 insertions(+), 76 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index 528ff7e017..db1d83be17 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -545,10 +545,11 @@ uint64_t ff_parse_ntp_time(uint64_t ntp_ts); * @param ttl the time to live of the stream, 0 if not multicast * @param fmt the AVFormatContext, which might contain options modifying * the generated SDP + * @return 0 on success, a negative error code on failure */ -void ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx, - const char *dest_addr, const char *dest_type, - int port, int ttl, AVFormatContext *fmt); +int ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx, + const char *dest_addr, const char *dest_type, + int port, int ttl, AVFormatContext *fmt); /** * Write a packet to another muxer than the one the user originally diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 1cdd21c97b..a5aba8a80c 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -151,7 +151,8 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) } #define MAX_PSET_SIZE 1024 -static char *extradata2psets(AVFormatContext *s, const AVCodecParameters *par) +static int extradata2psets(AVFormatContext *s, const AVCodecParameters *par, + char **out) { char *psets, *p; const uint8_t *r; @@ -162,15 +163,18 @@ static char *extradata2psets(AVFormatContext *s, const AVCodecParameters *par) uint8_t *tmpbuf = NULL; const uint8_t *sps = NULL, *sps_end; + *out = NULL; + if (par->extradata_size > MAX_EXTRADATA_SIZE) { av_log(s, AV_LOG_ERROR, "Too much extradata!\n"); - - return NULL; + return AVERROR_INVALIDDATA; } if (par->extradata[0] == 1) { - if (ff_avc_write_annexb_extradata(par->extradata, &extradata, - &extradata_size)) - return NULL; + int ret = ff_avc_write_annexb_extradata(par->extradata, &extradata, + &extradata_size); + if (ret < 0) + return ret; + tmpbuf = extradata; } @@ -178,7 +182,7 @@ static char *extradata2psets(AVFormatContext *s, const AVCodecParameters *par) if (!psets) { av_log(s, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets.\n"); av_free(tmpbuf); - return NULL; + return AVERROR(ENOMEM); } memcpy(psets, pset_string, strlen(pset_string)); p = psets + strlen(pset_string); @@ -203,11 +207,12 @@ static char *extradata2psets(AVFormatContext *s, const AVCodecParameters *par) sps_end = r1; } if (!av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r)) { - av_log(s, AV_LOG_ERROR, "Cannot Base64-encode %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"!\n", MAX_PSET_SIZE - (p - psets), r1 - r); + av_log(s, AV_LOG_ERROR, "Cannot Base64-encode %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"!\n", + MAX_PSET_SIZE - (p - psets), r1 - r); av_free(psets); av_free(tmpbuf); - return NULL; + return AVERROR_INVALIDDATA; } p += strlen(p); r = r1; @@ -220,10 +225,11 @@ static char *extradata2psets(AVFormatContext *s, const AVCodecParameters *par) } av_free(tmpbuf); - return psets; + *out = psets; + return 0; } -static char *extradata2psets_hevc(const AVCodecParameters *par) +static int extradata2psets_hevc(const AVCodecParameters *par, char **out) { char *psets; uint8_t *extradata = par->extradata; @@ -232,7 +238,9 @@ static char *extradata2psets_hevc(const AVCodecParameters *par) int ps_pos[3] = { 0 }; static const char * const ps_names[3] = { "vps", "sps", "pps" }; int num_arrays, num_nalus; - int pos, i, j; + int pos, i, j, ret; + + *out = NULL; // Convert to hvcc format. Since we need to group multiple NALUs of // the same type, and we might need to convert from one format to the @@ -240,9 +248,13 @@ static char *extradata2psets_hevc(const AVCodecParameters *par) // format. if (par->extradata[0] != 1) { AVIOContext *pb; - if (avio_open_dyn_buf(&pb) < 0) - return NULL; - if (ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0) < 0) { + + ret = avio_open_dyn_buf(&pb); + if (ret < 0) + return ret; + + ret = ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0); + if (ret < 0) { avio_close_dyn_buf(pb, &tmpbuf); goto err; } @@ -285,8 +297,11 @@ static char *extradata2psets_hevc(const AVCodecParameters *par) goto err; psets = av_mallocz(MAX_PSET_SIZE); - if (!psets) + if (!psets) { + ret = AVERROR(ENOMEM); goto err; + } + psets[0] = '\0'; for (i = 0; i < 3; i++) { @@ -317,41 +332,49 @@ static char *extradata2psets_hevc(const AVCodecParameters *par) } av_free(tmpbuf); - return psets; - + *out = psets; + return 0; err: + if (ret >= 0) + ret = AVERROR_INVALIDDATA; av_free(tmpbuf); - return NULL; + return ret; } -static char *extradata2config(AVFormatContext *s, const AVCodecParameters *par) +static int extradata2config(AVFormatContext *s, const AVCodecParameters *par, + char **out) { char *config; + *out = NULL; + if (par->extradata_size > MAX_EXTRADATA_SIZE) { av_log(s, AV_LOG_ERROR, "Too much extradata!\n"); - - return NULL; + return AVERROR_INVALIDDATA; } config = av_malloc(10 + par->extradata_size * 2); if (!config) { av_log(s, AV_LOG_ERROR, "Cannot allocate memory for the config info.\n"); - return NULL; + return AVERROR(ENOMEM); } memcpy(config, "; config=", 9); ff_data_to_hex(config + 9, par->extradata, par->extradata_size, 0); config[9 + par->extradata_size * 2] = 0; - return config; + *out = config; + return 0; } -static char *xiph_extradata2config(AVFormatContext *s, const AVCodecParameters *par) +static int xiph_extradata2config(AVFormatContext *s, const AVCodecParameters *par, + char **out) { uint8_t *config; char *encoded_config; const uint8_t *header_start[3]; int headers_len, header_len[3], config_len; - int first_header_size; + int first_header_size, ret; + + *out = NULL; switch (par->codec_id) { case AV_CODEC_ID_THEORA: @@ -362,14 +385,15 @@ static char *xiph_extradata2config(AVFormatContext *s, const AVCodecParameters * break; default: av_log(s, AV_LOG_ERROR, "Unsupported Xiph codec ID\n"); - return NULL; + return AVERROR(ENOSYS); } - if (avpriv_split_xiph_headers(par->extradata, par->extradata_size, - first_header_size, header_start, - header_len) < 0) { + ret = avpriv_split_xiph_headers(par->extradata, par->extradata_size, + first_header_size, header_start, + header_len); + if (ret < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); - return NULL; + return ret; } headers_len = header_len[0] + header_len[2]; @@ -407,12 +431,13 @@ static char *xiph_extradata2config(AVFormatContext *s, const AVCodecParameters * config, config_len); av_free(config); - return encoded_config; + *out = encoded_config; + return 0; xiph_fail: av_log(s, AV_LOG_ERROR, "Not enough memory for configuration string\n"); - return NULL; + return AVERROR(ENOMEM); } static int latm_context2profilelevel(const AVCodecParameters *par) @@ -444,7 +469,8 @@ static int latm_context2profilelevel(const AVCodecParameters *par) return profile_level; } -static char *latm_context2config(AVFormatContext *s, const AVCodecParameters *par) +static int latm_context2config(AVFormatContext *s, const AVCodecParameters *par, + char **out) { /* MP4A-LATM * The RTP payload format specification is described in RFC 3016 @@ -454,12 +480,14 @@ static char *latm_context2config(AVFormatContext *s, const AVCodecParameters *pa int rate_index; char *config; + *out = NULL; + for (rate_index = 0; rate_index < 16; rate_index++) if (avpriv_mpeg4audio_sample_rates[rate_index] == par->sample_rate) break; if (rate_index == 16) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n"); - return NULL; + return AVERROR(ENOSYS); } config_byte[0] = 0x40; @@ -472,19 +500,21 @@ static char *latm_context2config(AVFormatContext *s, const AVCodecParameters *pa config = av_malloc(6*2+1); if (!config) { av_log(s, AV_LOG_ERROR, "Cannot allocate memory for the config info.\n"); - return NULL; + return AVERROR(ENOMEM); } ff_data_to_hex(config, config_byte, 6, 1); config[12] = 0; - return config; + *out = config; + return 0; } -static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st, - int payload_type, AVFormatContext *fmt) +static int sdp_write_media_attributes(char *buff, int size, const AVStream *st, + int payload_type, AVFormatContext *fmt) { char *config = NULL; const AVCodecParameters *p = st->codecpar; + int ret = 0; switch (p->codec_id) { case AV_CODEC_ID_DIRAC: @@ -496,7 +526,9 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st av_opt_flag_is_set(fmt->priv_data, "rtpflags", "h264_mode0")) mode = 0; if (p->extradata_size) { - config = extradata2psets(fmt, p); + ret = extradata2psets(fmt, p, &config); + if (ret < 0) + return ret; } av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n" "a=fmtp:%d packetization-mode=%d%s\r\n", @@ -533,8 +565,11 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st payload_type, p->width, p->height); break; case AV_CODEC_ID_HEVC: - if (p->extradata_size) - config = extradata2psets_hevc(p); + if (p->extradata_size) { + ret = extradata2psets_hevc(p, &config); + if (ret < 0) + return ret; + } av_strlcatf(buff, size, "a=rtpmap:%d H265/90000\r\n", payload_type); if (config) av_strlcatf(buff, size, "a=fmtp:%d %s\r\n", @@ -542,7 +577,9 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st break; case AV_CODEC_ID_MPEG4: if (p->extradata_size) { - config = extradata2config(fmt, p); + ret = extradata2config(fmt, p, &config); + if (ret < 0) + return ret; } av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n" "a=fmtp:%d profile-level-id=1%s\r\n", @@ -552,25 +589,24 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st case AV_CODEC_ID_AAC: if (fmt && fmt->oformat && fmt->oformat->priv_class && av_opt_flag_is_set(fmt->priv_data, "rtpflags", "latm")) { - config = latm_context2config(fmt, p); - if (!config) - return NULL; + ret = latm_context2config(fmt, p, &config); + if (ret < 0) + return ret; av_strlcatf(buff, size, "a=rtpmap:%d MP4A-LATM/%d/%d\r\n" "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n", payload_type, p->sample_rate, p->channels, payload_type, latm_context2profilelevel(p), config); } else { if (p->extradata_size) { - config = extradata2config(fmt, p); + ret = extradata2config(fmt, p, &config); + if (ret < 0) + return ret; } else { /* FIXME: maybe we can forge config information based on the * codec parameters... */ av_log(fmt, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); - return NULL; - } - if (!config) { - return NULL; + return AVERROR(ENOSYS); } av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" "a=fmtp:%d profile-level-id=1;" @@ -618,11 +654,13 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st break; case AV_CODEC_ID_VORBIS: if (p->extradata_size) - config = xiph_extradata2config(fmt, p); - else + ret = xiph_extradata2config(fmt, p, &config); + else { av_log(fmt, AV_LOG_ERROR, "Vorbis configuration info missing\n"); - if (!config) - return NULL; + ret = AVERROR_INVALIDDATA; + } + if (ret < 0) + return ret; av_strlcatf(buff, size, "a=rtpmap:%d vorbis/%d/%d\r\n" "a=fmtp:%d configuration=%s\r\n", @@ -643,15 +681,17 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st break; default: av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); - return NULL; + return AVERROR(ENOSYS); } if (p->extradata_size) - config = xiph_extradata2config(fmt, p); - else + ret = xiph_extradata2config(fmt, p, &config); + else { av_log(fmt, AV_LOG_ERROR, "Theora configuration info missing\n"); - if (!config) - return NULL; + ret = AVERROR_INVALIDDATA; + } + if (ret < 0) + return ret; av_strlcatf(buff, size, "a=rtpmap:%d theora/90000\r\n" "a=fmtp:%d delivery-method=inline; " @@ -685,7 +725,7 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st break; default: av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); - return NULL; + return AVERROR(ENOSYS); } av_strlcatf(buff, size, "a=rtpmap:%d raw/90000\r\n" @@ -763,12 +803,12 @@ static char *sdp_write_media_attributes(char *buff, int size, const AVStream *st av_free(config); - return buff; + return 0; } -void ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx, - const char *dest_addr, const char *dest_type, - int port, int ttl, AVFormatContext *fmt) +int ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx, + const char *dest_addr, const char *dest_type, + int port, int ttl, AVFormatContext *fmt) { const AVCodecParameters *p = st->codecpar; const char *type; @@ -789,7 +829,7 @@ void ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx, av_strlcatf(buff, size, "b=AS:%"PRId64"\r\n", p->bit_rate / 1000); } - sdp_write_media_attributes(buff, size, st, payload_type, fmt); + return sdp_write_media_attributes(buff, size, st, payload_type, fmt); } int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size) @@ -835,10 +875,13 @@ int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size) ttl = 0; } for (j = 0; j < ac[i]->nb_streams; j++) { - ff_sdp_write_media(buf, size, ac[i]->streams[j], index++, - dst[0] ? dst : NULL, dst_type, - (port > 0) ? port + j * 2 : 0, - ttl, ac[i]); + int ret = ff_sdp_write_media(buf, size, ac[i]->streams[j], index++, + dst[0] ? dst : NULL, dst_type, + (port > 0) ? port + j * 2 : 0, + ttl, ac[i]); + if (ret < 0) + return ret; + if (port <= 0) { av_strlcatf(buf, size, "a=control:streamid=%d\r\n", i + j); @@ -867,9 +910,9 @@ int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size) return AVERROR(ENOSYS); } -void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, - const char *dest_addr, const char *dest_type, - int port, int ttl, AVFormatContext *fmt) +int ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, + const char *dest_addr, const char *dest_type, + int port, int ttl, AVFormatContext *fmt) { } #endif