[vlc-commits] coreaudio: add a way to set latency in us

Thomas Guillem git at videolan.org
Wed Mar 1 17:49:53 CET 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Mar  1 11:47:04 2017 +0100| [5e9498f1fe7d6397944b2f5ed44300cb422f4545] | committer: Thomas Guillem

coreaudio: add a way to set latency in us

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

 modules/audio_output/auhal.c            | 11 ++++++-----
 modules/audio_output/coreaudio_common.c |  4 ++--
 modules/audio_output/coreaudio_common.h |  6 ++++--
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index eb6607e..63b84cd 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -1385,7 +1385,7 @@ Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
     p_sys->i_stream_index = -1;
     p_sys->b_revert = false;
     p_sys->b_changed_mixing = false;
-    p_sys->c.i_device_latency = 0;
+    p_sys->c.i_latency_samples = 0;
 
     vlc_mutex_lock(&p_sys->selected_device_lock);
     p_sys->i_selected_dev = p_sys->i_new_selected_dev;
@@ -1488,17 +1488,18 @@ Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
     }
 
     /* get device latency */
-    AO_GET1PROP(p_sys->i_selected_dev, UInt32, &p_sys->c.i_device_latency,
+    AO_GET1PROP(p_sys->i_selected_dev, UInt32, &p_sys->c.i_latency_samples,
                 kAudioDevicePropertyLatency, kAudioObjectPropertyScopeOutput);
-    float f_latency_in_sec = (float)p_sys->c.i_device_latency / (float)fmt->i_rate;
+    float f_latency_in_sec = (float)p_sys->c.i_latency_samples
+                           / (float)fmt->i_rate;
     msg_Dbg(p_aout, "Current device has a latency of %u frames (%f sec)",
-            p_sys->c.i_device_latency, f_latency_in_sec);
+            p_sys->c.i_latency_samples, f_latency_in_sec);
 
     /* Ignore long Airplay latency as this is not correctly working yet */
     if (f_latency_in_sec > 0.5f)
     {
         msg_Info(p_aout, "Ignore high latency as it causes problems currently.");
-        p_sys->c.i_device_latency = 0;
+        p_sys->c.i_latency_samples = 0;
     }
 
     /* Check for Digital mode or Analog output mode */
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index e84cbc4..7bc8494 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -85,8 +85,8 @@ ca_TimeGet(audio_output_t *p_aout, mtime_t *delay)
     int32_t i_bytes;
     TPCircularBufferTail(&p_sys->circular_buffer, &i_bytes);
 
-    int64_t i_frames = BytesToFrames(p_sys, i_bytes) + p_sys->i_device_latency;
-    *delay = FramesToUs(p_sys, i_frames);
+    int64_t i_frames = BytesToFrames(p_sys, i_bytes) + p_sys->i_latency_samples;
+    *delay = FramesToUs(p_sys, i_frames) + p_sys->i_latency_us;
 
     return 0;
 }
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index 21831cf..8c71f76 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -58,8 +58,10 @@ struct aout_sys_common
 
     /* The following need to set by the caller */
 
-    /* The time the device needs to process the data. In samples. */
-    uint32_t            i_device_latency;
+    /* ca_TimeGet extra latency, in samples. */
+    uint32_t            i_latency_samples;
+    /* ca_TimeGet extra latency, in micro-seconds */
+    mtime_t             i_latency_us;
 };
 
 void ca_Render(audio_output_t *p_aout, uint8_t *p_output, size_t i_requested);



More information about the vlc-commits mailing list