[vlc-commits] audiounit_ios: merge the two Start functions

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 15:25:24 2017 +0100| [81a42e301c7216ac0e15d665dadb1b05dc49c589] | committer: Thomas Guillem

audiounit_ios: merge the two Start functions

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

 modules/audio_output/audiounit_ios.m | 116 +++++++++++++++--------------------
 1 file changed, 49 insertions(+), 67 deletions(-)

diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index 1c757ca..432e35f 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -167,14 +167,45 @@ Play(audio_output_t * p_aout, block_t * p_block)
 
 #pragma mark initialization
 
-/*
- * StartAnalog: open and setup a HAL AudioUnit to do PCM audio output
- */
+static void
+Stop(audio_output_t *p_aout)
+{
+    struct aout_sys_t   *p_sys = p_aout->sys;
+    OSStatus err;
+
+    err = AudioOutputUnitStop(p_sys->au_unit);
+    if (err != noErr)
+        msg_Warn(p_aout, "AudioOutputUnitStop failed [%4.4s]",
+                 (const char *)&err);
+
+    err = AudioUnitUninitialize(p_sys->au_unit);
+    if (err != noErr)
+        msg_Warn(p_aout, "AudioUnitUninitialize failed [%4.4s]",
+                 (const char *)&err);
+
+    err = AudioComponentInstanceDispose(p_sys->au_unit);
+    if (err != noErr)
+        msg_Warn(p_aout, "AudioComponentInstanceDispose failed [%4.4s]",
+                 (const char *)&err);
+
+    avas_SetActive(p_aout, false,
+                   AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation);
+
+    ca_Clean(p_aout);
+}
+
 static int
-StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
+Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
 {
-    struct aout_sys_t           *p_sys = p_aout->sys;
-    OSStatus status;
+    struct aout_sys_t *p_sys = p_aout->sys;
+    OSStatus err;
+
+    if (aout_FormatNbChannels(fmt) == 0)
+        return VLC_EGENERIC;
+
+    aout_FormatPrint(p_aout, "VLC is looking for:", fmt);
+
+    p_sys->au_unit = NULL;
 
     /* Activate the AVAudioSession */
     if (avas_SetActive(p_aout, true, 0) != VLC_SUCCESS)
@@ -187,12 +218,12 @@ StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
     if (p_sys->au_unit == NULL)
         goto error;
 
-    status = AudioUnitSetProperty(p_sys->au_unit,
-                                  kAudioOutputUnitProperty_EnableIO,
-                                  kAudioUnitScope_Output, 0,
-                                  &(UInt32){ 1 }, sizeof(UInt32));
-    if (status != noErr)
-        msg_Warn(p_aout, "failed to set IO mode (%i)", (int)status);
+    err = AudioUnitSetProperty(p_sys->au_unit,
+                               kAudioOutputUnitProperty_EnableIO,
+                               kAudioUnitScope_Output, 0,
+                               &(UInt32){ 1 }, sizeof(UInt32));
+    if (err != noErr)
+        msg_Warn(p_aout, "failed to set IO mode [%4.4s]", (const char *)&err);
 
     int ret = au_Initialize(p_aout, p_sys->au_unit, fmt, NULL);
     if (ret != VLC_SUCCESS)
@@ -207,11 +238,11 @@ StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
     }
     p_aout->play = Play;
 
-    status = AudioOutputUnitStart(p_sys->au_unit);
-    if (status != noErr)
+    err = AudioOutputUnitStart(p_sys->au_unit);
+    if (err != noErr)
     {
         msg_Err(p_aout, "AudioOutputUnitStart failed [%4.4s]",
-                (const char *) &status);
+                (const char *) &err);
         AudioUnitUninitialize(p_sys->au_unit);
         ca_Clean(p_aout);
         goto error;
@@ -220,64 +251,15 @@ StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
     if (p_sys->b_muted)
         Pause(p_aout, true, 0);
 
+    p_aout->mute_set  = MuteSet;
+    p_aout->pause = Pause;
+    msg_Dbg(p_aout, "analog AudioUnit output successfully opened");
     return VLC_SUCCESS;
 
 error:
     avas_SetActive(p_aout, false,
                    AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation);
     AudioComponentInstanceDispose(p_sys->au_unit);
-    return VLC_EGENERIC;
-}
-
-static void
-Stop(audio_output_t *p_aout)
-{
-    struct aout_sys_t   *p_sys = p_aout->sys;
-    OSStatus err;
-
-    err = AudioOutputUnitStop(p_sys->au_unit);
-    if (err != noErr)
-        msg_Warn(p_aout, "AudioOutputUnitStop failed [%4.4s]",
-                 (const char *)&err);
-
-    err = AudioUnitUninitialize(p_sys->au_unit);
-    if (err != noErr)
-        msg_Warn(p_aout, "AudioUnitUninitialize failed [%4.4s]",
-                 (const char *)&err);
-
-    err = AudioComponentInstanceDispose(p_sys->au_unit);
-    if (err != noErr)
-        msg_Warn(p_aout, "AudioComponentInstanceDispose failed [%4.4s]",
-                 (const char *)&err);
-
-    avas_SetActive(p_aout, false,
-                   AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation);
-
-    ca_Clean(p_aout);
-}
-
-static int
-Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
-{
-    struct aout_sys_t *p_sys = NULL;
-
-    if (aout_FormatNbChannels(fmt) == 0)
-        return VLC_EGENERIC;
-
-    p_sys = p_aout->sys;
-    p_sys->au_unit = NULL;
-
-    aout_FormatPrint(p_aout, "VLC is looking for:", fmt);
-
-    if (StartAnalog(p_aout, fmt) == VLC_SUCCESS) {
-        msg_Dbg(p_aout, "analog AudioUnit output successfully opened");
-        p_aout->mute_set  = MuteSet;
-        p_aout->pause = Pause;
-
-        return VLC_SUCCESS;
-    }
-
-    /* If we reach this, this aout has failed */
     msg_Err(p_aout, "opening AudioUnit output failed");
     return VLC_EGENERIC;
 }



More information about the vlc-commits mailing list