On Thu, Mar 24, 2022 at 07:11:42AM +0100, Alexandre Ratchov wrote: > Most audio/video players do a stop/start cycle whenever the play > position is changed, track is changed, etc. Currently, stopping drains > the play buffer, which by default is very large (to workaround very > long kernel non-preemptive code-paths). This makes player controls > sluggish. > > This diff adds a new sio_flush() function to workaround the jumbo > buffer sizes: it stops playback immediately, discarding buffered > data. Basically it's the same as sio_stop() but doesn't wait. The plan > is to make players use it. > > In the network protocol, sio_flush() is implemented by adding a flag > to the message corresponding to sio_stop(). Old sndiod servers ignore > it and just work with new libraries. New sndiod servers see that the > flag is not set by old libraries and properly drain the play buffer. > > Tested with mplayer, mpv and audacious, if we go this way other ports > will follow. >
Here's the diff to make mplayer, mpv and audacious use the new function. As you see, sio_stop() and sio_flush() are perfectly interchangable. The only difference is the time the function takes to complete (and the resulting silence). Index: x11/mplayer/Makefile =================================================================== RCS file: /cvs/ports/x11/mplayer/Makefile,v retrieving revision 1.319 diff -u -p -r1.319 Makefile --- x11/mplayer/Makefile 11 Mar 2022 20:16:48 -0000 1.319 +++ x11/mplayer/Makefile 23 Mar 2022 19:49:08 -0000 @@ -3,7 +3,7 @@ COMMENT= movie player supporting many fo V= 20211106 FFMPEG_V= 4.4.1 DISTNAME= mplayer-${V} -REVISION= 0 +REVISION= 1 CATEGORIES= x11 multimedia MASTER_SITES= https://comstyle.com/source/ EXTRACT_SUFX= .tar.xz Index: x11/mplayer/patches/patch-libao2_ao_sndio_c =================================================================== RCS file: x11/mplayer/patches/patch-libao2_ao_sndio_c diff -N x11/mplayer/patches/patch-libao2_ao_sndio_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ x11/mplayer/patches/patch-libao2_ao_sndio_c 23 Mar 2022 19:49:08 -0000 @@ -0,0 +1,21 @@ +Index: libao2/ao_sndio.c +--- libao2/ao_sndio.c.orig ++++ libao2/ao_sndio.c +@@ -179,7 +179,7 @@ static void uninit(int immed) + */ + static void reset(void) + { +- if (!sio_stop(hdl)) ++ if (!sio_flush(hdl)) + mp_msg(MSGT_AO, MSGL_ERR, "ao2: reset: couldn't stop\n"); + delay = 0; + if (!sio_start(hdl)) +@@ -235,7 +235,7 @@ static void audio_pause(void) + * sndio can't pause, so just stop + */ + prepause_delay = delay; +- if (!sio_stop(hdl)) ++ if (!sio_flush(hdl)) + mp_msg(MSGT_AO, MSGL_ERR, "ao2: pause: couldn't stop\n"); + delay = 0; + } Index: multimedia/mpv/Makefile =================================================================== RCS file: /cvs/ports/multimedia/mpv/Makefile,v retrieving revision 1.81 diff -u -p -r1.81 Makefile --- multimedia/mpv/Makefile 11 Mar 2022 19:39:24 -0000 1.81 +++ multimedia/mpv/Makefile 23 Mar 2022 19:49:08 -0000 @@ -4,7 +4,7 @@ GH_ACCOUNT = mpv-player GH_PROJECT = mpv GH_TAGNAME = v0.34.1 -REVISION = 0 +REVISION = 1 SHARED_LIBS += mpv 0.2 # 1.109 Index: multimedia/mpv/patches/patch-audio_out_ao_sndio_c =================================================================== RCS file: /cvs/ports/multimedia/mpv/patches/patch-audio_out_ao_sndio_c,v retrieving revision 1.6 diff -u -p -r1.6 patch-audio_out_ao_sndio_c --- multimedia/mpv/patches/patch-audio_out_ao_sndio_c 11 Mar 2022 19:39:24 -0000 1.6 +++ multimedia/mpv/patches/patch-audio_out_ao_sndio_c 23 Mar 2022 19:49:09 -0000 @@ -245,8 +245,8 @@ Index: audio/out/ao_sndio.c + if (p->playing) { + p->playing = false; + -+ if (!sio_stop(p->hdl)) { -+ MP_ERR(ao, "reset: couldn't sio_stop()\n"); ++ if (!sio_flush(p->hdl)) { ++ MP_ERR(ao, "reset: couldn't sio_flush()\n"); + } + p->delay = 0; + if (!sio_start(p->hdl)) { Index: audio/audacious/plugins/Makefile =================================================================== RCS file: /cvs/ports/audio/audacious/plugins/Makefile,v retrieving revision 1.10 diff -u -p -r1.10 Makefile --- audio/audacious/plugins/Makefile 8 Mar 2022 08:53:50 -0000 1.10 +++ audio/audacious/plugins/Makefile 23 Mar 2022 19:49:09 -0000 @@ -1,7 +1,7 @@ COMMENT = input and output plugins for Audacious DISTNAME = audacious-plugins-${VERSION} -REVISION = 2 +REVISION = 3 # BSD / GPL PERMIT_PACKAGE = Yes Index: audio/audacious/plugins/patches/patch-src_sndio_sndio_cc =================================================================== RCS file: audio/audacious/plugins/patches/patch-src_sndio_sndio_cc diff -N audio/audacious/plugins/patches/patch-src_sndio_sndio_cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ audio/audacious/plugins/patches/patch-src_sndio_sndio_cc 23 Mar 2022 19:49:09 -0000 @@ -0,0 +1,12 @@ +Index: src/sndio/sndio.cc +--- src/sndio/sndio.cc.orig ++++ src/sndio/sndio.cc +@@ -344,7 +344,7 @@ void SndioPlugin::flush () + { + pthread_mutex_lock (& m_mutex); + +- sio_stop (m_handle); ++ sio_flush (m_handle); + + m_frames_buffered = 0; + m_last_write_time = timeval ();