Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it
@ 2022-09-18 20:15 Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 02/17] avcodec/encode: Remove dead deprecated check Andreas Rheinhardt
                   ` (16 more replies)
  0 siblings, 17 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:15 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Otherwise, there might be leaks.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/avcodec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 29643199be..a165cdea95 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -235,6 +235,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
     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) {
             av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
         } else {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 02/17] avcodec/encode: Remove dead deprecated check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 03/17] avcodec/avcodec: Check for more invalid channel layouts Andreas Rheinhardt
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

The wrapper for the legacy channel layout API already sets
AVCodecContext.channels based upon AVCodecContext.channel_layout
if the latter is set while the former is unset.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/encode.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index ade4d458e7..2168b88ea8 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -629,8 +629,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
                    buf, channels, avctx->channels);
             return AVERROR(EINVAL);
         }
-    } else if (avctx->channel_layout) {
-        avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
     }
     if (avctx->channels < 0) {
         av_log(avctx, AV_LOG_ERROR, "Specified number of channels %d is not supported\n",
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 03/17] avcodec/avcodec: Check for more invalid channel layouts
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 02/17] avcodec/encode: Remove dead deprecated check Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-20 22:47   ` James Almer
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 04/17] avcodec/avcodec: Always use old channel count/layout if set Andreas Rheinhardt
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

In particular, check the provided channel layout for encoders
without AVCodec.ch_layouts set. This fixes an infinite loop
in the WavPack encoder (and maybe other issues in other encoders
as well) in case the channel count is zero.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/avcodec.c | 11 +++++++++++
 libavcodec/decode.c  |  5 -----
 libavcodec/encode.c  |  5 -----
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a165cdea95..96b69e0a17 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -246,6 +246,17 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
+    if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels
+        && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
+        av_log(avctx, AV_LOG_ERROR, "Codec requires channel layout to be set\n");
+        ret = AVERROR(EINVAL);
+        goto free_and_end;
+    }
+    if (avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
+        ret = AVERROR(EINVAL);
+        goto free_and_end;
+    }
     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);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 2961705c9d..6be2d3d6ed 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1595,11 +1595,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-    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);
-    }
     if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
         av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
                avctx->codec->max_lowres);
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 2168b88ea8..92e8337227 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -600,11 +600,6 @@ static int encode_preinit_audio(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
     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;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 04/17] avcodec/avcodec: Always use old channel count/layout if set
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 02/17] avcodec/encode: Remove dead deprecated check Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 03/17] avcodec/avcodec: Check for more invalid channel layouts Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 05/17] avcodec/encode: Remove deprecated always-false checks Andreas Rheinhardt
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This ensures that if AVCodecContext.channels or
AVCodecContext.channel_layout are set, AVCodecContext.ch_layout
has the equivalent values after this block.

(In case these values are set inconsistently, the consistency check
for ch_layout below will error out.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/avcodec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 96b69e0a17..754c21c97a 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -232,7 +232,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
     if (avctx->channel_layout && !avctx->channels)
         avctx->channels = av_popcount64(avctx->channel_layout);
 
-    if ((avctx->channels > 0 && avctx->ch_layout.nb_channels != avctx->channels) ||
+    if ((avctx->channels && 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);
@@ -240,8 +240,8 @@ FF_DISABLE_DEPRECATION_WARNINGS
             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;
         }
+        avctx->ch_layout.nb_channels = avctx->channels;
     }
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 05/17] avcodec/encode: Remove deprecated always-false checks
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (2 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 04/17] avcodec/avcodec: Always use old channel count/layout if set Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 06/17] avcodec/dfpwmdec: Remove always-false check Andreas Rheinhardt
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Now that it is ensured that the old and new channel count/layout
values coincide if the old ones are set, the consistency of the
AVChannelLayout (which is checked before we reach this point)
implies the consistency of the old values, making these checks
here dead code. So remove them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/encode.c | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 92e8337227..d1edce9edc 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -612,26 +612,6 @@ static int encode_preinit_audio(AVCodecContext *avctx)
             return AVERROR(EINVAL);
         }
     }
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-    if (avctx->channel_layout && avctx->channels) {
-        int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
-        if (channels != avctx->channels) {
-            char buf[512];
-            av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
-            av_log(avctx, AV_LOG_ERROR,
-                   "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
-                   buf, channels, avctx->channels);
-            return AVERROR(EINVAL);
-        }
-    }
-    if (avctx->channels < 0) {
-        av_log(avctx, AV_LOG_ERROR, "Specified number of channels %d is not supported\n",
-                avctx->channels);
-        return AVERROR(EINVAL);
-    }
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
 
     if (!avctx->bits_per_raw_sample)
         avctx->bits_per_raw_sample = 8 * av_get_bytes_per_sample(avctx->sample_fmt);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 06/17] avcodec/dfpwmdec: Remove always-false check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (3 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 05/17] avcodec/encode: Remove deprecated always-false checks Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 07/17] avcodec/pcm-blurayenc: Don't presume every channel layout to be native Andreas Rheinhardt
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This decoder does not have the AV_CODEC_CAP_CHANNEL_CONF set,
so that number of channels has to be set by the user before
avcodec_open2().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/dfpwmdec.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/libavcodec/dfpwmdec.c b/libavcodec/dfpwmdec.c
index 532a955b4c..4ddb806561 100644
--- a/libavcodec/dfpwmdec.c
+++ b/libavcodec/dfpwmdec.c
@@ -85,11 +85,6 @@ static av_cold int dfpwm_dec_init(struct AVCodecContext *ctx)
 {
     DFPWMState *state = ctx->priv_data;
 
-    if (ctx->ch_layout.nb_channels <= 0) {
-        av_log(ctx, AV_LOG_ERROR, "Invalid number of channels\n");
-        return AVERROR(EINVAL);
-    }
-
     state->fq = 0;
     state->q = 0;
     state->s = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 07/17] avcodec/pcm-blurayenc: Don't presume every channel layout to be native
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (4 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 06/17] avcodec/dfpwmdec: Remove always-false check Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 08/17] avcodec/pcm: Remove always-false check Andreas Rheinhardt
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

