From patchwork Wed Dec 8 01:06:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32120 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7042951iog; Tue, 7 Dec 2021 17:07:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaCXExT3t5VuO8/RXQ+nzOyoekVNCdrUrLnmlw1IyWkREOCGxiGF4299DIkf8bP0iREEqS X-Received: by 2002:aa7:cada:: with SMTP id l26mr14966329edt.376.1638925669534; Tue, 07 Dec 2021 17:07:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925669; cv=none; d=google.com; s=arc-20160816; b=foQHq/OnFV70hzae6zuCOff1PX5OqXoxq1IiI+NaQlHyIpsvtJqSDACKibSl1UDigF aOg/8mbsHOP8RWm4Sc0u5Y1Hm3UU2qNFX/pnsvEop9P9VcLyXfsMlwS93TPdSlY0SDvH /DL7TQ/gt8NehX+rJR8ztqSWcjvHlRGDmR6LpR1IPyGVBhH2OsZo4d8GlLLQ0CeK/oSk 3P+bfER86tTLB36iTKPIVNqZ6+s8dRtk2Dt2aedUTxz3fySRqy3iQ2Gwke2J+xS0sWOG /zxeuNxeefbnetnei6RNKrKYr1uo1SVxsgPct4DbLZAjS2jyXxJEifLeOSOJ9d1/RXbZ osTg== 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=ENT34jhDCrwoRNdm2HeHVxY1TBiz5Ds98ceSn175hz0=; b=vtpzPOoqP50yhPaL5YAVCR9IbFlJ8LRSmNFOwcxTQXJ4+hx35xm+rIE5Fb4RqXhS2D p+NLwfl22OBLgH3vI8+8LtRTirZi9bOhRspcSGyUyEz96zRcpSk8zh/jQ7pW4QG2zgnb 1yZmHkj8XbjQt4vJSTW9s8eIQ1YbynzhzUnyIzQT62p7b4dZPUN7u6mBzitNLPA6eLn9 0LlyXPVP75FMA4iZiETtdsNzgVdZfeJsXnyxuwFWpgSp2OaK4mv9y+zg5ogg1YGxVDHk NdslHI4UN7S0Hix+uGCUiwPB8VPAAJ08lcexRQpmJ5miMuGgyMZm9uWbNbcBLPtp4fMF B1uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=hsu1DBC0; 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 e6si2799925edz.445.2021.12.07.17.07.49; Tue, 07 Dec 2021 17:07:49 -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=hsu1DBC0; 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 D7FD668AA82; Wed, 8 Dec 2021 03:07:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f47.google.com (mail-ua1-f47.google.com [209.85.222.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D4D8468A3AD for ; Wed, 8 Dec 2021 03:07:25 +0200 (EET) Received: by mail-ua1-f47.google.com with SMTP id ay21so1842296uab.12 for ; Tue, 07 Dec 2021 17:07:25 -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=y8W0CHJZVz9tCC4+IOyMwJCunK01nNB2l28Egoa2b/w=; b=hsu1DBC0op7rAsrSna9pF0z3uCMzibPpRSKK7qUIjkm9BQ2PAkeZAsuKXOMzYWdbO6 J3oihlBfva1a7DfJ77PhelBs52o8JYo+uVU1M5O4MLhuZJz7boL5HsWwkvU8/bC8VRpF Y/W/319KynE7+EwkURVey6aTkQjyWaCwhfVU4GtJMyzR00h1V+Haa5HfW6YnuDnK91sx 7pc1qLAImRLXFAw/vuowAtsSMKdUmbV3sRx2vrv7bJ8+Ah4dykWfafTE/VctrTYyG3cB 5+F4fr41To/njYr7XGuZ47hnrHHkcx/uZgjhkogOjVjH9w1amUTI85sNODd5Fbj7Y3Da b0rA== 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=y8W0CHJZVz9tCC4+IOyMwJCunK01nNB2l28Egoa2b/w=; b=b3QN8FjYLYuiAJfTeaWiyZkpuarfU9AlqGmQ0ad6Ln84zlb20XB2b/H3q4+X2d1TGW h0Br4x+tWjTQpnJ/QhpS9sgtqh2b5ZX53u9XUR3V7yCsCGyFKCVpvzu53gRhdO2OPLE4 EpMHpisGypB8qb8Gx4IqlnioDw94y9hrV2f+X6vhIrxg4wnWhvZL7smpcPV4Msm3nfCi Z67G3AJAtGovp1VUfKR3cfV0QifzqgkAOAjzd+CEGBS7vuN5Eiy/ObWrFNFjfRpHXy3h GNQ3pQ3K2zE7VXhrDBM6Da98BmfL4v7iocIyENZNB2WJekBSeHmP2hzumh7FKSirW78n KFEQ== X-Gm-Message-State: AOAM530c/XVx/Xmm7I/IWMpHfcpRdPdyRBgmDzPiCqnFE6JzyvLB9pmJ v8g8d2viWnHg/d8cWsrN4CtOHg2PyXrucsKN X-Received: by 2002:ab0:6cea:: with SMTP id l10mr4043641uai.27.1638925642951; Tue, 07 Dec 2021 17:07:22 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:22 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:17 -0300 Message-Id: <20211208010649.381-2-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 001/279] Add a 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: Io5SLI4waFTK From: Anton Khirnov The new API is more extensible and allows for custom layouts. More accurate information is exported, eg for decoders that do not set a channel layout, lavc will not make one up for them. Deprecate the old API working with just uint64_t bitmasks. Expanded and completed by Vittorio Giovara and James Almer . Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavutil/channel_layout.c | 498 ++++++++++++++++++++++++++++++------ libavutil/channel_layout.h | 510 ++++++++++++++++++++++++++++++++++--- libavutil/version.h | 1 + 3 files changed, 906 insertions(+), 103 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index ac773a9e63..984255bfca 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -37,81 +37,132 @@ struct channel_name { }; static const struct channel_name channel_names[] = { - [0] = { "FL", "front left" }, - [1] = { "FR", "front right" }, - [2] = { "FC", "front center" }, - [3] = { "LFE", "low frequency" }, - [4] = { "BL", "back left" }, - [5] = { "BR", "back right" }, - [6] = { "FLC", "front left-of-center" }, - [7] = { "FRC", "front right-of-center" }, - [8] = { "BC", "back center" }, - [9] = { "SL", "side left" }, - [10] = { "SR", "side right" }, - [11] = { "TC", "top center" }, - [12] = { "TFL", "top front left" }, - [13] = { "TFC", "top front center" }, - [14] = { "TFR", "top front right" }, - [15] = { "TBL", "top back left" }, - [16] = { "TBC", "top back center" }, - [17] = { "TBR", "top back right" }, - [29] = { "DL", "downmix left" }, - [30] = { "DR", "downmix right" }, - [31] = { "WL", "wide left" }, - [32] = { "WR", "wide right" }, - [33] = { "SDL", "surround direct left" }, - [34] = { "SDR", "surround direct right" }, - [35] = { "LFE2", "low frequency 2" }, - [36] = { "TSL", "top side left" }, - [37] = { "TSR", "top side right" }, - [38] = { "BFC", "bottom front center" }, - [39] = { "BFL", "bottom front left" }, - [40] = { "BFR", "bottom front right" }, + [AV_CHAN_FRONT_LEFT ] = { "FL", "front left" }, + [AV_CHAN_FRONT_RIGHT ] = { "FR", "front right" }, + [AV_CHAN_FRONT_CENTER ] = { "FC", "front center" }, + [AV_CHAN_LOW_FREQUENCY ] = { "LFE", "low frequency" }, + [AV_CHAN_BACK_LEFT ] = { "BL", "back left" }, + [AV_CHAN_BACK_RIGHT ] = { "BR", "back right" }, + [AV_CHAN_FRONT_LEFT_OF_CENTER ] = { "FLC", "front left-of-center" }, + [AV_CHAN_FRONT_RIGHT_OF_CENTER] = { "FRC", "front right-of-center" }, + [AV_CHAN_BACK_CENTER ] = { "BC", "back center" }, + [AV_CHAN_SIDE_LEFT ] = { "SL", "side left" }, + [AV_CHAN_SIDE_RIGHT ] = { "SR", "side right" }, + [AV_CHAN_TOP_CENTER ] = { "TC", "top center" }, + [AV_CHAN_TOP_FRONT_LEFT ] = { "TFL", "top front left" }, + [AV_CHAN_TOP_FRONT_CENTER ] = { "TFC", "top front center" }, + [AV_CHAN_TOP_FRONT_RIGHT ] = { "TFR", "top front right" }, + [AV_CHAN_TOP_BACK_LEFT ] = { "TBL", "top back left" }, + [AV_CHAN_TOP_BACK_CENTER ] = { "TBC", "top back center" }, + [AV_CHAN_TOP_BACK_RIGHT ] = { "TBR", "top back right" }, + [AV_CHAN_STEREO_LEFT ] = { "DL", "downmix left" }, + [AV_CHAN_STEREO_RIGHT ] = { "DR", "downmix right" }, + [AV_CHAN_WIDE_LEFT ] = { "WL", "wide left" }, + [AV_CHAN_WIDE_RIGHT ] = { "WR", "wide right" }, + [AV_CHAN_SURROUND_DIRECT_LEFT ] = { "SDL", "surround direct left" }, + [AV_CHAN_SURROUND_DIRECT_RIGHT] = { "SDR", "surround direct right" }, + [AV_CHAN_LOW_FREQUENCY_2 ] = { "LFE2", "low frequency 2" }, + [AV_CHAN_TOP_SIDE_LEFT ] = { "TSL", "top side left" }, + [AV_CHAN_TOP_SIDE_RIGHT ] = { "TSR", "top side right" }, + [AV_CHAN_BOTTOM_FRONT_CENTER ] = { "BFC", "bottom front center" }, + [AV_CHAN_BOTTOM_FRONT_LEFT ] = { "BFL", "bottom front left" }, + [AV_CHAN_BOTTOM_FRONT_RIGHT ] = { "BFR", "bottom front right" }, }; -static const char *get_channel_name(int channel_id) +static const char *get_channel_name(enum AVChannel channel_id) { - if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names)) - return NULL; + if ((unsigned) channel_id >= FF_ARRAY_ELEMS(channel_names) || + !channel_names[channel_id].name) + return "?"; return channel_names[channel_id].name; } -static const struct { +static inline void get_channel_str(AVBPrint *bp, const char *str, + enum AVChannel channel_id) +{ + if (str) + av_bprintf(bp, "%s", str); + else + av_bprintf(bp, "?"); +} + +int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id) +{ + AVBPrint bp; + + if (!buf && buf_size) + return AVERROR(EINVAL); + + av_bprint_init_for_buffer(&bp, buf, buf_size); + get_channel_str(&bp, (unsigned)channel_id < FF_ARRAY_ELEMS(channel_names) ? + channel_names[channel_id].name : NULL, channel_id); + + return bp.len; +} +int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel_id) +{ + AVBPrint bp; + + if (!buf && buf_size) + return AVERROR(EINVAL); + + av_bprint_init_for_buffer(&bp, buf, buf_size); + get_channel_str(&bp, (unsigned)channel_id < FF_ARRAY_ELEMS(channel_names) ? + channel_names[channel_id].description : NULL, channel_id); + + return bp.len; +} + +enum AVChannel av_channel_from_string(const char *str) +{ + int i; + for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) { + if (channel_names[i].name && !strcmp(str, channel_names[i].name)) + return i; + } + return AV_CHAN_NONE; +} + +struct channel_layout_name { const char *name; - int nb_channels; - uint64_t layout; -} channel_layout_map[] = { - { "mono", 1, AV_CH_LAYOUT_MONO }, - { "stereo", 2, AV_CH_LAYOUT_STEREO }, - { "2.1", 3, AV_CH_LAYOUT_2POINT1 }, - { "3.0", 3, AV_CH_LAYOUT_SURROUND }, - { "3.0(back)", 3, AV_CH_LAYOUT_2_1 }, - { "4.0", 4, AV_CH_LAYOUT_4POINT0 }, - { "quad", 4, AV_CH_LAYOUT_QUAD }, - { "quad(side)", 4, AV_CH_LAYOUT_2_2 }, - { "3.1", 4, AV_CH_LAYOUT_3POINT1 }, - { "5.0", 5, AV_CH_LAYOUT_5POINT0_BACK }, - { "5.0(side)", 5, AV_CH_LAYOUT_5POINT0 }, - { "4.1", 5, AV_CH_LAYOUT_4POINT1 }, - { "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK }, - { "5.1(side)", 6, AV_CH_LAYOUT_5POINT1 }, - { "6.0", 6, AV_CH_LAYOUT_6POINT0 }, - { "6.0(front)", 6, AV_CH_LAYOUT_6POINT0_FRONT }, - { "hexagonal", 6, AV_CH_LAYOUT_HEXAGONAL }, - { "6.1", 7, AV_CH_LAYOUT_6POINT1 }, - { "6.1(back)", 7, AV_CH_LAYOUT_6POINT1_BACK }, - { "6.1(front)", 7, AV_CH_LAYOUT_6POINT1_FRONT }, - { "7.0", 7, AV_CH_LAYOUT_7POINT0 }, - { "7.0(front)", 7, AV_CH_LAYOUT_7POINT0_FRONT }, - { "7.1", 8, AV_CH_LAYOUT_7POINT1 }, - { "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE_BACK }, - { "7.1(wide-side)", 8, AV_CH_LAYOUT_7POINT1_WIDE }, - { "octagonal", 8, AV_CH_LAYOUT_OCTAGONAL }, - { "hexadecagonal", 16, AV_CH_LAYOUT_HEXADECAGONAL }, - { "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, }, - { "22.2", 24, AV_CH_LAYOUT_22POINT2, }, + AVChannelLayout layout; }; +static const struct channel_layout_name channel_layout_map[] = { + { "mono", AV_CHANNEL_LAYOUT_MONO }, + { "stereo", AV_CHANNEL_LAYOUT_STEREO }, + { "stereo", AV_CHANNEL_LAYOUT_STEREO_DOWNMIX }, + { "2.1", AV_CHANNEL_LAYOUT_2POINT1 }, + { "3.0", AV_CHANNEL_LAYOUT_SURROUND }, + { "3.0(back)", AV_CHANNEL_LAYOUT_2_1 }, + { "4.0", AV_CHANNEL_LAYOUT_4POINT0 }, + { "quad", AV_CHANNEL_LAYOUT_QUAD }, + { "quad(side)", AV_CHANNEL_LAYOUT_2_2 }, + { "3.1", AV_CHANNEL_LAYOUT_3POINT1 }, + { "5.0", AV_CHANNEL_LAYOUT_5POINT0_BACK }, + { "5.0(side)", AV_CHANNEL_LAYOUT_5POINT0 }, + { "4.1", AV_CHANNEL_LAYOUT_4POINT1 }, + { "5.1", AV_CHANNEL_LAYOUT_5POINT1_BACK }, + { "5.1(side)", AV_CHANNEL_LAYOUT_5POINT1 }, + { "6.0", AV_CHANNEL_LAYOUT_6POINT0 }, + { "6.0(front)", AV_CHANNEL_LAYOUT_6POINT0_FRONT }, + { "hexagonal", AV_CHANNEL_LAYOUT_HEXAGONAL }, + { "6.1", AV_CHANNEL_LAYOUT_6POINT1 }, + { "6.1(back)", AV_CHANNEL_LAYOUT_6POINT1_BACK }, + { "6.1(front)", AV_CHANNEL_LAYOUT_6POINT1_FRONT }, + { "7.0", AV_CHANNEL_LAYOUT_7POINT0 }, + { "7.0(front)", AV_CHANNEL_LAYOUT_7POINT0_FRONT }, + { "7.1", AV_CHANNEL_LAYOUT_7POINT1 }, + { "7.1(wide)", AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK }, + { "7.1(wide-side)", AV_CHANNEL_LAYOUT_7POINT1_WIDE }, + { "octagonal", AV_CHANNEL_LAYOUT_OCTAGONAL }, + { "hexadecagonal", AV_CHANNEL_LAYOUT_HEXADECAGONAL }, + { "downmix", AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, }, + { "22.2", AV_CHANNEL_LAYOUT_22POINT2, }, +}; + +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS static uint64_t get_channel_layout_single(const char *name, int name_len) { int i; @@ -121,7 +172,7 @@ static uint64_t get_channel_layout_single(const char *name, int name_len) for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) { if (strlen(channel_layout_map[i].name) == name_len && !memcmp(channel_layout_map[i].name, name, name_len)) - return channel_layout_map[i].layout; + return channel_layout_map[i].layout.u.mask; } for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) if (channel_names[i].name && @@ -189,8 +240,8 @@ void av_bprint_channel_layout(struct AVBPrint *bp, nb_channels = av_get_channel_layout_nb_channels(channel_layout); for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) - if (nb_channels == channel_layout_map[i].nb_channels && - channel_layout == channel_layout_map[i].layout) { + if (nb_channels == channel_layout_map[i].layout.nb_channels && + channel_layout == channel_layout_map[i].layout.u.mask) { av_bprintf(bp, "%s", channel_layout_map[i].name); return; } @@ -231,8 +282,8 @@ int av_get_channel_layout_nb_channels(uint64_t channel_layout) int64_t av_get_default_channel_layout(int nb_channels) { int i; for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) - if (nb_channels == channel_layout_map[i].nb_channels) - return channel_layout_map[i].layout; + if (nb_channels == channel_layout_map[i].layout.nb_channels) + return channel_layout_map[i].layout.u.mask; return 0; } @@ -287,7 +338,310 @@ int av_get_standard_channel_layout(unsigned index, uint64_t *layout, { if (index >= FF_ARRAY_ELEMS(channel_layout_map)) return AVERROR_EOF; - if (layout) *layout = channel_layout_map[index].layout; + if (layout) *layout = channel_layout_map[index].layout.u.mask; if (name) *name = channel_layout_map[index].name; return 0; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + +int av_channel_layout_from_mask(AVChannelLayout *channel_layout, + uint64_t mask) +{ + if (!mask) + return AVERROR(EINVAL); + + channel_layout->order = AV_CHANNEL_ORDER_NATIVE; + channel_layout->nb_channels = av_popcount64(mask); + channel_layout->u.mask = mask; + + return 0; +} + +int av_channel_layout_from_string(AVChannelLayout *channel_layout, + const char *str) +{ + int i, channels; + const char *dup = str; + char *end; + uint64_t mask = 0; + + /* channel layout names */ + for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) { + if (channel_layout_map[i].name && !strcmp(str, channel_layout_map[i].name)) { + *channel_layout = channel_layout_map[i].layout; + return 0; + } + } + + /* channel names */ + while (*dup) { + char *chname = av_get_token(&dup, "|"); + if (!chname) + return AVERROR(ENOMEM); + if (*dup) + dup++; // skip separator + for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) { + if (channel_names[i].name && !strcmp(chname, channel_names[i].name)) { + mask |= 1ULL << i; + } + } + av_free(chname); + } + if (mask) { + av_channel_layout_from_mask(channel_layout, mask); + return 0; + } + + /* channel layout mask */ + if (!strncmp(str, "0x", 2) && sscanf(str + 2, "%"SCNx64, &mask) == 1) { + av_channel_layout_from_mask(channel_layout, mask); + return 0; + } + + errno = 0; + channels = strtol(str, &end, 10); + + /* number of channels */ + if (!errno && *end == 'c' && !*(end + 1) && channels >= 0) { + av_channel_layout_default(channel_layout, channels); + return 0; + } + + /* number of unordered channels */ + if (!errno && (!*end || av_strnstr(str, "channels", strlen(str))) && channels >= 0) { + channel_layout->order = AV_CHANNEL_ORDER_UNSPEC; + channel_layout->nb_channels = channels; + return 0; + } + + return AVERROR_INVALIDDATA; +} + +void av_channel_layout_uninit(AVChannelLayout *channel_layout) +{ + if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) + av_freep(&channel_layout->u.map); + memset(channel_layout, 0, sizeof(*channel_layout)); +} + +int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) +{ + av_channel_layout_uninit(dst); + *dst = *src; + if (src->order == AV_CHANNEL_ORDER_CUSTOM) { + dst->u.map = av_malloc(src->nb_channels * sizeof(*dst->u.map)); + if (!dst->u.map) + return AVERROR(ENOMEM); + memcpy(dst->u.map, src->u.map, src->nb_channels * sizeof(*src->u.map)); + } + return 0; +} + +int av_channel_layout_describe(const AVChannelLayout *channel_layout, + char *buf, size_t buf_size) +{ + AVBPrint bp; + int i; + + if (!buf && buf_size) + return AVERROR(EINVAL); + + av_bprint_init_for_buffer(&bp, buf, buf_size); + + switch (channel_layout->order) { + case AV_CHANNEL_ORDER_NATIVE: + for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) + if (channel_layout->u.mask == channel_layout_map[i].layout.u.mask) { + av_bprintf(&bp, "%s", channel_layout_map[i].name); + return bp.len; + } + // fall-through + case AV_CHANNEL_ORDER_CUSTOM: + for (i = 0; i < channel_layout->nb_channels; i++) { + enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i); + const char *ch_name = get_channel_name(ch); + + if (i) + av_bprintf(&bp, "|"); + av_bprintf(&bp, "%s", ch_name); + } + if (channel_layout->nb_channels) + return bp.len; + // fall-through + case AV_CHANNEL_ORDER_UNSPEC: + av_bprintf(&bp, "%d channels", channel_layout->nb_channels); + return bp.len; + default: + return AVERROR(EINVAL); + } +} + +enum AVChannel +av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, + unsigned int idx) +{ + int i; + + if (idx >= channel_layout->nb_channels) + return AV_CHAN_NONE; + + switch (channel_layout->order) { + case AV_CHANNEL_ORDER_CUSTOM: + return channel_layout->u.map[idx].id; + case AV_CHANNEL_ORDER_NATIVE: + for (i = 0; i < 64; i++) { + if ((1ULL << i) & channel_layout->u.mask && !idx--) + return i; + } + default: + return AV_CHAN_NONE; + } +} + +enum AVChannel +av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout, + const char *name) +{ + enum AVChannel; + int channel, ret; + + switch (channel_layout->order) { + case AV_CHANNEL_ORDER_CUSTOM: + case AV_CHANNEL_ORDER_NATIVE: + channel = av_channel_from_string(name); + if (channel < 0) + return channel; + ret = av_channel_layout_index_from_channel(channel_layout, channel); + if (ret < 0) + return ret; + return channel; + } + + return AV_CHAN_NONE; +} + +int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, + enum AVChannel channel) +{ + int i; + + switch (channel_layout->order) { + case AV_CHANNEL_ORDER_CUSTOM: + for (i = 0; i < channel_layout->nb_channels; i++) + if (channel_layout->u.map[i].id == channel) + return i; + return AVERROR(EINVAL); + case AV_CHANNEL_ORDER_NATIVE: { + uint64_t mask = channel_layout->u.mask; + if (!(mask & (1ULL << channel))) + return AVERROR(EINVAL); + mask &= (1ULL << channel) - 1; + return av_popcount64(mask); + } + default: + return AVERROR(EINVAL); + } +} + +int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout, + const char *name) +{ + int ret; + + if (channel_layout->order == AV_CHANNEL_ORDER_UNSPEC) + return AVERROR(EINVAL); + + ret = av_channel_from_string(name); + if (ret < 0) + return ret; + return av_channel_layout_index_from_channel(channel_layout, ret); +} + +int av_channel_layout_check(const AVChannelLayout *channel_layout) +{ + if (channel_layout->nb_channels <= 0) + return 0; + + switch (channel_layout->order) { + case AV_CHANNEL_ORDER_NATIVE: + return av_popcount64(channel_layout->u.mask) == channel_layout->nb_channels; + case AV_CHANNEL_ORDER_CUSTOM: + return !!channel_layout->u.map; + case AV_CHANNEL_ORDER_UNSPEC: + return 1; + default: + return 0; + } +} + +int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1) +{ + int i; + + /* different channel counts -> not equal */ + if (chl->nb_channels != chl1->nb_channels) + return 1; + + /* if only one is unspecified -> not equal */ + if ((chl->order == AV_CHANNEL_ORDER_UNSPEC) != + (chl1->order == AV_CHANNEL_ORDER_UNSPEC)) + return 1; + /* both are unspecified -> equal */ + else if (chl->order == AV_CHANNEL_ORDER_UNSPEC) + return 0; + + /* can compare masks directly */ + if (chl->order != AV_CHANNEL_ORDER_CUSTOM && + chl->order == chl1->order) + return chl->u.mask != chl1->u.mask; + + /* compare channel by channel */ + for (i = 0; i < chl->nb_channels; i++) + if (av_channel_layout_channel_from_index(chl, i) != + av_channel_layout_channel_from_index(chl1, i)) + return 1; + return 0; +} + +void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels) +{ + int i; + for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) + if (nb_channels == channel_layout_map[i].layout.nb_channels) { + *ch_layout = channel_layout_map[i].layout; + return; + } + + ch_layout->order = AV_CHANNEL_ORDER_UNSPEC; + ch_layout->nb_channels = nb_channels; +} + +const AVChannelLayout *av_channel_layout_standard(void **opaque) +{ + uintptr_t i = (uintptr_t)*opaque; + const AVChannelLayout *ch_layout = NULL; + + if (i < FF_ARRAY_ELEMS(channel_layout_map)) { + ch_layout = &channel_layout_map[i].layout; + *opaque = (void*)(i + 1); + } + + return ch_layout; +} + +uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, + uint64_t mask) +{ + uint64_t ret = 0; + int i; + + if (channel_layout->order == AV_CHANNEL_ORDER_NATIVE) + return channel_layout->u.mask & mask; + + for (i = 0; i < 64; i++) + if (mask & (1ULL << i) && av_channel_layout_index_from_channel(channel_layout, i) >= 0) + ret |= (1ULL << i); + + return ret; +} diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index d39ae1177a..018e87ff0b 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -23,6 +23,10 @@ #define AVUTIL_CHANNEL_LAYOUT_H #include +#include + +#include "version.h" +#include "attributes.h" /** * @file @@ -34,6 +38,68 @@ * @{ */ +enum AVChannel { + ///< Invalid channel index + AV_CHAN_NONE = -1, + AV_CHAN_FRONT_LEFT, + AV_CHAN_FRONT_RIGHT, + AV_CHAN_FRONT_CENTER, + AV_CHAN_LOW_FREQUENCY, + AV_CHAN_BACK_LEFT, + AV_CHAN_BACK_RIGHT, + AV_CHAN_FRONT_LEFT_OF_CENTER, + AV_CHAN_FRONT_RIGHT_OF_CENTER, + AV_CHAN_BACK_CENTER, + AV_CHAN_SIDE_LEFT, + AV_CHAN_SIDE_RIGHT, + AV_CHAN_TOP_CENTER, + AV_CHAN_TOP_FRONT_LEFT, + AV_CHAN_TOP_FRONT_CENTER, + AV_CHAN_TOP_FRONT_RIGHT, + AV_CHAN_TOP_BACK_LEFT, + AV_CHAN_TOP_BACK_CENTER, + AV_CHAN_TOP_BACK_RIGHT, + /** Stereo downmix. */ + AV_CHAN_STEREO_LEFT = 29, + /** See above. */ + AV_CHAN_STEREO_RIGHT, + AV_CHAN_WIDE_LEFT, + AV_CHAN_WIDE_RIGHT, + AV_CHAN_SURROUND_DIRECT_LEFT, + AV_CHAN_SURROUND_DIRECT_RIGHT, + AV_CHAN_LOW_FREQUENCY_2, + AV_CHAN_TOP_SIDE_LEFT, + AV_CHAN_TOP_SIDE_RIGHT, + AV_CHAN_BOTTOM_FRONT_CENTER, + AV_CHAN_BOTTOM_FRONT_LEFT, + AV_CHAN_BOTTOM_FRONT_RIGHT, + + /** Channel is empty can be safely skipped. */ + AV_CHAN_SILENCE = 64, +}; + +enum AVChannelOrder { + /** + * Only the channel count is specified, without any further information + * about the channel order. + */ + AV_CHANNEL_ORDER_UNSPEC, + /** + * The native channel order, i.e. the channels are in the same order in + * which they are defined in the AVChannel enum. This supports up to 63 + * different channels. + */ + AV_CHANNEL_ORDER_NATIVE, + /** + * The channel order does not correspond to any other predefined order and + * is stored as an explicit map. For example, this could be used to support + * layouts with 64 or more channels, or with empty/skipped (AV_CHAN_SILENCE) + * channels at arbitrary positions. + */ + AV_CHANNEL_ORDER_CUSTOM, +}; + + /** * @defgroup channel_masks Audio channel masks * @@ -46,41 +112,46 @@ * * @{ */ -#define AV_CH_FRONT_LEFT 0x00000001 -#define AV_CH_FRONT_RIGHT 0x00000002 -#define AV_CH_FRONT_CENTER 0x00000004 -#define AV_CH_LOW_FREQUENCY 0x00000008 -#define AV_CH_BACK_LEFT 0x00000010 -#define AV_CH_BACK_RIGHT 0x00000020 -#define AV_CH_FRONT_LEFT_OF_CENTER 0x00000040 -#define AV_CH_FRONT_RIGHT_OF_CENTER 0x00000080 -#define AV_CH_BACK_CENTER 0x00000100 -#define AV_CH_SIDE_LEFT 0x00000200 -#define AV_CH_SIDE_RIGHT 0x00000400 -#define AV_CH_TOP_CENTER 0x00000800 -#define AV_CH_TOP_FRONT_LEFT 0x00001000 -#define AV_CH_TOP_FRONT_CENTER 0x00002000 -#define AV_CH_TOP_FRONT_RIGHT 0x00004000 -#define AV_CH_TOP_BACK_LEFT 0x00008000 -#define AV_CH_TOP_BACK_CENTER 0x00010000 -#define AV_CH_TOP_BACK_RIGHT 0x00020000 -#define AV_CH_STEREO_LEFT 0x20000000 ///< Stereo downmix. -#define AV_CH_STEREO_RIGHT 0x40000000 ///< See AV_CH_STEREO_LEFT. -#define AV_CH_WIDE_LEFT 0x0000000080000000ULL -#define AV_CH_WIDE_RIGHT 0x0000000100000000ULL -#define AV_CH_SURROUND_DIRECT_LEFT 0x0000000200000000ULL -#define AV_CH_SURROUND_DIRECT_RIGHT 0x0000000400000000ULL -#define AV_CH_LOW_FREQUENCY_2 0x0000000800000000ULL -#define AV_CH_TOP_SIDE_LEFT 0x0000001000000000ULL -#define AV_CH_TOP_SIDE_RIGHT 0x0000002000000000ULL -#define AV_CH_BOTTOM_FRONT_CENTER 0x0000004000000000ULL -#define AV_CH_BOTTOM_FRONT_LEFT 0x0000008000000000ULL -#define AV_CH_BOTTOM_FRONT_RIGHT 0x0000010000000000ULL +#define AV_CH_FRONT_LEFT (1ULL << AV_CHAN_FRONT_LEFT ) +#define AV_CH_FRONT_RIGHT (1ULL << AV_CHAN_FRONT_RIGHT ) +#define AV_CH_FRONT_CENTER (1ULL << AV_CHAN_FRONT_CENTER ) +#define AV_CH_LOW_FREQUENCY (1ULL << AV_CHAN_LOW_FREQUENCY ) +#define AV_CH_BACK_LEFT (1ULL << AV_CHAN_BACK_LEFT ) +#define AV_CH_BACK_RIGHT (1ULL << AV_CHAN_BACK_RIGHT ) +#define AV_CH_FRONT_LEFT_OF_CENTER (1ULL << AV_CHAN_FRONT_LEFT_OF_CENTER ) +#define AV_CH_FRONT_RIGHT_OF_CENTER (1ULL << AV_CHAN_FRONT_RIGHT_OF_CENTER) +#define AV_CH_BACK_CENTER (1ULL << AV_CHAN_BACK_CENTER ) +#define AV_CH_SIDE_LEFT (1ULL << AV_CHAN_SIDE_LEFT ) +#define AV_CH_SIDE_RIGHT (1ULL << AV_CHAN_SIDE_RIGHT ) +#define AV_CH_TOP_CENTER (1ULL << AV_CHAN_TOP_CENTER ) +#define AV_CH_TOP_FRONT_LEFT (1ULL << AV_CHAN_TOP_FRONT_LEFT ) +#define AV_CH_TOP_FRONT_CENTER (1ULL << AV_CHAN_TOP_FRONT_CENTER ) +#define AV_CH_TOP_FRONT_RIGHT (1ULL << AV_CHAN_TOP_FRONT_RIGHT ) +#define AV_CH_TOP_BACK_LEFT (1ULL << AV_CHAN_TOP_BACK_LEFT ) +#define AV_CH_TOP_BACK_CENTER (1ULL << AV_CHAN_TOP_BACK_CENTER ) +#define AV_CH_TOP_BACK_RIGHT (1ULL << AV_CHAN_TOP_BACK_RIGHT ) +#define AV_CH_STEREO_LEFT (1ULL << AV_CHAN_STEREO_LEFT ) +#define AV_CH_STEREO_RIGHT (1ULL << AV_CHAN_STEREO_RIGHT ) +#define AV_CH_WIDE_LEFT (1ULL << AV_CHAN_WIDE_LEFT ) +#define AV_CH_WIDE_RIGHT (1ULL << AV_CHAN_WIDE_RIGHT ) +#define AV_CH_SURROUND_DIRECT_LEFT (1ULL << AV_CHAN_SURROUND_DIRECT_LEFT ) +#define AV_CH_SURROUND_DIRECT_RIGHT (1ULL << AV_CHAN_SURROUND_DIRECT_RIGHT) +#define AV_CH_LOW_FREQUENCY_2 (1ULL << AV_CHAN_LOW_FREQUENCY_2 ) +#define AV_CH_TOP_SIDE_LEFT (1ULL << AV_CHAN_TOP_SIDE_LEFT ) +#define AV_CH_TOP_SIDE_RIGHT (1ULL << AV_CHAN_TOP_SIDE_RIGHT ) +#define AV_CH_BOTTOM_FRONT_CENTER (1ULL << AV_CHAN_BOTTOM_FRONT_CENTER ) +#define AV_CH_BOTTOM_FRONT_LEFT (1ULL << AV_CHAN_BOTTOM_FRONT_LEFT ) +#define AV_CH_BOTTOM_FRONT_RIGHT (1ULL << AV_CHAN_BOTTOM_FRONT_RIGHT ) +#if FF_API_OLD_CHANNEL_LAYOUT /** Channel mask value used for AVCodecContext.request_channel_layout to indicate that the user requests the channel order of the decoder output - to be the native codec channel order. */ + to be the native codec channel order. + @deprecated channel order is now indicated in a special field in + AVChannelLayout + */ #define AV_CH_LAYOUT_NATIVE 0x8000000000000000ULL +#endif /** * @} @@ -128,6 +199,157 @@ enum AVMatrixEncoding { AV_MATRIX_ENCODING_NB }; +/** + * @} + */ + +/** + * An AVChannelCustom defines a single channel within a custom order layout + * + * Unlike most structures in FFmpeg, sizeof(AVChannelCustom) is a part of the + * public ABI. + * + * No new fields may be added to it without a major version bump. + */ +typedef struct AVChannelCustom { + enum AVChannel id; +} AVChannelCustom; + +/** + * An AVChannelLayout holds information about the channel layout of audio data. + * + * A channel layout here is defined as a set of channels ordered in a specific + * way (unless the channel order is AV_CHANNEL_ORDER_UNSPEC, in which case an + * AVChannelLayout carries only the channel count). + * + * Unlike most structures in Libav, sizeof(AVChannelLayout) is a part of the + * public ABI and may be used by the caller. E.g. it may be allocated on stack + * or embedded in caller-defined structs. + * + * AVChannelLayout can be initialized as follows: + * - default initialization with {0}, followed by by setting all used fields + * correctly; + * - by assigning one of the predefined AV_CHANNEL_LAYOUT_* initializers; + * - with a constructor function, such as av_channel_layout_default(), + * av_channel_layout_from_mask() or av_channel_layout_from_string(). + * + * The channel layout must be unitialized with av_channel_layout_uninit() + * (strictly speaking this is not necessary for AV_CHANNEL_ORDER_NATIVE and + * AV_CHANNEL_ORDER_UNSPEC, but we recommend always calling + * av_channel_layout_uninit() regardless of the channel order used). + * + * Copying an AVChannelLayout via assigning is forbidden, + * av_channel_layout_copy() must be used. instead (and its return value should + * be checked) + * + * No new fields may be added to it without a major version bump, except for + * new elements of the union fitting in sizeof(uint64_t). + */ +typedef struct AVChannelLayout { + /** + * Channel order used in this layout. + * This is a mandatory field. + */ + enum AVChannelOrder order; + + /** + * Number of channels in this layout. Mandatory field. + */ + int nb_channels; + + /** + * Details about which channels are present in this layout. + * For AV_CHANNEL_ORDER_UNSPEC, this field is undefined and must not be + * used. + */ + union { + /** + * This member must be used for AV_CHANNEL_ORDER_NATIVE. + * It is a bitmask, where the position of each set bit means that the + * AVChannel with the corresponding value is present. + * + * I.e. when (mask & (1 << AV_CHAN_FOO)) is non-zero, then AV_CHAN_FOO + * is present in the layout. Otherwise it is not present. + * + * @note when a channel layout using a bitmask is constructed or + * modified manually (i.e. not using any of the av_channel_layout_* + * functions), the code doing it must ensure that the number of set bits + * is equal to nb_channels. + */ + uint64_t mask; + /** + * This member must be used when the channel order is + * AV_CHANNEL_ORDER_CUSTOM. It is a nb_channels-sized array, with each + * element signalling the presence of the AVChannel with the + * corresponding value in map[i].id. + * + * I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the + * i-th channel in the audio data. + */ + AVChannelCustom *map; + } u; +} AVChannelLayout; + +#define AV_CHANNEL_LAYOUT_MONO \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 1, .u = { .mask = AV_CH_LAYOUT_MONO }} +#define AV_CHANNEL_LAYOUT_STEREO \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 2, .u = { .mask = AV_CH_LAYOUT_STEREO }} +#define AV_CHANNEL_LAYOUT_2POINT1 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 3, .u = { .mask = AV_CH_LAYOUT_2POINT1 }} +#define AV_CHANNEL_LAYOUT_2_1 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 3, .u = { .mask = AV_CH_LAYOUT_2_1 }} +#define AV_CHANNEL_LAYOUT_SURROUND \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 3, .u = { .mask = AV_CH_LAYOUT_SURROUND }} +#define AV_CHANNEL_LAYOUT_3POINT1 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4, .u = { .mask = AV_CH_LAYOUT_3POINT1 }} +#define AV_CHANNEL_LAYOUT_4POINT0 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4, .u = { .mask = AV_CH_LAYOUT_4POINT0 }} +#define AV_CHANNEL_LAYOUT_4POINT1 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 5, .u = { .mask = AV_CH_LAYOUT_4POINT1 }} +#define AV_CHANNEL_LAYOUT_2_2 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4, .u = { .mask = AV_CH_LAYOUT_2_2 }} +#define AV_CHANNEL_LAYOUT_QUAD \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4, .u = { .mask = AV_CH_LAYOUT_QUAD }} +#define AV_CHANNEL_LAYOUT_5POINT0 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 5, .u = { .mask = AV_CH_LAYOUT_5POINT0 }} +#define AV_CHANNEL_LAYOUT_5POINT1 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6, .u = { .mask = AV_CH_LAYOUT_5POINT1 }} +#define AV_CHANNEL_LAYOUT_5POINT0_BACK \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 5, .u = { .mask = AV_CH_LAYOUT_5POINT0_BACK }} +#define AV_CHANNEL_LAYOUT_5POINT1_BACK \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6, .u = { .mask = AV_CH_LAYOUT_5POINT1_BACK }} +#define AV_CHANNEL_LAYOUT_6POINT0 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6, .u = { .mask = AV_CH_LAYOUT_6POINT0 }} +#define AV_CHANNEL_LAYOUT_6POINT0_FRONT \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6, .u = { .mask = AV_CH_LAYOUT_6POINT0_FRONT }} +#define AV_CHANNEL_LAYOUT_HEXAGONAL \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6, .u = { .mask = AV_CH_LAYOUT_HEXAGONAL }} +#define AV_CHANNEL_LAYOUT_6POINT1 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7, .u = { .mask = AV_CH_LAYOUT_6POINT1 }} +#define AV_CHANNEL_LAYOUT_6POINT1_BACK \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7, .u = { .mask = AV_CH_LAYOUT_6POINT1_BACK }} +#define AV_CHANNEL_LAYOUT_6POINT1_FRONT \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7, .u = { .mask = AV_CH_LAYOUT_6POINT1_FRONT }} +#define AV_CHANNEL_LAYOUT_7POINT0 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7, .u = { .mask = AV_CH_LAYOUT_7POINT0 }} +#define AV_CHANNEL_LAYOUT_7POINT0_FRONT \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7, .u = { .mask = AV_CH_LAYOUT_7POINT0_FRONT }} +#define AV_CHANNEL_LAYOUT_7POINT1 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8, .u = { .mask = AV_CH_LAYOUT_7POINT1 }} +#define AV_CHANNEL_LAYOUT_7POINT1_WIDE \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8, .u = { .mask = AV_CH_LAYOUT_7POINT1_WIDE }} +#define AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8, .u = { .mask = AV_CH_LAYOUT_7POINT1_WIDE_BACK }} +#define AV_CHANNEL_LAYOUT_OCTAGONAL \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8, .u = { .mask = AV_CH_LAYOUT_OCTAGONAL }} +#define AV_CHANNEL_LAYOUT_HEXADECAGONAL \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 16, .u = { .mask = AV_CH_LAYOUT_HEXAGONAL }} +#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 2, .u = { .mask = AV_CH_LAYOUT_STEREO_DOWNMIX }} +#define AV_CHANNEL_LAYOUT_22POINT2 \ + { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 24, .u = { .mask = AV_CH_LAYOUT_22POINT2 }} + +#if FF_API_OLD_CHANNEL_LAYOUT /** * Return a channel layout id that matches name, or 0 if no match is found. * @@ -144,7 +366,10 @@ enum AVMatrixEncoding { * AV_CH_* macros). * * Example: "stereo+FC" = "2c+FC" = "2c+1c" = "0x7" + * + * @deprecated use av_channel_layout_from_string() */ +attribute_deprecated uint64_t av_get_channel_layout(const char *name); /** @@ -158,7 +383,9 @@ uint64_t av_get_channel_layout(const char *name); * @param[out] nb_channels number of channels * * @return 0 on success, AVERROR(EINVAL) if the parsing fails. + * @deprecated use av_channel_layout_from_string() */ +attribute_deprecated int av_get_extended_channel_layout(const char *name, uint64_t* channel_layout, int* nb_channels); /** @@ -167,23 +394,32 @@ int av_get_extended_channel_layout(const char *name, uint64_t* channel_layout, i * * @param buf put here the string containing the channel layout * @param buf_size size in bytes of the buffer + * @deprecated use av_channel_layout_describe() */ +attribute_deprecated void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout); struct AVBPrint; /** * Append a description of a channel layout to a bprint buffer. + * @deprecated use av_channel_layout_describe() */ +attribute_deprecated void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout); /** * Return the number of channels in the channel layout. + * @deprecated use AVChannelLayout.nb_channels */ +attribute_deprecated int av_get_channel_layout_nb_channels(uint64_t channel_layout); /** * Return default channel layout for a given number of channels. + * + * @deprecated use av_channel_layout_default() */ +attribute_deprecated int64_t av_get_default_channel_layout(int nb_channels); /** @@ -194,20 +430,28 @@ int64_t av_get_default_channel_layout(int nb_channels); * * @return index of channel in channel_layout on success, a negative AVERROR * on error. + * + * @deprecated use av_channel_layout_index_from_channel() */ +attribute_deprecated int av_get_channel_layout_channel_index(uint64_t channel_layout, uint64_t channel); /** * Get the channel with the given index in channel_layout. + * @deprecated use av_channel_layout_channel_from_index() */ +attribute_deprecated uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index); /** * Get the name of a given channel. * * @return channel name on success, NULL on error. + * + * @deprecated use av_channel_name() */ +attribute_deprecated const char *av_get_channel_name(uint64_t channel); /** @@ -215,7 +459,9 @@ const char *av_get_channel_name(uint64_t channel); * * @param channel a channel layout with a single channel * @return channel description on success, NULL on error + * @deprecated use av_channel_description() */ +attribute_deprecated const char *av_get_channel_description(uint64_t channel); /** @@ -226,9 +472,211 @@ const char *av_get_channel_description(uint64_t channel); * @param[out] name name of the layout * @return 0 if the layout exists, * <0 if index is beyond the limits + * @deprecated use av_channel_layout_standard() */ +attribute_deprecated int av_get_standard_channel_layout(unsigned index, uint64_t *layout, const char **name); +#endif + +/** + * Get a human readable string in an abbreviated form describing a given channel, + * or "?" if not found. + * This is the inverse function of @ref av_channel_from_string(). + * + * @param buf pre-allocated buffer where to put the generated string + * @param buf_size size in bytes of the buffer. + * @return amount of bytes needed to hold the output string, or a negative AVERROR + * on failure. If the returned value is bigger than buf_size, then the + * string was truncated. + */ +int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel); + +/** + * Get a human readable string describing a given channel, or "?" if not found. + * + * @param buf pre-allocated buffer where to put the generated string + * @param buf_size size in bytes of the buffer. + * @return amount of bytes needed to hold the output string, or a negative AVERROR + * on failure. If the returned value is bigger than buf_size, then the + * string was truncated. + */ +int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel); + +/** + * This is the inverse function of @ref av_channel_name(). + * + * @return the channel with the given name + * AV_CHAN_NONE when name does not identify a known channel + */ +enum AVChannel av_channel_from_string(const char *name); + +/** + * Initialize a native channel layout from a bitmask indicating which channels + * are present. + * + * @param channel_layout the layout structure to be initialized + * @param mask bitmask describing the channel layout + * + * @return 0 on success + * AVERROR(EINVAL) for invalid mask values + */ +int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask); + +/** + * Initialize a channel layout from a given string description. + * The input string can be represented by: + * - the formal channel layout name (returned by av_channel_layout_describe()) + * - single or multiple channel names (returned by av_channel_name() + * or concatenated with "|") + * - a hexadecimal value of a channel layout (eg. "0x4") + * - the number of channels with default layout (eg. "5c") + * - the number of unordered channels (eg. "4" or "4 channels") + * + * @param channel_layout input channel layout + * @param str string describing the channel layout + * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise + */ +int av_channel_layout_from_string(AVChannelLayout *channel_layout, + const char *str); + +/** + * Get the default channel layout for a given number of channels. + * + * @param channel_layout the layout structure to be initialized + * @param nb_channels number of channels + */ +void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels); + +/** + * Iterate over all standard channel layouts. + * + * @param opaque a pointer where libavutil will store the iteration state. Must + * point to NULL to start the iteration. + * + * @return the standard channel layout or NULL when the iteration is + * finished + */ +const AVChannelLayout *av_channel_layout_standard(void **opaque); + +/** + * Free any allocated data in the channel layout and reset the channel + * count to 0. + * + * @param channel_layout the layout structure to be uninitialized + */ +void av_channel_layout_uninit(AVChannelLayout *channel_layout); + +/** + * Make a copy of a channel layout. This differs from just assigning src to dst + * in that it allocates and copies the map for AV_CHANNEL_ORDER_CUSTOM. + * + * @note the destination channel_layout will be always uninitialized before copy. + * + * @param dst destination channel layout + * @param src source channel layout + * @return 0 on success, a negative AVERROR on error. + */ +int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src); + +/** + * Get a human-readable string describing the channel layout properties. + * The string will be in the same format that is accepted by + * @ref av_channel_layout_from_string(). + * + * @param channel_layout channel layout to be described + * @param buf pre-allocated buffer where to put the generated string + * @param buf_size size in bytes of the buffer. + * @return amount of bytes needed to hold the output string, or a negative AVERROR + * on failure. If the returned value is bigger than buf_size, then the + * string was truncated. + */ +int av_channel_layout_describe(const AVChannelLayout *channel_layout, + char *buf, size_t buf_size); + +/** + * Get the channel with the given index in a channel layout. + * + * @param channel_layout input channel layout + * @return channel with the index idx in channel_layout on success or + * AV_CHAN_NONE on failure (if idx is not valid or the channel order is + * unspecified) + */ +enum AVChannel +av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx); + +/** + * Get the index of a given channel in a channel layout. In case multiple + * channels are found, only the first match will be returned. + * + * @param channel_layout input channel layout + * @return index of channel in channel_layout on success or a negative number if + * channel is not present in channel_layout. + */ +int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, + enum AVChannel channel); + +/** + * Get the index in a channel layout of a channel described by the given string. + * In case multiple channels are found, only the first match will be returned. + * + * This function accepts channel names in the same format as + * @ref av_channel_from_string(). + * + * @param channel_layout input channel layout + * @return a channel index described by the given string, or a negative AVERROR + * value. + */ +int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout, + const char *name); + +/** + * Get a channel described by the given string. + * + * This function accepts channel names in the same format as + * @ref av_channel_from_string(). + * + * @param channel_layout input channel layout + * @return a channel described by the given string, or a negative AVERROR value. + */ +int av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout, + const char *name); + +/** + * Find out what channels from a given set are present in a channel layout, + * without regard for their positions. + * + * @param channel_layout input channel layout + * @param mask a combination of AV_CH_* representing a set of channels + * @return a bitfield representing all the channels from mask that are present + * in channel_layout + */ +uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, + uint64_t mask); + +/** + * Check whether a channel layout is valid, i.e. can possibly describe audio + * data. + * + * @param channel_layout input channel layout + * @return 1 if channel_layout is valid, 0 otherwise. + */ +int av_channel_layout_check(const AVChannelLayout *channel_layout); + +/** + * Check whether two channel layouts are semantically the same, i.e. the same + * channels are present on the same positions in both. + * + * If one of the channel layouts is AV_CHANNEL_ORDER_UNSPEC, while the other is + * not, they are considered to be unequal. If both are AV_CHANNEL_ORDER_UNSPEC, + * they are considered equal iff the channel counts are the same in both. + * + * @param chl input channel layout + * @param chl1 input channel layout + * @return 0 if chl and chl1 are equal, 1 if they are not equal. A negative + * AVERROR code if one or both are invalid. + */ +int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1); /** * @} diff --git a/libavutil/version.h b/libavutil/version.h index 017fc277a6..d7179e1fdd 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -109,6 +109,7 @@ #define FF_API_DECLARE_ALIGNED (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_COLORSPACE_NAME (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58) +#define FF_API_OLD_CHANNEL_LAYOUT (LIBAVUTIL_VERSION_MAJOR < 58) /** * @} From patchwork Wed Dec 8 01:06:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32123 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7043171iog; Tue, 7 Dec 2021 17:08:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoiK5Xo+n7mw6sAOeJzzcEHDudkSgo7w7TAxROxshwXfv34p/QOowfPYCK+1bIeo5A5e+t X-Received: by 2002:a50:d68e:: with SMTP id r14mr14610276edi.5.1638925683654; Tue, 07 Dec 2021 17:08:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925683; cv=none; d=google.com; s=arc-20160816; b=l+ZcB5jvYGr9vP2rb8q62R1kW/SQcCYYWRBo+VW/iikU1GK7lz2Nze13/lw6bz14PL gQmSL//WE5H4qEvmxg27v2oE2wq24RW0MYxnB8MwxrZFcK8di5QPdSS8SKBKb3jAlAFS HbJsPN11ytahdnrqtIaI4UY6vJHWH1yo+p5YAQmSz+Y8spTRjTul0mgGD9r3Il3nA+o2 CSASohHp2uBYUKmOm4Z6688x2A2ocC1enMrCr8Q3bmBTPdSju73BdXaY0FoE21rhkuGo q/nSHtOZgIrWSTu6BNe/Lz47EyUkpFOl2qnDiMFzhcB0LcnLuvWzJl8NlpZAhUEX1n5S H8vA== 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=WLKbWkHuPh2qdkp9JNkhxyNblMRiMPXMCrZ+MjRF5bg=; b=wILA/9BPo6tIHsVmHAZyOvPqEeATafkzH0Q02Hpn9kL7DqtSSCIGyIGR5/bgqs4/Qg ldZ9G9gtUfhMdceMR6rarsiKIO7/vvrEXG1ATXRQBJJ4joNhsO1tvv/GGOWezAnJBfwe qWDKM+35ZpS8BBqlxizbeMgsJkvWAGxK2Jhx2v+kJTjB+M9YMrUXzTczMas/XF6ltej2 Dn0MdIDKDVjpig+Qz5+xcmReBtr2Xkf42fTYqwpAQ3MQjrGUJXWJ+99mqCTaAqbwcZpJ sDyrLoVqreB01ZHCNMkxep2cfue87zmcckeVqvQ0F+CXGWda3YOCOUrbcnHjcTqy8/1t h0xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=gEM27om0; 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 cr14si1931758ejc.271.2021.12.07.17.08.02; Tue, 07 Dec 2021 17:08:03 -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=gEM27om0; 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 0AFB768A0C5; Wed, 8 Dec 2021 03:07:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F04FA68A795 for ; Wed, 8 Dec 2021 03:07:25 +0200 (EET) Received: by mail-ua1-f53.google.com with SMTP id ay21so1842312uab.12 for ; Tue, 07 Dec 2021 17:07:25 -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=61Rhtuv5dBSdJ9PEiO5b1PW+IgUVtVsq/BLVBfCCoDY=; b=gEM27om0Qo4dx7RjhTJPR8Oz0lvjsfD2Jn4ZU/5BB4ZEYJwunFB/Lgbu6RU6WGapsV 7qtBtUub8QNeLy9KWOEfOKpXYJp0+qDxX38sPRkg6af6pVxlQUP3Yg7AyqX8VChHBaRT EtfDuWQ4A1uU7Mq1+Z0GT4eVP1Ys3FSiDfDvItPxRMS5gvN2b+dYSc9RaUg1mkxpHETr E683q2My+gNyqXSIwUoyp1JqkHQUPcaG5FTaLAjAelkn2HmxIvLE05FM2U7IJGeTDnsL oTQKORT0EiehP8ic4dT9MHxFBN+gGazO4obDNxLP2g7r5WLkXCA1b2Su2FbEusbUQ4u4 Mm5A== 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=61Rhtuv5dBSdJ9PEiO5b1PW+IgUVtVsq/BLVBfCCoDY=; b=c/93yHTu6gpzGnJ/5QuetJXHjxfDlzwFat3nSMEDirrIUg/0xBPEI40n+ZQ0ZeIN1M 8er6jQDxXZ1BMsrr8ZHewmbLWFGI/D2FeJh6kJQvVzFZX+SekkjnNTrlLjRMwoPJKg7B asnzRiPnriqejlWnocNb/GZjtYu7mknFOjaGYPS9nO/+5g9M85Ga2qucnZejWmxG2jhG 2Lso6uDwaulK0qGaV/9wMRjKO2mNkoVljAD/ozIdCQUaeDjZuemPcS4XVti9uIBhVUOC 0gCUeTnl7g1+b+yhn/32w+UXtL7Y70SiWqVpCAauTPB4183wZr+PsPrrvkIs59Lx8nU1 ui0A== X-Gm-Message-State: AOAM531sHz3rfnbH2mAu/lMbobrAAb/YRHMkmrlDEbhUP3jQVshoy4G5 IzbpgXFU8FynsjFOlYEOno5jMD9czIg5ueKW X-Received: by 2002:a05:6102:725:: with SMTP id u5mr48747006vsg.78.1638925644192; Tue, 07 Dec 2021 17:07:24 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:23 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:18 -0300 Message-Id: <20211208010649.381-3-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 002/279] fate: add a channel_layout API test 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: VtZh0mMNILRQ Signed-off-by: James Almer --- libavutil/Makefile | 1 + libavutil/tests/channel_layout.c | 221 +++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 4 + tests/ref/fate/channel_layout | 88 ++++++++++++ 4 files changed, 314 insertions(+) create mode 100644 libavutil/tests/channel_layout.c create mode 100644 tests/ref/fate/channel_layout diff --git a/libavutil/Makefile b/libavutil/Makefile index 529046dbc8..8915575cfa 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -219,6 +219,7 @@ TESTPROGS = adler32 \ bprint \ cast5 \ camellia \ + channel_layout \ color_utils \ cpu \ crc \ diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c new file mode 100644 index 0000000000..60854cf203 --- /dev/null +++ b/libavutil/tests/channel_layout.c @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2021 James Almer + * + * 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 "libavutil/channel_layout.c" + +#define CHANNEL_LAYOUT_FROM_MASK(layout, x) \ + av_channel_layout_uninit(&layout); \ + buf[0] = 0; \ + if (!av_channel_layout_from_mask(&layout, x)) \ + av_channel_layout_describe(&layout, buf, sizeof(buf)); + +#define CHANNEL_LAYOUT_FROM_STRING(layout, x) \ + av_channel_layout_uninit(&layout); \ + buf[0] = 0; \ + if (!av_channel_layout_from_string(&layout, x)) \ + av_channel_layout_describe(&layout, buf, sizeof(buf)); + +#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(layout, x) \ + ret = av_channel_layout_channel_from_index(&layout, x); \ + if (ret < 0) \ + ret = -1 + +#define CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(layout, x) \ + ret = av_channel_layout_index_from_channel(&layout, x); \ + if (ret < 0) \ + ret = -1 + +#define CHANNEL_LAYOUT_CHANNEL_FROM_STRING(layout, x) \ + ret = av_channel_layout_channel_from_string(&layout, x); \ + if (ret < 0) \ + ret = -1 + +#define CHANNEL_LAYOUT_INDEX_FROM_STRING(layout, x) \ + ret = av_channel_layout_index_from_string(&layout, x); \ + if (ret < 0) \ + ret = -1 + +int main(void) +{ + AVChannelLayout surround = { 0 }; + AVChannelLayout custom = { 0 }; + char buf[64]; + int ret; + + printf("Testing av_channel_name\n"); + av_channel_name(buf, sizeof(buf), AV_CHAN_FRONT_LEFT); + printf("With AV_CHAN_FRONT_LEFT: %27s\n", buf); + av_channel_name(buf, sizeof(buf), AV_CHAN_FRONT_RIGHT); + printf("With AV_CHAN_FRONT_RIGHT: %26s\n", buf); + + printf("Testing av_channel_description\n"); + av_channel_description(buf, sizeof(buf), AV_CHAN_FRONT_LEFT); + printf("With AV_CHAN_FRONT_LEFT: %27s\n", buf); + av_channel_description(buf, sizeof(buf), AV_CHAN_FRONT_RIGHT); + printf("With AV_CHAN_FRONT_RIGHT: %26s\n", buf); + + printf("\nTesting av_channel_from_string\n"); + printf("With \"FL\": %41d\n", av_channel_from_string("FL")); + printf("With \"FR\": %41d\n", av_channel_from_string("FR")); + + printf("\nTesting av_channel_layout_from_string\n"); + CHANNEL_LAYOUT_FROM_STRING(surround, "0x3f"); + printf("With \"0x3f\": %39s\n", buf); + CHANNEL_LAYOUT_FROM_STRING(surround, "6c"); + printf("With \"6c\": %41s\n", buf); + CHANNEL_LAYOUT_FROM_STRING(surround, "6"); + printf("With \"6\": %42s\n", buf); + CHANNEL_LAYOUT_FROM_STRING(surround, "6 channels"); + printf("With \"6 channels\": %33s\n", buf); + CHANNEL_LAYOUT_FROM_STRING(surround, "FL|FR|FC|BL|BR|LFE"); + printf("With \"FL|FR|FC|BL|BR|LFE\": %25s\n", buf); + CHANNEL_LAYOUT_FROM_STRING(surround, "5.1"); + printf("With \"5.1\": %40s\n", buf); + CHANNEL_LAYOUT_FROM_STRING(surround, "FL|FR|FC|SL|SR|LFE"); + printf("With \"FL|FR|FC|SL|SR|LFE\": %25s\n", buf); + CHANNEL_LAYOUT_FROM_STRING(surround, "5.1(side)"); + printf("With \"5.1(side)\": %34s\n", buf); + + printf("\n==Native layouts==\n"); + + printf("\nTesting av_channel_layout_from_mask\n"); + CHANNEL_LAYOUT_FROM_MASK(surround, AV_CH_LAYOUT_5POINT1); + printf("With AV_CH_LAYOUT_5POINT1: %25s\n", buf); + + printf("\nTesting av_channel_layout_channel_from_index\n"); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 0); + printf("On 5.1(side) layout with 0: %24d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 1); + printf("On 5.1(side) layout with 1: %24d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 2); + printf("On 5.1(side) layout with 2: %24d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 3); + printf("On 5.1(side) layout with 3: %24d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 4); + printf("On 5.1(side) layout with 4: %24d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 5); + printf("On 5.1(side) layout with 5: %24d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 6); + printf("On 5.1(side) layout with 6: %24d\n", ret); + + printf("\nTesting av_channel_layout_index_from_channel\n"); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_FRONT_LEFT); + printf("On 5.1(side) layout with AV_CHAN_FRONT_LEFT: %7d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_FRONT_RIGHT); + printf("On 5.1(side) layout with AV_CHAN_FRONT_RIGHT: %6d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_FRONT_CENTER); + printf("On 5.1(side) layout with AV_CHAN_FRONT_CENTER: %5d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_LOW_FREQUENCY); + printf("On 5.1(side) layout with AV_CHAN_LOW_FREQUENCY: %4d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_SIDE_LEFT); + printf("On 5.1(side) layout with AV_CHAN_SIDE_LEFT: %8d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_SIDE_RIGHT); + printf("On 5.1(side) layout with AV_CHAN_SIDE_RIGHT: %7d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_BACK_CENTER); + printf("On 5.1(side) layout with AV_CHAN_BACK_CENTER: %6d\n", ret); + + printf("\nTesting av_channel_layout_channel_from_string\n"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "FL"); + printf("On 5.1(side) layout with \"FL\": %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "FR"); + printf("On 5.1(side) layout with \"FR\": %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "FC"); + printf("On 5.1(side) layout with \"FC\": %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "LFE"); + printf("On 5.1(side) layout with \"LFE\": %20d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "SL"); + printf("On 5.1(side) layout with \"SL\": %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "SR"); + printf("On 5.1(side) layout with \"SR\": %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "BC"); + printf("On 5.1(side) layout with \"BC\": %21d\n", ret); + + printf("\nTesting av_channel_layout_index_from_string\n"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "FL"); + printf("On 5.1(side) layout with \"FL\": %21d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "FR"); + printf("On 5.1(side) layout with \"FR\": %21d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "FC"); + printf("On 5.1(side) layout with \"FC\": %21d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "LFE"); + printf("On 5.1(side) layout with \"LFE\": %20d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "SL"); + printf("On 5.1(side) layout with \"SL\": %21d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "SR"); + printf("On 5.1(side) layout with \"SR\": %21d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "BC"); + printf("On 5.1(side) layout with \"BC\": %21d\n", ret); + + printf("\n==Custom layouts==\n"); + + custom.order = AV_CHANNEL_ORDER_CUSTOM; + custom.nb_channels = 3; + custom.u.map = av_mallocz_array(3, sizeof(*custom.u.map)); + if (!custom.u.map) + return 1; + custom.u.map[0].id = AV_CHAN_FRONT_RIGHT; + custom.u.map[1].id = AV_CHAN_FRONT_LEFT; + custom.u.map[2].id = 63; + buf[0] = 0; + printf("\nTesting av_channel_layout_describe\n"); + av_channel_layout_describe(&custom, buf, sizeof(buf)); + printf("On \"FR|FL|Ch63\" layout: %28s\n", buf); + + printf("\nTesting av_channel_layout_index_from_string\n"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "FR"); + printf("On \"FR|FL|Ch63\" layout with \"FR\": %18d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "FL"); + printf("On \"FR|FL|Ch63\" layout with \"FL\": %18d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "BC"); + printf("On \"FR|FL|Ch63\" layout with \"BC\": %18d\n", ret); + + printf("\nTesting av_channel_layout_channel_from_string\n"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "FR"); + printf("On \"FR|FL|Ch63\" layout with \"FR\": %18d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "FL"); + printf("On \"FR|FL|Ch63\" layout with \"FL\": %18d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "BC"); + printf("On \"FR|FL|Ch63\" layout with \"BC\": %18d\n", ret); + + printf("\nTesting av_channel_layout_index_from_channel\n"); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, AV_CHAN_FRONT_RIGHT); + printf("On \"FR|FL|Ch63\" layout with AV_CHAN_FRONT_RIGHT: %3d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, AV_CHAN_FRONT_LEFT); + printf("On \"FR|FL|Ch63\" layout with AV_CHAN_FRONT_LEFT: %4d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, 63); + printf("On \"FR|FL|Ch63\" layout with 63: %20d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, AV_CHAN_BACK_CENTER); + printf("On \"FR|FL|Ch63\" layout with AV_CHAN_BACK_CENTER: %3d\n", ret); + + printf("\nTesting av_channel_layout_channel_from_index\n"); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 0); + printf("On \"FR|FL|Ch63\" layout with 0: %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 1); + printf("On \"FR|FL|Ch63\" layout with 1: %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 2); + printf("On \"FR|FL|Ch63\" layout with 2: %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 3); + printf("On \"FR|FL|Ch63\" layout with 3: %21d\n", ret); + + av_channel_layout_uninit(&surround); + av_channel_layout_uninit(&custom); + + return 0; +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 1ec9ed00ad..c32cf2e706 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -23,6 +23,10 @@ fate-cast5: libavutil/tests/cast5$(EXESUF) fate-cast5: CMD = run libavutil/tests/cast5$(EXESUF) fate-cast5: CMP = null +FATE_LIBAVUTIL += fate-channel_layout +fate-channel_layout: libavutil/tests/channel_layout$(EXESUF) +fate-channel_layout: CMD = run libavutil/tests/channel_layout$(EXESUF) + FATE_LIBAVUTIL += fate-audio_fifo fate-audio_fifo: libavutil/tests/audio_fifo$(EXESUF) fate-audio_fifo: CMD = run libavutil/tests/audio_fifo$(EXESUF) diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout new file mode 100644 index 0000000000..89d43f46f4 --- /dev/null +++ b/tests/ref/fate/channel_layout @@ -0,0 +1,88 @@ +Testing av_channel_name +With AV_CHAN_FRONT_LEFT: FL +With AV_CHAN_FRONT_RIGHT: FR +Testing av_channel_description +With AV_CHAN_FRONT_LEFT: front left +With AV_CHAN_FRONT_RIGHT: front right + +Testing av_channel_from_string +With "FL": 0 +With "FR": 1 + +Testing av_channel_layout_from_string +With "0x3f": 5.1 +With "6c": 5.1 +With "6": 6 channels +With "6 channels": 6 channels +With "FL|FR|FC|BL|BR|LFE": 5.1 +With "5.1": 5.1 +With "FL|FR|FC|SL|SR|LFE": 5.1(side) +With "5.1(side)": 5.1(side) + +==Native layouts== + +Testing av_channel_layout_from_mask +With AV_CH_LAYOUT_5POINT1: 5.1(side) + +Testing av_channel_layout_channel_from_index +On 5.1(side) layout with 0: 0 +On 5.1(side) layout with 1: 1 +On 5.1(side) layout with 2: 2 +On 5.1(side) layout with 3: 3 +On 5.1(side) layout with 4: 9 +On 5.1(side) layout with 5: 10 +On 5.1(side) layout with 6: -1 + +Testing av_channel_layout_index_from_channel +On 5.1(side) layout with AV_CHAN_FRONT_LEFT: 0 +On 5.1(side) layout with AV_CHAN_FRONT_RIGHT: 1 +On 5.1(side) layout with AV_CHAN_FRONT_CENTER: 2 +On 5.1(side) layout with AV_CHAN_LOW_FREQUENCY: 3 +On 5.1(side) layout with AV_CHAN_SIDE_LEFT: 4 +On 5.1(side) layout with AV_CHAN_SIDE_RIGHT: 5 +On 5.1(side) layout with AV_CHAN_BACK_CENTER: -1 + +Testing av_channel_layout_channel_from_string +On 5.1(side) layout with "FL": 0 +On 5.1(side) layout with "FR": 1 +On 5.1(side) layout with "FC": 2 +On 5.1(side) layout with "LFE": 3 +On 5.1(side) layout with "SL": 9 +On 5.1(side) layout with "SR": 10 +On 5.1(side) layout with "BC": -1 + +Testing av_channel_layout_index_from_string +On 5.1(side) layout with "FL": 0 +On 5.1(side) layout with "FR": 1 +On 5.1(side) layout with "FC": 2 +On 5.1(side) layout with "LFE": 3 +On 5.1(side) layout with "SL": 4 +On 5.1(side) layout with "SR": 5 +On 5.1(side) layout with "BC": -1 + +==Custom layouts== + +Testing av_channel_layout_describe +On "FR|FL|Ch63" layout: FR|FL|? + +Testing av_channel_layout_index_from_string +On "FR|FL|Ch63" layout with "FR": 0 +On "FR|FL|Ch63" layout with "FL": 1 +On "FR|FL|Ch63" layout with "BC": -1 + +Testing av_channel_layout_channel_from_string +On "FR|FL|Ch63" layout with "FR": 1 +On "FR|FL|Ch63" layout with "FL": 0 +On "FR|FL|Ch63" layout with "BC": -1 + +Testing av_channel_layout_index_from_channel +On "FR|FL|Ch63" layout with AV_CHAN_FRONT_RIGHT: 0 +On "FR|FL|Ch63" layout with AV_CHAN_FRONT_LEFT: 1 +On "FR|FL|Ch63" layout with 63: 2 +On "FR|FL|Ch63" layout with AV_CHAN_BACK_CENTER: -1 + +Testing av_channel_layout_channel_from_index +On "FR|FL|Ch63" layout with 0: 1 +On "FR|FL|Ch63" layout with 1: 0 +On "FR|FL|Ch63" layout with 2: 63 +On "FR|FL|Ch63" layout with 3: -1 From patchwork Wed Dec 8 01:06:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32121 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7043419iog; Tue, 7 Dec 2021 17:08:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9nAsjRilAMupjvq/NbHRTONthvLJGIitxghoALoL7F9RRLxXuE7EmIViJZSwnPPAbdLIP X-Received: by 2002:a17:907:98f6:: with SMTP id ke22mr3518669ejc.500.1638925696418; Tue, 07 Dec 2021 17:08:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925696; cv=none; d=google.com; s=arc-20160816; b=V501v6r22K9hAGhXWIYdZO/K4jzjRo/NouE+PQ80OLHpYGU7rYYoE/cao6w8WOdMsr 2eb+X5rxVy1jVGze+MZOIEI/piW+8OtvL1D4CmASTTAkXVpYYE1ZO2MDtj8ZisMVcElZ n9XK72kM9lvGQeM0hD627v8uBbQI38ly09V5RZNV75Uihw+ouUzMzCVwYX5OJ4gH6REI VLi2X74BQhJYU3ld6o5DJGCXdViD5vpMtvW+NX1eMmKAIblxHDvhz96ic4DNc6EwFrj3 KMkz9wOj7SBiovFaEH1i/by7es/wiYfbjH1HfMBvL//2O3zR+12h9UE+jbeq3i1RTpQe jzZQ== 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=aQ3T+CMgpbWnzl5VNDYhgjFL78NvyopgDbQIliaAFZs=; b=S34OozDcj/ONPS5lzp653N4V9hpCRVI70sV60A6zGZg0QRX4O6b7+rAHJIwcaoVYlu hbV/iZZv7NPt1W39bZg4mLHz2FuUhelhw9fxoiFqN4h5SawNCk1h2n0obFEUtHcXTEi9 5S0SExCWpW2NtDHjoDVz073oOBe3jzb28XY7vzfryfi2uDx9zoB5SUOjmSAFH9qjp58j p1NyXGFkbJONdlCS9jHxZM14UlmT4KVeBvaehCYn1UkUmUKVUujISZB3maxmu0fLsCeq eDUNVbXhQNWzFxDnk9SZTt9h2cHhDId1JEK1mVm3rTIFoVLYlbJgtDNY9vtuN+TLjlO5 Qvwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=mMtII7xd; 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 cx23si1780591edb.77.2021.12.07.17.08.15; Tue, 07 Dec 2021 17:08:16 -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=mMtII7xd; 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 021B568AD15; Wed, 8 Dec 2021 03:07:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C0E768AB82 for ; Wed, 8 Dec 2021 03:07:27 +0200 (EET) Received: by mail-ua1-f45.google.com with SMTP id r15so1930635uao.3 for ; Tue, 07 Dec 2021 17:07:27 -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=rgDocvg/ef6ttiqymDkxTfJqX77gt4UdtB3h2k7zv1s=; b=mMtII7xdQqd7RCV3TDyWnnee3DQIHDMOVqzGFah09kK2icglZC1bOlDrWoB9c1oC45 jso9hYzmSRQLrBWKX5r0xJoZxjxhAbPpLjLHdnpLQpQn61tHPLMO2alTBYdIUw460tzn ySzzh/DrAA/V4lTHE1QpJ8hUepk/T5T24+gLmBBfZ9CHJqTkLyKFcA2QUyueDt4r33Ax ULsU/Tk4B6ovgKfVs7tjGyuUaVwQUvughu8rYDvKCL/pj73Al4LdQS4MwEDlQGWirsfj FXni1fU9J3Yk5oG/60GUEpQjNQIPRzgIC13/S00TglnoJch4zgwdMlMh7Uy1qqYewqR+ Ud3A== 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=rgDocvg/ef6ttiqymDkxTfJqX77gt4UdtB3h2k7zv1s=; b=RWxv3utsA6nzOViFe82SF4NRCQs2HSss3o5Dqm659LxWortPc/cBcRxXiAhQSO6BcB hN4/2AatOUbFaWWesAf8jjiaNfTO68t/al8f8wiuJlqyRXqLrChGVdIxPCuozojxt8wL Jv+EuYLPoVkdz8ltvV3CIjMTMmOGqv92d0DaLNtvVQsFiXOasDMPsmOwMTM0OLeh4320 f8HW1TkZTtM/ntri5zKN7zbQqTSgXyR0vVpfgOtaIBPKXKvzcQKjecPBI+moIQwk3jyz BywVJMHwaO3K/KpDxL4NE+aG6oPUJZ89xS7nFwGVMnnbzo1+p8NutQlMpY/L8tkMG9tf YQVQ== X-Gm-Message-State: AOAM532UHwA6QolXJL0wwmJHZpL/k19Nq4w+Z1GGQChcOgvXkkBuHWho d6+Vd13ahxQ/8x3PhwRfZPh8vtiboz6nd+sL X-Received: by 2002:a67:dd12:: with SMTP id y18mr49375989vsj.56.1638925645598; Tue, 07 Dec 2021 17:07:25 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:25 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:19 -0300 Message-Id: <20211208010649.381-4-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 003/279] lavu: support AVChannelLayout AVOptions 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: InIjHxytnSob From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavutil/opt.c | 126 +++++++++++++++++++++++++++++++++++++++++- libavutil/opt.h | 12 ++++ libavutil/tests/opt.c | 8 +-- tests/ref/fate/opt | 16 +++--- 4 files changed, 149 insertions(+), 13 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index d951edca9d..445537fbad 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -39,6 +39,7 @@ #include "opt.h" #include "samplefmt.h" #include "bprint.h" +#include "version.h" #include @@ -71,7 +72,11 @@ static int read_number(const AVOption *o, const void *dst, double *num, int *den case AV_OPT_TYPE_INT: *intnum = *(int *)dst; return 0; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: +FF_ENABLE_DEPRECATION_WARNINGS +#endif case AV_OPT_TYPE_DURATION: case AV_OPT_TYPE_INT64: case AV_OPT_TYPE_UINT64: @@ -126,7 +131,11 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int *(int *)dst = llrint(num / den) * intnum; break; case AV_OPT_TYPE_DURATION: +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: +FF_ENABLE_DEPRECATION_WARNINGS +#endif case AV_OPT_TYPE_INT64:{ double d = num / den; if (intnum == 1 && d == (double)INT64_MAX) { @@ -465,6 +474,16 @@ static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_ return 0; } +static int set_string_channel_layout(void *obj, const AVOption *o, + const char *val, void *dst) +{ + AVChannelLayout *channel_layout = dst; + av_channel_layout_uninit(channel_layout); + if (!val) + return 0; + return av_channel_layout_from_string(channel_layout, val); +} + int av_opt_set(void *obj, const char *name, const char *val, int search_flags) { int ret = 0; @@ -472,12 +491,17 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags) const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); if (!o || !target_obj) return AVERROR_OPTION_NOT_FOUND; +FF_DISABLE_DEPRECATION_WARNINGS if (!val && (o->type != AV_OPT_TYPE_STRING && o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT && o->type != AV_OPT_TYPE_IMAGE_SIZE && o->type != AV_OPT_TYPE_DURATION && o->type != AV_OPT_TYPE_COLOR && - o->type != AV_OPT_TYPE_CHANNEL_LAYOUT && o->type != AV_OPT_TYPE_BOOL)) +#if FF_API_OLD_CHANNEL_LAYOUT + o->type != AV_OPT_TYPE_CHANNEL_LAYOUT && +#endif + o->type != AV_OPT_TYPE_BOOL)) return AVERROR(EINVAL); +FF_ENABLE_DEPRECATION_WARNINGS if (o->flags & AV_OPT_FLAG_READONLY) return AVERROR(EINVAL); @@ -533,6 +557,8 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags) } case AV_OPT_TYPE_COLOR: return set_string_color(obj, o, val, dst); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: if (!val || !strcmp(val, "none")) { *(int64_t *)dst = 0; @@ -546,6 +572,15 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags) return ret; } break; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + case AV_OPT_TYPE_CHLAYOUT: + ret = set_string_channel_layout(obj, o, val, dst); + if (ret < 0) { + av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val); + ret = AVERROR(EINVAL); + } + return ret; case AV_OPT_TYPE_DICT: return set_string_dict(obj, o, val, dst); } @@ -709,6 +744,8 @@ int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB); } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags) { void *target_obj; @@ -724,6 +761,8 @@ int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int searc *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl; return 0; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags) @@ -744,6 +783,22 @@ int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, return 0; } +int av_opt_set_chlayout(void *obj, const char *name, + const AVChannelLayout *channel_layout, + int search_flags) +{ + void *target_obj; + const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + AVChannelLayout *dst; + + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + + dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset); + + return av_channel_layout_copy(dst, channel_layout); +} + static void format_duration(char *buf, size_t size, int64_t d) { char *e; @@ -872,10 +927,18 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1], (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]); break; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: + i64 = *(int64_t *)dst; ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64); break; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + case AV_OPT_TYPE_CHLAYOUT: + ret = av_channel_layout_describe(dst, buf, sizeof(buf)); + break; case AV_OPT_TYPE_DICT: if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) { *out_val = NULL; @@ -1017,6 +1080,8 @@ int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AV return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample"); } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl) { void *dst, *target_obj; @@ -1033,6 +1098,24 @@ int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int *cl = *(int64_t *)dst; return 0; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + +int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl) +{ + void *dst, *target_obj; + const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + if (o->type != AV_OPT_TYPE_CHLAYOUT) { + av_log(obj, AV_LOG_ERROR, + "The value for option '%s' is not a channel layout.\n", name); + return AVERROR(EINVAL); + } + + dst = ((uint8_t*)target_obj) + o->offset; + return av_channel_layout_copy(cl, dst); +} int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val) { @@ -1225,7 +1308,12 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit, case AV_OPT_TYPE_COLOR: av_log(av_log_obj, AV_LOG_INFO, "%-12s ", ""); break; + case AV_OPT_TYPE_CHLAYOUT: +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: +FF_ENABLE_DEPRECATION_WARNINGS +#endif av_log(av_log_obj, AV_LOG_INFO, "%-12s ", ""); break; case AV_OPT_TYPE_BOOL: @@ -1282,6 +1370,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit, opt->type == AV_OPT_TYPE_IMAGE_SIZE || opt->type == AV_OPT_TYPE_STRING || opt->type == AV_OPT_TYPE_DICT || + opt->type == AV_OPT_TYPE_CHLAYOUT || opt->type == AV_OPT_TYPE_VIDEO_RATE) && !opt->default_val.str)) { av_log(av_log_obj, AV_LOG_INFO, " (default "); @@ -1334,11 +1423,16 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit, case AV_OPT_TYPE_STRING: case AV_OPT_TYPE_DICT: case AV_OPT_TYPE_VIDEO_RATE: + case AV_OPT_TYPE_CHLAYOUT: av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str); break; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64); break; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } av_log(av_log_obj, AV_LOG_INFO, ")"); } @@ -1388,7 +1482,11 @@ void av_opt_set_defaults2(void *s, int mask, int flags) case AV_OPT_TYPE_INT64: case AV_OPT_TYPE_UINT64: case AV_OPT_TYPE_DURATION: +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: +FF_ENABLE_DEPRECATION_WARNINGS +#endif case AV_OPT_TYPE_PIXEL_FMT: case AV_OPT_TYPE_SAMPLE_FMT: write_number(s, opt, dst, 1, 1, opt->default_val.i64); @@ -1421,6 +1519,9 @@ void av_opt_set_defaults2(void *s, int mask, int flags) case AV_OPT_TYPE_BINARY: set_string_binary(s, opt, opt->default_val.str, dst); break; + case AV_OPT_TYPE_CHLAYOUT: + set_string_channel_layout(s, opt, opt->default_val.str, dst); + break; case AV_OPT_TYPE_DICT: set_string_dict(s, opt, opt->default_val.str, dst); break; @@ -1745,7 +1846,11 @@ static int opt_size(enum AVOptionType type) case AV_OPT_TYPE_FLAGS: return sizeof(int); case AV_OPT_TYPE_DURATION: +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: +FF_ENABLE_DEPRECATION_WARNINGS +#endif case AV_OPT_TYPE_INT64: case AV_OPT_TYPE_UINT64: return sizeof(int64_t); @@ -1819,6 +1924,9 @@ int av_opt_copy(void *dst, const void *src) ret2 = av_dict_copy(ddict, *sdict, 0); if (ret2 < 0) ret = ret2; + } else if (o->type == AV_OPT_TYPE_CHLAYOUT) { + if (field_dst != field_src) + ret = av_channel_layout_copy(field_dst, field_src); } else { int size = opt_size(o->type); if (size < 0) @@ -1882,7 +1990,11 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch case AV_OPT_TYPE_DOUBLE: case AV_OPT_TYPE_DURATION: case AV_OPT_TYPE_COLOR: +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: +FF_ENABLE_DEPRECATION_WARNINGS +#endif break; case AV_OPT_TYPE_STRING: range->component_min = 0; @@ -1962,12 +2074,24 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o) case AV_OPT_TYPE_PIXEL_FMT: case AV_OPT_TYPE_SAMPLE_FMT: case AV_OPT_TYPE_INT: +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS case AV_OPT_TYPE_CHANNEL_LAYOUT: +FF_ENABLE_DEPRECATION_WARNINGS +#endif case AV_OPT_TYPE_DURATION: case AV_OPT_TYPE_INT64: case AV_OPT_TYPE_UINT64: read_number(o, dst, NULL, NULL, &i64); return o->default_val.i64 == i64; + case AV_OPT_TYPE_CHLAYOUT: { + AVChannelLayout ch_layout = { 0 }; + if (o->default_val.str) { + if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0) + return ret; + } + return !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout); + } case AV_OPT_TYPE_STRING: str = *(char **)dst; if (str == o->default_val.str) //2 NULLs diff --git a/libavutil/opt.h b/libavutil/opt.h index 2820435eec..461b5d3b6b 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -29,6 +29,7 @@ #include "rational.h" #include "avutil.h" +#include "channel_layout.h" #include "dict.h" #include "log.h" #include "pixfmt.h" @@ -237,8 +238,11 @@ enum AVOptionType{ AV_OPT_TYPE_VIDEO_RATE, ///< offset must point to AVRational AV_OPT_TYPE_DURATION, AV_OPT_TYPE_COLOR, +#if FF_API_OLD_CHANNEL_LAYOUT AV_OPT_TYPE_CHANNEL_LAYOUT, +#endif AV_OPT_TYPE_BOOL, + AV_OPT_TYPE_CHLAYOUT, }; /** @@ -693,7 +697,11 @@ int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_ int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags); int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags); int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags); +#if FF_API_OLD_CHANNEL_LAYOUT +attribute_deprecated int av_opt_set_channel_layout(void *obj, const char *name, int64_t ch_layout, int search_flags); +#endif +int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *layout, int search_flags); /** * @note Any old dictionary present is discarded and replaced with a copy of the new one. The * caller still owns val is and responsible for freeing it. @@ -748,7 +756,11 @@ int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_ int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt); int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt); int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val); +#if FF_API_OLD_CHANNEL_LAYOUT +attribute_deprecated int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *ch_layout); +#endif +int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *layout); /** * @param[out] out_val The returned dictionary is a copy of the actual value and must * be freed with av_dict_free() by the caller diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index e6ea892373..f1c222e850 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -41,7 +41,7 @@ typedef struct TestContext { enum AVSampleFormat sample_fmt; int64_t duration; uint8_t color[4]; - int64_t channel_layout; + AVChannelLayout channel_layout; void *binary; int binary_size; void *binary1; @@ -81,7 +81,7 @@ static const AVOption test_options[]= { {"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, INT_MAX, 1 }, {"duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 1000 }, 0, INT64_MAX, 1 }, {"color", "set color", OFFSET(color), AV_OPT_TYPE_COLOR, { .str = "pink" }, 0, 0, 1 }, - {"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, { .i64 = AV_CH_LAYOUT_HEXAGONAL }, 0, INT64_MAX, 1 }, + {"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHLAYOUT, { .str = "hexagonal" }, 0, 0, 1 }, {"bin", "set binary value", OFFSET(binary), AV_OPT_TYPE_BINARY, { .str="62696e00" }, 0, 0, 1 }, {"bin1", "set binary value", OFFSET(binary1), AV_OPT_TYPE_BINARY, { .str=NULL }, 0, 0, 1 }, {"bin2", "set binary value", OFFSET(binary2), AV_OPT_TYPE_BINARY, { .str="" }, 0, 0, 1 }, @@ -138,7 +138,7 @@ int main(void) printf("sample_fmt=%s\n", av_get_sample_fmt_name(test_ctx.sample_fmt)); printf("duration=%"PRId64"\n", test_ctx.duration); printf("color=%d %d %d %d\n", test_ctx.color[0], test_ctx.color[1], test_ctx.color[2], test_ctx.color[3]); - printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout, (int64_t)AV_CH_LAYOUT_HEXAGONAL); + printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout.u.mask, (int64_t)AV_CH_LAYOUT_HEXAGONAL); if (test_ctx.binary) printf("binary=%x %x %x %x\n", ((uint8_t*)test_ctx.binary)[0], ((uint8_t*)test_ctx.binary)[1], ((uint8_t*)test_ctx.binary)[2], ((uint8_t*)test_ctx.binary)[3]); printf("binary_size=%d\n", test_ctx.binary_size); @@ -280,7 +280,7 @@ int main(void) "color=blue", "color=0x223300", "color=0x42FF07AA", - "cl=stereo+downmix", + "cl=FL|FR", "cl=foo", "bin=boguss", "bin=111", diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt index aac3fa0e7e..4c7290c34a 100644 --- a/tests/ref/fate/opt +++ b/tests/ref/fate/opt @@ -33,7 +33,7 @@ TestContext AVOptions: -video_rate E.......... set videorate (default "25") -duration E.......... set duration (default 0.001) -color E.......... set color (default "pink") - -cl E.......... set channel layout (default 0x137) + -cl E.......... set channel layout (default "hexagonal") -bin E.......... set binary value -bin1 E.......... set binary value -bin2 E.......... set binary value @@ -115,7 +115,7 @@ name: sample_fmt get: s16 set: OK get: s16 name: video_rate get: 25/1 set: OK get: 25/1 OK name: duration get: 0.001 set: OK get: 0.001 OK name: color get: 0xffc0cbff set: OK get: 0xffc0cbff OK -name: cl get: 0x137 set: OK get: 0x137 OK +name: cl get: hexagonal set: OK get: hexagonal OK name: bin get: 62696E00 set: OK get: 62696E00 OK name: bin1 get: set: OK get: OK name: bin2 get: set: OK get: OK @@ -129,7 +129,7 @@ name: dict1 get: set: OK get: name: dict2 get: happy=\:-) set: OK get: happy=\:-) OK Test av_opt_serialize() -num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=0x137,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-) +num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-) Setting entry with key 'num' to value '0' Setting entry with key 'toggle' to value '1' Setting entry with key 'rational' to value '1/1' @@ -142,7 +142,7 @@ Setting entry with key 'sample_fmt' to value 's16' Setting entry with key 'video_rate' to value '25/1' Setting entry with key 'duration' to value '0.001' Setting entry with key 'color' to value '0xffc0cbff' -Setting entry with key 'cl' to value '0x137' +Setting entry with key 'cl' to value 'hexagonal' Setting entry with key 'bin' to value '62696E00' Setting entry with key 'bin1' to value '' Setting entry with key 'bin2' to value '' @@ -154,7 +154,7 @@ Setting entry with key 'bool2' to value 'true' Setting entry with key 'bool3' to value 'false' Setting entry with key 'dict1' to value '' Setting entry with key 'dict2' to value 'happy=\:-)' -num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=0x137,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-) +num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-) Testing av_set_options_string() Setting options string '' @@ -296,9 +296,9 @@ OK 'color=0x223300' Setting options string 'color=0x42FF07AA' Setting entry with key 'color' to value '0x42FF07AA' OK 'color=0x42FF07AA' -Setting options string 'cl=stereo+downmix' -Setting entry with key 'cl' to value 'stereo+downmix' -OK 'cl=stereo+downmix' +Setting options string 'cl=FL|FR' +Setting entry with key 'cl' to value 'FL|FR' +OK 'cl=FL|FR' Setting options string 'cl=foo' Setting entry with key 'cl' to value 'foo' Unable to parse option value "foo" as channel layout From patchwork Wed Dec 8 01:06:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32118 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7043650iog; Tue, 7 Dec 2021 17:08:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkZ/wOypqeMMXJDiDu+POCwBs2i68GcayOby/s0Hv0E6RxrJ95zh+D9orzc7zNbpoOWhyC X-Received: by 2002:aa7:c2c6:: with SMTP id m6mr14439825edp.42.1638925708386; Tue, 07 Dec 2021 17:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925708; cv=none; d=google.com; s=arc-20160816; b=B7Mfj4g4P2hTI8VKQUmOsJkOUQ2VaXDirvv7289LdCrRT1msfatqfnO8Apl3uMv+gA ATvVzHHt6bPRs9eLdrWNa+gM5l1Bceq+QBpHp9zSJyn01ktEKm+1RVPZIA7yIjYy5/1I TE9W7qHG+bEz7fYIJRcH/sbtIIio+0BempHI6NpHWbQjhesmMelxRhF8oXBBXTbtx792 ZxIpFEDmB6epbI1PJ7G6cW5la3n2BrQkbgRT28/5nZY5CjcG3M0tq0zqaUAzpcRppyaz +GhQNzdPhnmesSqb/1jEejhz1M2Q8+wLn9MwZg5MzfMNvLIRsi8YXvjDwBWiskE8LftV vqqw== 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=l5BGStm78ylwQfNB+6ptqEZdQrcMWMNwieFJMOHPUY4=; b=JJpP4hMycT4QIn4OlZ5seMFZKasJHEihAW+diJ7RFWlC6TJn1lriBauK8wPPNvtbGd zPsjv0I8Q7jNuI5f+6WxMKW7GnxtJWUo2tVgQjDB8Kc0fJ439nBtHH9odP3omSdrmD8N 0z/hzDtRE37dD6V79biYvkP8SP3f02wBuXy2lHaxXeRsnAbDgrDkmLS8kviB1y7EGnlJ +R23PRNYdF9iGzwzCQX8BuYrTQZO+4C/aMEIgFEm/UQ5Y/sQXiIWmCR/MdDwimNq/K72 5bK3HFvDt5dJc04GTAFyqDev2ATnC11T/V+Y+6hRv8Ei9Lpg0Z/qemwm7lplvGQXQNdN IeSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=aABLKD6A; 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 ds1si2685668edb.99.2021.12.07.17.08.28; Tue, 07 Dec 2021 17:08:28 -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=aABLKD6A; 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 F0BEC68ADCC; Wed, 8 Dec 2021 03:07:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 851E868AC75 for ; Wed, 8 Dec 2021 03:07:28 +0200 (EET) Received: by mail-ua1-f51.google.com with SMTP id a14so2030716uak.0 for ; Tue, 07 Dec 2021 17:07:28 -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=oy2C4j9eYp6F5lHMTp0YL5wYJ5tXEdrCdTtwukM6OmE=; b=aABLKD6AgbF8PVaUjBEg90Ciu+Ybjy7KycVn7VQb2wKfbQMVZhM6SaLlklBdY3w2dH FPLU7Y8kVLzg7D2PBZJ4aYwj8fU9ZfMNbQUDRRk/BT9TXLTi6DpEnTo90i+rquOhcdVg ZEvRMQi5Y30HoGog6dhS7lQbPfEdOisT9DWd0wAMNi3C7BkIXSSpS0moJ1G8F4Fk30sQ heC6rEK2mo12Z3rQQZy4YUFClzjFXYb3JdoPCXFJZbzeU5d+3csWNcl1vuCfS0pkiJV1 V3w6nMSKsamZHenxlli0o2SQqStaSUeQ8hRqo8JahSl0RJaZsRB2L6OU3jWs59XU/1Go Hmhg== 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=oy2C4j9eYp6F5lHMTp0YL5wYJ5tXEdrCdTtwukM6OmE=; b=pTTrsz4mZ2WuIq2VviZHUQP3qpVJYRZLmclH1LmhBjV33bl/epwsBPr3YFthouZkda LLR6TNMfcj6AXHKsmDEe9p8GZlHjk8YtOuggDPgW+BW83VPaEgeYdBgU571EuG2luvNs llQGI9Z2PCJbp4yuaki9vcJpXoGLwoX9V9WEollLiE//yNJ+Q/AAVI4xlbD9OQbK59eG 9Sed5KwRH7dUMjX5cu9BNmrkMRec/ebkqeoBYsaPufSlGum+eJtYlJbEusSsenmAmDaI U4nc2KThFJB96X7RDpU53hQC80lJHNBe45GO91iBqxse136ogWKvHPMP85KXUGZATDFo 5VaQ== X-Gm-Message-State: AOAM530t5Hh28TRxJVpWgUQ+9GBajkeo7cZx5xJkr0LppfFFU4DE/XFR 49gBvPWEPyRzc2nHTHIocDfcm9bE8OGgVAGz X-Received: by 2002:a67:f8c2:: with SMTP id c2mr45412013vsp.62.1638925646949; Tue, 07 Dec 2021 17:07:26 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:26 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:20 -0300 Message-Id: <20211208010649.381-5-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 004/279] lavc: deprecate channel count/layout changing side data 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: jBx6gaJxpu7c From: Anton Khirnov They are incompatible with the new channel layout scheme and no decoder uses them. Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavcodec/decode.c | 4 ++++ libavcodec/packet.h | 5 +++++ libavformat/dump.c | 9 ++++++++- libavformat/nutenc.c | 2 ++ libavformat/utils.c | 9 +++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 52bf5dcd33..01fea93c04 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -91,6 +91,8 @@ static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt) flags = bytestream_get_le32(&data); size -= 4; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { if (size < 4) goto fail; @@ -109,6 +111,8 @@ static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt) avctx->channel_layout = bytestream_get_le64(&data); size -= 8; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { if (size < 4) goto fail; diff --git a/libavcodec/packet.h b/libavcodec/packet.h index 4a349fe051..0c3729f32c 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -447,8 +447,13 @@ typedef struct AVPacketList { #define AV_PKT_FLAG_DISPOSABLE 0x0010 enum AVSideDataParamChangeFlags { +#if FF_API_OLD_CHANNEL_LAYOUT + /** + * @deprecated those are not used by any decoder + */ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001, AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002, +#endif AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004, AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008, }; diff --git a/libavformat/dump.c b/libavformat/dump.c index 4824965ee9..69b838fbc7 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -164,8 +164,11 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd) { int size = sd->size; const uint8_t *data = sd->data; - uint32_t flags, channels, sample_rate, width, height; + uint32_t flags, sample_rate, width, height; +#if FF_API_OLD_CHANNEL_LAYOUT + uint32_t channels; uint64_t layout; +#endif if (!data || sd->size < 4) goto fail; @@ -174,6 +177,8 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd) data += 4; size -= 4; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { if (size < 4) goto fail; @@ -191,6 +196,8 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd) av_log(ctx, AV_LOG_INFO, "channel layout: %s, ", av_get_channel_name(layout)); } +FF_ENABLE_DEPRECATION_WARNINGS +#endif /* FF_API_OLD_CHANNEL_LAYOUT */ if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { if (size < 4) goto fail; diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 7977980935..2479a3e9dd 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -894,6 +894,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int break; case AV_PKT_DATA_PARAM_CHANGE: flags = bytestream_get_le32(&data); +#if FF_API_OLD_CHANNEL_LAYOUT if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { put_str(dyn_bc, "Channels"); put_s(dyn_bc, bytestream_get_le32(&data)); @@ -907,6 +908,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int avio_write(dyn_bc, data, 8); data+=8; sm_data_count++; } +#endif if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { put_str(dyn_bc, "SampleRate"); put_s(dyn_bc, bytestream_get_le32(&data)); diff --git a/libavformat/utils.c b/libavformat/utils.c index 7840e8717c..7643e5ca10 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1319,6 +1319,9 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels, uint8_t *data; if (!pkt) return AVERROR(EINVAL); + +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS if (channels) { size += 4; flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT; @@ -1327,6 +1330,8 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels, size += 8; flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (sample_rate) { size += 4; flags |= AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE; @@ -1339,10 +1344,14 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels, if (!data) return AVERROR(ENOMEM); bytestream_put_le32(&data, flags); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS if (channels) bytestream_put_le32(&data, channels); if (channel_layout) bytestream_put_le64(&data, channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (sample_rate) bytestream_put_le32(&data, sample_rate); if (width || height) { From patchwork Wed Dec 8 01:06:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32129 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044328iog; Tue, 7 Dec 2021 17:09:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAB5eUXOEnJSTyNJTO1v7dM3qXBzB/7NINRYxGjAcWu4Cn4nlbte3fnF/4mSvEIlVAgnEx X-Received: by 2002:aa7:c783:: with SMTP id n3mr14709809eds.121.1638925736938; Tue, 07 Dec 2021 17:08:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925736; cv=none; d=google.com; s=arc-20160816; b=Zp31uxpe6f0GvA3NzqLpsQ9iouftymxXtjykwZC5shH058394Z/wBcEag1uf2O4aaa Cv3EHpaD/XmdRGICWCnEJH93L+WngVd8YezKrLt1A6G5P71rPtSNV0WMtyeW3v+A5Gnz SaFQBQTTGXkTfm1WQ2Uue2i+R92yrUFVho13PpL/73joEvXJo1M3KZ9qrHHH7SF/gzDZ MNVwBXGiCgZHzoNP/iYDEF0X0QjoRSGOh5zcjEZV3Gaw3PxGbrABo/oZZ9kZilPu47R3 EsGqL6UF17y8i+6rBPJuk0LFzjiJ+cYX9cmJI6/hYmlK3rKIv64iNBBfGre+U7V6Al3W E7bw== 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=RLCOe7qTdaY6RBb92CBpa4TY23/uQm2nVXnrs5X3nms=; b=qGnCiOJYMa8pxewPyZPCW1MSf4Az4aV59KeQYn0vne/gHLG76ZbaAnlenJiF0ptth8 XtplVf0p1mhOcR38ynJo65RJN6FPpEERfrc4P2p9koGL4Pj5lrd5rt/39xxkos0nOaD9 300bgl1dwnWGfQXzawkGfZHWVEwTGMmsTsVQsw9JcVW/lkC8JJHVfBnPl6En48RaD9e2 oRG1nc/DvkY56ON62Af5VjlZpkbcJntAjrT4AngO8EVkXqiyrYaeEFbYTzrF4cJXUVKg 2hair5i6jcVhz/1vslUFyVpWu4WziCYcaNO7p8J0APNaR6BY6COZgz1LUpId4qCI6VkY m9tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=luMS4nPU; 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 qw2si2672811ejc.118.2021.12.07.17.08.56; Tue, 07 Dec 2021 17:08:56 -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=luMS4nPU; 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 3F67268AE59; Wed, 8 Dec 2021 03:07:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C336B68ADF8 for ; Wed, 8 Dec 2021 03:07:32 +0200 (EET) Received: by mail-vk1-f175.google.com with SMTP id f7so554198vkf.10 for ; Tue, 07 Dec 2021 17:07:32 -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=uznTsAbrRwwqmmpx5clws+iPQAFvP8fYmLnZQO9pk4k=; b=luMS4nPUdfZEIi5Ue4KIvRBUcjQxPbfwk0TUMeiQh3XlFqMkdxNaRuQru3XJiRmOfJ L1Iljx9aWhOyH9fnz4hl2i070jG5ILe7ANaE/LRgTN+R4u6Dj9dKnltndIf8mNv8wLSG ZlInEgPQ69M66N83rr4NH38HH8qSJUgDXj862GsFPlK2CyjnHlPx4y5LjXoQoKuAqYE5 O/o/V7o/SxKC4/aiVv8VEA+v2FZnciTCW0mUHc2XArf0f4GDtaipSeb8RpP8OEYdtNlR qJpxN5V5sQ/J44Mc2pNBZPZZdAseyC/EdWD8bSxaTjy/Gh0YDodtG+OL2hNrC4IbxUXp DaUg== 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=uznTsAbrRwwqmmpx5clws+iPQAFvP8fYmLnZQO9pk4k=; b=quU0iwWcgTCefS2wMDYMQ3NlRQvbdCLx5ptpdPotyru32A1cVEEQ31WW2XyLT/kYah J9yNmaRPoRZ6kZ9IKXqoEESH+IfUqrz64g9X+nkZK4S7/Qwx77OHU5WFkxpqRSMlvvn3 4752Xr660RU18Y13HOrmyExpbCgQB6rVl/2AgxKfIUm3mDv2kxVi1rxP3plOad8gNjZ7 fhFXFz+9Y6GkobbdTAAAoUao0SO1ejJ03DV0d0hZf9Dvou0nPlP6mJzLm4ibxh8NY/UW MyLrkzzgQCaYtWO2VWZvAA0JFCqFxNOu/CBsm1ett1jZbTBWPE/0H/WhorkOsB57ct2e DsTA== X-Gm-Message-State: AOAM530ZrCs0schziT0hIDKotXrKRoGlHCFfE8t85wKlv261IvgZgzYd IPjkNdb/63ukIS2GFpnbaf0bFnKA8nk0ng2/ X-Received: by 2002:a1f:54c4:: with SMTP id i187mr56708384vkb.40.1638925649940; Tue, 07 Dec 2021 17:07:29 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:29 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:21 -0300 Message-Id: <20211208010649.381-6-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 005/279] avframe: switch to the 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: g0DTcHkAfoYp From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavutil/frame.c | 112 +++++++++++++++++++++++++++++++++++++--------- libavutil/frame.h | 12 ++++- 2 files changed, 103 insertions(+), 21 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 0912ad9131..d07d6d7984 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -186,18 +186,27 @@ fail: static int get_audio_buffer(AVFrame *frame, int align) { - int channels; int planar = av_sample_fmt_is_planar(frame->format); - int planes; + int channels, planes; int ret, i; - if (!frame->channels) - frame->channels = av_get_channel_layout_nb_channels(frame->channel_layout); - - channels = frame->channels; - planes = planar ? channels : 1; - - CHECK_CHANNELS_CONSISTENCY(frame); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!frame->ch_layout.nb_channels) { + if (frame->channel_layout) { + av_channel_layout_from_mask(&frame->ch_layout, frame->channel_layout); + } else { + frame->ch_layout.nb_channels = frame->channels; + frame->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + } + } + frame->channels = frame->ch_layout.nb_channels; + frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + frame->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + channels = frame->ch_layout.nb_channels; + planes = planar ? channels : 1; if (!frame->linesize[0]) { ret = av_samples_get_buffer_size(&frame->linesize[0], channels, frame->nb_samples, frame->format, @@ -245,10 +254,17 @@ int av_frame_get_buffer(AVFrame *frame, int align) if (frame->format < 0) return AVERROR(EINVAL); +FF_DISABLE_DEPRECATION_WARNINGS if (frame->width > 0 && frame->height > 0) return get_video_buffer(frame, align); - else if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0)) + else if (frame->nb_samples > 0 && + (av_channel_layout_check(&frame->ch_layout) +#if FF_API_OLD_CHANNEL_LAYOUT + || frame->channel_layout || frame->channels > 0 +#endif + )) return get_audio_buffer(frame, align); +FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } @@ -332,14 +348,33 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src) dst->format = src->format; dst->width = src->width; dst->height = src->height; + dst->nb_samples = src->nb_samples; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS dst->channels = src->channels; dst->channel_layout = src->channel_layout; - dst->nb_samples = src->nb_samples; + if (!av_channel_layout_check(&src->ch_layout)) { + if (src->channel_layout) + av_channel_layout_from_mask(&dst->ch_layout, src->channel_layout); + else { + dst->ch_layout.nb_channels = src->channels; + dst->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + } + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif ret = frame_copy_props(dst, src, 0); if (ret < 0) goto fail; + // this check is needed only until FF_API_OLD_CHANNEL_LAYOUT is out + if (av_channel_layout_check(&src->ch_layout)) { + ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout); + if (ret < 0) + goto fail; + } + /* duplicate the frame data if it's not refcounted */ if (!src->buf[0]) { ret = av_frame_get_buffer(dst, 0); @@ -392,13 +427,12 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src) /* duplicate extended data */ if (src->extended_data != src->data) { - int ch = src->channels; + int ch = dst->ch_layout.nb_channels; if (!ch) { ret = AVERROR(EINVAL); goto fail; } - CHECK_CHANNELS_CONSISTENCY(src); dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch); if (!dst->extended_data) { @@ -456,6 +490,8 @@ void av_frame_unref(AVFrame *frame) if (frame->extended_data != frame->data) av_freep(&frame->extended_data); + av_channel_layout_uninit(&frame->ch_layout); + get_frame_defaults(frame); } @@ -502,9 +538,18 @@ int av_frame_make_writable(AVFrame *frame) tmp.format = frame->format; tmp.width = frame->width; tmp.height = frame->height; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS tmp.channels = frame->channels; tmp.channel_layout = frame->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif tmp.nb_samples = frame->nb_samples; + ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout); + if (ret < 0) { + av_frame_unref(&tmp); + return ret; + } if (frame->hw_frames_ctx) ret = av_hwframe_get_buffer(frame->hw_frames_ctx, &tmp, 0); @@ -545,10 +590,16 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane) int planes, i; if (frame->nb_samples) { - int channels = frame->channels; + int channels = frame->ch_layout.nb_channels; + +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) + channels = av_get_channel_layout_nb_channels(frame->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (!channels) return NULL; - CHECK_CHANNELS_CONSISTENCY(frame); planes = av_sample_fmt_is_planar(frame->format) ? channels : 1; } else planes = 4; @@ -654,14 +705,28 @@ static int frame_copy_video(AVFrame *dst, const AVFrame *src) static int frame_copy_audio(AVFrame *dst, const AVFrame *src) { int planar = av_sample_fmt_is_planar(dst->format); - int channels = dst->channels; + int channels = dst->ch_layout.nb_channels; int planes = planar ? channels : 1; int i; - if (dst->nb_samples != src->nb_samples || - dst->channels != src->channels || - dst->channel_layout != src->channel_layout) +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) { + channels = av_get_channel_layout_nb_channels(dst->channel_layout); + planes = planar ? channels : 1; + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + +FF_DISABLE_DEPRECATION_WARNINGS + if (dst->nb_samples != src->nb_samples || + av_channel_layout_compare(&dst->ch_layout, &src->ch_layout) +#if FF_API_OLD_CHANNEL_LAYOUT + || dst->channel_layout != src->channel_layout +#endif + ) return AVERROR(EINVAL); +FF_ENABLE_DEPRECATION_WARNINGS CHECK_CHANNELS_CONSISTENCY(src); @@ -680,10 +745,17 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src) if (dst->format != src->format || dst->format < 0) return AVERROR(EINVAL); +FF_DISABLE_DEPRECATION_WARNINGS if (dst->width > 0 && dst->height > 0) return frame_copy_video(dst, src); - else if (dst->nb_samples > 0 && dst->channels > 0) + else if (dst->nb_samples > 0 && + (av_channel_layout_check(&dst->ch_layout) +#if FF_API_OLD_CHANNEL_LAYOUT + || dst->channel_layout || dst->channels +#endif + )) return frame_copy_audio(dst, src); +FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } diff --git a/libavutil/frame.h b/libavutil/frame.h index 3f295f6b9e..7f6aa1c7c8 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -30,6 +30,7 @@ #include "avutil.h" #include "buffer.h" +#include "channel_layout.h" #include "dict.h" #include "rational.h" #include "samplefmt.h" @@ -486,10 +487,14 @@ typedef struct AVFrame { */ int sample_rate; +#if FF_API_OLD_CHANNEL_LAYOUT /** * Channel layout of the audio data. + * @deprecated use ch_layout instead */ + attribute_deprecated uint64_t channel_layout; +#endif /** * AVBuffer references backing the data for this frame. All the pointers in @@ -674,6 +679,11 @@ typedef struct AVFrame { * for the target frame's private_ref field. */ AVBufferRef *private_ref; + + /** + * Channel layout of the audio data. + */ + AVChannelLayout ch_layout; } AVFrame; @@ -753,7 +763,7 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src); * The following fields must be set on frame before calling this function: * - format (pixel format for video, sample format for audio) * - width and height for video - * - nb_samples and channel_layout for audio + * - nb_samples and ch_layout for audio * * This function will fill AVFrame.data and AVFrame.buf arrays and, if * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf. From patchwork Wed Dec 8 01:06:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32124 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7043856iog; Tue, 7 Dec 2021 17:08:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZkWdQcWReTyausZcGZB7EJDsqGtLR5d9hZdyUXGKJKPH8a85REmxDBTsQZ45yMZJBDz/9 X-Received: by 2002:a17:906:a0d7:: with SMTP id bh23mr3636914ejb.82.1638925719544; Tue, 07 Dec 2021 17:08:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925719; cv=none; d=google.com; s=arc-20160816; b=vGWGG+hNiQizc/wH5oT6W0+roVsK9Wlt6MU6mWKWSdVgYV7tg7WU0zuZtnerGdPRrj uP9T+WIKz4NIRiTHOrlxlG/F4EUv4p4zS9yFEJe/Bknmd8KJ4GPIsj3Ir9jorm+DTBPV Xw8XOr7bXobq7/ZZnu8deXDJMb8y+Ey8XOkWxXM3/9cV+S2U0TRuD7r78fkoOepYWrc/ zqRQ3LRsnSwIbcuiVbxaZs4cOmDANT63FNxCXh1VMCWfsFY+ECp0pIrPzauM38nCvkSe 40Ba2uUyHmmcL8uxJjSJHAeT5/9EVaDmyU9fMI2Iy6tOPVOLnaZKOI5eNKFhRIRhtORM k+IQ== 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=yQ/PPYv4RgSj12J4aWOA0jegNUvOajLvxpF5Z8wFJCQ=; b=zfSMjDkbnfVDKBh9uJsSrq+AyK2dkNGGb/l93lGGqyl6m9RV3seyTJKqCyGAoHH7z9 MLzAPY3XrzCsgHD2vm+Af/cyP+EQd3L1Zu0bskxpaCWjFVNI49Nod+EJoPojek0SmJrQ iA1yyk3LPhdxt7sv8OfNMyQcAqpfDM4XKEhLnT/fyjq+tD3jYRAFd80HolRcvtW/Mii6 8j67DrZlvfiI3UVcpncyhBUeFqRAmHz2V1JaS4Z/H2H25NO8EdpQGUlWInWy/oR/i3Sx FK3vuKrXdnCcsY6vjPLxWAybTBCRobTrm3q2Ey0XIDEcO7Q/Rwu5VsDRx/cQ0wtHqYdE mKkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=RAV7WhAu; 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 e6si1897742ejb.739.2021.12.07.17.08.38; Tue, 07 Dec 2021 17:08:39 -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=RAV7WhAu; 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 1BC3068A980; Wed, 8 Dec 2021 03:07:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C8FC68AD93 for ; Wed, 8 Dec 2021 03:07:33 +0200 (EET) Received: by mail-ua1-f41.google.com with SMTP id 30so1830558uag.13 for ; Tue, 07 Dec 2021 17:07:33 -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=IGCiUibKaN7Kf1mSX/Z7JiSSXQ58O+YdvQvTYfFXiSw=; b=RAV7WhAuYpKmI64/W1ZRFGQBno9blYvHjbQiDpL+Ocn/aAuLYElA6XDK3nUjcaU+j4 BW2aW0Snqj+fWNOL52VmbhzDJ+A4WuhVxeOtktLH+YVHbTfDzhJPLWC5u2/KMvp00mfB vZ5PhYP+9q0LJXxByqBsmIYaZCvFEoMckmerw8dLfzkZMiTNKmvk7/z6Ww0bYBQpdD5y XWrJSetmdbVIfzBVOnww3EBBRulCUj5iT3JLFIVMFHqa45px9FulliidpBrYnFlbYXxF AxNXLh44YfIOo9bmDMhads0hNus73QH3INIAxQ1QpVZEbh8wEeOi5S7FcC0GrLljU66U HWsQ== 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=IGCiUibKaN7Kf1mSX/Z7JiSSXQ58O+YdvQvTYfFXiSw=; b=eidvPra49C7Cm28URLy0pIjhhN4x4D9u+u+Ov4e2oY3Rk8Vo4dTRK5g0rTc6i4WMAI QMW9iUfKxl8X15B2G8vbFHGzLiE2qhaEPZZF4DKwA/BkbDua9G9AojuNLfao2Wew4luA aGachvZxV51+W2669v7BIZqRY93d96nMSy9QAseEYHWP6t9YlN1yYkka6r7JXP8t3Zr8 1pB2/05256TPcl22s0APZVWk+eDnMrrf5jSuy+Yqw3lzQrngw0L2ow8hCm6FQo26HNFJ f6aqY3kHfpAu+jqn2PTc3H8GRxIj27hCEPG4A2ZOXDay/mzdQkvr5Gt+tHJDcbhR5KEJ Upmg== X-Gm-Message-State: AOAM530mxf2ksJTiRf3uBVgKUyrz4hPXx/EjcCAOssSP1u2WvhGG7AZV TbWYUW6cjjpBd29Ng05l9Wse0FQJZqmmci9z X-Received: by 2002:ab0:36c4:: with SMTP id v4mr4080631uau.8.1638925652206; Tue, 07 Dec 2021 17:07:32 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:31 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:22 -0300 Message-Id: <20211208010649.381-7-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 006/279] avcodecpar: switch to the 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: vz7fVGTWiRqx From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/codec_par.c | 37 +++++++++++++++++++++++++++++++++---- libavcodec/codec_par.h | 12 ++++++++++++ libavcodec/utils.c | 12 ++++++++++-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index 1a5168a04b..9d43af1db4 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -31,6 +31,7 @@ static void codec_parameters_reset(AVCodecParameters *par) { av_freep(&par->extradata); + av_channel_layout_uninit(&par->ch_layout); memset(par, 0, sizeof(*par)); @@ -71,6 +72,8 @@ void avcodec_parameters_free(AVCodecParameters **ppar) int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src) { + int ret; + codec_parameters_reset(dst); memcpy(dst, src, sizeof(*dst)); @@ -84,6 +87,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src dst->extradata_size = src->extradata_size; } + ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout); + if (ret < 0) + return ret; + return 0; } @@ -118,8 +125,19 @@ int avcodec_parameters_from_context(AVCodecParameters *par, break; case AVMEDIA_TYPE_AUDIO: par->format = codec->sample_fmt; - par->channel_layout = codec->channel_layout; - par->channels = codec->channels; + if (codec->channel_layout) + av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout); + else { + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = codec->channels; + } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + par->ch_layout.u.mask : 0; + par->channels = par->ch_layout.nb_channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif par->sample_rate = codec->sample_rate; par->block_align = codec->block_align; par->frame_size = codec->frame_size; @@ -173,8 +191,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec, break; case AVMEDIA_TYPE_AUDIO: codec->sample_fmt = par->format; - codec->channel_layout = par->channel_layout; - codec->channels = par->channels; + if (par->ch_layout.nb_channels) { + codec->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + par->ch_layout.u.mask : 0; + codec->channels = par->ch_layout.nb_channels; + } +#if FF_API_OLD_CHANNEL_LAYOUT + else { +FF_DISABLE_DEPRECATION_WARNINGS + codec->channel_layout = par->channel_layout; + codec->channels = par->channels; +FF_ENABLE_DEPRECATION_WARNINGS + } +#endif codec->sample_rate = par->sample_rate; codec->block_align = par->block_align; codec->frame_size = par->frame_size; diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h index 10cf79dff1..4cacfbf3b3 100644 --- a/libavcodec/codec_par.h +++ b/libavcodec/codec_par.h @@ -24,6 +24,7 @@ #include #include "libavutil/avutil.h" +#include "libavutil/channel_layout.h" #include "libavutil/rational.h" #include "libavutil/pixfmt.h" @@ -149,6 +150,7 @@ typedef struct AVCodecParameters { enum AVColorSpace color_space; enum AVChromaLocation chroma_location; +#if FF_API_OLD_CHANNEL_LAYOUT /** * Video only. Number of delayed frames. */ @@ -158,12 +160,17 @@ typedef struct AVCodecParameters { * Audio only. The channel layout bitmask. May be 0 if the channel layout is * unknown or unspecified, otherwise the number of bits set must be equal to * the channels field. + * @deprecated use ch_layout */ + attribute_deprecated uint64_t channel_layout; /** * Audio only. The number of audio channels. + * @deprecated use ch_layout.nb_channels */ + attribute_deprecated int channels; +#endif /** * Audio only. The number of audio samples per second. */ @@ -198,6 +205,11 @@ typedef struct AVCodecParameters { * Audio only. Number of samples to skip after a discontinuity. */ int seek_preroll; + + /** + * Audio only. The channel layout and number of channels. + */ + AVChannelLayout ch_layout; } AVCodecParameters; /** diff --git a/libavcodec/utils.c b/libavcodec/utils.c index a91a54b0dc..dc5156210f 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -826,8 +826,16 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes) { - int duration = get_audio_frame_duration(par->codec_id, par->sample_rate, - par->channels, par->block_align, + int channels = par->ch_layout.nb_channels; + int duration; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) + channels = par->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + duration = get_audio_frame_duration(par->codec_id, par->sample_rate, + channels, par->block_align, par->codec_tag, par->bits_per_coded_sample, par->bit_rate, par->extradata, par->frame_size, frame_bytes); From patchwork Wed Dec 8 01:06:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32119 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044015iog; Tue, 7 Dec 2021 17:08:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+ajGQSqG+n3s/23hy8wfl/7Mv7w5uP1z06LrOqqX6u4S2G9GFJ19/fuxghlLGpti1K20c X-Received: by 2002:a05:6402:26cb:: with SMTP id x11mr14390580edd.149.1638925727348; Tue, 07 Dec 2021 17:08:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925727; cv=none; d=google.com; s=arc-20160816; b=rpjYYJ2snKP0UvP454zSOtcSmF9AZ2Fno481d3kzzGxsNfzTH2zD2WbzDkZATfGZ9N /hkrd8O0RItbWXA5J2/PvbQ9vojV8iuUNjZQCeaizuvNGJHgE++GIGLYsINhXR2fe45x drrw+TFpQgRLhzRy3sf+8ui6ywAp4tkx7cEiQWjrQbB825NRERO+08dwL5oQwcXA+d5i xStnuh5qlPa0S7UZyo2j5P6XwzB7YcdERHBriQWOuhJtJqxvYQuOTHpeXvt5tt+EkLh/ YkiIUG4ailCZ3WZefWocYQRO3nrWRApy5+f4xUkATXwUG1QxhXgxleW0cMl5zkNTwZOl rGvw== 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=VYOM+OEEw4cVvZ7WGC5nHVAdkRoW9U4QtoQIKbDyvZ4=; b=x9y35aonmchS1z/cRLlWkxRMBCuZP5+NJi+j6Z4QMWnEzKEqQ6vO9eMgbv92eDNja4 qozQ4sLTOkosedB24UyFdbFIS4eigrbqbLS4KOuOttxjKaO5/b96dTcelBF81xzjOind vAWJJAg/0N8gmzL47fOhR0P6aiZK7QZAZ8KmegFqG/dE/RQU4VfS4qliFJ3fiKPkxTl0 9YkaosB5B2egKUpv1ifizhi1lWlEHCZa2MY2WPv5qcNGgiKj+26aHgj3b/NNjw95t+jU YvqVvYLpfXV8wR5r/Q1ck9YLioH0/Tx9vyMJjdpKedmhM/YDRRewxgGOjFOWFIozFeSO qqrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=SYVm82wW; 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 p8si2652532edj.225.2021.12.07.17.08.46; Tue, 07 Dec 2021 17:08:47 -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=SYVm82wW; 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 3AB9E68A993; Wed, 8 Dec 2021 03:07:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2EEB668A852 for ; Wed, 8 Dec 2021 03:07:34 +0200 (EET) Received: by mail-vk1-f172.google.com with SMTP id j1so588405vkr.1 for ; Tue, 07 Dec 2021 17:07:34 -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=tDkXROml0zMFczgrJaq9EcUtxudwTCREE5h3ne8Y/BQ=; b=SYVm82wWO+3hV+M/NjWLJ/5TbHhI1SqhStxmrJKO5YhWvMORWp7vp5zGGje+Z93krt Eeeo+61rie1uTJuVCxgaHi92I4MrmaBIZPqCTPLjLjOUbxn4svbaGuFI00oYx7q4eexc 2wg3vXSEfaW39AgW6L+vqyJBCt8Ew7o7YXLAB+2PxpwAcxk+LWJZKTsjbN09VcVR0Qv0 52fswoS1tFLp6krQlQBFRoQfSKYzccg/89ukQCtxizVXXNwnO8t7O9KJX+vWYuJdjvKd a+Kjj4iALEkYhwcpQupeNbkihNuELSbrhSPP43pp4Ms4xnGGhpDLxOom/A77noLo9o5g TAtg== 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=tDkXROml0zMFczgrJaq9EcUtxudwTCREE5h3ne8Y/BQ=; b=RPJYo1F6ZoRRzC4rp6rtoFylbZ3DxVpN8tROA4BssBaOx5/o1vvE2uVCgQFQVdM5/5 EMYSuMpfyloGhKE+k6Kqlh3jY5ix+lKLTbK13lL+Q1fpaWDVgvEZ74LRPnApvE78TTmZ WvpqEkgQ73kD0pitK9619zqEerKOog9dsjZclcQ4z7X4m4DmjvMnGLLdBvUY+eRTwuiC Lvn6wIBsKkS9FhPBwFGd8Q6TXLAPB4KhYR0KnuWz1OaP2OY+Q9Lrfu/rTFbWBrPtlAQM CHOAN1Qc1Bum/zoeUkgPiREiNfIzWtz/mdORZwIBL5x/LCQ6SfvrDBSxxnUZLS8swQZd 2vlQ== X-Gm-Message-State: AOAM531SlBT5pTiSxgu+5GFXGCUVnQJiqk7yqIwwvcaBmWtmMAC+Ignr A0W9w170YLiHC9YiVPitfSJthmWXBWKBF0pR X-Received: by 2002:a1f:7f01:: with SMTP id o1mr58011738vki.40.1638925653452; Tue, 07 Dec 2021 17:07:33 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:33 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:23 -0300 Message-Id: <20211208010649.381-8-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 007/279] lavf: add a temporary compat layer for the channel layout API change 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: wRQ0A41fjuEr From: Anton Khirnov Mediates between old-style (de)muxers and new-style callers. Will be removed once all the (de)muxers are converted to the new API. Signed-off-by: James Almer --- libavformat/demux.c | 12 ++++++++++++ libavformat/mux.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/libavformat/demux.c b/libavformat/demux.c index 745dc8687c..cb02c84f33 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -194,6 +194,18 @@ static int update_stream_avctx(AVFormatContext *s) sti->parser = NULL; } + /* if the demuxer exports old channel layouts, convert it to new */ + if (!st->codecpar->ch_layout.nb_channels && + st->codecpar->channels) { + if (st->codecpar->channel_layout) { + av_channel_layout_from_mask(&st->codecpar->ch_layout, + st->codecpar->channel_layout); + } else { + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = st->codecpar->channels; + } + } + /* update internal codec context, for the parser */ ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); if (ret < 0) diff --git a/libavformat/mux.c b/libavformat/mux.c index d93dc73f8e..fc9199230c 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -272,6 +272,16 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) ret = AVERROR(EINVAL); goto fail; } + + /* if the new-style channel layout is set, convert it to old one + * for old-style muxers */ + if (par->ch_layout.nb_channels && + !par->channels) { + par->channels = par->ch_layout.nb_channels; + par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + par->ch_layout.u.mask : 0; + } + if (!par->block_align) par->block_align = par->channels * av_get_bits_per_sample(par->codec_id) >> 3; From patchwork Wed Dec 8 01:06:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32140 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044662iog; Tue, 7 Dec 2021 17:09:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaOWxF2JnBIPHRairOhLa0KPpTYQDr5id1v9xNctemsQ2ID9TkS/vT3zRUmJHDdrzeKRL3 X-Received: by 2002:a17:907:a40c:: with SMTP id sg12mr3426125ejc.408.1638925765824; Tue, 07 Dec 2021 17:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925765; cv=none; d=google.com; s=arc-20160816; b=XxGUGjHueUeec8VmugXORkmf0awKWeVeB/OrJ7RAOjvLmYALdkWJMW3cv1BUcmgzZl e/yknEW5OXIIPPynp/eQbQt6yhAtsE0tjJ6ZjvDK5lQ/bkhiRTyU+0P5s8URaTqaH0S6 5t9jnn40nbvlcldDhlkMSjjHhx7sNflzk1GjRlSRR5nUwq2ckqffjeYD6cwDavtXajM/ IUaVC0Qrw0ltQ25STpden/ICqnVmvqonvZtWubKN5C75QSNH7vXdr0UkF6AOXQuB1NtA v5pKJDC0FfdIas/1HodM5RyP3J/HGGsy/V35Q6+9eo6dGLoBKuiQYJa2j2H/XfOTMt83 sXvw== 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=5jf438z68rv49BsjSPcYlGpl+eEDFzUga/UsmbcxbV8=; b=rHNDkwF990FEDK+U18VMShpxyZQ6AACp4e1xgP3blY7fAGfi+QDw5djm8AT6Hf78yD 5Y3qkskKnJ3zpC0lyXYL/SFqhSL/fR09LsSGi2gu2WgVqwgm1OmqftSVD2A0TzYCmtF2 1st2aQn63QJ6RkckIFvRMFlbTKm2lXZl5rLSr5O2gAElu8UbxhRXy0nNseiv4XEt1ZSY NL9Sb/mB0D7mRKdM1hhF0fRW1sYt8goaGnZeGcd4GTc05xmwN7fVP2STyhI4SzDqpl5V wW5iVR7Ee+dvY47HYzosH88h3shBEmZJlt8Jom1JwF94bPYB1QTpdx+8zjZH/9XX1YtY g0PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="fDWn2KY/"; 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 l2si1863623edf.22.2021.12.07.17.09.25; Tue, 07 Dec 2021 17:09:25 -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="fDWn2KY/"; 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 1D14E68A852; Wed, 8 Dec 2021 03:07:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9E7A168A3AD for ; Wed, 8 Dec 2021 03:07:37 +0200 (EET) Received: by mail-ua1-f50.google.com with SMTP id ay21so1842983uab.12 for ; Tue, 07 Dec 2021 17:07:37 -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=xPEgOyiS75t0KeyWxHXWrfXy7GljlnHSo205AIZFtBc=; b=fDWn2KY/Upqat/ei6aceueEC8lnKJWU1hzxTB42y3oGXdp5oTb69mUO3APnTk2Ety5 yTiJk1p9mPrkh66U3VNimK3EVpoyaVpnw9h6xTwHoIPuFK11BOHyqYYaX0+qo318uo7u 3fM3eSS6ch/U6M/h4DulPMJcz1idkLpeYPf7or4oFkVIwzDIYQ4gYF3f7/bw00evCIAC vRR+oVYmExqgrd9ZosiLLTorSkV3V5R7HBOttmRfz/TC2dUa7mVyFaOGoc9vmMV0aG69 gfRHk+D6IwIUg2vVqxNWBEi5WOLtu2PV9Hd66CpGGYNLET0WKewcyhVDcAbpunAGpMBp +Wjw== 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=xPEgOyiS75t0KeyWxHXWrfXy7GljlnHSo205AIZFtBc=; b=hBm5fQ5hCovuQksviMEewTGP90giNyHXbVbMUKXUe1kUXjI44xFvwej2aGHhsE2Qw9 wbO8F3TnHAJRu3YvP/55qmJEyy2Y58tw3S3WBhcubtIrSWGcSsAYZ9m8f5J/L0QEjaWD Ah/hrkOQ+TNlG5BQUZWHdr3crp7jp8Iw3JXklcLzY3JMjfO12jm3vQAzLQL0+i1KKPu+ 0den6kMeyv7eLb2R5j8Lt0S5eSHN69pRvfIrsnOWgmyzmgqWbSFi0KIW2JfXCyyzaVUo Xrq3sPfJf3HnLmmlqMItuWGk+dq+fnR7AU/T6xV5KiZQ1IQnqarP6H/y9sAjJ/VtsiQT baog== X-Gm-Message-State: AOAM532PndcUUu8KL8Dher3+ctccwAHR3AW/jgiWzUcDXNYA1d6zepAF jrqvrAWpAXkMxZTjhZi3NFh/rVPpxjy26lb4 X-Received: by 2002:a67:b208:: with SMTP id b8mr48902442vsf.77.1638925654670; Tue, 07 Dec 2021 17:07:34 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:34 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:24 -0300 Message-Id: <20211208010649.381-9-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 008/279] lavf: convert the generic layer to the new channel layout 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: xr/AmfUP6qS6 From: Anton Khirnov Signed-off-by: James Almer --- libavformat/demux.c | 16 ++++++++++++++++ libavformat/mux.c | 18 +++++++++++++++++- libavformat/utils.c | 4 ++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index cb02c84f33..3bfd753f64 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -206,6 +206,18 @@ static int update_stream_avctx(AVFormatContext *s) } } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (st->codecpar->ch_layout.nb_channels && + !st->codecpar->channels) { + st->codecpar->channels = st->codecpar->ch_layout.nb_channels; + st->codecpar->channel_layout = st->codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + st->codecpar->ch_layout.u.mask : 0; + + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + /* update internal codec context, for the parser */ ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); if (ret < 0) @@ -1335,8 +1347,12 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) return ret; st->codecpar->sample_rate = sti->avctx->sample_rate; st->codecpar->bit_rate = sti->avctx->bit_rate; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS st->codecpar->channels = sti->avctx->channels; st->codecpar->channel_layout = sti->avctx->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif st->codecpar->codec_id = sti->avctx->codec_id; } else { /* free packet */ diff --git a/libavformat/mux.c b/libavformat/mux.c index fc9199230c..9dd6b13ac8 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -282,8 +282,24 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) par->ch_layout.u.mask : 0; } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + /* if the caller is using the deprecated channel layout API, + * convert it to the new style */ + if (!par->ch_layout.nb_channels && + par->channels) { + if (par->channel_layout) { + av_channel_layout_from_mask(&par->ch_layout, par->channel_layout); + } else { + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = par->channels; + } + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (!par->block_align) - par->block_align = par->channels * + par->block_align = par->ch_layout.nb_channels * av_get_bits_per_sample(par->codec_id) >> 3; break; case AVMEDIA_TYPE_VIDEO: diff --git a/libavformat/utils.c b/libavformat/utils.c index 7643e5ca10..269223aaa8 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -526,7 +526,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, continue; if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb) continue; - if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate)) + if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate)) continue; if (decoder_ret) { decoder = ff_find_decoder(ic, st, par->codec_id); @@ -1512,7 +1512,7 @@ static int match_stream_specifier(AVFormatContext *s, AVStream *st, int val; switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: - val = par->sample_rate && par->channels; + val = par->sample_rate && par->ch_layout.nb_channels; if (par->format == AV_SAMPLE_FMT_NONE) return 0; break; From patchwork Wed Dec 8 01:06:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32141 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044313iog; Tue, 7 Dec 2021 17:09:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOvG65z2mGPtuq3ZBMXlA2Il7/7m7cm/Q5iioeqZff3fzZERfos4G2qMrjW9vcjohGa+07 X-Received: by 2002:a17:907:7b9b:: with SMTP id ne27mr3456277ejc.79.1638925746714; Tue, 07 Dec 2021 17:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925746; cv=none; d=google.com; s=arc-20160816; b=dnLgNBV4++FDYijtXsEDJcoBHzNkitezLawp4oIbaKmODw3f5RBahhgXntRastmiYj iWnqc8SZw34R3fSAzG/IqBOmQDpcmdWxfpbyYq29rCLQvRx3HYD29ttwA/IJ7ozkyIYf Vkzh7Dr8cYTxfAuQylg0yw+hVP61cah9UyiaTcEnKWAcHRoVz4i0YhNAfnj1FiiK1FbT 5nvs7QHdYmyRgZfwILnyqfLe2P40xgfFigZ9DZzdbE4SoPngF38wefGbh5o35dlWAfhA TEJXavdp5sOBBOWFdQyCf2ocBk2vyMqB+ETArFdsBnsykT66n0LBib9wT5vNvhcd7akQ nAUw== 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=DTLE5eO9JE3G4LaVoaIDlrkk4cKx55kXEmom7r6D0Ho=; b=y4Qb6Sqm36Lv8xfqR3GD7ToQfktrNUGnVvD6cSqtgvJdGBavY1AmqpLbvrkqjnUeZc svDUnykuYcBsDlDRo2zqGr7MxsQZ6Gpfb/WJNVGhKMmBL4Qc0SfGwAxYk3piIDwgy5Kc LcfMfu6KhO83IALRO19E8corQLJkwI6N5b0j9qNDPOxGfQIu6rH9M6ue9GmXQjQ9+Dso dEKG26GdHCzEdARQRecEfMYlBZxcV4AhlrEFxwc6di80xM2H2VbUS0YLmh8AkGDriM9t qgVuo6l2dBja4xgPvnDTaZ/cQgOcif7SstB7s7cTV6Zf8bWQwbQ0MGSnjXA7aVQ/KNCW zEUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=M8vmi0+N; 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 l10si1628448ejz.697.2021.12.07.17.09.06; Tue, 07 Dec 2021 17:09:06 -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=M8vmi0+N; 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 418D368AE77; Wed, 8 Dec 2021 03:07:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8850968AE6C for ; Wed, 8 Dec 2021 03:07:40 +0200 (EET) Received: by mail-ua1-f43.google.com with SMTP id 30so1830988uag.13 for ; Tue, 07 Dec 2021 17:07:40 -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=BVCK0GeOHyagtrPxYG/ArcICJBUIqMeOtgQVBcMRzRk=; b=M8vmi0+NXv15GRWVZOQF8QoqiGH2f63/f+Uzsru3FX3OiTQilwO4kjOUKrjAuo1EKq NlK0tmq8KVLcYG1O4Rds2ZdDYuIODHbGxooKOoTPEnsK0yrlX2uIpb/M1lpXcULZlsPt 6Ig7/rS37G4UXGXso4YpYqWX+EnDpaSf79JuIdyVR4kwUfBDztfpNJbP6eZTjWti5F0m UTXYvj5+g7K5ElCiYUyYnYy8TcPzpjENee9jufU00mJFcmCfJl6S/RrU8f399iQEkM7y Cp2mjjyvD6hP8L8ULC4OIKohHDTYs8d7uJr5EnQXW89Wi7VGP5d1FnPF0A3iPu0PN1Lc DrAw== 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=BVCK0GeOHyagtrPxYG/ArcICJBUIqMeOtgQVBcMRzRk=; b=rPOnmZvTv5u+kP61uv/lVkos0a0FvlCQSm/xmyXZ/abVUfGRFW4NS8+DWl2ugwCa7f m5Fm7Mk6DPAwczHNf83ulYG14/Dyuow+3tf38Mw6jA5vLxPiaazVjsAVi61jxXzT8p28 wmKnmLpPYe2VC7hNXqx/eAG4bahd7kcwmbqGs4rm+KLgDvocwaa/UtA5q1OFCrSV0jk0 6nF34Phnc7Ijeqo8mHhMlTESt3WCJ/5skceHCyZKP5009HFAiz8+BImJSwanpI8jDTv2 CfZGCTez97Xy5s6aRcM9eyqvVG4PHBaIdKOHItxsiEEskuxtw4vsmiNHy/zrvnBHiAJG 6wVg== X-Gm-Message-State: AOAM531los920tkPAdeDay5NDy+IFDNH0xDCDDpMzHD5wn5Fq/zCyyT5 klVi9iY6cqOuq5+xZRZLwXSfVzrHN1ezaF/J X-Received: by 2002:a67:edd7:: with SMTP id e23mr49820340vsp.52.1638925657276; Tue, 07 Dec 2021 17:07:37 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:36 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:25 -0300 Message-Id: <20211208010649.381-10-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 009/279] 3dostr: 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: ZopKk07AkbFp From: Anton Khirnov Signed-off-by: James Almer --- libavformat/3dostr.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c index 0c136c9ea0..9b6a4d1d86 100644 --- a/libavformat/3dostr.c +++ b/libavformat/3dostr.c @@ -102,15 +102,16 @@ static int threedostr_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->sample_rate = avio_rb32(s->pb); - st->codecpar->channels = avio_rb32(s->pb); - if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0) + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = avio_rb32(s->pb); + if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; codec = avio_rl32(s->pb); avio_skip(s->pb, 4); if (ctrl_size == 20 || ctrl_size == 3 || ctrl_size == -1) - st->duration = (avio_rb32(s->pb) - 1) / st->codecpar->channels; + st->duration = (avio_rb32(s->pb) - 1) / st->codecpar->ch_layout.nb_channels; else - st->duration = avio_rb32(s->pb) * 16 / st->codecpar->channels; + st->duration = avio_rb32(s->pb) * 16 / st->codecpar->ch_layout.nb_channels; size -= 56; found_shdr = 1; break; @@ -135,7 +136,7 @@ static int threedostr_read_header(AVFormatContext *s) switch (codec) { case MKTAG('S','D','X','2'): st->codecpar->codec_id = AV_CODEC_ID_SDX2_DPCM; - st->codecpar->block_align = 1 * st->codecpar->channels; + st->codecpar->block_align = 1 * st->codecpar->ch_layout.nb_channels; break; default: avpriv_request_sample(s, "codec %X", codec); @@ -178,7 +179,7 @@ static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); pkt->pos = pos; pkt->stream_index = 0; - pkt->duration = size / st->codecpar->channels; + pkt->duration = size / st->codecpar->ch_layout.nb_channels; return ret; default: av_log(s, AV_LOG_DEBUG, "skipping unknown chunk: %X\n", chunk); From patchwork Wed Dec 8 01:06:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32142 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044474iog; Tue, 7 Dec 2021 17:09:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwe4aKfU+mhMn2h2UGnRpmX7GVnkxphcp8EmsHZZoye+ee612Kr2uxSHCUCUB+Kv8hh7nEQ X-Received: by 2002:a05:6402:518e:: with SMTP id q14mr14420912edd.399.1638925755969; Tue, 07 Dec 2021 17:09:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925755; cv=none; d=google.com; s=arc-20160816; b=XYzT5S4i/RCqausxdlqnz9p6UrCEu+/gOJLexrJLJ+UjA+YThBC+ACmCQhL2I2Vc5U ZgX1kCaxBvCCLsSVj7vjml2yL5v5TOMkF5XpXJ27h0d8l61WEiOxQc4cZwMRQvnzPQrg gDTYs5ihmYhshk+Hj47H0eoB4qYfztwG/TaaUQR1UuWpKWQVHDFN2q0pIlr0UlmK2bVI Q6oZsCthJR7EoRXJWaDUp90R0ftFk3lWLim5AYeUrHV6pBLRLXOgLgmQkxoHKrKh7EnA 9H/iP0TsDJgnY4Gh+6RfA938ieAycTQatci5FcB0z7SA/IHCEDEP6uvzxNC4Q5qf+T04 XuWg== 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=M0jw+/OzGxtvWmGinhnB05wXMIXS4suQaLkZWRbW9Rk=; b=0bpzYClfYLa1GEJkJFTMXZrd/aT1wlGHwKYnRmslyXsnpgd26jou9KD4XdRAiyj1+F E5TGFt8cAAioqlrNNc18hkHHF1uF9K9EbbikDrr+Hh15s2cHBSiAYsmOIgTMSM+pyPcW mMi6JGbhowEuBtbfHGJi9g+CjS6donOvq6fuykWrLkRUc2bhOVPIJwRY5BYWyjhXtDjx RqZj73xcpw7lRz/YdiIOyQF/zahWWWRHiy6gM3UhYyoBwta7aSKcLJdjY3DtcSOaVxN6 Jf9Khqq2XNCi5EaLfAaN6bC1YZx42OPCSEnOcMvg+E1E2hpPoVWBFNBDuTWZYHtto3OZ SOCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=A0q6GTTW; 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 qf24si2402299ejc.251.2021.12.07.17.09.15; Tue, 07 Dec 2021 17:09:15 -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=A0q6GTTW; 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 31EF668AE95; Wed, 8 Dec 2021 03:07:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2382668AE77 for ; Wed, 8 Dec 2021 03:07:41 +0200 (EET) Received: by mail-ua1-f48.google.com with SMTP id j14so1866143uan.10 for ; Tue, 07 Dec 2021 17:07:41 -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=+8C6Bc9VEfGvKgRQgjAHt5pFxIVYjekcetM2Gf7nzSw=; b=A0q6GTTWxBewyVLJbg/m8B+dbBT8RBcfL5MqZSjG8yk22y+9KAfftajYzjeNItjntE rtBp7zKW2PZ1vwSEgQIxM2yVUjceQsbg6jVm7DIHQcmlKHXQawfL+elY5kI8aSDNDyD5 vHVWjtUUFTqmw88U5yXeCB0e6Rncj7pRbUJkETHnHqiKTk49eqT/sITpmJvnR+FppuDB /WbDQCejaO+IPuhdDqFDsK6ivBRegwDg8vVlXNOAMfGzkKTTpcrqatHkSH8FUftVPo1a fapM18TVUL3VitfhcX4HgD62Nf13VIF+oqbL3QWESrEMI3E6+hwnSWm5s1JDMDj9TVKb 1vEg== 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=+8C6Bc9VEfGvKgRQgjAHt5pFxIVYjekcetM2Gf7nzSw=; b=ugiEegIeNxNY1Hj7SdGImBmkWB5aVnGfJz0HA64yPxxsqjm4rl/SF8WItmb4qcaZK0 V3dtYNyYOObbJBgO824+HP+PtNIF5nULPDo9qIebaiPmcYxTAnkBjpQCMGmed6GuWVSf x22hdmsLYXrayXmmtnPNR4Hf6WeAPzM1mGYYZOn1uMCQzKOFupY4g3q4SqO1vwxdenA2 qBifQhKumhvpqnaYpPTw030uuZikQ1Iajt6LG2GNFOA0Xtk6PQ4nmNiN+AQqetz7FMBL m0fYVu+12qIzNP//qxRlQQieUwUmsAgG6BA6Kh690B/Q85BTRVYicYBS5QK9a5xTtHoL lZcQ== X-Gm-Message-State: AOAM530JSXl22SnyVv0Nr0Qkd8erVbbsizzkB4F40Vo+uN+DI2A/l4tD z1cj2Aqge5xgEQe6K2f3/Eno87VyW29QSHUN X-Received: by 2002:ab0:3898:: with SMTP id z24mr4128114uav.26.1638925660332; Tue, 07 Dec 2021 17:07:40 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:39 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:26 -0300 Message-Id: <20211208010649.381-11-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 010/279] 4xm: 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: QmbQ0n8Wbnps From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavformat/4xm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/4xm.c b/libavformat/4xm.c index f918b1fc57..243c22965e 100644 --- a/libavformat/4xm.c +++ b/libavformat/4xm.c @@ -186,13 +186,14 @@ static int parse_strk(AVFormatContext *s, st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_tag = 0; - st->codecpar->channels = fourxm->tracks[track].channels; + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = fourxm->tracks[track].channels; st->codecpar->sample_rate = fourxm->tracks[track].sample_rate; st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits; - st->codecpar->bit_rate = (int64_t)st->codecpar->channels * + st->codecpar->bit_rate = (int64_t)st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample; - st->codecpar->block_align = st->codecpar->channels * + st->codecpar->block_align = st->codecpar->ch_layout.nb_channels * st->codecpar->bits_per_coded_sample; if (fourxm->tracks[track].adpcm){ From patchwork Wed Dec 8 01:06:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32125 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044850iog; Tue, 7 Dec 2021 17:09:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhLe+NRpI1aETrtOO+sgWcvA+CLk8v8SQHq/MxkT7eg0o5XKeNOiZjo+q4RsdfCzK08wlv X-Received: by 2002:a17:906:7315:: with SMTP id di21mr257705ejc.193.1638925776702; Tue, 07 Dec 2021 17:09:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925776; cv=none; d=google.com; s=arc-20160816; b=W2beEh+Rc45RekgUq7tUfjwmGSJjtnOwLGYvBrKAJ4xizq7iGWcbP7JNsCCkO0ac9F 4uyNWQemkRns8h2rlNmZMeWllAPpEwpA7MgCxHGc9sxyZ8yU+P9GPYfBB3LOomlPQS3X /u5zLK5ejCuWNIa+NFKjXRpcIhVgYOErXcwMSrH4pGCBjtRI3Qn/fNyE9HBu1M2jwLgm KMgJFKjyyVNU71c70/rvOVdbKS6pr+lF8TyOZ3nGAgjgQfQvnq6bKr6tA1DWxWR/z9xb y6d9GYpS5K7On8UZHMRBuYC7lGMGeVt+C9TmH4+ZotqN2nB2bbYB5PyOHxwZ64DYTsVN 8qjg== 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=qHvPtwz2Jevc6Ignycv8UHVb4gQ7ZsQb+PUAPtiM0K4=; b=YfimaOZi8D2MthXzYRyWY1mt6GxAY9HCIbn4gpK62WhteZZGe46qPdG0b5lTn2wPMd THRlinFxTyNn6tmifUrtT6/vlEyy/RtLv4hiqnbPHAiwxt2Enkru541lddLZFGEN0J9W XtAFFY3OlTW3em7UAiwTueGoQgGW9xz0Zcdj5Y7J6VG5Un0ZgWzkPyZ91fnC8T70/2gK Tlcyn7YKr675aQFGmbqxzzfikVXIEs8moCLHHUgHNMNd2ra9p59KqqOZ4KdUSAiuQKjt sGJsBwsm9hAaYHRzamYgkUTrJy5M4NhMxKUeLtw65D/QmPKwq6FBeM22g8bq6U3vCk/V pzUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="UjZHWUx/"; 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 u6si10793ejj.742.2021.12.07.17.09.36; Tue, 07 Dec 2021 17:09:36 -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="UjZHWUx/"; 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 2F1CB68AEA9; Wed, 8 Dec 2021 03:07:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2F8B68ADF6 for ; Wed, 8 Dec 2021 03:07:43 +0200 (EET) Received: by mail-vk1-f181.google.com with SMTP id b192so580490vkf.3 for ; Tue, 07 Dec 2021 17:07:43 -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=ukXKGC6vBV1qdnMXHA5lgbyaRBikqDu6f7SuKT812GM=; b=UjZHWUx/7G9Ba4uX/i+tY+pa/rEh1afDWdKkGcJxOEbkcv2/EJDCijuyTT5nJKe74P nrVbTnc7rGD0ZMksocAg/1UtkJorwoh1nd3b40XZtQJy/hLurmFmF1oy5D8SLNOQuSfy OMdeaSJR5CARTRYKdGhTGuYFhwl1DuZk/+B3CWGRpcj9d7+llLrP7j/Zd4t35oTQrzXD 0qM/9uukvWAX39j/mKglDjbQJBID4jxgpLUjWekgR+XIS0MA+9Ki+ZI42mhSBQ1XW+Oo AKuszYe3dNVFqWCgiCYVR6eOwIu1G4QJsI3WUxALHrVxzkVB0HXNPQc0uOkgqUYy+oLY FKsQ== 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=ukXKGC6vBV1qdnMXHA5lgbyaRBikqDu6f7SuKT812GM=; b=rnjHdFWMwdiEI+esfr2Pe44IxlZ0tr8I2Dl4fJBsePJ7jaWCR7DooMTH/1t1/OjyrP kzaycielG9T/44FB6yArtkPNLu8zZofAzLWq3BM29mI89vdivtfcMrr8eWS25A/a5DK5 PS5LD5pG8Chmf1JF2KtAMpnR4hCBJIohk9tt9RXZgGCclXvgkWsqqO/dbfDNqPvu8UJO ktmiv0NWqJm6qYBvQel8wFF7ZKxtyKY9irsRmPgS+q8bn8oqlfrI8QTamQVhwCxvbsLP npgVsxo7nrCNX+pkaicyZKBJ3c07TWCsp6cIO7410Ud5U9Y47DVpX68bLdGn5pciz1Ld n1Rw== X-Gm-Message-State: AOAM533ZLSeifDGWSrj7FIkWYp3WMyT+NMa0npfzte+BsYi0Qm8BZg0l inI/Px7SHlvhIP/oHJt+HZR+y/+eR9hUBrW5 X-Received: by 2002:a1f:a3ca:: with SMTP id m193mr55982736vke.4.1638925661669; Tue, 07 Dec 2021 17:07:41 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:41 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:27 -0300 Message-Id: <20211208010649.381-12-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 011/279] aa: 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: IiUtdljCDEEx From: Anton Khirnov Signed-off-by: James Almer --- libavformat/aadec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/aadec.c b/libavformat/aadec.c index 72f4b6f7cc..fbb9e0114e 100644 --- a/libavformat/aadec.c +++ b/libavformat/aadec.c @@ -190,7 +190,8 @@ static int aa_read_header(AVFormatContext *s) } else if (!strcmp(codec_name, "acelp85")) { st->codecpar->codec_id = AV_CODEC_ID_SIPR; st->codecpar->block_align = 19; - st->codecpar->channels = 1; + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = 1; st->codecpar->sample_rate = 8500; st->codecpar->bit_rate = 8500; sti->need_parsing = AVSTREAM_PARSE_FULL_RAW; @@ -198,7 +199,8 @@ static int aa_read_header(AVFormatContext *s) } else if (!strcmp(codec_name, "acelp16")) { st->codecpar->codec_id = AV_CODEC_ID_SIPR; st->codecpar->block_align = 20; - st->codecpar->channels = 1; + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = 1; st->codecpar->sample_rate = 16000; st->codecpar->bit_rate = 16000; sti->need_parsing = AVSTREAM_PARSE_FULL_RAW; From patchwork Wed Dec 8 01:06:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32137 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7045017iog; Tue, 7 Dec 2021 17:09:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5Z+IFug3oW61Ar3i7HofwHr9qVErv/tx/mOCkEkZsAzmS9A3KJdB+he9Iz2DAmq+5ai8Y X-Received: by 2002:a17:907:7e8e:: with SMTP id qb14mr3471799ejc.562.1638925788068; Tue, 07 Dec 2021 17:09:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925788; cv=none; d=google.com; s=arc-20160816; b=DXhyz5dDZ/vi5Xpracq0pOZXSJOBrhCyI2/sWGvIZinSxlJP/F9yNZQZLM69m1qwJm aH3k+84O7A+XXKtaSJaEbbKE4Ii63QKs+IrRh79fz7/6bgWSbNHUSGcQ/sUAmbkn3CXj hxX60RrUczj9wthut3I+imW31qw50DsaZi1JO0a5KXV0Lqne2UQMqZiIGQZOdmURs3MW qna7eJb7PRr5JN4FzkF4hVLiecWvHJfABQxy3+yjyWGPLxGgq3C3UN7/dSk+2PPHlhXq HFEKcAm1oYCNBM4m0Z+/0pTmddtoN2YtSy1Zfw5dLmvtA2H97ZCkX3Do22LGEFiinG6o BDLA== 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=pGxznPd1fEnY+uM/FUBnQHYs33yKLuYvJeoufTKGGeg=; b=tymdINnAQOHnirbGMAFzvJcga4GDjx0GpAh1/P2LcTno9jUtqT3e5iYdnnka7Ez+7k 7RXlxFGOOhmA5zPNW2U6uCEkJDPZLfIgYDKGW4KY4vlq/jU86wFx+nBx2B/58RyxKhSm d/3lBxiNgm0IhiF8BN60EpQtTnOVabIs6Cx53v4NafpUMNPr3ofNVTThCmY5GxfE56k9 SEpz/jp9PTHgBduVQVDo6wddvdt275j1q1H9tmACqS5cFXUsgedxcbNtQgAV32JdsKvC nOZV3fbo08s6WN6KbaUCKB/N1mNLuSd9QRPXvvFU8FeGOI6r5NVpjHoWkca3SGIa2/rt bsmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=joVYHZvY; 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 i10si2055529ejd.303.2021.12.07.17.09.47; Tue, 07 Dec 2021 17:09:48 -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=joVYHZvY; 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 1A3F268AEBD; Wed, 8 Dec 2021 03:07:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AAB7668AE9C for ; Wed, 8 Dec 2021 03:07:44 +0200 (EET) Received: by mail-vk1-f182.google.com with SMTP id e27so579493vkd.4 for ; Tue, 07 Dec 2021 17:07:44 -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=512ft/qic8Yd87jhP0QsVsYGC7Jh9q5jFrMNMxW2fwU=; b=joVYHZvYlYFB/ub8yYtaNnEdqGhyXVjC4voZWJ33BiDLkM5O8qFAjf76WO+eiEIbTg mPqpTRyz1Hy5TYpXqyAc0FvLWhhv9YHAHai/1A0bfG0phb9EIvywbuqc/UHoHGKQMlw9 ZIdUuO3qWVIa/1E2hifyguEuTlIWjBMHAn5vddInfGZ2JIJcdktSCDuSRhFxeb649gxa jv5MkugYiDVzvjD5njyJ8O2QOo28vzqHip4niBaL1LXLdwfWsSlYux/DtkqOpNYpIkbA OErVJRf2GSAV9ujQSYqz4Cx0fwlT1eiGgPRNFXXBEGwYoitxgcy44Bs9aRGp1NhQyuFH ot1Q== 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=512ft/qic8Yd87jhP0QsVsYGC7Jh9q5jFrMNMxW2fwU=; b=umBPlClkcCmz5BVA/9VVL49RkXBBcfkinwvgefNakPazkwhdZaDg9/mLQKRSpV921v xBez01So1uYdP/ZI/l4ERstc1EtxewNUllFR/GCZKPcYfeWM66AdkLSBlyBGztHMaCgg og89Aoc0OZMb92OVuoElMqjPwzNBHr/X78Y5SkNfOMZGMEJ+0xgQ0JtqJGR3Fng+Rers OpWEHFANxja9LwukB95UhwozQP3Po40+rS/PLqWl9bMJ4oww0UOD1FD9CV2rmKTC/cYB 1xsC4meORyBvZYBxkMpaX19ixhryGQwZyu6hOf01RomOZxuveoF1eX+EL0V2dIVOMdSp VPkg== X-Gm-Message-State: AOAM533MOE3cYx2T579HeANyiHvaYI3JnLApC7/Zmv5ndBnqP4ozKHDV 11lM4x2prVYZ3Xq9R0WvyrJVqgx26crw/OU8 X-Received: by 2002:a05:6122:1354:: with SMTP id f20mr57561299vkp.12.1638925663009; Tue, 07 Dec 2021 17:07:43 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:42 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:28 -0300 Message-Id: <20211208010649.381-13-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 012/279] aax: 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: f4FBrn6Pe9o0 Signed-off-by: James Almer --- libavformat/aaxdec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c index b08ee036ed..8eb2540407 100644 --- a/libavformat/aaxdec.c +++ b/libavformat/aaxdec.c @@ -279,9 +279,10 @@ static int aax_read_header(AVFormatContext *s) ret = ff_get_extradata(s, par, pb, extradata_size); if (ret < 0) return ret; - par->channels = AV_RB8 (par->extradata + 7); + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = AV_RB8 (par->extradata + 7); par->sample_rate = AV_RB32(par->extradata + 8); - if (!par->channels || !par->sample_rate) + if (!par->ch_layout.nb_channels || !par->sample_rate) return AVERROR_INVALIDDATA; avpriv_set_pts_info(st, 64, 32, par->sample_rate); @@ -299,7 +300,7 @@ static int aax_read_packet(AVFormatContext *s, AVPacket *pkt) AAXContext *a = s->priv_data; AVCodecParameters *par = s->streams[0]->codecpar; AVIOContext *pb = s->pb; - const int size = 18 * par->channels; + const int size = 18 * par->ch_layout.nb_channels; int ret, extradata_size = 0; uint8_t *extradata = NULL; int skip = 0; From patchwork Wed Dec 8 01:06:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32147 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7045200iog; Tue, 7 Dec 2021 17:09:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWVHhEVWXXbfoFJQFZH1M84pN9Q2kehZz92rDF4lG+KxPNB/d8lLJZKx1eNjaLQG6Fijty X-Received: by 2002:a17:907:3f96:: with SMTP id hr22mr3504936ejc.492.1638925799516; Tue, 07 Dec 2021 17:09:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925799; cv=none; d=google.com; s=arc-20160816; b=hBoczl1uHRpIyAb+Jb22dvK38merBoe6KvGxmstTjXb3rL4+ffiRWV+yR98+9WfBE+ viSmT2//gZ0XgLuD3JOpxG4MQe5ivbTUC/FIE39IFUgt2prMMP62PbExatmiCeKKqXBF p02A8UjnJtjqytbzvqOKzR7OiOCWkDeSE0HPKzXbWRAJYzZyhSDjaZ5LHd5Q3xR0haCL 7Q89oDcjsWZTdTDFBsropriuumYG24INo3dyYbnwguSTnuvzl6IFWD7Jm2N11eFCceU5 D5t+9TQOOxuLBJtOeA6eGjaePxMM3el2WVC4QV+4UecV/kpHYV2d84/jWC6nijFK3dtb OIUA== 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=jYnPIOvUwf5tJ9+LUVe5m0GOqyWyQB6gBTvzI/AB3wM=; b=b/yVmo/VqyeBFZpHrblk7h7K4B4ZV19/JE5zFq/O9nOO3ItNJUuYSskQP5UPocynEP //AeaAYyGHvAG3n3ho2PNiTcPgTXHMZPoTBddpQyRoarRYCE/UjEpLU0vsBh3or8h68X /zOoZy/83SPXQ9GOHgPj++SDFT37/y6yeH4SLBl/U30e0cZfCfCqnt7J0RG9adEI8TWB cEI64n3xulOGWQtNJRsiKGWiGjzGZE2rIq4a7imYoCIT4i3zFQl0eBdWno32THwofgRt iZMf69QzHVYJqtca1XIjbMB2tlYrqeZzA9c8pLJQtNf2WWA9oncoUNBYvOgM1U2igLAv EgIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=VSCCs2zY; 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 ds8si2742588ejc.494.2021.12.07.17.09.59; Tue, 07 Dec 2021 17:09:59 -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=VSCCs2zY; 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 EC6D568A7AD; Wed, 8 Dec 2021 03:07:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EC3C868AEA9 for ; Wed, 8 Dec 2021 03:07:45 +0200 (EET) Received: by mail-vk1-f170.google.com with SMTP id 188so560454vku.8 for ; Tue, 07 Dec 2021 17:07:45 -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=nOevSgymdots+DtYaPcqX2wL+D2xwSHrMGGO5rjYl5A=; b=VSCCs2zYh6w0vPK4Ro6XY+0037h7V4BVi3Lo8sv6colUAr7Ydu4kRqjYMaxL0cdXOE 8d/dA5EHLcB77tla0f0Q7nI8nCaH9gcgIpdB6oVYJHrSNq7RLtJERFIa6iAYnxWURdec Qq6Uuc3rwkQBJijdi578qSEtjhJavAmcW6d2EFWV6b7mAym7QOHYJgpJIVoWqYElFkh7 L4Nklapf4QIi2A3ce/mN4CSKlKBbTasIpKrYd/uoe78eYQ0+SKaWBiV/4fe9PGXSWrHr igeDuSISD50srwopic3ZHuj2TTRS9+24EiujpeMqiATta6xwa/ZYmrv2f9IeCR0lZxxB xuIA== 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=nOevSgymdots+DtYaPcqX2wL+D2xwSHrMGGO5rjYl5A=; b=pSgXEO4JaGn57f1A5fexrGAulq5NuIwuds2wmh+g/XnYbJ29QkoV6FhwF1kouj2tju K8F6eGs/IKJfBlYpmb+MjEaA3sduBCuDH9mHR76JmjxrD9c8mDI9hHjvPkIW0tKRraY6 vxcnV540GavAxI0dBuw+6E3bh5GToY1yaUG/ullRUJrADqLellyqmdeGaAvNEqxLDh/F jZ+VUrLsr/M7qdeLmADDLubP8PX4Fe3NfI6RLEyaqeEI+oGzllKQbYIva+BXfijxjfKI +tJFD6OqpFIn53+2Lma1n+QyoAdzcI4azieKIoTvlxVZ3n2PNIA12JBc62qnpC1dcgUi CE3A== X-Gm-Message-State: AOAM531bEo2u8U4L2x3YXOlgrcxdwinMlWDPWuqkAdh3k8g3sZGBevSq AAtrz6CADbbrdHJt7R6KGTwpHamexEbgUqcy X-Received: by 2002:a1f:e605:: with SMTP id d5mr56713298vkh.39.1638925664153; Tue, 07 Dec 2021 17:07:44 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:43 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:29 -0300 Message-Id: <20211208010649.381-14-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 013/279] ace: 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: U797KCW+xi/8 Signed-off-by: James Almer --- libavformat/acedec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/acedec.c b/libavformat/acedec.c index a52a0f0e54..74128e0a6a 100644 --- a/libavformat/acedec.c +++ b/libavformat/acedec.c @@ -74,7 +74,8 @@ static int ace_read_header(AVFormatContext *s) st->start_time = 0; par = st->codecpar; par->codec_type = AVMEDIA_TYPE_AUDIO; - par->channels = nb_channels; + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = nb_channels; par->sample_rate = rate; par->block_align = (codec == 4 ? 0x60 : codec == 5 ? 0x98 : 0xC0) * nb_channels; st->duration = (size / par->block_align) * 1024LL; @@ -85,7 +86,7 @@ static int ace_read_header(AVFormatContext *s) return ret; AV_WL16(st->codecpar->extradata, 1); - AV_WL16(st->codecpar->extradata+2, 2048 * par->channels); + AV_WL16(st->codecpar->extradata+2, 2048 * nb_channels); AV_WL16(st->codecpar->extradata+4, 0); AV_WL16(st->codecpar->extradata+6, codec == 4 ? 1 : 0); AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0); From patchwork Wed Dec 8 01:06:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32143 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7045366iog; Tue, 7 Dec 2021 17:10:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQ4h6ofkmBY0v6fc6i9+Ru2/MjVebQEBxcBnM1K73ByM56mFF4ptsLP9BVH+3xEA3Di8s0 X-Received: by 2002:a50:e611:: with SMTP id y17mr14687422edm.270.1638925811316; Tue, 07 Dec 2021 17:10:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925811; cv=none; d=google.com; s=arc-20160816; b=seOOjPwzcPzPpxrIWVrCAb5brTtbH7TwrfCTOch3yPHfzpOEP7xpvWn8OuppxSWm+u y/NldUl8FEh5m3VYtYuO30wcXIfsNvk7nCQadgJkMhCO1rQ/R+A5N9rGb8la1BQs48H+ NjyqdjZZqf1NERLKXv4faDapsrlVQLWw1RKTiTf5d3lrE5TWo/jYqoVjINy1Ra2SlN7G bnzgPCrWJKHw6IbgIdqX0rHjxa+SVH6JrTsh1D4FNmbU8pMulUuicVfuSh3FXWsJ6czj Y4R5ILoVXhsyYBGOv9iP2LRfn0yY0Qiu0qyw6JjPC8b/B3aZKR2/sRvf9O7gBnRj9nps VJuQ== 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=xreVnxjYwaIB3iDNMB7lvfIlyCI1JJimAbDA8WeV0s4=; b=rsDP4UnM2AcVndrwyh4jj0UfHPiB7QBp2adLrC/QTq0xD1fgz72x69gpaUXX4wD0RK xyUQgrJ/DwU4UNkpKJfDK5R6+CZBtZlfvUVtfph6wrVUHLDLzZJOtkV4JTS08A7WiQXy 98VdjpdmsXVuGDH14rWtbBO5+DpwxWta+PvE5j1D8yDrQCz6sqiDNFToofCSfl6JgPhz zrbQBcxbTOnMA6He2aBAXb9xsFyTI8uZj5zQ7OTeFVOS08ofZ3k8UMLmwshj7N7Q95jb QgmZ6+Jo4poM80jQKYP6rB93j3tvpRYxLV/RMj4Vn/MH63juXCqUGF9BpPcz/55Bef2s l20w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=KlpVDFbr; 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 ne24si2633658ejc.492.2021.12.07.17.10.11; Tue, 07 Dec 2021 17:10:11 -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=KlpVDFbr; 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 5F06868AEB1; Wed, 8 Dec 2021 03:07:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2054F68AEC5 for ; Wed, 8 Dec 2021 03:07:46 +0200 (EET) Received: by mail-ua1-f46.google.com with SMTP id p2so1847319uad.11 for ; Tue, 07 Dec 2021 17:07:46 -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=kSSC8FluUjNunPAt3fQv0sPy65m6paXqhNgDYLS6xVE=; b=KlpVDFbrppmRcujOB3+S+SOgd5Q8fqGv25OFq7YsmXaEBgbKI5KAPyB0VMUFJ84aSq xIEG08KlYxSniBSyDXY5WBF8vBdPO7VmUYD8Fe3kMnqpL/tGdsfGMK3iZXkTL7aLbQBv tig6oYcZPivR/e2f9TcsVwG+JdT2r/zRx3xhY5g9t+mV++X1E9zPej69xla38mPfsArY U1scGL2WwZxvdHusCdVl5l4aIM3s2enfEzvM9TNAvuHol/t0n0UOinyYz4ZMy09YFSBG 4CD12D0hhP+WIu6LTmDTxKxtBJGgie0PBW9eBqolgNhJniBbYDX3PyXpNBFzfkwboqhH Kcig== 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=kSSC8FluUjNunPAt3fQv0sPy65m6paXqhNgDYLS6xVE=; b=DeelnzCjFK9qRVwWb2cue2SvQ4Sq1yQ5p3FQYBhKuYA7L7A4/VaW11aOldGBFp5Hju LcH97PmS3ftXI8OVV9KxugxZXqPtiEJg//UvBIqT/849cAc8lv/hNSm46TYu8iF58FUx JunOYaQt8R4ebdsbh/lssupgX/jhyhDyW0sKAQ3Mw1fSiBi9hxXv7SEyselzcOyW8BVf 1k81PYYn5mbAnfqHX16xG05pGzT4/dV/EuIBP0gDrrr0ZjSZz131XzBpqVKl9Q6Qghug kQPRCl+nJkrjhNMD1qr7+0ZyMvg4ZCsB97H9NuTs2q5BwJJ/dMCQ1XOIdko3/Hmj+oj+ e4Mg== X-Gm-Message-State: AOAM532fcTTa3KoU0lOLsSK7Dnp1VEA+g89ajXEAnnpX1KusOKhnrNa/ RDdEsDYSWqJtrJDPFvsLED3ZWI0gnUAVZJLQ X-Received: by 2002:a05:6102:199:: with SMTP id r25mr50566452vsq.53.1638925665386; Tue, 07 Dec 2021 17:07:45 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:45 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:30 -0300 Message-Id: <20211208010649.381-15-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 014/279] acm: 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: NTFnHIGxTIhP From: Anton Khirnov Signed-off-by: James Almer --- libavformat/acm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/acm.c b/libavformat/acm.c index 0ee9114f70..a6da000130 100644 --- a/libavformat/acm.c +++ b/libavformat/acm.c @@ -48,12 +48,13 @@ static int acm_read_header(AVFormatContext *s) if (ret < 0) return ret; - st->codecpar->channels = AV_RL16(st->codecpar->extradata + 8); + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = AV_RL16(st->codecpar->extradata + 8); st->codecpar->sample_rate = AV_RL16(st->codecpar->extradata + 10); - if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0) + if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; st->start_time = 0; - st->duration = AV_RL32(st->codecpar->extradata + 4) / st->codecpar->channels; + st->duration = AV_RL32(st->codecpar->extradata + 4) / st->codecpar->ch_layout.nb_channels; ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); From patchwork Wed Dec 8 01:06:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32145 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7045760iog; Tue, 7 Dec 2021 17:10:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQWAgYFN1d3i+KoQDJ7KP8s5Mje5We2IGaNDwEciwKf4hfILOPIsE9En4HX/8H2Vb2eOXe X-Received: by 2002:a17:906:4787:: with SMTP id cw7mr3735771ejc.311.1638925832116; Tue, 07 Dec 2021 17:10:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925832; cv=none; d=google.com; s=arc-20160816; b=oT4PM7khYiKuDFTvvZ1bAqhJS2BKw0uoi077PN57o2HsHrEazB8B4mvodXv3OAPcRg P31+AgX4HTktnJoiVypfk0W5Y+p0EGSimuk61ogS6WUnVuZZn94sZwFYhH3VX8M8/ws5 OCwNGd47+3wfuJUVWGhgsSPgXzM6fM/JxU6uVUJh/zTgnHr9zSRBdpKYuxhpSiY5U/Ue DLKRtfgrifLYX1YeYV8kEIlruXAvZ9qj1K3t8xF5vQ/uMiqH0JXFZsfvWvtplMMsqd8T juXgErPX0eznUMQQ1AYYU6Jx2NkZKwU3tpGdC8cqodzEBFzgvpJgBoIrhD3GSJxiKdyP 5yAQ== 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=HwgyfdBvsLjjt9Rf01W6OTvtaB8z/VdgZi6hR1+tXKE=; b=GDS2OICPimmut+xDBracEA27tKqyCaigUMEvRFzjpjtVDkBC1uxKL7m+EP4wEITr+h n0B48iTautJBDT7gz/C4gSVfGm3g4hVw9A+OmzeuIUga0sVAob8aAL+8tMITnhpl1J62 w+UzsAsATL4Lrk5P7bI1gviDQpXpPlEE31Z2Hq8WfFkHvF4a9aDhddlf9+B5e82d4DoI REHdwhb8ZGmOOK0nGKEy09ZQvl4UeKBzYwnPpW8aALwejmWCZpkFJizaoNV5pIH1wnHS TcV0NG8Rwe8TnbMNhTzco2pGCiciFfMzFll7vJrDo/qaXeHSxwqKBRRW4VoDRa7wI2HX 35XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=mNlfTueN; 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 m15si2543117edc.235.2021.12.07.17.10.23; Tue, 07 Dec 2021 17:10:32 -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=mNlfTueN; 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 3562968AF08; Wed, 8 Dec 2021 03:07:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F0C9568AECA for ; Wed, 8 Dec 2021 03:07:47 +0200 (EET) Received: by mail-vk1-f182.google.com with SMTP id s1so566660vks.9 for ; Tue, 07 Dec 2021 17:07: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=Sp6R3jWRZ+GTCaUv2kvQgm4ICmaV9Pd59tyxYkAaqE4=; b=mNlfTueN4QeBix6kdb28fuwBnM2C7j9ZhQqWlaZ9sfjhl5cLB6FQa0BlViG2qR2bWv AUeNsJmFZDeVnUBm4ozO3y41amuX9BFYTlb7jIMY5oJv4D3RNhZwWbzwHp4by/UMWwZq V83+WoAwi9J0hRZI7+lp/USJmVMjwhVyQ5ftvkulFGAnKVJIZLi9c7k7rGeewbDxkGQF 6JYkC1OcMqDm669uj8f/hkc8Me3W2rKRMitAQK4G36OvjXJzRnaz4wcl7ueKKoBLfa2m XvYjKaZ0d124+uG0Q5k4/K9HKj0afyD4KSReeyT0tHZ3ebY3SroEC7LLWHhgEq1gs98x yfFQ== 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=Sp6R3jWRZ+GTCaUv2kvQgm4ICmaV9Pd59tyxYkAaqE4=; b=WpS8GFLJLHpYXpWswQqTH5/qlh2IHoEggilg6FLD4/dLmpANebciRyIG+okbjv1+F2 e1fwGW9Y39vaUrs4cXrOGaEBNeZ8bwFsV/+jLpMS/x81bCf68TOFJQ92vPOJhdG9gAi0 oiXLxz9oUo80dgaA9roBaBKe+PCi6JluOUQkM9UPQODXC6pk70Ev5MEa1pPH44sRrkut luJKRbBujKAZfKlEQh1bBp0GQ4r1MWkhWa4mZWyoKNVQh5nKWBeg0gL8WBH2md/Ym74h qxm01DfHRKIIQXVzYcHWedPZhVrgYBHhrruvOFxIvrYG5YB0oBofrG0urB04HCmyR2uF ZiBA== X-Gm-Message-State: AOAM533BOK903l7rqxpdvmFrfaVketZ0LZg35usNzT31EzTw1J1LPB7h 2k9IX7tPLJIeKmPCvdo480UNd9VEhJwId/Xr X-Received: by 2002:a05:6122:1796:: with SMTP id o22mr57871283vkf.23.1638925666553; Tue, 07 Dec 2021 17:07:46 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:46 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:31 -0300 Message-Id: <20211208010649.381-16-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 015/279] act: 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: MyrQBNsnQeyL From: Anton Khirnov Signed-off-by: James Almer --- libavformat/act.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/act.c b/libavformat/act.c index a369157647..49639acfcc 100644 --- a/libavformat/act.c +++ b/libavformat/act.c @@ -88,7 +88,8 @@ static int read_header(AVFormatContext *s) } st->codecpar->frame_size=80; - st->codecpar->channels=1; + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = 1; avpriv_set_pts_info(st, 64, 1, 100); st->codecpar->codec_id=AV_CODEC_ID_G729; From patchwork Wed Dec 8 01:06:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32148 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7045814iog; Tue, 7 Dec 2021 17:10:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTnk51IHHP4M3XyV+BG4ZW1DVNi1d/OqiSms5WswyDHM22El34x7DYWcb9DunYC2Wn1Xlq X-Received: by 2002:a17:907:1c9d:: with SMTP id nb29mr3747225ejc.74.1638925835333; Tue, 07 Dec 2021 17:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925835; cv=none; d=google.com; s=arc-20160816; b=COKZDFKLPy9H0M70yAyYzcbo/rt9t03WbUNdaAlSHP24Cc4BhnC7NLMBwM++nFey8L it7IpMHicxaGI1TMaaKBZN4L5qGCuVh/BAx3rS4Ur8P2j5nMF0/D7eWSi/VqodcEwyjg kDtskTrLIQWc16VN66auXW1Ez7UAMKbbHCQCGg8mw/dcGkC6EIWONRl7mxK3r8YnkULk DXVr2kQ7Tydh5E2Dg+D292SJRYo4zRAubUtMKhZpBzPyyiIDhZmLrwCCdGtKYoSBmhRA PNQZrVWryVCZLJ07gOPFY1YHEmYODVCSJfOSzkOXAZSEVxhcCWg5Up+n9L1LI3AjSEPt Qq+w== 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=8pW5ZSXesTTSxBgWeBdzNyEjEbO+WI15Bby+6sCBUj4=; b=QffYFfg9dPQb2SkVgBcCjkmBkHkXSgO42/bfy0d5FVXiHEN1l8TuWdC6oDvBuDZE+O 3xuZkFDxZIk2wLtfXJom6PfZJ2xvpH95Kb18msEqgSflM9KPZux1E55MdRvtJIsmSgxE 3PsOEEEA1E0x6hQKELMXS+fNHaNO8NcuXt8lp1djEge3ex9N8Bu4LXSfQowznQKblo1n 0dEz+rk3SnsU6W/d3fgtbe/2pxes3j85oUDi0KknUh4o2RAYxxx2rHClgYVIPZAV4Uod 588KeBhqzK/l6ttT36lPGbUl8zcEUd++uxBFhRKX5sSgeJdgyPO0YwczY31rM94RDFdh p1Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=CLnI0dDM; 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 k26si2062997edk.310.2021.12.07.17.10.35; Tue, 07 Dec 2021 17:10:35 -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=CLnI0dDM; 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 2413D68AF10; Wed, 8 Dec 2021 03:07:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 77911680CAB for ; Wed, 8 Dec 2021 03:07:49 +0200 (EET) Received: by mail-vk1-f180.google.com with SMTP id h1so618013vkh.0 for ; Tue, 07 Dec 2021 17:07:49 -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=vygrBIcdFt+Y416k/+pMYchm9gDZoh6w1Vdds5JvAnk=; b=CLnI0dDMu3hF/smirPkVCYnWciECMpFwjhuf5KqUWfgugZdML2RaOmc754xX0C+AAN hrvd+z7ZjJEV7xeFoL7ADdNKxDVXA1YDsgcqY/LVEyvCVg/aFem7Khd8gimcKxz+L80v LfqAHMyLfloy/VTPPBFbSTUZXSpzbM6Hr2gy3sw5p5l73dgnD0Ptgdi7JG0BeU3VrOPT uL9nWvZ5MarqNWnoUKhJre7LSWIz5Wj4MDClIIXZ55wPXhqvEAJ885xwkzglyqHKRz12 rjpK393lyxEKzgyHEB23UzfKHoMc0pvUa1r7RQl/ePgkm0b2HiR4JJouhOB/z/Yyn8M/ G5ig== 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=vygrBIcdFt+Y416k/+pMYchm9gDZoh6w1Vdds5JvAnk=; b=IW/dulGMVKPj+KHjQ2U/cpYwS820cJ8iK/vzh8xmtfPtXCXEVV/qx8YCDBwQgPSteb GdRxyHsYRRyQrYXAAkkfolc2WF+XFeSMHvXrtGesN2m/3lpPXZ4qmk06uvluIC1ucgGY kkZvglTtGAtwgdiq9YzpGpWCOAUz3PVOTtquEhHdRzyHOTD+3uk0RbAus3351HjyCETs nWT9HYBewWK6Co0wjQp7nsCGvKOfaMhvshnVR3x490Ouyr7jQToRbQbyygSPoz/ZkfpB +u5j7ONs94O/BqcjrT96jcSGZxOLuaHHjgME7BU6RQz9WgNnQbyn9PBQFDEdYL8cKzt6 C7Ug== X-Gm-Message-State: AOAM530DZekSe4ly3e94DgUwgpbJw6/DHfREswJNHC/vvXLYuZtiwYo6 UwFazNVmpQ/V44ezJeFt+9ow0J4GcGOujf1C X-Received: by 2002:ac5:cfca:: with SMTP id m10mr56457556vkf.29.1638925667769; Tue, 07 Dec 2021 17:07:47 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:47 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:32 -0300 Message-Id: <20211208010649.381-17-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 016/279] adp: 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: FyaWGXLY/07w From: Anton Khirnov Signed-off-by: James Almer --- libavformat/adp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavformat/adp.c b/libavformat/adp.c index 6d5f9d274e..c9a5a04507 100644 --- a/libavformat/adp.c +++ b/libavformat/adp.c @@ -55,8 +55,7 @@ static int adp_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_ADPCM_DTK; - st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; - st->codecpar->channels = 2; + st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; st->codecpar->sample_rate = 48000; st->start_time = 0; if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) From patchwork Wed Dec 8 01:06:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32126 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7045951iog; Tue, 7 Dec 2021 17:10:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOF2AVKtCj9fiGFFQDf2ULK+r/bSqGUQfMLwP+f9ywKNdulwRtK7a0uw4tyyzXr2Hc7hbx X-Received: by 2002:a05:6402:1d50:: with SMTP id dz16mr14207734edb.385.1638925843836; Tue, 07 Dec 2021 17:10:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925843; cv=none; d=google.com; s=arc-20160816; b=cjuh/4MPJQzTdAFaUUKLKRJUCEWhpczQXz22CWJOjO2OSv2jmhXX47Rl/z/3TUU0Bm afcVA0cNULN9HT3DHTLPQH0BvIIfuuTMwlt5O2Jg99pZMXtPeLyXOjb7NALlAfE/oe5x BxhDKuLDPnTeOV1ewwfDsBIU5tda7T9pjwjvzqVx2R9f3Ne74dw6i7C6zQbxSOI1wyjS CTAecm4XDkvsS0a+owVX5iqt8EL9/WPiJjhlw0AGrhA4Yhr+Ou0ulZYLLmLOZL+xduIS 7HvcImoePukYgAjdecUpfBS544xvnUl4mvdqEHNoSFxC3WtKW5szZs2vn027cKhFnQjS 6FUg== 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=JdXndZpMKSChb5+CbXtcgyi9lpKOW/g/UFthacisf14=; b=KI4C773hm5eEgCfld67HrVW5T3exkUxx8EseteVoHG/YnstGUbixM1Sj0uuC7qfmYS PIzvt9V5J7DN6eqLHa8eYI/Neg3ON7ca/MBb7SuvfTf+uJJWxKxpH2mdZV5HyBTuc1xj 17CbVNUkqo/YeWs0hsgQox3CCOfGeMaO7Wcqld9dN4rgzbjTDZRkSqMDCtGXwOY19aTA JyTm3L4Ot2UiGqFmlALqWkCq+vHsI6LJPD/Hz8xz1NxbB1X2zy7uTCqQyvhByfmM20mj DqLd0/oDI+Ic9gFqy7+GhCWYmNJ+ymDVAa6BOOJaFaKsOC9ODgU5Ew9i5yFi68NRFmVQ ntQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=cmVvUIyd; 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 z2si2019524ejm.238.2021.12.07.17.10.43; Tue, 07 Dec 2021 17:10:43 -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=cmVvUIyd; 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 1792068AF1F; Wed, 8 Dec 2021 03:07:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B49D680CAB for ; Wed, 8 Dec 2021 03:07:50 +0200 (EET) Received: by mail-vk1-f170.google.com with SMTP id b192so580650vkf.3 for ; Tue, 07 Dec 2021 17:07:50 -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=t4mBm8ctmuIcixitD3zxDjPKRV31dAKCz5+lkQCxvQ0=; b=cmVvUIyd5KQrC5rrty6ikxV7iKMR+9u5TgHLWi/JM1lbcdznZTNBoEDmcuKPMIN2JR F6koLNsKoNOlsUSz7BQ/KfjFVobcmTZjAIiZOpfNWHRzY9gRen6k+nY9XazGUHktNfN4 awkkI2PdXelB/BYT0286JFp5r96oI9QuLBo65vxZ50c/qNArmw9c27VRzNhSaNuKCEN3 MgPh8nxWqSmR8ydP2gHc63QRZiG/FNgllK6lvboTiqyRQA2EVXhmEL/0edHTORFohBI4 D82+Qx4t0txQFyAwviAl3wYw8w5XJdv5Rb+3ey5sg1/J0fIYWrUgbqyJYVN/lKB12CfO g38Q== 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=t4mBm8ctmuIcixitD3zxDjPKRV31dAKCz5+lkQCxvQ0=; b=woOOYCUGf+jPD87POuN2wIBw3noFL0qyVE3v6ZlIvLzwCmBRAzgD22WSteuZwjQnL7 OqQKEam5gYxUZ2tH4B/0Dk30ZllUHxGoQK9EYowpPCBTqNEssoN/UsAOQe5H4kp6oR/8 xg7kLWMJVK4UPnb9Pw9FTwGLxjY/PPHB4RdrUYuQk06iO9fJik/Xa2jE95ELqtEKQVy2 ZNgqTEBQrLJ6fH8l36giE1npbk4Sp8OfdTWeNB+qBHpqS0JpKnw9d282D/6DC4P9XpSS YJzGWEZqGTqfTGNDvp7PdKJHhnTCsv0Qssz0qsOQbeltISBY54XxSAaCS3ITArduoRjW G4Ow== X-Gm-Message-State: AOAM531IogOKCMqFOh1YrLXD8zHR9dt96VFuSrXndTr62L8KlV2jGfXE iKjIWJEOHWzIuwPKeywj9oi3aHLzMAYH9S8A X-Received: by 2002:a05:6122:d09:: with SMTP id az9mr58783798vkb.23.1638925668920; Tue, 07 Dec 2021 17:07:48 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:33 -0300 Message-Id: <20211208010649.381-18-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 178/279] lavf: drop the channel layout compat layer for old-style (de)muxers 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: RG6TWUB6UEHo From: Anton Khirnov All the (de)muxers have been converted to the new API. Signed-off-by: James Almer --- libavformat/demux.c | 12 ------------ libavformat/mux.c | 9 --------- 2 files changed, 21 deletions(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index 3bfd753f64..a9670aeb34 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -194,18 +194,6 @@ static int update_stream_avctx(AVFormatContext *s) sti->parser = NULL; } - /* if the demuxer exports old channel layouts, convert it to new */ - if (!st->codecpar->ch_layout.nb_channels && - st->codecpar->channels) { - if (st->codecpar->channel_layout) { - av_channel_layout_from_mask(&st->codecpar->ch_layout, - st->codecpar->channel_layout); - } else { - st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - st->codecpar->ch_layout.nb_channels = st->codecpar->channels; - } - } - #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS if (st->codecpar->ch_layout.nb_channels && diff --git a/libavformat/mux.c b/libavformat/mux.c index 9dd6b13ac8..510ede21db 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -273,15 +273,6 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) goto fail; } - /* if the new-style channel layout is set, convert it to old one - * for old-style muxers */ - if (par->ch_layout.nb_channels && - !par->channels) { - par->channels = par->ch_layout.nb_channels; - par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - par->ch_layout.u.mask : 0; - } - #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS /* if the caller is using the deprecated channel layout API, From patchwork Wed Dec 8 01:06:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32144 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7046074iog; Tue, 7 Dec 2021 17:10:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNdxHJGmLq4ssPPjW/brIJtS/AxLHwMSutcV/Gj0CP3IUEGfkAGG1HPW0q1GblSjWn0xfk X-Received: by 2002:aa7:dc14:: with SMTP id b20mr14384650edu.133.1638925853232; Tue, 07 Dec 2021 17:10:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925853; cv=none; d=google.com; s=arc-20160816; b=nPOi8tbgJyLcMxPSf/Rwoyuct9yW81018AC1Y8m9JZYrL557W/S0lMDnzBmYX3XvJD TWzAwYQW7mDcNmN0zSFX8YnHie4CIarbH4MHUXYIISStqndusayuywE513JxcuVCuC/r 9FhXiTCL4sZdcyTI70wcztj/+xGvyI34qZSPfQpj4Qs3K5n3ZPiulbYuvW5I6NjAvRnz Mdh7KpB9LhwV2eeZSzLVSk79rmJ05E5F2BwR4U80VWg/a34M4TN08XUC68lVqchaK4ia I4XsVC2PJvoCcBvVHG0s8FJ3A2Ypq1md+WlhGCkHwR2dBirLcY0d3i0x6FWaXB6J7oYz F/IA== 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=6SoCWFveGr0OqHrRL587ZkRvmCPG00UyoIpcwwVIBWc=; b=G7rIxDH5TFpc5hgSGzV0n/dsdfZF9GLrNfZUgdya//Nwj175TYjMS/p30xZWpIxSUr 9/ez8ZIhuHsNn3o5/gntGn8m4aSTMTQVo5JiC1WYLYwkOEqFynVpmeWlwSLeh8vYefVS ofCz8s/A5BteVtljXFQbslIqyuUhXJukj63AkcYVcGG7a4caSk93k4WvI1Ttart42giT pFTLOQPySVffAqIdeK03k52flXM5qO3YiQjNrCcyWMLcRz/ei6hmQjz2GIBMDO4hsGvI P4x/3qLWHTLrojR+2ouAunhC4g70EAplTivQovTc7P/suKZLGLC2GjKwWjYJ5o11/KQ/ PBAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=LPhxdeDG; 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 sc33si2480871ejc.409.2021.12.07.17.10.52; Tue, 07 Dec 2021 17:10:53 -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=LPhxdeDG; 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 D2B1268AF19; Wed, 8 Dec 2021 03:07:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 66DE968AF18 for ; Wed, 8 Dec 2021 03:07:52 +0200 (EET) Received: by mail-ua1-f48.google.com with SMTP id n6so1964642uak.1 for ; Tue, 07 Dec 2021 17:07:52 -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=YhQXz6yZHHf9ZIVCJk9miX5vn9X4sW3OzNacg7VdL9k=; b=LPhxdeDGAIrlVFBFnPYWnuZpaxwuoCTabIWBlkMuUnTCWdkxJDYrlouS2/sziWRhHb B0BD7eyrCI6dnUNM3mCAvgmu0sRD7oh8xQurobV531/PBI2pP/AjGk8exFQnAqth7bTm B4MawtEVFY1e3h7bIM28ELKTcnp6G/ElghSHh/ZsC3H0i316rKNTuMbgnS0PGsqMYlTE yU4Q1Fo/HWPKgwPyFotw/E+/L/pb/VHJYhr6JUlv/tRXV2OcxvrbrNiDbUCDvJRwcf8c +G3Sbc+r1+Nkir775dnPonXqMj4l/xwwAhzmgHS0QzTfhT9/6Ns7ig75ujhhdzr/kB0r 4byA== 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=YhQXz6yZHHf9ZIVCJk9miX5vn9X4sW3OzNacg7VdL9k=; b=22GisuU5YB49mTvC2US8G6hbZHDZKiXbErNtZ4DYfnzAelTK4o3ezon6TckzmzbhAE Qvng6JdbFSmVDScgj7oLQyf0ZX9cKvoYTBFDXWHAbWbtn6fAWC75jk4s35B7GP2sVO9H kEoKddIm0pQKlbfHhrlKh8t8pA1+I2erXKTp1jG73f+7KjHBFWPFAGiSFJMpiO8IurX1 yJYWESrhT60HH3dkc78YxMTEJy/cAz/gqTht2icaf/K8EueI8NaokwzK0oj6u8/832m0 Biu0xb6b2m8wp+sxUcffhBhc1212eVUH3V0i4Zx5+RcyTS+BWABjAslWgzqLOTp7bEoC Z1Fg== X-Gm-Message-State: AOAM530DJww2k9bnnTTtDhJ+yPEIy4ZW+MWQglonF0b/zOp3R6/TvXVM Wgs3F668zrBmf3byDzwhiL5APYuCQsxfiTy9 X-Received: by 2002:ab0:44e:: with SMTP id 72mr4080176uav.121.1638925670508; Tue, 07 Dec 2021 17:07:50 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:49 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:34 -0300 Message-Id: <20211208010649.381-19-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 179/279] lavc: switch to the 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: WJkuMMG0uStT From: Vittorio Giovara Since the request_channel_layout is used only by a handful of codecs, move the option to codec private contexts. Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/avcodec.c | 80 ++++++++++++++++++++++++++++++---- libavcodec/avcodec.h | 23 +++++++++- libavcodec/codec.h | 11 +++++ libavcodec/codec_par.c | 52 +++++++++++++++++----- libavcodec/decode.c | 89 ++++++++++++++++++++++++++++---------- libavcodec/encode.c | 36 ++++++++++++--- libavcodec/options_table.h | 3 ++ libavcodec/pthread_frame.c | 10 ++++- libavcodec/utils.c | 12 ++++- libavformat/demux.c | 2 +- 10 files changed, 263 insertions(+), 55 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c00a9b2af8..4c576a848c 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -119,7 +119,7 @@ static int64_t get_bit_rate(AVCodecContext *ctx) case AVMEDIA_TYPE_AUDIO: bits_per_sample = av_get_bits_per_sample(ctx->codec_id); if (bits_per_sample) { - bit_rate = ctx->sample_rate * (int64_t)ctx->channels; + bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels; if (bit_rate > INT64_MAX / bits_per_sample) { bit_rate = 0; } else @@ -137,6 +137,8 @@ static int64_t get_bit_rate(AVCodecContext *ctx) int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options) { int ret = 0; + int orig_channels; + uint64_t orig_channel_layout; AVCodecInternal *avci; if (avcodec_is_open(avctx)) @@ -247,12 +249,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code } } - if (avctx->channels > FF_SANE_NB_CHANNELS || avctx->channels < 0) { - av_log(avctx, AV_LOG_ERROR, "Too many or invalid channels: %d\n", avctx->channels); - ret = AVERROR(EINVAL); - goto free_and_end; - } - if (avctx->sample_rate < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate); ret = AVERROR(EINVAL); @@ -264,6 +260,38 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code goto free_and_end; } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + /* compat wrapper for old-style callers */ + if (avctx->channel_layout && !avctx->channels) + avctx->channels = av_popcount64(avctx->channel_layout); + + if ((avctx->channels && avctx->channels != avctx->ch_layout.nb_channels) || + (avctx->channel_layout && avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE)) { + if (avctx->channel_layout) { + av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout); + } else { + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = avctx->channels; + } + } + + /* temporary compat wrapper for new-style callers and old-style codecs; + * to be removed once all the codecs have been converted */ + if (avctx->ch_layout.nb_channels) { + avctx->channels = avctx->ch_layout.nb_channels; + avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + avctx->ch_layout.u.mask : 0; + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) { + av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels); + ret = AVERROR(EINVAL); + goto free_and_end; + } + avctx->frame_number = 0; avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id); @@ -317,6 +345,13 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) avctx->thread_count = 1; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + orig_channels = avctx->channels; + orig_channel_layout = avctx->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (!(avctx->active_thread_type & FF_THREAD_FRAME) || avci->frame_thread_encoder) { if (avctx->codec->init) { @@ -334,6 +369,26 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (av_codec_is_decoder(avctx->codec)) { if (!avctx->bit_rate) avctx->bit_rate = get_bit_rate(avctx); + +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + /* decoder setting the old-style fields */ + if (avctx->channels != orig_channels || + avctx->channel_layout != orig_channel_layout) { + av_channel_layout_uninit(&avctx->ch_layout); + if (avctx->channel_layout) { + av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout); + } else { + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = avctx->channels; + } + } + + /* update the deprecated fields for old-style callers */ + avctx->channels = avctx->ch_layout.nb_channels; + avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + avctx->ch_layout.u.mask : 0; + /* validate channel layout from the decoder */ if (avctx->channel_layout) { int channels = av_get_channel_layout_nb_channels(avctx->channel_layout); @@ -358,6 +413,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ret = AVERROR(EINVAL); goto free_and_end; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif #if FF_API_AVCTX_TIMEBASE if (avctx->framerate.num > 0 && avctx->framerate.den > 0) @@ -487,6 +544,8 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_freep(&avctx->internal); } + av_channel_layout_uninit(&avctx->ch_layout); + for (i = 0; i < avctx->nb_coded_side_data; i++) av_freep(&avctx->coded_side_data[i].data); av_freep(&avctx->coded_side_data); @@ -666,7 +725,12 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) if (enc->sample_rate) { av_bprintf(&bprint, "%d Hz, ", enc->sample_rate); } - av_bprint_channel_layout(&bprint, enc->channels, enc->channel_layout); + { + char buf[512]; + int ret = av_channel_layout_describe(&enc->ch_layout, buf, sizeof(buf)); + if (ret >= 0) + av_bprintf(&bprint, "%s", buf); + } if (enc->sample_fmt != AV_SAMPLE_FMT_NONE && (str = av_get_sample_fmt_name(enc->sample_fmt))) { av_bprintf(&bprint, ", %s", str); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 7ee8bc2b7c..fadcd120cc 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -990,7 +990,14 @@ typedef struct AVCodecContext { /* audio only */ int sample_rate; ///< samples per second - int channels; ///< number of audio channels +#if FF_API_OLD_CHANNEL_LAYOUT + /** + * number of audio channels + * @deprecated use ch_layout.nb_channels + */ + attribute_deprecated + int channels; +#endif /** * audio sample format @@ -1035,19 +1042,25 @@ typedef struct AVCodecContext { */ int cutoff; +#if FF_API_OLD_CHANNEL_LAYOUT /** * Audio channel layout. * - encoding: set by user. * - decoding: set by user, may be overwritten by libavcodec. + * @deprecated use ch_layout */ + attribute_deprecated uint64_t channel_layout; /** * Request decoder to use this channel layout if it can (0 for default) * - encoding: unused * - decoding: Set by user. + * @deprecated use "downmix" codec private option */ + attribute_deprecated uint64_t request_channel_layout; +#endif /** * Type of service that the audio stream conveys. @@ -2024,6 +2037,14 @@ typedef struct AVCodecContext { * - decoding: unused */ int (*get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int flags); + + /** + * Audio channel layout. + * - encoding: must be set by the caller, to one of AVCodec.ch_layouts. + * - decoding: may be set by the caller if known e.g. from the container. + * The decoder can then override during decoding as needed. + */ + AVChannelLayout ch_layout; } AVCodecContext; struct MpegEncContext; diff --git a/libavcodec/codec.h b/libavcodec/codec.h index a8147ec21f..204a558798 100644 --- a/libavcodec/codec.h +++ b/libavcodec/codec.h @@ -224,7 +224,13 @@ typedef struct AVCodec { const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1 const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0 const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1 +#if FF_API_OLD_CHANNEL_LAYOUT + /** + * @deprecated use ch_layouts instead + */ + attribute_deprecated const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0 +#endif const AVClass *priv_class; ///< AVClass for the private context const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} @@ -240,6 +246,11 @@ typedef struct AVCodec { */ const char *wrapper_name; + /** + * Array of supported channel layouts, terminated with a zeroed layout. + */ + const AVChannelLayout *ch_layouts; + /***************************************************************** * No fields below this line are part of the public API. They * may not be used outside of libavcodec and can be changed and diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index 9d43af1db4..052c64a315 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -125,11 +125,25 @@ int avcodec_parameters_from_context(AVCodecParameters *par, break; case AVMEDIA_TYPE_AUDIO: par->format = codec->sample_fmt; - if (codec->channel_layout) - av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout); - else { - par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - par->ch_layout.nb_channels = codec->channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + // if the old/new fields are set inconsistently, prefer the old ones + if ((codec->channels && codec->channels != codec->ch_layout.nb_channels) || + (codec->channel_layout && (codec->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + codec->ch_layout.u.mask != codec->channel_layout))) { + if (codec->channel_layout) + av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout); + else { + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = codec->channels; + } +FF_ENABLE_DEPRECATION_WARNINGS + } else +#endif + if (codec->ch_layout.nb_channels) { + int ret = av_channel_layout_copy(&par->ch_layout, &codec->ch_layout); + if (ret < 0) + return ret; } #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS @@ -191,18 +205,32 @@ int avcodec_parameters_to_context(AVCodecContext *codec, break; case AVMEDIA_TYPE_AUDIO: codec->sample_fmt = par->format; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + // if the old/new fields are set inconsistently, prefer the old ones + if ((par->channels && par->channels != par->ch_layout.nb_channels) || + (par->channel_layout && (par->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + par->ch_layout.u.mask != par->channel_layout))) { + if (par->channel_layout) + av_channel_layout_from_mask(&codec->ch_layout, par->channel_layout); + else { + codec->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + codec->ch_layout.nb_channels = par->channels; + } +FF_ENABLE_DEPRECATION_WARNINGS + } else +#endif if (par->ch_layout.nb_channels) { - codec->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - par->ch_layout.u.mask : 0; - codec->channels = par->ch_layout.nb_channels; + int ret = av_channel_layout_copy(&codec->ch_layout, &par->ch_layout); + if (ret < 0) + return ret; } #if FF_API_OLD_CHANNEL_LAYOUT - else { FF_DISABLE_DEPRECATION_WARNINGS - codec->channel_layout = par->channel_layout; - codec->channels = par->channels; + codec->channel_layout = codec->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + codec->ch_layout.u.mask : 0; + codec->channels = codec->ch_layout.nb_channels; FF_ENABLE_DEPRECATION_WARNINGS - } #endif codec->sample_rate = par->sample_rate; codec->block_align = par->block_align; diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 01fea93c04..aa74c677ef 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -359,10 +359,14 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, if (ret >= 0 && got_frame) { if (frame->format == AV_SAMPLE_FMT_NONE) frame->format = avctx->sample_fmt; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS if (!frame->channel_layout) frame->channel_layout = avctx->channel_layout; if (!frame->channels) frame->channels = avctx->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (!frame->sample_rate) frame->sample_rate = avctx->sample_rate; } @@ -394,7 +398,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, avci->skip_samples); } else { av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples, - frame->nb_samples - avci->skip_samples, avctx->channels, frame->format); + frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format); if(avctx->pkt_timebase.num && avctx->sample_rate) { int64_t diff_ts = av_rescale_q(avci->skip_samples, (AVRational){1, avctx->sample_rate}, @@ -683,8 +687,12 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr case AVMEDIA_TYPE_AUDIO: avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate : avctx->sample_rate; - avci->initial_channels = frame->channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + avci->initial_channels = frame->ch_layout.nb_channels; avci->initial_channel_layout = frame->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif break; } } @@ -698,10 +706,15 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr avci->initial_height != frame->height; break; case AVMEDIA_TYPE_AUDIO: +FF_DISABLE_DEPRECATION_WARNINGS changed |= avci->initial_sample_rate != frame->sample_rate || avci->initial_sample_rate != avctx->sample_rate || +#if FF_API_OLD_CHANNEL_LAYOUT avci->initial_channels != frame->channels || - avci->initial_channel_layout != frame->channel_layout; + avci->initial_channel_layout != frame->channel_layout +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS break; } @@ -1260,7 +1273,13 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { int planar = av_sample_fmt_is_planar(frame->format); - ch = frame->channels; + ch = frame->ch_layout.nb_channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!ch) + ch = frame->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif planes = planar ? ch : 1; } @@ -1568,25 +1587,18 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) frame->sample_rate = avctx->sample_rate; if (frame->format < 0) frame->format = avctx->sample_fmt; - if (!frame->channel_layout) { - if (avctx->channel_layout) { - if (av_get_channel_layout_nb_channels(avctx->channel_layout) != - avctx->channels) { - av_log(avctx, AV_LOG_ERROR, "Inconsistent channel " - "configuration.\n"); - return AVERROR(EINVAL); - } - - frame->channel_layout = avctx->channel_layout; - } else { - if (avctx->channels > FF_SANE_NB_CHANNELS) { - av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n", - avctx->channels); - return AVERROR(ENOSYS); - } - } + if (!frame->ch_layout.nb_channels) { + int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); + if (ret < 0) + return ret; } - frame->channels = avctx->channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + frame->channels = frame->ch_layout.nb_channels; + frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + frame->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif break; } return 0; @@ -1676,7 +1688,36 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) goto fail; } } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { - if (frame->nb_samples * (int64_t)avctx->channels > avctx->max_samples) { +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + /* temporary compat layer for decoders setting the old-style channel + * layout fields; shall be removed after all the decoders are converted + * to the new API */ + if ((avctx->channels > 0 && avctx->ch_layout.nb_channels != avctx->channels) || + (avctx->channel_layout && (avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + avctx->ch_layout.u.mask != avctx->channel_layout))) { + av_channel_layout_uninit(&avctx->ch_layout); + if (avctx->channel_layout) { + if (av_popcount64(avctx->channel_layout) != avctx->channels) { + av_log(avctx, AV_LOG_ERROR, "Inconsistent channel layout/channels\n"); + ret = AVERROR(EINVAL); + goto fail; + } + av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout); + } else { + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = avctx->channels; + } + } + + /* compat layer for old-style get_buffer() implementations */ + avctx->channels = avctx->ch_layout.nb_channels; + avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ? + avctx->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) { av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples); ret = AVERROR(EINVAL); goto fail; @@ -1786,7 +1827,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif - if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->channels == 0 && + if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->ch_layout.nb_channels == 0 && !(avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) { av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n"); return AVERROR(EINVAL); diff --git a/libavcodec/encode.c b/libavcodec/encode.c index dd25cf999b..0dd5e3fdd1 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -114,9 +114,10 @@ static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src) int ret; frame->format = src->format; - frame->channel_layout = src->channel_layout; - frame->channels = src->channels; frame->nb_samples = s->frame_size; + ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout); + if (ret < 0) + goto fail; ret = av_frame_get_buffer(frame, 0); if (ret < 0) goto fail; @@ -126,11 +127,12 @@ static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src) goto fail; if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0, - src->nb_samples, s->channels, s->sample_fmt)) < 0) + src->nb_samples, s->ch_layout.nb_channels, + s->sample_fmt)) < 0) goto fail; if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples, frame->nb_samples - src->nb_samples, - s->channels, s->sample_fmt)) < 0) + s->ch_layout.nb_channels, s->sample_fmt)) < 0) goto fail; return 0; @@ -420,7 +422,7 @@ int ff_encode_preinit(AVCodecContext *avctx) for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) { if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) break; - if (avctx->channels == 1 && + if (avctx->ch_layout.nb_channels == 1 && av_get_planar_sample_fmt(avctx->sample_fmt) == av_get_planar_sample_fmt(avctx->codec->sample_fmts[i])) { avctx->sample_fmt = avctx->codec->sample_fmts[i]; @@ -468,7 +470,27 @@ int ff_encode_preinit(AVCodecContext *avctx) avctx->sample_rate); return AVERROR(EINVAL); } - if (avctx->codec->channel_layouts) { + if (avctx->codec->ch_layouts) { + if (!av_channel_layout_check(&avctx->ch_layout)) { + av_log(avctx, AV_LOG_WARNING, "Channel layout not specified correctly\n"); + return AVERROR(EINVAL); + } + + for (i = 0; avctx->codec->ch_layouts[i].nb_channels; i++) { + if (!av_channel_layout_compare(&avctx->ch_layout, &avctx->codec->ch_layouts[i])) + break; + } + if (!avctx->codec->ch_layouts[i].nb_channels) { + char buf[512]; + int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); + if (ret > 0) + av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf); + return AVERROR(EINVAL); + } +FF_DISABLE_DEPRECATION_WARNINGS + } +#if FF_API_OLD_CHANNEL_LAYOUT + else if (avctx->codec->channel_layouts) { if (!avctx->channel_layout) { av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n"); } else { @@ -501,6 +523,8 @@ int ff_encode_preinit(AVCodecContext *avctx) avctx->channels); return AVERROR(EINVAL); } +FF_ENABLE_DEPRECATION_WARNINGS +#endif if(avctx->codec_type == AVMEDIA_TYPE_VIDEO) { const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); if ( avctx->bits_per_raw_sample < 0 diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 130341a2ec..c093b626d4 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -262,8 +262,11 @@ static const AVOption avcodec_options[] = { {"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.i64 = 256 }, 0, INT_MAX, V|E}, {"compression_level", NULL, OFFSET(compression_level), AV_OPT_TYPE_INT, {.i64 = FF_COMPRESSION_DEFAULT }, INT_MIN, INT_MAX, V|A|E}, {"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX}, +{"ch_layout", NULL, OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL }, 0, 0, A|E|D, "ch_layout"}, +#if FF_API_OLD_CHANNEL_LAYOUT {"channel_layout", NULL, OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64 = DEFAULT }, 0, UINT64_MAX, A|E|D, "channel_layout"}, {"request_channel_layout", NULL, OFFSET(request_channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64 = DEFAULT }, 0, UINT64_MAX, A|D, "request_channel_layout"}, +#endif {"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0.0, FLT_MAX, V|E}, {"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), AV_OPT_TYPE_FLOAT, {.dbl = 3 }, 0.0, FLT_MAX, V|E}, {"ticks_per_frame", NULL, OFFSET(ticks_per_frame), AV_OPT_TYPE_INT, {.i64 = 1 }, 1, INT_MAX, A|V|E|D}, diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 73b1b7d7d9..e71f0860a7 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -297,10 +297,18 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src, dst->hwaccel = src->hwaccel; dst->hwaccel_context = src->hwaccel_context; - dst->channels = src->channels; dst->sample_rate = src->sample_rate; dst->sample_fmt = src->sample_fmt; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + dst->channels = src->channels; dst->channel_layout = src->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + err = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout); + if (err < 0) + return err; + dst->internal->hwaccel_priv_data = src->internal->hwaccel_priv_data; if (!!dst->hw_frames_ctx != !!src->hw_frames_ctx || diff --git a/libavcodec/utils.c b/libavcodec/utils.c index dc5156210f..729e19005b 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -816,8 +816,16 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) { - int duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate, - avctx->channels, avctx->block_align, + int channels = avctx->ch_layout.nb_channels; + int duration; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) + channels = avctx->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate, + channels, avctx->block_align, avctx->codec_tag, avctx->bits_per_coded_sample, avctx->bit_rate, avctx->extradata, avctx->frame_size, frame_bytes); diff --git a/libavformat/demux.c b/libavformat/demux.c index a9670aeb34..8227d10ff1 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1951,7 +1951,7 @@ static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr) FAIL("unspecified sample format"); if (!avctx->sample_rate) FAIL("unspecified sample rate"); - if (!avctx->channels) + if (!avctx->ch_layout.nb_channels) FAIL("unspecified number of channels"); if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) FAIL("no decodable DTS frames"); From patchwork Wed Dec 8 01:06:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32134 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7046215iog; Tue, 7 Dec 2021 17:11:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9ThxnU9iYwf4aoMTc+pqchB5Kml8KnBwJV6j2zA31aEk/LRWX/Uqo0gXB4YE8W7ESWbP8 X-Received: by 2002:a05:6402:440f:: with SMTP id y15mr14804655eda.22.1638925862446; Tue, 07 Dec 2021 17:11:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925862; cv=none; d=google.com; s=arc-20160816; b=lwxWDCq3+j7YcK/Mx5S389aq+uNpp5GKrZyVl7+tR+YIplvOQkkEImXtIhyOznDeTa iqHqe1KCF6KkuBhfCj8FVX7FEOUGlLrrOGo0wUgbo+QXgeiNvN5kBoe4SR/rr8ihqqjl hKpEzaMpnfIZn97+JhNG7o4GTkc7e6WcL3x9x9R2vuDarj1v7pzRqstJM1ieA9azUadb 4DW+m8Z5XgKX3jVWdAgepZoaTg4pp/b0PCOrE1EHOb94j3mJj2f8DO8FxUJ/V2ob4PWf 704guKxTjPRKMq0EGqIgLYkwJhQ4juUpVBtAzLwINSVknCoHrtF2WW3P4ey0PCfJU/JM uKdg== 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=i5eHeA3UVuK26smM4x+c/OkzaKMyYwT4D2TJIk4YW+s=; b=N0HyF9Y6aqO0OdMb3uNHt2+Rwelwin363S1GAbr33JFvxBIEYbqb0Rd+ky+bMrqCmR vRTMg6qe9aWHEBqJjtEASuF3UUiSEBxPuQC/yytk/3PQMdQT4nw18YFAVSc2+UKOfoyz vmVRwqo1aE5oTMEWhptEGWxYGeMV6wsw9FP3pFPnl6g6dt61cMVPnKeMR06+d0Okd/17 EhSn88KdYcJ0I7ihgjjgDsDJ7NOOmTcREfz2E8bWQNsWVkipw8G+cUPRfMyaMnC/oGYU e1mkHCVyiebjYuXCtwDf36uiMMWUSyKBqVq3sWyhhpk572jsELhYoKk5jub3Vf8B6N2X DQhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=h2Ne6pKc; 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 hd37si2081826ejc.349.2021.12.07.17.11.02; Tue, 07 Dec 2021 17:11:02 -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=h2Ne6pKc; 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 61B0E68AEA3; Wed, 8 Dec 2021 03:08:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2685968AF21 for ; Wed, 8 Dec 2021 03:07:53 +0200 (EET) Received: by mail-ua1-f53.google.com with SMTP id a14so2032362uak.0 for ; Tue, 07 Dec 2021 17:07:53 -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=2f5ZezIXZiTo3YVZLHysET0XIgDsctgDpAHf2Y4U/w8=; b=h2Ne6pKcM6B2OnEBtfCZerq+SV23I5kVue70Z06uVqdaQpjnN4BreIdUGx2rkFZ1XV DPaTQmHTRYZKyocKfy6LrMHANaBWkGolwapRgd4SxVTWHDgcsUj2+Cg8R+EsJh89dkXF yRPTk3rfS5Trt+EOQZQ0THZU2tnhxMzGzdxFAYE+BgY7WJsfhpspD6sTv51Dm73QG6Io Wl3Irar7Vbvwv7BVQhR0UiR3NGKevu+CFtJRaVsjhtsYp8hDDkQVnz4h1OHcVbfAXs6g RAK0eLlQMBUCUg24f+yUrkEH8tbG/nbPGEVuYiIMz1ndX7xlgnLqwRvJdGtqzuh/zc11 gyZQ== 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=2f5ZezIXZiTo3YVZLHysET0XIgDsctgDpAHf2Y4U/w8=; b=094PocHLozinBJUgJSioxj7PYGFyP2Wgy4m6byx8j95RdrunwpmltlUIsiqfuYMdE0 asMTm1gYncdDRIgwh6aIk82D1ni+dYzHX1MipL4MLL19+31K6L49AIsYaEs5Q4qW/JgJ Gttd975lnaz5x6p5/C8C4yRyIaUsu+qy2NeKX+Ac63Z45o2UEnu1Y4VH4aWw8c5ZVWuB rbkT7SEmE1Lwk95BTdcPkNaesKQCEi6f/dLyqUNYbyPcrCFTR4k4jxWBaPg2COxYvMNp kix79ekvK2woXhtVLW7y1SXQVm3LowZekwZL6qNq7vUD4R6Zpz647sczUuZzeFytE5oT EYew== X-Gm-Message-State: AOAM532HvLpPFw2FoOKEGX8aB43hqkBv1buBq3JBc1ayZvPKNn7Zy5qO TE3GcAeLFg4IiV0QYBrXR2Z1jIylflmQindc X-Received: by 2002:ab0:20d4:: with SMTP id z20mr4184992ual.23.1638925671702; Tue, 07 Dec 2021 17:07:51 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:51 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:35 -0300 Message-Id: <20211208010649.381-20-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 180/279] 8svx: 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: IBDFi0J6+/nw From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/8svx.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c index 6ef8cd73fe..6ef7921274 100644 --- a/libavcodec/8svx.c +++ b/libavcodec/8svx.c @@ -88,38 +88,39 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, { EightSvxContext *esc = avctx->priv_data; AVFrame *frame = data; + int channels = avctx->ch_layout.nb_channels; int buf_size; int ch, ret; int hdr_size = 2; /* decode and interleave the first packet */ if (!esc->data[0] && avpkt) { - int chan_size = avpkt->size / avctx->channels - hdr_size; + int chan_size = avpkt->size / channels - hdr_size; - if (avpkt->size % avctx->channels) { + if (avpkt->size % channels) { av_log(avctx, AV_LOG_WARNING, "Packet with odd size, ignoring last byte\n"); } - if (avpkt->size < (hdr_size + 1) * avctx->channels) { + if (avpkt->size < (hdr_size + 1) * channels) { av_log(avctx, AV_LOG_ERROR, "packet size is too small\n"); return AVERROR_INVALIDDATA; } esc->fib_acc[0] = avpkt->data[1] + 128; - if (avctx->channels == 2) + if (channels == 2) esc->fib_acc[1] = avpkt->data[2+chan_size+1] + 128; esc->data_idx = 0; esc->data_size = chan_size; if (!(esc->data[0] = av_malloc(chan_size))) return AVERROR(ENOMEM); - if (avctx->channels == 2) { + if (channels == 2) { if (!(esc->data[1] = av_malloc(chan_size))) { av_freep(&esc->data[0]); return AVERROR(ENOMEM); } } memcpy(esc->data[0], &avpkt->data[hdr_size], chan_size); - if (avctx->channels == 2) + if (channels == 2) memcpy(esc->data[1], &avpkt->data[2*hdr_size+chan_size], chan_size); } if (!esc->data[0]) { @@ -139,7 +140,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - for (ch = 0; ch < avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx], buf_size, &esc->fib_acc[ch], esc->table); } @@ -148,14 +149,14 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, *got_frame_ptr = 1; - return ((avctx->frame_number == 0)*hdr_size + buf_size)*avctx->channels; + return ((avctx->frame_number == 0) * hdr_size + buf_size) * channels; } static av_cold int eightsvx_decode_init(AVCodecContext *avctx) { EightSvxContext *esc = avctx->priv_data; - if (avctx->channels < 1 || avctx->channels > 2) { + if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) { av_log(avctx, AV_LOG_ERROR, "8SVX does not support more than 2 channels\n"); return AVERROR_INVALIDDATA; } From patchwork Wed Dec 8 01:06:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32136 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7046356iog; Tue, 7 Dec 2021 17:11:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCCUtkEPUxsu7uS6EpaczkTifFgvRtl8bZlWX73iNi6XJMGpmQf5LA18jWVsv1jbrzrbTG X-Received: by 2002:a17:907:e86:: with SMTP id ho6mr3358859ejc.197.1638925872554; Tue, 07 Dec 2021 17:11:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925872; cv=none; d=google.com; s=arc-20160816; b=bATpF6SurX2Hjib6Ea0N5EuUghIZldhqpWUtzYfsDxWDjqa8/zjxKYNDqeKSDi/e5r mrxhtm9vS2Ef2budK0Mrp2+5hiciXJ+Bi5bJNiJqqa+IA9DA9UJK8uf5luDjn+kDZF9C Eo3uIkZMbFq8HG5iPOMN0B1Rj1zAmMnD+1OrUn7H8UMH3CmeCNxZ315S/rbUbDCo+uFI OBSqlBUZpZIlIaAUPL63YEd7bkGga8Fot4kb04JIjh++DUP2TA2Jqor8Cdq9qJyc37Aj OBSHmevBTcvN2jfJ7pxsDrGUVEyyRdLQlq/lOuL19ZiXJIn/GSwUzyC+ylTWCRCicD6+ USNQ== 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=nsK+oR38f1ZddZlyzUBuNHKlEP2hECbNg7w3a7FkNco=; b=gm/KPs6FriazTPSLluh6MUcEkHxCqmOOKSduyU0ynDk1u2Ih6/MGnM1H1IFc78Nf2n bS+fysLFR7NvOSuD19YNmuDx0sA8S6lbJLu2AEPP9j5OaNNgFieC80BKIvBzDePgJ7V1 QqLZ2p97ElXfSyZJGLas4G5oPmZIsFwHQWoig2bj2MaHTOI1GS6yrSYp1fW3Z4k7hPFu 4N8ySS5t2BIs9RRV4ETjSu3MlX00bA0hVjK5JwXSQsRkNZoYUhkv7NPkwYsE0uq194eF WZl0F0npmsams9yEeJ4AwGBaJUL8yBzbdmLUlsc4IOtduPFk+ZFomawOHn8Fvry/OY2b 6XWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nvd76gmP; 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 i25si1901052eds.454.2021.12.07.17.11.12; Tue, 07 Dec 2021 17:11:12 -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=nvd76gmP; 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 229C968AF3A; Wed, 8 Dec 2021 03:08:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4EE3C68AEA3 for ; Wed, 8 Dec 2021 03:07:55 +0200 (EET) Received: by mail-ua1-f54.google.com with SMTP id l24so1953685uak.2 for ; Tue, 07 Dec 2021 17:07:54 -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=KnYCt+TqYQ4TYxy2BYjYhVzDwoUmrNUmuW4N7+J+Og0=; b=nvd76gmPl2JnV2S+FusDK6KJCPurMvTXC2+QCqwstl+HyZDg6u2UB5Or4hTWBQ+t+0 txuhLIXwYEZZ20vZSU/3lAzXQUh55FoOkq57sK0soIV1//h8f+TNOMK0aAztANyYnaHF 3qJnWgfYWNpS7EeWcEYHq5rX4vaLB7T1rlodKbSuWa3mnKYOoA0zdv5JT1qMqXeMvHYA TixZyp5cnzpN6gQPxhEmTuSgbhfa+gdh0RoPGzwHffF1DEtUH1GFclJR36YO+M/jD+nW Zw1lZWH14LmAaWHr4bAG5WD5gO1XvSM0+qsGmzv3a9DpauFXbln4BUlHrLGaxCZvSi3o uijA== 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=KnYCt+TqYQ4TYxy2BYjYhVzDwoUmrNUmuW4N7+J+Og0=; b=ezO8VqDlpOFpqzHknc7AZFBGWnAu/1AaebhhqGJG+xFZKCTr/PNakkYShlo6LJ3Exn V+YoTg9zxZNIhxmec+SmrYBMYebjMCD8plCq/fjr2AhFF+O5RjsBsFNb3+wAxvjO6w2K 469tV+4ZL7i6KyqnJorNdJP+5TWb/JW3zNE5En9GCxuWhDk9uX9Rdv6/D1Vzb0VJ6Zfj GM/cW0Rn0u7BR7DRsuFI+ankzCPqKW+CwH7Goe8nX2PclG4tI+bn3vWziXenIrLpCQRV PWgzyAx9Wo3a2b8J0iNDZ8XASr0+Ba/CcwNvhOpXrs7kOlGSM34+/PwvEQvfXaNGtI8G dRxg== X-Gm-Message-State: AOAM533IBv07JXu+1WUkMxzeuyruWINSc38cSpEiIVurT0wOd9ezLDx0 6sGSmBjrRMhUhzyfPyAR5eZ7HNkgXqg8xLEw X-Received: by 2002:ab0:67d7:: with SMTP id w23mr4146932uar.3.1638925673007; Tue, 07 Dec 2021 17:07:53 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:52 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:36 -0300 Message-Id: <20211208010649.381-21-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 181/279] aac: 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: 6EntrkR7OAys From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/aac.h | 11 ++++-- libavcodec/aac_ac3_parser.c | 9 +++-- libavcodec/aaccoder.c | 10 +++--- libavcodec/aaccoder_twoloop.h | 4 +-- libavcodec/aacdec_template.c | 59 ++++++++++++++++++++++++-------- libavcodec/aacenc.c | 13 ++++--- libavcodec/aacenc.h | 64 ++++++++++++++++++----------------- libavcodec/aacenctab.h | 16 ++++----- libavcodec/aacpsy.c | 8 ++--- libavcodec/psymodel.c | 8 ++--- libavcodec/psymodel.h | 2 +- 11 files changed, 125 insertions(+), 79 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index 1e82f56ca9..53be546857 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -32,6 +32,7 @@ #include "aac_defines.h" +#include "libavutil/channel_layout.h" #include "libavutil/float_dsp.h" #include "libavutil/fixed_dsp.h" #include "libavutil/mem_internal.h" @@ -125,8 +126,7 @@ typedef struct OutputConfiguration { MPEG4AudioConfig m4ac; uint8_t layout_map[MAX_ELEM_ID*4][3]; int layout_map_tags; - int channels; - uint64_t channel_layout; + AVChannelLayout ch_layout; enum OCStatus status; } OutputConfiguration; @@ -288,6 +288,11 @@ typedef struct ChannelElement { SpectralBandReplication sbr; } ChannelElement; +enum AACOutputChannelOrder { + CHANNEL_ORDER_DEFAULT, + CHANNEL_ORDER_CODED, +}; + /** * main AAC context */ @@ -352,6 +357,8 @@ struct AACContext { int dmono_mode; ///< 0->not dmono, 1->use first channel, 2->use second channel /** @} */ + enum AACOutputChannelOrder output_channel_order; + DECLARE_ALIGNED(32, INTFLOAT, temp)[128]; OutputConfiguration oc[2]; diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c index e84d30aea2..cd54a0a3e2 100644 --- a/libavcodec/aac_ac3_parser.c +++ b/libavcodec/aac_ac3_parser.c @@ -90,8 +90,13 @@ get_next: if (avctx->codec_id != AV_CODEC_ID_AAC) { avctx->sample_rate = s->sample_rate; if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) { - avctx->channels = s->channels; - avctx->channel_layout = s->channel_layout; + av_channel_layout_uninit(&avctx->ch_layout); + if (s->channel_layout) { + av_channel_layout_from_mask(&avctx->ch_layout, s->channel_layout); + } else { + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = s->channels; + } } s1->duration = s->samples; avctx->audio_service_type = s->service_type; diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index 7bbd4d5b2e..f460479498 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -397,7 +397,7 @@ static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, const float lambda) { int start = 0, i, w, w2, g; - int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels * (lambda / 120.f); + int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->ch_layout.nb_channels * (lambda / 120.f); float dists[128] = { 0 }, uplims[128] = { 0 }; float maxvals[128]; int fflag, minscaler; @@ -556,7 +556,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f); int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate - / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels) + / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels) * (lambda / 120.f); /** Keep this in sync with twoloop's cutoff selection */ @@ -564,7 +564,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne int prev = -1000, prev_sf = -1; int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE) ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024) - : (avctx->bit_rate / avctx->channels); + : (avctx->bit_rate / avctx->ch_layout.nb_channels); frame_bit_rate *= 1.15f; @@ -693,14 +693,14 @@ static void mark_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelEleme const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f); int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate - / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels) + / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels) * (lambda / 120.f); /** Keep this in sync with twoloop's cutoff selection */ float rate_bandwidth_multiplier = 1.5f; int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE) ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024) - : (avctx->bit_rate / avctx->channels); + : (avctx->bit_rate / avctx->ch_layout.nb_channels); frame_bit_rate *= 1.15f; diff --git a/libavcodec/aaccoder_twoloop.h b/libavcodec/aaccoder_twoloop.h index 8e1bc88a85..0504a916ad 100644 --- a/libavcodec/aaccoder_twoloop.h +++ b/libavcodec/aaccoder_twoloop.h @@ -71,7 +71,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, { int start = 0, i, w, w2, g, recomprd; int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate - / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels) + / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels) * (lambda / 120.f); int refbits = destbits; int toomanybits, toofewbits; @@ -186,7 +186,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, float rate_bandwidth_multiplier = 1.5f; int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE) ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024) - : (avctx->bit_rate / avctx->channels); + : (avctx->bit_rate / avctx->ch_layout.nb_channels); /** Compensate for extensions that increase efficiency */ if (s->options.pns || s->options.intensity_stereo) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 7149b331ae..387a4acfce 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -174,7 +174,7 @@ static int frame_configure_elements(AVCodecContext *avctx) /* get output buffer */ av_frame_unref(ac->frame); - if (!avctx->channels) + if (!avctx->ch_layout.nb_channels) return 1; ac->frame->nb_samples = 2048; @@ -182,7 +182,7 @@ static int frame_configure_elements(AVCodecContext *avctx) return ret; /* map output channel pointers to AVFrame data */ - for (ch = 0; ch < avctx->channels; ch++) { + for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { if (ac->output_element[ch]) ac->output_element[ch]->ret = (INTFLOAT *)ac->frame->extended_data[ch]; } @@ -517,8 +517,7 @@ static int push_output_configuration(AACContext *ac) { static void pop_output_configuration(AACContext *ac) { if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) { ac->oc[1] = ac->oc[0]; - ac->avctx->channels = ac->oc[1].channels; - ac->avctx->channel_layout = ac->oc[1].channel_layout; + ac->avctx->ch_layout = ac->oc[1].ch_layout; output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, ac->oc[1].status, 0); } @@ -555,7 +554,14 @@ static int output_configure(AACContext *ac, } // Try to sniff a reasonable channel order, otherwise output the // channels in the order the PCE declared them. - if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channel_layout == AV_CH_LAYOUT_NATIVE) + ac->output_channel_order = CHANNEL_ORDER_CODED; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + if (ac->output_channel_order == CHANNEL_ORDER_DEFAULT) layout = sniff_channel_order(layout_map, tags); for (i = 0; i < tags; i++) { int type = layout_map[i][0]; @@ -577,9 +583,22 @@ static int output_configure(AACContext *ac, } } - if (layout) avctx->channel_layout = layout; - ac->oc[1].channel_layout = layout; - avctx->channels = ac->oc[1].channels = channels; + av_channel_layout_uninit(&ac->oc[1].ch_layout); + if (layout) + av_channel_layout_from_mask(&ac->oc[1].ch_layout, layout); + else { + ac->oc[1].ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + ac->oc[1].ch_layout.nb_channels = channels; + } + + av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + avctx->channels = avctx->ch_layout.nb_channels; + avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + avctx->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif ac->oc[1].status = oc_type; if (get_new_frame) { @@ -1292,12 +1311,12 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) sr = sample_rate_idx(avctx->sample_rate); ac->oc[1].m4ac.sampling_index = sr; - ac->oc[1].m4ac.channels = avctx->channels; + ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels; ac->oc[1].m4ac.sbr = -1; ac->oc[1].m4ac.ps = -1; for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) - if (ff_mpeg4audio_channels[i] == avctx->channels) + if (ff_mpeg4audio_channels[i] == avctx->ch_layout.nb_channels) break; if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { i = 0; @@ -1315,7 +1334,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) } } - if (avctx->channels > MAX_CHANNELS) { + if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); return AVERROR_INVALIDDATA; } @@ -2556,7 +2575,8 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); skip_bits_long(gb, 8 * cnt - 4); return res; - } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED && ac->avctx->channels == 1) { + } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED && + ac->avctx->ch_layout.nb_channels == 1) { ac->oc[1].m4ac.sbr = 1; ac->oc[1].m4ac.ps = 1; ac->avctx->profile = FF_PROFILE_AAC_HE_V2; @@ -3264,7 +3284,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, if (avctx->debug & FF_DEBUG_STARTCODE) av_log(avctx, AV_LOG_DEBUG, "Elem type:%x id:%x\n", elem_type, elem_id); - if (!avctx->channels && elem_type != TYPE_PCE) { + if (!avctx->ch_layout.nb_channels && elem_type != TYPE_PCE) { err = AVERROR_INVALIDDATA; goto fail; } @@ -3385,7 +3405,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, } } - if (!avctx->channels) { + if (!avctx->ch_layout.nb_channels) { *got_frame_ptr = 0; return 0; } @@ -3419,7 +3439,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, /* for dual-mono audio (SCE + SCE) */ is_dmono = ac->dmono_mode && sce_count == 2 && - ac->oc[1].channel_layout == (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT); + !av_channel_layout_compare(&ac->oc[1].ch_layout, + &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); if (is_dmono) { if (ac->dmono_mode == 1) ((AVFrame *)data)->data[1] =((AVFrame *)data)->data[0]; @@ -3553,6 +3574,14 @@ static const AVOption options[] = { {"sub" , "Select Sub/Right channel", 0, AV_OPT_TYPE_CONST, {.i64= 2}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"}, {"both", "Select both channels", 0, AV_OPT_TYPE_CONST, {.i64= 0}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"}, + { "channel_order", "Order in which the channels are to be exported", + offsetof(AACContext, output_channel_order), AV_OPT_TYPE_INT, + { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, AACDEC_FLAGS, "channel_order" }, + { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST, + { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = AACDEC_FLAGS, "channel_order" }, + { "coded", "order in which the channels are coded in the bitstream", + 0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = AACDEC_FLAGS, "channel_order" }, + {NULL}, }; diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index e462566078..8b9d7009a7 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -962,11 +962,11 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120; /* Channel map and unspecified bitrate guessing */ - s->channels = avctx->channels; + s->channels = avctx->ch_layout.nb_channels; s->needs_pce = 1; for (i = 0; i < FF_ARRAY_ELEMS(aac_normal_chan_layouts); i++) { - if (avctx->channel_layout == aac_normal_chan_layouts[i]) { + if (!av_channel_layout_compare(&avctx->ch_layout, &aac_normal_chan_layouts[i])) { s->needs_pce = s->options.pce; break; } @@ -975,10 +975,13 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) if (s->needs_pce) { char buf[64]; for (i = 0; i < FF_ARRAY_ELEMS(aac_pce_configs); i++) - if (avctx->channel_layout == aac_pce_configs[i].layout) + if (!av_channel_layout_compare(&avctx->ch_layout, &aac_pce_configs[i].layout)) break; - av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout); - ERROR_IF(i == FF_ARRAY_ELEMS(aac_pce_configs), "Unsupported channel layout \"%s\"\n", buf); + av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); + if (i == FF_ARRAY_ELEMS(aac_pce_configs)) { + av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout \"%s\"\n", buf); + return AVERROR(EINVAL); + } av_log(avctx, AV_LOG_INFO, "Using a PCE to encode channel layout \"%s\"\n", buf); s->pce = aac_pce_configs[i]; s->reorder_map = s->pce.reorder_map; diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h index b106910ce0..a001c7ca60 100644 --- a/libavcodec/aacenc.h +++ b/libavcodec/aacenc.h @@ -94,7 +94,7 @@ typedef struct AACQuantizeBandCostCacheEntry { } AACQuantizeBandCostCacheEntry; typedef struct AACPCEInfo { - int64_t layout; + AVChannelLayout layout; int num_ele[4]; ///< front, side, back, lfe int pairing[3][8]; ///< front, side, back int index[4][8]; ///< front, side, back, lfe @@ -139,7 +139,7 @@ typedef struct AACPCEInfo { */ static const AACPCEInfo aac_pce_configs[] = { { - .layout = AV_CH_LAYOUT_MONO, + .layout = AV_CHANNEL_LAYOUT_MONO, .num_ele = { 1, 0, 0, 0 }, .pairing = { { 0 }, }, .index = { { 0 }, }, @@ -147,7 +147,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0 }, }, { - .layout = AV_CH_LAYOUT_STEREO, + .layout = AV_CHANNEL_LAYOUT_STEREO, .num_ele = { 1, 0, 0, 0 }, .pairing = { { 1 }, }, .index = { { 0 }, }, @@ -155,7 +155,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1 }, }, { - .layout = AV_CH_LAYOUT_2POINT1, + .layout = AV_CHANNEL_LAYOUT_2POINT1, .num_ele = { 1, 0, 0, 1 }, .pairing = { { 1 }, }, .index = { { 0 },{ 0 },{ 0 },{ 0 } }, @@ -163,7 +163,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2 }, }, { - .layout = AV_CH_LAYOUT_2_1, + .layout = AV_CHANNEL_LAYOUT_2_1, .num_ele = { 1, 0, 1, 0 }, .pairing = { { 1 },{ 0 },{ 0 } }, .index = { { 0 },{ 0 },{ 0 }, }, @@ -171,7 +171,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2 }, }, { - .layout = AV_CH_LAYOUT_SURROUND, + .layout = AV_CHANNEL_LAYOUT_SURROUND, .num_ele = { 2, 0, 0, 0 }, .pairing = { { 1, 0 }, }, .index = { { 0, 0 }, }, @@ -179,7 +179,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2 }, }, { - .layout = AV_CH_LAYOUT_3POINT1, + .layout = AV_CHANNEL_LAYOUT_3POINT1, .num_ele = { 2, 0, 0, 1 }, .pairing = { { 1, 0 }, }, .index = { { 0, 0 }, { 0 }, { 0 }, { 0 }, }, @@ -187,7 +187,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3 }, }, { - .layout = AV_CH_LAYOUT_4POINT0, + .layout = AV_CHANNEL_LAYOUT_4POINT0, .num_ele = { 2, 0, 1, 0 }, .pairing = { { 1, 0 }, { 0 }, { 0 }, }, .index = { { 0, 0 }, { 0 }, { 1 } }, @@ -195,7 +195,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3 }, }, { - .layout = AV_CH_LAYOUT_4POINT1, + .layout = AV_CHANNEL_LAYOUT_4POINT1, .num_ele = { 2, 1, 1, 0 }, .pairing = { { 1, 0 }, { 0 }, { 0 }, }, .index = { { 0, 0 }, { 1 }, { 2 }, { 0 } }, @@ -203,7 +203,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4 }, }, { - .layout = AV_CH_LAYOUT_2_2, + .layout = AV_CHANNEL_LAYOUT_2_2, .num_ele = { 1, 1, 0, 0 }, .pairing = { { 1 }, { 1 }, }, .index = { { 0 }, { 1 }, }, @@ -211,7 +211,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3 }, }, { - .layout = AV_CH_LAYOUT_QUAD, + .layout = AV_CHANNEL_LAYOUT_QUAD, .num_ele = { 1, 0, 1, 0 }, .pairing = { { 1 }, { 0 }, { 1 }, }, .index = { { 0 }, { 0 }, { 1 } }, @@ -219,7 +219,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3 }, }, { - .layout = AV_CH_LAYOUT_5POINT0, + .layout = AV_CHANNEL_LAYOUT_5POINT0, .num_ele = { 2, 1, 0, 0 }, .pairing = { { 1, 0 }, { 1 }, }, .index = { { 0, 0 }, { 1 } }, @@ -227,7 +227,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4 }, }, { - .layout = AV_CH_LAYOUT_5POINT1, + .layout = AV_CHANNEL_LAYOUT_5POINT1, .num_ele = { 2, 1, 1, 0 }, .pairing = { { 1, 0 }, { 0 }, { 1 }, }, .index = { { 0, 0 }, { 1 }, { 1 } }, @@ -235,7 +235,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5 }, }, { - .layout = AV_CH_LAYOUT_5POINT0_BACK, + .layout = AV_CHANNEL_LAYOUT_5POINT0_BACK, .num_ele = { 2, 0, 1, 0 }, .pairing = { { 1, 0 }, { 0 }, { 1 } }, .index = { { 0, 0 }, { 0 }, { 1 } }, @@ -243,7 +243,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4 }, }, { - .layout = AV_CH_LAYOUT_5POINT1_BACK, + .layout = AV_CHANNEL_LAYOUT_5POINT1_BACK, .num_ele = { 2, 1, 1, 0 }, .pairing = { { 1, 0 }, { 0 }, { 1 }, }, .index = { { 0, 0 }, { 1 }, { 1 } }, @@ -251,7 +251,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5 }, }, { - .layout = AV_CH_LAYOUT_6POINT0, + .layout = AV_CHANNEL_LAYOUT_6POINT0, .num_ele = { 2, 1, 1, 0 }, .pairing = { { 1, 0 }, { 1 }, { 0 }, }, .index = { { 0, 0 }, { 1 }, { 1 } }, @@ -259,7 +259,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5 }, }, { - .layout = AV_CH_LAYOUT_6POINT0_FRONT, + .layout = AV_CHANNEL_LAYOUT_6POINT0_FRONT, .num_ele = { 2, 1, 0, 0 }, .pairing = { { 1, 1 }, { 1 } }, .index = { { 1, 0 }, { 2 }, }, @@ -267,7 +267,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5 }, }, { - .layout = AV_CH_LAYOUT_HEXAGONAL, + .layout = AV_CHANNEL_LAYOUT_HEXAGONAL, .num_ele = { 2, 0, 2, 0 }, .pairing = { { 1, 0 },{ 0 },{ 1, 0 }, }, .index = { { 0, 0 },{ 0 },{ 1, 1 } }, @@ -275,7 +275,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5 }, }, { - .layout = AV_CH_LAYOUT_6POINT1, + .layout = AV_CHANNEL_LAYOUT_6POINT1, .num_ele = { 2, 1, 2, 0 }, .pairing = { { 1, 0 },{ 0 },{ 1, 0 }, }, .index = { { 0, 0 },{ 1 },{ 1, 2 } }, @@ -283,7 +283,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6 }, }, { - .layout = AV_CH_LAYOUT_6POINT1_BACK, + .layout = AV_CHANNEL_LAYOUT_6POINT1_BACK, .num_ele = { 2, 1, 2, 0 }, .pairing = { { 1, 0 }, { 0 }, { 1, 0 }, }, .index = { { 0, 0 }, { 1 }, { 1, 2 } }, @@ -291,7 +291,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6 }, }, { - .layout = AV_CH_LAYOUT_6POINT1_FRONT, + .layout = AV_CHANNEL_LAYOUT_6POINT1_FRONT, .num_ele = { 2, 1, 2, 0 }, .pairing = { { 1, 0 }, { 0 }, { 1, 0 }, }, .index = { { 0, 0 }, { 1 }, { 1, 2 } }, @@ -299,7 +299,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6 }, }, { - .layout = AV_CH_LAYOUT_7POINT0, + .layout = AV_CHANNEL_LAYOUT_7POINT0, .num_ele = { 2, 1, 1, 0 }, .pairing = { { 1, 0 }, { 1 }, { 1 }, }, .index = { { 0, 0 }, { 1 }, { 2 }, }, @@ -307,7 +307,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6 }, }, { - .layout = AV_CH_LAYOUT_7POINT0_FRONT, + .layout = AV_CHANNEL_LAYOUT_7POINT0_FRONT, .num_ele = { 2, 1, 1, 0 }, .pairing = { { 1, 0 }, { 1 }, { 1 }, }, .index = { { 0, 0 }, { 1 }, { 2 }, }, @@ -315,7 +315,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6 }, }, { - .layout = AV_CH_LAYOUT_7POINT1, + .layout = AV_CHANNEL_LAYOUT_7POINT1, .num_ele = { 2, 1, 2, 0 }, .pairing = { { 1, 0 }, { 0 }, { 1, 1 }, }, .index = { { 0, 0 }, { 1 }, { 1, 2 }, { 0 } }, @@ -323,7 +323,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, }, { - .layout = AV_CH_LAYOUT_7POINT1_WIDE, + .layout = AV_CHANNEL_LAYOUT_7POINT1_WIDE, .num_ele = { 2, 1, 2, 0 }, .pairing = { { 1, 0 }, { 0 },{ 1, 1 }, }, .index = { { 0, 0 }, { 1 }, { 1, 2 }, { 0 } }, @@ -331,7 +331,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, }, { - .layout = AV_CH_LAYOUT_7POINT1_WIDE_BACK, + .layout = AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK, .num_ele = { 2, 1, 2, 0 }, .pairing = { { 1, 0 }, { 0 }, { 1, 1 }, }, .index = { { 0, 0 }, { 1 }, { 1, 2 }, { 0 } }, @@ -339,7 +339,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, }, { - .layout = AV_CH_LAYOUT_OCTAGONAL, + .layout = AV_CHANNEL_LAYOUT_OCTAGONAL, .num_ele = { 2, 1, 2, 0 }, .pairing = { { 1, 0 }, { 1 }, { 1, 0 }, }, .index = { { 0, 0 }, { 1 }, { 2, 1 } }, @@ -347,7 +347,8 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, }, { /* Meant for order 2/mixed ambisonics */ - .layout = AV_CH_LAYOUT_OCTAGONAL | AV_CH_TOP_CENTER, + .layout = { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 9, + .u.mask = AV_CH_LAYOUT_OCTAGONAL | AV_CH_TOP_CENTER }, .num_ele = { 2, 2, 2, 0 }, .pairing = { { 1, 0 }, { 1, 0 }, { 1, 0 }, }, .index = { { 0, 0 }, { 1, 1 }, { 2, 2 } }, @@ -355,8 +356,9 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, }, { /* Meant for order 2/mixed ambisonics */ - .layout = AV_CH_LAYOUT_6POINT0_FRONT | AV_CH_BACK_CENTER | - AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT | AV_CH_TOP_CENTER, + .layout = { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 10, + .u.mask = AV_CH_LAYOUT_6POINT0_FRONT | AV_CH_BACK_CENTER | + AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT | AV_CH_TOP_CENTER }, .num_ele = { 2, 2, 2, 0 }, .pairing = { { 1, 1 }, { 1, 0 }, { 1, 0 }, }, .index = { { 0, 1 }, { 2, 0 }, { 3, 1 } }, @@ -364,7 +366,7 @@ static const AACPCEInfo aac_pce_configs[] = { .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, }, { - .layout = AV_CH_LAYOUT_HEXADECAGONAL, + .layout = AV_CHANNEL_LAYOUT_HEXADECAGONAL, .num_ele = { 4, 2, 4, 0 }, .pairing = { { 1, 0, 1, 0 }, { 1, 1 }, { 1, 0, 1, 0 }, }, .index = { { 0, 0, 1, 1 }, { 2, 3 }, { 4, 2, 5, 3 } }, diff --git a/libavcodec/aacenctab.h b/libavcodec/aacenctab.h index f54dd16bed..e783a55ab3 100644 --- a/libavcodec/aacenctab.h +++ b/libavcodec/aacenctab.h @@ -45,14 +45,14 @@ extern const uint8_t *const ff_aac_swb_size_128[]; extern const int ff_aac_swb_size_128_len; /* Supported layouts without using a PCE */ -static const int64_t aac_normal_chan_layouts[7] = { - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_SURROUND, - AV_CH_LAYOUT_4POINT0, - AV_CH_LAYOUT_5POINT0_BACK, - AV_CH_LAYOUT_5POINT1_BACK, - AV_CH_LAYOUT_7POINT1, +static const AVChannelLayout aac_normal_chan_layouts[7] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_4POINT0, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + AV_CHANNEL_LAYOUT_5POINT1_BACK, + AV_CHANNEL_LAYOUT_7POINT1, }; /** default channel configurations */ diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c index 0c64f2c7b0..4c5ab2c9d5 100644 --- a/libavcodec/aacpsy.c +++ b/libavcodec/aacpsy.c @@ -263,13 +263,13 @@ static av_cold void lame_window_init(AacPsyContext *ctx, AVCodecContext *avctx) { int i, j; - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < avctx->ch_layout.nb_channels; i++) { AacPsyChannel *pch = &ctx->ch[i]; if (avctx->flags & AV_CODEC_FLAG_QSCALE) pch->attack_threshold = psy_vbr_map[avctx->global_quality / FF_QP2LAMBDA].st_lrm; else - pch->attack_threshold = lame_calc_attack_threshold(avctx->bit_rate / avctx->channels / 1000); + pch->attack_threshold = lame_calc_attack_threshold(avctx->bit_rate / avctx->ch_layout.nb_channels / 1000); for (j = 0; j < AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS; j++) pch->prev_energy_subshort[j] = 10.0f; @@ -303,7 +303,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) { float bark; int i, j, g, start; float prev, minscale, minath, minsnr, pe_min; - int chan_bitrate = ctx->avctx->bit_rate / ((ctx->avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : ctx->avctx->channels); + int chan_bitrate = ctx->avctx->bit_rate / ((ctx->avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : ctx->avctx->ch_layout.nb_channels); const int bandwidth = ctx->cutoff ? ctx->cutoff : AAC_CUTOFF(ctx->avctx); const float num_bark = calc_bark((float)bandwidth); @@ -370,7 +370,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) { } } - pctx->ch = av_calloc(ctx->avctx->channels, sizeof(*pctx->ch)); + pctx->ch = av_calloc(ctx->avctx->ch_layout.nb_channels, sizeof(*pctx->ch)); if (!pctx->ch) { av_freep(&ctx->model_priv_data); return AVERROR(ENOMEM); diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c index 93c8408297..890b13e1c8 100644 --- a/libavcodec/psymodel.c +++ b/libavcodec/psymodel.c @@ -35,7 +35,7 @@ av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, int i, j, k = 0; ctx->avctx = avctx; - ctx->ch = av_calloc(avctx->channels, 2 * sizeof(ctx->ch[0])); + ctx->ch = av_calloc(avctx->ch_layout.nb_channels, 2 * sizeof(ctx->ch[0])); ctx->group = av_calloc(num_groups, sizeof(ctx->group[0])); ctx->bands = av_malloc_array (sizeof(ctx->bands[0]), num_lens); ctx->num_bands = av_malloc_array (sizeof(ctx->num_bands[0]), num_lens); @@ -120,13 +120,13 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av FF_FILTER_MODE_LOWPASS, FILT_ORDER, cutoff_coeff, 0.0, 0.0); if (ctx->fcoeffs) { - ctx->fstate = av_calloc(avctx->channels, sizeof(ctx->fstate[0])); + ctx->fstate = av_calloc(avctx->ch_layout.nb_channels, sizeof(ctx->fstate[0])); if (!ctx->fstate) { av_free(ctx->fcoeffs); av_free(ctx); return NULL; } - for (i = 0; i < avctx->channels; i++) + for (i = 0; i < avctx->ch_layout.nb_channels; i++) ctx->fstate[i] = ff_iir_filter_init_state(FILT_ORDER); } } @@ -154,7 +154,7 @@ av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx) int i; ff_iir_filter_free_coeffsp(&ctx->fcoeffs); if (ctx->fstate) - for (i = 0; i < ctx->avctx->channels; i++) + for (i = 0; i < ctx->avctx->ch_layout.nb_channels; i++) ff_iir_filter_free_statep(&ctx->fstate[i]); av_freep(&ctx->fstate); av_free(ctx); diff --git a/libavcodec/psymodel.h b/libavcodec/psymodel.h index e5f917d495..22899a38d9 100644 --- a/libavcodec/psymodel.h +++ b/libavcodec/psymodel.h @@ -41,7 +41,7 @@ #define AAC_CUTOFF(s) ( \ (s->flags & AV_CODEC_FLAG_QSCALE) \ ? s->sample_rate / 2 \ - : AAC_CUTOFF_FROM_BITRATE(s->bit_rate, s->channels, s->sample_rate) \ + : AAC_CUTOFF_FROM_BITRATE(s->bit_rate, s->ch_layout.nb_channels, s->sample_rate) \ ) /** From patchwork Wed Dec 8 01:06:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32138 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7046552iog; Tue, 7 Dec 2021 17:11:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxbAwb1qmgr/FbndUsttyz3zKYoc8ugwH05sggIAHp4y4PlkR8klj0kvSsS5DLkyTcmD2n X-Received: by 2002:a17:907:3e0a:: with SMTP id hp10mr3594508ejc.318.1638925886259; Tue, 07 Dec 2021 17:11:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925886; cv=none; d=google.com; s=arc-20160816; b=fjcHJ6KCmSLyY8mEACk4DKle+bLaavq+gGTxdJMKLEv8X3L95af10PKJ34hPCjJFS9 44FsvDNYU4ikj0Qv+BEFMKeVy38eOp/fEuVYT75L0dc5LiH8HkXHKqEDc1IXuDfx5OXB 3sWlq6o2JOZA2UtqyDBe8CYRx7AVqX02oqtnv+s441Q7rmA9jUxXcg67t4qs7Pynshki MCkAtr6T50e+jEO+0CLateETQXqgTqSiPKQRDmGTJicNlnUKSfko3Z3qaTe30mU/Jdyb qkvUBNaoi93TkU8RkipeD1kJEuMCJQuUaI4ykbjpvVoxQPYWwvcmXewnkWyugVNR2VNO j8UA== 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=xraH7jSkAT0xvagAWBB5mud8Lfht5UZdEdqjAeb3VsA=; b=N0Bmzct+As0h0wnZBImU1yqJNni9jWTCqe2VMdTymvuzOjvvdcoHS/EFlacF/BuiQw K6BK9nq5k+9Gh6BUllf47Ks7gxNbKULPLKrpmQi+qalyFxdqHo3KV8LoiID6r7yW1vT2 RvBmUoNAVw7rapTsL15dBx6JDXWWAQTmHF2afIRDMOh09VFrsZcFCtP1mvj1vqa2HYhk IK7l+Eo+fgPaNfp5lMWvfEl7JObZVexbGMJ6FMnqaIO0aYsx67ToIFsL2jANWiQMo/UM em26a5oMRYBbiIMJ31yhrkDIAU533DyaLiwbAXnbKRggelHBtr8nsDKKmO+RM1EV4qdX 94hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=GUGbKjJw; 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 n11si3081116edx.213.2021.12.07.17.11.22; Tue, 07 Dec 2021 17:11:26 -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=GUGbKjJw; 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 F33E468AF41; Wed, 8 Dec 2021 03:08:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6140D68AF19 for ; Wed, 8 Dec 2021 03:07:56 +0200 (EET) Received: by mail-ua1-f42.google.com with SMTP id l24so1953748uak.2 for ; Tue, 07 Dec 2021 17:07:56 -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=Lc/HqNR0Fs/vXJOgVxEklNDH/XJWxn/YiDS0VKilHBc=; b=GUGbKjJwRtE6tcAV3JrlTCNEvQRdR2gnrBoOEx99j3PQ4Coa7rimX/GzBWZzIty4zS dRy8QEwejU0GQVAwGwRCjdTIwldGyywMRUwzkRlAHS3T46znNGphA4t6AlCLioliFjoF dPYXfklJ8ThDQOUp+xGNevuiwRLSzAnfWvO5fMU8LGoki4V4m+sVsQzrhscUKanI0HXS Ttf5cnJFQheVn5KJoul709a40H3iWzqvSfHw8Tne+HMQTRGW1W8Zy82hYADWaIwhg6ka d+1utpCZWR094X6h0ByBKUY+P049FAjLpx0rlrRBx29BpX1/lVyiFZxLw83M5tYBVcBT cYWw== 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=Lc/HqNR0Fs/vXJOgVxEklNDH/XJWxn/YiDS0VKilHBc=; b=y1KIRVFfM6CACM9giXhb8NWTnlFN0HN7ydsuLuGMJZ3gxqZ4EeUdou/nM7AjTyuW60 M/HrWOIEmty9+yXilaP/n14OcojeKu6l7DTzvhh8K0TVcS8oU6iXPIZpS/G6GEaWP1L9 z2XVY0jj/zH3+DNmXRiHt/n2TbHg2Q+1EWU+C3qmcBiCqUmsPee2L75NOOqvK/KvNCBT RkeBW17ZmQf1+GxS6xkK9VBWrRCiYrB+OEGJsDm2r2jP5SWD/Qy14LgTf3KTXdpYUhy7 APEctUZ9snny/AorF9xMkC+ZxPjUjP+cUAzArCSUXn+gAcUJQbJMCAJesW7a5a52MO7f JSKg== X-Gm-Message-State: AOAM531tI0cqce+x3hryywj02eI0+vYr5vXmya7aSbRdlRQv1R9rEMNU W+qRL64ZijGaDxgMTijFJULLZAfc+hgCyyG0 X-Received: by 2002:a05:6102:cd1:: with SMTP id g17mr50563964vst.55.1638925674303; Tue, 07 Dec 2021 17:07:54 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:53 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:37 -0300 Message-Id: <20211208010649.381-22-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 182/279] ac3: 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: ft2mU4hzCubD From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/aac_ac3_parser.c | 6 +++ libavcodec/ac3dec.c | 57 +++++++++++++++++---------- libavcodec/ac3dec.h | 2 + libavcodec/ac3dec_fixed.c | 1 + libavcodec/ac3dec_float.c | 2 + libavcodec/ac3enc.c | 78 +++++++++++++++++++++++++++++-------- libavcodec/ac3enc.h | 4 +- libavcodec/ac3enc_fixed.c | 5 +++ libavcodec/ac3enc_float.c | 5 +++ libavcodec/eac3enc.c | 5 +++ tests/fate/ac3.mak | 16 ++++---- 11 files changed, 135 insertions(+), 46 deletions(-) diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c index cd54a0a3e2..4ce7a73972 100644 --- a/libavcodec/aac_ac3_parser.c +++ b/libavcodec/aac_ac3_parser.c @@ -97,6 +97,12 @@ get_next: avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; avctx->ch_layout.nb_channels = s->channels; } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + avctx->channels = avctx->ch_layout.nb_channels; + avctx->channel_layout = s->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } s1->duration = s->samples; avctx->audio_service_type = s->service_type; diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index c7deb56e1c..309f11cec2 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -32,6 +32,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/crc.h" #include "libavutil/downmix_info.h" +#include "libavutil/intmath.h" #include "libavutil/opt.h" #include "libavutil/thread.h" #include "bswapdsp.h" @@ -186,6 +187,8 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) { static AVOnce init_static_once = AV_ONCE_INIT; AC3DecodeContext *s = avctx->priv_data; + const AVChannelLayout mono = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; + const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; int i, ret; s->avctx = avctx; @@ -214,12 +217,23 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; /* allow downmixing to stereo or mono */ - if (avctx->channels > 1 && - avctx->request_channel_layout == AV_CH_LAYOUT_MONO) - avctx->channels = 1; - else if (avctx->channels > 2 && - avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) - avctx->channels = 2; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channel_layout) { + av_channel_layout_uninit(&s->downmix_layout); + av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (avctx->ch_layout.nb_channels > 1 && + !av_channel_layout_compare(&s->downmix_layout, &mono)) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; + } else if (avctx->ch_layout.nb_channels > 2 && + !av_channel_layout_compare(&s->downmix_layout, &stereo)) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; + } s->downmixed = 1; for (i = 0; i < AC3_MAX_CHANNELS; i++) { @@ -1480,6 +1494,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, const SHORTFLOAT *output[AC3_MAX_CHANNELS]; enum AVMatrixEncoding matrix_encoding; AVDownmixInfo *downmix_info; + uint64_t mask; s->superframe_size = 0; @@ -1590,11 +1605,11 @@ dependent_frame: if (s->lfe_on) s->output_mode |= AC3_OUTPUT_LFEON; if (s->channels > 1 && - avctx->request_channel_layout == AV_CH_LAYOUT_MONO) { + !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) { s->out_channels = 1; s->output_mode = AC3_CHMODE_MONO; } else if (s->channels > 2 && - avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) { + !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) { s->out_channels = 2; s->output_mode = AC3_CHMODE_STEREO; } @@ -1615,10 +1630,13 @@ dependent_frame: av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n"); return AVERROR_INVALIDDATA; } - avctx->channels = s->out_channels; - avctx->channel_layout = avpriv_ac3_channel_layout_tab[s->output_mode & ~AC3_OUTPUT_LFEON]; + + mask = avpriv_ac3_channel_layout_tab[s->output_mode & ~AC3_OUTPUT_LFEON]; if (s->output_mode & AC3_OUTPUT_LFEON) - avctx->channel_layout |= AV_CH_LOW_FREQUENCY; + mask |= AV_CH_LOW_FREQUENCY; + + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, mask); /* set audio service type based on bitstream mode for AC-3 */ avctx->audio_service_type = s->bitstream_mode; @@ -1714,20 +1732,20 @@ skip: channel_layout |= ff_eac3_custom_channel_map_locations[ch][1]; } } - if (av_get_channel_layout_nb_channels(channel_layout) > EAC3_MAX_CHANNELS) { + if (av_popcount64(channel_layout) > EAC3_MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Too many channels (%d) coded\n", - av_get_channel_layout_nb_channels(channel_layout)); + av_popcount64(channel_layout)); return AVERROR_INVALIDDATA; } - avctx->channel_layout = channel_layout; - avctx->channels = av_get_channel_layout_nb_channels(channel_layout); + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, channel_layout); for (ch = 0; ch < EAC3_MAX_CHANNELS; ch++) { if (s->channel_map & (1 << (EAC3_MAX_CHANNELS - ch - 1))) { if (ff_eac3_custom_channel_map_locations[ch][0]) { - int index = av_get_channel_layout_channel_index(channel_layout, - ff_eac3_custom_channel_map_locations[ch][1]); + int index = av_channel_layout_index_from_channel(&avctx->ch_layout, + ff_ctzll(ff_eac3_custom_channel_map_locations[ch][1])); if (index < 0) return AVERROR_INVALIDDATA; if (extend >= channel_map_size) @@ -1739,8 +1757,7 @@ skip: for (i = 0; i < 64; i++) { if ((1ULL << i) & ff_eac3_custom_channel_map_locations[ch][1]) { - int index = av_get_channel_layout_channel_index(channel_layout, - 1ULL << i); + int index = av_channel_layout_index_from_channel(&avctx->ch_layout, i); if (index < 0) return AVERROR_INVALIDDATA; if (extend >= channel_map_size) @@ -1759,7 +1776,7 @@ skip: if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - for (ch = 0; ch < avctx->channels; ch++) { + for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { int map = extended_channel_map[ch]; av_assert0(ch>=AV_NUM_DATA_POINTERS || frame->extended_data[ch] == frame->data[ch]); memcpy((SHORTFLOAT *)frame->extended_data[ch], diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index 85653990cf..9444124974 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -251,6 +251,8 @@ typedef struct AC3DecodeContext { DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread DECLARE_ALIGNED(32, SHORTFLOAT, output_buffer)[EAC3_MAX_CHANNELS][AC3_BLOCK_SIZE * 6]; ///< final output buffer ///@} + + AVChannelLayout downmix_layout; } AC3DecodeContext; /** diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c index 8645952621..ae433c5cc7 100644 --- a/libavcodec/ac3dec_fixed.c +++ b/libavcodec/ac3dec_fixed.c @@ -157,6 +157,7 @@ static const AVOption options[] = { { "cons_noisegen", "enable consistent noise generation", OFFSET(consistent_noise_generation), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR }, { "heavy_compr", "enable heavy dynamic range compression", OFFSET(heavy_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, + { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR }, { NULL}, }; diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c index 573fbe75b6..2b1b359a0c 100644 --- a/libavcodec/ac3dec_float.c +++ b/libavcodec/ac3dec_float.c @@ -43,6 +43,8 @@ static const AVOption options[] = { {"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, {"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, + { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR }, + { NULL}, }; diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 034aa0beb9..30ba8bfecd 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -147,6 +147,7 @@ static uint8_t exponent_group_tab[2][3][256]; /** * List of supported channel layouts. */ +#if FF_API_OLD_CHANNEL_LAYOUT const uint64_t ff_ac3_channel_layouts[19] = { AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, @@ -168,6 +169,47 @@ const uint64_t ff_ac3_channel_layouts[19] = { AV_CH_LAYOUT_5POINT1_BACK, 0 }; +#endif + +const AVChannelLayout ff_ac3_ch_layouts[19] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_2_1, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_2_2, + AV_CHANNEL_LAYOUT_QUAD, + AV_CHANNEL_LAYOUT_4POINT0, + AV_CHANNEL_LAYOUT_5POINT0, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + { + .nb_channels = 2, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_MONO | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 3, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_STEREO | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 4, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_2_1 | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 4, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_SURROUND | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 5, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_4POINT0 | AV_CH_LOW_FREQUENCY, + }, + AV_CHANNEL_LAYOUT_5POINT1, + AV_CHANNEL_LAYOUT_5POINT1_BACK, + { 0 }, +}; /** * Table to remap channels from SMPTE order to AC-3 order. @@ -1797,7 +1839,7 @@ static void dprint_options(AC3EncodeContext *s) } ff_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id); ff_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt)); - av_get_channel_layout_string(strbuf, 32, s->channels, avctx->channel_layout); + av_channel_layout_describe(&avctx->ch_layout, strbuf, sizeof(strbuf)); ff_dlog(avctx, "channel_layout: %s\n", strbuf); ff_dlog(avctx, "sample_rate: %d\n", s->sample_rate); ff_dlog(avctx, "bit_rate: %d\n", s->bit_rate); @@ -2041,11 +2083,11 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s) /* validate audio service type / channels combination */ if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE && - avctx->channels == 1) || + avctx->ch_layout.nb_channels == 1) || ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY || avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY || avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER) - && avctx->channels > 1)) { + && avctx->ch_layout.nb_channels > 1)) { av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the " "specified number of channels\n"); return AVERROR(EINVAL); @@ -2167,27 +2209,29 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx) /* * Set channel information during initialization. */ -static av_cold int set_channel_info(AC3EncodeContext *s, int channels, - uint64_t *channel_layout) +static av_cold int set_channel_info(AVCodecContext *avctx) { - int ch_layout; + AC3EncodeContext *s = avctx->priv_data; + int channels = avctx->ch_layout.nb_channels; + uint64_t mask = avctx->ch_layout.u.mask; if (channels < 1 || channels > AC3_MAX_CHANNELS) return AVERROR(EINVAL); - if (*channel_layout > 0x7FF) + if (mask > 0x7FF) return AVERROR(EINVAL); - ch_layout = *channel_layout; - if (!ch_layout) - ch_layout = av_get_default_channel_layout(channels); - s->lfe_on = !!(ch_layout & AV_CH_LOW_FREQUENCY); + if (!mask) + av_channel_layout_default(&avctx->ch_layout, channels); + mask = avctx->ch_layout.u.mask; + + s->lfe_on = !!(mask & AV_CH_LOW_FREQUENCY); s->channels = channels; s->fbw_channels = channels - s->lfe_on; s->lfe_channel = s->lfe_on ? s->fbw_channels + 1 : -1; if (s->lfe_on) - ch_layout -= AV_CH_LOW_FREQUENCY; + mask -= AV_CH_LOW_FREQUENCY; - switch (ch_layout) { + switch (mask) { case AV_CH_LAYOUT_MONO: s->channel_mode = AC3_CHMODE_MONO; break; case AV_CH_LAYOUT_STEREO: s->channel_mode = AC3_CHMODE_STEREO; break; case AV_CH_LAYOUT_SURROUND: s->channel_mode = AC3_CHMODE_3F; break; @@ -2204,9 +2248,9 @@ static av_cold int set_channel_info(AC3EncodeContext *s, int channels, s->has_surround = s->channel_mode & 0x04; s->channel_map = ac3_enc_channel_map[s->channel_mode][s->lfe_on]; - *channel_layout = ch_layout; if (s->lfe_on) - *channel_layout |= AV_CH_LOW_FREQUENCY; + mask |= AV_CH_LOW_FREQUENCY; + av_channel_layout_from_mask(&avctx->ch_layout, mask); return 0; } @@ -2218,12 +2262,12 @@ static av_cold int validate_options(AC3EncodeContext *s) int i, ret, max_sr; /* validate channel layout */ - if (!avctx->channel_layout) { + if (!avctx->ch_layout.nb_channels) { av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The " "encoder will guess the layout, but it " "might be incorrect.\n"); } - ret = set_channel_info(s, avctx->channels, &avctx->channel_layout); + ret = set_channel_info(avctx); if (ret) { av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n"); return ret; diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index ec9ead8a4e..895b375936 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -265,8 +265,10 @@ typedef struct AC3EncodeContext { void (*output_frame_header)(struct AC3EncodeContext *s); } AC3EncodeContext; - +#if FF_API_OLD_CHANNEL_LAYOUT extern const uint64_t ff_ac3_channel_layouts[19]; +#endif +extern const AVChannelLayout ff_ac3_ch_layouts[19]; extern const AVOption ff_ac3_enc_options[]; extern const AVClass ff_ac3enc_class; extern const AVCodecDefault ff_ac3_enc_defaults[]; diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c index 80aa98c691..6e0abf4a26 100644 --- a/libavcodec/ac3enc_fixed.c +++ b/libavcodec/ac3enc_fixed.c @@ -119,6 +119,7 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx) } +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_ac3_fixed_encoder = { .name = "ac3_fixed", .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), @@ -134,6 +135,10 @@ const AVCodec ff_ac3_fixed_encoder = { .priv_class = &ff_ac3enc_class, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, .supported_samplerates = ff_ac3_sample_rate_tab, +#if FF_API_OLD_CHANNEL_LAYOUT .channel_layouts = ff_ac3_channel_layouts, +#endif + .ch_layouts = ff_ac3_ch_layouts, .defaults = ff_ac3_enc_defaults, }; +FF_ENABLE_DEPRECATION_WARNINGS diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c index e4a3794dd8..0e605cdf2c 100644 --- a/libavcodec/ac3enc_float.c +++ b/libavcodec/ac3enc_float.c @@ -123,6 +123,7 @@ av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx) return ff_ac3_encode_init(avctx); } +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_ac3_encoder = { .name = "ac3", .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), @@ -137,7 +138,11 @@ const AVCodec ff_ac3_encoder = { AV_SAMPLE_FMT_NONE }, .priv_class = &ff_ac3enc_class, .supported_samplerates = ff_ac3_sample_rate_tab, +#if FF_API_OLD_CHANNEL_LAYOUT .channel_layouts = ff_ac3_channel_layouts, +#endif + .ch_layouts = ff_ac3_ch_layouts, .defaults = ff_ac3_enc_defaults, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; +FF_ENABLE_DEPRECATION_WARNINGS diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c index 96ef00ea4f..c959aec55c 100644 --- a/libavcodec/eac3enc.c +++ b/libavcodec/eac3enc.c @@ -248,6 +248,7 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s) } +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_eac3_encoder = { .name = "eac3", .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"), @@ -262,7 +263,11 @@ const AVCodec ff_eac3_encoder = { AV_SAMPLE_FMT_NONE }, .priv_class = &eac3enc_class, .supported_samplerates = ff_ac3_sample_rate_tab, +#if FF_API_OLD_CHANNEL_LAYOUT .channel_layouts = ff_ac3_channel_layouts, +#endif + .ch_layouts = ff_ac3_ch_layouts, .defaults = ff_ac3_enc_defaults, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; +FF_ENABLE_DEPRECATION_WARNINGS diff --git a/tests/fate/ac3.mak b/tests/fate/ac3.mak index 39b555161d..f0c3d18049 100644 --- a/tests/fate/ac3.mak +++ b/tests/fate/ac3.mak @@ -6,13 +6,13 @@ FATE_AC3 += fate-ac3-4.0 fate-ac3-4.0: CMD = pcm -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-4.0: REF = $(SAMPLES)/ac3/millers_crossing_4.0_v2.pcm -#request_channel_layout 4 -> front channel +#downmix 4.0 -> front channel FATE_AC3 += fate-ac3-4.0-downmix-mono -fate-ac3-4.0-downmix-mono: CMD = pcm -request_channel_layout 4 -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 +fate-ac3-4.0-downmix-mono: CMD = pcm -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm FATE_AC3 += fate-ac3-4.0-downmix-stereo -fate-ac3-4.0-downmix-stereo: CMD = pcm -request_channel_layout stereo -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 +fate-ac3-4.0-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-4.0-downmix-stereo: REF = $(SAMPLES)/ac3/millers_crossing_4.0_stereo_v2.pcm FATE_AC3 += fate-ac3-5.1 @@ -20,11 +20,11 @@ fate-ac3-5.1: CMD = pcm -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_v2.pcm FATE_AC3 += fate-ac3-5.1-downmix-mono -fate-ac3-5.1-downmix-mono: CMD = pcm -request_channel_layout FC -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-5.1-downmix-mono: CMD = pcm -downmix FC -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm FATE_AC3 += fate-ac3-5.1-downmix-stereo -fate-ac3-5.1-downmix-stereo: CMD = pcm -request_channel_layout 2c -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-5.1-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm FATE_AC3 += fate-ac3-fixed-2.0 @@ -32,15 +32,15 @@ fate-ac3-fixed-2.0: CMD = pcm -c ac3_fixed -i $(TARGET_SAMPLES)/ac3/monsters_inc fate-ac3-fixed-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small_v2.pcm FATE_AC3 += fate-ac3-fixed-4.0-downmix-mono -fate-ac3-fixed-4.0-downmix-mono: CMD = pcm -c ac3_fixed -request_channel_layout mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 +fate-ac3-fixed-4.0-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-fixed-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm FATE_AC3 += fate-ac3-fixed-5.1-downmix-mono -fate-ac3-fixed-5.1-downmix-mono: CMD = pcm -c ac3_fixed -request_channel_layout 4 -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-fixed-5.1-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-fixed-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm FATE_AC3 += fate-ac3-fixed-5.1-downmix-stereo -fate-ac3-fixed-5.1-downmix-stereo: CMD = pcm -c ac3_fixed -request_channel_layout 3 -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-fixed-5.1-downmix-stereo: CMD = pcm -c ac3_fixed -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-fixed-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm FATE_EAC3 += fate-eac3-1 From patchwork Wed Dec 8 01:06:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32127 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7046750iog; Tue, 7 Dec 2021 17:11:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDnE/C66cEY9cXflYW0bBYKuzHFBb1Nr67kxndbNZlnNUwX0dRtt5d+g1avurBeIylgOJA X-Received: by 2002:a17:906:229b:: with SMTP id p27mr3527255eja.264.1638925899219; Tue, 07 Dec 2021 17:11:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925899; cv=none; d=google.com; s=arc-20160816; b=Ij2iYtZtVJ2vVZeK34TheA8vP/hnPQn0TYMHF40aT2Tq7OI+Ar2iBMiE7xnYUgcmR5 xG70k6xGqjXzaRggNPK/zQWbPtp63DKcgKDGnC/JTNsRfasrHgzM0mKZn7AtmDwsUxwa tvY9XIeoWzpT9FNv3I4YJBMi4HhColDJDmNWzJLnRkH66Qj4TdRTcpzQLl6+lAmU4jrQ hpiQZU7XL2Chp0rEf52I09W1Kg69G9zJQ3nF7IfOh+wv2E35FxRYKazzbya6i8fwBrlm bFj/a9exON20/lJgS37W12JO03fzDvxIHnQlTsHQcL5P+f4oamZN7tjDumGfTmTWz1Pl L0Xg== 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=qEsc+8PgZ5a5RS7cm0YdvZjFobt6Kr/3/5LxFrjyf/E=; b=donj+omTj/HbNfJ2JZAaE9xNehEElc1rNp9kcQXkBZt1/X1cRnf9AuiPHYbG5rPxck aYT9gD/W4WksQCYx73wUstE+8GnXVnZwPJZgwhFMZaOdJbzrE9Io8Tt7cvl2wisPTGPY mxG1OoC+vg7FHpHi5EbfUaUouOw+toclrjbHqKe3EfwkUnYaBN2rnvfDc/ZHy5mNJBty ynA4LvBG1KBxV1pQy1IMEMcCndQaX6h+4d54N94cDxyFIiGRIIYLVQ2+wvnDroVcFRC+ +m8NpR9+mWnxTP0X0a2xhcZUTH30kGOJxy73vrixZg8ZE8AHqVQw+jeoyGp5FgaIqM90 aAEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Wiqg3Jot; 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 qk44si2225726ejc.469.2021.12.07.17.11.33; Tue, 07 Dec 2021 17:11:39 -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=Wiqg3Jot; 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 0574B68AF49; Wed, 8 Dec 2021 03:08:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 262F368AEDA for ; Wed, 8 Dec 2021 03:07:59 +0200 (EET) Received: by mail-vk1-f178.google.com with SMTP id q21so585195vkn.2 for ; Tue, 07 Dec 2021 17:07:59 -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=f6mUH/MCa9LV35UHZKVq72YA+/+X86/D6CT73tPAtaQ=; b=Wiqg3JottP3ABb/v6630J0z9dX3QNLdldNrYQkKx7o8sdpvmch30ImhdZHJnHwKDx3 0gIKlYT0zdxtIEQzCmvJfGsJNgSeWn6TD8lYqWTv/gu2xkGYB0ghDMmfHwb+x/ePwM51 UlKdTeUwyqhUA846OgLuGyt3qEryhRZ/dS/P9oLvyfDfWIii35mpUvzsDhv38BZ64FPm hYnI+QhrxuXEHMuB7LbTjo+NUB275P6NC0ctz7sydtpQBMnTLpbQ64a0uBXJQJ/zFBOF qRYXkudB28rqJiGdSSxt/zWV88mW6J7SUXg/I7eXhvwogwZHjLwlAwr5lZuGtUMjGZeN B3bg== 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=f6mUH/MCa9LV35UHZKVq72YA+/+X86/D6CT73tPAtaQ=; b=7dmIo5u/MXb155K40bVyXDhtYShDCPlxOtsjVKNOof+80R1bBhOp9QtaDRBoS1w4km iMpm4ciPGO8NSpEbQl85Pnx0/J6+SDGN019rDNsrCoxGrvcQBqiiwoTvdjhkjsKe80ie MHHV5yZpW0F7kN4+TujfNh9BlQeenNubiXjWtOrOI57Ijyp7l0pJSn8FNBfBkZrHItW6 Nzt5CswP4DVh+8L6p9yZegMusd7kbxJZQxIZIEhDaiZVk58YW5U3AYOJTOkCmq4thcUC 4X+dzB2zPEarthjlsRaf+9yE9feTE8Grp4OgEVUARdj28yqmki1lMynEa1fBnevIUQoe Bw4Q== X-Gm-Message-State: AOAM531uG7IipBNebjvAK2R5JaCLpb+Tta3iBD1zyWBmMBrMjps0Mgr/ son4/pGpb9bj/FowDpib8Wj3XtYgWZpR0QpH X-Received: by 2002:ac5:c805:: with SMTP id y5mr57770558vkl.29.1638925675834; Tue, 07 Dec 2021 17:07:55 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:55 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:38 -0300 Message-Id: <20211208010649.381-23-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 183/279] adpcm: 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: qYLZc6DH3QiB From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/adpcm.c | 151 ++++++++++++++++++++++-------------------- libavcodec/adpcmenc.c | 122 +++++++++++++++++----------------- 2 files changed, 141 insertions(+), 132 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index cfde5f58b9..0591314302 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -271,14 +271,15 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) case AV_CODEC_ID_ADPCM_MTAF: min_channels = 2; max_channels = 8; - if (avctx->channels & 1) { - avpriv_request_sample(avctx, "channel count %d", avctx->channels); + if (avctx->ch_layout.nb_channels & 1) { + avpriv_request_sample(avctx, "channel count %d", avctx->ch_layout.nb_channels); return AVERROR_PATCHWELCOME; } break; case AV_CODEC_ID_ADPCM_PSX: max_channels = 8; - if (avctx->channels <= 0 || avctx->block_align % (16 * avctx->channels)) + if (avctx->ch_layout.nb_channels <= 0 || + avctx->block_align % (16 * avctx->ch_layout.nb_channels)) return AVERROR_INVALIDDATA; break; case AV_CODEC_ID_ADPCM_IMA_DAT4: @@ -287,7 +288,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) max_channels = 14; break; } - if (avctx->channels < min_channels || avctx->channels > max_channels) { + if (avctx->ch_layout.nb_channels < min_channels || + avctx->ch_layout.nb_channels > max_channels) { av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); return AVERROR(EINVAL); } @@ -298,7 +300,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) return AVERROR_INVALIDDATA; break; case AV_CODEC_ID_ADPCM_ARGO: - if (avctx->bits_per_coded_sample != 4 || avctx->block_align != 17 * avctx->channels) + if (avctx->bits_per_coded_sample != 4 || + avctx->block_align != 17 * avctx->ch_layout.nb_channels) return AVERROR_INVALIDDATA; break; case AV_CODEC_ID_ADPCM_ZORK: @@ -336,7 +339,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) AV_SAMPLE_FMT_S16; break; case AV_CODEC_ID_ADPCM_MS: - avctx->sample_fmt = avctx->channels > 2 ? AV_SAMPLE_FMT_S16P : + avctx->sample_fmt = avctx->ch_layout.nb_channels > 2 ? AV_SAMPLE_FMT_S16P : AV_SAMPLE_FMT_S16; break; default: @@ -755,6 +758,7 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_ ADPCMDecodeContext *c = avctx->priv_data; GetBitContext gb; const int8_t *table; + int channels = avctx->ch_layout.nb_channels; int k0, signmask, nb_bits, count; int size = buf_size*8; int i; @@ -767,16 +771,16 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_ k0 = 1 << (nb_bits-2); signmask = 1 << (nb_bits-1); - while (get_bits_count(&gb) <= size - 22*avctx->channels) { - for (i = 0; i < avctx->channels; i++) { + while (get_bits_count(&gb) <= size - 22 * channels) { + for (i = 0; i < channels; i++) { *samples++ = c->status[i].predictor = get_sbits(&gb, 16); c->status[i].step_index = get_bits(&gb, 6); } - for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) { + for (count = 0; get_bits_count(&gb) <= size - nb_bits * channels && count < 4095; count++) { int i; - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < channels; i++) { // similar to IMA adpcm int delta = get_bits(&gb, nb_bits); int step = ff_adpcm_step_table[c->status[i].step_index]; @@ -840,7 +844,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, { ADPCMDecodeContext *s = avctx->priv_data; int nb_samples = 0; - int ch = avctx->channels; + int ch = avctx->ch_layout.nb_channels; int has_coded_samples = 0; int header_size; @@ -1061,6 +1065,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; ADPCMDecodeContext *c = avctx->priv_data; + int channels = avctx->ch_layout.nb_channels; int16_t *samples; int16_t **samples_p; int st; /* stereo */ @@ -1089,13 +1094,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, frame->nb_samples = nb_samples = coded_samples; } - st = avctx->channels == 2 ? 1 : 0; + st = channels == 2 ? 1 : 0; switch(avctx->codec->id) { CASE(ADPCM_IMA_QT, /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples). Channel data is interleaved per-chunk. */ - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { ADPCMChannelStatus *cs = &c->status[channel]; int predictor; int step_index; @@ -1134,7 +1139,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_WAV, - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { ADPCMChannelStatus *cs = &c->status[i]; cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1153,12 +1158,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, GetBitContext g; for (int n = 0; n < (nb_samples - 1) / samples_per_block; n++) { - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { ADPCMChannelStatus *cs = &c->status[i]; samples = &samples_p[i][1 + n * samples_per_block]; for (int j = 0; j < block_size; j++) { - temp[j] = buf[4 * avctx->channels + block_size * n * avctx->channels + - (j % 4) + (j / 4) * (avctx->channels * 4) + i * 4]; + temp[j] = buf[4 * channels + block_size * n * channels + + (j % 4) + (j / 4) * (channels * 4) + i * 4]; } ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size); if (ret < 0) @@ -1169,10 +1174,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } } } - bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4); + bytestream2_skip(&gb, avctx->block_align - channels * 4); } else { for (int n = 0; n < (nb_samples - 1) / 8; n++) { - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { ADPCMChannelStatus *cs = &c->status[i]; samples = &samples_p[i][1 + n * 8]; for (int m = 0; m < 8; m += 2) { @@ -1185,10 +1190,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_4XM, - for (int i = 0; i < avctx->channels; i++) + for (int i = 0; i < channels; i++) c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (c->status[i].step_index > 88u) { av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", @@ -1197,7 +1202,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } } - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { ADPCMChannelStatus *cs = &c->status[i]; samples = (int16_t *)frame->data[i]; for (int n = nb_samples >> 1; n > 0; n--) { @@ -1208,9 +1213,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_AGM, - for (int i = 0; i < avctx->channels; i++) + for (int i = 0; i < channels; i++) c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); - for (int i = 0; i < avctx->channels; i++) + for (int i = 0; i < channels; i++) c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16); for (int n = 0; n < nb_samples >> (1 - st); n++) { @@ -1222,8 +1227,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, CASE(ADPCM_MS, int block_predictor; - if (avctx->channels > 2) { - for (int channel = 0; channel < avctx->channels; channel++) { + if (avctx->ch_layout.nb_channels > 2) { + for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) { samples = samples_p[channel]; block_predictor = bytestream2_get_byteu(&gb); if (block_predictor > 6) { @@ -1285,7 +1290,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_MTAF, - for (int channel = 0; channel < avctx->channels; channel += 2) { + for (int channel = 0; channel < channels; channel += 2) { bytestream2_skipu(&gb, 4); c->status[channel ].step = bytestream2_get_le16u(&gb) & 0x1f; c->status[channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f; @@ -1306,7 +1311,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_DK4, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { ADPCMChannelStatus *cs = &c->status[channel]; cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1338,7 +1343,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int nibble; int decode_top_nibble_next = 0; int diff_channel; - const int16_t *samples_end = samples + avctx->channels * nb_samples; + const int16_t *samples_end = samples + channels * nb_samples; bytestream2_skipu(&gb, 10); c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1385,7 +1390,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, bytestream2_skip(&gb, 1); ) /* End of CASE */ CASE(ADPCM_IMA_ISS, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { ADPCMChannelStatus *cs = &c->status[channel]; cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1412,7 +1417,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_MOFLEX, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { ADPCMChannelStatus *cs = &c->status[channel]; cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1424,7 +1429,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } for (int subframe = 0; subframe < nb_samples / 256; subframe++) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { samples = samples_p[channel] + 256 * subframe; for (int n = 0; n < 256; n += 2) { int v = bytestream2_get_byteu(&gb); @@ -1435,7 +1440,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_DAT4, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { ADPCMChannelStatus *cs = &c->status[channel]; samples = samples_p[channel]; bytestream2_skip(&gb, 4); @@ -1462,26 +1467,26 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, ) /* End of CASE */ CASE(ADPCM_IMA_APM, for (int n = nb_samples / 2; n > 0; n--) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_qt_expand_nibble(&c->status[channel], v >> 4 ); samples[st] = adpcm_ima_qt_expand_nibble(&c->status[channel], v & 0x0F); } - samples += avctx->channels; + samples += channels; } ) /* End of CASE */ CASE(ADPCM_IMA_ALP, for (int n = nb_samples / 2; n > 0; n--) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_alp_expand_nibble(&c->status[channel], v >> 4 , 2); samples[st] = adpcm_ima_alp_expand_nibble(&c->status[channel], v & 0x0F, 2); } - samples += avctx->channels; + samples += channels; } ) /* End of CASE */ CASE(ADPCM_IMA_CUNNING, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int16_t *smp = samples_p[channel]; for (int n = 0; n < nb_samples / 2; n++) { int v = bytestream2_get_byteu(&gb); @@ -1498,7 +1503,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_RAD, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { ADPCMChannelStatus *cs = &c->status[channel]; cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1514,17 +1519,17 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, byte[0] = bytestream2_get_byteu(&gb); if (st) byte[1] = bytestream2_get_byteu(&gb); - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3); } - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3); } } ) /* End of CASE */ CASE(ADPCM_IMA_WS, if (c->vqa_version == 3) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int16_t *smp = samples_p[channel]; for (int n = nb_samples / 2; n > 0; n--) { @@ -1535,12 +1540,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } } else { for (int n = nb_samples / 2; n > 0; n--) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); } - samples += avctx->channels; + samples += channels; } } bytestream2_seek(&gb, 0, SEEK_END); @@ -1548,13 +1553,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, CASE(ADPCM_XA, int16_t *out0 = samples_p[0]; int16_t *out1 = samples_p[1]; - int samples_per_block = 28 * (3 - avctx->channels) * 4; + int samples_per_block = 28 * (3 - channels) * 4; int sample_offset = 0; int bytes_remaining; while (bytestream2_get_bytes_left(&gb) >= 128) { if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb), &c->status[0], &c->status[1], - avctx->channels, sample_offset)) < 0) + channels, sample_offset)) < 0) return ret; bytestream2_skipu(&gb, 128); sample_offset += samples_per_block; @@ -1604,7 +1609,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces, each coding 28 stereo samples. */ - if(avctx->channels != 2) + if (channels != 2) return AVERROR_INVALIDDATA; current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1649,7 +1654,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, CASE(ADPCM_EA_MAXIS_XA, int coeff[2][2], shift[2]; - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int byte = bytestream2_get_byteu(&gb); for (int i = 0; i < 2; i++) coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i]; @@ -1661,7 +1666,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, byte[0] = bytestream2_get_byteu(&gb); if (st) byte[1] = bytestream2_get_byteu(&gb); for (int i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */ - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int sample = sign_extend(byte[channel] >> i, 4) * (1 << shift[channel]); sample = (sample + c->status[channel].sample1 * coeff[channel][0] + @@ -1690,12 +1695,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int count = 0; int offsets[6]; - for (unsigned channel = 0; channel < avctx->channels; channel++) + for (unsigned channel = 0; channel < channels; channel++) offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) : bytestream2_get_le32(&gb)) + - (avctx->channels + 1) * 4; + (channels + 1) * 4; - for (unsigned channel = 0; channel < avctx->channels; channel++) { + for (unsigned channel = 0; channel < channels; channel++) { int count1; bytestream2_seek(&gb, offsets[channel], SEEK_SET); @@ -1759,7 +1764,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } #endif /* CONFIG_ADPCM_EA_Rx_DECODER */ CASE(ADPCM_EA_XAS, - for (int channel=0; channel < avctx->channels; channel++) { + for (int channel=0; channel < channels; channel++) { int coeff[2][4], shift[4]; int16_t *s = samples_p[channel]; for (int n = 0; n < 4; n++, s += 32) { @@ -1791,7 +1796,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_ACORN, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { ADPCMChannelStatus *cs = &c->status[channel]; cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = bytestream2_get_le16u(&gb) & 0xFF; @@ -1808,7 +1813,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_AMV, - av_assert0(avctx->channels == 1); + av_assert0(channels == 1); /* * Header format: @@ -1848,7 +1853,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_IMA_SMJPEG, - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16); c->status[i].step_index = bytestream2_get_byteu(&gb); bytestream2_skipu(&gb, 1); @@ -1931,7 +1936,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_AICA, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { samples = samples_p[channel]; for (int n = nb_samples >> 1; n > 0; n--) { int v = bytestream2_get_byteu(&gb); @@ -1953,7 +1958,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } for (int m = 0; m < blocks; m++) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int prev1 = c->status[channel].sample1; int prev2 = c->status[channel].sample2; @@ -2005,33 +2010,33 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, if (avctx->extradata) { GetByteContext tb; - if (avctx->extradata_size < 32 * avctx->channels) { + if (avctx->extradata_size < 32 * channels) { av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n"); return AVERROR_INVALIDDATA; } bytestream2_init(&tb, avctx->extradata, avctx->extradata_size); - for (int i = 0; i < avctx->channels; i++) + for (int i = 0; i < channels; i++) for (int n = 0; n < 16; n++) table[i][n] = THP_GET16(tb); } else { - for (int i = 0; i < avctx->channels; i++) + for (int i = 0; i < channels; i++) for (int n = 0; n < 16; n++) table[i][n] = THP_GET16(gb); if (!c->has_status) { /* Initialize the previous sample. */ - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { c->status[i].sample1 = THP_GET16(gb); c->status[i].sample2 = THP_GET16(gb); } c->has_status = 1; } else { - bytestream2_skip(&gb, avctx->channels * 4); + bytestream2_skip(&gb, channels * 4); } } - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { samples = samples_p[ch]; /* Read in every sample for this channel. */ @@ -2065,7 +2070,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } #endif /* CONFIG_ADPCM_THP(_LE)_DECODER */ CASE(ADPCM_DTK, - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { samples = samples_p[channel]; /* Read in every sample for this channel. */ @@ -2113,9 +2118,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_PSX, - for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * avctx->channels); block++) { - int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * avctx->channels) / (16 * avctx->channels); - for (int channel = 0; channel < avctx->channels; channel++) { + for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * channels); block++) { + int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * channels) / (16 * channels); + for (int channel = 0; channel < channels; channel++) { samples = samples_p[channel] + block * nb_samples_per_block; av_assert0((block + 1) * nb_samples_per_block <= nb_samples); @@ -2172,7 +2177,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, * They should be 0 initially. */ for (int block = 0; block < avpkt->size / avctx->block_align; block++) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) { ADPCMChannelStatus *cs = c->status + channel; int control, shift; @@ -2191,19 +2196,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } ) /* End of CASE */ CASE(ADPCM_ZORK, - for (int n = 0; n < nb_samples * avctx->channels; n++) { + for (int n = 0; n < nb_samples * channels; n++) { int v = bytestream2_get_byteu(&gb); - *samples++ = adpcm_zork_expand_nibble(&c->status[n % avctx->channels], v); + *samples++ = adpcm_zork_expand_nibble(&c->status[n % channels], v); } ) /* End of CASE */ CASE(ADPCM_IMA_MTF, for (int n = nb_samples / 2; n > 0; n--) { - for (int channel = 0; channel < avctx->channels; channel++) { + for (int channel = 0; channel < channels; channel++) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_mtf_expand_nibble(&c->status[channel], v >> 4); samples[st] = adpcm_ima_mtf_expand_nibble(&c->status[channel], v & 0x0F); } - samples += avctx->channels; + samples += channels; } ) /* End of CASE */ default: diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index b0f6f209b7..92c31b4841 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -79,11 +79,7 @@ typedef struct ADPCMEncodeContext { static av_cold int adpcm_encode_init(AVCodecContext *avctx) { ADPCMEncodeContext *s = avctx->priv_data; - - if (avctx->channels > 2) { - av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n"); - return AVERROR(EINVAL); - } + int channels = avctx->ch_layout.nb_channels; /* * AMV's block size has to match that of the corresponding video @@ -130,8 +126,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) CASE(ADPCM_IMA_WAV, /* each 16 bits sample gives one nibble and we have 4 bytes per channel overhead */ - avctx->frame_size = (s->block_size - 4 * avctx->channels) * 8 / - (4 * avctx->channels) + 1; + avctx->frame_size = (s->block_size - 4 * channels) * 8 / + (4 * channels) + 1; /* seems frame_size isn't taken into account... have to buffer the samples :-( */ avctx->block_align = s->block_size; @@ -139,13 +135,13 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) ) /* End of CASE */ CASE(ADPCM_IMA_QT, avctx->frame_size = 64; - avctx->block_align = 34 * avctx->channels; + avctx->block_align = 34 * channels; ) /* End of CASE */ CASE(ADPCM_MS, uint8_t *extradata; /* each 16 bits sample gives one nibble and we have 7 bytes per channel overhead */ - avctx->frame_size = (s->block_size - 7 * avctx->channels) * 2 / avctx->channels + 2; + avctx->frame_size = (s->block_size - 7 * channels) * 2 / channels + 2; avctx->bits_per_coded_sample = 4; avctx->block_align = s->block_size; if (!(avctx->extradata = av_malloc(32 + AV_INPUT_BUFFER_PADDING_SIZE))) @@ -160,7 +156,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) } ) /* End of CASE */ CASE(ADPCM_YAMAHA, - avctx->frame_size = s->block_size * 2 / avctx->channels; + avctx->frame_size = s->block_size * 2 / channels; avctx->block_align = s->block_size; ) /* End of CASE */ CASE(ADPCM_SWF, @@ -172,11 +168,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } avctx->frame_size = 4096; /* Hardcoded according to the SWF spec. */ - avctx->block_align = (2 + avctx->channels * (22 + 4 * (avctx->frame_size - 1)) + 7) / 8; + avctx->block_align = (2 + channels * (22 + 4 * (avctx->frame_size - 1)) + 7) / 8; ) /* End of CASE */ case AV_CODEC_ID_ADPCM_IMA_SSI: case AV_CODEC_ID_ADPCM_IMA_ALP: - avctx->frame_size = s->block_size * 2 / avctx->channels; + avctx->frame_size = s->block_size * 2 / channels; avctx->block_align = s->block_size; break; CASE(ADPCM_IMA_AMV, @@ -185,7 +181,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (avctx->channels != 1) { + if (channels != 1) { av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); return AVERROR(EINVAL); } @@ -194,7 +190,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->block_align = 8 + (FFALIGN(avctx->frame_size, 2) / 2); ) /* End of CASE */ CASE(ADPCM_IMA_APM, - avctx->frame_size = s->block_size * 2 / avctx->channels; + avctx->frame_size = s->block_size * 2 / channels; avctx->block_align = s->block_size; if (!(avctx->extradata = av_mallocz(28 + AV_INPUT_BUFFER_PADDING_SIZE))) @@ -203,11 +199,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) ) /* End of CASE */ CASE(ADPCM_ARGO, avctx->frame_size = 32; - avctx->block_align = 17 * avctx->channels; + avctx->block_align = 17 * channels; ) /* End of CASE */ CASE(ADPCM_IMA_WS, /* each 16 bits sample gives one nibble */ - avctx->frame_size = s->block_size * 2 / avctx->channels; + avctx->frame_size = s->block_size * 2 / channels; avctx->block_align = s->block_size; ) /* End of CASE */ default: @@ -606,16 +602,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int16_t **samples_p; uint8_t *dst; ADPCMEncodeContext *c = avctx->priv_data; + int channels = avctx->ch_layout.nb_channels; samples = (const int16_t *)frame->data[0]; samples_p = (int16_t **)frame->extended_data; - st = avctx->channels == 2; + st = channels == 2; if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI || avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_ALP || avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM || avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_WS) - pkt_size = (frame->nb_samples * avctx->channels) / 2; + pkt_size = (frame->nb_samples * channels) / 2; else pkt_size = avctx->block_align; if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0) @@ -626,7 +623,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, CASE(ADPCM_IMA_WAV, int blocks = (frame->nb_samples - 1) / 8; - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { ADPCMChannelStatus *status = &c->status[ch]; status->prev_sample = samples_p[ch][0]; /* status->step_index = 0; @@ -639,15 +636,15 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, /* stereo: 4 bytes (8 samples) for left, 4 bytes for right */ if (avctx->trellis > 0) { uint8_t *buf; - if (!FF_ALLOC_TYPED_ARRAY(buf, avctx->channels * blocks * 8)) + if (!FF_ALLOC_TYPED_ARRAY(buf, channels * blocks * 8)) return AVERROR(ENOMEM); - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { adpcm_compress_trellis(avctx, &samples_p[ch][1], buf + ch * blocks * 8, &c->status[ch], blocks * 8, 1); } for (int i = 0; i < blocks; i++) { - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { uint8_t *buf1 = buf + ch * blocks * 8 + i * 8; for (int j = 0; j < 8; j += 2) *dst++ = buf1[j] | (buf1[j + 1] << 4); @@ -656,7 +653,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_free(buf); } else { for (int i = 0; i < blocks; i++) { - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { ADPCMChannelStatus *status = &c->status[ch]; const int16_t *smp = &samples_p[ch][1 + i * 8]; for (int j = 0; j < 8; j += 2) { @@ -672,7 +669,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, PutBitContext pb; init_put_bits(&pb, dst, pkt_size); - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { ADPCMChannelStatus *status = &c->status[ch]; put_bits(&pb, 9, (status->prev_sample & 0xFFFF) >> 7); put_bits(&pb, 7, status->step_index); @@ -703,7 +700,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(avctx->trellis == 0); for (int i = 0; i < frame->nb_samples; i++) { - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++)); } } @@ -717,11 +714,11 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(avctx->trellis == 0); for (int n = frame->nb_samples / 2; n > 0; n--) { - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, *samples++)); put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, samples[st])); } - samples += avctx->channels; + samples += channels; } flush_put_bits(&pb); @@ -738,7 +735,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, put_bits(&pb, 2, 2); // set 4-bit flash adpcm format // init the encoder state - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { // clip step so it fits 6 bits c->status[i].step_index = av_clip_uintp2(c->status[i].step_index, 6); put_sbits(&pb, 16, samples[i]); @@ -748,22 +745,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (avctx->trellis > 0) { uint8_t buf[8190 /* = 2 * n */]; - adpcm_compress_trellis(avctx, samples + avctx->channels, buf, - &c->status[0], n, avctx->channels); - if (avctx->channels == 2) - adpcm_compress_trellis(avctx, samples + avctx->channels + 1, + adpcm_compress_trellis(avctx, samples + channels, buf, + &c->status[0], n, channels); + if (channels == 2) + adpcm_compress_trellis(avctx, samples + channels + 1, buf + n, &c->status[1], n, - avctx->channels); + channels); for (int i = 0; i < n; i++) { put_bits(&pb, 4, buf[i]); - if (avctx->channels == 2) + if (channels == 2) put_bits(&pb, 4, buf[n + i]); } } else { for (int i = 1; i < frame->nb_samples; i++) { put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], - samples[avctx->channels * i])); - if (avctx->channels == 2) + samples[channels * i])); + if (channels == 2) put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2 * i + 1])); } @@ -771,47 +768,47 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, flush_put_bits(&pb); ) /* End of CASE */ CASE(ADPCM_MS, - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { int predictor = 0; *dst++ = predictor; c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor]; c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor]; } - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { if (c->status[i].idelta < 16) c->status[i].idelta = 16; bytestream_put_le16(&dst, c->status[i].idelta); } - for (int i = 0; i < avctx->channels; i++) + for (int i = 0; i < channels; i++) c->status[i].sample2= *samples++; - for (int i = 0; i < avctx->channels; i++) { + for (int i = 0; i < channels; i++) { c->status[i].sample1 = *samples++; bytestream_put_le16(&dst, c->status[i].sample1); } - for (int i = 0; i < avctx->channels; i++) + for (int i = 0; i < channels; i++) bytestream_put_le16(&dst, c->status[i].sample2); if (avctx->trellis > 0) { - const int n = avctx->block_align - 7 * avctx->channels; + const int n = avctx->block_align - 7 * channels; uint8_t *buf = av_malloc(2 * n); if (!buf) return AVERROR(ENOMEM); - if (avctx->channels == 1) { + if (channels == 1) { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, - avctx->channels); + channels); for (int i = 0; i < n; i += 2) *dst++ = (buf[i] << 4) | buf[i + 1]; } else { adpcm_compress_trellis(avctx, samples, buf, - &c->status[0], n, avctx->channels); + &c->status[0], n, channels); adpcm_compress_trellis(avctx, samples + 1, buf + n, - &c->status[1], n, avctx->channels); + &c->status[1], n, channels); for (int i = 0; i < n; i++) *dst++ = (buf[i] << 4) | buf[n + i]; } av_free(buf); } else { - for (int i = 7 * avctx->channels; i < avctx->block_align; i++) { + for (int i = 7 * channels; i < avctx->block_align; i++) { int nibble; nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++) << 4; nibble |= adpcm_ms_compress_sample(&c->status[st], *samples++); @@ -826,22 +823,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (!buf) return AVERROR(ENOMEM); n *= 2; - if (avctx->channels == 1) { + if (channels == 1) { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, - avctx->channels); + channels); for (int i = 0; i < n; i += 2) *dst++ = buf[i] | (buf[i + 1] << 4); } else { adpcm_compress_trellis(avctx, samples, buf, - &c->status[0], n, avctx->channels); + &c->status[0], n, channels); adpcm_compress_trellis(avctx, samples + 1, buf + n, - &c->status[1], n, avctx->channels); + &c->status[1], n, channels); for (int i = 0; i < n; i++) *dst++ = buf[i] | (buf[n + i] << 4); } av_free(buf); } else - for (n *= avctx->channels; n > 0; n--) { + for (n *= channels; n > 0; n--) { int nibble; nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++); nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4; @@ -855,17 +852,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(avctx->trellis == 0); for (int n = frame->nb_samples / 2; n > 0; n--) { - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++)); put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, samples[st])); } - samples += avctx->channels; + samples += channels; } flush_put_bits(&pb); ) /* End of CASE */ CASE(ADPCM_IMA_AMV, - av_assert0(avctx->channels == 1); + av_assert0(channels == 1); c->status[0].prev_sample = *samples; bytestream_put_le16(&dst, c->status[0].prev_sample); @@ -880,7 +877,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (!buf) return AVERROR(ENOMEM); - adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, avctx->channels); + adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, channels); for (int i = 0; i < n; i++) bytestream_put_byte(&dst, (buf[2 * i] << 4) | buf[2 * i + 1]); @@ -904,7 +901,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(frame->nb_samples == 32); - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { int64_t error = INT64_MAX, tmperr = INT64_MAX; int shift = 2, flag = 0; int saved1 = c->status[ch].sample1; @@ -941,14 +938,14 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(avctx->trellis == 0); for (int n = frame->nb_samples / 2; n > 0; n--) { /* stereo: 1 byte (2 samples) for left, 1 byte for right */ - for (int ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < channels; ch++) { int t1, t2; t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++); t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]); put_bits(&pb, 4, t2); put_bits(&pb, 4, t1); } - samples += avctx->channels; + samples += channels; } flush_put_bits(&pb); ) /* End of CASE */ @@ -968,6 +965,12 @@ static const enum AVSampleFormat sample_fmts_p[] = { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }; +static const AVChannelLayout ch_layouts[] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + { 0 }, +}; + static const AVOption options[] = { { .name = "block_size", @@ -1001,6 +1004,7 @@ const AVCodec ff_ ## name_ ## _encoder = { \ .encode2 = adpcm_encode_frame, \ .close = adpcm_encode_close, \ .sample_fmts = sample_fmts_, \ + .ch_layouts = ch_layouts, \ .capabilities = capabilities_ | AV_CODEC_CAP_DR1, \ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, \ .priv_class = &adpcm_encoder_class, \ From patchwork Wed Dec 8 01:06:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32150 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7046911iog; Tue, 7 Dec 2021 17:11:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyV/hNKatbM4uVOZn7TpBU8GSvQZJJlaKJxbNtdrN62kqLGGyXGNQdqiTmC2J9tZk1B1j/B X-Received: by 2002:a05:6402:1e8b:: with SMTP id f11mr14653431edf.304.1638925910906; Tue, 07 Dec 2021 17:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925910; cv=none; d=google.com; s=arc-20160816; b=xyS7eMzkft8eRWhZ7HtLIwZ9t0opOIgPk67fyb943RLhdNMAoJtjlOQwSMRJB2Lqkp UthFFGTJBy60pUWkHjlZPV+DTtMpVsxQWv8IgIQ5HpnrXDEeMWgrsuSW/eGqp8KHDe+U cisddKriFMVM23UPd3nxYP07UVQCqcCnpmR++5n1jYPOOJB7Bihx7FBEFam7pnIJ5m+l XZMvUCt7FV4hLdZSHaliNpKd2MIDMRZmqs2sTNb0El1h+77uDfoAkgn+Tha8rzZhIFxA VHgwb09mo7899wCQ5ByFsO2EGvRZt0wrU+cX6OR7Jo1/zt6/+aTcrettgo8rVGpA9Oe/ uN+g== 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=JDCTqzbwwij+yrYFlMJ3zUnZWj0oI+ZDEGq5bgDfi4c=; b=S27TAV8BuNH8BFf9UNzhyHVfmXASUIXTm1oQRwtex8SvhwMfxQs8rm2TPRmUbspf9q pViZKUEItUL1QfOAPwJ2P3BzUia4vj5wvCUuEAFCq6s7VxjRK99E0maw1DunsgXXgAp0 ipOJicL8dNfbsW8JenFX8HzH1i4trHntfffzuNpddvDQ/4Vguh1A2oZ+5q1AkIEncVjn axlVZgUda3EsA0CISyf9ZQwcLgHj/FnWjCR65iA3kGlER2TRHbVIDo78C9YU4hahI4KM KN24uhsbPHP9/EjRt2h0/UNaH1egsnmCgSuyScjZ3P6ZlnaTsAR22CuAGQlQCJzbb6S9 PRcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=D22mFheK; 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 qb38si2495399ejc.165.2021.12.07.17.11.44; Tue, 07 Dec 2021 17:11:50 -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=D22mFheK; 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 E0E3468AF2C; Wed, 8 Dec 2021 03:08:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E8F568AF2C for ; Wed, 8 Dec 2021 03:07:59 +0200 (EET) Received: by mail-ua1-f51.google.com with SMTP id o1so1932562uap.4 for ; Tue, 07 Dec 2021 17:07:59 -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=otFIrGlK/AFqctJcFoKP9vtS+3aGtuvWoRY5M1mjKq8=; b=D22mFheK8QZAyq+8YKb67trUTg6PYuH4r92WX34zgMiqy6b1Jk1bohBeWjXNPAx2jG Hml3VKa0k9LXQyVaaRA7E6X+DjP6jODMXUZGJMYplituMmogX1fER33WC3zOUNwCLVsn k41Cs56/PdPtaJq1bqNFbUsZaVp+HXqc9gDtY/y+Gf2ZCHyz71e2QG1HBlOf7ns6EGbE wWlweC7xwCcXQQlgCXjERUfV+4aTH8Gkzz0LBKucyBd9+Atj4IAl2lbL3/FFFcOe+lrD 0K5kGtjoAcvqUkemQ8mFpgIhWKI6NxjkdD/nhmSi/iwTUOWRDQcqynXk9SlmUolOGrjE 1gwA== 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=otFIrGlK/AFqctJcFoKP9vtS+3aGtuvWoRY5M1mjKq8=; b=kLZW9OHLiloVyW0dMznxkxJ5hMUTT/7839p8qJDdzzoxgdA0hFzt9D9Yq4zAeMlEOp O1QvlooLaMjTu8im25z6cN8r8iItvX3AXWIpQUXsmdwg1uKWT8PJ/l0gHHkssVBnTSAr xghjC8MRwiZH53VZkHK7vcTmuUZk4RMAyhIdp8dv/qQfTfrwZegMgxeaerlYIqaPwXQr ykFQGPfm/zV3bvLizKjwJ1GUvdE5IU0Zfw+PUxZ84jS258vmqO+WSAkcw1K/QqP3s8Ot rrYsoie5LPLrLEf0Bx9cwAg3A4H25PrKOeFZDfg09yuBtiGpocmxNo/o7bSqlgpf63ev ycuw== X-Gm-Message-State: AOAM531scNE6CX/Svd3uLiJrZmL7BaEICok8/cQItHs+Vge58N3CjMG+ n0Lxmr7OxMFHfSeuahGcNlUAPv2TqQ0Vx87S X-Received: by 2002:a05:6102:199:: with SMTP id r25mr49923139vsq.44.1638925677038; Tue, 07 Dec 2021 17:07:57 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:56 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:39 -0300 Message-Id: <20211208010649.381-24-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 184/279] adx: 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: jepCOY4zQ0bq From: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/adx.c | 16 +++++++++++----- libavcodec/adxdec.c | 6 +++--- libavcodec/adxenc.c | 11 ++++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/libavcodec/adx.c b/libavcodec/adx.c index cd88b16660..c60fabb40b 100644 --- a/libavcodec/adx.c +++ b/libavcodec/adx.c @@ -38,7 +38,7 @@ void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff) int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, int bufsize, int *header_size, int *coeff) { - int offset, cutoff; + int offset, cutoff, channels; if (bufsize < 24) return AVERROR_INVALIDDATA; @@ -58,18 +58,24 @@ int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, } /* channels */ - avctx->channels = buf[7]; - if (avctx->channels <= 0 || avctx->channels > 2) + channels = buf[7]; + if (channels <= 0 || channels > 2) return AVERROR_INVALIDDATA; + if (avctx->ch_layout.nb_channels != channels) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = channels; + } + /* sample rate */ avctx->sample_rate = AV_RB32(buf + 8); if (avctx->sample_rate < 1 || - avctx->sample_rate > INT_MAX / (avctx->channels * BLOCK_SIZE * 8)) + avctx->sample_rate > INT_MAX / (channels * BLOCK_SIZE * 8)) return AVERROR_INVALIDDATA; /* bit rate */ - avctx->bit_rate = avctx->sample_rate * avctx->channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES; + avctx->bit_rate = avctx->sample_rate * channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES; /* LPC coefficients */ if (coeff) { diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c index 20256a092e..b3d946e81c 100644 --- a/libavcodec/adxdec.c +++ b/libavcodec/adxdec.c @@ -46,7 +46,7 @@ static av_cold int adx_decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); return AVERROR_INVALIDDATA; } - c->channels = avctx->channels; + c->channels = avctx->ch_layout.nb_channels; c->header_parsed = 1; } @@ -132,7 +132,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); return AVERROR_INVALIDDATA; } - c->channels = avctx->channels; + c->channels = avctx->ch_layout.nb_channels; c->header_parsed = 1; if (buf_size < header_size) return AVERROR_INVALIDDATA; @@ -147,7 +147,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF packet */ - if (!num_blocks || buf_size % (BLOCK_SIZE * avctx->channels)) { + if (!num_blocks || buf_size % (BLOCK_SIZE * c->channels)) { if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) { c->eof = 1; *got_frame_ptr = 0; diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c index c5849a40a1..3736e746a9 100644 --- a/libavcodec/adxenc.c +++ b/libavcodec/adxenc.c @@ -107,7 +107,7 @@ static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize) bytestream_put_byte(&buf, 3); /* encoding */ bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */ bytestream_put_byte(&buf, 4); /* sample size */ - bytestream_put_byte(&buf, avctx->channels); /* channels */ + bytestream_put_byte(&buf, avctx->ch_layout.nb_channels); /* channels */ bytestream_put_be32(&buf, avctx->sample_rate); /* sample rate */ bytestream_put_be32(&buf, 0); /* total sample count */ bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */ @@ -125,7 +125,7 @@ static av_cold int adx_encode_init(AVCodecContext *avctx) { ADXContext *c = avctx->priv_data; - if (avctx->channels > 2) { + if (avctx->ch_layout.nb_channels > 2) { av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); return AVERROR(EINVAL); } @@ -144,6 +144,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ADXContext *c = avctx->priv_data; const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL; uint8_t *dst; + int channels = avctx->ch_layout.nb_channels; int ch, out_size, ret; if (!samples) { @@ -162,7 +163,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return 0; } - out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE; + out_size = BLOCK_SIZE * channels + !c->header_parsed * HEADER_SIZE; if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0) return ret; dst = avpkt->data; @@ -177,8 +178,8 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, c->header_parsed = 1; } - for (ch = 0; ch < avctx->channels; ch++) { - adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels); + for (ch = 0; ch < channels; ch++) { + adx_encode(c, dst, samples + ch, &c->prev[ch], channels); dst += BLOCK_SIZE; } From patchwork Wed Dec 8 01:06:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32149 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047307iog; Tue, 7 Dec 2021 17:12:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMx/gRIj2dXIkNLlSImamCQziZwjaaFNZHwMtwEF5FnY3UOtt7JwFXF4Iy9wgRRrslOLeo X-Received: by 2002:a17:906:81cb:: with SMTP id e11mr3492320ejx.186.1638925933071; Tue, 07 Dec 2021 17:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925933; cv=none; d=google.com; s=arc-20160816; b=gTT8USux0cFxnifA5/agRV7tp/FJt1WCLopT5DxwocmmesRR39pdsBgnUYwffa0vol vOnZFQWFSEWSYiwG0z0wnUhHyoSM5VHvqDNsSxMWNVfh+/iGo9uXSDuxT4iRyb9UDQtR 7zerlQCQ/NebgBLU/JmsqU9qVqG6JAhFsc1UZse1Cte5vz7kG1OAa5HbyPq3+abeIeDo d/OtY2cfU9bpns+Hao5Gf0xktwY4iuYdHMWAVxvnerIJdMFPSo5u9dartqGA/uYNSjyj ygiAVDscyHaN/rbSzHmS81IGeD+RnbkDZluFIB0B+i3kEkzfTrqsc+VOPlDSFMSDy0+8 mltQ== 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=UVQzWWQcW8lzMP7S5X7IB21jtzoTnhkKVxKehswDZdM=; b=LlW1qKKwrxAbmvJ4zFBd7lGxEqIhv17mxYskUzaUPcsy4QICXp9MJrmEtWX2KZsAyK YL3aUk/8R2/5k7hRdQyt1xibCIZ95MLwph+ruN8gOp8qfuTzrx0So6aQDOORszk75ZIP +xOVfCQpQJDc4bT2gyINhJ6kJUIG1Ey1c9BwkuCNYvbxIBfAvLJjZ7s/5RN8IcQUCBdX 0hbXbI3NClrUqdEk1CsN4iqjk3MsLzdHpD/+2SKyqu9sv9hSeb/hgUgwURX4QbCFVIti /Kil9TcpNpiQCXQrxwJpib7n5SRcHIRBywcDeF/EtyR4OX9jyy3d6rpInc6Q6BLzfAcn 1fNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=edX4ht7p; 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 nd9si2747411ejc.154.2021.12.07.17.12.08; Tue, 07 Dec 2021 17:12:13 -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=edX4ht7p; 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 7C95168AF71; Wed, 8 Dec 2021 03:08:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA55768AF45 for ; Wed, 8 Dec 2021 03:07:59 +0200 (EET) Received: by mail-ua1-f51.google.com with SMTP id w23so1919887uao.5 for ; Tue, 07 Dec 2021 17:07:59 -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=MUJd3JvZgsGU/NSwl+dok4id6Yy/tniZxXkaxjj3eIQ=; b=edX4ht7pnurrsg6/H64rcbsq4W5HlDKAwEnRWBWN8vDO2DqF8cHXbHcW1PI2X8Mt9C AHoPxw8tlTBt2xMrnqoXCqr7ty80fVpxaOlhFkd+7UtN/35p8mXqnfVHR2PxvrxJG9j+ HVPz2oMXAoelfpdyjO7z/lPQwWtKuw6U0l2xI7CIHElwAXXAdhMkS1zl3jKugHjKjVBO dxO5v4Rm716Iht0ED4G5jrVshwqKnZWv2z20VM3BsYwi9Q0hlzmCqFVF3DknmK839Q2u GU7Zyv3l4+o1kJpY/os9/qbLqracNRFKE9LStOeNyutyYtl+S0rhfMvZqn+qJXhCgvxf ilHA== 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=MUJd3JvZgsGU/NSwl+dok4id6Yy/tniZxXkaxjj3eIQ=; b=iOW7Js+l6+DFNh2qOkLx5jRVEp8K2WqBwQBooE31AeLc6FBkyB12mYLk2sauDdr9Qv hJb1aM0svKYi3U+G7aWtU/Mqnpeker+G61XpD7/+At5un7DRY1Orx5ciljdQrtnH84J6 ZedduClO9iGOry4IuioDSsQ7+Xur/+/955EFY0YoJKi0DI7Md5iMY8NwDLAB0paZma8G 6faExUcoWNCP6TzwItzNz1NiBJnk19+DUbL3THccpyaOGzwrD+LFJPknfkqe3M0AIpG9 GnF9+fZbYKbzmnXvsWkoE8HOZQixi2fn6hT1t6e2qMDO6R9/q8bIvZpQ49LNNhYylGXI JHNA== X-Gm-Message-State: AOAM53079CbQi97UbMMv/pFWqQo8/r3DSlReBEe2pFpsBI8UwF1mDtL6 GMaLs2Z4NaWB4jFe+yhXpOwnRRU8j5VyfqmN X-Received: by 2002:a67:e0c9:: with SMTP id m9mr48770806vsl.63.1638925678202; Tue, 07 Dec 2021 17:07:58 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:57 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:40 -0300 Message-Id: <20211208010649.381-25-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 185/279] alac: 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: WmznoyNBUDj9 From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/alac.c | 16 ++++++---------- libavcodec/alac_data.c | 20 ++++++++++---------- libavcodec/alac_data.h | 6 ++++++ libavcodec/alacenc.c | 37 +++++++++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 28 deletions(-) diff --git a/libavcodec/alac.c b/libavcodec/alac.c index 67fc2a3e41..db1e725f66 100644 --- a/libavcodec/alac.c +++ b/libavcodec/alac.c @@ -576,21 +576,17 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) avctx->bits_per_raw_sample = alac->sample_size; avctx->sample_rate = alac->sample_rate; - if (alac->channels < 1) { + if (alac->channels < 1 || alac->channels > ALAC_MAX_CHANNELS) { av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n"); - alac->channels = avctx->channels; - } else { - if (alac->channels > ALAC_MAX_CHANNELS) - alac->channels = avctx->channels; - else - avctx->channels = alac->channels; + alac->channels = avctx->ch_layout.nb_channels; } - if (avctx->channels > ALAC_MAX_CHANNELS || avctx->channels <= 0 ) { + if (avctx->ch_layout.nb_channels > ALAC_MAX_CHANNELS || avctx->ch_layout.nb_channels <= 0 ) { avpriv_report_missing_feature(avctx, "Channel count %d", - avctx->channels); + avctx->ch_layout.nb_channels); return AVERROR_PATCHWELCOME; } - avctx->channel_layout = ff_alac_channel_layouts[alac->channels - 1]; + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = ff_alac_ch_layouts[alac->channels - 1]; if ((ret = allocate_buffers(alac)) < 0) { av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n"); diff --git a/libavcodec/alac_data.c b/libavcodec/alac_data.c index 0bcb06c075..d8ed53f444 100644 --- a/libavcodec/alac_data.c +++ b/libavcodec/alac_data.c @@ -32,16 +32,16 @@ const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNEL { 2, 6, 7, 0, 1, 4, 5, 3 } }; -const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = { - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_SURROUND, - AV_CH_LAYOUT_4POINT0, - AV_CH_LAYOUT_5POINT0_BACK, - AV_CH_LAYOUT_5POINT1_BACK, - AV_CH_LAYOUT_6POINT1_BACK, - AV_CH_LAYOUT_7POINT1_WIDE_BACK, - 0 +const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_4POINT0, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + AV_CHANNEL_LAYOUT_5POINT1_BACK, + AV_CHANNEL_LAYOUT_6POINT1_BACK, + AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK, + { 0 } }; const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5] = { diff --git a/libavcodec/alac_data.h b/libavcodec/alac_data.h index 650d6dcd15..a68a5f2648 100644 --- a/libavcodec/alac_data.h +++ b/libavcodec/alac_data.h @@ -23,6 +23,8 @@ #include +#include "libavutil/channel_layout.h" + enum AlacRawDataBlockType { /* At the moment, only SCE, CPE, LFE, and END are recognized. */ TYPE_SCE, @@ -39,7 +41,11 @@ enum AlacRawDataBlockType { extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS]; +extern const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1]; + +#if FF_API_OLD_CHANNEL_LAYOUT extern const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1]; +#endif extern const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5]; diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c index a38aa6e7d7..09af0584bc 100644 --- a/libavcodec/alacenc.c +++ b/libavcodec/alacenc.c @@ -462,14 +462,15 @@ static int write_frame(AlacEncodeContext *s, AVPacket *avpkt, uint8_t * const *samples) { PutBitContext *pb = &s->pbctx; - const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[s->avctx->channels - 1]; - const uint8_t *ch_map = ff_alac_channel_layout_offsets[s->avctx->channels - 1]; + int channels = s->avctx->ch_layout.nb_channels; + const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[channels - 1]; + const uint8_t *ch_map = ff_alac_channel_layout_offsets[channels - 1]; int ch, element, sce, cpe; init_put_bits(pb, avpkt->data, avpkt->size); ch = element = sce = cpe = 0; - while (ch < s->avctx->channels) { + while (ch < channels) { if (ch_elements[element] == TYPE_CPE) { write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]], samples[ch_map[ch + 1]]); @@ -532,7 +533,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) s->rc.rice_modifier = 4; s->max_coded_frame_size = get_max_frame_size(avctx->frame_size, - avctx->channels, + avctx->ch_layout.nb_channels, avctx->bits_per_raw_sample); avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); @@ -545,10 +546,10 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c')); AV_WB32(alac_extradata+12, avctx->frame_size); AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample); - AV_WB8 (alac_extradata+21, avctx->channels); + AV_WB8 (alac_extradata+21, avctx->ch_layout.nb_channels); AV_WB32(alac_extradata+24, s->max_coded_frame_size); AV_WB32(alac_extradata+28, - avctx->sample_rate * avctx->channels * avctx->bits_per_raw_sample); // average bitrate + avctx->sample_rate * avctx->ch_layout.nb_channels * avctx->bits_per_raw_sample); // average bitrate AV_WB32(alac_extradata+32, avctx->sample_rate); // Set relevant extradata fields @@ -585,7 +586,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->frame_size = frame->nb_samples; if (frame->nb_samples < DEFAULT_FRAME_SIZE) - max_frame_size = get_max_frame_size(s->frame_size, avctx->channels, + max_frame_size = get_max_frame_size(s->frame_size, avctx->ch_layout.nb_channels, avctx->bits_per_raw_sample); else max_frame_size = s->max_coded_frame_size; @@ -616,6 +617,21 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return 0; } +#if FF_API_OLD_CHANNEL_LAYOUT +const uint64_t alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = { + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_SURROUND, + AV_CH_LAYOUT_4POINT0, + AV_CH_LAYOUT_5POINT0_BACK, + AV_CH_LAYOUT_5POINT1_BACK, + AV_CH_LAYOUT_6POINT1_BACK, + AV_CH_LAYOUT_7POINT1_WIDE_BACK, + 0 +}; +#endif + + #define OFFSET(x) offsetof(AlacEncodeContext, x) #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@ -632,6 +648,7 @@ static const AVClass alacenc_class = { .version = LIBAVUTIL_VERSION_INT, }; +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_alac_encoder = { .name = "alac", .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), @@ -643,9 +660,13 @@ const AVCodec ff_alac_encoder = { .encode2 = alac_encode_frame, .close = alac_encode_close, .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, - .channel_layouts = ff_alac_channel_layouts, +#if FF_API_OLD_CHANNEL_LAYOUT + .channel_layouts = alac_channel_layouts, +#endif + .ch_layouts = ff_alac_ch_layouts, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; +FF_ENABLE_DEPRECATION_WARNINGS From patchwork Wed Dec 8 01:06:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32132 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047488iog; Tue, 7 Dec 2021 17:12:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmQjxs1M8iXz+fA7TN28CtqYM2xrcdFmwy8hKmeCoegC1i5jS0nLLcYoApPrbtquYqJS6r X-Received: by 2002:aa7:c30e:: with SMTP id l14mr14433945edq.370.1638925943203; Tue, 07 Dec 2021 17:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925943; cv=none; d=google.com; s=arc-20160816; b=Jvnp0zdMKiG6FW5CgDzSEQvFI7WLdU3r1jUzSILwF6J/Gs7bQVUz7CDf++Y8YjC8g8 Cl5RpZROIacOSz4bvWfyLYdEFXjHxUdpkmZl15i0yLDUDzzFvDYVDkInpC5SKKYY3CmP raTUvlSQKeONy1jkd4++Nzul/kIST46ngoPyZE5YVZiOX44Gvrg5RQyFxgkWS/kxjiGV CW7o23RbIbhIuCQMKMCwmQa4INc1/zjml6qpofXX51mryHRaYkNP3jFjd5KkRwe9He++ Du1DgYiBXHXzx8hRJObc/ayjMjjuE8foVhkQHX8wPF76ZTJZEBxgU/qn3uzbTv/GW+SJ m94g== 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=XUdi668tbU34I/lDpf/UEGRHjjG9O8+kkv2ySyeqEuE=; b=0ML087nTr6wjtssTfe59FpvFQ1gqDG9ZBfht7fmhuJCvd+LX94W2Se5pHpet2W/iTz GcLAYl24tpt/MwQVorCSl8ystfMcYJs52OLpMIDZqpv9glRoETZW20nb3BxZoAj+JASH Srs4Ybyp8Gy8FsFrvT7jE1Arf31z+f7/9dha19R2VmWk40Gu+8j3ybIEHJRwjDxE0fCW Ab/yDd/o4j3ymev2aJGwJo65udab1SBFgUxz8lLuFg58T2AdohCrDxesZfThTiJWCrwt I3jHFFdES/xMRrtW/x4h9yO97V+ptz7uwfSPS+FobZjIBlZCl0xOTGNmQz0+VbjvdTz1 KtBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=DSRbBE7y; 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 c14si2002802edn.629.2021.12.07.17.12.20; Tue, 07 Dec 2021 17:12: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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=DSRbBE7y; 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 56F6E68AF7A; Wed, 8 Dec 2021 03:08:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1921D68AF3B for ; Wed, 8 Dec 2021 03:08:01 +0200 (EET) Received: by mail-ua1-f45.google.com with SMTP id l24so1954029uak.2 for ; Tue, 07 Dec 2021 17:08:01 -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=Brudn/FkW7HNIRG/9terOp7dJBjp5wkNgR0a0HuWl64=; b=DSRbBE7yTaZi1HuuXxV1u3ut9UkveVBnZvx/q9ar4c2Ryrt5JqmLRtadJJwvQL5chJ u0IIzyaixhykj2ZmlnypHZar6FqBnYt70TsQl/QhqJ2jzgm2Z0+lpjStVuuNrcOXYRZ1 v/LhUPe1jQ4OzdI0KVEHfYLXnb0wsUBAel92OSKR7ZkbT4e4vD1MLTUgjl9pL7JEivbb ucJx8xddMQIB1AEA+UVspuMtvabIZGfo1HZcjtLqBjxAh+ZeGnM0LGK+ltw3Jwj1WHVA zv+pTuNe/fnPECywqUQMmb30Rn0BmOS4m3Zw23g3SZya7+e21Bi9KB3Zoz7rK+NYWX14 7XRA== 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=Brudn/FkW7HNIRG/9terOp7dJBjp5wkNgR0a0HuWl64=; b=AAA9Ldsa4IicLIzT8I4D7ALtI72i3EFCkKb/TuJIbu7ICne4UgFSED3KmU/Cc0NaU3 YYnTAqW+VUHVwfz4fns5cICNlOtBMkXSwe7zZ5lPTQnzyAXFKrz3ZBQO/8X6vbbdlwsj 9R8nDUAr5b/Rvh1RU7tg6Ld5TuWicdpea4Uxp8Jg/FfLHvFgoDOf1rpjw80NHsyfmoId LEYjhoU1L2DoaOT16DSX2q9eQ4K96xHoEm/FNhV3Edik4linSHreVavbXROoS9/HCWZE AaAYFXFl9iqKZ6xMcpRLx0wbdKNwCDhguF+6AFi8pwFKr+ommmV0Pw9tW8UiPtIF4sVm TOpA== X-Gm-Message-State: AOAM533JVKYyJ8M3xUH7bTOvnhGmW/u6A1+649IFXTIO3wglbLm2tl9q VxTn8EQ0Hfenxf6Nq1f4+vHCmGzD8+MO0SYx X-Received: by 2002:a05:6102:c4d:: with SMTP id y13mr49833086vss.43.1638925679469; Tue, 07 Dec 2021 17:07:59 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:59 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:41 -0300 Message-Id: <20211208010649.381-26-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 271/279] lavc: drop temporary compat wrappers for channel layout API change 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: w2/LVyF927iq From: Anton Khirnov Signed-off-by: James Almer --- libavcodec/aacdec_template.c | 7 ------- libavcodec/avcodec.c | 29 ----------------------------- libavcodec/dca_lbr.c | 7 ------- libavcodec/dcadec.c | 8 -------- libavcodec/decode.c | 20 -------------------- libavcodec/encode.c | 15 --------------- 6 files changed, 86 deletions(-) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 387a4acfce..349ecdefb3 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -592,13 +592,6 @@ FF_ENABLE_DEPRECATION_WARNINGS } av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout); -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - avctx->channels = avctx->ch_layout.nb_channels; - avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - avctx->ch_layout.u.mask : 0; -FF_ENABLE_DEPRECATION_WARNINGS -#endif ac->oc[1].status = oc_type; if (get_new_frame) { diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 4c576a848c..35a6bf9bfe 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -137,8 +137,6 @@ static int64_t get_bit_rate(AVCodecContext *ctx) int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options) { int ret = 0; - int orig_channels; - uint64_t orig_channel_layout; AVCodecInternal *avci; if (avcodec_is_open(avctx)) @@ -275,14 +273,6 @@ FF_DISABLE_DEPRECATION_WARNINGS avctx->ch_layout.nb_channels = avctx->channels; } } - - /* temporary compat wrapper for new-style callers and old-style codecs; - * to be removed once all the codecs have been converted */ - if (avctx->ch_layout.nb_channels) { - avctx->channels = avctx->ch_layout.nb_channels; - avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - avctx->ch_layout.u.mask : 0; - } FF_ENABLE_DEPRECATION_WARNINGS #endif @@ -345,13 +335,6 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) avctx->thread_count = 1; -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - orig_channels = avctx->channels; - orig_channel_layout = avctx->channel_layout; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - if (!(avctx->active_thread_type & FF_THREAD_FRAME) || avci->frame_thread_encoder) { if (avctx->codec->init) { @@ -372,18 +355,6 @@ FF_ENABLE_DEPRECATION_WARNINGS #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS - /* decoder setting the old-style fields */ - if (avctx->channels != orig_channels || - avctx->channel_layout != orig_channel_layout) { - av_channel_layout_uninit(&avctx->ch_layout); - if (avctx->channel_layout) { - av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout); - } else { - avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - avctx->ch_layout.nb_channels = avctx->channels; - } - } - /* update the deprecated fields for old-style callers */ avctx->channels = avctx->ch_layout.nb_channels; avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c index c11f2f7e18..527bc8b7c0 100644 --- a/libavcodec/dca_lbr.c +++ b/libavcodec/dca_lbr.c @@ -1744,13 +1744,6 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame) av_channel_layout_uninit(&avctx->ch_layout); av_channel_layout_from_mask(&avctx->ch_layout, channel_mask); -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - avctx->channels = avctx->ch_layout.nb_channels; - avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - avctx->ch_layout.u.mask : 0; -FF_ENABLE_DEPRECATION_WARNINGS -#endif frame->nb_samples = 1024 << s->freq_range; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c index 239ed9ac91..9f40da20fc 100644 --- a/libavcodec/dcadec.c +++ b/libavcodec/dcadec.c @@ -78,14 +78,6 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask av_channel_layout_from_mask(&avctx->ch_layout, wav_mask); } -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - avctx->channels = avctx->ch_layout.nb_channels; - avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - avctx->ch_layout.u.mask : 0; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - return nchannels; } diff --git a/libavcodec/decode.c b/libavcodec/decode.c index aa74c677ef..24357a4d09 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1690,26 +1690,6 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS - /* temporary compat layer for decoders setting the old-style channel - * layout fields; shall be removed after all the decoders are converted - * to the new API */ - if ((avctx->channels > 0 && avctx->ch_layout.nb_channels != avctx->channels) || - (avctx->channel_layout && (avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || - avctx->ch_layout.u.mask != avctx->channel_layout))) { - av_channel_layout_uninit(&avctx->ch_layout); - if (avctx->channel_layout) { - if (av_popcount64(avctx->channel_layout) != avctx->channels) { - av_log(avctx, AV_LOG_ERROR, "Inconsistent channel layout/channels\n"); - ret = AVERROR(EINVAL); - goto fail; - } - av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout); - } else { - avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - avctx->ch_layout.nb_channels = avctx->channels; - } - } - /* compat layer for old-style get_buffer() implementations */ avctx->channels = avctx->ch_layout.nb_channels; avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ? diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 0dd5e3fdd1..af274a5cc5 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -490,21 +490,6 @@ int ff_encode_preinit(AVCodecContext *avctx) FF_DISABLE_DEPRECATION_WARNINGS } #if FF_API_OLD_CHANNEL_LAYOUT - else if (avctx->codec->channel_layouts) { - if (!avctx->channel_layout) { - av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n"); - } else { - for (i = 0; avctx->codec->channel_layouts[i] != 0; i++) - if (avctx->channel_layout == avctx->codec->channel_layouts[i]) - break; - if (avctx->codec->channel_layouts[i] == 0) { - char buf[512]; - av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout); - av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf); - return AVERROR(EINVAL); - } - } - } if (avctx->channel_layout && avctx->channels) { int channels = av_get_channel_layout_nb_channels(avctx->channel_layout); if (channels != avctx->channels) { From patchwork Wed Dec 8 01:06:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32139 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047660iog; Tue, 7 Dec 2021 17:12:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1UMMOSib4X313lCXgaNpkQ5xQw5NXq6meHkZYWH35B9b28mPoKeJIxOTLWKWzFex5Il3k X-Received: by 2002:a05:6402:42c6:: with SMTP id i6mr14418904edc.223.1638925952800; Tue, 07 Dec 2021 17:12:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925952; cv=none; d=google.com; s=arc-20160816; b=P0XcKvdtjroiUOQBgiQ+zlK2n20e0deG/JD6BSVDVAB48ppj6HAMXqc+SOeuV+u1E0 v/snluuI0uhf08ByB1I1CxMeGI1AwycAp+e0/7BxeNGlhrnx+c1jr2IuEeJMOf0T1WN8 8MnyMHe3QnPqGONrXG7ZHcWwCCfBkQBvq34DTUUsShj/xeQ9a820ml/fK/hDajCIC6m5 F2xZezIxSo2qe8NeaTSHNeznRF3EnzDIsIAMiPC96tMRbqrDoAAN3SuuEARMZuV65PM8 Tcf//wfy9vlNKlnax1fchXQzLANZmaksWbPI8UoWrWrfH8BN4QdnhK7bddp/Jcgm0ibS hj1Q== 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=quKsCCWMGCVlVUiof9PIv3OMohIcermgRG78qyJTwJc=; b=Bx7W06iw30vMjuhXpWAkF8sVzfjV82XS0T/WBIsLIQN+GUcRX6PbtGPkwf0GhrFfxG 8Q5IW26azcwjSkrQxfpuuLXo7AELsXml4XPiGkq0/c0LR2cohBdRuouDkrj70v2XYXxZ 6gIiSfzFeYXsL9vdTBaDMHWp75uUmClnL439jZkSFlyZX7tH9qCapWRQ9E+7B8L/TVoW q5KQAcZTtRibVHUJ9F0Fte1SWNGCf9Sef7HXa7D+FOATPD7lrz9NIzk+l8CQlOl0W5Mq x6O2hiB9q4z9HS+TLRlpsmi36r+EWnNBQFiXr0vo02FzFnlcKyVk+ipRcqD5QH6BW4y4 LBUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=DHJoszte; 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 y17si2857017edc.415.2021.12.07.17.12.31; Tue, 07 Dec 2021 17:12:32 -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=DHJoszte; 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 4605B68AF88; Wed, 8 Dec 2021 03:08:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 311CB68AF52 for ; Wed, 8 Dec 2021 03:08:02 +0200 (EET) Received: by mail-ua1-f54.google.com with SMTP id y5so1894461ual.7 for ; Tue, 07 Dec 2021 17:08:02 -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=2B7LDTyam225swvVMrR7YkEVsJnyN8mvmEs+xhhQBP4=; b=DHJoszteolR4kQjgqc1Cm8Fipmd3pjAHR7DE68NhgnCEwtOgttsbJmHcXR1qMBPk5G VPec+pTo4voUBJ2/k2DYlNd2qr+KlNuMR3tU6Yscu6dBN8ZhgWHTDv1TM2WReV2s0Iyf QGkIljDccNRzXiDIsD8rh9ELlh33HGFK+7DB6oKCCV70xT1Ye3aFIfqAsj0VmrZjZHSa oMJKCKBHAS1QKbmubvayZbbaHgRfaw0sNSKrsiumNSHAq0K8TwSkX5+KZCNx4SELZYi3 TUpcrGdhUqvdlJPZBf1aA0F+eVzW8GzPlXt6j2yNakltGxl3uQLPM8jSrzIUd1XCt1gp TZWQ== 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=2B7LDTyam225swvVMrR7YkEVsJnyN8mvmEs+xhhQBP4=; b=4sM+LL9O5B6nYGryq9GG9dZy03J0Pgrbb3saexoAQeMmfZ39wHpdGesdY3JE8axm6k BkCt+7+d7Yr8YD0gJYxKL5JzNpYYoxp6ZlMvCpg+ICSyuPpUgZuFcKxBiH3lBU6ZpCPL KMWJnBDoh0V1sGBRN8zipUdKduuCa70KEp9Dk9tNWmPxJe08oCWeBEYNr7MhmZlFKAfC pXijq4qL1G9CBH4HjZwRXFneDCovrzvaXT94iSKdYIORBWgbrQkvyJWW6WQfPC48k6he rUIT19DoCelOyQxcml+t/CIrE2D3SZ/bKiWSuznek1n1dr9MOB7m1QMSPrw/2LvEtKfI 0DXA== X-Gm-Message-State: AOAM532LMT3WtskLdgO6QiS7LDTbqsrf+rYyj3wS6VQsdp0Fn676jb+W pQUk+DaSXEaelor+YK1MfXvoAaXY+2ohG835 X-Received: by 2002:a67:bc16:: with SMTP id t22mr50254690vsn.10.1638925680682; Tue, 07 Dec 2021 17:08:00 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:00 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:42 -0300 Message-Id: <20211208010649.381-27-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 272/279] lavf: Add non diegetic stream disposition flag 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: JAUqJT5TeMgR From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavformat/avformat.h | 7 +++++++ libavformat/dump.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 75699f3a32..907cf9d7c6 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -872,6 +872,13 @@ typedef struct AVIndexEntry { */ #define AV_DISPOSITION_TIMED_THUMBNAILS (1 << 11) +/** + * The stream is intended to be mixed with a spatial audio track. For example, + * it could be used for narration or stereo music, and may remain unchanged by + * listener head rotation. + */ +#define AV_DISPOSITION_NON_DIEGETIC (1 << 12) + /** * The subtitle stream contains captions, providing a transcription and possibly * a translation of audio. Typically intended for hearing-impaired audiences. diff --git a/libavformat/dump.c b/libavformat/dump.c index 69b838fbc7..e3f0056c20 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -618,6 +618,8 @@ static void dump_stream_format(const AVFormatContext *ic, int i, av_log(NULL, AV_LOG_INFO, " (dependent)"); if (st->disposition & AV_DISPOSITION_STILL_IMAGE) av_log(NULL, AV_LOG_INFO, " (still image)"); + if (st->disposition & AV_DISPOSITION_NON_DIEGETIC) + av_log(NULL, AV_LOG_INFO, " (non-diegetic)"); av_log(NULL, AV_LOG_INFO, "\n"); dump_metadata(NULL, st->metadata, " "); From patchwork Wed Dec 8 01:06:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32135 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047146iog; Tue, 7 Dec 2021 17:12:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkChki77+VvleaxL/U+/rqlGTnhPjfQS7LcPOOq52PUAOFakrqs2nBmsTe/BymMzZjA4P+ X-Received: by 2002:a05:6402:50cf:: with SMTP id h15mr14682563edb.90.1638925924662; Tue, 07 Dec 2021 17:12:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925924; cv=none; d=google.com; s=arc-20160816; b=mevhT7KBBhL4TcP1+j2BgpNoEbXOkpLBPixy+HMmyys3cjb6MaiVTbBh4ImqPHzuqb 2JA31KtDFOaCm45UnaYBeRTHbcP9otIpqbDysoc7i4Zo/8vKW+PRrmSAq5IC6/rFXA8I D7Tek330Joyr1XqmYDCv5M1lNTRnGUFkUML1TdAAGaUmyuNN0MxssgwrqOwwdSGHpCML NXGK4ic99ty9Y5JQbKPvMgnYCrywq//pd1b4CMtlR1f08xrRsNXDR4FwHXqpAW9XzMN3 aVxcpe7/V7ii6+Xhqs2hO1MhLhnSzv9qBYZCLVwP8RhJe53pjw/2ua1RFS2UGXGqlWUa 9bhw== 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=6T3lRPrSAQTKxJ/6tKQWPnrWnmdt1tykQqrJ5/Hsvms=; b=lTuyWg7pSy+/PTVXv23/Hqi31LFZ3ATxCYMyBYzUS3tBZiq9gD1/iF0GskT5VoPtJR tJSsf7x+IKhXANCmftHY8SsAa3VSaZmItn19iTkGib3RIvIDilG2KhfxEZUWSKNQ8Kew 5QWg8orpJ4787qLQ5gCR9FAfIyiK+v2PNnmys5lWHNMKe1SLLTncLMEBU50xYfSj3svE o42b5kLTXifK46Ai7B78K3ERt3hWmh4s2uAZ7HHe13zSs9qMofmiGauCagrZj5G+D0yk mhwszZ3OaVwnz/M0IpBQPO7Jicso1BrLYtxuGAyBhtXhhSTod8l3YEb/7GjzLyhP0ZNg zbUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=lirapaB0; 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 u3si2190565ejz.294.2021.12.07.17.11.55; Tue, 07 Dec 2021 17:12:04 -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=lirapaB0; 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 B422068AF6D; Wed, 8 Dec 2021 03:08:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3668F68AF45 for ; Wed, 8 Dec 2021 03:08:04 +0200 (EET) Received: by mail-ua1-f53.google.com with SMTP id t13so1882941uad.9 for ; Tue, 07 Dec 2021 17:08:04 -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=Jb8dvNLrTrtWZ7Wbm6Sa28PsMEQOM58R6dIrBYOosAo=; b=lirapaB0xxoFiQiCvBCn7rq4dB6EHvgOyNC3MzVBktVDUPwELgYLKry/yV03FQ1zW3 9IRiI8RZMXrxl4hm6sCd9JVsJlcgpDvVoKQBXwj7GK7xjItK15I9wKezE0ChiFEJvkDN czz1LM+Lu8LEIkj3qoWem0T67KZp++AuXFaIFeLLjtrCuq9daEKjYnKkQmf/NtvyDhRc tZ2ts0j2xzItfl8dcdXUJbv76Gtwd8pez/mTeVw5Q4qxch2sbCKlLt/aOaZiRmchpuMn ArW0SEiWJZNl3+vDei9JIXyvUqHapn6hMepRc1FNInRwrdT3as122F0+9baeiYUacm3N i92g== 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=Jb8dvNLrTrtWZ7Wbm6Sa28PsMEQOM58R6dIrBYOosAo=; b=JL/EwHg51BqoeqS2YgNVlMUjuVzGWAvCIvSoFRI+EPcyj3YEJqLvCAcbyIwt6UKgXd khjIVgfH0JutHrz4oB9IoMQQvFM7rq4Cb6EqOGFOdnZn1BiCsuLUPobWm2GPmGPqvdGt +6T9ztJjDa4pRCJH7HC/K5LgqE+eiEs8JVatwGH9gAyAbhg1oqVSALocykdKCEJpM0XQ cYNKWu6ZxxStDq61yX4iazHWAI6JHIPRhtq24H/9sCg+GsOVUvj5ZDfr7+tbfZDQPhGo V0FXtLw7/Qei0bAgexCL6TPC6rUKYfo7z+yLm4Qqw769VAehUxBsWOnGIJxo1b9jP9AL APZA== X-Gm-Message-State: AOAM533Xyp0aXnm3f8i+NYP2W1z2ins+8khwqMRHZGjiCPu4G/fQdCi9 +BoVRjUpLb/ZNfbsN0GK6RxHoM6ptPlFnCxT X-Received: by 2002:a05:6102:c16:: with SMTP id x22mr50048790vss.69.1638925682041; Tue, 07 Dec 2021 17:08:02 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:01 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:43 -0300 Message-Id: <20211208010649.381-28-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 273/279] swresample: 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: m2dxLkObPHO0 Signed-off-by: James Almer --- libswresample/options.c | 33 +++- libswresample/rematrix.c | 227 ++++++++++++++++++---------- libswresample/rematrix_template.c | 7 +- libswresample/swresample.c | 158 ++++++++++++++++--- libswresample/swresample.h | 63 ++++++++ libswresample/swresample_frame.c | 65 +++++++- libswresample/swresample_internal.h | 10 +- 7 files changed, 443 insertions(+), 120 deletions(-) diff --git a/libswresample/options.c b/libswresample/options.c index 6911709157..ffa27c590d 100644 --- a/libswresample/options.c +++ b/libswresample/options.c @@ -34,12 +34,19 @@ #define OFFSET(x) offsetof(SwrContext,x) #define PARAM AV_OPT_FLAG_AUDIO_PARAM +#define DEPREC AV_OPT_FLAG_DEPRECATED static const AVOption options[]={ -{"ich" , "set input channel count" , OFFSET(user_in_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, -{"in_channel_count" , "set input channel count" , OFFSET(user_in_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, -{"och" , "set output channel count" , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, -{"out_channel_count" , "set output channel count" , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, +#if FF_API_OLD_CHANNEL_LAYOUT +{"ich" , "set input channel count (Deprecated, use ichl)", + OFFSET(user_in_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, +{"in_channel_count" , "set input channel count (Deprecated, use in_chlayout)", + OFFSET(user_in_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, +{"och" , "set output channel count (Deprecated, use ochl)", + OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, +{"out_channel_count" , "set output channel count (Deprecated, use out_chlayout)", + OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, +#endif {"uch" , "set used channel count" , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, {"used_channel_count" , "set used channel count" , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, {"isr" , "set input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT , {.i64=0 }, 0 , INT_MAX , PARAM}, @@ -52,10 +59,20 @@ static const AVOption options[]={ {"out_sample_fmt" , "set output sample format" , OFFSET(out_sample_fmt ), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1 , INT_MAX, PARAM}, {"tsf" , "set internal sample format" , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1 , INT_MAX, PARAM}, {"internal_sample_fmt" , "set internal sample format" , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1 , INT_MAX, PARAM}, -{"icl" , "set input channel layout" , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"}, -{"in_channel_layout" , "set input channel layout" , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"}, -{"ocl" , "set output channel layout" , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"}, -{"out_channel_layout" , "set output channel layout" , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"}, +#if FF_API_OLD_CHANNEL_LAYOUT +{"icl" , "set input channel layout (Deprecated, use ichl)", + OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"}, +{"in_channel_layout" , "set input channel layout (Deprecated, use in_chlayout)", + OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"}, +{"ocl" , "set output channel layout (Deprecated, use ochl)", + OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"}, +{"out_channel_layout" , "set output channel layout (Deprecated, use out_chlayout)", + OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0 }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"}, +#endif +{"ichl" , "set input channel layout" , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, +{"in_chlayout" , "set input channel layout" , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, +{"ochl" , "set output channel layout" , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, +{"out_chlayout" , "set output channel layout" , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, {"clev" , "set center mix level" , OFFSET(clev ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB }, -32 , 32 , PARAM}, {"center_mix_level" , "set center mix level" , OFFSET(clev ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB }, -32 , 32 , PARAM}, {"slev" , "set surround mix level" , OFFSET(slev ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB }, -32 , 32 , PARAM}, diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 94b3de88f6..106ab88454 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -64,15 +64,31 @@ int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) { int nb_in, nb_out, in, out; + int user_in_chlayout_nb_channels, user_out_chlayout_nb_channels; if (!s || s->in_convert) // s needs to be allocated but not initialized return AVERROR(EINVAL); memset(s->matrix, 0, sizeof(s->matrix)); memset(s->matrix_flt, 0, sizeof(s->matrix_flt)); + +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + user_in_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_in_ch_layout); +FF_ENABLE_DEPRECATION_WARNINGS + if (!user_in_chlayout_nb_channels) +#endif + user_in_chlayout_nb_channels = s->user_in_chlayout.nb_channels; nb_in = (s->user_in_ch_count > 0) ? s->user_in_ch_count : - av_get_channel_layout_nb_channels(s->user_in_ch_layout); + user_in_chlayout_nb_channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + user_out_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_out_ch_layout); +FF_ENABLE_DEPRECATION_WARNINGS + if (!user_out_chlayout_nb_channels) +#endif + user_out_chlayout_nb_channels = s->user_out_chlayout.nb_channels; nb_out = (s->user_out_ch_count > 0) ? s->user_out_ch_count : - av_get_channel_layout_nb_channels(s->user_out_ch_layout); + user_out_chlayout_nb_channels; for (out = 0; out < nb_out; out++) { for (in = 0; in < nb_in; in++) s->matrix_flt[out][in] = s->matrix[out][in] = matrix[in]; @@ -88,95 +104,141 @@ static int even(int64_t layout){ return 0; } -static int64_t clean_layout(void *s, int64_t layout){ - if(layout && layout != AV_CH_FRONT_CENTER && !(layout&(layout-1))) { +static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s) +{ + int ret = 0; + + if(av_channel_layout_index_from_channel(in, AV_CH_FRONT_CENTER) < 0 && in->nb_channels == 1) { char buf[128]; - av_get_channel_layout_string(buf, sizeof(buf), -1, layout); + av_channel_layout_describe(in, buf, sizeof(buf)); av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf); - return AV_CH_FRONT_CENTER; - } + *out = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; + } else + ret = av_channel_layout_copy(out, in); - return layout; + return ret; } -static int sane_layout(int64_t layout){ - if(!(layout & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker +static int sane_layout(AVChannelLayout *ch_layout) { + if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE) + return 0; + if(!av_channel_layout_subset(ch_layout, AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker return 0; - if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymetric front + if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)))) // no asymetric front return 0; - if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))) // no asymetric side + if(!even(av_channel_layout_subset(ch_layout, (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)))) // no asymetric side return 0; - if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT))) + if(!even(av_channel_layout_subset(ch_layout, (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)))) return 0; - if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))) + if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)))) return 0; - if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX) + if(ch_layout->nb_channels >= SWR_CH_MAX) return 0; return 1; } +#if FF_API_OLD_CHANNEL_LAYOUT av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout_param, double center_mix_level, double surround_mix_level, double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param, int stride, enum AVMatrixEncoding matrix_encoding, void *log_context) { - int i, j, out_i; + AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 }; + int ret; + + ret = av_channel_layout_from_mask(&in_ch_layout, in_ch_layout_param); + ret |= av_channel_layout_from_mask(&out_ch_layout, out_ch_layout_param); + if (ret < 0) + return ret; + + return swr_build_matrix2(&in_ch_layout, &out_ch_layout, center_mix_level, surround_mix_level, + lfe_mix_level, maxval, rematrix_volume, matrix_param, + stride, matrix_encoding, log_context); +} +#endif + +av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout, + double center_mix_level, double surround_mix_level, + double lfe_mix_level, double maxval, + double rematrix_volume, double *matrix_param, + ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context) +{ + int i, j, out_i, ret; + AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 }; double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}}; - int64_t unaccounted, in_ch_layout, out_ch_layout; + int64_t unaccounted; double maxcoef=0; char buf[128]; - in_ch_layout = clean_layout(log_context, in_ch_layout_param); - out_ch_layout = clean_layout(log_context, out_ch_layout_param); - - if( out_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX - && (in_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0 - ) - out_ch_layout = AV_CH_LAYOUT_STEREO; + ret = clean_layout(&in_ch_layout, in_layout, log_context); + ret |= clean_layout(&out_ch_layout, out_layout, log_context); + if (ret < 0) + goto fail; - if( in_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX - && (out_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0 - ) - in_ch_layout = AV_CH_LAYOUT_STEREO; - - if (in_ch_layout == AV_CH_LAYOUT_22POINT2 && - out_ch_layout != AV_CH_LAYOUT_22POINT2) { - in_ch_layout = (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER); - av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout); + if( !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX) + && !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX) + ) { + av_channel_layout_uninit(&out_ch_layout); + out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; + } + if( !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX) + && !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX) + ) { + av_channel_layout_uninit(&in_ch_layout); + in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; + } + if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) && + av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) { + av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER)); + av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf)); av_log(log_context, AV_LOG_WARNING, "Full-on remixing from 22.2 has not yet been implemented! " "Processing the input as '%s'\n", buf); } - if(!sane_layout(in_ch_layout)){ - av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout_param); + if(!av_channel_layout_check(&in_ch_layout)) { + av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n"); + ret = AVERROR(EINVAL); + goto fail; + } + if(!sane_layout(&in_ch_layout)) { + av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf)); av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf); - return AVERROR(EINVAL); + ret = AVERROR(EINVAL); + goto fail; } - if(!sane_layout(out_ch_layout)){ - av_get_channel_layout_string(buf, sizeof(buf), -1, out_ch_layout_param); + if(!av_channel_layout_check(&out_ch_layout)) { + av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n"); + ret = AVERROR(EINVAL); + goto fail; + } + if(!sane_layout(&out_ch_layout)) { + av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf)); av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf); - return AVERROR(EINVAL); + ret = AVERROR(EINVAL); + goto fail; } for(i=0; i= 0 + && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx) matrix[i][i]= 1.0; } - unaccounted= in_ch_layout & ~out_ch_layout; + unaccounted = in_ch_layout.u.mask & ~out_ch_layout.u.mask; //FIXME implement dolby surround //FIXME implement full ac3 if(unaccounted & AV_CH_FRONT_CENTER){ - if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){ - if(in_ch_layout & AV_CH_LAYOUT_STEREO) { + if(av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){ + if(av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO)) { matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level; matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level; } else { @@ -187,23 +249,23 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout av_assert0(0); } if(unaccounted & AV_CH_LAYOUT_STEREO){ - if(out_ch_layout & AV_CH_FRONT_CENTER){ + if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){ matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2; matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2; - if(in_ch_layout & AV_CH_FRONT_CENTER) + if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2); }else av_assert0(0); } if(unaccounted & AV_CH_BACK_CENTER){ - if(out_ch_layout & AV_CH_BACK_LEFT){ + if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){ matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2; matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2; - }else if(out_ch_layout & AV_CH_SIDE_LEFT){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){ matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2; matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2; - }else if(out_ch_layout & AV_CH_FRONT_LEFT){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){ if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY || matrix_encoding == AV_MATRIX_ENCODING_DPLII) { if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) { @@ -217,24 +279,24 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2; matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2; } - }else if(out_ch_layout & AV_CH_FRONT_CENTER){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){ matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2; }else av_assert0(0); } if(unaccounted & AV_CH_BACK_LEFT){ - if(out_ch_layout & AV_CH_BACK_CENTER){ + if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){ matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2; matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2; - }else if(out_ch_layout & AV_CH_SIDE_LEFT){ - if(in_ch_layout & AV_CH_SIDE_LEFT){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){ + if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){ matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2; matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2; }else{ matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0; matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0; } - }else if(out_ch_layout & AV_CH_FRONT_LEFT){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){ if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) { matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2; matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2; @@ -249,7 +311,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level; matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level; } - }else if(out_ch_layout & AV_CH_FRONT_CENTER){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){ matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2; matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2; }else @@ -257,20 +319,20 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout } if(unaccounted & AV_CH_SIDE_LEFT){ - if(out_ch_layout & AV_CH_BACK_LEFT){ + if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){ /* if back channels do not exist in the input, just copy side channels to back channels, otherwise mix side into back */ - if (in_ch_layout & AV_CH_BACK_LEFT) { + if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) { matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2; matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2; } else { matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0; matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0; } - }else if(out_ch_layout & AV_CH_BACK_CENTER){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){ matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2; matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2; - }else if(out_ch_layout & AV_CH_FRONT_LEFT){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){ if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) { matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2; matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2; @@ -285,7 +347,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level; matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level; } - }else if(out_ch_layout & AV_CH_FRONT_CENTER){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){ matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2; matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2; }else @@ -293,10 +355,10 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout } if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){ - if(out_ch_layout & AV_CH_FRONT_LEFT){ + if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){ matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0; matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0; - }else if(out_ch_layout & AV_CH_FRONT_CENTER){ + }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){ matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2; matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2; }else @@ -304,9 +366,9 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout } /* mix LFE into front left/right or center */ if (unaccounted & AV_CH_LOW_FREQUENCY) { - if (out_ch_layout & AV_CH_FRONT_CENTER) { + if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) { matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level; - } else if (out_ch_layout & AV_CH_FRONT_LEFT) { + } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) { matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2; matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2; } else @@ -316,15 +378,19 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout for(out_i=i=0; i<64; i++){ double sum=0; int in_i=0; - if((out_ch_layout & (1ULL<= 0 + && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx); + } sum += fabs(matrix_param[stride*out_i + in_i]); in_i++; } @@ -350,17 +416,22 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout } av_log(log_context, AV_LOG_DEBUG, "Matrix coefficients:\n"); - for(i=0; imatrix, 0, sizeof(s->matrix)); - ret = swr_build_matrix(s->in_ch_layout, s->out_ch_layout, + ret = swr_build_matrix2(&s->in_ch_layout, &s->out_ch_layout, s->clev, s->slev, s->lfe_mix_level, maxval, s->rematrix_volume, (double*)s->matrix, s->matrix[1] - s->matrix[0], s->matrix_encoding, s); @@ -519,8 +590,8 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus off = len1 * out->bps; } - av_assert0(!s->out_ch_layout || out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout)); - av_assert0(!s-> in_ch_layout || in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout)); + av_assert0(s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || out->ch_count == s->out_ch_layout.nb_channels); + av_assert0(s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || in ->ch_count == s->in_ch_layout.nb_channels); for(out_i=0; out_ich_count; out_i++){ switch(s->matrix_ch[out_i][0]){ diff --git a/libswresample/rematrix_template.c b/libswresample/rematrix_template.c index add65e3155..f5a508361c 100644 --- a/libswresample/rematrix_template.c +++ b/libswresample/rematrix_template.c @@ -88,13 +88,16 @@ static void RENAME(mix8to2)(SAMPLE **out, const SAMPLE **in, COEFF *coeffp, inte } static RENAME(mix_any_func_type) *RENAME(get_mix_any_func)(SwrContext *s){ - if( s->out_ch_layout == AV_CH_LAYOUT_STEREO && (s->in_ch_layout == AV_CH_LAYOUT_5POINT1 || s->in_ch_layout == AV_CH_LAYOUT_5POINT1_BACK) + if( !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) + && ( !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1) + || !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK)) && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3] && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4] ) return RENAME(mix6to2); - if( s->out_ch_layout == AV_CH_LAYOUT_STEREO && s->in_ch_layout == AV_CH_LAYOUT_7POINT1 + if( !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) + && !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1) && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3] && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4] && !s->matrix[0][7] && !s->matrix[1][6] diff --git a/libswresample/swresample.c b/libswresample/swresample.c index c03fe5528f..fe75e847af 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -56,6 +56,8 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map){ return 0; } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, @@ -97,6 +99,58 @@ fail: swr_free(&s); return NULL; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + +int swr_alloc_set_opts2(struct SwrContext **ps, + AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, + AVChannelLayout *in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, + int log_offset, void *log_ctx) { + struct SwrContext *s = *ps; + int ret; + + if (!s) s = swr_alloc(); + if (!s) return AVERROR(ENOMEM); + + s->log_level_offset= log_offset; + s->log_ctx= log_ctx; + + if ((ret = av_opt_set_chlayout(s, "ochl", out_ch_layout, 0)) < 0) + goto fail; + + if ((ret = av_opt_set_int(s, "osf", out_sample_fmt, 0)) < 0) + goto fail; + + if ((ret = av_opt_set_int(s, "osr", out_sample_rate, 0)) < 0) + goto fail; + + if ((ret = av_opt_set_chlayout(s, "ichl", in_ch_layout, 0)) < 0) + goto fail; + + if ((ret = av_opt_set_int(s, "isf", in_sample_fmt, 0)) < 0) + goto fail; + + if ((ret = av_opt_set_int(s, "isr", in_sample_rate, 0)) < 0) + goto fail; + + av_opt_set_int(s, "uch", 0, 0); + +#if FF_API_OLD_CHANNEL_LAYOUT + // Clear old API values so they don't take precedence in swr_init() + av_opt_set_int(s, "icl", 0, 0); + av_opt_set_int(s, "ocl", 0, 0); + av_opt_set_int(s, "ich", 0, 0); + av_opt_set_int(s, "och", 0, 0); +#endif + + *ps = s; + + return 0; +fail: + av_log(s, AV_LOG_ERROR, "Failed to set option\n"); + swr_free(ps); + return ret; +} static void set_audiodata_fmt(AudioData *a, enum AVSampleFormat fmt){ a->fmt = fmt; @@ -125,6 +179,8 @@ static void clear_context(SwrContext *s){ free_temp(&s->drop_temp); free_temp(&s->dither.noise); free_temp(&s->dither.temp); + av_channel_layout_uninit(&s->in_ch_layout); + av_channel_layout_uninit(&s->out_ch_layout); swri_audio_convert_free(&s-> in_convert); swri_audio_convert_free(&s->out_convert); swri_audio_convert_free(&s->full_convert); @@ -138,6 +194,9 @@ av_cold void swr_free(SwrContext **ss){ SwrContext *s= *ss; if(s){ clear_context(s); + av_channel_layout_uninit(&s->user_in_chlayout); + av_channel_layout_uninit(&s->user_out_chlayout); + if (s->resampler) s->resampler->free(&s->resample); } @@ -172,25 +231,72 @@ av_cold int swr_init(struct SwrContext *s){ av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate); return AVERROR(EINVAL); } + s->used_ch_count = s->user_used_ch_count; +#if FF_API_OLD_CHANNEL_LAYOUT s->out.ch_count = s-> user_out_ch_count; s-> in.ch_count = s-> user_in_ch_count; - s->used_ch_count = s->user_used_ch_count; - s-> in_ch_layout = s-> user_in_ch_layout; - s->out_ch_layout = s->user_out_ch_layout; + // if the old/new fields are set inconsistently, prefer the old ones + if ((s->user_in_ch_count && s->user_in_ch_count != s->user_in_chlayout.nb_channels) || + (s->user_in_ch_layout && (s->user_in_chlayout.order != AV_CHANNEL_ORDER_NATIVE || + s->user_in_chlayout.u.mask != s->user_in_ch_layout))) { + av_channel_layout_uninit(&s->in_ch_layout); + if (s->user_in_ch_layout) + av_channel_layout_from_mask(&s->in_ch_layout, s->user_in_ch_layout); + else { + s->in_ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + s->in_ch_layout.nb_channels = s->user_in_ch_count; + } + } else + av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout); + + if ((s->user_out_ch_count && s->user_out_ch_count != s->user_out_chlayout.nb_channels) || + (s->user_out_ch_layout && (s->user_out_chlayout.order != AV_CHANNEL_ORDER_NATIVE || + s->user_out_chlayout.u.mask != s->user_out_ch_layout))) { + av_channel_layout_uninit(&s->out_ch_layout); + if (s->user_out_ch_layout) + av_channel_layout_from_mask(&s->out_ch_layout, s->user_out_ch_layout); + else { + s->out_ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + s->out_ch_layout.nb_channels = s->user_out_ch_count; + } + } else + av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout); + + if (!s->out.ch_count && !s->user_out_ch_layout) + s->out.ch_count = s->out_ch_layout.nb_channels; + if (!s-> in.ch_count && !s-> user_in_ch_layout) + s-> in.ch_count = s->in_ch_layout.nb_channels; +#else + s->out.ch_count = s-> user_out_chlayout.nb_channels; + s-> in.ch_count = s-> user_in_chlayout.nb_channels; + + ret = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout); + ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout); + if (ret < 0) + return ret; +#endif s->int_sample_fmt= s->user_int_sample_fmt; s->dither.method = s->user_dither_method; - if(av_get_channel_layout_nb_channels(s-> in_ch_layout) > SWR_CH_MAX) { - av_log(s, AV_LOG_WARNING, "Input channel layout 0x%"PRIx64" is invalid or unsupported.\n", s-> in_ch_layout); - s->in_ch_layout = 0; + if(!av_channel_layout_check(&s->in_ch_layout) || + s->in_ch_layout.nb_channels > SWR_CH_MAX || + ( s->in_ch_layout.order != AV_CHANNEL_ORDER_NATIVE + && s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC)) { + av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1)); + av_log(s, AV_LOG_WARNING, "Input channel layout \"%s\" is invalid or unsupported.\n", l1); + av_channel_layout_uninit(&s->in_ch_layout); } - if(av_get_channel_layout_nb_channels(s->out_ch_layout) > SWR_CH_MAX) { - av_log(s, AV_LOG_WARNING, "Output channel layout 0x%"PRIx64" is invalid or unsupported.\n", s->out_ch_layout); - s->out_ch_layout = 0; + if(!av_channel_layout_check(&s->out_ch_layout) || + s->out_ch_layout.nb_channels > SWR_CH_MAX || + ( s->out_ch_layout.order != AV_CHANNEL_ORDER_NATIVE + && s->out_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC)) { + av_channel_layout_describe(&s->out_ch_layout, l2, sizeof(l2)); + av_log(s, AV_LOG_WARNING, "Output channel layout \"%s\" is invalid or unsupported.\n", l2); + av_channel_layout_uninit(&s->out_ch_layout); } switch(s->engine){ @@ -206,17 +312,18 @@ av_cold int swr_init(struct SwrContext *s){ if(!s->used_ch_count) s->used_ch_count= s->in.ch_count; - if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){ + if(s->used_ch_count && s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels){ av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n"); - s-> in_ch_layout= 0; + av_channel_layout_uninit(&s->in_ch_layout); } - if(!s-> in_ch_layout) - s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count); - if(!s->out_ch_layout) - s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count); + if(!s->in_ch_layout.nb_channels || s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + av_channel_layout_default(&s->in_ch_layout, s->used_ch_count); + if(!s->out_ch_layout.nb_channels || s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + av_channel_layout_default(&s->out_ch_layout, s->out.ch_count); - s->rematrix= s->out_ch_layout !=s->in_ch_layout || s->rematrix_volume!=1.0 || + s->rematrix= av_channel_layout_compare(&s->out_ch_layout, &s->in_ch_layout) || + s->rematrix_volume!=1.0 || s->rematrix_custom; if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){ @@ -291,33 +398,36 @@ av_cold int swr_init(struct SwrContext *s){ #define RSC 1 //FIXME finetune if(!s-> in.ch_count) - s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); + s-> in.ch_count = s->in_ch_layout.nb_channels; if(!s->used_ch_count) s->used_ch_count= s->in.ch_count; if(!s->out.ch_count) - s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); + s->out.ch_count = s->out_ch_layout.nb_channels; if(!s-> in.ch_count){ - av_assert0(!s->in_ch_layout); + av_assert0(s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC); av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n"); ret = AVERROR(EINVAL); goto fail; } - av_get_channel_layout_string(l1, sizeof(l1), s-> in.ch_count, s-> in_ch_layout); - av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout); - if (s->out_ch_layout && s->out.ch_count != av_get_channel_layout_nb_channels(s->out_ch_layout)) { +#if FF_API_OLD_CHANNEL_LAYOUT + av_channel_layout_describe(&s->out_ch_layout, l1, sizeof(l1)); + if (s->out_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->out.ch_count != s->out_ch_layout.nb_channels) { av_log(s, AV_LOG_ERROR, "Output channel layout %s mismatches specified channel count %d\n", l2, s->out.ch_count); ret = AVERROR(EINVAL); goto fail; } - if (s->in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s->in_ch_layout)) { +#endif + av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1)); + if (s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels) { av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_count); ret = AVERROR(EINVAL); goto fail; } - if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) { + if (( s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC + || s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) { av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s " "but there is not enough information to do it\n", l1, l2); ret = AVERROR(EINVAL); diff --git a/libswresample/swresample.h b/libswresample/swresample.h index c7b84fbcac..c6ff2345e9 100644 --- a/libswresample/swresample.h +++ b/libswresample/swresample.h @@ -227,6 +227,7 @@ int swr_init(struct SwrContext *s); */ int swr_is_initialized(struct SwrContext *s); +#if FF_API_OLD_CHANNEL_LAYOUT /** * Allocate SwrContext if needed and set/reset common parameters. * @@ -246,12 +247,40 @@ int swr_is_initialized(struct SwrContext *s); * * @see swr_init(), swr_free() * @return NULL on error, allocated context otherwise + * @deprecated use @ref swr_alloc_set_opts2() */ +attribute_deprecated struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx); +#endif +/** + * Allocate SwrContext if needed and set/reset common parameters. + * + * This function does not require s to be allocated with swr_alloc(). On the + * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters + * on the allocated context. + * + * @param ps Pointer to an existing Swr context if available, or to NULL if not. + * On success, *ps will be set the allocated context. + * @param out_ch_layout output channel layout (AV_CH_LAYOUT_*) + * @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*). + * @param out_sample_rate output sample rate (frequency in Hz) + * @param in_ch_layout input channel layout (AV_CH_LAYOUT_*) + * @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*). + * @param in_sample_rate input sample rate (frequency in Hz) + * @param log_offset logging level offset + * @param log_ctx parent logging context, can be NULL + * + * @see swr_init(), swr_free() + * @return 0 on success, a negative AVERROR code on error. + */ +int swr_alloc_set_opts2(struct SwrContext **ps, + AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, + AVChannelLayout *in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, + int log_offset, void *log_ctx); /** * @} * @@ -362,6 +391,7 @@ int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensatio */ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map); +#if FF_API_OLD_CHANNEL_LAYOUT /** * Generate a channel mixing matrix. * @@ -384,13 +414,46 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map); * @param matrix_encoding matrixed stereo downmix mode (e.g. dplii) * @param log_ctx parent logging context, can be NULL * @return 0 on success, negative AVERROR code on failure + * @deprecated use @ref swr_build_matrix2() */ +attribute_deprecated int swr_build_matrix(uint64_t in_layout, uint64_t out_layout, double center_mix_level, double surround_mix_level, double lfe_mix_level, double rematrix_maxval, double rematrix_volume, double *matrix, int stride, enum AVMatrixEncoding matrix_encoding, void *log_ctx); +#endif + +/** + * Generate a channel mixing matrix. + * + * This function is the one used internally by libswresample for building the + * default mixing matrix. It is made public just as a utility function for + * building custom matrices. + * + * @param in_layout input channel layout + * @param out_layout output channel layout + * @param center_mix_level mix level for the center channel + * @param surround_mix_level mix level for the surround channel(s) + * @param lfe_mix_level mix level for the low-frequency effects channel + * @param rematrix_maxval if 1.0, coefficients will be normalized to prevent + * overflow. if INT_MAX, coefficients will not be + * normalized. + * @param[out] matrix mixing coefficients; matrix[i + stride * o] is + * the weight of input channel i in output channel o. + * @param stride distance between adjacent input channels in the + * matrix array + * @param matrix_encoding matrixed stereo downmix mode (e.g. dplii) + * @param log_ctx parent logging context, can be NULL + * @return 0 on success, negative AVERROR code on failure + */ +int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout, + double center_mix_level, double surround_mix_level, + double lfe_mix_level, double maxval, + double rematrix_volume, double *matrix_param, + ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, + void *log_context); /** * Set a customized remix matrix. diff --git a/libswresample/swresample_frame.c b/libswresample/swresample_frame.c index d95c1cc537..747cf119a9 100644 --- a/libswresample/swresample_frame.c +++ b/libswresample/swresample_frame.c @@ -29,7 +29,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in) swr_close(s); if (in) { - if (av_opt_set_int(s, "icl", in->channel_layout, 0) < 0) + AVChannelLayout in_ch_layout = { 0 }; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + // if the old/new fields are set inconsistently, prefer the old ones + if ((in->channel_layout && (in->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + in->ch_layout.u.mask != in->channel_layout))) { + av_channel_layout_from_mask(&in_ch_layout, in->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS + } else +#endif + if (av_channel_layout_copy(&in_ch_layout, &in->ch_layout) < 0) + goto fail; + if (av_opt_set_chlayout(s, "ichl", &in_ch_layout, 0) < 0) goto fail; if (av_opt_set_int(s, "isf", in->format, 0) < 0) goto fail; @@ -38,7 +50,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in) } if (out) { - if (av_opt_set_int(s, "ocl", out->channel_layout, 0) < 0) + AVChannelLayout out_ch_layout = { 0 }; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + // if the old/new fields are set inconsistently, prefer the old ones + if ((out->channel_layout && (out->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + out->ch_layout.u.mask != out->channel_layout))) { + av_channel_layout_from_mask(&out_ch_layout, out->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS + } else +#endif + if (av_channel_layout_copy(&out_ch_layout, &out->ch_layout) < 0) + goto fail; + if (av_opt_set_chlayout(s, "ochl", &out_ch_layout, 0) < 0) goto fail; if (av_opt_set_int(s, "osf", out->format, 0) < 0) goto fail; @@ -58,7 +82,19 @@ static int config_changed(SwrContext *s, int ret = 0; if (in) { - if (s->in_ch_layout != in->channel_layout || + AVChannelLayout in_ch_layout = { 0 }; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + // if the old/new fields are set inconsistently, prefer the old ones + if ((in->channel_layout && (in->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + in->ch_layout.u.mask != in->channel_layout))) { + av_channel_layout_from_mask(&in_ch_layout, in->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS + } else +#endif + if ((ret = av_channel_layout_copy(&in_ch_layout, &in->ch_layout)) < 0) + return ret; + if (av_channel_layout_compare(&s->in_ch_layout, &in_ch_layout) || s->in_sample_rate != in->sample_rate || s->in_sample_fmt != in->format) { ret |= AVERROR_INPUT_CHANGED; @@ -66,7 +102,19 @@ static int config_changed(SwrContext *s, } if (out) { - if (s->out_ch_layout != out->channel_layout || + AVChannelLayout out_ch_layout = { 0 }; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + // if the old/new fields are set inconsistently, prefer the old ones + if ((out->channel_layout && (out->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + out->ch_layout.u.mask != out->channel_layout))) { + av_channel_layout_from_mask(&out_ch_layout, out->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS + } else +#endif + if ((ret = av_channel_layout_copy(&out_ch_layout, &out->ch_layout)) < 0) + return ret; + if (av_channel_layout_compare(&s->out_ch_layout, &out_ch_layout) || s->out_sample_rate != out->sample_rate || s->out_sample_fmt != out->format) { ret |= AVERROR_OUTPUT_CHANGED; @@ -116,7 +164,14 @@ static inline int available_samples(AVFrame *out) if (av_sample_fmt_is_planar(out->format)) { return samples; } else { - int channels = av_get_channel_layout_nb_channels(out->channel_layout); + int channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + channels = av_get_channel_layout_nb_channels(out->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS + if (!channels) +#endif + channels = out->ch_layout.nb_channels; return samples / channels; } } diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index f2ea5a226d..262a0e2b8c 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -99,8 +99,8 @@ struct SwrContext { enum AVSampleFormat in_sample_fmt; ///< input sample format enum AVSampleFormat int_sample_fmt; ///< internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P) enum AVSampleFormat out_sample_fmt; ///< output sample format - int64_t in_ch_layout; ///< input channel layout - int64_t out_ch_layout; ///< output channel layout + AVChannelLayout in_ch_layout; ///< input channel layout + AVChannelLayout out_ch_layout; ///< output channel layout int in_sample_rate; ///< input sample rate int out_sample_rate; ///< output sample rate int flags; ///< miscellaneous flags such as SWR_FLAG_RESAMPLE @@ -114,11 +114,15 @@ struct SwrContext { int used_ch_count; ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count) int engine; + int user_used_ch_count; ///< User set used channel count +#if FF_API_OLD_CHANNEL_LAYOUT int user_in_ch_count; ///< User set input channel count int user_out_ch_count; ///< User set output channel count - int user_used_ch_count; ///< User set used channel count int64_t user_in_ch_layout; ///< User set input channel layout int64_t user_out_ch_layout; ///< User set output channel layout +#endif + AVChannelLayout user_in_chlayout; ///< User set input channel layout + AVChannelLayout user_out_chlayout; ///< User set output channel layout enum AVSampleFormat user_int_sample_fmt; ///< User set internal sample format int user_dither_method; ///< User set dither method From patchwork Wed Dec 8 01:06:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32130 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7048097iog; Tue, 7 Dec 2021 17:13:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxH2x6i6vG8MwRq60qLVt3oYIoCz0LqtyHq/VAufAm/3f5J76eZIC0x4dWsotgq6Cyaq8WO X-Received: by 2002:a05:6402:254f:: with SMTP id l15mr13957259edb.12.1638925981105; Tue, 07 Dec 2021 17:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925981; cv=none; d=google.com; s=arc-20160816; b=ANfe3bTdYaeD7cqin0d5whw9Dr+pal2O/1j/QoMfoZQ+cxgnduwA8ZH4ZbjPjvTfY0 Lu2hkMWSgRmldi/4trjRwJNVy8pjHYI2y5Pgsg1u7lJmanaIeyYw8rn1qsIeipU1RDvr a6Jcyqkov5kCpbtiT9BO1NPYAfVWNCNWUYauFziJHJMZMvpQ5uqZ/nteN2VypfkOojUN /7v7OOvPHaT1QH57wdtA1Rpo8HpCGI2AXImobEB+if2YvPvBZg2N1sp0gbiKjPN4BapV nNtQDqBdq7a34XT7omKVaUaZ628UiKksPTvLKIsWfotux9FI3LBk5SgQZQhnEmJC001f h0lA== 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=8LUkWuT67yyLjVtWUt4WB7qtSrLWlqRbjS1sTYX1QmU=; b=DB7Eh5ICBWrjfOGk6jzzbne3Sbr/3C5rwQA14wXMiNR1s7yP/foNwUSg0Rx1oTWjSh InjUqOE/opvwkgTssEp4yOUsFYaYdfkxNCqZNdcmGXbeQbhETOmtDS7ualD54pPn/5TN INQ5Gcr0uDGSU+gjrgs6TT8egjgp+gKhVntji5bTuxYPrtIwK6MuUWSxmx0MAWo0RUO1 lcRyenAY/TblVih60nRmPjMmJDiL2c2ypnKrzWIqYglzbQNPUgGnTiEvPu0qGasOXhh/ A0WBTdMQoHq8g6JlBV8r8cMleo8iUWM4ZvD03M2OriiimTNgwwVv0XXx8xXwSU4UsLRF eYbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nm2RslPT; 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 eb6si2875898edb.320.2021.12.07.17.13.00; Tue, 07 Dec 2021 17:13:01 -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=nm2RslPT; 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 3BE8268AF97; Wed, 8 Dec 2021 03:08:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7AEC768AF48 for ; Wed, 8 Dec 2021 03:08:07 +0200 (EET) Received: by mail-ua1-f45.google.com with SMTP id w23so1920231uao.5 for ; Tue, 07 Dec 2021 17:08:07 -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=fbYFCSe2zvXv9fKWwAETiVQtSZbEfmbD928ZA0VvtzA=; b=nm2RslPTsLRgSSySKvqNCCmJGvXjAmSQzRjZKge9DfygABo0YoASudi/sl316RnGPX 35eGB1RH0nterk/NVF9KT5AHvFKSqSeIORo3uXlb5M/+/G5jEM6m79fz8SHTNFCBBLv0 w4ROFtwev9cmy1tE9tENlqSi+HrRI8vPK2rZW96v1ellMiV9Ie8fPJ+y6GiD5beTKZaG RoyCQQExg8Xpxno3yepZ4shoEOg6HC9Z8otvW1/27Xj0BZlAoW4RTW8AcEeX+817nRku BPb2pVjTtZqLhJI6oYBZgh1s3W0K9a3QbuLRXykSUK+GsCEYUOAsFGnR4BtWhXdqcpy+ fXSw== 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=fbYFCSe2zvXv9fKWwAETiVQtSZbEfmbD928ZA0VvtzA=; b=qOmEAZ10ALgXyKp8fXfnMYPs35lfbhGl+ofqPSNkWOoY2B1HnJJA/2YvkS4djtKQsr HWk5z2h165beelFb6yj97JWqIUUQTdS7FVwTsdmv6vIlZbXNCbYFAcOjsfcn6r1oNykt NgbryLcoqDWUZMe97nOdsuSyT1Clh3PoHtAMUpfG9MP9XBvPvyhmXuMowaO/WnSVIYAS 7OBcGsPLjHTnhjBkV/a2fNdB5g9GuQEtCXl//wStXKUFg9OmctoY3GdU7aYXonTmAvWi iMu1qXrLGuphEx38k/gWz++U4FxSb/klxC0urXrjZlDBaEr05zYIKV3zO4WbgObnP3QN TY+Q== X-Gm-Message-State: AOAM531y+0p1gI437DK6elzd8btlSQlpG8rDy8JrhMVeKda858QBPqGa eadOFudOthur7JKwhgzC0IA9lygBEmtkf18X X-Received: by 2002:a05:6102:a4a:: with SMTP id i10mr49521918vss.47.1638925683912; Tue, 07 Dec 2021 17:08:03 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:03 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:44 -0300 Message-Id: <20211208010649.381-29-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 274/279] avfilter: 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: c6LHaFv8P94c Signed-off-by: James Almer --- libavfilter/aeval.c | 19 +- libavfilter/af_afir.c | 9 +- libavfilter/af_aformat.c | 32 +++- libavfilter/af_amerge.c | 38 ++-- libavfilter/af_amix.c | 2 +- libavfilter/af_apulsator.c | 2 +- libavfilter/af_aresample.c | 41 +++-- libavfilter/af_ashowinfo.c | 13 +- libavfilter/af_asr.c | 2 +- libavfilter/af_biquads.c | 42 ++--- libavfilter/af_bs2b.c | 2 +- libavfilter/af_channelmap.c | 86 +++++---- libavfilter/af_channelsplit.c | 42 +++-- libavfilter/af_compand.c | 6 + libavfilter/af_compensationdelay.c | 7 + libavfilter/af_crossfeed.c | 2 +- libavfilter/af_earwax.c | 2 +- libavfilter/af_extrastereo.c | 2 +- libavfilter/af_firequalizer.c | 5 +- libavfilter/af_haas.c | 2 +- libavfilter/af_hdcd.c | 4 +- libavfilter/af_headphone.c | 22 +-- libavfilter/af_join.c | 268 +++++++++++++++++++---------- libavfilter/af_ladspa.c | 16 +- libavfilter/af_lv2.c | 17 +- libavfilter/af_pan.c | 62 +++---- libavfilter/af_replaygain.c | 2 +- libavfilter/af_sofalizer.c | 86 ++++----- libavfilter/af_speechnorm.c | 12 +- libavfilter/af_stereotools.c | 2 +- libavfilter/af_stereowiden.c | 2 +- libavfilter/af_surround.c | 72 ++++---- libavfilter/asrc_afirsrc.c | 2 +- libavfilter/asrc_anoisesrc.c | 2 +- libavfilter/asrc_anullsrc.c | 13 +- libavfilter/asrc_flite.c | 6 +- libavfilter/asrc_hilbert.c | 2 +- libavfilter/asrc_sinc.c | 2 +- libavfilter/asrc_sine.c | 2 +- libavfilter/audio.c | 11 +- libavfilter/avf_aphasemeter.c | 2 +- libavfilter/avf_avectorscope.c | 2 +- libavfilter/avf_showcqt.c | 3 +- libavfilter/avf_showspatial.c | 2 +- libavfilter/avf_showspectrum.c | 3 +- libavfilter/avf_showvolume.c | 9 +- libavfilter/avfilter.c | 15 +- libavfilter/avfilter.h | 10 +- libavfilter/avfiltergraph.c | 84 +++++---- libavfilter/buffersink.c | 29 +++- libavfilter/buffersink.h | 7 +- libavfilter/buffersrc.c | 92 +++++++--- libavfilter/buffersrc.h | 9 + libavfilter/f_ebur128.c | 10 +- libavfilter/f_streamselect.c | 4 + libavfilter/formats.c | 131 +++++++++----- libavfilter/formats.h | 16 +- libavfilter/graphdump.c | 4 +- libavfilter/internal.h | 2 +- libavfilter/src_movie.c | 19 +- libavfilter/tests/filtfmts.c | 3 +- libavfilter/tests/formats.c | 8 +- libavfilter/vaf_spectrumsynth.c | 2 +- tests/ref/fate/filter-formats | 20 +-- 64 files changed, 903 insertions(+), 544 deletions(-) diff --git a/libavfilter/aeval.c b/libavfilter/aeval.c index 42cfa81325..58db12c026 100644 --- a/libavfilter/aeval.c +++ b/libavfilter/aeval.c @@ -57,7 +57,7 @@ typedef struct EvalContext { const AVClass *class; char *sample_rate_str; int sample_rate; - int64_t chlayout; + AVChannelLayout chlayout; char *chlayout_str; int nb_channels; ///< number of output channels int nb_in_channels; ///< number of input channels @@ -70,7 +70,6 @@ typedef struct EvalContext { uint64_t n; double var_values[VAR_VARS_NB]; double *channel_values; - int64_t out_channel_layout; } EvalContext; static double val(void *priv, double ch) @@ -181,7 +180,7 @@ static av_cold int init(AVFilterContext *ctx) if (ret < 0) return ret; - ret = parse_channel_expressions(ctx, av_get_channel_layout_nb_channels(eval->chlayout)); + ret = parse_channel_expressions(ctx, eval->chlayout.nb_channels); if (ret < 0) return ret; } @@ -190,8 +189,8 @@ static av_cold int init(AVFilterContext *ctx) if ((ret = parse_channel_expressions(ctx, -1)) < 0) return ret; - eval->chlayout = av_get_default_channel_layout(eval->nb_channels); - if (!eval->chlayout && eval->nb_channels <= 0) { + av_channel_layout_default(&eval->chlayout, eval->nb_channels); + if (eval->nb_channels <= 0) { av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n", eval->nb_channels); return AVERROR(EINVAL); @@ -231,7 +230,7 @@ static int config_props(AVFilterLink *outlink) eval->var_values[VAR_NB_IN_CHANNELS] = NAN; eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->channels; - av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout); + av_channel_layout_describe(&eval->chlayout, buf, sizeof(buf)); av_log(outlink->src, AV_LOG_VERBOSE, "sample_rate:%d chlayout:%s duration:%"PRId64"\n", @@ -244,7 +243,7 @@ static int query_formats(AVFilterContext *ctx) { EvalContext *eval = ctx->priv; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE }; - int64_t chlayouts[] = { eval->chlayout ? eval->chlayout : FF_COUNT2LAYOUT(eval->nb_channels) , -1 }; + AVChannelLayout chlayouts[] = { eval->chlayout.nb_channels ? eval->chlayout : FF_COUNT2LAYOUT(eval->nb_channels), { 0 } }; int sample_rates[] = { eval->sample_rate, -1 }; int ret; @@ -365,9 +364,7 @@ static int aeval_query_formats(AVFilterContext *ctx) } else { // outlink supports only requested output channel layout layouts = NULL; - if ((ret = ff_add_channel_layout(&layouts, - eval->out_channel_layout ? eval->out_channel_layout : - FF_COUNT2LAYOUT(eval->nb_channels))) < 0) + if ((ret = ff_add_channel_layout(&layouts, &FF_COUNT2LAYOUT(eval->nb_channels))) < 0) return ret; if ((ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts)) < 0) return ret; @@ -387,7 +384,7 @@ static int aeval_config_output(AVFilterLink *outlink) int ret; if (eval->same_chlayout) { - eval->chlayout = inlink->channel_layout; + eval->chlayout = inlink->ch_layout; if ((ret = parse_channel_expressions(ctx, inlink->channels)) < 0) return ret; diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c index ace5087e90..b1517af245 100644 --- a/libavfilter/af_afir.c +++ b/libavfilter/af_afir.c @@ -745,7 +745,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0) return ret; - ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO); + ret = ff_add_channel_layout(&mono, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO); if (ret) return ret; for (int i = 1; i < ctx->nb_inputs; i++) { @@ -764,11 +764,18 @@ static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; AudioFIRContext *s = ctx->priv; + int ret; s->one2many = ctx->inputs[1 + s->selir]->channels == 1; outlink->sample_rate = ctx->inputs[0]->sample_rate; outlink->time_base = ctx->inputs[0]->time_base; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS outlink->channel_layout = ctx->inputs[0]->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if ((ret = av_channel_layout_copy(&outlink->ch_layout, &ctx->inputs[0]->ch_layout)) < 0) + return ret; outlink->channels = ctx->inputs[0]->channels; s->nb_channels = outlink->channels; diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index ed3c75311a..f42e240cbd 100644 --- a/libavfilter/af_aformat.c +++ b/libavfilter/af_aformat.c @@ -104,9 +104,35 @@ static av_cold int init(AVFilterContext *ctx) ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format"); PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format, get_sample_rate, 0, "sample rate"); - PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts, - ff_add_channel_layout, av_get_channel_layout, 0, - "channel layout"); + { + char *next, *cur = s->channel_layouts_str, sep; + int ret; + + if (s->channel_layouts_str && strchr(s->channel_layouts_str, ',')) { + av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to " + "separate channel layouts.\n"); + sep = ','; + } else + sep = '|'; + + while (cur) { + AVChannelLayout fmt = { 0 }; + next = strchr(cur, sep); + if (next) + *next++ = 0; + + ret = av_channel_layout_from_string(&fmt, cur); + if (ret < 0) { + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur); + return ret; + } + if ((ret = ff_add_channel_layout(&s->channel_layouts, &fmt)) < 0) { + return ret; + } + + cur = next; + } + } return 0; } diff --git a/libavfilter/af_amerge.c b/libavfilter/af_amerge.c index 9109af22c5..edc7933ab6 100644 --- a/libavfilter/af_amerge.c +++ b/libavfilter/af_amerge.c @@ -73,7 +73,8 @@ static int query_formats(AVFilterContext *ctx) AV_SAMPLE_FMT_NONE }; AMergeContext *s = ctx->priv; - int64_t inlayout[SWR_CH_MAX], outlayout = 0; + AVChannelLayout *inlayout[SWR_CH_MAX] = { NULL }, outlayout = { 0 }; + uint64_t outmask = 0; AVFilterChannelLayouts *layouts; int i, ret, overlap = 0, nb_ch = 0; @@ -84,20 +85,21 @@ static int query_formats(AVFilterContext *ctx) "No channel layout for input %d\n", i + 1); return AVERROR(EAGAIN); } - inlayout[i] = ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0]; + inlayout[i] = &ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0]; if (ctx->inputs[i]->incfg.channel_layouts->nb_channel_layouts > 1) { char buf[256]; - av_get_channel_layout_string(buf, sizeof(buf), 0, inlayout[i]); + av_channel_layout_describe(inlayout[i], buf, sizeof(buf)); av_log(ctx, AV_LOG_INFO, "Using \"%s\" for input %d\n", buf, i + 1); } s->in[i].nb_ch = FF_LAYOUT2COUNT(inlayout[i]); if (s->in[i].nb_ch) { overlap++; } else { - s->in[i].nb_ch = av_get_channel_layout_nb_channels(inlayout[i]); - if (outlayout & inlayout[i]) + s->in[i].nb_ch = inlayout[i]->nb_channels; + if (av_channel_layout_subset(inlayout[i], outmask)) overlap++; - outlayout |= inlayout[i]; + outmask |= inlayout[i]->order == AV_CHANNEL_ORDER_NATIVE ? + inlayout[i]->u.mask : 0; } nb_ch += s->in[i].nb_ch; } @@ -111,19 +113,20 @@ static int query_formats(AVFilterContext *ctx) "output layout will be determined by the number of distinct input channels\n"); for (i = 0; i < nb_ch; i++) s->route[i] = i; - outlayout = av_get_default_channel_layout(nb_ch); - if (!outlayout && nb_ch) - outlayout = 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch); + av_channel_layout_default(&outlayout, nb_ch); + if (!KNOWN(&outlayout) && nb_ch) + av_channel_layout_from_mask(&outlayout, 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch)); } else { int *route[SWR_CH_MAX]; int c, out_ch_number = 0; + av_channel_layout_from_mask(&outlayout, outmask); route[0] = s->route; for (i = 1; i < s->nb_inputs; i++) route[i] = route[i - 1] + s->in[i - 1].nb_ch; for (c = 0; c < 64; c++) for (i = 0; i < s->nb_inputs; i++) - if ((inlayout[i] >> c) & 1) + if (av_channel_layout_index_from_channel(inlayout[i], c) >= 0) *(route[i]++) = out_ch_number++; } if ((ret = ff_set_common_formats_from_list(ctx, packed_sample_fmts)) < 0) @@ -136,7 +139,7 @@ static int query_formats(AVFilterContext *ctx) return ret; } layouts = NULL; - if ((ret = ff_add_channel_layout(&layouts, outlayout)) < 0) + if ((ret = ff_add_channel_layout(&layouts, &outlayout)) < 0) return ret; if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0) return ret; @@ -149,6 +152,7 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; AMergeContext *s = ctx->priv; AVBPrint bp; + char buf[128]; int i; s->bps = av_get_bytes_per_sample(ctx->outputs[0]->format); @@ -157,10 +161,12 @@ static int config_output(AVFilterLink *outlink) av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC); for (i = 0; i < s->nb_inputs; i++) { av_bprintf(&bp, "%sin%d:", i ? " + " : "", i); - av_bprint_channel_layout(&bp, -1, ctx->inputs[i]->channel_layout); + av_channel_layout_describe(&ctx->inputs[i]->ch_layout, buf, sizeof(buf)); + av_bprintf(&bp, "%s", buf); } av_bprintf(&bp, " -> out:"); - av_bprint_channel_layout(&bp, -1, ctx->outputs[0]->channel_layout); + av_channel_layout_describe(&ctx->outputs[0]->ch_layout, buf, sizeof(buf)); + av_bprintf(&bp, "%s", buf); av_log(ctx, AV_LOG_VERBOSE, "%s\n", bp.str); return 0; @@ -237,8 +243,14 @@ static int try_push_frame(AVFilterContext *ctx, int nb_samples) outbuf->pts = inbuf[0]->pts; outbuf->nb_samples = nb_samples; + if ((ret = av_channel_layout_copy(&outbuf->ch_layout, &outlink->ch_layout)) < 0) + return ret; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS outbuf->channel_layout = outlink->channel_layout; outbuf->channels = outlink->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif while (nb_samples) { /* Unroll the most common sample formats: speed +~350% for the loop, diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index 3f51d43acd..097f637aac 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -282,7 +282,7 @@ static int config_output(AVFilterLink *outlink) s->scale_norm[i] = s->weight_sum / FFABS(s->weights[i]); calculate_scales(s, 0); - av_get_channel_layout_string(buf, sizeof(buf), -1, outlink->channel_layout); + av_channel_layout_describe(&outlink->ch_layout, buf, sizeof(buf)); av_log(ctx, AV_LOG_VERBOSE, "inputs:%d fmt:%s srate:%d cl:%s\n", s->nb_inputs, diff --git a/libavfilter/af_apulsator.c b/libavfilter/af_apulsator.c index c2a8de0e0b..c3ca752035 100644 --- a/libavfilter/af_apulsator.c +++ b/libavfilter/af_apulsator.c @@ -192,7 +192,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_DBL )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0) return ret; diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c index 6e1be5b7eb..422c34d0e3 100644 --- a/libavfilter/af_aresample.c +++ b/libavfilter/af_aresample.c @@ -65,7 +65,8 @@ static int query_formats(AVFilterContext *ctx) { AResampleContext *aresample = ctx->priv; enum AVSampleFormat out_format; - int64_t out_rate, out_layout; + AVChannelLayout out_layout = { 0 }; + int64_t out_rate; AVFilterLink *inlink = ctx->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; @@ -79,7 +80,7 @@ static int query_formats(AVFilterContext *ctx) av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0); av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format); av_opt_get_int(aresample->swr, "osr", 0, &out_rate); - av_opt_get_int(aresample->swr, "ocl", 0, &out_layout); + av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout); in_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO); if ((ret = ff_formats_ref(in_formats, &inlink->outcfg.formats)) < 0) @@ -111,8 +112,8 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_formats_ref(out_formats, &outlink->incfg.formats)) < 0) return ret; - if(out_layout) { - int64_t layout_list[] = { out_layout, -1 }; + if(av_channel_layout_check(&out_layout) && out_layout.order == AV_CHANNEL_ORDER_NATIVE) { + const AVChannelLayout layout_list[] = { out_layout, { 0 } }; out_layouts = ff_make_format64_list(layout_list); } else out_layouts = ff_all_channel_counts(); @@ -127,38 +128,35 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; AResampleContext *aresample = ctx->priv; - int64_t out_rate, out_layout; + AVChannelLayout out_layout = { 0 }; + int64_t out_rate; enum AVSampleFormat out_format; char inchl_buf[128], outchl_buf[128]; - aresample->swr = swr_alloc_set_opts(aresample->swr, - outlink->channel_layout, outlink->format, outlink->sample_rate, - inlink->channel_layout, inlink->format, inlink->sample_rate, - 0, ctx); - if (!aresample->swr) - return AVERROR(ENOMEM); - if (!inlink->channel_layout) - av_opt_set_int(aresample->swr, "ich", inlink->channels, 0); - if (!outlink->channel_layout) - av_opt_set_int(aresample->swr, "och", outlink->channels, 0); + ret = swr_alloc_set_opts2(&aresample->swr, + &outlink->ch_layout, outlink->format, outlink->sample_rate, + &inlink->ch_layout, inlink->format, inlink->sample_rate, + 0, ctx); + if (ret < 0) + return ret; ret = swr_init(aresample->swr); if (ret < 0) return ret; av_opt_get_int(aresample->swr, "osr", 0, &out_rate); - av_opt_get_int(aresample->swr, "ocl", 0, &out_layout); + av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout); av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format); outlink->time_base = (AVRational) {1, out_rate}; av_assert0(outlink->sample_rate == out_rate); - av_assert0(outlink->channel_layout == out_layout || !outlink->channel_layout); + av_assert0(!av_channel_layout_compare(&outlink->ch_layout, &out_layout)); av_assert0(outlink->format == out_format); aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate; - av_get_channel_layout_string(inchl_buf, sizeof(inchl_buf), inlink ->channels, inlink ->channel_layout); - av_get_channel_layout_string(outchl_buf, sizeof(outchl_buf), outlink->channels, outlink->channel_layout); + av_channel_layout_describe(&inlink ->ch_layout, inchl_buf, sizeof(inchl_buf)); + av_channel_layout_describe(&outlink->ch_layout, outchl_buf, sizeof(outchl_buf)); av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n", inlink ->channels, inchl_buf, av_get_sample_fmt_name(inlink->format), inlink->sample_rate, @@ -189,8 +187,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) av_frame_copy_props(outsamplesref, insamplesref); outsamplesref->format = outlink->format; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS outsamplesref->channels = outlink->channels; outsamplesref->channel_layout = outlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + outsamplesref->ch_layout = outlink->ch_layout; outsamplesref->sample_rate = outlink->sample_rate; if(insamplesref->pts != AV_NOPTS_VALUE) { diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c index c76756db63..949f0e52a4 100644 --- a/libavfilter/af_ashowinfo.c +++ b/libavfilter/af_ashowinfo.c @@ -178,6 +178,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) { AVFilterContext *ctx = inlink->dst; AShowInfoContext *s = ctx->priv; +#if FF_API_OLD_CHANNEL_LAYOUT + AVChannelLayout layout = { 0 }; +#endif char chlayout_str[128]; uint32_t checksum = 0; int channels = inlink->channels; @@ -200,8 +203,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) s->plane_checksums[0]; } - av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), buf->channels, - buf->channel_layout); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (av_channel_layout_from_mask(&layout, buf->channel_layout)) { + av_channel_layout_describe(&layout, chlayout_str, sizeof(chlayout_str)); +FF_ENABLE_DEPRECATION_WARNINGS + } else if (buf->ch_layout.nb_channels) +#endif + av_channel_layout_describe(&buf->ch_layout, chlayout_str, sizeof(chlayout_str)); av_log(ctx, AV_LOG_INFO, "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" " diff --git a/libavfilter/af_asr.c b/libavfilter/af_asr.c index 42250e79e2..b402f5ff26 100644 --- a/libavfilter/af_asr.c +++ b/libavfilter/af_asr.c @@ -131,7 +131,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_S16 )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_MONO )) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO )) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0 || (ret = ff_set_common_samplerates_from_list(ctx, sample_rates )) < 0) return ret; diff --git a/libavfilter/af_biquads.c b/libavfilter/af_biquads.c index ee42b2a034..a655d21226 100644 --- a/libavfilter/af_biquads.c +++ b/libavfilter/af_biquads.c @@ -125,7 +125,7 @@ typedef struct BiquadsContext { double frequency; double width; double mix; - uint64_t channels; + AVChannelLayout ch_layout; int normalize; int order; @@ -843,7 +843,9 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job int ch; for (ch = start; ch < end; ch++) { - if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) { + if (!(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 && + av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0)) { + if (buf != out_buf) memcpy(out_buf->extended_data[ch], buf->extended_data[ch], buf->nb_samples * s->block_align); @@ -982,8 +984,8 @@ static const AVOption equalizer_options[] = { {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, @@ -1024,8 +1026,8 @@ static const AVOption bass_lowshelf_options[] = { {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, @@ -1073,8 +1075,8 @@ static const AVOption treble_highshelf_options[] = { {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, @@ -1121,8 +1123,8 @@ static const AVOption bandpass_options[] = { {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, @@ -1159,8 +1161,8 @@ static const AVOption bandreject_options[] = { {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, @@ -1199,8 +1201,8 @@ static const AVOption lowpass_options[] = { {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, @@ -1239,8 +1241,8 @@ static const AVOption highpass_options[] = { {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, @@ -1277,8 +1279,8 @@ static const AVOption allpass_options[] = { {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS}, @@ -1312,8 +1314,8 @@ static const AVOption biquad_options[] = { {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}, - {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, - {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS}, + {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, + {"c", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS}, {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"}, diff --git a/libavfilter/af_bs2b.c b/libavfilter/af_bs2b.c index 90ae846d95..20e6d8141a 100644 --- a/libavfilter/af_bs2b.c +++ b/libavfilter/af_bs2b.c @@ -104,7 +104,7 @@ static int query_formats(AVFilterContext *ctx) }; int ret; - if (ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO) != 0) + if (ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) != 0) return AVERROR(ENOMEM); ret = ff_set_common_channel_layouts(ctx, layouts); if (ret < 0) diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index d3ab77920f..c8d259a9ff 100644 --- a/libavfilter/af_channelmap.c +++ b/libavfilter/af_channelmap.c @@ -38,8 +38,8 @@ #include "internal.h" struct ChannelMap { - uint64_t in_channel; - uint64_t out_channel; + int in_channel; + int out_channel; int in_channel_idx; int out_channel_idx; }; @@ -59,7 +59,7 @@ typedef struct ChannelMapContext { const AVClass *class; char *mapping_str; char *channel_layout_str; - uint64_t output_layout; + AVChannelLayout output_layout; struct ChannelMap map[MAX_CH]; int nch; enum MappingMode mode; @@ -105,13 +105,13 @@ static int get_channel_idx(char **map, int *ch, char delim, int max_ch) return 0; } -static int get_channel(char **map, uint64_t *ch, char delim) +static int get_channel(char **map, int *ch, char delim) { char *next = split(*map, delim); if (!next && delim == '-') return AVERROR(EINVAL); - *ch = av_get_channel_layout(*map); - if (av_get_channel_layout_nb_channels(*ch) != 1) + *ch = av_channel_from_string(*map); + if (*ch < 0) return AVERROR(EINVAL); *map = next; return 0; @@ -167,7 +167,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx) for (i = 0; i < map_entries; i++) { int in_ch_idx = -1, out_ch_idx = -1; - uint64_t in_ch = 0, out_ch = 0; + int in_ch = 0, out_ch = 0; static const char err[] = "Failed to parse channel map\n"; switch (mode) { case MAP_ONE_INT: @@ -198,13 +198,13 @@ static av_cold int channelmap_init(AVFilterContext *ctx) case MAP_PAIR_INT_STR: if (get_channel_idx(&mapping, &in_ch_idx, '-', MAX_CH) < 0 || get_channel(&mapping, &out_ch, separator) < 0 || - out_ch & out_ch_mask) { + (1ULL << out_ch) & out_ch_mask) { av_log(ctx, AV_LOG_ERROR, err); return AVERROR(EINVAL); } s->map[i].in_channel_idx = in_ch_idx; s->map[i].out_channel = out_ch; - out_ch_mask |= out_ch; + out_ch_mask |= 1ULL << out_ch; break; case MAP_PAIR_STR_INT: if (get_channel(&mapping, &in_ch, '-') < 0 || @@ -218,42 +218,57 @@ static av_cold int channelmap_init(AVFilterContext *ctx) case MAP_PAIR_STR_STR: if (get_channel(&mapping, &in_ch, '-') < 0 || get_channel(&mapping, &out_ch, separator) < 0 || - out_ch & out_ch_mask) { + (1ULL << out_ch) & out_ch_mask) { av_log(ctx, AV_LOG_ERROR, err); return AVERROR(EINVAL); } s->map[i].in_channel = in_ch; s->map[i].out_channel = out_ch; - out_ch_mask |= out_ch; + out_ch_mask |= 1ULL << out_ch; break; } } s->mode = mode; s->nch = map_entries; - s->output_layout = out_ch_mask ? out_ch_mask : - av_get_default_channel_layout(map_entries); + if (out_ch_mask) + av_channel_layout_from_mask(&s->output_layout, out_ch_mask); + else + av_channel_layout_default(&s->output_layout, map_entries); if (s->channel_layout_str) { - uint64_t fmt; - if ((fmt = av_get_channel_layout(s->channel_layout_str)) == 0) { - av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n", + AVChannelLayout fmt = { 0 }; + int ret; + if ((ret = av_channel_layout_from_string(&fmt, s->channel_layout_str)) < 0) { +#if FF_API_OLD_CHANNEL_LAYOUT + uint64_t mask; +FF_DISABLE_DEPRECATION_WARNINGS + if ((mask = av_get_channel_layout(s->channel_layout_str)) == 0) { +#endif + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n", + s->channel_layout_str); + return AVERROR(EINVAL); +#if FF_API_OLD_CHANNEL_LAYOUT + } +FF_ENABLE_DEPRECATION_WARNINGS + av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n", s->channel_layout_str); - return AVERROR(EINVAL); + av_channel_layout_from_mask(&fmt, mask); +#endif } if (mode == MAP_NONE) { int i; - s->nch = av_get_channel_layout_nb_channels(fmt); + s->nch = fmt.nb_channels; for (i = 0; i < s->nch; i++) { s->map[i].in_channel_idx = i; s->map[i].out_channel_idx = i; } - } else if (out_ch_mask && out_ch_mask != fmt) { - av_get_channel_layout_string(buf, sizeof(buf), 0, out_ch_mask); + } else if (out_ch_mask && av_channel_layout_compare(&s->output_layout, &fmt)) { + av_channel_layout_describe(&s->output_layout, buf, sizeof(buf)); av_log(ctx, AV_LOG_ERROR, "Output channel layout '%s' does not match the list of channel mapped: '%s'.\n", s->channel_layout_str, buf); return AVERROR(EINVAL); - } else if (s->nch != av_get_channel_layout_nb_channels(fmt)) { + } else if (s->nch != fmt.nb_channels) { av_log(ctx, AV_LOG_ERROR, "Output channel layout %s does not match the number of channels mapped %d.\n", s->channel_layout_str, s->nch); @@ -261,7 +276,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx) } s->output_layout = fmt; } - if (!s->output_layout) { + if (!s->output_layout.nb_channels) { av_log(ctx, AV_LOG_ERROR, "Output channel layout is not set and " "cannot be guessed from the maps.\n"); return AVERROR(EINVAL); @@ -269,8 +284,8 @@ static av_cold int channelmap_init(AVFilterContext *ctx) if (mode == MAP_PAIR_INT_STR || mode == MAP_PAIR_STR_STR) { for (i = 0; i < s->nch; i++) { - s->map[i].out_channel_idx = av_get_channel_layout_channel_index( - s->output_layout, s->map[i].out_channel); + s->map[i].out_channel_idx = av_channel_layout_index_from_channel( + &s->output_layout, s->map[i].out_channel); } } @@ -285,7 +300,7 @@ static int channelmap_query_formats(AVFilterContext *ctx) if ((ret = ff_set_common_formats (ctx, ff_planar_sample_fmts())) < 0 || (ret = ff_set_common_all_samplerates(ctx )) < 0 || - (ret = ff_add_channel_layout(&channel_layouts, s->output_layout)) < 0 || + (ret = ff_add_channel_layout(&channel_layouts, &s->output_layout)) < 0 || (ret = ff_channel_layouts_ref(channel_layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0) return ret; @@ -301,7 +316,7 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf) const ChannelMapContext *s = ctx->priv; const int nch_in = inlink->channels; const int nch_out = s->nch; - int ch; + int ch, ret; uint8_t *source_planes[MAX_CH]; memcpy(source_planes, buf->extended_data, @@ -336,7 +351,13 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf) memcpy(buf->data, buf->extended_data, FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0])); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS buf->channel_layout = outlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if ((ret = av_channel_layout_copy(&buf->ch_layout, &outlink->ch_layout)) < 0) + return ret; buf->channels = outlink->channels; return ff_filter_frame(outlink, buf); @@ -346,24 +367,23 @@ static int channelmap_config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; ChannelMapContext *s = ctx->priv; - int nb_channels = inlink->channels; + int nb_channels = inlink->ch_layout.nb_channels; int i, err = 0; - const char *channel_name; + char channel_name[64]; char layout_name[256]; for (i = 0; i < s->nch; i++) { struct ChannelMap *m = &s->map[i]; if (s->mode == MAP_PAIR_STR_INT || s->mode == MAP_PAIR_STR_STR) { - m->in_channel_idx = av_get_channel_layout_channel_index( - inlink->channel_layout, m->in_channel); + m->in_channel_idx = av_channel_layout_index_from_channel( + &inlink->ch_layout, m->in_channel); } if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) { - av_get_channel_layout_string(layout_name, sizeof(layout_name), - nb_channels, inlink->channel_layout); + av_channel_layout_describe(&inlink->ch_layout, layout_name, sizeof(layout_name)); if (m->in_channel) { - channel_name = av_get_channel_name(m->in_channel); + av_channel_name(channel_name, sizeof(channel_name), m->in_channel); av_log(ctx, AV_LOG_ERROR, "input channel '%s' not available from input layout '%s'\n", channel_name, layout_name); diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c index 1a2519dd32..099ba097e2 100644 --- a/libavfilter/af_channelsplit.c +++ b/libavfilter/af_channelsplit.c @@ -36,7 +36,7 @@ typedef struct ChannelSplitContext { const AVClass *class; - uint64_t channel_layout; + AVChannelLayout channel_layout; char *channel_layout_str; char *channels_str; @@ -57,11 +57,11 @@ AVFILTER_DEFINE_CLASS(channelsplit); static av_cold int init(AVFilterContext *ctx) { ChannelSplitContext *s = ctx->priv; - uint64_t channel_layout; + AVChannelLayout channel_layout = { 0 }; int nb_channels; int all = 0, ret = 0, i; - if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) { + if ((ret = av_channel_layout_from_string(&s->channel_layout, s->channel_layout_str)) < 0) { av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n", s->channel_layout_str); ret = AVERROR(EINVAL); @@ -70,27 +70,32 @@ static av_cold int init(AVFilterContext *ctx) if (!strcmp(s->channels_str, "all")) { - nb_channels = av_get_channel_layout_nb_channels(s->channel_layout); + nb_channels = s->channel_layout.nb_channels; channel_layout = s->channel_layout; all = 1; } else { - if ((ret = av_get_extended_channel_layout(s->channels_str, &channel_layout, &nb_channels)) < 0) + if ((ret = av_channel_layout_from_string(&channel_layout, s->channels_str)) < 0) return ret; } for (i = 0; i < nb_channels; i++) { - uint64_t channel = av_channel_layout_extract_channel(channel_layout, i); - AVFilterPad pad = { 0 }; + int channel = av_channel_layout_channel_from_index(&channel_layout, i); + char buf[64]; + AVFilterPad pad = { .flags = AVFILTERPAD_FLAG_FREE_NAME }; + av_channel_name(buf, sizeof(buf), channel); pad.type = AVMEDIA_TYPE_AUDIO; - pad.name = av_get_channel_name(channel); + pad.name = av_strdup(buf); + if (!pad.name) + return AVERROR(ENOMEM); if (all) { s->map[i] = i; } else { - if ((ret = av_get_channel_layout_channel_index(s->channel_layout, channel)) < 0) { + if ((ret = av_channel_layout_index_from_channel(&s->channel_layout, channel)) < 0) { av_log(ctx, AV_LOG_ERROR, "Channel name '%s' not present in channel layout '%s'.\n", - av_get_channel_name(channel), s->channel_layout_str); + pad.name, s->channel_layout_str); + av_freep(&pad.name); return ret; } @@ -115,15 +120,18 @@ static int query_formats(AVFilterContext *ctx) (ret = ff_set_common_all_samplerates(ctx)) < 0) return ret; - if ((ret = ff_add_channel_layout(&in_layouts, s->channel_layout)) < 0 || + if ((ret = ff_add_channel_layout(&in_layouts, &s->channel_layout)) < 0 || (ret = ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->outcfg.channel_layouts)) < 0) return ret; for (i = 0; i < ctx->nb_outputs; i++) { + AVChannelLayout channel_layout = { 0 }; AVFilterChannelLayouts *out_layouts = NULL; - uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, s->map[i]); + int channel = av_channel_layout_channel_from_index(&s->channel_layout, s->map[i]); - if ((ret = ff_add_channel_layout(&out_layouts, channel)) < 0 || + if ((channel < 0) || + (ret = av_channel_layout_from_mask(&channel_layout, 1ULL << channel)) < 0 || + (ret = ff_add_channel_layout(&out_layouts, &channel_layout)) < 0 || (ret = ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->incfg.channel_layouts)) < 0) return ret; } @@ -139,6 +147,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) for (i = 0; i < ctx->nb_outputs; i++) { AVFrame *buf_out = av_frame_clone(buf); + int channel = av_channel_layout_channel_from_index(&buf->ch_layout, s->map[i]); if (!buf_out) { ret = AVERROR(ENOMEM); @@ -146,8 +155,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) } buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[s->map[i]]; + ret = av_channel_layout_from_mask(&buf_out->ch_layout, 1ULL << channel); + if (ret < 0) + break; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS buf_out->channel_layout = av_channel_layout_extract_channel(buf->channel_layout, s->map[i]); +FF_ENABLE_DEPRECATION_WARNINGS +#endif buf_out->channels = 1; ret = ff_filter_frame(ctx->outputs[i], buf_out); diff --git a/libavfilter/af_compand.c b/libavfilter/af_compand.c index 2f8a580279..31e1a0b548 100644 --- a/libavfilter/af_compand.c +++ b/libavfilter/af_compand.c @@ -503,7 +503,13 @@ static int config_output(AVFilterLink *outlink) s->delay_frame->format = outlink->format; s->delay_frame->nb_samples = s->delay_samples; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS s->delay_frame->channel_layout = outlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if ((err = av_channel_layout_copy(&s->delay_frame->ch_layout, &outlink->ch_layout)) < 0) + return err; err = av_frame_get_buffer(s->delay_frame, 0); if (err) diff --git a/libavfilter/af_compensationdelay.c b/libavfilter/af_compensationdelay.c index 6a58fd21bd..94b9447df2 100644 --- a/libavfilter/af_compensationdelay.c +++ b/libavfilter/af_compensationdelay.c @@ -68,6 +68,7 @@ static int config_input(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; CompensationDelayContext *s = ctx->priv; unsigned min_size, new_size = 1; + int ret; s->delay = (s->distance_m * 100. + s->distance_cm * 1. + s->distance_mm * .1) * COMP_DELAY_SOUND_FRONT_DELAY(s->temp) * inlink->sample_rate; @@ -83,7 +84,13 @@ static int config_input(AVFilterLink *inlink) s->buf_size = new_size; s->delay_frame->format = inlink->format; s->delay_frame->nb_samples = new_size; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS s->delay_frame->channel_layout = inlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if ((ret = av_channel_layout_copy(&s->delay_frame->ch_layout, &inlink->ch_layout)) < 0) + return ret; return av_frame_get_buffer(s->delay_frame, 0); } diff --git a/libavfilter/af_crossfeed.c b/libavfilter/af_crossfeed.c index ecfbb978d4..15990703e1 100644 --- a/libavfilter/af_crossfeed.c +++ b/libavfilter/af_crossfeed.c @@ -46,7 +46,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_DBL )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0 || (ret = ff_set_common_all_samplerates (ctx )) < 0) return ret; diff --git a/libavfilter/af_earwax.c b/libavfilter/af_earwax.c index fa0162abb2..f420a5ac55 100644 --- a/libavfilter/af_earwax.c +++ b/libavfilter/af_earwax.c @@ -88,7 +88,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_S16P )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO )) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0 || (ret = ff_set_common_samplerates_from_list(ctx, sample_rates)) < 0) return ret; diff --git a/libavfilter/af_extrastereo.c b/libavfilter/af_extrastereo.c index 1645ccb944..6f1d691d8e 100644 --- a/libavfilter/af_extrastereo.c +++ b/libavfilter/af_extrastereo.c @@ -49,7 +49,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_FLT )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0) return ret; diff --git a/libavfilter/af_firequalizer.c b/libavfilter/af_firequalizer.c index 568b78117a..cf63d0f21c 100644 --- a/libavfilter/af_firequalizer.c +++ b/libavfilter/af_firequalizer.c @@ -608,13 +608,14 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g av_log(ctx, AV_LOG_WARNING, "dumping failed.\n"); vars[VAR_CHS] = inlink->channels; - vars[VAR_CHLAYOUT] = inlink->channel_layout; + vars[VAR_CHLAYOUT] = inlink->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + inlink->ch_layout.u.mask : 0; vars[VAR_SR] = inlink->sample_rate; for (ch = 0; ch < inlink->channels; ch++) { float *rdft_buf = s->kernel_tmp_buf + ch * s->rdft_len; double result; vars[VAR_CH] = ch; - vars[VAR_CHID] = av_channel_layout_extract_channel(inlink->channel_layout, ch); + vars[VAR_CHID] = av_channel_layout_channel_from_index(&inlink->ch_layout, ch); vars[VAR_F] = 0.0; if (xlog) vars[VAR_F] = log2(0.05 * vars[VAR_F]); diff --git a/libavfilter/af_haas.c b/libavfilter/af_haas.c index 281ec276f9..d283da7261 100644 --- a/libavfilter/af_haas.c +++ b/libavfilter/af_haas.c @@ -87,7 +87,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_DBL )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0) return ret; diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c index 494642106d..08907e718e 100644 --- a/libavfilter/af_hdcd.c +++ b/libavfilter/af_hdcd.c @@ -1627,10 +1627,10 @@ static int query_formats(AVFilterContext *ctx) }; int ret; - ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_MONO); + ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO); if (ret < 0) return ret; - ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO); + ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); if (ret < 0) return ret; diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index b2030dbbbb..15bada4315 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -85,13 +85,13 @@ typedef struct HeadphoneContext { uint64_t mapping[64]; } HeadphoneContext; -static int parse_channel_name(const char *arg, uint64_t *rchannel) +static int parse_channel_name(const char *arg, int *rchannel) { - uint64_t layout = av_get_channel_layout(arg); + int channel = av_channel_from_string(arg); - if (av_get_channel_layout_nb_channels(layout) != 1) + if (channel < 0) return AVERROR(EINVAL); - *rchannel = layout; + *rchannel = channel; return 0; } @@ -103,14 +103,14 @@ static void parse_map(AVFilterContext *ctx) p = s->map; while ((arg = av_strtok(p, "|", &tokenizer))) { - uint64_t out_channel; + int out_channel; p = NULL; if (parse_channel_name(arg, &out_channel)) { av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg); continue; } - if (used_channels & out_channel) { + if (used_channels & (1ULL << out_channel)) { av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", arg); continue; } @@ -451,7 +451,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) ptr = (float *)frame->extended_data[0]; if (s->hrir_fmt == HRIR_STEREO) { - int idx = av_get_channel_layout_channel_index(inlink->channel_layout, + int idx = av_channel_layout_index_from_channel(&inlink->ch_layout, s->mapping[i]); if (idx < 0) continue; @@ -481,7 +481,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) int I, N = ctx->inputs[1]->channels; for (k = 0; k < N / 2; k++) { - int idx = av_get_channel_layout_channel_index(inlink->channel_layout, + int idx = av_channel_layout_index_from_channel(&inlink->ch_layout, s->mapping[k]); if (idx < 0) continue; @@ -602,7 +602,7 @@ static int query_formats(AVFilterContext *ctx) if (ret) return ret; - ret = ff_add_channel_layout(&stereo_layout, AV_CH_LAYOUT_STEREO); + ret = ff_add_channel_layout(&stereo_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); if (ret) return ret; ret = ff_channel_layouts_ref(stereo_layout, &ctx->outputs[0]->incfg.channel_layouts); @@ -637,8 +637,8 @@ static int config_input(AVFilterLink *inlink) return AVERROR(EINVAL); } - s->lfe_channel = av_get_channel_layout_channel_index(inlink->channel_layout, - AV_CH_LOW_FREQUENCY); + s->lfe_channel = av_channel_layout_index_from_channel(&inlink->ch_layout, + AV_CHAN_LOW_FREQUENCY); return 0; } diff --git a/libavfilter/af_join.c b/libavfilter/af_join.c index 6cc21f465c..05fc69e67e 100644 --- a/libavfilter/af_join.c +++ b/libavfilter/af_join.c @@ -24,6 +24,7 @@ * a single output */ +#include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" @@ -36,10 +37,10 @@ #include "internal.h" typedef struct ChannelMap { - int input; ///< input stream index - int in_channel_idx; ///< index of in_channel in the input stream data - uint64_t in_channel; ///< layout describing the input channel - uint64_t out_channel; ///< layout describing the output channel + int input; ///< input stream index + int in_channel_idx; ///< index of in_channel in the input stream data + enum AVChannel in_channel; + enum AVChannel out_channel; } ChannelMap; typedef struct JoinContext { @@ -48,11 +49,10 @@ typedef struct JoinContext { int inputs; char *map; char *channel_layout_str; - uint64_t channel_layout; + AVChannelLayout ch_layout; int64_t eof_pts; - int nb_channels; ChannelMap *channels; /** @@ -79,20 +79,21 @@ static const AVOption join_options[] = { { NULL } }; +#define MAP_SEPARATOR '|' + AVFILTER_DEFINE_CLASS(join); static int parse_maps(AVFilterContext *ctx) { JoinContext *s = ctx->priv; - char separator = '|'; char *cur = s->map; while (cur && *cur) { + ChannelMap *map; char *sep, *next, *p; - uint64_t in_channel = 0, out_channel = 0; - int input_idx, out_ch_idx, in_ch_idx; + int input_idx, out_ch_idx; - next = strchr(cur, separator); + next = strchr(cur, MAP_SEPARATOR); if (next) *next++ = 0; @@ -104,28 +105,16 @@ static int parse_maps(AVFilterContext *ctx) } *sep++ = 0; -#define PARSE_CHANNEL(str, var, inout) \ - if (!(var = av_get_channel_layout(str))) { \ - av_log(ctx, AV_LOG_ERROR, "Invalid " inout " channel: %s.\n", str);\ - return AVERROR(EINVAL); \ - } \ - if (av_get_channel_layout_nb_channels(var) != 1) { \ - av_log(ctx, AV_LOG_ERROR, "Channel map describes more than one " \ - inout " channel.\n"); \ - return AVERROR(EINVAL); \ - } - /* parse output channel */ - PARSE_CHANNEL(sep, out_channel, "output"); - if (!(out_channel & s->channel_layout)) { - av_log(ctx, AV_LOG_ERROR, "Output channel '%s' is not present in " - "requested channel layout.\n", sep); + out_ch_idx = av_channel_layout_index_from_string(&s->ch_layout, sep); + if (out_ch_idx < 0) { + av_log(ctx, AV_LOG_ERROR, "Invalid output channel: %s.\n", sep); return AVERROR(EINVAL); } - out_ch_idx = av_get_channel_layout_channel_index(s->channel_layout, - out_channel); - if (s->channels[out_ch_idx].input >= 0) { + map = &s->channels[out_ch_idx]; + + if (map->input >= 0) { av_log(ctx, AV_LOG_ERROR, "Multiple maps for output channel " "'%s'.\n", sep); return AVERROR(EINVAL); @@ -142,19 +131,21 @@ static int parse_maps(AVFilterContext *ctx) if (*cur) cur++; - in_ch_idx = strtol(cur, &p, 0); + map->input = input_idx; + map->in_channel = AV_CHAN_NONE; + map->in_channel_idx = strtol(cur, &p, 0); if (p == cur) { - /* channel specifier is not a number, - * try to parse as channel name */ - PARSE_CHANNEL(cur, in_channel, "input"); + /* channel specifier is not a number, handle as channel name */ + map->in_channel = av_channel_from_string(cur); + if (map->in_channel < 0) { + av_log(ctx, AV_LOG_ERROR, "Invalid input channel: %s.\n", cur); + return AVERROR(EINVAL); + } + } else if (map->in_channel_idx < 0) { + av_log(ctx, AV_LOG_ERROR, "Invalid input channel index: %d\n", map->in_channel_idx); + return AVERROR(EINVAL); } - s->channels[out_ch_idx].input = input_idx; - if (in_channel) - s->channels[out_ch_idx].in_channel = in_channel; - else - s->channels[out_ch_idx].in_channel_idx = in_ch_idx; - cur = next; } return 0; @@ -165,22 +156,37 @@ static av_cold int join_init(AVFilterContext *ctx) JoinContext *s = ctx->priv; int ret, i; - if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) { - av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n", + ret = av_channel_layout_from_string(&s->ch_layout, s->channel_layout_str); + if (ret < 0) { +#if FF_API_OLD_CHANNEL_LAYOUT + uint64_t mask; +FF_DISABLE_DEPRECATION_WARNINGS + mask = av_get_channel_layout(s->channel_layout_str); + if (!mask) { +#endif + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n", + s->channel_layout_str); + return AVERROR(EINVAL); +#if FF_API_OLD_CHANNEL_LAYOUT + } +FF_ENABLE_DEPRECATION_WARNINGS + av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n", s->channel_layout_str); - return AVERROR(EINVAL); + av_channel_layout_from_mask(&s->ch_layout, mask); +#endif } - s->nb_channels = av_get_channel_layout_nb_channels(s->channel_layout); - s->channels = av_calloc(s->nb_channels, sizeof(*s->channels)); - s->buffers = av_calloc(s->nb_channels, sizeof(*s->buffers)); + s->channels = av_calloc(s->ch_layout.nb_channels, sizeof(*s->channels)); + s->buffers = av_calloc(s->ch_layout.nb_channels, sizeof(*s->buffers)); s->input_frames = av_calloc(s->inputs, sizeof(*s->input_frames)); if (!s->channels || !s->buffers|| !s->input_frames) return AVERROR(ENOMEM); - for (i = 0; i < s->nb_channels; i++) { - s->channels[i].out_channel = av_channel_layout_extract_channel(s->channel_layout, i); - s->channels[i].input = -1; + for (i = 0; i < s->ch_layout.nb_channels; i++) { + s->channels[i].out_channel = av_channel_layout_channel_from_index(&s->ch_layout, i); + s->channels[i].input = -1; + s->channels[i].in_channel_idx = -1; + s->channels[i].in_channel = AV_CHAN_NONE; } if ((ret = parse_maps(ctx)) < 0) @@ -221,7 +227,7 @@ static int join_query_formats(AVFilterContext *ctx) AVFilterChannelLayouts *layouts = NULL; int i, ret; - if ((ret = ff_add_channel_layout(&layouts, s->channel_layout)) < 0 || + if ((ret = ff_add_channel_layout(&layouts, &s->ch_layout)) < 0 || (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0) return ret; @@ -238,38 +244,55 @@ static int join_query_formats(AVFilterContext *ctx) return 0; } +typedef struct ChannelList { + enum AVChannel *ch; + int nb_ch; +} ChannelList; + +static enum AVChannel channel_list_pop(ChannelList *chl, int idx) +{ + enum AVChannel ret = chl->ch[idx]; + memcpy(chl->ch + idx, chl->ch + idx + 1, + (chl->nb_ch - idx - 1) * sizeof(*chl->ch)); + chl->nb_ch--; + return ret; +} + +/* + * If ch is present in chl, remove it from the list and return it. + * Otherwise return AV_CHAN_NONE. + */ +static enum AVChannel channel_list_pop_ch(ChannelList *chl, enum AVChannel ch) +{ + for (int i = 0; i < chl->nb_ch; i++) + if (chl->ch[i] == ch) + return channel_list_pop(chl, i); + return AV_CHAN_NONE; +} + static void guess_map_matching(AVFilterContext *ctx, ChannelMap *ch, - uint64_t *inputs) + ChannelList *inputs) { int i; for (i = 0; i < ctx->nb_inputs; i++) { - AVFilterLink *link = ctx->inputs[i]; - - if (ch->out_channel & link->channel_layout && - !(ch->out_channel & inputs[i])) { + if (channel_list_pop_ch(&inputs[i], ch->out_channel) != AV_CHAN_NONE) { ch->input = i; ch->in_channel = ch->out_channel; - inputs[i] |= ch->out_channel; return; } } } static void guess_map_any(AVFilterContext *ctx, ChannelMap *ch, - uint64_t *inputs) + ChannelList *inputs) { int i; for (i = 0; i < ctx->nb_inputs; i++) { - AVFilterLink *link = ctx->inputs[i]; - - if ((inputs[i] & link->channel_layout) != link->channel_layout) { - uint64_t unused = link->channel_layout & ~inputs[i]; - + if (inputs[i].nb_ch) { ch->input = i; - ch->in_channel = av_channel_layout_extract_channel(unused, 0); - inputs[i] |= ch->in_channel; + ch->in_channel = channel_list_pop(&inputs[i], 0); return; } } @@ -279,81 +302,136 @@ static int join_config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; JoinContext *s = ctx->priv; - uint64_t *inputs; // nth element tracks which channels are used from nth input + // unused channels from each input + ChannelList *inputs_unused; + char inbuf[64], outbuf[64]; int i, ret = 0; - /* initialize inputs to user-specified mappings */ - if (!(inputs = av_calloc(ctx->nb_inputs, sizeof(*inputs)))) + /* initialize unused channel list for each input */ + inputs_unused = av_calloc(ctx->nb_inputs, sizeof(*inputs_unused)); + if (!inputs_unused) return AVERROR(ENOMEM); - for (i = 0; i < s->nb_channels; i++) { + for (i = 0; i < ctx->nb_inputs; i++) { + AVFilterLink *inlink = ctx->inputs[i]; + AVChannelLayout *chl = &inlink->ch_layout; + ChannelList *iu = &inputs_unused[i]; + + iu->nb_ch = chl->nb_channels; + iu->ch = av_malloc_array(iu->nb_ch, sizeof(*iu->ch)); + if (!iu->ch) { + ret = AVERROR(ENOMEM); + goto fail; + } + + for (int ch_idx = 0; ch_idx < iu->nb_ch; ch_idx++) { + iu->ch[ch_idx] = av_channel_layout_channel_from_index(chl, ch_idx); + if (iu->ch[ch_idx] < 0) { + /* no channel ordering information in this input, + * so don't auto-map from it */ + iu->nb_ch = 0; + break; + } + } + } + + /* process user-specified maps */ + for (i = 0; i < s->ch_layout.nb_channels; i++) { ChannelMap *ch = &s->channels[i]; AVFilterLink *inlink; + AVChannelLayout *ichl; + ChannelList *iu; if (ch->input < 0) continue; inlink = ctx->inputs[ch->input]; + ichl = &inlink->ch_layout; + iu = &inputs_unused[ch->input]; + + /* get the index for the channels defined by name */ + if (ch->in_channel != AV_CHAN_NONE) { + ch->in_channel_idx = av_channel_layout_index_from_channel(ichl, ch->in_channel); + if (ch->in_channel_idx < 0) { + av_channel_name(inbuf, sizeof(inbuf), ch->in_channel); + av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in " + "input stream #%d.\n", inbuf, + ch->input); + ret = AVERROR(EINVAL); + goto fail; + } + } - if (!ch->in_channel) - ch->in_channel = av_channel_layout_extract_channel(inlink->channel_layout, - ch->in_channel_idx); - - if (!(ch->in_channel & inlink->channel_layout)) { - av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in " - "input stream #%d.\n", av_get_channel_name(ch->in_channel), - ch->input); + /* make sure channels specified by index actually exist */ + if (ch->in_channel_idx >= ichl->nb_channels) { + av_log(ctx, AV_LOG_ERROR, "Requested channel with index %d is not " + "present in input stream #%d.\n", ch->in_channel_idx, ch->input); ret = AVERROR(EINVAL); goto fail; } - inputs[ch->input] |= ch->in_channel; + channel_list_pop_ch(iu, av_channel_layout_channel_from_index(ichl, ch->in_channel_idx)); } /* guess channel maps when not explicitly defined */ /* first try unused matching channels */ - for (i = 0; i < s->nb_channels; i++) { + for (i = 0; i < s->ch_layout.nb_channels; i++) { ChannelMap *ch = &s->channels[i]; if (ch->input < 0) - guess_map_matching(ctx, ch, inputs); + guess_map_matching(ctx, ch, inputs_unused); } /* if the above failed, try to find _any_ unused input channel */ - for (i = 0; i < s->nb_channels; i++) { + for (i = 0; i < s->ch_layout.nb_channels; i++) { ChannelMap *ch = &s->channels[i]; if (ch->input < 0) - guess_map_any(ctx, ch, inputs); + guess_map_any(ctx, ch, inputs_unused); if (ch->input < 0) { + av_channel_name(outbuf, sizeof(outbuf), ch->out_channel); av_log(ctx, AV_LOG_ERROR, "Could not find input channel for " "output channel '%s'.\n", - av_get_channel_name(ch->out_channel)); + outbuf); + ret = AVERROR(EINVAL); goto fail; } - ch->in_channel_idx = av_get_channel_layout_channel_index(ctx->inputs[ch->input]->channel_layout, - ch->in_channel); + if (ch->in_channel != AV_CHAN_NONE) { + ch->in_channel_idx = av_channel_layout_index_from_channel( + &ctx->inputs[ch->input]->ch_layout, ch->in_channel); + } + + av_assert0(ch->in_channel_idx >= 0); } /* print mappings */ av_log(ctx, AV_LOG_VERBOSE, "mappings: "); - for (i = 0; i < s->nb_channels; i++) { + for (i = 0; i < s->ch_layout.nb_channels; i++) { ChannelMap *ch = &s->channels[i]; - av_log(ctx, AV_LOG_VERBOSE, "%d.%s => %s ", ch->input, - av_get_channel_name(ch->in_channel), - av_get_channel_name(ch->out_channel)); + AVFilterLink *inlink = ctx->inputs[ch->input]; + AVChannelLayout *ichl = &inlink->ch_layout; + enum AVChannel in_ch = av_channel_layout_channel_from_index( + ichl, ch->in_channel_idx); + + av_channel_name(inbuf, sizeof(inbuf), in_ch); + av_channel_name(outbuf, sizeof(outbuf), ch->out_channel); + av_log(ctx, AV_LOG_VERBOSE, "%d.%s(%d) => %s(%d) ", ch->input, + inbuf, ch->in_channel_idx, + outbuf, i); } av_log(ctx, AV_LOG_VERBOSE, "\n"); for (i = 0; i < ctx->nb_inputs; i++) { - if (!inputs[i]) + if (inputs_unused[i].nb_ch == ctx->inputs[i]->ch_layout.nb_channels) av_log(ctx, AV_LOG_WARNING, "No channels are used from input " "stream %d.\n", i); } fail: - av_freep(&inputs); + for (i = 0; i < ctx->nb_inputs; i++) + av_freep(&inputs_unused[i].ch); + av_freep(&inputs_unused); return ret; } @@ -382,8 +460,8 @@ static int try_push_frame(AVFilterContext *ctx) frame = av_frame_alloc(); if (!frame) return AVERROR(ENOMEM); - if (s->nb_channels > FF_ARRAY_ELEMS(frame->data)) { - frame->extended_data = av_calloc(s->nb_channels, + if (s->ch_layout.nb_channels > FF_ARRAY_ELEMS(frame->data)) { + frame->extended_data = av_calloc(s->ch_layout.nb_channels, sizeof(*frame->extended_data)); if (!frame->extended_data) { ret = AVERROR(ENOMEM); @@ -392,7 +470,7 @@ static int try_push_frame(AVFilterContext *ctx) } /* copy the data pointers */ - for (i = 0; i < s->nb_channels; i++) { + for (i = 0; i < s->ch_layout.nb_channels; i++) { ChannelMap *ch = &s->channels[i]; AVFrame *cur = s->input_frames[ch->input]; AVBufferRef *buf; @@ -442,7 +520,13 @@ static int try_push_frame(AVFilterContext *ctx) } frame->nb_samples = nb_samples; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS frame->channel_layout = outlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if ((ret = av_channel_layout_copy(&frame->ch_layout, &outlink->ch_layout)) < 0) + return ret; frame->channels = outlink->channels; frame->sample_rate = outlink->sample_rate; frame->format = outlink->format; @@ -450,7 +534,7 @@ static int try_push_frame(AVFilterContext *ctx) frame->linesize[0] = linesize; if (frame->data != frame->extended_data) { memcpy(frame->data, frame->extended_data, sizeof(*frame->data) * - FFMIN(FF_ARRAY_ELEMS(frame->data), s->nb_channels)); + FFMIN(FF_ARRAY_ELEMS(frame->data), s->ch_layout.nb_channels)); } s->eof_pts = frame->pts + av_rescale_q(frame->nb_samples, diff --git a/libavfilter/af_ladspa.c b/libavfilter/af_ladspa.c index ff16388a56..2cf3d9741e 100644 --- a/libavfilter/af_ladspa.c +++ b/libavfilter/af_ladspa.c @@ -366,7 +366,13 @@ static int config_output(AVFilterLink *outlink) outlink->format = inlink->format; outlink->sample_rate = inlink->sample_rate; if (s->nb_inputs == s->nb_outputs) { + if ((ret = av_channel_layout_copy(&outlink->ch_layout, &inlink->ch_layout)) < 0) + return ret; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS outlink->channel_layout = inlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif outlink->channels = inlink->channels; } @@ -681,7 +687,7 @@ static int query_formats(AVFilterContext *ctx) return ret; } else if (s->nb_inputs == 2 && s->nb_outputs == 2) { layouts = NULL; - ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO); + ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); if (ret < 0) return ret; ret = ff_set_common_channel_layouts(ctx, layouts); @@ -692,10 +698,10 @@ static int query_formats(AVFilterContext *ctx) if (s->nb_inputs >= 1) { AVFilterLink *inlink = ctx->inputs[0]; - uint64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs); + AVChannelLayout inlayout = FF_COUNT2LAYOUT(s->nb_inputs); layouts = NULL; - ret = ff_add_channel_layout(&layouts, inlayout); + ret = ff_add_channel_layout(&layouts, &inlayout); if (ret < 0) return ret; ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts); @@ -710,10 +716,10 @@ static int query_formats(AVFilterContext *ctx) } if (s->nb_outputs >= 1) { - uint64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs); + AVChannelLayout outlayout = FF_COUNT2LAYOUT(s->nb_outputs); layouts = NULL; - ret = ff_add_channel_layout(&layouts, outlayout); + ret = ff_add_channel_layout(&layouts, &outlayout); if (ret < 0) return ret; ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts); diff --git a/libavfilter/af_lv2.c b/libavfilter/af_lv2.c index 0f0c797989..963818fb67 100644 --- a/libavfilter/af_lv2.c +++ b/libavfilter/af_lv2.c @@ -288,7 +288,14 @@ static int config_output(AVFilterLink *outlink) outlink->format = inlink->format; outlink->sample_rate = sample_rate = inlink->sample_rate; if (s->nb_inputs == s->nb_outputs) { + int ret; + if ((ret = av_channel_layout_copy(&outlink->ch_layout, &inlink->ch_layout)) < 0) + return ret; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS outlink->channel_layout = inlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif outlink->channels = inlink->channels; } @@ -496,7 +503,7 @@ static int query_formats(AVFilterContext *ctx) if (s->nb_inputs == 2 && s->nb_outputs == 2) { layouts = NULL; - ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO); + ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); if (ret < 0) return ret; ret = ff_set_common_channel_layouts(ctx, layouts); @@ -505,10 +512,10 @@ static int query_formats(AVFilterContext *ctx) } else { if (s->nb_inputs >= 1) { AVFilterLink *inlink = ctx->inputs[0]; - uint64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs); + AVChannelLayout inlayout = FF_COUNT2LAYOUT(s->nb_inputs); layouts = NULL; - ret = ff_add_channel_layout(&layouts, inlayout); + ret = ff_add_channel_layout(&layouts, &inlayout); if (ret < 0) return ret; ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts); @@ -523,10 +530,10 @@ static int query_formats(AVFilterContext *ctx) } if (s->nb_outputs >= 1) { - uint64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs); + AVChannelLayout outlayout = FF_COUNT2LAYOUT(s->nb_outputs); layouts = NULL; - ret = ff_add_channel_layout(&layouts, outlayout); + ret = ff_add_channel_layout(&layouts, &outlayout); if (ret < 0) return ret; ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts); diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c index a8a18960c4..424eca2664 100644 --- a/libavfilter/af_pan.c +++ b/libavfilter/af_pan.c @@ -42,7 +42,7 @@ typedef struct PanContext { const AVClass *class; char *args; - int64_t out_channel_layout; + AVChannelLayout out_channel_layout; double gain[MAX_CHANNELS][MAX_CHANNELS]; int64_t need_renorm; int need_renumber; @@ -65,23 +65,15 @@ static void skip_spaces(char **arg) static int parse_channel_name(char **arg, int *rchannel, int *rnamed) { char buf[8]; - int len, i, channel_id = 0; - int64_t layout, layout0; + int len, channel_id = 0; skip_spaces(arg); /* try to parse a channel name, e.g. "FL" */ if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) { - layout0 = layout = av_get_channel_layout(buf); - /* channel_id <- first set bit in layout */ - for (i = 32; i > 0; i >>= 1) { - if (layout >= (int64_t)1 << i) { - channel_id += i; - layout >>= i; - } - } - /* reject layouts that are not a single channel */ - if (channel_id >= MAX_CHANNELS || layout0 != (int64_t)1 << channel_id) - return AVERROR(EINVAL); + channel_id = av_channel_from_string(buf); + if (channel_id < 0) + return channel_id; + *rchannel = channel_id; *rnamed = 1; *arg += len; @@ -137,17 +129,12 @@ static av_cold int init(AVFilterContext *ctx) goto fail; } if (named) { - if (!((pan->out_channel_layout >> out_ch_id) & 1)) { + if ((out_ch_id = av_channel_layout_index_from_channel(&pan->out_channel_layout, out_ch_id)) < 0) { av_log(ctx, AV_LOG_ERROR, "Channel \"%.8s\" does not exist in the chosen layout\n", arg0); ret = AVERROR(EINVAL); goto fail; } - /* get the channel number in the output channel layout: - * out_channel_layout & ((1 << out_ch_id) - 1) are all the - * channels that come before out_ch_id, - * so their count is the index of out_ch_id */ - out_ch_id = av_get_channel_layout_nb_channels(pan->out_channel_layout & (((int64_t)1 << out_ch_id) - 1)); } if (out_ch_id < 0 || out_ch_id >= pan->nb_output_channels) { av_log(ctx, AV_LOG_ERROR, @@ -269,9 +256,7 @@ static int query_formats(AVFilterContext *ctx) // outlink supports only requested output channel layout layouts = NULL; - if ((ret = ff_add_channel_layout(&layouts, - pan->out_channel_layout ? pan->out_channel_layout : - FF_COUNT2LAYOUT(pan->nb_output_channels))) < 0) + if ((ret = ff_add_channel_layout(&layouts, &pan->out_channel_layout)) < 0) return ret; return ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts); } @@ -281,13 +266,13 @@ static int config_props(AVFilterLink *link) AVFilterContext *ctx = link->dst; PanContext *pan = ctx->priv; char buf[1024], *cur; - int i, j, k, r; + int i, j, k, r, ret; double t; if (pan->need_renumber) { // input channels were given by their name: renumber them for (i = j = 0; i < MAX_CHANNELS; i++) { - if ((link->channel_layout >> i) & 1) { + if (av_channel_layout_index_from_channel(&link->ch_layout, i) >= 0) { for (k = 0; k < pan->nb_output_channels; k++) pan->gain[k][j] = pan->gain[k][i]; j++; @@ -306,20 +291,12 @@ static int config_props(AVFilterLink *link) } // init libswresample context - pan->swr = swr_alloc_set_opts(pan->swr, - pan->out_channel_layout, link->format, link->sample_rate, - link->channel_layout, link->format, link->sample_rate, - 0, ctx); - if (!pan->swr) + ret = swr_alloc_set_opts2(&pan->swr, + &pan->out_channel_layout, link->format, link->sample_rate, + &link->ch_layout, link->format, link->sample_rate, + 0, ctx); + if (ret < 0) return AVERROR(ENOMEM); - if (!link->channel_layout) { - if (av_opt_set_int(pan->swr, "ich", link->channels, 0) < 0) - return AVERROR(EINVAL); - } - if (!pan->out_channel_layout) { - if (av_opt_set_int(pan->swr, "och", pan->nb_output_channels, 0) < 0) - return AVERROR(EINVAL); - } // gains are pure, init the channel mapping if (pan->pure_gains) { @@ -336,7 +313,6 @@ static int config_props(AVFilterLink *link) pan->channel_map[i] = ch_id; } - av_opt_set_int(pan->swr, "icl", pan->out_channel_layout, 0); av_opt_set_int(pan->swr, "uch", pan->nb_output_channels, 0); swr_set_channel_mapping(pan->swr, pan->channel_map); } else { @@ -357,8 +333,6 @@ static int config_props(AVFilterLink *link) for (j = 0; j < link->channels; j++) pan->gain[i][j] /= t; } - av_opt_set_int(pan->swr, "icl", link->channel_layout, 0); - av_opt_set_int(pan->swr, "ocl", pan->out_channel_layout, 0); swr_set_matrix(pan->swr, pan->gain[0], pan->gain[1] - pan->gain[0]); } @@ -405,7 +379,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) swr_convert(pan->swr, outsamples->extended_data, n, (void *)insamples->extended_data, n); av_frame_copy_props(outsamples, insamples); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS outsamples->channel_layout = outlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if ((ret = av_channel_layout_copy(&outsamples->ch_layout, &outlink->ch_layout)) < 0) + return ret; outsamples->channels = outlink->channels; ret = ff_filter_frame(outlink, outsamples); diff --git a/libavfilter/af_replaygain.c b/libavfilter/af_replaygain.c index e9bfc5676c..53852ac8bc 100644 --- a/libavfilter/af_replaygain.c +++ b/libavfilter/af_replaygain.c @@ -327,7 +327,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_FLT )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0) return ret; diff --git a/libavfilter/af_sofalizer.c b/libavfilter/af_sofalizer.c index 20b717bdf8..383d137144 100644 --- a/libavfilter/af_sofalizer.c +++ b/libavfilter/af_sofalizer.c @@ -187,25 +187,15 @@ static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate) static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel) { - int len, i, channel_id = 0; - int64_t layout, layout0; + int len, channel_id = 0; char buf[8] = {0}; /* try to parse a channel name, e.g. "FL" */ if (av_sscanf(*arg, "%7[A-Z]%n", buf, &len)) { - layout0 = layout = av_get_channel_layout(buf); - /* channel_id <- first set bit in layout */ - for (i = 32; i > 0; i >>= 1) { - if (layout >= 1LL << i) { - channel_id += i; - layout >>= i; - } - } - /* reject layouts that are not a single channel */ - if (channel_id >= 64 || layout0 != 1LL << channel_id) { - av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf); - return AVERROR(EINVAL); - } + channel_id = av_channel_from_string(buf); + if (channel_id < 0) + return channel_id; + *rchannel = channel_id; *arg += len; return 0; @@ -221,7 +211,7 @@ static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel) return AVERROR(EINVAL); } -static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout) +static void parse_speaker_pos(AVFilterContext *ctx) { SOFAlizerContext *s = ctx->priv; char *arg, *tokenizer, *p, *args = av_strdup(s->speakers_pos); @@ -256,7 +246,7 @@ static int get_speaker_pos(AVFilterContext *ctx, float *speaker_azim, float *speaker_elev) { struct SOFAlizerContext *s = ctx->priv; - uint64_t channels_layout = ctx->inputs[0]->channel_layout; + AVChannelLayout *channel_layout = &ctx->inputs[0]->ch_layout; float azim[64] = { 0 }; float elev[64] = { 0 }; int m, ch, n_conv = ctx->inputs[0]->channels; /* get no. input channels */ @@ -267,45 +257,45 @@ static int get_speaker_pos(AVFilterContext *ctx, s->lfe_channel = -1; if (s->speakers_pos) - parse_speaker_pos(ctx, channels_layout); + parse_speaker_pos(ctx); /* set speaker positions according to input channel configuration: */ for (m = 0, ch = 0; ch < n_conv && m < 64; m++) { - uint64_t mask = channels_layout & (1ULL << m); - - switch (mask) { - case AV_CH_FRONT_LEFT: azim[ch] = 30; break; - case AV_CH_FRONT_RIGHT: azim[ch] = 330; break; - case AV_CH_FRONT_CENTER: azim[ch] = 0; break; - case AV_CH_LOW_FREQUENCY: - case AV_CH_LOW_FREQUENCY_2: s->lfe_channel = ch; break; - case AV_CH_BACK_LEFT: azim[ch] = 150; break; - case AV_CH_BACK_RIGHT: azim[ch] = 210; break; - case AV_CH_BACK_CENTER: azim[ch] = 180; break; - case AV_CH_SIDE_LEFT: azim[ch] = 90; break; - case AV_CH_SIDE_RIGHT: azim[ch] = 270; break; - case AV_CH_FRONT_LEFT_OF_CENTER: azim[ch] = 15; break; - case AV_CH_FRONT_RIGHT_OF_CENTER: azim[ch] = 345; break; - case AV_CH_TOP_CENTER: azim[ch] = 0; + int chan = av_channel_layout_channel_from_index(channel_layout, m); + + switch (chan) { + case AV_CHAN_FRONT_LEFT: azim[ch] = 30; break; + case AV_CHAN_FRONT_RIGHT: azim[ch] = 330; break; + case AV_CHAN_FRONT_CENTER: azim[ch] = 0; break; + case AV_CHAN_LOW_FREQUENCY: + case AV_CHAN_LOW_FREQUENCY_2: s->lfe_channel = ch; break; + case AV_CHAN_BACK_LEFT: azim[ch] = 150; break; + case AV_CHAN_BACK_RIGHT: azim[ch] = 210; break; + case AV_CHAN_BACK_CENTER: azim[ch] = 180; break; + case AV_CHAN_SIDE_LEFT: azim[ch] = 90; break; + case AV_CHAN_SIDE_RIGHT: azim[ch] = 270; break; + case AV_CHAN_FRONT_LEFT_OF_CENTER: azim[ch] = 15; break; + case AV_CHAN_FRONT_RIGHT_OF_CENTER: azim[ch] = 345; break; + case AV_CHAN_TOP_CENTER: azim[ch] = 0; elev[ch] = 90; break; - case AV_CH_TOP_FRONT_LEFT: azim[ch] = 30; + case AV_CHAN_TOP_FRONT_LEFT: azim[ch] = 30; elev[ch] = 45; break; - case AV_CH_TOP_FRONT_CENTER: azim[ch] = 0; + case AV_CHAN_TOP_FRONT_CENTER: azim[ch] = 0; elev[ch] = 45; break; - case AV_CH_TOP_FRONT_RIGHT: azim[ch] = 330; + case AV_CHAN_TOP_FRONT_RIGHT: azim[ch] = 330; elev[ch] = 45; break; - case AV_CH_TOP_BACK_LEFT: azim[ch] = 150; + case AV_CHAN_TOP_BACK_LEFT: azim[ch] = 150; elev[ch] = 45; break; - case AV_CH_TOP_BACK_RIGHT: azim[ch] = 210; + case AV_CHAN_TOP_BACK_RIGHT: azim[ch] = 210; elev[ch] = 45; break; - case AV_CH_TOP_BACK_CENTER: azim[ch] = 180; + case AV_CHAN_TOP_BACK_CENTER: azim[ch] = 180; elev[ch] = 45; break; - case AV_CH_WIDE_LEFT: azim[ch] = 90; break; - case AV_CH_WIDE_RIGHT: azim[ch] = 270; break; - case AV_CH_SURROUND_DIRECT_LEFT: azim[ch] = 90; break; - case AV_CH_SURROUND_DIRECT_RIGHT: azim[ch] = 270; break; - case AV_CH_STEREO_LEFT: azim[ch] = 90; break; - case AV_CH_STEREO_RIGHT: azim[ch] = 270; break; + case AV_CHAN_WIDE_LEFT: azim[ch] = 90; break; + case AV_CHAN_WIDE_RIGHT: azim[ch] = 270; break; + case AV_CHAN_SURROUND_DIRECT_LEFT: azim[ch] = 90; break; + case AV_CHAN_SURROUND_DIRECT_RIGHT: azim[ch] = 270; break; + case AV_CHAN_STEREO_LEFT: azim[ch] = 90; break; + case AV_CHAN_STEREO_RIGHT: azim[ch] = 270; break; case 0: break; default: return AVERROR(EINVAL); @@ -316,7 +306,7 @@ static int get_speaker_pos(AVFilterContext *ctx, elev[ch] = s->vspkrpos[m].elev; } - if (mask) + if (chan) ch++; } @@ -668,7 +658,7 @@ static int query_formats(AVFilterContext *ctx) return ret; layouts = NULL; - ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO); + ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); if (ret) return ret; diff --git a/libavfilter/af_speechnorm.c b/libavfilter/af_speechnorm.c index 212a926f36..3b20f61d99 100644 --- a/libavfilter/af_speechnorm.c +++ b/libavfilter/af_speechnorm.c @@ -68,7 +68,7 @@ typedef struct SpeechNormalizerContext { double threshold_value; double raise_amount; double fall_amount; - uint64_t channels; + AVChannelLayout ch_layout; int invert; int link; @@ -103,8 +103,8 @@ static const AVOption speechnorm_options[] = { { "r", "set the expansion raising amount", OFFSET(raise_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS }, { "fall", "set the compression raising amount", OFFSET(fall_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS }, { "f", "set the compression raising amount", OFFSET(fall_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS }, - { "channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS }, - { "h", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS }, + { "channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS }, + { "h", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS }, { "invert", "set inverted filtering", OFFSET(invert), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, { "i", "set inverted filtering", OFFSET(invert), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, { "link", "set linked channels filtering", OFFSET(link), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, @@ -287,7 +287,8 @@ static void filter_channels_## name (AVFilterContext *ctx, ChannelContext *cc = &s->cc[ch]; \ const ptype *src = (const ptype *)in->extended_data[ch]; \ ptype *dst = (ptype *)out->extended_data[ch]; \ - const int bypass = !(av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels); \ + const int bypass = !(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 && \ + av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0); \ int n = 0; \ \ while (n < nb_samples) { \ @@ -336,7 +337,8 @@ static void filter_link_channels_## name (AVFilterContext *ctx, for (int ch = 0; ch < inlink->channels; ch++) { \ ChannelContext *cc = &s->cc[ch]; \ \ - cc->bypass = !(av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels); \ + cc->bypass = !(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 && \ + av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0); \ \ next_pi(ctx, cc, cc->bypass); \ min_size = FFMIN(min_size, cc->pi_size); \ diff --git a/libavfilter/af_stereotools.c b/libavfilter/af_stereotools.c index 27ec4a2e4a..eedc7c68bd 100644 --- a/libavfilter/af_stereotools.c +++ b/libavfilter/af_stereotools.c @@ -107,7 +107,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_DBL )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0) return ret; diff --git a/libavfilter/af_stereowiden.c b/libavfilter/af_stereowiden.c index 7cce1a8f28..a91ea03957 100644 --- a/libavfilter/af_stereowiden.c +++ b/libavfilter/af_stereowiden.c @@ -60,7 +60,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_FLT )) < 0 || (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 || + (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_set_common_channel_layouts (ctx , layout )) < 0) return ret; diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c index ccd85148e9..a5fa595d20 100644 --- a/libavfilter/af_surround.c +++ b/libavfilter/af_surround.c @@ -92,8 +92,8 @@ typedef struct AudioSurroundContext { float lowcut; float highcut; - uint64_t out_channel_layout; - uint64_t in_channel_layout; + AVChannelLayout out_channel_layout; + AVChannelLayout in_channel_layout; int nb_in_channels; int nb_out_channels; @@ -171,7 +171,7 @@ static int query_formats(AVFilterContext *ctx) return ret; layouts = NULL; - ret = ff_add_channel_layout(&layouts, s->out_channel_layout); + ret = ff_add_channel_layout(&layouts, &s->out_channel_layout); if (ret) return ret; @@ -180,7 +180,7 @@ static int query_formats(AVFilterContext *ctx) return ret; layouts = NULL; - ret = ff_add_channel_layout(&layouts, s->in_channel_layout); + ret = ff_add_channel_layout(&layouts, &s->in_channel_layout); if (ret) return ret; @@ -212,31 +212,31 @@ static int config_input(AVFilterLink *inlink) return AVERROR(ENOMEM); for (ch = 0; ch < s->nb_in_channels; ch++) s->input_levels[ch] = s->level_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_CENTER); if (ch >= 0) s->input_levels[ch] *= s->fc_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_LEFT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_LEFT); if (ch >= 0) s->input_levels[ch] *= s->fl_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_RIGHT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_RIGHT); if (ch >= 0) s->input_levels[ch] *= s->fr_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_LEFT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_LEFT); if (ch >= 0) s->input_levels[ch] *= s->sl_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_RIGHT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_RIGHT); if (ch >= 0) s->input_levels[ch] *= s->sr_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_LEFT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_LEFT); if (ch >= 0) s->input_levels[ch] *= s->bl_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_RIGHT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_RIGHT); if (ch >= 0) s->input_levels[ch] *= s->br_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_CENTER); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_CENTER); if (ch >= 0) s->input_levels[ch] *= s->bc_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_LOW_FREQUENCY); if (ch >= 0) s->input_levels[ch] *= s->lfe_in; @@ -275,31 +275,31 @@ static int config_output(AVFilterLink *outlink) return AVERROR(ENOMEM); for (ch = 0; ch < s->nb_out_channels; ch++) s->output_levels[ch] = s->level_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_CENTER); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_CENTER); if (ch >= 0) s->output_levels[ch] *= s->fc_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_LEFT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_LEFT); if (ch >= 0) s->output_levels[ch] *= s->fl_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_RIGHT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_RIGHT); if (ch >= 0) s->output_levels[ch] *= s->fr_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_LEFT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_LEFT); if (ch >= 0) s->output_levels[ch] *= s->sl_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_RIGHT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_RIGHT); if (ch >= 0) s->output_levels[ch] *= s->sr_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_LEFT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_LEFT); if (ch >= 0) s->output_levels[ch] *= s->bl_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_RIGHT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_RIGHT); if (ch >= 0) s->output_levels[ch] *= s->br_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_CENTER); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_CENTER); if (ch >= 0) s->output_levels[ch] *= s->bc_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_LOW_FREQUENCY); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_LOW_FREQUENCY); if (ch >= 0) s->output_levels[ch] *= s->lfe_out; @@ -1373,15 +1373,16 @@ static av_cold int init(AVFilterContext *ctx) { AudioSurroundContext *s = ctx->priv; float overlap; - int i; + int64_t in_channel_layout, out_channel_layout; + int i, ret; - if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) { + if ((ret = av_channel_layout_from_string(&s->out_channel_layout, s->out_channel_layout_str)) < 0) { av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n", s->out_channel_layout_str); - return AVERROR(EINVAL); + return ret; } - if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) { + if ((ret = av_channel_layout_from_string(&s->in_channel_layout, s->in_channel_layout_str)) < 0) { av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n", s->in_channel_layout_str); return AVERROR(EINVAL); @@ -1393,10 +1394,15 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } - switch (s->in_channel_layout) { + in_channel_layout = s->in_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ? + s->in_channel_layout.u.mask : 0; + out_channel_layout = s->out_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ? + s->out_channel_layout.u.mask : 0; + + switch (in_channel_layout) { case AV_CH_LAYOUT_STEREO: s->filter = filter_stereo; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_MONO: s->upmix_stereo = upmix_1_0; break; @@ -1442,7 +1448,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_2POINT1: s->filter = filter_2_1; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_5POINT1_BACK: s->upmix_2_1 = upmix_5_1_back_2_1; break; @@ -1452,7 +1458,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_SURROUND: s->filter = filter_surround; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_3POINT1: s->upmix_3_0 = upmix_3_1_surround; break; @@ -1465,7 +1471,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_5POINT0: s->filter = filter_5_0_side; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_7POINT1: s->upmix_5_0 = upmix_7_1_5_0_side; break; @@ -1475,7 +1481,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_5POINT1: s->filter = filter_5_1_side; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_7POINT1: s->upmix_5_1 = upmix_7_1_5_1; break; @@ -1485,7 +1491,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_5POINT1_BACK: s->filter = filter_5_1_back; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_7POINT1: s->upmix_5_1 = upmix_7_1_5_1; break; diff --git a/libavfilter/asrc_afirsrc.c b/libavfilter/asrc_afirsrc.c index 3612610e75..b3651d3862 100644 --- a/libavfilter/asrc_afirsrc.c +++ b/libavfilter/asrc_afirsrc.c @@ -109,7 +109,7 @@ static av_cold void uninit(AVFilterContext *ctx) static av_cold int query_formats(AVFilterContext *ctx) { AudioFIRSourceContext *s = ctx->priv; - static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 }; + static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } }; int sample_rates[] = { s->sample_rate, -1 }; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT, diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c index 8c834492fe..8e90a420ea 100644 --- a/libavfilter/asrc_anoisesrc.c +++ b/libavfilter/asrc_anoisesrc.c @@ -84,7 +84,7 @@ AVFILTER_DEFINE_CLASS(anoisesrc); static av_cold int query_formats(AVFilterContext *ctx) { ANoiseSrcContext *s = ctx->priv; - static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 }; + static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } }; int sample_rates[] = { s->sample_rate, -1 }; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBL, diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c index 7ee2fa5a5d..17cbc5fb6c 100644 --- a/libavfilter/asrc_anullsrc.c +++ b/libavfilter/asrc_anullsrc.c @@ -37,8 +37,7 @@ typedef struct ANullContext { const AVClass *class; - char *channel_layout_str; - uint64_t channel_layout; + AVChannelLayout ch_layout; char *sample_rate_str; int sample_rate; int64_t duration; @@ -50,8 +49,8 @@ typedef struct ANullContext { #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM static const AVOption anullsrc_options[]= { - { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS }, - { "cl", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS }, + { "channel_layout", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS }, + { "cl", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS }, { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS }, { "r", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS }, { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, UINT16_MAX, FLAGS }, @@ -72,17 +71,13 @@ static av_cold int init(AVFilterContext *ctx) null->sample_rate_str, ctx)) < 0) return ret; - if ((ret = ff_parse_channel_layout(&null->channel_layout, NULL, - null->channel_layout_str, ctx)) < 0) - return ret; - return 0; } static int query_formats(AVFilterContext *ctx) { ANullContext *null = ctx->priv; - int64_t chlayouts[] = { null->channel_layout, -1 }; + const AVChannelLayout chlayouts[] = { null->ch_layout, { 0 } }; int sample_rates[] = { null->sample_rate, -1 }; int ret; diff --git a/libavfilter/asrc_flite.c b/libavfilter/asrc_flite.c index 17e7a5b9bc..5fab8086ba 100644 --- a/libavfilter/asrc_flite.c +++ b/libavfilter/asrc_flite.c @@ -225,11 +225,13 @@ static int query_formats(AVFilterContext *ctx) int ret; AVFilterChannelLayouts *chlayouts = NULL; - int64_t chlayout = av_get_default_channel_layout(flite->wave->num_channels); AVFilterFormats *sample_formats = NULL; AVFilterFormats *sample_rates = NULL; + AVChannelLayout chlayout = { 0 }; - if ((ret = ff_add_channel_layout (&chlayouts , chlayout )) < 0 || + av_channel_layout_default(&chlayout, flite->wave->num_channels); + + if ((ret = ff_add_channel_layout (&chlayouts , &chlayout )) < 0 || (ret = ff_set_common_channel_layouts (ctx , chlayouts )) < 0 || (ret = ff_add_format (&sample_formats, AV_SAMPLE_FMT_S16 )) < 0 || (ret = ff_set_common_formats (ctx , sample_formats )) < 0 || diff --git a/libavfilter/asrc_hilbert.c b/libavfilter/asrc_hilbert.c index 82996c7362..6469ea2cda 100644 --- a/libavfilter/asrc_hilbert.c +++ b/libavfilter/asrc_hilbert.c @@ -77,7 +77,7 @@ static av_cold void uninit(AVFilterContext *ctx) static av_cold int query_formats(AVFilterContext *ctx) { HilbertContext *s = ctx->priv; - static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 }; + static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } }; int sample_rates[] = { s->sample_rate, -1 }; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT, diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c index aaa81291a8..e4ae61c406 100644 --- a/libavfilter/asrc_sinc.c +++ b/libavfilter/asrc_sinc.c @@ -76,7 +76,7 @@ static int activate(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx) { SincContext *s = ctx->priv; - static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 }; + static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } }; int sample_rates[] = { s->sample_rate, -1 }; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }; diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c index c8995ae2c9..780070e205 100644 --- a/libavfilter/asrc_sine.c +++ b/libavfilter/asrc_sine.c @@ -180,7 +180,7 @@ static av_cold void uninit(AVFilterContext *ctx) static av_cold int query_formats(AVFilterContext *ctx) { SineContext *sine = ctx->priv; - static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 }; + static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } }; int sample_rates[] = { sine->sample_rate, -1 }; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }; diff --git a/libavfilter/audio.c b/libavfilter/audio.c index cebc9709dd..34cb1d1ec8 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -40,9 +40,8 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) { AVFrame *frame = NULL; int channels = link->channels; - int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout); - av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels); + av_assert0(channels == link->ch_layout.nb_channels); if (!link->frame_pool) { link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, @@ -77,7 +76,15 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) return NULL; frame->nb_samples = nb_samples; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS frame->channel_layout = link->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) { + av_frame_free(&frame); + return NULL; + } frame->sample_rate = link->sample_rate; av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format); diff --git a/libavfilter/avf_aphasemeter.c b/libavfilter/avf_aphasemeter.c index d9302cf867..eae584d17f 100644 --- a/libavfilter/avf_aphasemeter.c +++ b/libavfilter/avf_aphasemeter.c @@ -101,7 +101,7 @@ static int query_formats(AVFilterContext *ctx) formats = ff_make_format_list(sample_fmts); if ((ret = ff_formats_ref (formats, &inlink->outcfg.formats )) < 0 || (ret = ff_formats_ref (formats, &outlink->incfg.formats )) < 0 || - (ret = ff_add_channel_layout (&layout, AV_CH_LAYOUT_STEREO )) < 0 || + (ret = ff_add_channel_layout (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO )) < 0 || (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0 || (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0) return ret; diff --git a/libavfilter/avf_avectorscope.c b/libavfilter/avf_avectorscope.c index ba392153f3..c1deaa1ea0 100644 --- a/libavfilter/avf_avectorscope.c +++ b/libavfilter/avf_avectorscope.c @@ -207,7 +207,7 @@ static int query_formats(AVFilterContext *ctx) formats = ff_make_format_list(sample_fmts); if ((ret = ff_formats_ref (formats, &inlink->outcfg.formats )) < 0 || - (ret = ff_add_channel_layout (&layout, AV_CH_LAYOUT_STEREO )) < 0 || + (ret = ff_add_channel_layout (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0) return ret; diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c index 6f63574a8f..057a957a2a 100644 --- a/libavfilter/avf_showcqt.c +++ b/libavfilter/avf_showcqt.c @@ -1325,7 +1325,8 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE }; - static const int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO_DOWNMIX, -1 }; + static const AVChannelLayout channel_layouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO, + (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, { 0 } }; int ret; /* set input audio formats */ diff --git a/libavfilter/avf_showspatial.c b/libavfilter/avf_showspatial.c index 64e5204837..74357a9e1a 100644 --- a/libavfilter/avf_showspatial.c +++ b/libavfilter/avf_showspatial.c @@ -94,7 +94,7 @@ static int query_formats(AVFilterContext *ctx) formats = ff_make_format_list(sample_fmts); if ((ret = ff_formats_ref (formats, &inlink->outcfg.formats )) < 0 || - (ret = ff_add_channel_layout (&layout, AV_CH_LAYOUT_STEREO )) < 0 || + (ret = ff_add_channel_layout (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 || (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0) return ret; diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c index 74d2dd758c..6e958f1b0a 100644 --- a/libavfilter/avf_showspectrum.c +++ b/libavfilter/avf_showspectrum.c @@ -738,8 +738,7 @@ static int draw_legend(AVFilterContext *ctx, int samples) uint8_t *dst; char chlayout_str[128]; - av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), inlink->channels, - inlink->channel_layout); + av_channel_layout_describe(&inlink->ch_layout, chlayout_str, sizeof(chlayout_str)); text = av_asprintf("%d Hz | %s", inlink->sample_rate, chlayout_str); if (!text) diff --git a/libavfilter/avf_showvolume.c b/libavfilter/avf_showvolume.c index 401b65ca69..e8edd867d8 100644 --- a/libavfilter/avf_showvolume.c +++ b/libavfilter/avf_showvolume.c @@ -322,6 +322,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) ShowVolumeContext *s = ctx->priv; const int step = s->step; int c, j, k, max_draw; + char channel_name[64]; AVFrame *out; if (!s->out || s->out->width != outlink->w || @@ -375,8 +376,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) } if (s->h >= 8 && s->draw_text) { - const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c)); - if (!channel_name) + int ret = av_channel_name(channel_name, sizeof(channel_name), av_channel_layout_channel_from_index(&insamples->ch_layout, c)); + if (ret < 0) continue; drawtext(s->out, c * (s->h + s->b) + (s->h - 10) / 2, outlink->h - 35, channel_name, 1); } @@ -411,8 +412,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) } if (s->h >= 8 && s->draw_text) { - const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c)); - if (!channel_name) + int ret = av_channel_name(channel_name, sizeof(channel_name), av_channel_layout_channel_from_index(&insamples->ch_layout, c)); + if (ret < 0) continue; drawtext(s->out, 2, c * (s->h + s->b) + (s->h - 8) / 2, channel_name, 0); } diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 7362bcdab5..b502356b3f 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -204,6 +204,7 @@ void avfilter_link_free(AVFilterLink **link) ff_framequeue_free(&(*link)->fifo); ff_frame_pool_uninit((FFFramePool**)&(*link)->frame_pool); + av_channel_layout_uninit(&(*link)->ch_layout); av_freep(link); } @@ -405,7 +406,7 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end) end ? "\n" : ""); } else { char buf[128]; - av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout); + av_channel_layout_describe(&link->ch_layout, buf, sizeof(buf)); ff_tlog(ctx, "link[%p r:%d cl:%s fmt:%s %s->%s]%s", @@ -1040,7 +1041,17 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame) av_log(link->dst, AV_LOG_ERROR, "Channel count change is not supported\n"); goto error; } - if (frame->channel_layout != link->channel_layout) { +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (frame->channel_layout && frame->channel_layout != link->channel_layout) { + av_log(link->dst, AV_LOG_ERROR, "Channel layout change is not supported\n"); + goto error; + } +FF_ENABLE_DEPRECATION_WARNINGS + if (av_channel_layout_check(&frame->ch_layout) && av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) { +#else + if (av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) { +#endif av_log(link->dst, AV_LOG_ERROR, "Channel layout change is not supported\n"); goto error; } diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index b105dc3159..329eac5b01 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -543,7 +543,15 @@ struct AVFilterLink { int h; ///< agreed upon image height AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio /* These parameters apply only to audio */ - uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h) +#if FF_API_OLD_CHANNEL_LAYOUT + /** + * channel layout of current buffer (see libavutil/channel_layout.h) + * @deprecated use ch_layout + */ + attribute_deprecated + uint64_t channel_layout; +#endif + AVChannelLayout ch_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h) int sample_rate; ///< samples per second int format; ///< agreed upon media format diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index b8b432e98b..08cc16b53a 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -639,6 +639,8 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref) link->format = link->incfg.formats->formats[0]; if (link->type == AVMEDIA_TYPE_AUDIO) { + int ret; + if (!link->incfg.samplerates->nb_formats) { av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for" " the link between filters %s and %s.\n", link->src->name, @@ -659,11 +661,16 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref) return AVERROR(EINVAL); } link->incfg.channel_layouts->nb_channel_layouts = 1; - link->channel_layout = link->incfg.channel_layouts->channel_layouts[0]; - if ((link->channels = FF_LAYOUT2COUNT(link->channel_layout))) - link->channel_layout = 0; - else - link->channels = av_get_channel_layout_nb_channels(link->channel_layout); + ret = av_channel_layout_copy(&link->ch_layout, &link->incfg.channel_layouts->channel_layouts[0]); + if (ret < 0) + return ret; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + link->channel_layout = link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + link->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + link->channels = link->ch_layout.nb_channels; } ff_formats_unref(&link->incfg.formats); @@ -725,12 +732,12 @@ static int reduce_formats_on_filter(AVFilterContext *filter) /* reduce channel layouts */ for (i = 0; i < filter->nb_inputs; i++) { AVFilterLink *inlink = filter->inputs[i]; - uint64_t fmt; + AVChannelLayout fmt = { 0 }; if (!inlink->outcfg.channel_layouts || inlink->outcfg.channel_layouts->nb_channel_layouts != 1) continue; - fmt = inlink->outcfg.channel_layouts->channel_layouts[0]; + av_channel_layout_copy(&fmt, &inlink->outcfg.channel_layouts->channel_layouts[0]); for (j = 0; j < filter->nb_outputs; j++) { AVFilterLink *outlink = filter->outputs[j]; @@ -741,17 +748,17 @@ static int reduce_formats_on_filter(AVFilterContext *filter) continue; if (fmts->all_layouts && - (!FF_LAYOUT2COUNT(fmt) || fmts->all_counts)) { + (KNOWN(&fmt) || fmts->all_counts)) { /* Turn the infinite list into a singleton */ fmts->all_layouts = fmts->all_counts = 0; - if (ff_add_channel_layout(&outlink->incfg.channel_layouts, fmt) < 0) + if (ff_add_channel_layout(&outlink->incfg.channel_layouts, &fmt) < 0) ret = 1; break; } for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) { - if (fmts->channel_layouts[k] == fmt) { - fmts->channel_layouts[0] = fmt; + if (!av_channel_layout_compare(&fmts->channel_layouts[k], &fmt)) { + av_channel_layout_copy(&fmts->channel_layouts[0], &fmt); fmts->nb_channel_layouts = 1; ret = 1; break; @@ -887,26 +894,31 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter) continue; for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) { - uint64_t in_chlayout = link->outcfg.channel_layouts->channel_layouts[0]; - uint64_t out_chlayout = outlink->incfg.channel_layouts->channel_layouts[j]; - int in_channels = av_get_channel_layout_nb_channels(in_chlayout); - int out_channels = av_get_channel_layout_nb_channels(out_chlayout); - int count_diff = out_channels - in_channels; + AVChannelLayout in_chlayout = { 0 }, out_chlayout = { 0 }; + int in_channels; + int out_channels; + int count_diff; int matched_channels, extra_channels; int score = 100000; - if (FF_LAYOUT2COUNT(in_chlayout) || FF_LAYOUT2COUNT(out_chlayout)) { + av_channel_layout_copy(&in_chlayout, &link->outcfg.channel_layouts->channel_layouts[0]); + av_channel_layout_copy(&out_chlayout, &outlink->incfg.channel_layouts->channel_layouts[j]); + in_channels = in_chlayout.nb_channels; + out_channels = out_chlayout.nb_channels; + count_diff = out_channels - in_channels; + if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) { /* Compute score in case the input or output layout encodes a channel count; in this case the score is not altered by the computation afterwards, as in_chlayout and out_chlayout have both been set to 0 */ - if (FF_LAYOUT2COUNT(in_chlayout)) - in_channels = FF_LAYOUT2COUNT(in_chlayout); - if (FF_LAYOUT2COUNT(out_chlayout)) - out_channels = FF_LAYOUT2COUNT(out_chlayout); + if (!KNOWN(&in_chlayout)) + in_channels = FF_LAYOUT2COUNT(&in_chlayout); + if (!KNOWN(&out_chlayout)) + out_channels = FF_LAYOUT2COUNT(&out_chlayout); score -= 10000 + FFABS(out_channels - in_channels) + (in_channels > out_channels ? 10000 : 0); - in_chlayout = out_chlayout = 0; + av_channel_layout_uninit(&in_chlayout); + av_channel_layout_uninit(&out_chlayout); /* Let the remaining computation run, even if the score value is not altered */ } @@ -915,27 +927,27 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter) for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) { uint64_t cmp0 = ch_subst[k][0]; uint64_t cmp1 = ch_subst[k][1]; - if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) && - (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) { - in_chlayout &= ~cmp0; - out_chlayout &= ~cmp1; + if ( av_channel_layout_subset(& in_chlayout, cmp0) && + !av_channel_layout_subset(&out_chlayout, cmp0) && + av_channel_layout_subset(&out_chlayout, cmp1) && + !av_channel_layout_subset(& in_chlayout, cmp1)) { + av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0)); + av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~cmp1)); /* add score for channel match, minus a deduction for having to do the substitution */ - score += 10 * av_get_channel_layout_nb_channels(cmp1) - 2; + score += 10 * av_popcount64(cmp1) - 2; } } /* no penalty for LFE channel mismatch */ - if ( (in_chlayout & AV_CH_LOW_FREQUENCY) && - (out_chlayout & AV_CH_LOW_FREQUENCY)) + if (av_channel_layout_channel_from_index(&in_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0 && + av_channel_layout_channel_from_index(&out_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0) score += 10; - in_chlayout &= ~AV_CH_LOW_FREQUENCY; - out_chlayout &= ~AV_CH_LOW_FREQUENCY; + av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(&in_chlayout, ~AV_CH_LOW_FREQUENCY)); + av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~AV_CH_LOW_FREQUENCY)); - matched_channels = av_get_channel_layout_nb_channels(in_chlayout & - out_chlayout); - extra_channels = av_get_channel_layout_nb_channels(out_chlayout & - (~in_chlayout)); + matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask); + extra_channels = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask)); score += 10 * matched_channels - 5 * extra_channels; if (score > best_score || @@ -946,7 +958,7 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter) } } av_assert0(best_idx >= 0); - FFSWAP(uint64_t, outlink->incfg.channel_layouts->channel_layouts[0], + FFSWAP(AVChannelLayout, outlink->incfg.channel_layouts->channel_layouts[0], outlink->incfg.channel_layouts->channel_layouts[best_idx]); } diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index c0215669e7..b7fcaf89b2 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -74,7 +74,7 @@ static void cleanup_redundant_layouts(AVFilterContext *ctx) if (buf->channel_counts[i] < 64) counts |= (uint64_t)1 << buf->channel_counts[i]; for (i = lc = 0; i < nb_layouts; i++) { - n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]); + n = av_popcount64(buf->channel_layouts[i]); if (n < 64 && (counts & ((uint64_t)1 << n))) av_log(ctx, AV_LOG_WARNING, "Removing channel layout 0x%"PRIx64", redundant with %d channels\n", @@ -218,11 +218,28 @@ MAKE_AVFILTERLINK_ACCESSOR(int , h ) MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio) MAKE_AVFILTERLINK_ACCESSOR(int , channels ) +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS MAKE_AVFILTERLINK_ACCESSOR(uint64_t , channel_layout ) +FF_ENABLE_DEPRECATION_WARNINGS +#endif MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate ) MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef * , hw_frames_ctx ) +int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out) +{ + AVChannelLayout ch_layout = { 0 }; + int ret; + + av_assert0(ctx->filter->activate == activate); + ret = av_channel_layout_copy(&ch_layout, &ctx->inputs[0]->ch_layout); + if (ret < 0) + return ret; + *out = ch_layout; + return 0; +} + #define CHECK_LIST_SIZE(field) \ if (buf->field ## _size % sizeof(*buf->field)) { \ av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \ @@ -256,6 +273,7 @@ static int asink_query_formats(AVFilterContext *ctx) { BufferSinkContext *buf = ctx->priv; AVFilterFormats *formats = NULL; + AVChannelLayout layout = { 0 }; AVFilterChannelLayouts *layouts = NULL; unsigned i; int ret; @@ -277,11 +295,14 @@ static int asink_query_formats(AVFilterContext *ctx) buf->all_channel_counts) { cleanup_redundant_layouts(ctx); for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++) - if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) + if ((ret = av_channel_layout_from_mask(&layout, buf->channel_layouts[i])) < 0 || + (ret = ff_add_channel_layout(&layouts, &layout) < 0)) return ret; - for (i = 0; i < NB_ITEMS(buf->channel_counts); i++) - if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0) + for (i = 0; i < NB_ITEMS(buf->channel_counts); i++) { + layout = FF_COUNT2LAYOUT(buf->channel_counts[i]); + if ((ret = ff_add_channel_layout(&layouts, &layout)) < 0) return ret; + } if (buf->all_channel_counts) { if (layouts) av_log(ctx, AV_LOG_WARNING, diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index 69ed0f29a8..ae90ae87fa 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -46,7 +46,7 @@ * - av_buffersink_get_h(), * - av_buffersink_get_sample_aspect_ratio(), * - av_buffersink_get_channels(), - * - av_buffersink_get_channel_layout(), + * - av_buffersink_get_ch_layout(), * - av_buffersink_get_sample_rate(). * * The format can be constrained by setting options, using av_opt_set() and @@ -156,7 +156,12 @@ int av_buffersink_get_h (const AVFilterContext *c AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx); int av_buffersink_get_channels (const AVFilterContext *ctx); +#if FF_API_OLD_CHANNEL_LAYOUT +attribute_deprecated uint64_t av_buffersink_get_channel_layout (const AVFilterContext *ctx); +#endif +int av_buffersink_get_ch_layout (const AVFilterContext *ctx, + AVChannelLayout *ch_layout); int av_buffersink_get_sample_rate (const AVFilterContext *ctx); AVBufferRef * av_buffersink_get_hw_frames_ctx (const AVFilterContext *ctx); diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index b0611872f1..0cfa6a9b3d 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -60,8 +60,8 @@ typedef struct BufferSourceContext { int sample_rate; enum AVSampleFormat sample_fmt; int channels; - uint64_t channel_layout; char *channel_layout_str; + AVChannelLayout ch_layout; int eof; } BufferSourceContext; @@ -73,12 +73,12 @@ typedef struct BufferSourceContext { av_log(s, AV_LOG_WARNING, "Changing video frame properties on the fly is not supported by all filters.\n");\ } -#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format, pts)\ +#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, layout, count, format, pts)\ if (c->sample_fmt != format || c->sample_rate != srate ||\ - c->channel_layout != ch_layout || c->channels != ch_count) {\ + av_channel_layout_compare(&c->ch_layout, &layout) || c->channels != count) {\ av_log(s, AV_LOG_INFO, "filter context - fmt: %s r: %d layout: %"PRIX64" ch: %d, incoming frame - fmt: %s r: %d layout: %"PRIX64" ch: %d pts_time: %s\n",\ - av_get_sample_fmt_name(c->sample_fmt), c->sample_rate, c->channel_layout, c->channels,\ - av_get_sample_fmt_name(format), srate, ch_layout, ch_count, av_ts2timestr(pts, &s->outputs[0]->time_base));\ + av_get_sample_fmt_name(c->sample_fmt), c->sample_rate, c->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? c->ch_layout.u.mask : 0, c->channels,\ + av_get_sample_fmt_name(format), srate, layout.order == AV_CHANNEL_ORDER_NATIVE ? layout.u.mask : 0, count, av_ts2timestr(pts, &s->outputs[0]->time_base));\ av_log(s, AV_LOG_ERROR, "Changing audio frame properties on the fly is not supported.\n");\ return AVERROR(EINVAL);\ } @@ -127,8 +127,20 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par } if (param->sample_rate > 0) s->sample_rate = param->sample_rate; - if (param->channel_layout) - s->channel_layout = param->channel_layout; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + // if the old/new fields are set inconsistently, prefer the old ones + if (param->channel_layout && (param->ch_layout.order != AV_CHANNEL_ORDER_NATIVE || + param->ch_layout.u.mask != param->channel_layout)) { + av_channel_layout_from_mask(&s->ch_layout, param->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS + } else +#endif + if (param->ch_layout.nb_channels) { + int ret = av_channel_layout_copy(&s->ch_layout, ¶m->ch_layout); + if (ret < 0) + return ret; + } break; default: return AVERROR_BUG; @@ -168,11 +180,15 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra AVFrame *copy; int refcounted, ret; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS if (frame && frame->channel_layout && av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) { av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n"); return AVERROR(EINVAL); } +FF_ENABLE_DEPRECATION_WARNINGS +#endif s->nb_failed_requests = 0; @@ -192,9 +208,19 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra break; case AVMEDIA_TYPE_AUDIO: /* For layouts unknown on input but known on link after negotiation. */ +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS if (!frame->channel_layout) - frame->channel_layout = s->channel_layout; - CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->channel_layout, + frame->channel_layout = s->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + s->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (!frame->ch_layout.nb_channels) { + ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout); + if (ret < 0) + return ret; + } + CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->ch_layout, frame->channels, frame->format, frame->pts); break; default: @@ -301,6 +327,7 @@ AVFILTER_DEFINE_CLASS(abuffer); static av_cold int init_audio(AVFilterContext *ctx) { BufferSourceContext *s = ctx->priv; + char buf[128]; int ret = 0; if (s->sample_fmt == AV_SAMPLE_FMT_NONE) { @@ -308,24 +335,39 @@ static av_cold int init_audio(AVFilterContext *ctx) return AVERROR(EINVAL); } - if (s->channel_layout_str || s->channel_layout) { + if (s->channel_layout_str || s->ch_layout.nb_channels) { int n; - if (!s->channel_layout) { - s->channel_layout = av_get_channel_layout(s->channel_layout_str); - if (!s->channel_layout) { - av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n", + if (!s->ch_layout.nb_channels) { + ret = av_channel_layout_from_string(&s->ch_layout, s->channel_layout_str); + if (ret < 0) { +#if FF_API_OLD_CHANNEL_LAYOUT + uint64_t mask; +FF_DISABLE_DEPRECATION_WARNINGS + mask = av_get_channel_layout(s->channel_layout_str); + if (!mask) { +#endif + av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n", + s->channel_layout_str); + return AVERROR(EINVAL); +#if FF_API_OLD_CHANNEL_LAYOUT + } +FF_ENABLE_DEPRECATION_WARNINGS + av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n", s->channel_layout_str); - return AVERROR(EINVAL); + av_channel_layout_from_mask(&s->ch_layout, mask); +#endif } } - n = av_get_channel_layout_nb_channels(s->channel_layout); + + n = s->ch_layout.nb_channels; + av_channel_layout_describe(&s->ch_layout, buf, sizeof(buf)); if (s->channels) { if (n != s->channels) { av_log(ctx, AV_LOG_ERROR, "Mismatching channel count %d and layout '%s' " "(%d channels)\n", - s->channels, s->channel_layout_str, n); + s->channels, buf, n); return AVERROR(EINVAL); } } @@ -334,6 +376,9 @@ static av_cold int init_audio(AVFilterContext *ctx) av_log(ctx, AV_LOG_ERROR, "Neither number of channels nor " "channel layout specified\n"); return AVERROR(EINVAL); + } else { + s->ch_layout = FF_COUNT2LAYOUT(s->channels); + av_channel_layout_describe(&s->ch_layout, buf, sizeof(buf)); } if (!s->time_base.num) @@ -342,7 +387,7 @@ static av_cold int init_audio(AVFilterContext *ctx) av_log(ctx, AV_LOG_VERBOSE, "tb:%d/%d samplefmt:%s samplerate:%d chlayout:%s\n", s->time_base.num, s->time_base.den, av_get_sample_fmt_name(s->sample_fmt), - s->sample_rate, s->channel_layout_str); + s->sample_rate, buf); return ret; } @@ -374,9 +419,7 @@ static int query_formats(AVFilterContext *ctx) (ret = ff_set_common_samplerates (ctx , samplerates )) < 0) return ret; - if ((ret = ff_add_channel_layout(&channel_layouts, - c->channel_layout ? c->channel_layout : - FF_COUNT2LAYOUT(c->channels))) < 0) + if ((ret = ff_add_channel_layout(&channel_layouts, &c->ch_layout)) < 0) return ret; if ((ret = ff_set_common_channel_layouts(ctx, channel_layouts)) < 0) return ret; @@ -405,8 +448,11 @@ static int config_props(AVFilterLink *link) } break; case AVMEDIA_TYPE_AUDIO: - if (!c->channel_layout) - c->channel_layout = link->channel_layout; + if (!c->ch_layout.nb_channels) { + int ret = av_channel_layout_copy(&c->ch_layout, &link->ch_layout); + if (ret < 0) + return ret; + } break; default: return AVERROR(EINVAL); diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h index 08fbd18a47..3b248b37cd 100644 --- a/libavfilter/buffersrc.h +++ b/libavfilter/buffersrc.h @@ -110,10 +110,19 @@ typedef struct AVBufferSrcParameters { */ int sample_rate; +#if FF_API_OLD_CHANNEL_LAYOUT /** * Audio only, the audio channel layout + * @deprecated use ch_layout */ + attribute_deprecated uint64_t channel_layout; +#endif + + /** + * Audio only, the audio channel layout + */ + AVChannelLayout ch_layout; } AVBufferSrcParameters; /** diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c index 88d6a1fe46..2a6edba3d8 100644 --- a/libavfilter/f_ebur128.c +++ b/libavfilter/f_ebur128.c @@ -422,7 +422,7 @@ static int config_audio_output(AVFilterLink *outlink) int i; AVFilterContext *ctx = outlink->src; EBUR128Context *ebur128 = ctx->priv; - const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout); + const int nb_channels = outlink->ch_layout.nb_channels; #define BACK_MASK (AV_CH_BACK_LEFT |AV_CH_BACK_CENTER |AV_CH_BACK_RIGHT| \ AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \ @@ -439,8 +439,8 @@ static int config_audio_output(AVFilterLink *outlink) for (i = 0; i < nb_channels; i++) { /* channel weighting */ - const uint64_t chl = av_channel_layout_extract_channel(outlink->channel_layout, i); - if (chl & (AV_CH_LOW_FREQUENCY|AV_CH_LOW_FREQUENCY_2)) { + const int chl = av_channel_layout_channel_from_index(&outlink->ch_layout, i); + if (chl == AV_CHAN_LOW_FREQUENCY || chl == AV_CHAN_LOW_FREQUENCY_2) { ebur128->ch_weighting[i] = 0; } else if (chl & BACK_MASK) { ebur128->ch_weighting[i] = 1.41; @@ -472,11 +472,11 @@ static int config_audio_output(AVFilterLink *outlink) !ebur128->true_peaks_per_frame || !ebur128->swr_ctx) return AVERROR(ENOMEM); - av_opt_set_int(ebur128->swr_ctx, "in_channel_layout", outlink->channel_layout, 0); + av_opt_set_chlayout(ebur128->swr_ctx, "in_ch_layout", &outlink->ch_layout, 0); av_opt_set_int(ebur128->swr_ctx, "in_sample_rate", outlink->sample_rate, 0); av_opt_set_sample_fmt(ebur128->swr_ctx, "in_sample_fmt", outlink->format, 0); - av_opt_set_int(ebur128->swr_ctx, "out_channel_layout", outlink->channel_layout, 0); + av_opt_set_chlayout(ebur128->swr_ctx, "out_ch_layout", &outlink->ch_layout, 0); av_opt_set_int(ebur128->swr_ctx, "out_sample_rate", 192000, 0); av_opt_set_sample_fmt(ebur128->swr_ctx, "out_sample_fmt", outlink->format, 0); diff --git a/libavfilter/f_streamselect.c b/libavfilter/f_streamselect.c index 3708d2b256..a895ddd4e0 100644 --- a/libavfilter/f_streamselect.c +++ b/libavfilter/f_streamselect.c @@ -119,7 +119,11 @@ static int config_output(AVFilterLink *outlink) case AVMEDIA_TYPE_AUDIO: outlink->sample_rate = inlink->sample_rate; outlink->channels = inlink->channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS outlink->channel_layout = inlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif break; } diff --git a/libavfilter/formats.c b/libavfilter/formats.c index ba62f73248..8bf0fe2ef1 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -28,8 +28,6 @@ #include "internal.h" #include "formats.h" -#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */ - /** * Add all refs from a to ret and destroy a. */ @@ -215,7 +213,7 @@ static int merge_channel_layouts(void *va, void *vb) { AVFilterChannelLayouts *a = va; AVFilterChannelLayouts *b = vb; - uint64_t *channel_layouts; + AVChannelLayout *channel_layouts; unsigned a_all = a->all_layouts + a->all_counts; unsigned b_all = b->all_layouts + b->all_counts; int ret_max, ret_nb = 0, i, j, round; @@ -233,8 +231,8 @@ static int merge_channel_layouts(void *va, void *vb) if (a_all == 1 && !b_all) { /* keep only known layouts in b; works also for b_all = 1 */ for (i = j = 0; i < b->nb_channel_layouts; i++) - if (KNOWN(b->channel_layouts[i])) - b->channel_layouts[j++] = b->channel_layouts[i]; + if (KNOWN(&b->channel_layouts[i]) && i != j++) + av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]); /* Not optimal: the unknown layouts of b may become known after another merge. */ if (!j) @@ -246,17 +244,18 @@ static int merge_channel_layouts(void *va, void *vb) } ret_max = a->nb_channel_layouts + b->nb_channel_layouts; - if (!(channel_layouts = av_malloc_array(ret_max, sizeof(*channel_layouts)))) + if (!(channel_layouts = av_mallocz_array(ret_max, sizeof(*channel_layouts)))) return AVERROR(ENOMEM); /* a[known] intersect b[known] */ for (i = 0; i < a->nb_channel_layouts; i++) { - if (!KNOWN(a->channel_layouts[i])) + if (!KNOWN(&a->channel_layouts[i])) continue; for (j = 0; j < b->nb_channel_layouts; j++) { - if (a->channel_layouts[i] == b->channel_layouts[j]) { - channel_layouts[ret_nb++] = a->channel_layouts[i]; - a->channel_layouts[i] = b->channel_layouts[j] = 0; + if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) { + av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]); + av_channel_layout_uninit(&a->channel_layouts[i]); + av_channel_layout_uninit(&b->channel_layouts[j]); break; } } @@ -265,24 +264,24 @@ static int merge_channel_layouts(void *va, void *vb) 2nd round: a[generic] intersect b[known] */ for (round = 0; round < 2; round++) { for (i = 0; i < a->nb_channel_layouts; i++) { - uint64_t fmt = a->channel_layouts[i], bfmt; - if (!fmt || !KNOWN(fmt)) + AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 }; + if (!av_channel_layout_check(fmt) || !KNOWN(fmt)) continue; - bfmt = FF_COUNT2LAYOUT(av_get_channel_layout_nb_channels(fmt)); + bfmt = FF_COUNT2LAYOUT(fmt->nb_channels); for (j = 0; j < b->nb_channel_layouts; j++) - if (b->channel_layouts[j] == bfmt) - channel_layouts[ret_nb++] = a->channel_layouts[i]; + if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt)) + av_channel_layout_copy(&channel_layouts[ret_nb++], fmt); } /* 1st round: swap to prepare 2nd round; 2nd round: put it back */ FFSWAP(AVFilterChannelLayouts *, a, b); } /* a[generic] intersect b[generic] */ for (i = 0; i < a->nb_channel_layouts; i++) { - if (KNOWN(a->channel_layouts[i])) + if (KNOWN(&a->channel_layouts[i])) continue; for (j = 0; j < b->nb_channel_layouts; j++) - if (a->channel_layouts[i] == b->channel_layouts[j]) - channel_layouts[ret_nb++] = a->channel_layouts[i]; + if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) + av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]); } if (!ret_nb) { @@ -388,15 +387,31 @@ AVFilterFormats *ff_make_format_list(const int *fmts) return formats; } -AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts) +AVFilterChannelLayouts *ff_make_format64_list(const AVChannelLayout *fmts) { - MAKE_FORMAT_LIST(AVFilterChannelLayouts, - channel_layouts, nb_channel_layouts); + AVFilterChannelLayouts *ch_layouts; + int count = 0; + if (fmts) + for (count = 0; fmts[count].nb_channels; count++) + ; + ch_layouts = av_mallocz(sizeof(*ch_layouts)); + if (!ch_layouts) + return NULL; + ch_layouts->nb_channel_layouts = count; + if (count) { + ch_layouts->channel_layouts = + av_mallocz_array(count, sizeof(*ch_layouts->channel_layouts)); + if (!ch_layouts->channel_layouts) { + av_freep(&ch_layouts); + return NULL; + } + } + if (count) - memcpy(formats->channel_layouts, fmts, - sizeof(*formats->channel_layouts) * count); + memcpy(ch_layouts->channel_layouts, fmts, + sizeof(*ch_layouts->channel_layouts) * count); - return formats; + return ch_layouts; } #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \ @@ -415,6 +430,11 @@ do { \ } \ \ (*f)->list = fmts; \ + ASSIGN_FMT(f, fmt, list, nb); \ +} while (0) + +#define ASSIGN_FMT(f, fmt, list, nb) \ +do { \ (*f)->list[(*f)->nb++] = fmt; \ } while (0) @@ -424,10 +444,21 @@ int ff_add_format(AVFilterFormats **avff, int64_t fmt) return 0; } -int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout) +#undef ASSIGN_FMT +#define ASSIGN_FMT(f, fmt, list, nb) \ +do { \ + int ret; \ + memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \ + ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \ + if (ret < 0) \ + return ret; \ + (*f)->nb++; \ +} while (0) + +int ff_add_channel_layout(AVFilterChannelLayouts **l, AVChannelLayout *channel_layout) { av_assert1(!(*l && (*l)->all_layouts)); - ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, uint64_t, channel_layouts, nb_channel_layouts); + ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts); return 0; } @@ -664,7 +695,7 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx, } int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx, - const int64_t *fmts) + const AVChannelLayout *fmts) { return ff_set_common_channel_layouts(ctx, ff_make_format64_list(fmts)); } @@ -787,23 +818,41 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx) return 0; } -int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg, +int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, void *log_ctx) { - int64_t chlayout; - int nb_channels; - - if (av_get_extended_channel_layout(arg, &chlayout, &nb_channels) < 0) { - av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); - return AVERROR(EINVAL); + AVChannelLayout chlayout = { 0 }; + int res; + + res = av_channel_layout_from_string(&chlayout, arg); + if (res < 0) { +#if FF_API_OLD_CHANNEL_LAYOUT + int64_t mask; + int nb_channels; +FF_DISABLE_DEPRECATION_WARNINGS + if (av_get_extended_channel_layout(arg, &mask, &nb_channels) < 0) { +#endif + av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); + return AVERROR(EINVAL); +#if FF_API_OLD_CHANNEL_LAYOUT + } +FF_ENABLE_DEPRECATION_WARNINGS + av_log(log_ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n", + arg); + if (mask) + av_channel_layout_from_mask(&chlayout, mask); + else + chlayout = (AVChannelLayout) { .order = AV_CHANNEL_ORDER_UNSPEC, .nb_channels = nb_channels }; +#endif } - if (!chlayout && !nret) { + + if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) { av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg); return AVERROR(EINVAL); } *ret = chlayout; if (nret) - *nret = nb_channels; + *nret = chlayout.nb_channels; return 0; } @@ -846,11 +895,11 @@ int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts) return check_list(log, "sample rate", fmts); } -static int layouts_compatible(uint64_t a, uint64_t b) +static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b) { - return a == b || - (KNOWN(a) && !KNOWN(b) && av_get_channel_layout_nb_channels(a) == FF_LAYOUT2COUNT(b)) || - (KNOWN(b) && !KNOWN(a) && av_get_channel_layout_nb_channels(b) == FF_LAYOUT2COUNT(a)); + return !av_channel_layout_compare(a, b) || + (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) || + (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels); } int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts) @@ -869,7 +918,7 @@ int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fm } for (i = 0; i < fmts->nb_channel_layouts; i++) { for (j = i + 1; j < fmts->nb_channel_layouts; j++) { - if (layouts_compatible(fmts->channel_layouts[i], fmts->channel_layouts[j])) { + if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) { av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n"); return AVERROR(EINVAL); } diff --git a/libavfilter/formats.h b/libavfilter/formats.h index a884d15213..e55180f45c 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -83,7 +83,7 @@ struct AVFilterFormats { * (e.g. AV_CH_LAYOUT_STEREO and FF_COUNT2LAYOUT(2). */ struct AVFilterChannelLayouts { - uint64_t *channel_layouts; ///< list of channel layouts + AVChannelLayout *channel_layouts; ///< list of channel layouts int nb_channel_layouts; ///< number of channel layouts char all_layouts; ///< accept any known channel layout char all_counts; ///< accept any channel layout or count @@ -99,14 +99,16 @@ struct AVFilterChannelLayouts { * The result is only valid inside AVFilterChannelLayouts and immediately * related functions. */ -#define FF_COUNT2LAYOUT(c) (0x8000000000000000ULL | (c)) +#define FF_COUNT2LAYOUT(c) ((AVChannelLayout) { .order = AV_CHANNEL_ORDER_UNSPEC, .nb_channels = c }) /** * Decode a channel count encoded as a channel layout. * Return 0 if the channel layout was a real one. */ -#define FF_LAYOUT2COUNT(l) (((l) & 0x8000000000000000ULL) ? \ - (int)((l) & 0x7FFFFFFF) : 0) +#define FF_LAYOUT2COUNT(l) (((l)->order == AV_CHANNEL_ORDER_UNSPEC) ? \ + (l)->nb_channels : 0) + +#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */ /** * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct -- @@ -126,7 +128,7 @@ av_warn_unused_result AVFilterChannelLayouts *ff_all_channel_counts(void); av_warn_unused_result -AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts); +AVFilterChannelLayouts *ff_make_format64_list(const AVChannelLayout *fmts); /** * Helpers for query_formats() which set all free audio links to the same list @@ -141,7 +143,7 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx, */ av_warn_unused_result int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx, - const int64_t *fmts); + const AVChannelLayout *fmts); /** * Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts()) */ @@ -178,7 +180,7 @@ av_warn_unused_result int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts); av_warn_unused_result -int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout); +int ff_add_channel_layout(AVFilterChannelLayouts **l, AVChannelLayout *channel_layout); /** * Add *ref as a new reference to f. diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c index cf8914b558..80f7bf6c98 100644 --- a/libavfilter/graphdump.c +++ b/libavfilter/graphdump.c @@ -30,6 +30,7 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) { const char *format; + char layout[128]; AVBPrint dummy_buffer; if (!buf) { @@ -49,7 +50,8 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) format = av_x_if_null(av_get_sample_fmt_name(link->format), "?"); av_bprintf(buf, "[%dHz %s:", (int)link->sample_rate, format); - av_bprint_channel_layout(buf, link->channels, link->channel_layout); + av_channel_layout_describe(&link->ch_layout, layout, sizeof(layout)); + av_bprintf(buf, "%s", layout); av_bprint_chars(buf, ']', 1); break; diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 1099b82b4b..3eecaca3fb 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -237,7 +237,7 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx); * @return >= 0 in case of success, a negative AVERROR code on error */ av_warn_unused_result -int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg, +int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, void *log_ctx); void ff_update_link_current_pts(AVFilterLink *link, int64_t pts); diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index b89a680883..3ebd279df7 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -189,23 +189,24 @@ static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx) { AVCodecParameters *dec_par = st->st->codecpar; char buf[256]; - int64_t chl = av_get_default_channel_layout(dec_par->channels); + AVChannelLayout chl = { 0 }; - if (!chl) { + av_channel_layout_default(&chl, dec_par->ch_layout.nb_channels); + + if (!KNOWN(&chl)) { av_log(log_ctx, AV_LOG_ERROR, "Channel layout is not set in stream %d, and could not " "be guessed from the number of channels (%d)\n", - st_index, dec_par->channels); + st_index, dec_par->ch_layout.nb_channels); return AVERROR(EINVAL); } - av_get_channel_layout_string(buf, sizeof(buf), dec_par->channels, chl); + av_channel_layout_describe(&chl, buf, sizeof(buf)); av_log(log_ctx, AV_LOG_WARNING, "Channel layout is not set in output stream %d, " "guessed channel layout is '%s'\n", st_index, buf); - dec_par->channel_layout = chl; - return 0; + return av_channel_layout_copy(&dec_par->ch_layout, &chl); } static av_cold int movie_common_init(AVFilterContext *ctx) @@ -315,7 +316,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx) if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0) return ret; if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - !movie->st[i].st->codecpar->channel_layout) { + !KNOWN(&movie->st[i].st->codecpar->ch_layout)) { ret = guess_channel_layout(&movie->st[i], i, ctx); if (ret < 0) return ret; @@ -351,7 +352,7 @@ static int movie_query_formats(AVFilterContext *ctx) { MovieContext *movie = ctx->priv; int list[] = { 0, -1 }; - int64_t list64[] = { 0, -1 }; + AVChannelLayout list64[] = { { 0 }, { 0 } }; int i, ret; for (i = 0; i < ctx->nb_outputs; i++) { @@ -372,7 +373,7 @@ static int movie_query_formats(AVFilterContext *ctx) list[0] = c->sample_rate; if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->incfg.samplerates)) < 0) return ret; - list64[0] = c->channel_layout; + list64[0] = c->ch_layout; if ((ret = ff_channel_layouts_ref(ff_make_format64_list(list64), &outlink->incfg.channel_layouts)) < 0) return ret; diff --git a/libavfilter/tests/filtfmts.c b/libavfilter/tests/filtfmts.c index d793480344..909c1e8dc9 100644 --- a/libavfilter/tests/filtfmts.c +++ b/libavfilter/tests/filtfmts.c @@ -59,8 +59,7 @@ static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads for (unsigned j = 0; layouts && j < layouts->nb_channel_layouts; j++) { char buf[256]; - av_get_channel_layout_string(buf, sizeof(buf), -1, - layouts->channel_layouts[j]); + av_channel_layout_describe(&layouts->channel_layouts[j], buf, sizeof(buf)); printf("%s[%u] %s: chlayout:%s\n", inout_string, i, pad_name, buf); } diff --git a/libavfilter/tests/formats.c b/libavfilter/tests/formats.c index c1e30e73ee..7b28ccf0b5 100644 --- a/libavfilter/tests/formats.c +++ b/libavfilter/tests/formats.c @@ -112,14 +112,18 @@ int main(void) "-1c", "60c", "65c", +#if FF_API_OLD_CHANNEL_LAYOUT "2C", "60C", "65C", +#endif "5.1", "stereo", +#if FF_API_OLD_CHANNEL_LAYOUT "1+1+1+1", "1c+1c+1c+1c", "2c+1c", +#endif "0x3", }; @@ -129,12 +133,12 @@ int main(void) } for ( i = 0; iincfg.formats )) < 0 || - (ret = ff_add_channel_layout (&layout, FF_COUNT2LAYOUT(s->channels))) < 0 || + (ret = ff_add_channel_layout (&layout, &FF_COUNT2LAYOUT(s->channels))) < 0 || (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0) return ret; diff --git a/tests/ref/fate/filter-formats b/tests/ref/fate/filter-formats index 17ff5b222f..fd692a2725 100644 --- a/tests/ref/fate/filter-formats +++ b/tests/ref/fate/filter-formats @@ -66,20 +66,20 @@ quad(side) 7 channels (FL+FR+BC+SL+SR+DL+DR) 8 channels (FL+FR+LFE+BC+SL+SR+DL+DR) 8 channels (FL+FR+FC+BC+SL+SR+DL+DR) --1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, blah); -0 = ff_parse_channel_layout(0000000000000001, 1, 1); -0 = ff_parse_channel_layout(0000000000000002, 1, 2); --1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, -1); -0 = ff_parse_channel_layout(000000000000003C, 4, 60); -0 = ff_parse_channel_layout(0000000000000041, 2, 65); +-1 = ff_parse_channel_layout(0000000000000000, -1, blah); +0 = ff_parse_channel_layout(0000000000000000, 1, 1); +0 = ff_parse_channel_layout(0000000000000000, 2, 2); +-1 = ff_parse_channel_layout(0000000000000000, -1, -1); +0 = ff_parse_channel_layout(0000000000000000, 60, 60); +0 = ff_parse_channel_layout(0000000000000000, 65, 65); 0 = ff_parse_channel_layout(0000000000000004, 1, 1c); 0 = ff_parse_channel_layout(0000000000000003, 2, 2c); --1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, -1c); --1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 60c); --1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65c); +-1 = ff_parse_channel_layout(0000000000000000, -1, -1c); +0 = ff_parse_channel_layout(0000000000000000, 60, 60c); +0 = ff_parse_channel_layout(0000000000000000, 65, 65c); 0 = ff_parse_channel_layout(0000000000000000, 2, 2C); 0 = ff_parse_channel_layout(0000000000000000, 60, 60C); --1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65C); +-1 = ff_parse_channel_layout(0000000000000000, -1, 65C); 0 = ff_parse_channel_layout(000000000000003F, 6, 5.1); 0 = ff_parse_channel_layout(0000000000000003, 2, stereo); 0 = ff_parse_channel_layout(0000000000000001, 1, 1+1+1+1); From patchwork Wed Dec 8 01:06:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32133 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047792iog; Tue, 7 Dec 2021 17:12:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxYl899RE00XTvACQ3kuXN/hxjuPNm4SJvr8bihVrfB3eqPyp9Vx7q0pWDpAmOrao2ZCDa X-Received: by 2002:a17:906:ad89:: with SMTP id la9mr3546933ejb.178.1638925961156; Tue, 07 Dec 2021 17:12:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925961; cv=none; d=google.com; s=arc-20160816; b=QxLR0Anf0mdu3+zR8XKLG1uekcjv/T3vseGcBXSrIkrG6V4CCqn5dsLNDs+AGec+4B g8hSvPZtlYZomEjfRbYP/EI8d1A3hGLNQnZu9yQrOsEbFGIfoA0CzTkbmpWFIYtTMvuw FH//z1fm0ntUqv/O3+XhaPlR7JQas9Guix2A5y6ai4RG1eeYjgjTjF0Rvy4TpRgrIz3r 9eFdComcgcCa4PFqgh3Aur22Kbl+79yZA/heqr1AD/0RBovdcrvnhJQzDzURB0yqLtEv 7eRAlknLwagLzoVNM/Q3KOfdh/ATYz6uQ2CnTPguSJvEDWVdbldVOlSCijDDMOo2HyTl OFsA== 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=gvGobYR8bjsqFwQbmKGE0AT9Gq/AK77crHMiccnFmXQ=; b=QIbaN6bM91kePVJ0qHuHSuj86qKONtQpPGTguaz0rfSWS/St+LG5UQc46nddUcbGSj l+mEn8+Uzq6FnXQm7y5opJfeKjsDuN8ZZ7mjpvug+6/aOjjvLMkUdTopq1N+LonFquhi 9OrouXvMX+BRocqXW+Q6M4BvPAau8bF+xLAU7tJwq7oeeS6/j2peuUSH78tPaR3T7CMk u2fziVfvXyBdpjnAEg1wC/YpMGrA0oIJeWscNyt4xGlJ+ClLkGMvsQsmwYIkczxUbNGs W2mBbGJc8cssP17sljvjYypPl6naLZAQ55gmw/IMHv07wT+TEN7evxEZBG/BWg4a7qWz zkfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="ktUW/WlI"; 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 y19si2922372edc.31.2021.12.07.17.12.40; Tue, 07 Dec 2021 17:12:41 -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="ktUW/WlI"; 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 4049C68AF8A; Wed, 8 Dec 2021 03:08:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CE6B68AF5D for ; Wed, 8 Dec 2021 03:08:07 +0200 (EET) Received: by mail-ua1-f44.google.com with SMTP id i6so1904333uae.6 for ; Tue, 07 Dec 2021 17:08:07 -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=asbF1PVUyNV9/PupJmltUYpUGyMUJyg+qZvI0Qvf8zQ=; b=ktUW/WlISKCAAYX20IwIXb0z6/SuBAAkvO8QT3EwpvzVPkjozNd6nkfCvuaLto47sb 1X8XxQcGZJHFQplKxIAUDLX7Q2v4DJ5On5U9L33oyHS8pwQjmaJrrNEGq/yH+KWqz1TQ 7ZkmeOMWWUGwnSajOCCJkbKHBFc68ppLwy3pU84OPUwOGJw8zAeDhNM+mPiSx8PdmVCz wIAckY6m0sVnbCuakWDDcGmNDBjqXs/8GovtE1g4r1rFzgPcBgtp85o+QDW6HPqxmxQT OARlfvbzu/pECpIwThM7c/uesaZSjP8cR5uiC3S8MIHwZOE8X9u5nc8ZbC3Ndsf61kYG 2uYw== 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=asbF1PVUyNV9/PupJmltUYpUGyMUJyg+qZvI0Qvf8zQ=; b=x8UOUmzD2Xk6Z7IyUI0J3WVfdLruxuk0EeXGndf2SUwKsK/clErGVLoLPBK8/QSBDy Khb50HMclm0JMOC4tTLyWJWgFaFRhSSxYmCxAzLW1oTi3n5mLClDp45CpWxfOk0kKgs9 XPt75pJRmbajKTYyZwVTvSXmVzR1RtYFtNaOmHPoI2NEg1g8NDqthOXRFmZNKUYvlqid 3p2EwZtcqNT1yF6W9SwePyaR4si3vYJlr9MPkRRLa8DIP46bHof8CpGK70DtiauC+vAY cxkhOTxV8tZyV/ABjJhA0PKZbOQBslUD5tSk4a8DHOJYjbOhtSe+c7RVlWHS/Djx8yta 36qw== X-Gm-Message-State: AOAM5312Kxio8Cxw81At2Bc61r1latQ2DZwuFq1tB8tFFxdLyxMDmSlF bI9Ra+b4EUVWBj7E5VL6kdU6921xkgsP3JSX X-Received: by 2002:ab0:7619:: with SMTP id o25mr4167968uap.49.1638925685142; Tue, 07 Dec 2021 17:08:05 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:04 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:45 -0300 Message-Id: <20211208010649.381-30-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 275/279] ffmpeg: 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: 3kAPYa16GO2g Signed-off-by: James Almer --- fftools/cmdutils.c | 42 +++++++++++++++--------- fftools/cmdutils.h | 8 ----- fftools/ffmpeg.c | 47 ++++++++++++++++---------- fftools/ffmpeg.h | 7 ++-- fftools/ffmpeg_filter.c | 43 +++++++++++++++++------- fftools/ffmpeg_opt.c | 62 ++++++++++++++++++++++++++++++----- tests/fate/aac.mak | 2 +- tests/fate/cover-art.mak | 2 +- tests/fate/lavf-container.mak | 2 +- 9 files changed, 147 insertions(+), 68 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 3c8e5a82cd..223015db8b 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1470,8 +1470,19 @@ static void print_codec(const AVCodec *c) GET_SAMPLE_RATE_NAME); PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats", AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME); - PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts", - 0, GET_CH_LAYOUT_DESC); + + if (c->ch_layouts) { + const AVChannelLayout *p = c->ch_layouts; + + printf(" Supported channel layouts:"); + while (p->nb_channels) { + char name[128]; + av_channel_layout_describe(p, name, sizeof(name)); + printf(" %s", name); + p++; + } + printf("\n"); + } if (c->priv_class) { show_help_children(c->priv_class, @@ -1784,29 +1795,30 @@ int show_pix_fmts(void *optctx, const char *opt, const char *arg) int show_layouts(void *optctx, const char *opt, const char *arg) { + const AVChannelLayout *ch_layout; + void *iter = NULL; + char buf[128], buf2[128]; int i = 0; - uint64_t layout, j; - const char *name, *descr; printf("Individual channels:\n" "NAME DESCRIPTION\n"); for (i = 0; i < 63; i++) { - name = av_get_channel_name((uint64_t)1 << i); - if (!name) + av_channel_name(buf, sizeof(buf), i); + if (!strcmp(buf, "?")) continue; - descr = av_get_channel_description((uint64_t)1 << i); - printf("%-14s %s\n", name, descr); + av_channel_description(buf2, sizeof(buf2), i); + printf("%-14s %s\n", buf, buf2); } printf("\nStandard channel layouts:\n" "NAME DECOMPOSITION\n"); - for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) { - if (name) { - printf("%-14s ", name); - for (j = 1; j; j <<= 1) - if ((layout & j)) - printf("%s%s", (layout & (j - 1)) ? "+" : "", av_get_channel_name(j)); + while (ch_layout = av_channel_layout_standard(&iter)) { + av_channel_layout_describe(ch_layout, buf, sizeof(buf)); + av_channel_name(buf2, sizeof(buf2), i); + printf("%-14s ", buf); + for (i = 0; i < 63; i++) + if (av_channel_layout_index_from_channel(ch_layout, i) >= 0) + printf("%s%s", i ? "+" : "", buf2); printf("\n"); - } } return 0; } diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 82cda208be..fce2da288b 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -663,14 +663,6 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); char name[16];\ snprintf(name, sizeof(name), "%d", rate); -#define GET_CH_LAYOUT_NAME(ch_layout)\ - char name[16];\ - snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout); - -#define GET_CH_LAYOUT_DESC(ch_layout)\ - char name[128];\ - av_get_channel_layout_string(name, sizeof(name), 0, ch_layout); - double get_rotation(int32_t *displaymatrix); #endif /* FFTOOLS_CMDUTILS_H */ diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0f1834cdbe..6dc5a00356 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -555,6 +555,7 @@ static void ffmpeg_cleanup(int ret) avfilter_inout_free(&ofilter->out_tmp); av_freep(&ofilter->name); + av_channel_layout_uninit(&ofilter->ch_layout); av_freep(&fg->outputs[j]); } av_freep(&fg->outputs); @@ -1537,7 +1538,7 @@ static int reap_filters(int flush) break; case AVMEDIA_TYPE_AUDIO: if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && - enc->channels != filtered_frame->channels) { + enc->ch_layout.nb_channels != filtered_frame->ch_layout.nb_channels) { av_log(NULL, AV_LOG_ERROR, "Audio filter graph output is not normalized and encoder does not support parameter changes\n"); break; @@ -1883,17 +1884,22 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti print_final_stats(total_size); } -static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) +static int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) { + int ret; + // We never got any input. Set a fake format, which will // come from libavformat. ifilter->format = par->format; ifilter->sample_rate = par->sample_rate; - ifilter->channels = par->channels; - ifilter->channel_layout = par->channel_layout; ifilter->width = par->width; ifilter->height = par->height; ifilter->sample_aspect_ratio = par->sample_aspect_ratio; + ret = av_channel_layout_copy(&ifilter->ch_layout, &par->ch_layout); + if (ret < 0) + return ret; + + return 0; } static void flush_encoders(void) @@ -1921,8 +1927,11 @@ static void flush_encoders(void) int x; for (x = 0; x < fg->nb_inputs; x++) { InputFilter *ifilter = fg->inputs[x]; - if (ifilter->format < 0) - ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar); + if (ifilter->format < 0 && + ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar) < 0) { + av_log(NULL, AV_LOG_ERROR, "Error copying paramerets from input stream\n"); + exit_program(1); + } } if (!ifilter_has_all_input_formats(fg)) @@ -2098,16 +2107,15 @@ int guess_input_channel_layout(InputStream *ist) { AVCodecContext *dec = ist->dec_ctx; - if (!dec->channel_layout) { + if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { char layout_name[256]; - if (dec->channels > ist->guess_layout_max) + if (dec->ch_layout.nb_channels > ist->guess_layout_max) return 0; - dec->channel_layout = av_get_default_channel_layout(dec->channels); - if (!dec->channel_layout) + av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels); + if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) return 0; - av_get_channel_layout_string(layout_name, sizeof(layout_name), - dec->channels, dec->channel_layout); + av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name)); av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream " "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name); } @@ -2160,8 +2168,7 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_ref switch (ifilter->ist->st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: need_reinit |= ifilter->sample_rate != frame->sample_rate || - ifilter->channels != frame->channels || - ifilter->channel_layout != frame->channel_layout; + av_channel_layout_compare(&ifilter->ch_layout, &frame->ch_layout); break; case AVMEDIA_TYPE_VIDEO: need_reinit |= ifilter->width != frame->width || @@ -2241,8 +2248,11 @@ static int ifilter_send_eof(InputFilter *ifilter, int64_t pts) return ret; } else { // the filtergraph was never configured - if (ifilter->format < 0) - ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar); + if (ifilter->format < 0) { + ret = ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar); + if (ret < 0) + return ret; + } if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index); return AVERROR_INVALIDDATA; @@ -3318,8 +3328,9 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) case AVMEDIA_TYPE_AUDIO: enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter); enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter); - enc_ctx->channel_layout = av_buffersink_get_channel_layout(ost->filter->filter); - enc_ctx->channels = av_buffersink_get_channels(ost->filter->filter); + ret = av_buffersink_get_ch_layout(ost->filter->filter, &enc_ctx->ch_layout); + if (ret < 0) + return ret; if (ost->bits_per_raw_sample) enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9b200b806a..75f6f9ef72 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -250,8 +250,7 @@ typedef struct InputFilter { AVRational sample_aspect_ratio; int sample_rate; - int channels; - uint64_t channel_layout; + AVChannelLayout ch_layout; AVBufferRef *hw_frames_ctx; int32_t *displaymatrix; @@ -274,12 +273,12 @@ typedef struct OutputFilter { AVRational frame_rate; int format; int sample_rate; - uint64_t channel_layout; + AVChannelLayout ch_layout; // those are only set if no format is specified and the encoder gives us multiple options // They point directly to the relevant lists of the encoder. const int *formats; - const uint64_t *channel_layouts; + const AVChannelLayout *ch_layouts; const int *sample_rates; } OutputFilter; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 501a0acd61..6d52713cd6 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -153,8 +153,23 @@ DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats, DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0, "%d", ) -DEF_CHOOSE_FORMAT(channel_layouts, uint64_t, channel_layout, channel_layouts, 0, - "0x%"PRIx64, ) +static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint) +{ + if (av_channel_layout_check(&ofilter->ch_layout) && ofilter->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) { + av_bprintf(bprint, "channel_layouts=0x%"PRIx64, ofilter->ch_layout.u.mask); + } else if (ofilter->ch_layouts) { + const AVChannelLayout *p; + + av_bprintf(bprint, "channel_layouts="); + for (p = ofilter->ch_layouts; p->nb_channels; p++) { + av_bprintf(bprint, "0x%"PRIx64 "|", p->u.mask); + } + if (bprint->len > 0) + bprint->str[--bprint->len] = '\0'; + } else + return; + av_bprint_chars(bprint, ':', 1); +} int init_simple_filtergraph(InputStream *ist, OutputStream *ost) { @@ -541,9 +556,11 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, } while (0) av_bprint_init(&args, 0, AV_BPRINT_SIZE_UNLIMITED); if (ost->audio_channels_mapped) { + AVChannelLayout mapped_layout = { 0 }; int i; - av_bprintf(&args, "0x%"PRIx64, - av_get_default_channel_layout(ost->audio_channels_mapped)); + av_channel_layout_default(&mapped_layout, ost->audio_channels_mapped); + av_bprintf(&args, "0x%"PRIx64, mapped_layout.order == AV_CHANNEL_ORDER_NATIVE ? + mapped_layout.u.mask : 0); for (i = 0; i < ost->audio_channels_mapped; i++) if (ost->audio_channels_map[i] != -1) av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]); @@ -552,8 +569,8 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, av_bprint_clear(&args); } - if (codec->channels && !codec->channel_layout) - codec->channel_layout = av_get_default_channel_layout(codec->channels); + if (codec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + av_channel_layout_default(&codec->ch_layout, codec->ch_layout.nb_channels); choose_sample_fmts(ofilter, &args); choose_sample_rates(ofilter, &args); @@ -840,11 +857,11 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, 1, ifilter->sample_rate, ifilter->sample_rate, av_get_sample_fmt_name(ifilter->format)); - if (ifilter->channel_layout) + if (av_channel_layout_check(&ifilter->ch_layout) && ifilter->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) av_bprintf(&args, ":channel_layout=0x%"PRIx64, - ifilter->channel_layout); + ifilter->ch_layout.u.mask); else - av_bprintf(&args, ":channels=%d", ifilter->channels); + av_bprintf(&args, ":channels=%d", ifilter->ch_layout.nb_channels); snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, ist->file_index, ist->st->index); @@ -1092,7 +1109,10 @@ int configure_filtergraph(FilterGraph *fg) ofilter->height = av_buffersink_get_h(sink); ofilter->sample_rate = av_buffersink_get_sample_rate(sink); - ofilter->channel_layout = av_buffersink_get_channel_layout(sink); + av_channel_layout_uninit(&ofilter->ch_layout); + ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout); + if (ret < 0) + goto fail; } fg->reconfiguration = 1; @@ -1166,8 +1186,7 @@ int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame) ifilter->sample_aspect_ratio = frame->sample_aspect_ratio; ifilter->sample_rate = frame->sample_rate; - ifilter->channels = frame->channels; - ifilter->channel_layout = frame->channel_layout; + ifilter->ch_layout = frame->ch_layout; av_freep(&ifilter->displaymatrix); sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 9c820ab73f..0eb2c779f2 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -507,7 +507,7 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) /* allow trailing ? to map_channel */ if (allow_unused = strchr(mapchan, '?')) *allow_unused = 0; - if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels || + if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels || input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) { if (allow_unused) { av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n", @@ -1954,9 +1954,14 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); if (!ost->stream_copy) { + int channels = 0; char *sample_fmt = NULL; - MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st); + MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st); + if (channels) { + audio_enc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + audio_enc->ch_layout.nb_channels = channels; + } MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st); if (sample_fmt && @@ -2378,7 +2383,7 @@ static int open_output_file(OptionsContext *o, const char *filename) for (i = 0; i < ifile->nb_streams; i++) { int score; ist = input_streams[ifile->ist_index + i]; - score = ist->st->codecpar->channels + score = ist->st->codecpar->ch_layout.nb_channels + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS) + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); if (ist->user_set_discard == AVDISCARD_ALL) @@ -2651,10 +2656,10 @@ loop_end: } else { f->sample_rates = ost->enc->supported_samplerates; } - if (ost->enc_ctx->channels) { - f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels); - } else { - f->channel_layouts = ost->enc->channel_layouts; + if (ost->enc_ctx->ch_layout.nb_channels) { + av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); + } else if (ost->enc->ch_layouts) { + f->ch_layouts = ost->enc->ch_layouts; } break; } @@ -3237,6 +3242,41 @@ static int opt_timecode(void *optctx, const char *opt, const char *arg) return ret; } +static int opt_ch_layout(void *optctx, const char *opt, const char *arg) +{ + OptionsContext *o = optctx; + char layout_str[32]; + char *stream_str; + char *ac_str; + int ret, ac_str_size; + AVChannelLayout layout = { 0 }; + + ret = av_channel_layout_from_string(&layout, arg); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg); + return AVERROR(EINVAL); + } + ret = opt_default_new(o, opt, arg); + if (ret < 0) + return ret; + + /* set 'ac' option based on channel layout */ + snprintf(layout_str, sizeof(layout_str), "%d", layout.nb_channels); + stream_str = strchr(opt, ':'); + ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0); + ac_str = av_mallocz(ac_str_size); + if (!ac_str) + return AVERROR(ENOMEM); + av_strlcpy(ac_str, "ac", 3); + if (stream_str) + av_strlcat(ac_str, stream_str, ac_str_size); + ret = parse_option(o, ac_str, layout_str, options); + av_free(ac_str); + + return ret; +} + +#if FF_API_OLD_CHANNEL_LAYOUT static int opt_channel_layout(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; @@ -3272,6 +3312,7 @@ static int opt_channel_layout(void *optctx, const char *opt, const char *arg) return ret; } +#endif static int opt_audio_qscale(void *optctx, const char *opt, const char *arg) { @@ -3818,9 +3859,14 @@ const OptionDef options[] = { { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(sample_fmts) }, "set sample format", "format" }, + { "ch_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE | + OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_ch_layout }, + "set channel layout", "layout" }, +#if FF_API_OLD_CHANNEL_LAYOUT { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_channel_layout }, - "set channel layout", "layout" }, + "deprecated, use -ch_layout", "layout" }, +#endif { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters }, "set audio filters", "filter_graph" }, { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) }, diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak index 1743428f54..d8750b093a 100644 --- a/tests/fate/aac.mak +++ b/tests/fate/aac.mak @@ -237,7 +237,7 @@ fate-aac-latm_000000001180bc60: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_00000000 fate-aac-latm_000000001180bc60: REF = $(SAMPLES)/aac/latm_000000001180bc60.s16 FATE_AAC_LATM += fate-aac-latm_stereo_to_51 -fate-aac-latm_stereo_to_51: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -channel_layout 5.1 +fate-aac-latm_stereo_to_51: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -ch_layout 5.1 fate-aac-latm_stereo_to_51: REF = $(SAMPLES)/aac/latm_stereo_to_51_ref.s16 fate-aac-autobsf-adtstoasc: CMD = transcode "aac" $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \ diff --git a/tests/fate/cover-art.mak b/tests/fate/cover-art.mak index c2e3b1e7c1..49fe044a7b 100644 --- a/tests/fate/cover-art.mak +++ b/tests/fate/cover-art.mak @@ -55,7 +55,7 @@ FATE_COVER_ART_REMUX-$(call ALLYES, FILE_PROTOCOL MOV_DEMUXER OGG_DEMUXER \ FLAC_MUXER FLAC_DEMUXER FLAC_DECODER \ FRAMECRC_MUXER PIPE_PROTOCOL) \ += fate-cover-art-flac-remux -fate-cover-art-flac-remux: CMD = transcode mov $(TARGET_SAMPLES)/lossless-audio/inside.m4a flac "-map 0 -map 1:v -map 1:v -af channelmap=channel_layout=FL+FC,aresample -c:a flac -multi_dim_quant 1 -c:v:0 copy -metadata:s:v:0 comment=Illustration -metadata:s:v:0 title=OpenMusic -filter:v:1 scale -c:v:1 png -metadata:s:v:1 title=landscape -c:v:2 copy -filter:v:3 scale -metadata:s:v:2 title=portrait -c:v:3 bmp -metadata:s:v:3 comment=Conductor -c:v:4 copy -t 0.4" "-map 0 -map 0:a -c:a:0 copy -c:v copy" "" "-show_entries format_tags:stream_tags:stream_disposition=attached_pic:stream=index,codec_name" "-f ogg -i $(TARGET_SAMPLES)/cover_art/ogg_vorbiscomment_cover.opus" +fate-cover-art-flac-remux: CMD = transcode mov $(TARGET_SAMPLES)/lossless-audio/inside.m4a flac "-map 0 -map 1:v -map 1:v -af channelmap=channel_layout=FL|FC,aresample -c:a flac -multi_dim_quant 1 -c:v:0 copy -metadata:s:v:0 comment=Illustration -metadata:s:v:0 title=OpenMusic -filter:v:1 scale -c:v:1 png -metadata:s:v:1 title=landscape -c:v:2 copy -filter:v:3 scale -metadata:s:v:2 title=portrait -c:v:3 bmp -metadata:s:v:3 comment=Conductor -c:v:4 copy -t 0.4" "-map 0 -map 0:a -c:a:0 copy -c:v copy" "" "-show_entries format_tags:stream_tags:stream_disposition=attached_pic:stream=index,codec_name" "-f ogg -i $(TARGET_SAMPLES)/cover_art/ogg_vorbiscomment_cover.opus" FCA_TEMP-$(call ALLYES, RAWVIDEO_MUXER FILE_PROTOCOL) = $(FATE_COVER_ART-yes) FATE_COVER_ART = $(FCA_TEMP-yes) diff --git a/tests/fate/lavf-container.mak b/tests/fate/lavf-container.mak index 9e0eed4851..446a0cfbe2 100644 --- a/tests/fate/lavf-container.mak +++ b/tests/fate/lavf-container.mak @@ -26,7 +26,7 @@ $(FATE_LAVF_CONTAINER): $(AREF) $(VREF) fate-lavf-asf: CMD = lavf_container "" "-c:a mp2 -ar 44100" "-r 25" fate-lavf-avi fate-lavf-nut: CMD = lavf_container "" "-c:a mp2 -ar 44100 -threads 1" -fate-lavf-dv: CMD = lavf_container "-ar 48000 -channel_layout stereo" "-r 25 -s pal" +fate-lavf-dv: CMD = lavf_container "-ar 48000 -ch_layout stereo" "-r 25 -s pal" fate-lavf-dv_pal: CMD = lavf_container_timecode_nodrop "-ar 48000 -r 25 -s pal -ac 2 -f dv" fate-lavf-dv_ntsc: CMD = lavf_container_timecode_drop "-ar 48000 -pix_fmt yuv411p -s ntsc -ac 2 -f dv" fate-lavf-flv fate-lavf-swf: CMD = lavf_container "" "-an" From patchwork Wed Dec 8 01:06:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32151 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047932iog; Tue, 7 Dec 2021 17:12:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+yx2MSngzs3rbYB9QmbNOf5ErDgZOhqb/8ODgYefp9kjO2qDlH2+L+4YT8pL0MfoWbP+P X-Received: by 2002:a17:907:c22:: with SMTP id ga34mr3458054ejc.217.1638925970653; Tue, 07 Dec 2021 17:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925970; cv=none; d=google.com; s=arc-20160816; b=yCikFU9Zfuqag8XEZhnauwMqbilTSEU/zR1p3rZI8IjmED+doTCT2IIa2uv8pvwWY/ VO2msUYr2c4afSiTaaeTprc46ur6wjGv8W6kEiqMzeXgPqQR4KJjO392Za7zsoKIBdQl Cz6uybbcvUkM8u9U7hJ43jbUXHDvjSiNiYw0l8xqPO2Eqv+q4RZFtB/aFkJlJs3/pF8/ kQkmO2NcpsvYpam1g3eC7qndrVlNEiXrADo5DBN8X6vAglCbv8nVumI2NmmYrA8chqj+ oynHzl1ta8d4hxSzmTnc5R57Bck6fiG+Qth7GPbVHv1tD8AhsAKspbcwnT7mtiUx0Wa0 ZZ/w== 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=umvvTTtSQZSlo5CKGhyeqHkOKO5SqgrC+tep2AErAGI=; b=C9rpeHuU2xkp32iyTLZq4taiT7JBetfSFeYlxOYetsVRWiOlMc3hY9d1hKWMzWu3CW QMsrDv2xj8L3wUc2qMVZTBr+CBJD2IO/CLpK0sf22gFycEn7p57ZqE1CS4aI+uauIpNA UOEo44VBWnABnFZIH7XGJ6LNcjE7BPjN6bDz7qSu0uNludOcPOJZIueGCQnQh/TL3mUs XbLpS1ThxiT1PiKceT06w8agtilAehUuxzWh1gFjLHdkI/7zc8Zxl5nlbu4WtuemAemj aAKlX5RA9Z6tKJF3sAS3mpF0aiIVpTsUebRBGeJaOP4ueaGtVBl1B4gN+quSNl5i9NNZ jDPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=BdXDdRP3; 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 j19si2680874edj.137.2021.12.07.17.12.50; Tue, 07 Dec 2021 17:12:50 -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=BdXDdRP3; 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 2C16768AF1C; Wed, 8 Dec 2021 03:08:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA88D68AF6E for ; Wed, 8 Dec 2021 03:08:07 +0200 (EET) Received: by mail-ua1-f51.google.com with SMTP id l24so1954340uak.2 for ; Tue, 07 Dec 2021 17:08:07 -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=uahLS5slZO31Ils5Z5jz3VL7IZJFGKdp1vH+exRWFNA=; b=BdXDdRP3uMOis1m2wThzdUm5kQ9eaafVMcVsBIdHWpfhJMgc8ZMSrHBpT5ZdxH3v01 jJ/ZM+bqc2D4NUcSRqDCVaJZ6Dw7bLeUta+7UiSXWMJdMzeYimbhTXF8hYEWKst4jD37 5PNSLYN9CiXT2omu6weoqGF3A7lQr2KQZBAlvRHiT2jovzELNFKKTBTGcTj7eQnzuuR2 BZTMQkM5nMcHJgN0ZgzmUvUC7eFfsdbDurgUzKB3uzFdwjcEJSw5VA0Xa3elb7h81ZqP ftefhGMEt6X7S38eJ+eIuStK80XvS/i0tsDELlHmw8zSYv5p54D1H8yULucWv20SkYzm vLRw== 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=uahLS5slZO31Ils5Z5jz3VL7IZJFGKdp1vH+exRWFNA=; b=f7ZMBrSo71HqG4jpP8jiwun+FirzwkXbDAAW6hFuqGeAb8rdGoRd8VBVj2OcY6Apc8 Gld+RMwAfvKa4PCsg3QdF8drvgKrew/iYcZAZpusU8fJvRukEtZixZm+N1t8byJc9FXA HglJ81ZGDwW/V/5b79fq6HPn3grsVjWL3l6VWJkl6e/Gm06nomLrAPnIH5eEs9we/rcm upEiASWLRV2hWrwuslN4apLSN6hXTsvcEwu8BnQJ3CiCOn4KYdKtxvu/MwOahS/uWkjw KwTBbeMtimrxdsB30cyv2ctuuNye85qSbqCzSPU94RJK+WfOCXq+n+NSjxGK7L1KHLob 0GDw== X-Gm-Message-State: AOAM533HU4AliDzD8tPMTGg2A7RG6a0LzLUVNry/n8o9aleJwvFOxl0l eRvMUjE7vjzYbjBeWvzvL/m931gMx4nprZ9h X-Received: by 2002:ab0:35e8:: with SMTP id w8mr4060309uau.31.1638925686343; Tue, 07 Dec 2021 17:08:06 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:05 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:46 -0300 Message-Id: <20211208010649.381-31-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 276/279] ffprobe: 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: sz30qKB0VRJa Signed-off-by: James Almer --- fftools/ffprobe.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 0711e02922..52d3d26962 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2295,12 +2295,10 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, if (s) print_str ("sample_fmt", s); else print_str_opt("sample_fmt", "unknown"); print_int("nb_samples", frame->nb_samples); - print_int("channels", frame->channels); - if (frame->channel_layout) { - av_bprint_clear(&pbuf); - av_bprint_channel_layout(&pbuf, frame->channels, - frame->channel_layout); - print_str ("channel_layout", pbuf.str); + print_int("channels", frame->ch_layout.nb_channels); + if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { + av_channel_layout_describe(&frame->ch_layout, val_str, sizeof(val_str)); + print_str ("channel_layout", val_str); } else print_str_opt("channel_layout", "unknown"); break; @@ -2704,12 +2702,11 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id if (s) print_str ("sample_fmt", s); else print_str_opt("sample_fmt", "unknown"); print_val("sample_rate", par->sample_rate, unit_hertz_str); - print_int("channels", par->channels); + print_int("channels", par->ch_layout.nb_channels); - if (par->channel_layout) { - av_bprint_clear(&pbuf); - av_bprint_channel_layout(&pbuf, par->channels, par->channel_layout); - print_str ("channel_layout", pbuf.str); + if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { + av_channel_layout_describe(&par->ch_layout, val_str, sizeof(val_str)); + print_str ("channel_layout", val_str); } else { print_str_opt("channel_layout", "unknown"); } From patchwork Wed Dec 8 01:06:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32131 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7048313iog; Tue, 7 Dec 2021 17:13:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMca0LgJ82mEm1YcNxvjw2QpxgET3LpQafCksZ5utnuO0gWTZYIJUe/N9BJt4BX6kc+ABL X-Received: by 2002:a17:907:7213:: with SMTP id dr19mr3517688ejc.157.1638925993482; Tue, 07 Dec 2021 17:13:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925993; cv=none; d=google.com; s=arc-20160816; b=mOLnAN2hJQ8RWIYqG7yYQ+5wbglvOHnZqDNDg0XScplX2aUpyECTGAKYStlydUWS4p F2bE64LYD2oCmm79M0ltNmHTG5Nb+VUBnLDzZhYj7sQyF5c1AuusORKH1LI6Zl9dtw4u 8eY1XmiRycMXWuN2UdIS/khq5ZZ4Ap3V/8cfkoT3xePuI5dnlUbo+41MNE3gSIrd/NwR b5mzeXlEGU4DMKiwTytaEXFA+Fzu9CQyUZ7EREyQ1gROlNwY0YCzYLhohOzW3tP1jzZv ttautRhVu9mX+Sb3GggghsVKJyB9Lc+Sy58anfV/Ea9F66ERATtfsBAYOj/r9v3MkrPO 0+Uw== 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=VgNXA8ZZY9C3rmsKfv61+eflWzsZ9FytN7W2sGYEvsk=; b=r6vfAcST6BsK2yzqmO4FlpoNPRSDwhTV6nwW81r7x84RzX+ii4eHG+bwykS1cvNbHH S1RvLKVoY48OJeT1FxG9CkXgFuHUIETuvz43IayHnsIjHRFw2vlDxwzXbGto9vxEcUwr g1RJEQbQfhey8IIWSWWq+iNvkqfmpQ5d+upZ0c6WM8jjqenRwuD8e2yQy8p5dbJkUdb0 Bo7VW0i4zr9OXKct+dx5HJa9vCPv0/+Xqgzfmgz9CyLrAbGCJWI9V4CePoNqZqvFH9zg QzM6MeXPt9qSYoTcYlw1pa1hhhWCSCcEevH/c31Rm9EisyGiirifEMH7uqv/GeR3Meqw ZxLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=eWVc7jDs; 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 i9si1813383edx.174.2021.12.07.17.13.13; Tue, 07 Dec 2021 17:13:13 -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=eWVc7jDs; 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 3481C68AF9C; Wed, 8 Dec 2021 03:08:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 328DE68AF78 for ; Wed, 8 Dec 2021 03:08:09 +0200 (EET) Received: by mail-ua1-f53.google.com with SMTP id p37so1890968uae.8 for ; Tue, 07 Dec 2021 17:08:09 -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=ZBchVHGtt0ic1uofzBQFCx3wr8jf8hMUIboneDig81k=; b=eWVc7jDskn36xox8qd8xvnyHTTSdg1P5llAp55QsEEfVMhosDs0Gtenw/WKmR9JHcd YhdVJ0X622UqMFl0sjpRY5qeXG2HunjHnlvDGJ0t36snv49jIdiB62RiehUZcA6iXy4R c/VuNyks+Vt9P8xmRfGIDSH4y4NpFmGsU/0MO0103aaYaCzXRVGeF5oZrVsyP5Qjt2fd RzIWbMBOapgBMziKokNgRkP73gAagWb+dG/9ejThwnUK9LaZ9RD2yYP6n9vqtOJrtf1+ AaiQ4ITGbYlOqdJabnXRg4hjXTuTOQSFY1rAr22UDnOcVpgaxipuF31SVhQjCqWlYieZ 9e5g== 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=ZBchVHGtt0ic1uofzBQFCx3wr8jf8hMUIboneDig81k=; b=O8KbXNMXFoVAIaRjASWlQ0A1YJvczrwj+ElWL3Wvq6BLa9NDoSFKfdnbR/85Wf9m1+ a000RuEp5UvsSkHte5MBoks0WEelnuMByzr0f72UR8YNoX+VE9cbOR4zREIPT3zDo/L/ UwihOHQYq268kbbafZSEpfH2EDUj0KTX3HLOOdW27sf3IHyabyRmDObqpn8XiX8hZTdX Tchy6p0UxlJcQTAjSP+QfJUzEGzBSULgJa9pjSACcaf7Sy3LzkUYDN9Vjw343V+z0hEz k+mJWR+dtESV58jNOH58A1qLnmGtDKN67W4Sv946xvCg3sNddhT5tbMka3niwHRma4hh Ej/A== X-Gm-Message-State: AOAM532hUk+OoUPogi29pjLj2zZnxKfo7NuXxL9fSxirNCMH9UJoQNHg rB3AlU8qyi5OpsryL62cRHHWQcK6NEBE52bw X-Received: by 2002:ab0:378b:: with SMTP id d11mr4098476uav.61.1638925687553; Tue, 07 Dec 2021 17:08:07 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:07 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:47 -0300 Message-Id: <20211208010649.381-32-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 277/279] channel_layout: add support for Ambisonic 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: Kgd8q7n2XGMk From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavutil/channel_layout.c | 147 ++++++++++++++++++++++++++++++- libavutil/channel_layout.h | 49 +++++++++++ libavutil/tests/channel_layout.c | 10 +++ tests/ref/fate/channel_layout | 6 ++ 4 files changed, 210 insertions(+), 2 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 984255bfca..a51af95fcf 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -31,6 +31,9 @@ #include "bprint.h" #include "common.h" +#define CHAN_IS_AMBI(x) ((x) >= AV_CHAN_AMBISONIC_BASE &&\ + (x) <= AV_CHAN_AMBISONIC_END) + struct channel_name { const char *name; const char *description; @@ -80,7 +83,10 @@ static const char *get_channel_name(enum AVChannel channel_id) static inline void get_channel_str(AVBPrint *bp, const char *str, enum AVChannel channel_id) { - if (str) + if (channel_id >= AV_CHAN_AMBISONIC_BASE && + channel_id <= AV_CHAN_AMBISONIC_END) + av_bprintf(bp, "ambisonic %d", channel_id - AV_CHAN_AMBISONIC_BASE); + else if (str) av_bprintf(bp, "%s", str); else av_bprintf(bp, "?"); @@ -116,6 +122,14 @@ int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel_id enum AVChannel av_channel_from_string(const char *str) { int i; + + if (!strncmp(str, "ambisonic", 9)) { + i = strtol(str + 9, NULL, 0); + if (i < 0 || i > AV_CHAN_AMBISONIC_END - AV_CHAN_AMBISONIC_BASE) + return AV_CHAN_NONE; + return AV_CHAN_AMBISONIC_BASE + i; + } + for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) { if (channel_names[i].name && !strcmp(str, channel_names[i].name)) return i; @@ -415,6 +429,53 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, return 0; } + /* ambisonic */ + if (!strncmp(str, "ambisonic ", 10)) { + const char *p = str + 10; + char *endptr; + AVChannelLayout extra = {0}; + int order; + + order = strtol(p, &endptr, 0); + if (order < 0 || order + 1 > INT_MAX / (order + 1) || + (*endptr && *endptr != '|')) + return AVERROR(EINVAL); + + channel_layout->order = AV_CHANNEL_ORDER_AMBISONIC; + channel_layout->nb_channels = (order + 1) * (order + 1); + + if (*endptr) { + int ret = av_channel_layout_from_string(&extra, endptr + 1); + if (ret < 0) + return ret; + if (extra.order != AV_CHANNEL_ORDER_NATIVE || + extra.nb_channels >= INT_MAX - channel_layout->nb_channels) { + av_channel_layout_uninit(&extra); + return AVERROR(EINVAL); + } + + channel_layout->order = AV_CHANNEL_ORDER_CUSTOM; + channel_layout->u.map = + av_mallocz_array(channel_layout->nb_channels + extra.nb_channels, + sizeof(*channel_layout->u.map)); + if (!channel_layout->u.map) { + av_channel_layout_uninit(&extra); + return AVERROR(ENOMEM); + } + + for (i = 0; i < channel_layout->nb_channels; i++) + channel_layout->u.map[i].id = AV_CHAN_AMBISONIC_BASE + i; + for (i = 0; i < extra.nb_channels; i++) { + enum AVChannel ch = av_channel_layout_channel_from_index(&extra, i); + channel_layout->u.map[channel_layout->nb_channels + i].id = ch; + } + channel_layout->nb_channels += extra.nb_channels; + av_channel_layout_uninit(&extra); + } + + return 0; + } + return AVERROR_INVALIDDATA; } @@ -438,6 +499,67 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) return 0; } +/** + * If the custom layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, write its string description in dst + * and return 0. + * If it is something else, write NULL in dst and return 0. + * Return negative error code on error. + */ +static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +{ + const AVChannelCustom *map = channel_layout->u.map; + int i, highest_ambi, order; + + highest_ambi = -1; + for (i = 0; i < channel_layout->nb_channels; i++) { + int is_ambi = CHAN_IS_AMBI(map[i].id); + + /* ambisonic following non-ambisonic */ + if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id)) + return 0; + + /* non-default ordering */ + if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i) + return 0; + + if (CHAN_IS_AMBI(map[i].id)) + highest_ambi = i; + } + /* no ambisonic channels*/ + if (highest_ambi < 0) + return 0; + + order = floor(sqrt(highest_ambi)); + /* incomplete order - some harmonics are missing */ + if ((order + 1) * (order + 1) != highest_ambi + 1) + return 0; + + av_bprintf(bp, "ambisonic %d", order); + + /* extra channels present */ + if (highest_ambi < channel_layout->nb_channels - 1) { + AVChannelLayout extra; + char buf[128]; + + extra.order = AV_CHANNEL_ORDER_CUSTOM; + extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1; + extra.u.map = av_mallocz_array(extra.nb_channels, sizeof(*extra.u.map)); + if (!extra.u.map) + return AVERROR(ENOMEM); + + for (i = 0; i < extra.nb_channels; i++) + extra.u.map[i].id = map[highest_ambi + 1 + i].id; + + av_channel_layout_describe(&extra, buf, sizeof(buf)); + av_channel_layout_uninit(&extra); + + av_bprintf(bp, "|%s", buf); + } + + return 0; +} + int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size) { @@ -458,6 +580,12 @@ int av_channel_layout_describe(const AVChannelLayout *channel_layout, } // fall-through case AV_CHANNEL_ORDER_CUSTOM: + if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { + int res = try_describe_ambisonic(&bp, channel_layout); + if (res < 0) + return res; + } + for (i = 0; i < channel_layout->nb_channels; i++) { enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i); const char *ch_name = get_channel_name(ch); @@ -472,6 +600,9 @@ int av_channel_layout_describe(const AVChannelLayout *channel_layout, case AV_CHANNEL_ORDER_UNSPEC: av_bprintf(&bp, "%d channels", channel_layout->nb_channels); return bp.len; + case AV_CHANNEL_ORDER_AMBISONIC: + av_bprintf(&bp, "ambisonic %d", (int)floor(sqrt(channel_layout->nb_channels - 1))); + return bp.len; default: return AVERROR(EINVAL); } @@ -489,6 +620,8 @@ av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, switch (channel_layout->order) { case AV_CHANNEL_ORDER_CUSTOM: return channel_layout->u.map[idx].id; + case AV_CHANNEL_ORDER_AMBISONIC: + return AV_CHAN_AMBISONIC_BASE + idx; case AV_CHANNEL_ORDER_NATIVE: for (i = 0; i < 64; i++) { if ((1ULL << i) & channel_layout->u.mask && !idx--) @@ -532,6 +665,11 @@ int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, if (channel_layout->u.map[i].id == channel) return i; return AVERROR(EINVAL); + case AV_CHANNEL_ORDER_AMBISONIC: + if (!CHAN_IS_AMBI(channel) || + channel - AV_CHAN_AMBISONIC_BASE >= channel_layout->nb_channels) + return AVERROR(EINVAL); + return channel - AV_CHAN_AMBISONIC_BASE; case AV_CHANNEL_ORDER_NATIVE: { uint64_t mask = channel_layout->u.mask; if (!(mask & (1ULL << channel))) @@ -591,8 +729,13 @@ int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout else if (chl->order == AV_CHANNEL_ORDER_UNSPEC) return 0; + /* both ambisonic with same channel count -> equal */ + if (chl->order == AV_CHANNEL_ORDER_AMBISONIC && + chl1->order == chl->order) + return 0; + /* can compare masks directly */ - if (chl->order != AV_CHANNEL_ORDER_CUSTOM && + if (chl->order == AV_CHANNEL_ORDER_NATIVE && chl->order == chl1->order) return chl->u.mask != chl1->u.mask; diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 018e87ff0b..7b77a74b61 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -76,6 +76,23 @@ enum AVChannel { /** Channel is empty can be safely skipped. */ AV_CHAN_SILENCE = 64, + + /** + * Range of channels between AV_CHAN_AMBISONIC_BASE and + * AV_CHAN_AMBISONIC_END represent Ambisonic components using the ACN system. + * + * Given a channel id between AV_CHAN_AMBISONIC_BASE and + * AV_CHAN_AMBISONIC_END (inclusive), the ACN index of the channel is + * = - AV_CHAN_AMBISONIC_BASE. + * + * @note these values are only used for AV_CHANNEL_ORDER_CUSTOM channel + * orderings, the AV_CHANNEL_ORDER_AMBISONIC ordering orders the channels + * implicitly by their position in the stream. + */ + AV_CHAN_AMBISONIC_BASE = 0x400, + // leave space for 1024 ids, which correspond to maximum order-32 harmonics, + // which should be enough for the foreseeable use cases + AV_CHAN_AMBISONIC_END = 0x7ff, }; enum AVChannelOrder { @@ -97,6 +114,29 @@ enum AVChannelOrder { * channels at arbitrary positions. */ AV_CHANNEL_ORDER_CUSTOM, + /** + * The audio is represented as the decomposition of the sound field into + * spherical harmonics. Each channel corresponds to a single expansion + * component. Channels are ordered according to ACN (Ambisonic Channel + * Number). + * + * The channel with the index n in the stream contains the spherical + * harmonic of degree l and order m given by + * @code{.unparsed} + * l = floor(sqrt(n)), + * m = n - l * (l + 1). + * @endcode + * + * Conversely given a spherical harmonic of degree l and order m, the + * corresponding channel index n is given by + * @code{.unparsed} + * n = l * (l + 1) + m. + * @endcode + * + * Normalization is assumed to be SN3D (Schmidt Semi-Normalization) + * as defined in AmbiX format $ 2.1. + */ + AV_CHANNEL_ORDER_AMBISONIC, }; @@ -285,6 +325,11 @@ typedef struct AVChannelLayout { * * I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the * i-th channel in the audio data. + * + * When map[i].id is in the range between AV_CHAN_AMBISONIC_BASE and + * AV_CHAN_AMBISONIC_END (inclusive), the channel contains an ambisonic + * component with ACN index (as defined above) + * n = map[i].id - AV_CHAN_AMBISONIC_BASE. */ AVChannelCustom *map; } u; @@ -348,6 +393,8 @@ typedef struct AVChannelLayout { { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 2, .u = { .mask = AV_CH_LAYOUT_STEREO_DOWNMIX }} #define AV_CHANNEL_LAYOUT_22POINT2 \ { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 24, .u = { .mask = AV_CH_LAYOUT_22POINT2 }} +#define AV_CHANNEL_LAYOUT_AMBISONIC_FIRST_ORDER \ + { .order = AV_CHANNEL_ORDER_AMBISONIC, .nb_channels = 4, .u = { .mask = 0 }} #if FF_API_OLD_CHANNEL_LAYOUT /** @@ -532,6 +579,8 @@ int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask); * - a hexadecimal value of a channel layout (eg. "0x4") * - the number of channels with default layout (eg. "5c") * - the number of unordered channels (eg. "4" or "4 channels") + * - the ambisonic order followed by optional non-diegetic channels (eg. + * "ambisonic 2|stereo") * * @param channel_layout input channel layout * @param str string describing the channel layout diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c index 60854cf203..e4b42b1574 100644 --- a/libavutil/tests/channel_layout.c +++ b/libavutil/tests/channel_layout.c @@ -64,16 +64,26 @@ int main(void) printf("With AV_CHAN_FRONT_LEFT: %27s\n", buf); av_channel_name(buf, sizeof(buf), AV_CHAN_FRONT_RIGHT); printf("With AV_CHAN_FRONT_RIGHT: %26s\n", buf); + av_channel_name(buf, sizeof(buf), AV_CHAN_AMBISONIC_BASE); + printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", buf); + av_channel_name(buf, sizeof(buf), AV_CHAN_AMBISONIC_END); + printf("With AV_CHAN_AMBISONIC_END: %24s\n", buf); printf("Testing av_channel_description\n"); av_channel_description(buf, sizeof(buf), AV_CHAN_FRONT_LEFT); printf("With AV_CHAN_FRONT_LEFT: %27s\n", buf); av_channel_description(buf, sizeof(buf), AV_CHAN_FRONT_RIGHT); printf("With AV_CHAN_FRONT_RIGHT: %26s\n", buf); + av_channel_description(buf, sizeof(buf), AV_CHAN_AMBISONIC_BASE); + printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", buf); + av_channel_description(buf, sizeof(buf), AV_CHAN_AMBISONIC_END); + printf("With AV_CHAN_AMBISONIC_END: %24s\n", buf); printf("\nTesting av_channel_from_string\n"); printf("With \"FL\": %41d\n", av_channel_from_string("FL")); printf("With \"FR\": %41d\n", av_channel_from_string("FR")); + printf("With \"ambisonic 0\": %32d\n", av_channel_from_string("ambisonic 0")); + printf("With \"ambisonic 1023\": %29d\n", av_channel_from_string("ambisonic 1023")); printf("\nTesting av_channel_layout_from_string\n"); CHANNEL_LAYOUT_FROM_STRING(surround, "0x3f"); diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout index 89d43f46f4..1a74216125 100644 --- a/tests/ref/fate/channel_layout +++ b/tests/ref/fate/channel_layout @@ -1,13 +1,19 @@ Testing av_channel_name With AV_CHAN_FRONT_LEFT: FL With AV_CHAN_FRONT_RIGHT: FR +With AV_CHAN_AMBISONIC_BASE: ambisonic 0 +With AV_CHAN_AMBISONIC_END: ambisonic 1023 Testing av_channel_description With AV_CHAN_FRONT_LEFT: front left With AV_CHAN_FRONT_RIGHT: front right +With AV_CHAN_AMBISONIC_BASE: ambisonic 0 +With AV_CHAN_AMBISONIC_END: ambisonic 1023 Testing av_channel_from_string With "FL": 0 With "FR": 1 +With "ambisonic 0": 1024 +With "ambisonic 1023": 2047 Testing av_channel_layout_from_string With "0x3f": 5.1 From patchwork Wed Dec 8 01:06:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32146 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7048453iog; Tue, 7 Dec 2021 17:13:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVLQ6b9M529XM30FNz6CLXGi/1whAXyis5FEgLyTNKqGcE9mn2xzwgG+4rhPodd9YK6dsU X-Received: by 2002:a05:6402:34d2:: with SMTP id w18mr9976929edc.35.1638926003548; Tue, 07 Dec 2021 17:13:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638926003; cv=none; d=google.com; s=arc-20160816; b=A8HVibEmmSHWW20webkFCZJG/J1FKwd/tiLI3Rle+QgmYseNVQSNHGXVW0h/xC87+e YZnChcxYoj/sabY4OOiSM61KEjH5M/KhoB62c/ABfOGO9fZqfgoPeOzJYDEedTgvnguj 8t7L5639rIJIQD4jojzZSoovfZcFN3bZlh3jHJF9hxA6bNs3XS8JgfVuxuSa4OI33VA6 RfMpQQvPFvWwkZcYQqhcPNyi3pEO42iVuWDi1df84e62NIvj62tvHLBQmX3ZYCmerQDu 7VFq5VmwP06xRxIWhGoJ1HjjUv9gT65cH0HBy8od9RNlDd/kewPe1H7mXWB+l1rb7oGR AEfw== 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=LDQ0bM9rbXsNkhDBQM5cxTFlkLCzOVBOdW+awqGAqBg=; b=K7X6Qu3DrHXJv1T+GGTQfAs9L25XhxerCOkRqhni5I/WVmYzIFEH9CMWffLbbGTC2w ZnWYKIEfVEdl2hsZjP6NnPDUeGYGvcO6gDFUllDRqvk5CXPNiZP15BiH3uZujWWD2hvo KbGruf64yYMX2kWeLWnzyWiEOm8xffeUgOlUIC1Nf1FOlXYc27ivr8KtVRw/JwSCqRK2 ho773hQkJn+ljqKBgnByzclQmv5k1pQqt4nxDkQBVdj4LmZPO9wFuqiNVvuJOREWaZn+ U8ulKABPFDI/MyXCE+KMmEpVc6BPgbDPU3cV5M43LvDpLvswIfkjD6N6YRCeMxiiCOQA Kbpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="JjR+/GKt"; 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 fy1si2217849ejc.786.2021.12.07.17.13.23; Tue, 07 Dec 2021 17:13: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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="JjR+/GKt"; 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 1B7A868AFA8; Wed, 8 Dec 2021 03:08:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A25268AF87 for ; Wed, 8 Dec 2021 03:08:10 +0200 (EET) Received: by mail-ua1-f41.google.com with SMTP id y5so1894848ual.7 for ; Tue, 07 Dec 2021 17:08:10 -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=gJyE2RZDBKN2Zczoktkgb5kkuD6ckLr76O5JzXS50To=; b=JjR+/GKtD4nLjMwka9jQUmFOUNo5lbU+QxgJyKMcG4ELqqNYxiRkDbmSarRslwXUvw hbezoj0HuqGZEMKh+2sfmAWdaBOgIW6mWwl/IdMMIkrS9w/yLGj2N//6hfSn1qRDGrxT SRtmekbCXuMADCJnmITgLVJLGgDxSVKVhR49tO4G3G8JbhbqU3pmn2JUU4+3QljLdQ5w N4Sljf1ksbjrV+O8nhnkt0MbRf2jrcQ9m8VinvgAtO/yZ8yxU/hvOr9ehSCuzkdq4kQt zBE4pEVFcZ4exzqYhkFT5drt+dfEkCMETtzyqute3HqiNq/TJdjZtdTXqhTXxVvv3qka CduA== 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=gJyE2RZDBKN2Zczoktkgb5kkuD6ckLr76O5JzXS50To=; b=wfIz5WpQtpqzClTyEf0hhBVC+f0QVrV+anG5XAPkIgp7t/+ep7i8Ve17a7fADKqhib LrQge9MLVELO9D4vUu4ZPSpKKme+FmiS4KUoKYYfciEkFG5G35MYiiylfsczmAMLcNXy 0X6lCnDc58rE14xDKNXCuP1UFihJ/1Ur9Af2gdLiWszsY3o+FE57zpp0iGIABaQX/pp5 DHMaMmj6lanv7X6BeEwW9VQ/sI38IyPg8C+D5uhphmta8XAKcRNsZMar80GzHwhdQ5t+ uyibSMy1hqz4uKnHFbL0Lpdhqtof1+qVF7qOMAif7DLVGlVneEd61o+Fr4FHaJPYOnnA eO/A== X-Gm-Message-State: AOAM530L/wNAsDcz08WP/I1GSd5V3p9T9JodhS+duC043jNt9Np8xViC /Tab1RxvM/KoKdRmRhLMQo+U29vH6DgKDd12 X-Received: by 2002:ab0:3c48:: with SMTP id u8mr4201901uaw.73.1638925688760; Tue, 07 Dec 2021 17:08:08 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:08 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:48 -0300 Message-Id: <20211208010649.381-33-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 278/279] opus: export mapping family 2 (Ambisonic) as Ambisonic layout 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: BovB7So3vfgt From: Anton Khirnov Signed-off-by: James Almer --- libavcodec/opus.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libavcodec/opus.c b/libavcodec/opus.c index 73cac74f96..4d89068025 100644 --- a/libavcodec/opus.c +++ b/libavcodec/opus.c @@ -398,8 +398,22 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, ret = AVERROR_INVALIDDATA; goto fail; } - layout.order = AV_CHANNEL_ORDER_UNSPEC; + layout.nb_channels = channels; + if (channels == (ambisonic_order + 1) * (ambisonic_order + 1)) { + layout.order = AV_CHANNEL_ORDER_AMBISONIC; + } else { + layout.order = AV_CHANNEL_ORDER_CUSTOM; + layout.u.map = av_mallocz_array(channels, sizeof(*layout.u.map)); + if (!layout.u.map) { + ret = AVERROR(ENOMEM); + goto fail; + } + for (i = 0; i < channels - 2; i++) + layout.u.map[i].id = AV_CHAN_AMBISONIC_BASE + i; + layout.u.map[channels - 2].id = AV_CHAN_FRONT_LEFT; + layout.u.map[channels - 1].id = AV_CHAN_FRONT_RIGHT; + } } else { layout.order = AV_CHANNEL_ORDER_UNSPEC; layout.nb_channels = channels; @@ -450,8 +464,10 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, } } - av_channel_layout_uninit(&avctx->ch_layout); - avctx->ch_layout = layout; + ret = av_channel_layout_copy(&avctx->ch_layout, &layout); + if (ret < 0) + goto fail; + s->nb_streams = streams; s->nb_stereo_streams = stereo_streams; From patchwork Wed Dec 8 01:06:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32128 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7048597iog; Tue, 7 Dec 2021 17:13:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbHFFULRJszr8+q2egTEpeisj41FtGHW+L25KKX8d9mfLExHO3JF3G7Tis/tZrXW0t45Zz X-Received: by 2002:a05:6402:35cc:: with SMTP id z12mr14090263edc.393.1638926013408; Tue, 07 Dec 2021 17:13:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638926013; cv=none; d=google.com; s=arc-20160816; b=aeW8E1z5v+1cK1NtOap2LbGmGEHL0Fq4ZHcztiN2eLMcjrwNzK+rhskYtU4gcRJ3vC mLp/ewo4lNT+SnZUMODrrGUhoNbVm1QNkqDSBzRsxzIRHYCPrOu7lxReI62NYSWKcp9O TZF42+BnSskCuI3KQP7EWcoIS3+nTZZ9bgze0mTLleI7XU6wg0lY68bLOaOi64Rj4a+z nT/8lXQHIX6MSbbJ5lZfrwkbTJZKOl7Aww42KeodHxvf8cymBrJ/VTx3ZeVdUNneQSJl vI+qsdAJpJCm1zhOHALVs0dQyMf9voMZNchMRPdoGpt1LpOv57YOykmDtJID+XrZhTVq U2iQ== 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=ZhZRl/Qkti49edm5ebLazIAEOd3o8ncOlBRCDXoeswg=; b=rath1Z/AxtbRpeTTHPuoOCtBqYHcbeaMSJ92vJMEgnU/R5/94TDEkQac/RuIEZYO2Y H+zXy9IYOZ6ECc8rbJlAuYT5a2NIxH8avSqStQTKBbWiL5nU33UXXoeLexeksb/dKI3K AMFC3QXjan9YgIk36+uoLH7fFV0S/16889DPN8i6wFf9T/1jt+jwJaonShi+q1Rfi2sC w9PRUH/7BsA08OysSpLQ9LQ/LI5GHv2Ia6iuCwDVlTWrjnspJdXFGnnSu4uwECt/qNvf 7m3DJn41Do7uPSo4az+HWOQHYUrqiAzsT/XdmfPb2ObHgjgs7BwD75tkY4szy4qfNV8b PTIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=bpB35XZA; 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 v8si1671593ejb.422.2021.12.07.17.13.33; Tue, 07 Dec 2021 17:13:33 -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=bpB35XZA; 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 E3ABC68AFAF; Wed, 8 Dec 2021 03:08:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8046A68AF67 for ; Wed, 8 Dec 2021 03:08:11 +0200 (EET) Received: by mail-ua1-f45.google.com with SMTP id i6so1904584uae.6 for ; Tue, 07 Dec 2021 17:08:11 -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=f/jOKmLHM0YotEe9tUU8hfnxVKuVPOt44SBECm/M67c=; b=bpB35XZAd4WvVFNC28LYi2KogjFXqgQAhikVxtLeCi5rAkXfw4Ui2aN5h3H87nGGKB uzCknXosWjw+fo6ZYf89Bu0sQ4JGLQKgDUqe68yfyPxHnACaBIqCQGynT+LG3fVooahY we01hLwWSYJnVZkpFCadcCA1y/1RQ9B7iztl261YAzJSpNYHFTf5dANcnlFdPzT1K7KO CEslu/Mqc86rmz8wI+H1K/Sa2r6Y2NPry02IPlgbh1lV1vXBUPl8+97QfBVhRG1ys7va 6/9+93nCfOpCZeN+6AUE7gIA/j+rVV5NFEpr0U3W8nrjdBSXjY34h+QgflPSNo4hLQWx U12w== 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=f/jOKmLHM0YotEe9tUU8hfnxVKuVPOt44SBECm/M67c=; b=YuRGARxCDYQDFnJUIcuJ2Sfy3pP8Mt3ZGAaN5hbz1THG45aA932SuUEOYUygSAZu63 IpPDsyfnWhh7QNcbVYfYGkb3o9VZ4ktax+zN4xbLhGOrdUPPW1MkJKOidBvicx7TQLE4 eiDmssPVOkaPuiYxXIHwy8kYQWF/qCK+hkdJqtOGNVzxWlfPtRhMlwQs+7pioH41GDyY Uf6Hd+2+pTbut+m+YdH6LwyyxwX8sSK/I79hUxhHc/4DfxVM4bot1muQIPhz2mVlnvBg 2P/jKLELzPep2hzXsfiA5UUMb1WFuGbYPfCCWOdSEry/Ni2QsYuPY16G6xhS3M7wcxQY vkSA== X-Gm-Message-State: AOAM530+UfSEf819jZ6nopi0jlxiiZv3xRvFycCk/4UD9aSaycim5FZE tyxVa4xtlPCNDGuYr8XwPoBLQ/Tz2s2+IBQ9 X-Received: by 2002:a67:cd8b:: with SMTP id r11mr49776737vsl.27.1638925690025; Tue, 07 Dec 2021 17:08:10 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:09 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:49 -0300 Message-Id: <20211208010649.381-34-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 279/279] mov: Implement spatial audio support 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: 54r1TMfOavXH From: Vittorio Giovara As defined by Google's Spatial Audio RFC. Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavformat/mov.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index b061659252..9bb126e028 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7223,6 +7223,100 @@ cleanup: return ret; } +static int mov_read_SA3D(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + int i, version, type; + int ambisonic_order, channel_order, normalization, channel_count; + + if (c->fc->nb_streams < 1) + return 0; + + st = c->fc->streams[c->fc->nb_streams - 1]; + + if (atom.size < 16) { + av_log(c->fc, AV_LOG_ERROR, "SA3D audio box too small\n"); + return AVERROR_INVALIDDATA; + } + + version = avio_r8(pb); + if (version) { + av_log(c->fc, AV_LOG_WARNING, "Unsupported SA3D box version %d\n", version); + return 0; + } + + type = avio_r8(pb); + if (type) { + av_log(c->fc, AV_LOG_WARNING, + "Unsupported ambisonic type %d\n", type); + return 0; + } + + ambisonic_order = avio_rb32(pb); + + channel_order = avio_r8(pb); + if (channel_order) { + av_log(c->fc, AV_LOG_WARNING, + "Unsupported channel_order %d\n", channel_order); + return 0; + } + + normalization = avio_r8(pb); + if (normalization) { + av_log(c->fc, AV_LOG_WARNING, + "Unsupported normalization %d\n", normalization); + return 0; + } + + channel_count = avio_rb32(pb); + if (channel_count != (ambisonic_order + 1) * (ambisonic_order + 1)) { + av_log(c->fc, AV_LOG_ERROR, + "Invalid number of channels (%d / %d)\n", + channel_count, ambisonic_order); + return 0; + } + + for (i = 0; i < channel_count; i++) { + if (i != avio_rb32(pb)) { + av_log(c->fc, AV_LOG_WARNING, + "Ambisonic channel reordering is not supported\n"); + return 0; + } + } + + av_channel_layout_uninit(&st->codecpar->ch_layout); + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_AMBISONIC; + st->codecpar->ch_layout.nb_channels = channel_count; + + return 0; +} + +static int mov_read_SAND(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + int version; + + if (c->fc->nb_streams < 1) + return 0; + + st = c->fc->streams[c->fc->nb_streams - 1]; + + if (atom.size < 5) { + av_log(c->fc, AV_LOG_ERROR, "Empty SAND audio box\n"); + return AVERROR_INVALIDDATA; + } + + version = avio_r8(pb); + if (version) { + av_log(c->fc, AV_LOG_WARNING, "Unsupported SAND box version %d\n", version); + return 0; + } + + st->disposition |= AV_DISPOSITION_NON_DIEGETIC; + + return 0; +} + static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('A','C','L','R'), mov_read_aclr }, { MKTAG('A','P','R','G'), mov_read_avid }, @@ -7322,6 +7416,8 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('d','v','v','C'), mov_read_dvcc_dvvc }, { MKTAG('d','v','w','C'), mov_read_dvcc_dvvc }, { MKTAG('k','i','n','d'), mov_read_kind }, +{ MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */ +{ MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */ { 0, NULL } };