[vlc-commits] ALSA: get PCM delay and state in a single system call

Rémi Denis-Courmont git at videolan.org
Sat Nov 3 11:44:13 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov  3 12:42:27 2012 +0200| [38d91b7f06c21ab8e778d022cac31195027f8134] | committer: Rémi Denis-Courmont

ALSA: get PCM delay and state in a single system call

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

 modules/audio_output/alsa.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index aa056a1..af16da6 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -553,15 +553,20 @@ static void Play (audio_output_t *aout, block_t *block,
                       sys->format.i_bitspersample / 8);
 
     snd_pcm_t *pcm = sys->pcm;
-    snd_pcm_sframes_t frames;
-    snd_pcm_state_t state = snd_pcm_state (pcm);
+    snd_pcm_status_t *status;
+    int val;
 
-    if (snd_pcm_delay (pcm, &frames) == 0)
+    snd_pcm_status_alloca (&status);
+    val = snd_pcm_status (pcm, status);
+    if (val < 0)
+        msg_Err (aout, "cannot get status: %s", snd_strerror (val));
+    else
     {
+        snd_pcm_sframes_t frames = snd_pcm_status_get_delay (status);
         mtime_t delay = frames * CLOCK_FREQ / sys->format.i_rate;
         delay += mdate () - block->i_pts;
 
-        if (state != SND_PCM_STATE_RUNNING)
+        if (snd_pcm_status_get_state (status) != SND_PCM_STATE_RUNNING)
         {
             if (delay < 0)
             {
@@ -597,6 +602,8 @@ static void Play (audio_output_t *aout, block_t *block,
 
     while (block->i_nb_samples > 0)
     {
+        snd_pcm_sframes_t frames;
+
         frames = snd_pcm_writei (pcm, block->p_buffer, block->i_nb_samples);
         if (frames >= 0)
         {



More information about the vlc-commits mailing list