The pcm_bluray encoder has AVCodec.ch_layouts set, so that
ff_encode_preinit() checks that the channel layout in use
is equivalent to one of the layouts from AVCodec.ch_layouts.
Yet equivalent is not the same as identical; in particular,
custom layouts equivalent to native layouts are possible
(and necessary if one wants to use the name/opaque fields
with an ordinary channel layout), so one must not simply
use AVChannelLayout.u.mask. Use av_channel_layout_subset()
instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/pcm-blurayenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/pcm-blurayenc.c b/libavcodec/pcm-blurayenc.c
index 1f1a3a27d8..03ed88b8ae 100644
--- a/libavcodec/pcm-blurayenc.c
+++ b/libavcodec/pcm-blurayenc.c
@@ -63,7 +63,7 @@ static av_cold int pcm_bluray_encode_init(AVCodecContext *avctx)
         return AVERROR_BUG;
     }
 
-    switch (avctx->ch_layout.u.mask) {
+    switch (av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0)) {
     case AV_CH_LAYOUT_MONO:
         ch_layout = 1;
         break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 08/17] avcodec/pcm: Remove always-false check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (5 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 07/17] avcodec/pcm-blurayenc: Don't presume every channel layout to be native Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 09/17] avcodec/libcodec2: Remove dead channel count check Andreas Rheinhardt
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

None of the decoders here have the AV_CODEC_CAP_CHANNEL_CONF set,
so that it is already checked generically that the number of channels
is positive.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/pcm.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index fcb8ae1c2c..ee36a364c8 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -254,11 +254,6 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
     AVFloatDSPContext *fdsp;
     int i;
 
-    if (avctx->ch_layout.nb_channels <= 0) {
-        av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
-        return AVERROR(EINVAL);
-    }
-
     switch (avctx->codec_id) {
     case AV_CODEC_ID_PCM_ALAW:
         for (i = 0; i < 256; i++)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 09/17] avcodec/libcodec2: Remove dead channel count check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (6 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 08/17] avcodec/pcm: Remove always-false check Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-21 13:31   ` Tomas Härdin
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 10/17] avcodec/libshine: " Andreas Rheinhardt
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This encoder has AVCodec.ch_layouts set, so that this is checked
generically.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libcodec2.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/libcodec2.c b/libavcodec/libcodec2.c
index be9677ddeb..581ef04ce2 100644
--- a/libavcodec/libcodec2.c
+++ b/libavcodec/libcodec2.c
@@ -105,7 +105,6 @@ static av_cold int libcodec2_init_encoder(AVCodecContext *avctx)
 
     //will need to be smarter once we get wideband support
     if (avctx->sample_rate != 8000 ||
-        avctx->ch_layout.nb_channels != 1 ||
         avctx->sample_fmt != AV_SAMPLE_FMT_S16) {
         av_log(avctx, AV_LOG_ERROR, "only 8 kHz 16-bit mono allowed\n");
         return AVERROR(EINVAL);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 10/17] avcodec/libshine: Remove dead channel count check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (7 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 09/17] avcodec/libcodec2: Remove dead channel count check Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 11/17] avcodec/libspeexenc: " Andreas Rheinhardt
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This encoder has AVCodec.ch_layouts set, so that this is checked
generically.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libshine.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/libavcodec/libshine.c b/libavcodec/libshine.c
index 621c57816a..e266229f03 100644
--- a/libavcodec/libshine.c
+++ b/libavcodec/libshine.c
@@ -44,11 +44,6 @@ static av_cold int libshine_encode_init(AVCodecContext *avctx)
 {
     SHINEContext *s = avctx->priv_data;
 
-    if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > 2){
-        av_log(avctx, AV_LOG_ERROR, "only mono or stereo is supported\n");
-        return AVERROR(EINVAL);
-    }
-
     shine_set_config_mpeg_defaults(&s->config.mpeg);
     if (avctx->bit_rate)
         s->config.mpeg.bitr = avctx->bit_rate / 1000;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 11/17] avcodec/libspeexenc: Remove dead channel count check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (8 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 10/17] avcodec/libshine: " Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 12/17] avcodec/mpegaudioenc_template: " Andreas Rheinhardt
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This encoder has AVCodec.ch_layouts set, so that this is checked
generically.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libspeexenc.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index 8d2c6347fa..2191e7dac7 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -152,13 +152,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
     int header_size;
     int32_t complexity;
 
-    /* channels */
-    if (channels < 1 || channels > 2) {
-        av_log(avctx, AV_LOG_ERROR, "Invalid channels (%d). Only stereo and "
-               "mono are supported\n", channels);
-        return AVERROR(EINVAL);
-    }
-
     /* sample rate and encoding mode */
     switch (avctx->sample_rate) {
     case  8000: mode = speex_lib_get_mode(SPEEX_MODEID_NB);  break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 12/17] avcodec/mpegaudioenc_template: Remove dead channel count check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (9 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 11/17] avcodec/libspeexenc: " Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 13/17] avcodec/mlpenc: Fix channel layouts Andreas Rheinhardt
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

The encoders using this have AVCodec.ch_layouts set, so that
this is checked generically.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpegaudioenc_template.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/libavcodec/mpegaudioenc_template.c b/libavcodec/mpegaudioenc_template.c
index 67b8069102..396e8a4899 100644
--- a/libavcodec/mpegaudioenc_template.c
+++ b/libavcodec/mpegaudioenc_template.c
@@ -82,10 +82,6 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
     int i, v, table;
     float a;
 
-    if (channels <= 0 || channels > 2){
-        av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels);
-        return AVERROR(EINVAL);
-    }
     bitrate = bitrate / 1000;
     s->nb_channels = channels;
     avctx->frame_size = MPA_FRAME_SIZE;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 13/17] avcodec/mlpenc: Fix channel layouts
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (10 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 12/17] avcodec/mpegaudioenc_template: " Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-21  7:13   ` Paul B Mahol
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 14/17] avcodec/mlpenc: Simplify channel layout comparisons Andreas Rheinhardt
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

