[FFmpeg-devel] [PATCH 211/281] flac: convert to new channel layout API

Anton Khirnov anton at khirnov.net
Wed Feb 23 12:24:52 EET 2022


Quoting James Almer (2022-01-13 03:04:50)
> From: Anton Khirnov <anton at khirnov.net>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
> Signed-off-by: Anton Khirnov <anton at khirnov.net>
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  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)

Not sure why I wrote this check like this originally, now it seems
better to check for order != UNSPEC, so that a user-supplied custom
layout is preserved.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list