[vlc-commits] audiounit: update device latency when the route changes

Thomas Guillem git at videolan.org
Wed Jul 17 16:57:07 CEST 2019


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Jul 17 15:56:03 2019 +0200| [e2b5eb9b880380448587b32546a279497d626d96] | committer: Thomas Guillem

audiounit: update device latency when the route changes

(cherry picked from commit b46f49a81ce75d026b9fac1d00f5568c4a5ce6d3)

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

 modules/audio_output/audiounit_ios.m    |  7 +++++++
 modules/audio_output/coreaudio_common.c | 10 ++++++++++
 modules/audio_output/coreaudio_common.h |  2 ++
 3 files changed, 19 insertions(+)

diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index 45c18c0d61..29b46da5f0 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -170,6 +170,7 @@ enum port_type
 - (void)audioSessionRouteChange:(NSNotification *)notification
 {
     audio_output_t *p_aout = [self aout];
+    struct aout_sys_t *p_sys = p_aout->sys;
     NSDictionary *userInfo = notification.userInfo;
     NSInteger routeChangeReason =
         [[userInfo valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
@@ -179,6 +180,12 @@ enum port_type
     if (routeChangeReason == AVAudioSessionRouteChangeReasonNewDeviceAvailable
      || routeChangeReason == AVAudioSessionRouteChangeReasonOldDeviceUnavailable)
         aout_RestartRequest(p_aout, AOUT_RESTART_OUTPUT);
+    else
+    {
+        const mtime_t latency_us = [p_sys->avInstance outputLatency] * CLOCK_FREQ;
+        ca_SetDeviceLatency(p_aout, latency_us);
+        msg_Dbg(p_aout, "Current device has a new latency of %lld us", latency_us);
+    }
 }
 
 - (void)handleInterruption:(NSNotification *)notification
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index 8d7f33fdf5..223bf41ed3 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -437,6 +437,16 @@ ca_SetAliveState(audio_output_t *p_aout, bool alive)
         vlc_sem_post(&p_sys->flush_sem);
 }
 
+void ca_SetDeviceLatency(audio_output_t *p_aout, mtime_t i_dev_latency_us)
+{
+    struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
+
+    lock_lock(p_sys);
+    /* cf. TODO in ca_Initialize */
+    p_sys->i_dev_latency_us = i_dev_latency_us > 1000000 ? 1000000 : i_dev_latency_us;
+    lock_unlock(p_sys);
+}
+
 AudioUnit
 au_NewOutputInstance(audio_output_t *p_aout, OSType comp_sub_type)
 {
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index c9c6873a37..6b0951b82b 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -103,6 +103,8 @@ void ca_Uninitialize(audio_output_t *p_aout);
 
 void ca_SetAliveState(audio_output_t *p_aout, bool alive);
 
+void ca_SetDeviceLatency(audio_output_t *p_aout, mtime_t i_dev_latency_us);
+
 AudioUnit au_NewOutputInstance(audio_output_t *p_aout, OSType comp_sub_type);
 
 int  au_Initialize(audio_output_t *p_aout, AudioUnit au,



More information about the vlc-commits mailing list