Commit fc81dcfa authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

sndio: emulate flush

This is really crappy, but it's as good as I can make it with such a
dumb interface.
parent 03c7740c
...@@ -46,6 +46,7 @@ vlc_module_end () ...@@ -46,6 +46,7 @@ vlc_module_end ()
static int TimeGet (audio_output, mtime_t *); static int TimeGet (audio_output, mtime_t *);
static void Play (audio_output_t *, block_t *); static void Play (audio_output_t *, block_t *);
static void Pause (audio_output_t *, bool, mtime_t); static void Pause (audio_output_t *, bool, mtime_t);
static void Flush (audio_output_t *, bool);
static int VolumeSet (audio_output_t *, float); static int VolumeSet (audio_output_t *, float);
static int MuteSet (audio_output_t *, bool); static int MuteSet (audio_output_t *, bool);
static void VolumeChanged (void *, unsigned); static void VolumeChanged (void *, unsigned);
...@@ -59,6 +60,7 @@ struct aout_sys_t ...@@ -59,6 +60,7 @@ struct aout_sys_t
unsigned rate; unsigned rate;
unsigned volume; unsigned volume;
bool mute; bool mute;
bool paused;
}; };
/** Initializes an sndio playback stream */ /** Initializes an sndio playback stream */
...@@ -158,7 +160,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -158,7 +160,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
aout->time_get = TimeGet; aout->time_get = TimeGet;
aout->play = Play; aout->play = Play;
aout->pause = Pause; aout->pause = Pause;
aout->flush = NULL; /* sndio sucks! */ aout->flush = Flush;
if (sio_onvol(sys->hdl, VolumeChanged, aout)) if (sio_onvol(sys->hdl, VolumeChanged, aout))
{ {
aout->volume_set = VolumeSet; aout->volume_set = VolumeSet;
...@@ -172,6 +174,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -172,6 +174,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
sys->read_offset = 0; sys->read_offset = 0;
sys->write_offset = 0; sys->write_offset = 0;
sys->paused = false;
sio_onmove (sys->hdl, PositionChanged, aout); sio_onmove (sys->hdl, PositionChanged, aout);
sio_start (sys->hdl); sio_start (sys->hdl);
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -238,9 +241,33 @@ static void Pause (audio_output_t *aout, bool pause, mtime_t date) ...@@ -238,9 +241,33 @@ static void Pause (audio_output_t *aout, bool pause, mtime_t date)
sys->write_offset = 0; sys->write_offset = 0;
sio_start (sys->hdl); sio_start (sys->hdl);
} }
sys->paused = pause;
(void) date; (void) date;
} }
static void Drain (audio_output_t *aout)
{
long long frames = sys->write_offset - sys->read_offset;
if (frames > 0)
msleep (frames * CLOCK_FREQ / sys->rate);
}
static void Flush (audio_output_t *aout, bool wait)
{
if (wait)
{
Drain (aout);
}
else
{
if (sys->paused)
return;
Pause (aout, true);
Pause (aout, false);
}
}
static void VolumeChanged (void *arg, unsigned volume) static void VolumeChanged (void *arg, unsigned volume)
{ {
audio_output_t *aout = arg; audio_output_t *aout = arg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment