[vlc-commits] coreaudio: rework initialization
Thomas Guillem
git at videolan.org
Thu Mar 2 18:16:52 CET 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Mar 2 10:10:17 2017 +0100| [f3d6aec4ea98d92cc2862215494a0d9b567b47a0] | committer: Thomas Guillem
coreaudio: rework initialization
Rename ca_Init() to ca_Initialize() and ca_Clean() to ca_Uninitialize().
au_Initialize() calls now ca_Initialize().
Add au_Uninitialize() that calls ca_Uninitialize().
Functions starting with ca_ are generic and used by AudioUnit (auhal and
audiounit_ios) or AudioDevice (only auhal for passthrough on macOS).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f3d6aec4ea98d92cc2862215494a0d9b567b47a0
---
modules/audio_output/audiounit_ios.m | 19 ++-----------------
modules/audio_output/auhal.c | 19 ++++---------------
modules/audio_output/coreaudio_common.c | 27 ++++++++++++++++++++++++---
modules/audio_output/coreaudio_common.h | 8 +++++---
4 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index de56c65..f85bd1e 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -50,8 +50,6 @@ vlc_module_end ()
#pragma mark -
#pragma mark private declarations
-#define AUDIO_BUFFER_SIZE_IN_SECONDS (AOUT_MAX_ADVANCE_TIME / CLOCK_FREQ)
-
/* aout wrapper: used as observer for notifications */
@interface AoutWrapper : NSObject
- (instancetype)initWithAout:(audio_output_t *)aout;
@@ -317,10 +315,7 @@ Stop(audio_output_t *p_aout)
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);
+ au_Uninitialize(p_aout, p_sys->au_unit);
err = AudioComponentInstanceDispose(p_sys->au_unit);
if (err != noErr)
@@ -329,8 +324,6 @@ Stop(audio_output_t *p_aout)
avas_SetActive(p_aout, false,
AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation);
-
- ca_Clean(p_aout);
}
static int
@@ -378,13 +371,6 @@ Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
if (ret != VLC_SUCCESS)
goto error;
- ret = ca_Init(p_aout, fmt, AUDIO_BUFFER_SIZE_IN_SECONDS * fmt->i_rate *
- fmt->i_bytes_per_frame);
- if (ret != VLC_SUCCESS)
- {
- AudioUnitUninitialize(p_sys->au_unit);
- goto error;
- }
p_aout->play = Play;
err = AudioOutputUnitStart(p_sys->au_unit);
@@ -392,8 +378,7 @@ Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
{
msg_Err(p_aout, "AudioOutputUnitStart failed [%4.4s]",
(const char *) &err);
- AudioUnitUninitialize(p_sys->au_unit);
- ca_Clean(p_aout);
+ au_Uninitialize(p_aout, p_sys->au_unit);
goto error;
}
diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index 63b84cd..cd1c7d5 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -67,8 +67,6 @@ vlc_module_end ()
#define AOUT_VAR_SPDIF_FLAG 0xf00000
-#define AUDIO_BUFFER_SIZE_IN_SECONDS ((AOUT_MAX_ADVANCE_TIME + CLOCK_FREQ) / CLOCK_FREQ)
-
/*****************************************************************************
* aout_sys_t: private audio output method descriptor
*****************************************************************************
@@ -998,20 +996,12 @@ StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
if (ret != VLC_SUCCESS)
goto error;
- ret = ca_Init(p_aout, fmt, AUDIO_BUFFER_SIZE_IN_SECONDS * fmt->i_rate *
- fmt->i_bytes_per_frame);
- if (ret != VLC_SUCCESS)
- {
- AudioUnitUninitialize(p_sys->au_unit);
- goto error;
- }
-
err = AudioOutputUnitStart(p_sys->au_unit);
if (err != noErr)
{
- AudioUnitUninitialize(p_sys->au_unit);
msg_Err(p_aout, "AudioUnitInitialize failed: [%4.4s]",
(const char *)&err);
+ au_Uninitialize(p_aout, p_sys->au_unit);
goto error;
}
@@ -1250,7 +1240,7 @@ StartSPDIF(audio_output_t * p_aout, audio_sample_format_t *fmt)
return VLC_EGENERIC;
}
- ret = ca_Init(p_aout, fmt, 200 * AOUT_SPDIF_SIZE);
+ ret = ca_Initialize(p_aout, fmt, 200 * AOUT_SPDIF_SIZE);
if (ret != VLC_SUCCESS)
{
AudioDeviceDestroyIOProcID(p_sys->i_selected_dev, p_sys->i_procID);
@@ -1286,7 +1276,7 @@ Stop(audio_output_t *p_aout)
if (p_sys->au_unit)
{
AudioOutputUnitStop(p_sys->au_unit);
- AudioUnitUninitialize(p_sys->au_unit);
+ au_Uninitialize(p_aout, p_sys->au_unit);
AudioComponentInstanceDispose(p_sys->au_unit);
}
@@ -1336,6 +1326,7 @@ Stop(audio_output_t *p_aout)
msg_Err(p_aout, "failed to re-set mixmode [%4.4s]",
(const char *)&err);
}
+ ca_Uninitialize(p_aout);
}
if (p_sys->i_hog_pid == getpid())
@@ -1359,8 +1350,6 @@ Stop(audio_output_t *p_aout)
kAudioDevicePropertyDeviceIsAlive,
kAudioObjectPropertyScopeGlobal);
- ca_Clean(p_aout);
-
p_sys->b_digital = false;
}
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index 48afacd..ebfa342 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -30,6 +30,8 @@
#import <vlc_dialog.h>
#endif
+#define AUDIO_BUFFER_SIZE_IN_SECONDS ((AOUT_MAX_ADVANCE_TIME + CLOCK_FREQ) / CLOCK_FREQ)
+
static inline uint64_t
BytesToFrames(struct aout_sys_common *p_sys, size_t i_bytes)
{
@@ -179,8 +181,8 @@ ca_Play(audio_output_t * p_aout, block_t * p_block)
}
int
-ca_Init(audio_output_t *p_aout, const audio_sample_format_t *fmt,
- size_t i_audio_buffer_size)
+ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt,
+ size_t i_audio_buffer_size)
{
struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
@@ -204,7 +206,7 @@ ca_Init(audio_output_t *p_aout, const audio_sample_format_t *fmt,
}
void
-ca_Clean(audio_output_t *p_aout)
+ca_Uninitialize(audio_output_t *p_aout)
{
struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
@@ -699,5 +701,24 @@ au_Initialize(audio_output_t *p_aout, AudioUnit au, audio_sample_format_t *fmt,
return VLC_EGENERIC;
}
+ ret = ca_Initialize(p_aout, fmt, AUDIO_BUFFER_SIZE_IN_SECONDS *
+ fmt->i_rate * fmt->i_bytes_per_frame);
+ if (ret != VLC_SUCCESS)
+ {
+ AudioUnitUninitialize(au);
+ return VLC_EGENERIC;
+ }
+
return VLC_SUCCESS;
}
+
+void
+au_Uninitialize(audio_output_t *p_aout, AudioUnit au)
+{
+ OSStatus err = AudioUnitUninitialize(au);
+ if (err != noErr)
+ msg_Warn(p_aout, "AudioUnitUninitialize failed [%4.4s]",
+ (const char *)&err);
+
+ ca_Uninitialize(p_aout);
+}
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index 8c71f76..330bd64 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -74,13 +74,15 @@ void ca_Pause(audio_output_t * p_aout, bool pause, mtime_t date);
void ca_Play(audio_output_t * p_aout, block_t * p_block);
-int ca_Init(audio_output_t *p_aout, const audio_sample_format_t *fmt,
- size_t i_audio_buffer_size);
+int ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt,
+ size_t i_audio_buffer_size);
-void ca_Clean(audio_output_t *p_aout);
+void ca_Uninitialize(audio_output_t *p_aout);
AudioUnit au_NewOutputInstance(audio_output_t *p_aout, OSType comp_sub_type);
int au_Initialize(audio_output_t *p_aout, AudioUnit au,
audio_sample_format_t *fmt,
const AudioChannelLayout *outlayout);
+
+void au_Uninitialize(audio_output_t *p_aout, AudioUnit au);
More information about the vlc-commits
mailing list