path: root/demux/codec_tags.c
diff options
authorwm4 <wm4@nowhere>2014-09-24 22:55:50 +0200
committerwm4 <wm4@nowhere>2014-09-24 22:55:50 +0200
commit9ac86d9e994aeb764207f4d0279b3d37266f79e6 (patch)
treee1d7ca4e241e8dbe551e9a65eb7dd1e0b4008876 /demux/codec_tags.c
parent8a8f65d73d7009b13571293d1de6284d42a318e8 (diff)
audio: decouple demux and audio decoder/filter sample formats
For a while, we used this to transfer PCM from demuxer to the filter chain. We had a special "codec" that mapped what MPlayer used to do (MPlayer passes the AF sample format over an extra field to ad_pcm, which specially interprets it). Do this by providing a mp_set_pcm_codec() function, which describes a sample format in a generic way, and sets the appropriate demuxer header fields so that libavcodec interprets it correctly. We use the fact that libavcodec has separate PCM decoders for each format. These are systematically named, so we can easily map them. This has the advantage that we can change the audio filter chain as we like, without losing features from the "rawaudio" demuxer. In fact, this commit also gets rid of the audio filter chain formats completely. Instead have an explicit list of PCM formats. (We could even just have the user pass libavcodec PCM decoder names directly, but that would be annoying in other ways.)
Diffstat (limited to 'demux/codec_tags.c')
1 files changed, 16 insertions, 0 deletions
diff --git a/demux/codec_tags.c b/demux/codec_tags.c
index 3f5a3e0922..23e1935dba 100644
--- a/demux/codec_tags.c
+++ b/demux/codec_tags.c
@@ -383,3 +383,19 @@ uint32_t mp_video_fourcc_alias(uint32_t fourcc)
return fourcc;
+void mp_set_pcm_codec(struct sh_stream *sh, bool sign, bool is_float, int bits,
+ bool is_be)
+ // This uses libavcodec pcm codec names, e.g. "pcm_u16le".
+ char codec[64] = "pcm_";
+ if (is_float) {
+ mp_snprintf_cat(codec, sizeof(codec), "f");
+ } else {
+ mp_snprintf_cat(codec, sizeof(codec), sign ? "s" : "u");
+ }
+ mp_snprintf_cat(codec, sizeof(codec), "%d", bits);
+ if (bits != 8)
+ mp_snprintf_cat(codec, sizeof(codec), is_be ? "be" : "le");
+ sh->codec = talloc_strdup(sh->audio, codec);