diff mbox series

[FFmpeg-devel,2/3] avformat/dfpwmdec: add support to set channel layout

Message ID 20220318221907.44594-2-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/3] avformat/slndec: add support to set channel layout | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

James Almer March 18, 2022, 10:19 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dfpwmdec.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/dfpwmdec.c b/libavformat/dfpwmdec.c
index 9f935a422a..3bd8bc0e41 100644
--- a/libavformat/dfpwmdec.c
+++ b/libavformat/dfpwmdec.c
@@ -32,6 +32,7 @@  typedef struct DFPWMAudioDemuxerContext {
     AVClass *class;
     int sample_rate;
     int channels;
+    AVChannelLayout ch_layout;
 } DFPWMAudioDemuxerContext;
 
 static int dfpwm_read_header(AVFormatContext *s)
@@ -48,7 +49,13 @@  static int dfpwm_read_header(AVFormatContext *s)
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
     par->codec_id    = s->iformat->raw_codec_id;
     par->sample_rate = s1->sample_rate;
-    par->ch_layout.nb_channels = s1->channels;
+    if (s1->channels)
+        par->ch_layout.nb_channels = s1->channels;
+    else {
+        int ret = av_channel_layout_copy(&par->ch_layout, &s1->ch_layout);
+        if (ret < 0)
+            return ret;
+    }
     par->bits_per_coded_sample = 1;
     par->block_align = 1;
 
@@ -58,7 +65,8 @@  static int dfpwm_read_header(AVFormatContext *s)
 
 static const AVOption dfpwm_options[] = {
     { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
-    { "channels",    "", offsetof(DFPWMAudioDemuxerContext, channels),    AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "channels",    "", offsetof(DFPWMAudioDemuxerContext, channels),    AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "ch_layout",   "", offsetof(DFPWMAudioDemuxerContext, ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
     { NULL },
 };
 static const AVClass dfpwm_demuxer_class = {