[vlc-commits] aout: coreaudio: add Open/Close helpers

Thomas Guillem git at videolan.org
Fri Sep 8 13:46:23 CEST 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Sep  8 12:55:57 2017 +0200| [0e518afc950210620b12f198d4e02e2cbf8a85b3] | committer: Thomas Guillem

aout: coreaudio: add Open/Close helpers

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

 modules/audio_output/audiounit_ios.m    |  2 ++
 modules/audio_output/auhal.c            |  2 ++
 modules/audio_output/coreaudio_common.c | 36 ++++++++++++++++++++++++---------
 modules/audio_output/coreaudio_common.h |  4 ++++
 4 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index e87ffeee91..25859f2163 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -499,6 +499,7 @@ Close(vlc_object_t *obj)
 
     [sys->aoutWrapper release];
 
+    ca_Close(aout);
     free(sys);
 }
 
@@ -532,5 +533,6 @@ Open(vlc_object_t *obj)
     for (unsigned int i = 0; i< sizeof(au_devs) / sizeof(au_devs[0]); ++i)
         aout_HotplugReport(aout, au_devs[i].psz_id, au_devs[i].psz_name);
 
+    ca_Open(aout);
     return VLC_SUCCESS;
 }
diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index db3a36c52a..6bf1f202c1 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -1592,6 +1592,7 @@ static void Close(vlc_object_t *obj)
     vlc_mutex_destroy(&p_sys->selected_device_lock);
     vlc_mutex_destroy(&p_sys->device_list_lock);
 
+    ca_Close(p_aout);
     free(p_sys);
 }
 
@@ -1655,5 +1656,6 @@ static int Open(vlc_object_t *obj)
     SwitchAudioDevice(p_aout, psz_audio_device);
     free(psz_audio_device);
 
+    ca_Open(p_aout);
     return VLC_SUCCESS;
 }
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index 75e12df3bc..6e78b07e1a 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -42,6 +42,30 @@ FramesToUs(struct aout_sys_common *p_sys, uint64_t i_nb_frames)
     return i_nb_frames * CLOCK_FREQ / p_sys->i_rate;
 }
 
+void
+ca_Open(audio_output_t *p_aout)
+{
+    struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
+
+    atomic_init(&p_sys->i_underrun_size, 0);
+    atomic_init(&p_sys->b_paused, false);
+    atomic_init(&p_sys->b_do_flush, false);
+    vlc_sem_init(&p_sys->flush_sem, 0);
+
+    p_aout->play = ca_Play;
+    p_aout->pause = ca_Pause;
+    p_aout->flush = ca_Flush;
+    p_aout->time_get = ca_TimeGet;
+}
+
+void
+ca_Close(audio_output_t *p_aout)
+{
+    struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
+
+    vlc_sem_destroy(&p_sys->flush_sem);
+}
+
 /* Called from render callbacks. No lock, wait, and IO here */
 void
 ca_Render(audio_output_t *p_aout, uint8_t *p_output, size_t i_requested)
@@ -191,11 +215,8 @@ ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt,
 {
     struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
 
-    atomic_init(&p_sys->i_underrun_size, 0);
-    atomic_init(&p_sys->b_paused, false);
-    atomic_init(&p_sys->b_do_flush, false);
-    vlc_sem_init(&p_sys->flush_sem, 0);
-
+    atomic_store(&p_sys->i_underrun_size, 0);
+    atomic_store(&p_sys->b_paused, false);
     p_sys->i_rate = fmt->i_rate;
     p_sys->i_bytes_per_frame = fmt->i_bytes_per_frame;
     p_sys->i_frame_length = fmt->i_frame_length;
@@ -230,10 +251,6 @@ ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt,
     if (!TPCircularBufferInit(&p_sys->circular_buffer, i_audiobuffer_size))
         return VLC_EGENERIC;
 
-    p_aout->play = ca_Play;
-    p_aout->pause = ca_Pause;
-    p_aout->flush = ca_Flush;
-    p_aout->time_get = ca_TimeGet;
     return VLC_SUCCESS;
 }
 
@@ -244,7 +261,6 @@ ca_Uninitialize(audio_output_t *p_aout)
 
     /* clean-up circular buffer */
     TPCircularBufferCleanup(&p_sys->circular_buffer);
-    vlc_sem_destroy(&p_sys->flush_sem);
 }
 
 AudioUnit
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index 8d0ec10374..6719db6580 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -65,6 +65,10 @@ struct aout_sys_common
     mtime_t             i_dev_latency_us;
 };
 
+void ca_Open(audio_output_t *p_aout);
+
+void ca_Close(audio_output_t *p_aout);
+
 void ca_Render(audio_output_t *p_aout, uint8_t *p_output, size_t i_requested);
 
 int  ca_TimeGet(audio_output_t *p_aout, mtime_t *delay);



More information about the vlc-commits mailing list