[vlc-commits] sndio: emulate flush
Rémi Denis-Courmont
git at videolan.org
Fri Nov 16 17:47:37 CET 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Nov 16 18:47:08 2012 +0200| [fc81dcfab88f3d0ed4d338c66643260aec608e3f] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fc81dcfab88f3d0ed4d338c66643260aec608e3f
---
modules/audio_output/sndio.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/modules/audio_output/sndio.c b/modules/audio_output/sndio.c
index 76479f0..54fca5e 100644
--- a/modules/audio_output/sndio.c
+++ b/modules/audio_output/sndio.c
@@ -46,6 +46,7 @@ vlc_module_end ()
static int TimeGet (audio_output, mtime_t *);
static void Play (audio_output_t *, block_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 MuteSet (audio_output_t *, bool);
static void VolumeChanged (void *, unsigned);
@@ -59,6 +60,7 @@ struct aout_sys_t
unsigned rate;
unsigned volume;
bool mute;
+ bool paused;
};
/** Initializes an sndio playback stream */
@@ -158,7 +160,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
aout->time_get = TimeGet;
aout->play = Play;
aout->pause = Pause;
- aout->flush = NULL; /* sndio sucks! */
+ aout->flush = Flush;
if (sio_onvol(sys->hdl, VolumeChanged, aout))
{
aout->volume_set = VolumeSet;
@@ -172,6 +174,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
sys->read_offset = 0;
sys->write_offset = 0;
+ sys->paused = false;
sio_onmove (sys->hdl, PositionChanged, aout);
sio_start (sys->hdl);
return VLC_SUCCESS;
@@ -238,9 +241,33 @@ static void Pause (audio_output_t *aout, bool pause, mtime_t date)
sys->write_offset = 0;
sio_start (sys->hdl);
}
+ sys->paused = pause;
(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)
{
audio_output_t *aout = arg;
More information about the vlc-commits
mailing list