mirror of
https://code.videolan.org/videolan/vlc
synced 2024-07-21 07:24:15 +02:00
coreaudio: factor AudioUnit creation
This commit is contained in:
parent
5dcaa9fd9c
commit
13765817b9
@ -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");
|
||||
p_sys->au_unit = au_NewOutputInstance(p_aout, kAudioUnitSubType_RemoteIO);
|
||||
if (p_sys->au_unit == NULL)
|
||||
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);
|
||||
return VLC_EGENERIC;
|
||||
}
|
||||
|
||||
status = AudioUnitSetProperty(p_sys->au_unit,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user