From 1ba5a8f283e3894158f12f025035903e13d0f8ae Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Sep 2012 20:13:12 +0200 Subject: rawaudio: use mplayer audio format for format option The rawaudio demuxer had a rather hard to use way to set the audio format with the --rawaudio=format=value option. The user had to pass a numeric value, which then was set as wFormatTag member in the WAVEFORMATEX header. Make it use the mplayer audio format (the same as --af=format=value). Add a new internal pseudo audio codec tag, which is hopefully unused, which makes ad_pcm use the value in wFormatTag as internal mplayer audio format. Playing non-PCM formats is disabled. (At least AC3 can be played directly.) --- DOCS/man/en/options.rst | 7 ++----- etc/codecs.conf | 1 + libaf/format.c | 7 ++++++- libaf/format.h | 2 ++ libmpcodecs/ad_pcm.c | 6 ++++++ libmpdemux/demux_rawaudio.c | 30 ++++++++++++++---------------- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 0772bc2f76..127b3ffe5d 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1521,16 +1521,13 @@ --rawaudio= This option lets you play raw audio files. You have to use ``--demuxer=rawaudio`` as well. It may also be used to play audio CDs - which are not 44kHz 16-bit stereo. For playing raw AC-3 streams use - ``--rawaudio=format=0x2000 --demuxer=rawaudio``. + which are not 44kHz 16-bit stereo. Available options are: :channels=: number of channels :rate=: rate in samples per second - :samplesize=: sample size in bytes - :bitrate=: bitrate for rawaudio files - :format=: fourcc in hex + :format=: mplayer audio format (e.g. s16le) --rawvideo= This option lets you play raw video files. You have to use diff --git a/etc/codecs.conf b/etc/codecs.conf index ccc7943d29..0b2fcb793e 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -1774,6 +1774,7 @@ audiocodec pcm fourcc 23ni ; (MOV files) fourcc lpcm ; (MOV files) fourcc FL32 ; (aiff files) + fourcc MPaf ; internal MPlayer FourCC for demux_rawaudio ;;;; these are for hardware support only: (alaw,ulaw,ima-adpcm,mpeg,ac3) ; format 0x6 ; format 0x7 diff --git a/libaf/format.c b/libaf/format.c index ffdf435e71..88d66522a0 100644 --- a/libaf/format.c +++ b/libaf/format.c @@ -112,12 +112,17 @@ const char *af_fmt2str_short(int format) return "??"; } +static bool af_fmt_valid(int format) +{ + return (format & AF_FORMAT_MASK) == format; +} + int af_str2fmt_short(bstr str) { if (bstr_startswith0(str, "0x")) { bstr rest; int fmt = bstrtoll(str, &rest, 16); - if (rest.len == 0) + if (rest.len == 0 && af_fmt_valid(fmt)) return fmt; } diff --git a/libaf/format.h b/libaf/format.h index 36f5c3fb59..e60c0789b9 100644 --- a/libaf/format.h +++ b/libaf/format.h @@ -66,6 +66,8 @@ #define AF_FORMAT_IEC61937 (6<<6) #define AF_FORMAT_SPECIAL_MASK (7<<6) +#define AF_FORMAT_MASK ((1<<9)-1) + // PREDEFINED formats #define AF_FORMAT_U8 (AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_8BIT|AF_FORMAT_NE) diff --git a/libmpcodecs/ad_pcm.c b/libmpcodecs/ad_pcm.c index 6ddae6afeb..c265dfcd56 100644 --- a/libmpcodecs/ad_pcm.c +++ b/libmpcodecs/ad_pcm.c @@ -21,6 +21,8 @@ #include #include +#include + #include "talloc.h" #include "config.h" #include "ad_internal.h" @@ -119,6 +121,10 @@ static int init(sh_audio_t * sh_audio) sh_audio->sample_format = AF_FORMAT_S32_LE; sh_audio->samplesize = 4; break; + case MKTAG('M', 'P', 'a', 'f'): + sh_audio->sample_format = h->wFormatTag; + sh_audio->samplesize = (af_fmt2bits(sh_audio->sample_format) + 7) / 8; + break; default: if (sh_audio->samplesize != 2) sh_audio->sample_format = AF_FORMAT_U8; diff --git a/libmpdemux/demux_rawaudio.c b/libmpdemux/demux_rawaudio.c index 495f8e9817..2a8fea05f0 100644 --- a/libmpdemux/demux_rawaudio.c +++ b/libmpdemux/demux_rawaudio.c @@ -28,20 +28,17 @@ #include "stream/stream.h" #include "demuxer.h" #include "stheader.h" +#include "libaf/format.h" static int channels = 2; static int samplerate = 44100; -static int samplesize = 2; -static int bitrate = 0; -static int format = 0x1; // Raw PCM +static int format = AF_FORMAT_S16_NE; const m_option_t demux_rawaudio_opts[] = { { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL }, { "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL }, - { "samplesize", &samplesize, CONF_TYPE_INT,CONF_RANGE,1,8, NULL }, - { "bitrate", &bitrate, CONF_TYPE_INT,CONF_MIN,0,0, NULL }, - { "format", &format, CONF_TYPE_INT, CONF_MIN, 0 , 0, NULL }, + { "format", &format, CONF_TYPE_AFMT, 0, 0, 0, NULL }, {NULL, NULL, 0, 0, 0, 0, NULL} }; @@ -50,20 +47,21 @@ static demuxer_t* demux_rawaudio_open(demuxer_t* demuxer) { sh_audio_t* sh_audio; WAVEFORMATEX* w; + if ((format & AF_FORMAT_SPECIAL_MASK) != 0) + return NULL; + sh_audio = new_sh_audio(demuxer,0); sh_audio->wf = w = malloc(sizeof(*w)); - w->wFormatTag = sh_audio->format = format; + // Not a WAVEFORMATEX format; just abuse it to pass the internal mplayer + // format to ad_pcm.c + w->wFormatTag = format; + sh_audio->format = MKTAG('M', 'P', 'a', 'f'); w->nChannels = sh_audio->channels = channels; w->nSamplesPerSec = sh_audio->samplerate = samplerate; - if (bitrate > 999) - w->nAvgBytesPerSec = bitrate/8; - else if (bitrate > 0) - w->nAvgBytesPerSec = bitrate*125; - else - w->nAvgBytesPerSec = samplerate*samplesize*channels; - w->nBlockAlign = channels*samplesize; - sh_audio->samplesize = samplesize; - w->wBitsPerSample = 8*samplesize; + sh_audio->samplesize = (af_fmt2bits(format) + 7) / 8; + w->nAvgBytesPerSec = samplerate * sh_audio->samplesize * channels; + w->nBlockAlign = channels * sh_audio->samplesize; + w->wBitsPerSample = 8 * sh_audio->samplesize; w->cbSize = 0; demuxer->movi_start = demuxer->stream->start_pos; -- cgit v1.2.3