mirror of
https://github.com/mpv-player/mpv
synced 2025-02-05 22:52:18 +00:00
audio: remove ao_driver.drain
The recent change to the common code removed all calls to ->drain. It's currently emulated via a timed sleep and polling ao_eof_reached(). That is actually fallback code for AOs which lacked draining. I could just readd the drain call, but it was a bad idea anyway. My plan to handle this better is to require the AO to signal a underrun, even if AOPLAY_FINAL_CHUNK is not set. Also reinstate not possibly waiting for ao_lavc.c. ao_pcm.c did not have anything to handle this; whatever.
This commit is contained in:
parent
1b03970d79
commit
9885952c2a
@ -944,12 +944,6 @@ static int init(struct ao *ao)
|
||||
return r;
|
||||
}
|
||||
|
||||
static void drain(struct ao *ao)
|
||||
{
|
||||
struct priv *p = ao->priv;
|
||||
snd_pcm_drain(p->alsa);
|
||||
}
|
||||
|
||||
static int get_space(struct ao *ao)
|
||||
{
|
||||
struct priv *p = ao->priv;
|
||||
@ -1260,7 +1254,6 @@ const struct ao_driver audio_out_alsa = {
|
||||
.pause = audio_pause,
|
||||
.resume = audio_resume,
|
||||
.reset = reset,
|
||||
.drain = drain,
|
||||
.wait = audio_wait,
|
||||
.wakeup = ao_wakeup_poll,
|
||||
.list_devs = list_devs,
|
||||
|
@ -345,11 +345,6 @@ static int play(struct ao *ao, void **data, int samples, int flags)
|
||||
return taken;
|
||||
}
|
||||
|
||||
static void drain(struct ao *ao)
|
||||
{
|
||||
// pretend we support it, so generic code doesn't force a wait
|
||||
}
|
||||
|
||||
const struct ao_driver audio_out_lavc = {
|
||||
.encode = true,
|
||||
.description = "audio encoding using libavcodec",
|
||||
@ -361,7 +356,6 @@ const struct ao_driver audio_out_lavc = {
|
||||
.uninit = uninit,
|
||||
.get_space = get_space,
|
||||
.play = play,
|
||||
.drain = drain,
|
||||
};
|
||||
|
||||
// vim: sw=4 ts=4 et tw=80
|
||||
|
@ -229,7 +229,6 @@ const struct ao_driver audio_out_null = {
|
||||
.get_delay = get_delay,
|
||||
.pause = pause,
|
||||
.resume = resume,
|
||||
.drain = wait_drain,
|
||||
.priv_size = sizeof(struct priv),
|
||||
.priv_defaults = &(const struct priv) {
|
||||
.bufferlen = 0.2,
|
||||
|
@ -274,16 +274,6 @@ err_out:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void drain(struct ao *ao)
|
||||
{
|
||||
ALint state;
|
||||
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
||||
while (state == AL_PLAYING) {
|
||||
mp_sleep_us(10000);
|
||||
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
||||
}
|
||||
}
|
||||
|
||||
static void unqueue_buffers(struct ao *ao)
|
||||
{
|
||||
struct priv *q = ao->priv;
|
||||
@ -420,7 +410,6 @@ const struct ao_driver audio_out_openal = {
|
||||
.pause = audio_pause,
|
||||
.resume = audio_resume,
|
||||
.reset = reset,
|
||||
.drain = drain,
|
||||
.priv_size = sizeof(struct priv),
|
||||
.priv_defaults = &(const struct priv) {
|
||||
.num_buffers = 4,
|
||||
|
@ -278,15 +278,6 @@ static bool select_chmap(struct ao *ao, pa_channel_map *dst)
|
||||
chmap_pa_from_mp(dst, &ao->channels);
|
||||
}
|
||||
|
||||
static void drain(struct ao *ao)
|
||||
{
|
||||
struct priv *priv = ao->priv;
|
||||
if (priv->stream) {
|
||||
pa_threaded_mainloop_lock(priv->mainloop);
|
||||
waitop(priv, pa_stream_drain(priv->stream, success_cb, ao));
|
||||
}
|
||||
}
|
||||
|
||||
static void uninit(struct ao *ao)
|
||||
{
|
||||
struct priv *priv = ao->priv;
|
||||
@ -826,7 +817,6 @@ const struct ao_driver audio_out_pulse = {
|
||||
.get_delay = get_delay,
|
||||
.pause = pause,
|
||||
.resume = resume,
|
||||
.drain = drain,
|
||||
.wait = wait_audio,
|
||||
.wakeup = wakeup,
|
||||
.hotplug_init = hotplug_init,
|
||||
|
@ -403,19 +403,21 @@ void ao_drain(struct ao *ao)
|
||||
p->final_chunk = true;
|
||||
wakeup_playthread(ao);
|
||||
double left = 0;
|
||||
if (p->playing && !p->paused)
|
||||
if (p->playing && !p->paused && !ao->driver->encode)
|
||||
left = mp_ring_buffered(p->buffers[0]) / (double)ao->bps * 1e6;
|
||||
pthread_mutex_unlock(&p->lock);
|
||||
|
||||
// Wait for lower bound.
|
||||
mp_sleep_us(left);
|
||||
// And then poll for actual end. (Unfortunately, this code considers
|
||||
// audio APIs which do not want you to use mutexes in the audio
|
||||
// callback, and an extra semaphore would require slightly more effort.)
|
||||
// Limit to arbitrary ~250ms max. waiting for robustness.
|
||||
int64_t max = mp_time_us() + 250000;
|
||||
while (mp_time_us() < max && !ao_eof_reached(ao))
|
||||
mp_sleep_us(1);
|
||||
if (left > 0) {
|
||||
// Wait for lower bound.
|
||||
mp_sleep_us(left);
|
||||
// And then poll for actual end. (Unfortunately, this code considers
|
||||
// audio APIs which do not want you to use mutexes in the audio
|
||||
// callback, and an extra semaphore would require slightly more effort.)
|
||||
// Limit to arbitrary ~250ms max. waiting for robustness.
|
||||
int64_t max = mp_time_us() + 250000;
|
||||
while (mp_time_us() < max && !ao_eof_reached(ao))
|
||||
mp_sleep_us(1);
|
||||
}
|
||||
|
||||
ao_reset(ao);
|
||||
}
|
||||
|
@ -107,7 +107,6 @@ bool init_buffer_post(struct ao *ao);
|
||||
* resume
|
||||
* Optional:
|
||||
* control
|
||||
* drain
|
||||
* wait
|
||||
* wakeup
|
||||
* b) ->play must be NULL. ->resume must be provided, and should make the
|
||||
@ -162,8 +161,6 @@ struct ao_driver {
|
||||
int (*play)(struct ao *ao, void **data, int samples, int flags);
|
||||
// push based: see ao_get_delay()
|
||||
double (*get_delay)(struct ao *ao);
|
||||
// push based: block until all queued audio is played (optional)
|
||||
void (*drain)(struct ao *ao);
|
||||
// Optional. Return true if audio has stopped in any way.
|
||||
bool (*get_eof)(struct ao *ao);
|
||||
// Wait until the audio buffer needs to be refilled. The lock is the
|
||||
|
Loading…
Reference in New Issue
Block a user