aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-03-18 19:24:58 +0100
committerJames Almer <jamrial@gmail.com>2022-03-18 18:59:03 -0300
commitfce01276422a0e121d61aec811ee1773f9013b9c (patch)
treeaa01888d5d4bf4710b8e4509673b1178edbc98a5
parent327efa66331ebdc0087c6b656059a8df2f404019 (diff)
downloadffmpeg-fce01276422a0e121d61aec811ee1773f9013b9c.tar.gz
avformat/pcmdec: add support to set channel layout
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r--libavformat/pcmdec.c17
-rw-r--r--libavformat/version.h2
2 files changed, 15 insertions, 4 deletions
diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index c7da740541..dcd13787d5 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -22,6 +22,7 @@
#include "config_components.h"
#include "libavutil/avstring.h"
+#include "libavutil/channel_layout.h"
#include "avformat.h"
#include "internal.h"
#include "pcm.h"
@@ -33,6 +34,7 @@ typedef struct PCMAudioDemuxerContext {
AVClass *class;
int sample_rate;
int channels;
+ AVChannelLayout ch_layout;
} PCMAudioDemuxerContext;
static int pcm_read_header(AVFormatContext *s)
@@ -50,7 +52,13 @@ static int pcm_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;
+ }
av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type);
if (mime_type && s->iformat->mime_type) {
@@ -78,8 +86,10 @@ static int pcm_read_header(AVFormatContext *s)
return AVERROR_INVALIDDATA;
}
par->sample_rate = rate;
- if (channels > 0)
+ if (channels > 0) {
+ av_channel_layout_uninit(&par->ch_layout);
par->ch_layout.nb_channels = channels;
+ }
if (little_endian)
par->codec_id = AV_CODEC_ID_PCM_S16LE;
}
@@ -98,7 +108,8 @@ static int pcm_read_header(AVFormatContext *s)
static const AVOption pcm_options[] = {
{ "sample_rate", "", offsetof(PCMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 44100}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
- { "channels", "", offsetof(PCMAudioDemuxerContext, channels), AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(PCMAudioDemuxerContext, channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "ch_layout", "", offsetof(PCMAudioDemuxerContext, ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
static const AVClass pcm_demuxer_class = {
diff --git a/libavformat/version.h b/libavformat/version.h
index de9cc8e31d..f4a26c2870 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
#include "version_major.h"
#define LIBAVFORMAT_VERSION_MINOR 20
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \