From patchwork Thu Jan 13 02:04:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33485 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp40218iog; Wed, 12 Jan 2022 18:39:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPZj9eLK4mYvhhUrW2PXqCc32+fy5AsWzDQTk3H5hoHCZ+1XbcT7pHEgzWDynfWam4ShGi X-Received: by 2002:a17:906:2a48:: with SMTP id k8mr2051739eje.758.1642041541140; Wed, 12 Jan 2022 18:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041541; cv=none; d=google.com; s=arc-20160816; b=IXh2zcoatv6LrmHd3+AeB2+LaFMF3FIxyXm8epXyjK4DZWcSrqHiIxvk1KWgEneHeH YoxXJCjyZQJGKorxamc61aW4laPMF0TiXGhASVoafH7GpCyU3Cin2y5hR64IjZokf7Y1 jW+ZJEjQ6I3JMzxf7YdRBMAgwpFZd5wa59Hw2apAZ0G5wNA9k9dWKNhXIQdlEh1y58hP /wRrJjKkoI1NpD78QzQGEYf3uGEoU5ejbNI6QAejU3YrJEo5Ew3JbFBgFktS+rOe6Ywf rScWX6pi1OIhh2806TH+pnntMLEecVytu9FZpOEpoFQH9VISxpkNNz15I1xbmpVPdNpC 9LBw== 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=n36PmPWdKDVw74bDiNgjHik2YuWDCBZHUiKquPwwoaA=; b=KJey9/LBKXdo9FphcDeN+hyI7ORDaJoSu/36eJQ3OtDlhkPYUww8CQ/03TzSW3q+NH EsUye47CWHl5gJF6wfizQz9c96uqAhvKcHxAAPsTCncp7MlQ12/LUxKySGACvNmgH4Q9 4StBKGZE8mydKb7qyBY9RYCQQux+gegGyZdDIt+xEdd69b3OZHAAE8GOwSoSLc7Gp21m SigFoBa1smLz7LeoMXul27DiWwm/swaPW5HerCTyNST7MTVNusAD5ElozlS6HXTNS7q5 /9sAIkY/7pWfciSM1tSQUxZ9RAI0utAinE5jBMiFaWK30y3ZoZ00qwhYvTb6K2NfvtrL aiaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=QGVLr8zP; 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 gn40si761321ejc.205.2022.01.12.18.39.00; Wed, 12 Jan 2022 18:39: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=QGVLr8zP; 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 CD24468B808; Thu, 13 Jan 2022 04:05:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59FC468B800 for ; Thu, 13 Jan 2022 04:05:34 +0200 (EET) Received: by mail-qt1-f173.google.com with SMTP id c10so5396692qte.2 for ; Wed, 12 Jan 2022 18:05: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=Juu0qMcUIcxKyi38eueXnq39CyQrFSolie0VHKZ/aZQ=; b=QGVLr8zPXodY0IRNtugsq49XclDWxojq3vYGg9HKqePdiLtMxkWbSoslGMAI3Nj828 KuBosQT949b0UUf8yuOTAVqsBlOmIIic+BXB8rsgmhXV3bSKn1p6CMO0d7ywZS2/KYV2 uPIsjMZ+Q/jQwHnV++uSqB32BzZEUBA9My6CCTikQuXLlYbkL4yHrr9oyTIsuoX9InLz mRuD0tOxsmvHP6NLDcr3mx7yyeaUK65jvpsRpvtPq7R/Mk808AFx61BDbEEXt0hmkRmG MRBnLM21ERZEZ7dZQfZU/KBHvGD75+KJPVS3ClfNtc3TrD00XBdh/Mzx4ptkKpRCNuWn Gvig== 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=Juu0qMcUIcxKyi38eueXnq39CyQrFSolie0VHKZ/aZQ=; b=pUDOJwIskpv1AZ9VWuMNxRG2oMCTw7oHTvj5T8kwFL36APJrsfOUrDZnfh2cyJgvyH EdjoU1kGvJrwcTpMz6+EXBKvPVLuOVjvm+Hr7lDEosKIVr1IBwweDIhra+RWb3CGTQrJ sWUjoDQohK8X2IqjOTFNFyLE4LRUrCHrTpwW6GfZaY3VX2WGJ74Uw7XvqwhDbBQ15hTv hHrLDmvYtTtRyOTbnzUm6UEsqtQWrj8VmJMHDuTNHh0HDxsvgJaWOva8ptposMVFsmnU sO6GvZxwpoDm4Q+DqkzQKI1ZhUsJD2dxG3ydn8ucpGJTpt2OdGtDQprXdMSERXq8rgPx XzFw== X-Gm-Message-State: AOAM531JgLqzH1oPQCNzAIs6Qgz5LYnQilSfy63tV/iEM+3Fu+RsaBN0 6jTdYLFcurCFgXhxBHGfTXGdLDeV8mY= X-Received: by 2002:ac8:598b:: with SMTP id e11mr2043988qte.522.1642039532901; Wed, 12 Jan 2022 18:05:32 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id k9sm1264556qko.29.2022.01.12.18.05.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:05:32 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:04:50 -0300 Message-Id: <20220113020518.730-2-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 211/281] flac: 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: cg7tuvrA0LsJ From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/flac.c | 39 +++++++++++++++++++++------------------ libavcodec/flac.h | 2 +- libavcodec/flac_parser.c | 7 ++----- libavcodec/flacdec.c | 9 ++++----- libavcodec/flacenc.c | 26 +++++++++++++------------- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/libavcodec/flac.c b/libavcodec/flac.c index 7b075d4bd3..51014faea1 100644 --- a/libavcodec/flac.c +++ b/libavcodec/flac.c @@ -29,15 +29,15 @@ static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 }; -static const uint64_t flac_channel_layouts[8] = { - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_SURROUND, - AV_CH_LAYOUT_QUAD, - AV_CH_LAYOUT_5POINT0, - AV_CH_LAYOUT_5POINT1, - AV_CH_LAYOUT_6POINT1, - AV_CH_LAYOUT_7POINT1 +static const AVChannelLayout flac_channel_layouts[8] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_QUAD, + AV_CHANNEL_LAYOUT_5POINT0, + AV_CHANNEL_LAYOUT_5POINT1, + AV_CHANNEL_LAYOUT_6POINT1, + AV_CHANNEL_LAYOUT_7POINT1 }; static int64_t get_utf8(GetBitContext *gb) @@ -193,12 +193,19 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx, return 1; } -void ff_flac_set_channel_layout(AVCodecContext *avctx) +void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels) { - if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts)) - avctx->channel_layout = flac_channel_layouts[avctx->channels - 1]; + if (channels == avctx->ch_layout.nb_channels && + avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && + avctx->ch_layout.u.mask) + return; + + av_channel_layout_uninit(&avctx->ch_layout); + if (channels <= FF_ARRAY_ELEMS(flac_channel_layouts)) + avctx->ch_layout = flac_channel_layouts[channels - 1]; else - avctx->channel_layout = 0; + avctx->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC, + .nb_channels = channels }; } int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, @@ -229,13 +236,9 @@ int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, return AVERROR_INVALIDDATA; } - avctx->channels = s->channels; avctx->sample_rate = s->samplerate; avctx->bits_per_raw_sample = s->bps; - - if (!avctx->channel_layout || - av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) - ff_flac_set_channel_layout(avctx); + ff_flac_set_channel_layout(avctx, s->channels); s->samples = get_bits64(&gb, 36); diff --git a/libavcodec/flac.h b/libavcodec/flac.h index 991ab43f3c..cb220ab4c0 100644 --- a/libavcodec/flac.h +++ b/libavcodec/flac.h @@ -131,7 +131,7 @@ int ff_flac_get_max_frame_size(int blocksize, int ch, int bps); int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, FLACFrameInfo *fi, int log_level_offset); -void ff_flac_set_channel_layout(AVCodecContext *avctx); +void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels); /** * Parse the metadata block parameters from the header. diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c index cd9a2cb574..81b6f12ab3 100644 --- a/libavcodec/flac_parser.c +++ b/libavcodec/flac_parser.c @@ -628,11 +628,8 @@ static int get_best_header(FLACParseContext *fpc, const uint8_t **poutbuf, check_header_mismatch(fpc, header, child, 0); } - if (header->fi.channels != fpc->avctx->channels || - !fpc->avctx->channel_layout) { - fpc->avctx->channels = header->fi.channels; - ff_flac_set_channel_layout(fpc->avctx); - } + ff_flac_set_channel_layout(fpc->avctx, header->fi.channels); + fpc->avctx->sample_rate = header->fi.samplerate; fpc->pc->duration = header->fi.blocksize; *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size, diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index 09051cc663..eaa2dc6cf1 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -483,15 +483,14 @@ static int decode_frame(FLACContext *s) if ( s->flac_stream_info.channels && fi.channels != s->flac_stream_info.channels && s->got_streaminfo) { - s->flac_stream_info.channels = s->avctx->channels = fi.channels; - ff_flac_set_channel_layout(s->avctx); + s->flac_stream_info.channels = fi.channels; + ff_flac_set_channel_layout(s->avctx, fi.channels); ret = allocate_buffers(s); if (ret < 0) return ret; } - s->flac_stream_info.channels = s->avctx->channels = fi.channels; - if (!s->avctx->channel_layout) - ff_flac_set_channel_layout(s->avctx); + s->flac_stream_info.channels = fi.channels; + ff_flac_set_channel_layout(s->avctx, fi.channels); s->ch_mode = fi.ch_mode; if (!s->flac_stream_info.bps && !fi.bps) { diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 9f6f449323..0912ca2f47 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -241,7 +241,7 @@ static av_cold void dprint_compression_options(FlacEncodeContext *s) static av_cold int flac_encode_init(AVCodecContext *avctx) { int freq = avctx->sample_rate; - int channels = avctx->channels; + int channels = avctx->ch_layout.nb_channels; FlacEncodeContext *s = avctx->priv_data; int i, level, ret; uint8_t *streaminfo; @@ -398,18 +398,18 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) s->frame_count = 0; s->min_framesize = s->max_framesize; - if (channels == 3 && - avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) || - channels == 4 && - avctx->channel_layout != AV_CH_LAYOUT_2_2 && - avctx->channel_layout != AV_CH_LAYOUT_QUAD || - channels == 5 && - avctx->channel_layout != AV_CH_LAYOUT_5POINT0 && - avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK || - channels == 6 && - avctx->channel_layout != AV_CH_LAYOUT_5POINT1 && - avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK) { - if (avctx->channel_layout) { + if ((channels == 3 && + av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND)) || + (channels == 4 && + av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2) && + av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD)) || + (channels == 5 && + av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0) && + av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) || + (channels == 6 && + av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1) && + av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK))) { + if (avctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, " "output stream will have incorrect " "channel layout.\n");