The encoder actually creates files with side channels, not back
channels. See thd_layout in mlp_parse.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mlpenc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index b66f3a3067..463332593f 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -628,14 +628,14 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
             ctx->channel_arrangement = 1;
             ctx->thd_substream_info  = 0x14;
         } else if (!av_channel_layout_compare(&avctx->ch_layout,
-                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) {
+                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) {
             ctx->ch_modifier_thd0    = 1;
             ctx->ch_modifier_thd1    = 1;
             ctx->ch_modifier_thd2    = 1;
             ctx->channel_arrangement = 11;
             ctx->thd_substream_info  = 0x104;
         } else if (!av_channel_layout_compare(&avctx->ch_layout,
-                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK)) {
+                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) {
             ctx->ch_modifier_thd0    = 2;
             ctx->ch_modifier_thd1    = 1;
             ctx->ch_modifier_thd2    = 2;
@@ -2277,13 +2277,13 @@ const FFCodec ff_truehd_encoder = {
     .p.sample_fmts          = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE},
     .p.supported_samplerates = (const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
 #if FF_API_OLD_CHANNEL_LAYOUT
-    .p.channel_layouts      = (const uint64_t[]) {AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_5POINT1_BACK, 0},
+    .p.channel_layouts      = (const uint64_t[]) { AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1, 0 },
 #endif
     .p.ch_layouts           = (const AVChannelLayout[]) {
                                   AV_CHANNEL_LAYOUT_MONO,
                                   AV_CHANNEL_LAYOUT_STEREO,
-                                  AV_CHANNEL_LAYOUT_5POINT0_BACK,
-                                  AV_CHANNEL_LAYOUT_5POINT1_BACK,
+                                  AV_CHANNEL_LAYOUT_5POINT0,
+                                  AV_CHANNEL_LAYOUT_5POINT1,
                                   { 0 }
                               },
     .caps_internal          = FF_CODEC_CAP_INIT_CLEANUP,
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 14/17] avcodec/mlpenc: Simplify channel layout comparisons
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (11 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 13/17] avcodec/mlpenc: Fix channel layouts Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-21  7:15   ` Paul B Mahol
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 15/17] avcodec/mlpenc: Remove dead channel layout checks Andreas Rheinhardt
                   ` (3 subsequent siblings)
  16 siblings, 1 reply; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

These encoders have AVCodec.ch_layouts set, so ff_encode_preinit()
has already checked that the used channel layout is equivalent
to one of these native layouts. Therefore one can simply
compare the channel masks (with the added complication
that one has to use av_channel_layout_subset() to get it,
because the channel layout is not guaranteed to have
AV_CHANNEL_ORDER_NATIVE).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mlpenc.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index 463332593f..d2e28888f7 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -480,6 +480,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
     static AVOnce init_static_once = AV_ONCE_INIT;
     MLPEncodeContext *ctx = avctx->priv_data;
     RestartHeader *const rh = &ctx->restart_header;
+    uint64_t channels_present;
     unsigned int sum = 0;
     size_t size;
     int ret;
@@ -589,19 +590,20 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
 
     ctx->num_substreams = 1; // TODO: change this after adding multi-channel support for TrueHD
 
+    channels_present = av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0);
     if (ctx->avctx->codec_id == AV_CODEC_ID_MLP) {
-        static const AVChannelLayout layout_arrangement[] = {
-            AV_CHANNEL_LAYOUT_MONO,         AV_CHANNEL_LAYOUT_STEREO,
-            AV_CHANNEL_LAYOUT_2_1,          AV_CHANNEL_LAYOUT_QUAD,
-            AV_CHANNEL_LAYOUT_2POINT1,      { 0 }, { 0 },
-            AV_CHANNEL_LAYOUT_SURROUND,     AV_CHANNEL_LAYOUT_4POINT0,
-            AV_CHANNEL_LAYOUT_5POINT0_BACK, AV_CHANNEL_LAYOUT_3POINT1,
-            AV_CHANNEL_LAYOUT_4POINT1,      AV_CHANNEL_LAYOUT_5POINT1_BACK,
+        static const uint64_t layout_arrangement[] = {
+            AV_CH_LAYOUT_MONO,         AV_CH_LAYOUT_STEREO,
+            AV_CH_LAYOUT_2_1,          AV_CH_LAYOUT_QUAD,
+            AV_CH_LAYOUT_2POINT1,      0, 0,
+            AV_CH_LAYOUT_SURROUND,     AV_CH_LAYOUT_4POINT0,
+            AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_3POINT1,
+            AV_CH_LAYOUT_4POINT1,      AV_CH_LAYOUT_5POINT1_BACK,
         };
         int i;
 
         for (i = 0; i < FF_ARRAY_ELEMS(layout_arrangement); i++)
-            if (!av_channel_layout_compare(&avctx->ch_layout, &layout_arrangement[i]))
+            if (channels_present == layout_arrangement[i])
                 break;
         if (i == FF_ARRAY_ELEMS(layout_arrangement)) {
             av_log(avctx, AV_LOG_ERROR, "Unsupported channel arrangement\n");
@@ -613,29 +615,25 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
         ctx->summary_info      = ff_mlp_ch_info[ctx->channel_arrangement].summary_info     ;
     } else {
         /* TrueHD */
-        if (!av_channel_layout_compare(&avctx->ch_layout,
-                                       &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) {
+        if (channels_present == AV_CH_LAYOUT_MONO) {
             ctx->ch_modifier_thd0    = 3;
             ctx->ch_modifier_thd1    = 3;
             ctx->ch_modifier_thd2    = 3;
             ctx->channel_arrangement = 2;
             ctx->thd_substream_info  = 0x14;
-        } else if (!av_channel_layout_compare(&avctx->ch_layout,
-                                       &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) {
+        } else if (channels_present == AV_CH_LAYOUT_STEREO) {
             ctx->ch_modifier_thd0    = 1;
             ctx->ch_modifier_thd1    = 1;
             ctx->ch_modifier_thd2    = 1;
             ctx->channel_arrangement = 1;
             ctx->thd_substream_info  = 0x14;
-        } else if (!av_channel_layout_compare(&avctx->ch_layout,
-                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) {
+        } else if (channels_present == AV_CH_LAYOUT_5POINT0) {
             ctx->ch_modifier_thd0    = 1;
             ctx->ch_modifier_thd1    = 1;
             ctx->ch_modifier_thd2    = 1;
             ctx->channel_arrangement = 11;
             ctx->thd_substream_info  = 0x104;
-        } else if (!av_channel_layout_compare(&avctx->ch_layout,
-                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) {
+        } else if (channels_present == AV_CH_LAYOUT_5POINT1) {
             ctx->ch_modifier_thd0    = 2;
             ctx->ch_modifier_thd1    = 1;
             ctx->ch_modifier_thd2    = 2;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 15/17] avcodec/mlpenc: Remove dead channel layout checks
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (12 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 14/17] avcodec/mlpenc: Simplify channel layout comparisons Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-21  7:14   ` Paul B Mahol
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 16/17] avcodec/dcaenc: Remove dead checks for unspec channel layouts Andreas Rheinhardt
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

ff_encode_preinit() has already checked that the channel layout
is equivalent to one of the layouts in AVCodec.ch_layouts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mlpenc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index d2e28888f7..878c5aedc1 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -27,6 +27,7 @@
 #include "encode.h"
 #include "put_bits.h"
 #include "audio_frame_queue.h"
+#include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/crc.h"
 #include "libavutil/avstring.h"
@@ -602,12 +603,11 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
         };
         int i;
 
-        for (i = 0; i < FF_ARRAY_ELEMS(layout_arrangement); i++)
+        for (i = 0;; i++) {
+            av_assert1(i < FF_ARRAY_ELEMS(layout_arrangement) ||
+                       !"Impossible channel layout");
             if (channels_present == layout_arrangement[i])
                 break;
-        if (i == FF_ARRAY_ELEMS(layout_arrangement)) {
-            av_log(avctx, AV_LOG_ERROR, "Unsupported channel arrangement\n");
-            return AVERROR(EINVAL);
         }
         ctx->channel_arrangement = i;
         ctx->flags = FLAGS_DVDA;
@@ -640,8 +640,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
             ctx->channel_arrangement = 15;
             ctx->thd_substream_info  = 0x104;
         } else {
-            av_log(avctx, AV_LOG_ERROR, "Unsupported channel arrangement\n");
-            return AVERROR(EINVAL);
+            av_assert1(!"AVCodec.ch_layouts needs to be updated");
         }
         ctx->flags = 0;
         ctx->channel_occupancy = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 16/17] avcodec/dcaenc: Remove dead checks for unspec channel layouts
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (13 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 15/17] avcodec/mlpenc: Remove dead channel layout checks Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 17/17] avcodec/dcaenc: Simplify channel layout check Andreas Rheinhardt
  2022-09-20 22:15 ` [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This encoder has AVCodec.ch_layouts set, so ff_encode_preinit()
ensures that the used channel layout is equivalent to one of
these.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
The new channel layout API is more stricter wrt these checks than the
old one; the old one let you pass if channels was set and channel_layout
unset. If this was not intended (or only semi-intended), then setting
the channel layout based upon channel count should IMO be done
generically in ff_encode_preinit().

 libavcodec/dcaenc.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index d0de6d3eee..0996296d8c 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -222,13 +222,6 @@ static int encode_init(AVCodecContext *avctx)
     if (ff_dcaadpcm_init(&c->adpcm_ctx))
         return AVERROR(ENOMEM);
 
-    if (layout.order == AV_CHANNEL_ORDER_UNSPEC) {
-        av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
-                                      "encoder will guess the layout, but it "
-                                      "might be incorrect.\n");
-        av_channel_layout_default(&layout, layout.nb_channels);
-    }
-
     if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
         c->channel_config = 0;
     else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO))
@@ -239,10 +232,6 @@ static int encode_init(AVCodecContext *avctx)
         c->channel_config = 9;
     else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
         c->channel_config = 9;
-    else {
-        av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout!\n");
-        return AVERROR_PATCHWELCOME;
-    }
 
     if (c->lfe_channel) {
         c->fullband_channels--;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [FFmpeg-devel] [PATCH 17/17] avcodec/dcaenc: Simplify channel layout check
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (14 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 16/17] avcodec/dcaenc: Remove dead checks for unspec channel layouts Andreas Rheinhardt
@ 2022-09-18 20:27 ` Andreas Rheinhardt
  2022-09-20 22:15 ` [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-18 20:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

ff_encode_preinit() ensures that the channel layout is equivalent
to one of the channel layouts in AVCodec.ch_layout; given that
all of these channel layouts have distinct numbers of channels,
one can therefore uniquely determine the channel layout by
the number of channels.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/dcaenc.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 0996296d8c..46618c13f9 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -222,16 +222,25 @@ static int encode_init(AVCodecContext *avctx)
     if (ff_dcaadpcm_init(&c->adpcm_ctx))
         return AVERROR(ENOMEM);
 
-    if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
+    switch (layout.nb_channels) {
+    case 1: /* mono */
         c->channel_config = 0;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO))
+        break;
+    case 2: /* stereo */
         c->channel_config = 2;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2))
+        break;
+    case 4: /* 2.2 */
         c->channel_config = 8;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
+        break;
+    case 5: /* 5.0 */
         c->channel_config = 9;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
+        break;
+    case 6: /* 5.1 */
         c->channel_config = 9;
+        break;
+    default:
+        av_assert1(!"impossible channel layout");
+    }
 
     if (c->lfe_channel) {
         c->fullband_channels--;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it
  2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
                   ` (15 preceding siblings ...)
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 17/17] avcodec/dcaenc: Simplify channel layout check Andreas Rheinhardt
@ 2022-09-20 22:15 ` Andreas Rheinhardt
  16 siblings, 0 replies; 23+ messages in thread
From: Andreas Rheinhardt @ 2022-09-20 22:15 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> Otherwise, there might be leaks.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/avcodec.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index 29643199be..a165cdea95 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -235,6 +235,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
>      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) {
>              av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
>          } else {

Will apply this patchset tomorrow unless there are objections.

- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [FFmpeg-devel] [PATCH 03/17] avcodec/avcodec: Check for more invalid channel layouts
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 03/17] avcodec/avcodec: Check for more invalid channel layouts Andreas Rheinhardt
@ 2022-09-20 22:47   ` James Almer
  0 siblings, 0 replies; 23+ messages in thread
From: James Almer @ 2022-09-20 22:47 UTC (permalink / raw)
  To: ffmpeg-devel

On 9/18/2022 5:27 PM, Andreas Rheinhardt wrote:
> In particular, check the provided channel layout for encoders
> without AVCodec.ch_layouts set. This fixes an infinite loop
> in the WavPack encoder (and maybe other issues in other encoders
> as well) in case the channel count is zero.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>   libavcodec/avcodec.c | 11 +++++++++++
>   libavcodec/decode.c  |  5 -----
>   libavcodec/encode.c  |  5 -----
>   3 files changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index a165cdea95..96b69e0a17 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -246,6 +246,17 @@ FF_DISABLE_DEPRECATION_WARNINGS
>   FF_ENABLE_DEPRECATION_WARNINGS
>   #endif
>   
> +    if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels
> +        && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {

nit: Might be a good idea to add a comment that this decoder-only flag 
is being checked here even for encoders as it will be a no-op for those.

> +        av_log(avctx, AV_LOG_ERROR, "Codec requires channel layout to be set\n");

const char *codec_string = av_codec_is_encoder(codec) ? "Encoder" : 
"Decoder";
av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n", 
codec_string);

> +        ret = AVERROR(EINVAL);
> +        goto free_and_end;
> +    }
> +    if (avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) {
> +        av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
> +        ret = AVERROR(EINVAL);
> +        goto free_and_end;
> +    }
>       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);
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 2961705c9d..6be2d3d6ed 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -1595,11 +1595,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
>   FF_ENABLE_DEPRECATION_WARNINGS
>   #endif
>   
> -    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);
> -    }
>       if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
>           av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
>                  avctx->codec->max_lowres);
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index 2168b88ea8..92e8337227 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -600,11 +600,6 @@ static int encode_preinit_audio(AVCodecContext *avctx)
>           return AVERROR(EINVAL);
>       }
>       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;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [FFmpeg-devel] [PATCH 13/17] avcodec/mlpenc: Fix channel layouts
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 13/17] avcodec/mlpenc: Fix channel layouts Andreas Rheinhardt
@ 2022-09-21  7:13   ` Paul B Mahol
  0 siblings, 0 replies; 23+ messages in thread
From: Paul B Mahol @ 2022-09-21  7:13 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt

On 9/18/22, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
> The encoder actually creates files with side channels, not back
> channels. See thd_layout in mlp_parse.h.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mlpenc.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>

lgtm

> diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
> index b66f3a3067..463332593f 100644
> --- a/libavcodec/mlpenc.c
> +++ b/libavcodec/mlpenc.c
> @@ -628,14 +628,14 @@ static av_cold int mlp_encode_init(AVCodecContext
> *avctx)
>              ctx->channel_arrangement = 1;
>              ctx->thd_substream_info  = 0x14;
>          } else if (!av_channel_layout_compare(&avctx->ch_layout,
> -
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) {
> +
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) {
>              ctx->ch_modifier_thd0    = 1;
>              ctx->ch_modifier_thd1    = 1;
>              ctx->ch_modifier_thd2    = 1;
>              ctx->channel_arrangement = 11;
>              ctx->thd_substream_info  = 0x104;
>          } else if (!av_channel_layout_compare(&avctx->ch_layout,
> -
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK)) {
> +
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) {
>              ctx->ch_modifier_thd0    = 2;
>              ctx->ch_modifier_thd1    = 1;
>              ctx->ch_modifier_thd2    = 2;
> @@ -2277,13 +2277,13 @@ const FFCodec ff_truehd_encoder = {
>      .p.sample_fmts          = (const enum AVSampleFormat[])
> {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE},
>      .p.supported_samplerates = (const int[]) {44100, 48000, 88200, 96000,
> 176400, 192000, 0},
>  #if FF_API_OLD_CHANNEL_LAYOUT
> -    .p.channel_layouts      = (const uint64_t[]) {AV_CH_LAYOUT_MONO,
> AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_5POINT1_BACK,
> 0},
> +    .p.channel_layouts      = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
> AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1, 0 },
>  #endif
>      .p.ch_layouts           = (const AVChannelLayout[]) {
>                                    AV_CHANNEL_LAYOUT_MONO,
>                                    AV_CHANNEL_LAYOUT_STEREO,
> -                                  AV_CHANNEL_LAYOUT_5POINT0_BACK,
> -                                  AV_CHANNEL_LAYOUT_5POINT1_BACK,
> +                                  AV_CHANNEL_LAYOUT_5POINT0,
> +                                  AV_CHANNEL_LAYOUT_5POINT1,
>                                    { 0 }
>                                },
>      .caps_internal          = FF_CODEC_CAP_INIT_CLEANUP,
> --
> 2.34.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [FFmpeg-devel] [PATCH 15/17] avcodec/mlpenc: Remove dead channel layout checks
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 15/17] avcodec/mlpenc: Remove dead channel layout checks Andreas Rheinhardt
@ 2022-09-21  7:14   ` Paul B Mahol
  0 siblings, 0 replies; 23+ messages in thread
From: Paul B Mahol @ 2022-09-21  7:14 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt

On 9/18/22, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
> ff_encode_preinit() has already checked that the channel layout
> is equivalent to one of the layouts in AVCodec.ch_layouts.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mlpenc.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>


lgtm

> diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
> index d2e28888f7..878c5aedc1 100644
> --- a/libavcodec/mlpenc.c
> +++ b/libavcodec/mlpenc.c
> @@ -27,6 +27,7 @@
>  #include "encode.h"
>  #include "put_bits.h"
>  #include "audio_frame_queue.h"
> +#include "libavutil/avassert.h"
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/crc.h"
>  #include "libavutil/avstring.h"
> @@ -602,12 +603,11 @@ static av_cold int mlp_encode_init(AVCodecContext
> *avctx)
>          };
>          int i;
>
> -        for (i = 0; i < FF_ARRAY_ELEMS(layout_arrangement); i++)
> +        for (i = 0;; i++) {
> +            av_assert1(i < FF_ARRAY_ELEMS(layout_arrangement) ||
> +                       !"Impossible channel layout");
>              if (channels_present == layout_arrangement[i])
>                  break;
> -        if (i == FF_ARRAY_ELEMS(layout_arrangement)) {
> -            av_log(avctx, AV_LOG_ERROR, "Unsupported channel
> arrangement\n");
> -            return AVERROR(EINVAL);
>          }
>          ctx->channel_arrangement = i;
>          ctx->flags = FLAGS_DVDA;
> @@ -640,8 +640,7 @@ static av_cold int mlp_encode_init(AVCodecContext
> *avctx)
>              ctx->channel_arrangement = 15;
>              ctx->thd_substream_info  = 0x104;
>          } else {
> -            av_log(avctx, AV_LOG_ERROR, "Unsupported channel
> arrangement\n");
> -            return AVERROR(EINVAL);
> +            av_assert1(!"AVCodec.ch_layouts needs to be updated");
>          }
>          ctx->flags = 0;
>          ctx->channel_occupancy = 0;
> --
> 2.34.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [FFmpeg-devel] [PATCH 14/17] avcodec/mlpenc: Simplify channel layout comparisons
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 14/17] avcodec/mlpenc: Simplify channel layout comparisons Andreas Rheinhardt
@ 2022-09-21  7:15   ` Paul B Mahol
  0 siblings, 0 replies; 23+ messages in thread
From: Paul B Mahol @ 2022-09-21  7:15 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt

On 9/18/22, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
> These encoders have AVCodec.ch_layouts set, so ff_encode_preinit()
> has already checked that the used channel layout is equivalent
> to one of these native layouts. Therefore one can simply
> compare the channel masks (with the added complication
> that one has to use av_channel_layout_subset() to get it,
> because the channel layout is not guaranteed to have
> AV_CHANNEL_ORDER_NATIVE).
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mlpenc.c | 30 ++++++++++++++----------------
>  1 file changed, 14 insertions(+), 16 deletions(-)
>


probably ok

> diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
> index 463332593f..d2e28888f7 100644
> --- a/libavcodec/mlpenc.c
> +++ b/libavcodec/mlpenc.c
> @@ -480,6 +480,7 @@ static av_cold int mlp_encode_init(AVCodecContext
> *avctx)
>      static AVOnce init_static_once = AV_ONCE_INIT;
>      MLPEncodeContext *ctx = avctx->priv_data;
>      RestartHeader *const rh = &ctx->restart_header;
> +    uint64_t channels_present;
>      unsigned int sum = 0;
>      size_t size;
>      int ret;
> @@ -589,19 +590,20 @@ static av_cold int mlp_encode_init(AVCodecContext
> *avctx)
>
>      ctx->num_substreams = 1; // TODO: change this after adding
> multi-channel support for TrueHD
>
> +    channels_present = av_channel_layout_subset(&avctx->ch_layout,
> ~(uint64_t)0);
>      if (ctx->avctx->codec_id == AV_CODEC_ID_MLP) {
> -        static const AVChannelLayout layout_arrangement[] = {
> -            AV_CHANNEL_LAYOUT_MONO,         AV_CHANNEL_LAYOUT_STEREO,
> -            AV_CHANNEL_LAYOUT_2_1,          AV_CHANNEL_LAYOUT_QUAD,
> -            AV_CHANNEL_LAYOUT_2POINT1,      { 0 }, { 0 },
> -            AV_CHANNEL_LAYOUT_SURROUND,     AV_CHANNEL_LAYOUT_4POINT0,
> -            AV_CHANNEL_LAYOUT_5POINT0_BACK, AV_CHANNEL_LAYOUT_3POINT1,
> -            AV_CHANNEL_LAYOUT_4POINT1,
> AV_CHANNEL_LAYOUT_5POINT1_BACK,
> +        static const uint64_t layout_arrangement[] = {
> +            AV_CH_LAYOUT_MONO,         AV_CH_LAYOUT_STEREO,
> +            AV_CH_LAYOUT_2_1,          AV_CH_LAYOUT_QUAD,
> +            AV_CH_LAYOUT_2POINT1,      0, 0,
> +            AV_CH_LAYOUT_SURROUND,     AV_CH_LAYOUT_4POINT0,
> +            AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_3POINT1,
> +            AV_CH_LAYOUT_4POINT1,      AV_CH_LAYOUT_5POINT1_BACK,
>          };
>          int i;
>
>          for (i = 0; i < FF_ARRAY_ELEMS(layout_arrangement); i++)
> -            if (!av_channel_layout_compare(&avctx->ch_layout,
> &layout_arrangement[i]))
> +            if (channels_present == layout_arrangement[i])
>                  break;
>          if (i == FF_ARRAY_ELEMS(layout_arrangement)) {
>              av_log(avctx, AV_LOG_ERROR, "Unsupported channel
> arrangement\n");
> @@ -613,29 +615,25 @@ static av_cold int mlp_encode_init(AVCodecContext
> *avctx)
>          ctx->summary_info      =
> ff_mlp_ch_info[ctx->channel_arrangement].summary_info     ;
>      } else {
>          /* TrueHD */
> -        if (!av_channel_layout_compare(&avctx->ch_layout,
> -
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) {
> +        if (channels_present == AV_CH_LAYOUT_MONO) {
>              ctx->ch_modifier_thd0    = 3;
>              ctx->ch_modifier_thd1    = 3;
>              ctx->ch_modifier_thd2    = 3;
>              ctx->channel_arrangement = 2;
>              ctx->thd_substream_info  = 0x14;
> -        } else if (!av_channel_layout_compare(&avctx->ch_layout,
> -
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) {
> +        } else if (channels_present == AV_CH_LAYOUT_STEREO) {
>              ctx->ch_modifier_thd0    = 1;
>              ctx->ch_modifier_thd1    = 1;
>              ctx->ch_modifier_thd2    = 1;
>              ctx->channel_arrangement = 1;
>              ctx->thd_substream_info  = 0x14;
> -        } else if (!av_channel_layout_compare(&avctx->ch_layout,
> -
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) {
> +        } else if (channels_present == AV_CH_LAYOUT_5POINT0) {
>              ctx->ch_modifier_thd0    = 1;
>              ctx->ch_modifier_thd1    = 1;
>              ctx->ch_modifier_thd2    = 1;
>              ctx->channel_arrangement = 11;
>              ctx->thd_substream_info  = 0x104;
> -        } else if (!av_channel_layout_compare(&avctx->ch_layout,
> -
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) {
> +        } else if (channels_present == AV_CH_LAYOUT_5POINT1) {
>              ctx->ch_modifier_thd0    = 2;
>              ctx->ch_modifier_thd1    = 1;
>              ctx->ch_modifier_thd2    = 2;
> --
> 2.34.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [FFmpeg-devel] [PATCH 09/17] avcodec/libcodec2: Remove dead channel count check
  2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 09/17] avcodec/libcodec2: Remove dead channel count check Andreas Rheinhardt
@ 2022-09-21 13:31   ` Tomas Härdin
  0 siblings, 0 replies; 23+ messages in thread
From: Tomas Härdin @ 2022-09-21 13:31 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

sön 2022-09-18 klockan 22:27 +0200 skrev Andreas Rheinhardt:
> This encoder has AVCodec.ch_layouts set, so that this is checked
> generically.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/libcodec2.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavcodec/libcodec2.c b/libavcodec/libcodec2.c
> index be9677ddeb..581ef04ce2 100644
> --- a/libavcodec/libcodec2.c
> +++ b/libavcodec/libcodec2.c
> @@ -105,7 +105,6 @@ static av_cold int
> libcodec2_init_encoder(AVCodecContext *avctx)
>  
>      //will need to be smarter once we get wideband support
>      if (avctx->sample_rate != 8000 ||
> -        avctx->ch_layout.nb_channels != 1 ||
>          avctx->sample_fmt != AV_SAMPLE_FMT_S16) {
>          av_log(avctx, AV_LOG_ERROR, "only 8 kHz 16-bit mono
> allowed\n");
>          return AVERROR(EINVAL);

Should be fine

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2022-09-21 13:32 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-18 20:15 [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 02/17] avcodec/encode: Remove dead deprecated check Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 03/17] avcodec/avcodec: Check for more invalid channel layouts Andreas Rheinhardt
2022-09-20 22:47   ` James Almer
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 04/17] avcodec/avcodec: Always use old channel count/layout if set Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 05/17] avcodec/encode: Remove deprecated always-false checks Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 06/17] avcodec/dfpwmdec: Remove always-false check Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 07/17] avcodec/pcm-blurayenc: Don't presume every channel layout to be native Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 08/17] avcodec/pcm: Remove always-false check Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 09/17] avcodec/libcodec2: Remove dead channel count check Andreas Rheinhardt
2022-09-21 13:31   ` Tomas Härdin
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 10/17] avcodec/libshine: " Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 11/17] avcodec/libspeexenc: " Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 12/17] avcodec/mpegaudioenc_template: " Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 13/17] avcodec/mlpenc: Fix channel layouts Andreas Rheinhardt
2022-09-21  7:13   ` Paul B Mahol
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 14/17] avcodec/mlpenc: Simplify channel layout comparisons Andreas Rheinhardt
2022-09-21  7:15   ` Paul B Mahol
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 15/17] avcodec/mlpenc: Remove dead channel layout checks Andreas Rheinhardt
2022-09-21  7:14   ` Paul B Mahol
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 16/17] avcodec/dcaenc: Remove dead checks for unspec channel layouts Andreas Rheinhardt
2022-09-18 20:27 ` [FFmpeg-devel] [PATCH 17/17] avcodec/dcaenc: Simplify channel layout check Andreas Rheinhardt
2022-09-20 22:15 ` [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git