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.)
This commit is contained in:
wm4 2012-09-02 20:13:12 +02:00
parent 1f5635d02c
commit 1ba5a8f283
6 changed files with 31 additions and 22 deletions

View File

@ -1521,16 +1521,13 @@
--rawaudio=<option1:option2:...>
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=<value>: number of channels
:rate=<value>: rate in samples per second
:samplesize=<value>: sample size in bytes
:bitrate=<value>: bitrate for rawaudio files
:format=<value>: fourcc in hex
:format=<value>: mplayer audio format (e.g. s16le)
--rawvideo=<option1:option2:...>
This option lets you play raw video files. You have to use

View File

@ -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

View File

@ -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;
}

View File

@ -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)

View File

@ -21,6 +21,8 @@
#include <unistd.h>
#include <stdbool.h>
#include <libavutil/common.h>
#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;

View File

@ -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;