ao_oss: return actual OSS playing state

fix: https://github.com/mpv-player/mpv/issues/10640
This commit is contained in:
rim 2023-02-12 19:22:47 +02:00 committed by Dudemanguy
parent 4502522a7a
commit 5afc0da530
1 changed files with 2 additions and 11 deletions

View File

@ -4,7 +4,7 @@
* Original author: A'rpi * Original author: A'rpi
* Support for >2 output channels added 2001-11-25 * Support for >2 output channels added 2001-11-25
* - Steve Davies <steve@daviesfam.org> * - Steve Davies <steve@daviesfam.org>
* Rozhuk Ivan <rozhuk.im@gmail.com> 2020 * Rozhuk Ivan <rozhuk.im@gmail.com> 2020-2023
* *
* This file is part of mpv. * This file is part of mpv.
* *
@ -52,7 +52,6 @@
struct priv { struct priv {
int dsp_fd; int dsp_fd;
bool playing;
double bps; /* Bytes per second. */ double bps; /* Bytes per second. */
}; };
@ -240,7 +239,6 @@ static int init(struct ao *ao)
ao->samplerate = samplerate; ao->samplerate = samplerate;
ao->channels = channels; ao->channels = channels;
p->bps = (channels.num * samplerate * af_fmt_to_bytes(format)); p->bps = (channels.num * samplerate * af_fmt_to_bytes(format));
p->playing = false;
return 0; return 0;
@ -260,7 +258,6 @@ static void uninit(struct ao *ao)
ioctl(p->dsp_fd, SNDCTL_DSP_HALT, NULL); ioctl(p->dsp_fd, SNDCTL_DSP_HALT, NULL);
close(p->dsp_fd); close(p->dsp_fd);
p->dsp_fd = -1; p->dsp_fd = -1;
p->playing = false;
} }
static int control(struct ao *ao, enum aocontrol cmd, void *arg) static int control(struct ao *ao, enum aocontrol cmd, void *arg)
@ -298,7 +295,6 @@ static void reset(struct ao *ao)
int trig = 0; int trig = 0;
/* Clear buf and do not start playback after data written. */ /* Clear buf and do not start playback after data written. */
p->playing = false;
if (ioctl(p->dsp_fd, SNDCTL_DSP_HALT, NULL) == -1 || if (ioctl(p->dsp_fd, SNDCTL_DSP_HALT, NULL) == -1 ||
ioctl(p->dsp_fd, SNDCTL_DSP_SETTRIGGER, &trig) == -1) ioctl(p->dsp_fd, SNDCTL_DSP_SETTRIGGER, &trig) == -1)
{ {
@ -318,7 +314,6 @@ static void start(struct ao *ao)
MP_WARN_IOCTL_ERR(ao); MP_WARN_IOCTL_ERR(ao);
return; return;
} }
p->playing = true;
} }
static bool audio_write(struct ao *ao, void **data, int samples) static bool audio_write(struct ao *ao, void **data, int samples)
@ -335,13 +330,11 @@ static bool audio_write(struct ao *ao, void **data, int samples)
continue; continue;
MP_WARN(ao, "audio_write: write() fail, err = %i: %s.\n", MP_WARN(ao, "audio_write: write() fail, err = %i: %s.\n",
errno, strerror(errno)); errno, strerror(errno));
p->playing = false;
return false; return false;
} }
if ((size_t)rc != size) { if ((size_t)rc != size) {
MP_WARN(ao, "audio_write: unexpected partial write: required: %zu, written: %zu.\n", MP_WARN(ao, "audio_write: unexpected partial write: required: %zu, written: %zu.\n",
size, (size_t)rc); size, (size_t)rc);
p->playing = false;
return false; return false;
} }
@ -358,7 +351,6 @@ static void get_state(struct ao *ao, struct mp_pcm_state *state)
ioctl(p->dsp_fd, SNDCTL_DSP_GETODELAY, &odelay) == -1) ioctl(p->dsp_fd, SNDCTL_DSP_GETODELAY, &odelay) == -1)
{ {
MP_WARN_IOCTL_ERR(ao); MP_WARN_IOCTL_ERR(ao);
p->playing = false;
memset(state, 0x00, sizeof(struct mp_pcm_state)); memset(state, 0x00, sizeof(struct mp_pcm_state));
state->delay = 0.0; state->delay = 0.0;
return; return;
@ -366,7 +358,7 @@ static void get_state(struct ao *ao, struct mp_pcm_state *state)
state->free_samples = (info.bytes / ao->sstride); state->free_samples = (info.bytes / ao->sstride);
state->queued_samples = (ao->device_buffer - state->free_samples); state->queued_samples = (ao->device_buffer - state->free_samples);
state->delay = (odelay / p->bps); state->delay = (odelay / p->bps);
state->playing = p->playing; state->playing = (state->queued_samples != 0);
} }
static void list_devs(struct ao *ao, struct ao_device_list *list) static void list_devs(struct ao *ao, struct ao_device_list *list)
@ -404,6 +396,5 @@ const struct ao_driver audio_out_oss = {
.priv_size = sizeof(struct priv), .priv_size = sizeof(struct priv),
.priv_defaults = &(const struct priv) { .priv_defaults = &(const struct priv) {
.dsp_fd = -1, .dsp_fd = -1,
.playing = false,
}, },
}; };