[vlc-commits] OSS audio output: Prefer GETODELAY over GETOSPACE.

Hans-Kristian Arntzen git at videolan.org
Sat Jul 30 10:01:12 CEST 2011


vlc | branch: master | Hans-Kristian Arntzen <maister at archlinux.us> | Wed Jul 27 20:50:14 2011 +0200| [e1e7a73c506ddd85a70ef2856f44c46e26d2c471] | committer: Rémi Denis-Courmont

OSS audio output: Prefer GETODELAY over GETOSPACE.

Fix the possibly wrong assumption that we're able to accurately
calculate latency using GETOSPACE
(buffer size - available bytes to write).

New code uses GETODELAY to get latency directly but falls back to
GETOSPACE calculation should GETODELAY fail.

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e1e7a73c506ddd85a70ef2856f44c46e26d2c471
---

 modules/audio_output/oss.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/modules/audio_output/oss.c b/modules/audio_output/oss.c
index eabcbbd..7446945 100644
--- a/modules/audio_output/oss.c
+++ b/modules/audio_output/oss.c
@@ -553,15 +553,22 @@ static mtime_t BufferDuration( audio_output_t * p_aout )
     audio_buf_info audio_buf;
     int i_bytes;
 
-    /* Fill the audio_buf_info structure:
-     * - fragstotal: total number of fragments allocated
-     * - fragsize: size of a fragment in bytes
-     * - bytes: available space in bytes (includes partially used fragments)
-     * Note! 'bytes' could be more than fragments*fragsize */
-    ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf );
-
-    /* calculate number of available fragments (not partially used ones) */
-    i_bytes = (audio_buf.fragstotal * audio_buf.fragsize) - audio_buf.bytes;
+#ifdef SNDCTL_DSP_GETODELAY
+    if ( ioctl( p_sys->i_fd, SNDCTL_DSP_GETODELAY, &i_bytes ) < 0 )
+#endif
+    {
+        /* Fall back to GETOSPACE and approximate latency. */
+
+        /* Fill the audio_buf_info structure:
+         * - fragstotal: total number of fragments allocated
+         * - fragsize: size of a fragment in bytes
+         * - bytes: available space in bytes (includes partially used fragments)
+         * Note! 'bytes' could be more than fragments*fragsize */
+        ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf );
+
+        /* calculate number of available fragments (not partially used ones) */
+        i_bytes = (audio_buf.fragstotal * audio_buf.fragsize) - audio_buf.bytes;
+    }
 
     /* Return the fragment duration */
     return (mtime_t)i_bytes * 1000000



More information about the vlc-commits mailing list