From patchwork Thu Jan 13 01:57:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33411 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp30930iog; Wed, 12 Jan 2022 18:21:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJygXMT3gSDa+tTBxSTuqwLIKuBZCn23KR7PKnr71Y1oqN48EnwJN6vxEH+T8YQybWg3EnR+ X-Received: by 2002:a05:6402:510a:: with SMTP id m10mr2206847edd.320.1642040494053; Wed, 12 Jan 2022 18:21:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642040494; cv=none; d=google.com; s=arc-20160816; b=YllPRNyp6hw33zTE/43QmkilJYwA9HKZ6GoEaQKZmZMTbPHOzLopyDBgHwLKWb0P9R J6rU9p4eIkbsMsVuxjzQBILaekOT2gxpwO9MKBe7L/R19Kz6nXdTdhV3uwyfuWIYfKbI Y2N/a0B6Ajhu2Qq+uKpXMvfkulzmvuGZFgG6vPn1qvwiYeZr+PhHMLaehIqwmxb39UN7 E/bxT4pUcZcoFhtj3y+drLy4ZuF20IG49l61L6+EjbQ9yXnZ2gdg6nKIczefAi47uJ0y DaTYitfX/vORZd5+NAws5JfElJmMoG0m1wWz19oUrra5abdXyxqcm1olU6/MPTBvKQVB HWdQ== 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:dkim-signature:delivered-to; bh=IL/7QseypZsf7d5EuWZ3TQin9g3B28hHqNpbrcxNqOQ=; b=aDrstDBCigKEnECv3Y9OPkZeSRZG+eW64tPVTycO1mhWxhSrRKnmQ09cSf3jQYDesp 2qKxYgir55KUNtFzwhxTOTK6/ocgsJNgCmD5ruFkdpiF1vSpTx/qvUhMmtdS5t/YZCgW 3GqpWlNJ1ufT2NhYk5BOA+Y1Psbo10dr0ikCR21Z23sT2hh62kp7cFC2geuj81jUqYld +rnUhvy9B6naGveroNVBFR48BzKwh/nf+baPzH47YH+0k7FN4nh+1w13Rtz+Rqky9Q0P wdhuGNorS++G4GNtylvSoH3rVKIAFURsBRwDGqqk4oCtY5Ft4ThYyRS/3PGWxch0R0uV HwsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=AswwAQjX; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gn31si752526ejc.354.2022.01.12.18.21.33; Wed, 12 Jan 2022 18:21: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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=AswwAQjX; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1549D68B3A5; Thu, 13 Jan 2022 03:58:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2601768B378 for ; Thu, 13 Jan 2022 03:58:47 +0200 (EET) Received: by mail-qt1-f175.google.com with SMTP id f17so5336903qtf.8 for ; Wed, 12 Jan 2022 17:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DzKLmOdi7X/hs299p+d7rs812LcY5xSHHjEKZnAACGc=; b=AswwAQjXqMv/lVR9yWxw1pHyIgNA5igRo3+ZWGK2VryYNWLP0Y/OIc0bP5xw6QF4Ja KuMKDOdyFciB7nzE3vv6e6YJlWKccoC7hK454c7F2oMTvptnpU/PDLPMGmMEQXQD+QCo 5X+H4mcD7hBXcdp/qL9nIXu4ErKX+7g2coDm5QPHXmRkY2uPZnbgHUqSZXoTRIISXGwK rHqrS8z41tG//ZaosKy8eo1DHeDV8JEc/MYlpGJ27j9cMgoHxT8+A0nCm5+9REVYQHa6 nPhAuSvw2kT0O2ibHmWoZRw+sUfAEbgNIP+StwPuEnaHS00U74dsM9hnxvYcIXEEjTuE uCNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DzKLmOdi7X/hs299p+d7rs812LcY5xSHHjEKZnAACGc=; b=1khuU1CZPpSuIrdbaFViKjK/8ahtwCIxFZWriR5Y0yD2haWqvBZBg3ya0qj4APjTcW 4r62GWtu2b0RUyMvCJgiTjC65GiiKd+gA7+Lk+1LjdNKBDjSInIjqP+UCksvUpmmwrAN x02tzYWLd2dbWt0lL129EWlG6W6xbxzEPlOGmaPwEx4fxpdXha5TA5i+3lAw1r/pRsca ume71yuFVgk+wkCUXdyd6H4wuAn17K72sCvUDPadzq1fPE592p+XDQrMgc5Yaa2suRWC T/KEM25+W30h3Y3j9DAd+pDhH+l3+D1RC2IOX3wol0w8CogyjJ5BnxQ+YuaU87nLEItH dXUA== X-Gm-Message-State: AOAM531rFQUas4cn5lvgcZ71d04kYyagtD3DFMhMm+xnW9kmo3Tj7GsZ GHCg0x5pATMLjBoAq/5MyPjuMZIW0L4= X-Received: by 2002:a05:622a:178e:: with SMTP id s14mr2049042qtk.688.1642039125442; Wed, 12 Jan 2022 17:58:45 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id u19sm893081qke.1.2022.01.12.17.58.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 17:58:45 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 22:57:52 -0300 Message-Id: <20220113015806.519-17-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 135/281] rtp: convert to new channel layout API 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: RJbmMU25r6Y7 From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavformat/rtp.c | 10 ++++++---- libavformat/rtpdec.c | 4 ++-- libavformat/rtpdec_amr.c | 3 +-- libavformat/rtpenc.c | 14 +++++++------- libavformat/rtsp.c | 6 +++--- libavformat/rtsp.h | 1 - 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libavformat/rtp.c b/libavformat/rtp.c index c536a6f082..004191a550 100644 --- a/libavformat/rtp.c +++ b/libavformat/rtp.c @@ -77,8 +77,10 @@ int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type) if (rtp_payload_types[i].codec_id != AV_CODEC_ID_NONE) { par->codec_type = rtp_payload_types[i].codec_type; par->codec_id = rtp_payload_types[i].codec_id; - if (rtp_payload_types[i].audio_channels > 0) - par->channels = rtp_payload_types[i].audio_channels; + if (rtp_payload_types[i].audio_channels > 0) { + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = rtp_payload_types[i].audio_channels; + } if (rtp_payload_types[i].clock_rate > 0) par->sample_rate = rtp_payload_types[i].clock_rate; return 0; @@ -111,13 +113,13 @@ int ff_rtp_get_payload_type(const AVFormatContext *fmt, /* G722 has 8000 as nominal rate even if the sample rate is 16000, * see section 4.5.2 in RFC 3551. */ if (par->codec_id == AV_CODEC_ID_ADPCM_G722 && - par->sample_rate == 16000 && par->channels == 1) + par->sample_rate == 16000 && par->ch_layout.nb_channels == 1) return rtp_payload_types[i].pt; if (par->codec_type == AVMEDIA_TYPE_AUDIO && ((rtp_payload_types[i].clock_rate > 0 && par->sample_rate != rtp_payload_types[i].clock_rate) || (rtp_payload_types[i].audio_channels > 0 && - par->channels != rtp_payload_types[i].audio_channels))) + par->ch_layout.nb_channels != rtp_payload_types[i].audio_channels))) continue; return rtp_payload_types[i].pt; } diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 20fe2b82d7..e56fde9d48 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -538,7 +538,7 @@ static int opus_write_extradata(AVCodecParameters *codecpar) * This mapping family only supports mono and stereo layouts. And RFC7587 * specifies that the number of channels in the SDP must be 2. */ - if (codecpar->channels > 2) { + if (codecpar->ch_layout.nb_channels > 2) { return AVERROR_INVALIDDATA; } @@ -553,7 +553,7 @@ static int opus_write_extradata(AVCodecParameters *codecpar) /* Version */ bytestream_put_byte (&bs, 0x1); /* Channel count */ - bytestream_put_byte (&bs, codecpar->channels); + bytestream_put_byte (&bs, codecpar->ch_layout.nb_channels); /* Pre skip */ bytestream_put_le16 (&bs, 0); /* Input sample rate */ diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c index 988b7bddfd..20b435039c 100644 --- a/libavformat/rtpdec_amr.c +++ b/libavformat/rtpdec_amr.c @@ -64,11 +64,10 @@ static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data, return AVERROR_INVALIDDATA; } - if (st->codecpar->channels != 1) { + if (st->codecpar->ch_layout.nb_channels != 1) { av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n"); return AVERROR_INVALIDDATA; } - st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; /* The AMR RTP packet consists of one header byte, followed * by one TOC byte for each AMR frame in the packet, followed diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 6be67b5885..ce629a8095 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -236,7 +236,7 @@ static int rtp_write_header(AVFormatContext *s1) avpriv_set_pts_info(st, 32, 1, 8000); break; case AV_CODEC_ID_OPUS: - if (st->codecpar->channels > 2) { + if (st->codecpar->ch_layout.nb_channels > 2) { av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n"); goto fail; } @@ -264,7 +264,7 @@ static int rtp_write_header(AVFormatContext *s1) av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n"); goto fail; } - if (st->codecpar->channels != 1) { + if (st->codecpar->ch_layout.nb_channels != 1) { av_log(s1, AV_LOG_ERROR, "Only mono is supported\n"); goto fail; } @@ -541,24 +541,24 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) case AV_CODEC_ID_PCM_ALAW: case AV_CODEC_ID_PCM_U8: case AV_CODEC_ID_PCM_S8: - return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels); + return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->ch_layout.nb_channels); case AV_CODEC_ID_PCM_U16BE: case AV_CODEC_ID_PCM_U16LE: case AV_CODEC_ID_PCM_S16BE: case AV_CODEC_ID_PCM_S16LE: - return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->channels); + return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->ch_layout.nb_channels); case AV_CODEC_ID_PCM_S24BE: - return rtp_send_samples(s1, pkt->data, size, 24 * st->codecpar->channels); + return rtp_send_samples(s1, pkt->data, size, 24 * st->codecpar->ch_layout.nb_channels); case AV_CODEC_ID_ADPCM_G722: /* The actual sample size is half a byte per sample, but since the * stream clock rate is 8000 Hz while the sample rate is 16000 Hz, * the correct parameter for send_samples_bits is 8 bits per stream * clock. */ - return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels); + return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->ch_layout.nb_channels); case AV_CODEC_ID_ADPCM_G726: case AV_CODEC_ID_ADPCM_G726LE: return rtp_send_samples(s1, pkt->data, size, - st->codecpar->bits_per_coded_sample * st->codecpar->channels); + st->codecpar->bits_per_coded_sample * st->codecpar->ch_layout.nb_channels); case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: rtp_send_mpegaudio(s1, pkt->data, size); diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 70c18941ca..5fa756bf5c 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -323,19 +323,19 @@ static int sdp_parse_rtpmap(AVFormatContext *s, case AVMEDIA_TYPE_AUDIO: av_log(s, AV_LOG_DEBUG, "audio codec set to: %s\n", c_name); par->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; - par->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; + par->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; if (i > 0) { par->sample_rate = i; avpriv_set_pts_info(st, 32, 1, par->sample_rate); get_word_sep(buf, sizeof(buf), "/", &p); i = atoi(buf); if (i > 0) - par->channels = i; + av_channel_layout_default(&par->ch_layout, i); } av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n", par->sample_rate); av_log(s, AV_LOG_DEBUG, "audio channels set to: %i\n", - par->channels); + par->ch_layout.nb_channels); break; case AVMEDIA_TYPE_VIDEO: av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name); diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index 8b64e29d70..3133bf61c1 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -75,7 +75,6 @@ enum RTSPControlTransport { #define RTSPS_DEFAULT_PORT 322 #define RTSP_MAX_TRANSPORTS 8 #define RTSP_TCP_MAX_PACKET_SIZE 1472 -#define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100 #define RTSP_RTP_PORT_MIN 5000 #define RTSP_RTP_PORT_MAX 65000