[vlc-commits] coreaudio: factor AudioUnit creation
Thomas Guillem
git at videolan.org
Wed Mar 1 17:49:52 CET 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Feb 24 16:09:14 2017 +0100| [13765817b958c79d197f879f1b78677b3ff43140] | committer: Thomas Guillem
coreaudio: factor AudioUnit creation
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=13765817b958c79d197f879f1b78677b3ff43140
---
modules/audio_output/audiounit_ios.m | 22 ++--------------------
modules/audio_output/auhal.c | 26 ++------------------------
modules/audio_output/coreaudio_common.c | 30 ++++++++++++++++++++++++++++++
modules/audio_output/coreaudio_common.h | 4 ++++
4 files changed, 38 insertions(+), 44 deletions(-)
diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index a5294e2..8a64ea7 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -26,11 +26,9 @@
#import <vlc_plugin.h>
-#import <AudioUnit/AudioUnit.h>
#import <CoreAudio/CoreAudioTypes.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
-#import <AudioToolbox/AudioToolbox.h>
#import <mach/mach_time.h>
#pragma mark -
@@ -191,28 +189,12 @@ static int
StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
{
struct aout_sys_t *p_sys = p_aout->sys;
- AudioComponentDescription desc;
AURenderCallbackStruct callback;
OSStatus status;
- /* Lets go find our Component */
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = kAudioUnitSubType_RemoteIO;
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
-
- AudioComponent au_component = AudioComponentFindNext(NULL, &desc);
- if (au_component == NULL) {
- msg_Warn(p_aout, "we cannot find our audio component");
- return VLC_EGENERIC;
- }
-
- status = AudioComponentInstanceNew(au_component, &p_sys->au_unit);
- if (status != noErr) {
- msg_Warn(p_aout, "we cannot open our audio component (%i)", (int)status);
+ p_sys->au_unit = au_NewOutputInstance(p_aout, kAudioUnitSubType_RemoteIO);
+ if (p_sys->au_unit == NULL)
return VLC_EGENERIC;
- }
status = AudioUnitSetProperty(p_sys->au_unit,
kAudioOutputUnitProperty_EnableIO,
diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index a960680..cb2a9d6 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -29,9 +29,7 @@
#import <vlc_plugin.h>
#import <vlc_dialog.h> // vlc_dialog_display_error
-#import <AudioUnit/AudioUnit.h> // AudioUnit
#import <CoreAudio/CoreAudio.h> // AudioDeviceID
-#import <AudioToolbox/AudioFormat.h> // AudioFormatGetProperty
#import <CoreServices/CoreServices.h>
#pragma mark -
@@ -994,7 +992,6 @@ StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
OSStatus err = noErr;
UInt32 i_param_size = 0;
int i_original;
- AudioComponentDescription desc;
AudioStreamBasicDescription DeviceFormat;
AudioChannelLayout *layout;
AURenderCallbackStruct input;
@@ -1004,28 +1001,9 @@ StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
if (Gestalt(gestaltSystemVersionMinor, ¤tMinorSystemVersion) != noErr)
msg_Err(p_aout, "failed to check OSX version");
- /* Lets go find our Component */
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = kAudioUnitSubType_HALOutput;
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
-
- AudioComponent au_component;
- au_component = AudioComponentFindNext(NULL, &desc);
- if (au_component == NULL)
- {
- msg_Err(p_aout, "cannot find any HAL component, PCM output failed");
+ p_sys->au_unit = au_NewOutputInstance(p_aout, kAudioUnitSubType_HALOutput);
+ if (p_sys->au_unit == NULL)
return VLC_EGENERIC;
- }
-
- err = AudioComponentInstanceNew(au_component, &p_sys->au_unit);
- if (err != noErr)
- {
- msg_Err(p_aout, "cannot open HAL component, PCM output failed [%4.4s]",
- (const char *)&err);
- return VLC_EGENERIC;
- }
/* Set the device we will use for this output unit */
err = AudioUnitSetProperty(p_sys->au_unit,
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index f7f7fcc..910546a 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -181,3 +181,33 @@ ca_Clean(audio_output_t *p_aout)
/* clean-up circular buffer */
TPCircularBufferCleanup(&p_sys->circular_buffer);
}
+
+AudioUnit
+au_NewOutputInstance(audio_output_t *p_aout, OSType comp_sub_type)
+{
+ AudioComponentDescription desc = {
+ .componentType = kAudioUnitType_Output,
+ .componentSubType = comp_sub_type,
+ .componentManufacturer = kAudioUnitManufacturer_Apple,
+ .componentFlags = 0,
+ .componentFlagsMask = 0,
+ };
+
+ AudioComponent au_component;
+ au_component = AudioComponentFindNext(NULL, &desc);
+ if (au_component == NULL)
+ {
+ msg_Err(p_aout, "cannot find any AudioComponent, PCM output failed");
+ return NULL;
+ }
+
+ AudioUnit au;
+ OSStatus err = AudioComponentInstanceNew(au_component, &au);
+ if (err != noErr)
+ {
+ msg_Err(p_aout, "cannot open AudioComponent, PCM output failed [%4.4s]",
+ (const char *)&err);
+ return NULL;
+ }
+ return au;
+}
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index 7403a30..1b6f908 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -30,6 +30,8 @@
#import <vlc_atomic.h>
#import <vlc_aout.h>
+#import <AudioUnit/AudioUnit.h>
+#import <AudioToolbox/AudioToolbox.h>
#import "TPCircularBuffer.h"
#define STREAM_FORMAT_MSG(pre, sfm) \
@@ -71,3 +73,5 @@ int ca_Init(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);
+
+AudioUnit au_NewOutputInstance(audio_output_t *p_aout, OSType comp_sub_type);
More information about the vlc-commits
mailing list