[vlc-commits] auhal: use audio device latency for better a/ v synchronization and airplay support

David Fuhrmann git at videolan.org
Thu Apr 10 11:45:51 CEST 2014


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Wed Apr  9 18:56:00 2014 +0200| [1702e77aeb284e52b482b667bb77c982426dc447] | committer: David Fuhrmann

auhal: use audio device latency for better a/v synchronization and airplay support

refs #7127

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

 modules/audio_output/auhal.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index 5cec0ad..e512bc3 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -117,6 +117,8 @@ struct aout_sys_t
     vlc_cond_t                  cond;
 
     bool                        b_ignore_streams_changed_callback;
+
+    UInt32                      i_device_latency;    /* The time the device needs to process the data. In samples. */
 };
 
 #pragma mark -
@@ -314,6 +316,7 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
     p_sys->b_changed_mixing = false;
     p_sys->i_bytes_per_sample = 0;
     p_sys->b_paused = false;
+    p_sys->i_device_latency = 0;
 
     vlc_mutex_lock(&p_sys->var_lock);
     p_sys->i_selected_dev = p_sys->i_new_selected_dev;
@@ -409,6 +412,22 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
         goto error;
     }
 
+    /* get device latency */
+    AudioObjectPropertyAddress latencyAddress = { kAudioDevicePropertyLatency, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
+    i_param_size = sizeof(p_sys->i_device_latency);
+    err = AudioObjectGetPropertyData(p_sys->i_selected_dev,
+                                     &latencyAddress,
+                                     0,
+                                     NULL,
+                                     &i_param_size,
+                                     &p_sys->i_device_latency);
+    if (err != noErr) {
+        msg_Warn(p_aout, "Cannot get device latency [%4.4s]",
+                 (char *)&err);
+    }
+    msg_Dbg(p_aout, "Current device has a latency of %u frames", p_sys->i_device_latency);
+
+
     bool b_success = false;
 
     /* Check for Digital mode or Analog output mode */
@@ -1424,7 +1443,7 @@ static int TimeGet(audio_output_t *p_aout, mtime_t *delay)
     int32_t availableBytes;
     TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
 
-    *delay = (availableBytes / p_sys->i_bytes_per_sample) * CLOCK_FREQ / p_sys->i_rate;
+    *delay = ((availableBytes / p_sys->i_bytes_per_sample) + p_sys->i_device_latency) * CLOCK_FREQ / p_sys->i_rate;
 
     return 0;
 }



More information about the vlc-commits mailing list