summaryrefslogtreecommitdiffstats
path: root/libmpdemux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-02 20:13:12 +0200
committerwm4 <wm4@nowhere>2012-09-18 21:07:29 +0200
commit1ba5a8f283e3894158f12f025035903e13d0f8ae (patch)
tree7ff315850990353487a332cfc9f2917f6d43ed14 /libmpdemux
parent1f5635d02cf1ad89025e5409fc05b718cbb04935 (diff)
downloadmpv-1ba5a8f283e3894158f12f025035903e13d0f8ae.tar.bz2
mpv-1ba5a8f283e3894158f12f025035903e13d0f8ae.tar.xz
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.)
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/demux_rawaudio.c30
1 files changed, 14 insertions, 16 deletions
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;