summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-16 19:15:32 +0200
committerwm4 <wm4@nowhere>2013-06-16 19:36:56 +0200
commit4d3a2c7e0dac38546f5fc2c7737a6ec1f09e30f6 (patch)
tree8324cc1b661ff83ad9a8f50c5f08b42d838e4731 /audio
parentf88193091b3de59b496633682b659cd388e24a59 (diff)
downloadmpv-4d3a2c7e0dac38546f5fc2c7737a6ec1f09e30f6.tar.bz2
mpv-4d3a2c7e0dac38546f5fc2c7737a6ec1f09e30f6.tar.xz
audio/out: remove ao->outburst/buffersize fields
The core didn't use these fields, and use of them was inconsistent accross AOs. Some didn't use them at all. Some only set them; the values were completely unused by the core. Some made full use of them. Remove these fields. In places where they are still needed, make them private AO state. Remove the --abs option. It set the buffer size for ao_oss and ao_dsound (being ignored by all other AOs), and was already marked as obsolete. If it turns out that it's still needed for ao_oss or ao_dsound, their default buffer sizes could be adjusted, and if even that doesn't help, AO suboptions could be added in these cases.
Diffstat (limited to 'audio')
-rw-r--r--audio/out/ao.c3
-rw-r--r--audio/out/ao.h8
-rw-r--r--audio/out/ao_alsa.c16
-rw-r--r--audio/out/ao_coreaudio.c6
-rw-r--r--audio/out/ao_dsound.c14
-rw-r--r--audio/out/ao_jack.c8
-rw-r--r--audio/out/ao_lavc.c10
-rw-r--r--audio/out/ao_null.c16
-rw-r--r--audio/out/ao_openal.c2
-rw-r--r--audio/out/ao_oss.c47
-rw-r--r--audio/out/ao_pcm.c3
-rw-r--r--audio/out/ao_sdl.c4
12 files changed, 64 insertions, 73 deletions
diff --git a/audio/out/ao.c b/audio/out/ao.c
index 9cfa383972..7abb33f89f 100644
--- a/audio/out/ao.c
+++ b/audio/out/ao.c
@@ -107,8 +107,7 @@ void list_audio_out(void)
struct ao *ao_create(struct MPOpts *opts, struct input_ctx *input)
{
struct ao *r = talloc(NULL, struct ao);
- *r = (struct ao){.outburst = 512, .buffersize = -1,
- .opts = opts, .input_ctx = input };
+ *r = (struct ao){.opts = opts, .input_ctx = input };
return r;
}
diff --git a/audio/out/ao.h b/audio/out/ao.h
index 0e004572a6..146c35f823 100644
--- a/audio/out/ao.h
+++ b/audio/out/ao.h
@@ -89,13 +89,11 @@ struct ao {
int samplerate;
struct mp_chmap channels;
int format;
- int bps; // bytes per second
- int outburst;
- int buffersize;
- double pts;
+ int bps; // bytes per second
+ double pts; // some mplayer.c state (why is this here?)
struct bstr buffer;
int buffer_playable_size;
- bool probing;
+ bool probing; // if true, don't fail loudly on init
bool initialized;
bool untimed;
bool no_persistent_volume; // the AO does the equivalent of af_volume
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index 6dd04d2967..bbd4603d18 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -57,6 +57,8 @@ struct priv {
int can_pause;
snd_pcm_sframes_t prepause_frames;
float delay_before_pause;
+ int buffersize;
+ int outburst;
};
#define BUFFER_TIME 500000 // 0.5 s
@@ -579,15 +581,15 @@ static int init(struct ao *ao, char *params)
err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams, &bufsize);
CHECK_ALSA_ERROR("Unable to get buffersize");
- ao->buffersize = bufsize * p->bytes_per_sample;
+ p->buffersize = bufsize * p->bytes_per_sample;
mp_msg(MSGT_AO, MSGL_V, "alsa-init: got buffersize=%i\n",
- ao->buffersize);
+ p->buffersize);
err = snd_pcm_hw_params_get_period_size(alsa_hwparams, &chunk_size, NULL);
CHECK_ALSA_ERROR("Unable to get period size");
mp_msg(MSGT_AO, MSGL_V, "alsa-init: got period size %li\n", chunk_size);
- ao->outburst = chunk_size * p->bytes_per_sample;
+ p->outburst = chunk_size * p->bytes_per_sample;
/* setting software parameters */
err = snd_pcm_sw_params_current(p->alsa, alsa_swparams);
@@ -621,7 +623,7 @@ static int init(struct ao *ao, char *params)
mp_msg(MSGT_AO, MSGL_V,
"alsa: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
ao->samplerate, ao->channels.num, (int)p->bytes_per_sample,
- ao->buffersize, snd_pcm_format_description(p->alsa_fmt));
+ p->buffersize, snd_pcm_format_description(p->alsa_fmt));
return 0;
@@ -733,7 +735,7 @@ static int play(struct ao *ao, void *data, int len, int flags)
int num_frames;
snd_pcm_sframes_t res = 0;
if (!(flags & AOPLAY_FINAL_CHUNK))
- len = len / ao->outburst * ao->outburst;
+ len = len / p->outburst * p->outburst;
num_frames = len / p->bytes_per_sample;
//mp_msg(MSGT_AO,MSGL_ERR,"alsa-play: frames=%i, len=%i\n",num_frames,len);
@@ -789,8 +791,8 @@ static int get_space(struct ao *ao)
CHECK_ALSA_ERROR("cannot get pcm status");
unsigned space = snd_pcm_status_get_avail(status) * p->bytes_per_sample;
- if (space > ao->buffersize) // Buffer underrun?
- space = ao->buffersize;
+ if (space > p->buffersize) // Buffer underrun?
+ space = p->buffersize;
return space;
alsa_error:
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index ea9e431535..38c7c7fc29 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -626,9 +626,7 @@ static int init(struct ao *ao, char *params)
goto err_out2;
ao->bps = ao->samplerate * inDesc.mBytesPerFrame;
- ao->buffersize = ao->bps;
p->buffer = mp_ring_new(p, get_ring_size(ao));
- ao->outburst = maxFrames;
print_buffer(p->buffer);
@@ -861,11 +859,7 @@ static int OpenSPDIF(struct ao *ao)
(p->stream_format.mBytesPerPacket /
p->stream_format.mFramesPerPacket);
- /* For ac3/dts, just use packet size 6144 bytes as chunk size. */
- int chunk_size = p->stream_format.mBytesPerPacket;
- ao->buffersize = ao->bps;
p->buffer = mp_ring_new(p, get_ring_size(ao));
- ao->outburst = chunk_size;
print_buffer(p->buffer);
diff --git a/audio/out/ao_dsound.c b/audio/out/ao_dsound.c
index 5b49a67d16..bb410183eb 100644
--- a/audio/out/ao_dsound.c
+++ b/audio/out/ao_dsound.c
@@ -94,6 +94,8 @@ struct priv {
int audio_volume;
int device_index;
+
+ int outburst; ///play in multiple of chunks of this size
};
static float get_delay(struct ao *ao);
@@ -438,13 +440,12 @@ static int init(struct ao *ao, char *params)
ao->samplerate = rate;
ao->format = format;
ao->bps = ao->channels.num * rate * (af_fmt2bits(format) >> 3);
- if (ao->buffersize == -1)
- ao->buffersize = ao->bps; // space for 1 sec
+ int buffersize = ao->bps; // space for 1 sec
mp_msg(MSGT_AO, MSGL_V,
"ao_dsound: Samplerate:%iHz Channels:%i Format:%s\n", rate,
ao->channels.num, af_fmt2str_short(format));
mp_msg(MSGT_AO, MSGL_V, "ao_dsound: Buffersize:%d bytes (%d msec)\n",
- ao->buffersize, ao->buffersize / ao->bps * 1000);
+ buffersize, buffersize / ao->bps * 1000);
//fill waveformatex
ZeroMemory(&wformat, sizeof(WAVEFORMATEXTENSIBLE));
@@ -488,12 +489,12 @@ static int init(struct ao *ao, char *params)
wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec *
wformat.Format.nBlockAlign;
- dsbdesc.dwBufferBytes = ao->buffersize;
+ dsbdesc.dwBufferBytes = buffersize;
dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&wformat;
p->buffer_size = dsbdesc.dwBufferBytes;
p->write_offset = 0;
p->min_free_space = wformat.Format.nBlockAlign;
- ao->outburst = wformat.Format.nBlockAlign * 512;
+ p->outburst = wformat.Format.nBlockAlign * 512;
// create primary buffer and set its format
@@ -633,7 +634,6 @@ static int get_space(struct ao *ao)
\brief play 'len' bytes of 'data'
\param data pointer to the data to play
\param len size in bytes of the data buffer, gets rounded down to outburst*n
- NOTE: outburst stuff might be outdated/deprecated
\param flags currently unused
\return number of played bytes
*/
@@ -644,7 +644,7 @@ static int play(struct ao *ao, void *data, int len, int flags)
len = space;
if (!(flags & AOPLAY_FINAL_CHUNK))
- len = (len / ao->outburst) * ao->outburst;
+ len = (len / p->outburst) * p->outburst;
return write_buffer(ao, data, len);
}
diff --git a/audio/out/ao_jack.c b/audio/out/ao_jack.c
index ff5c37a818..c677f4555d 100644
--- a/audio/out/ao_jack.c
+++ b/audio/out/ao_jack.c
@@ -51,6 +51,7 @@ struct priv {
jack_port_t * ports[MAX_CHANS];
int num_ports; // Number of used ports == number of channels
jack_client_t *client;
+ int outburst;
float jack_latency;
int estimate;
volatile int paused;
@@ -280,9 +281,8 @@ static int init(struct ao *ao, char *params)
ao->format = AF_FORMAT_FLOAT_NE;
int unitsize = ao->channels.num * sizeof(float);
- ao->outburst = CHUNK_SIZE / unitsize * unitsize;
- ao->buffersize = NUM_CHUNKS * ao->outburst;
- p->ring = mp_ring_new(p, ao->buffersize);
+ p->outburst = CHUNK_SIZE / unitsize * unitsize;
+ p->ring = mp_ring_new(p, NUM_CHUNKS * p->outburst);
free(matching_ports);
free(port_name);
free(client_name);
@@ -365,7 +365,7 @@ static int play(struct ao *ao, void *data, int len, int flags)
{
struct priv *p = ao->priv;
if (!(flags & AOPLAY_FINAL_CHUNK))
- len -= len % ao->outburst;
+ len -= len % p->outburst;
p->underrun = 0;
return mp_ring_write(p->ring, data, len);
}
diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c
index d2ae5e1e53..4fe709ce9a 100644
--- a/audio/out/ao_lavc.c
+++ b/audio/out/ao_lavc.c
@@ -281,10 +281,6 @@ out_takefirst:
encode_lavc_getoffset(ao->encode_lavc_ctx, ac->stream);
ac->offset_left = ac->offset;
- //fill_ao_data:
- ao->outburst =
- ac->aframesize * ac->sample_size * ao->channels.num * ac->framecount;
- ao->buffersize = ao->outburst * 2;
ao->untimed = true;
ao->priv = ac;
@@ -354,7 +350,9 @@ static void uninit(struct ao *ao, bool cut_audio)
// return: how many bytes can be played without blocking
static int get_space(struct ao *ao)
{
- return ao->outburst;
+ struct priv *ac = ao->priv;
+
+ return ac->aframesize * ac->sample_size * ao->channels.num * ac->framecount;
}
// must get exactly ac->aframesize amount of data
@@ -487,7 +485,7 @@ static int encode(struct ao *ao, double apts, void *data)
}
// plays 'len' bytes of 'data'
-// it should round it down to outburst*n
+// it should round it down to frame sizes
// return: number of bytes played
static int play(struct ao *ao, void *data, int len, int flags)
{
diff --git a/audio/out/ao_null.c b/audio/out/ao_null.c
index f3c60913b5..dde2102daa 100644
--- a/audio/out/ao_null.c
+++ b/audio/out/ao_null.c
@@ -31,6 +31,8 @@
struct priv {
double last_time;
float buffered_bytes;
+ int buffersize;
+ int outburst;
};
static void drain(struct ao *ao)
@@ -55,9 +57,9 @@ static int init(struct ao *ao, char *params)
return -1;
int samplesize = af_fmt2bits(ao->format) / 8;
- ao->outburst = 256 * ao->channels.num * samplesize;
+ priv->outburst = 256 * ao->channels.num * samplesize;
// A "buffer" for about 0.2 seconds of audio
- ao->buffersize = (int)(ao->samplerate * 0.2 / 256 + 1) * ao->outburst;
+ priv->buffersize = (int)(ao->samplerate * 0.2 / 256 + 1) * priv->outburst;
priv->last_time = mp_time_sec();
return 0;
@@ -92,18 +94,18 @@ static int get_space(struct ao *ao)
struct priv *priv = ao->priv;
drain(ao);
- return ao->buffersize - priv->buffered_bytes;
+ return priv->buffersize - priv->buffered_bytes;
}
static int play(struct ao *ao, void *data, int len, int flags)
{
struct priv *priv = ao->priv;
- int maxbursts = (ao->buffersize - priv->buffered_bytes) / ao->outburst;
- int playbursts = len / ao->outburst;
+ int maxbursts = (priv->buffersize - priv->buffered_bytes) / priv->outburst;
+ int playbursts = len / priv->outburst;
int bursts = playbursts > maxbursts ? maxbursts : playbursts;
- priv->buffered_bytes += bursts * ao->outburst;
- return bursts * ao->outburst;
+ priv->buffered_bytes += bursts * priv->outburst;
+ return bursts * priv->outburst;
}
static float get_delay(struct ao *ao)
diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c
index 60f4dd7c99..44f26c9cf1 100644
--- a/audio/out/ao_openal.c
+++ b/audio/out/ao_openal.c
@@ -188,8 +188,6 @@ static int init(struct ao *ao, char *params)
if (alcGetError(dev) == ALC_NO_ERROR && freq)
ao->samplerate = freq;
ao->format = AF_FORMAT_S16_NE;
- ao->buffersize = CHUNK_SIZE * NUM_BUF;
- ao->outburst = ao->channels.num * CHUNK_SIZE;
tmpbuf = malloc(CHUNK_SIZE);
free(device);
return 0;
diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c
index d5125ffcd7..fa590f7965 100644
--- a/audio/out/ao_oss.c
+++ b/audio/out/ao_oss.c
@@ -58,6 +58,8 @@ struct priv {
int oss_mixer_channel;
audio_buf_info zz;
int audio_delay_method;
+ int buffersize;
+ int outburst;
};
static int format_table[][2] = {
@@ -206,6 +208,8 @@ static int init(struct ao *ao, char *params)
.oss_mixer_device = mdev ? mdev : PATH_DEV_MIXER,
.oss_mixer_channel = SOUND_MIXER_PCM,
.audio_delay_method = 2,
+ .buffersize = -1,
+ .outburst = 512,
};
ao->priv = p;
@@ -363,29 +367,28 @@ ac3_retry:
"support SNDCTL_DSP_GETOSPACE\n");
if (ioctl(p->audio_fd, SNDCTL_DSP_GETBLKSIZE, &r) == -1)
mp_msg(MSGT_AO, MSGL_V, "audio_setup: %d bytes/frag (config.h)\n",
- ao->outburst);
+ p->outburst);
else {
- ao->outburst = r;
+ p->outburst = r;
mp_msg(MSGT_AO, MSGL_V, "audio_setup: %d bytes/frag (GETBLKSIZE)\n",
- ao->outburst);
+ p->outburst);
}
} else {
mp_msg(MSGT_AO, MSGL_V,
"audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n",
p->zz.fragments, p->zz.fragstotal, p->zz.fragsize, p->zz.bytes);
- if (ao->buffersize == -1)
- ao->buffersize = p->zz.bytes;
- ao->outburst = p->zz.fragsize;
+ p->buffersize = p->zz.bytes;
+ p->outburst = p->zz.fragsize;
}
- if (ao->buffersize == -1) {
+ if (p->buffersize == -1) {
// Measuring buffer size:
void *data;
- ao->buffersize = 0;
+ p->buffersize = 0;
#ifdef HAVE_AUDIO_SELECT
- data = malloc(ao->outburst);
- memset(data, 0, ao->outburst);
- while (ao->buffersize < 0x40000) {
+ data = malloc(p->outburst);
+ memset(data, 0, p->outburst);
+ while (p->buffersize < 0x40000) {
fd_set rfds;
struct timeval tv;
FD_ZERO(&rfds);
@@ -394,11 +397,11 @@ ac3_retry:
tv.tv_usec = 0;
if (!select(p->audio_fd + 1, NULL, &rfds, NULL, &tv))
break;
- write(p->audio_fd, data, ao->outburst);
- ao->buffersize += ao->outburst;
+ write(p->audio_fd, data, p->outburst);
+ p->buffersize += p->outburst;
}
free(data);
- if (ao->buffersize == 0) {
+ if (p->buffersize == 0) {
mp_tmsg(MSGT_AO, MSGL_ERR, "[AO OSS]\n *** Your audio driver "
"DOES NOT support select() ***\n Recompile mpv with "
"#undef HAVE_AUDIO_SELECT in config.h !\n\n");
@@ -408,7 +411,7 @@ ac3_retry:
}
ao->bps = ao->channels.num * (af_fmt2bits(ao->format) / 8);
- ao->outburst -= ao->outburst % ao->bps; // round down
+ p->outburst -= p->outburst % ao->bps; // round down
ao->bps *= ao->samplerate;
return 0;
@@ -479,7 +482,7 @@ static void reset(struct ao *ao)
static int get_space(struct ao *ao)
{
struct priv *p = ao->priv;
- int playsize = ao->outburst;
+ int playsize = p->outburst;
#ifdef SNDCTL_DSP_GETOSPACE
if (ioctl(p->audio_fd, SNDCTL_DSP_GETOSPACE, &p->zz) != -1) {
@@ -503,7 +506,7 @@ static int get_space(struct ao *ao)
}
#endif
- return ao->outburst;
+ return p->outburst;
}
// stop playing, keep buffers (for pause)
@@ -522,9 +525,9 @@ static int play(struct ao *ao, void *data, int len, int flags)
struct priv *p = ao->priv;
if (len == 0)
return len;
- if (len > ao->outburst || !(flags & AOPLAY_FINAL_CHUNK)) {
- len /= ao->outburst;
- len *= ao->outburst;
+ if (len > p->outburst || !(flags & AOPLAY_FINAL_CHUNK)) {
+ len /= p->outburst;
+ len *= p->outburst;
}
len = write(p->audio_fd, data, len);
return len;
@@ -560,12 +563,12 @@ static float get_delay(struct ao *ao)
if (p->audio_delay_method == 1) {
// SNDCTL_DSP_GETOSPACE
if (ioctl(p->audio_fd, SNDCTL_DSP_GETOSPACE, &p->zz) != -1) {
- return ((float)(ao->buffersize -
+ return ((float)(p->buffersize -
p->zz.bytes)) / (float)ao->bps;
}
p->audio_delay_method = 0; // fallback if not supported
}
- return ((float)ao->buffersize) / (float)ao->bps;
+ return ((float)p->buffersize) / (float)ao->bps;
}
const struct ao_driver audio_out_oss = {
diff --git a/audio/out/ao_pcm.c b/audio/out/ao_pcm.c
index 903e89bc8b..7cceaad1cb 100644
--- a/audio/out/ao_pcm.c
+++ b/audio/out/ao_pcm.c
@@ -151,7 +151,6 @@ static int init(struct ao *ao, char *params)
if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels))
return -1;
- ao->outburst = 65536;
ao->bps = ao->channels.num * ao->samplerate * (af_fmt2bits(ao->format) / 8);
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO PCM] File: %s (%s)\n"
@@ -207,7 +206,7 @@ static void uninit(struct ao *ao, bool cut_audio)
static int get_space(struct ao *ao)
{
- return ao->outburst;
+ return 65536;
}
static int play(struct ao *ao, void *data, int len, int flags)
diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c
index 572266c4a8..ee95e77d44 100644
--- a/audio/out/ao_sdl.c
+++ b/audio/out/ao_sdl.c
@@ -248,9 +248,7 @@ static int init(struct ao *ao, char *params)
}
ao->samplerate = obtained.freq;
- ao->buffersize = obtained.size * bufcnt;
- ao->outburst = obtained.size;
- priv->buffer = av_fifo_alloc(ao->buffersize);
+ priv->buffer = av_fifo_alloc(obtained.size * bufcnt);
priv->buffer_mutex = SDL_CreateMutex();
if (!priv->buffer_mutex) {
mp_msg(MSGT_AO, MSGL_ERR, "[sdl] SDL_CreateMutex failed\n");