From 9ac86d9e994aeb764207f4d0279b3d37266f79e6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 24 Sep 2014 22:55:50 +0200 Subject: 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.) --- demux/demux_tv.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'demux/demux_tv.c') diff --git a/demux/demux_tv.c b/demux/demux_tv.c index a4421a86cf..198ca922e5 100644 --- a/demux/demux_tv.c +++ b/demux/demux_tv.c @@ -8,6 +8,7 @@ #include "options/options.h" #include "demux.h" +#include "codec_tags.h" #include "audio/format.h" #include "video/img_fourcc.h" @@ -105,11 +106,8 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check) switch(audio_format) { - case AF_FORMAT_U8: - case AF_FORMAT_S8: - case AF_FORMAT_U16: + // This is the only format any of the current inputs generate. case AF_FORMAT_S16: - case AF_FORMAT_S32: break; default: MP_ERR(tvh, "Audio type '%s' unsupported!\n", @@ -127,29 +125,11 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check) &nchannels); mp_chmap_from_channels(&sh_audio->channels, nchannels); - sh_a->codec = "mp-pcm"; - sh_a->format = audio_format; - - int samplesize = af_fmt2bps(audio_format); - int block_align = samplesize * sh_audio->channels.num; - int bytes_per_second = sh_audio->samplerate * block_align; - - sh_audio->bitrate = bytes_per_second * 8; - - // emulate WF for win32 codecs: - sh_audio->wf = talloc_zero(sh_audio, MP_WAVEFORMATEX); - sh_audio->wf->wFormatTag = sh_a->format; - sh_audio->wf->nChannels = sh_audio->channels.num; - sh_audio->wf->wBitsPerSample = samplesize * 8; - sh_audio->wf->nSamplesPerSec = sh_audio->samplerate; - sh_audio->wf->nBlockAlign = block_align; - sh_audio->wf->nAvgBytesPerSec = bytes_per_second; - // wav header usually implies little endian - sh_audio->big_endian = BYTE_ORDER == BIG_ENDIAN; + // s16ne + mp_set_pcm_codec(sh_a, true, false, 16, BYTE_ORDER == BIG_ENDIAN); MP_VERBOSE(tvh, " TV audio: %d channels, %d bits, %d Hz\n", - sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample, - sh_audio->wf->nSamplesPerSec); + nchannels, 16, sh_audio->samplerate); } no_audio: -- cgit v1.2.3