Commit 210f2129 authored by Felix Paul Kühne's avatar Felix Paul Kühne

auhal: updated to current AudioUnit API

should be tested with SPDIF devices
parent ff7dc8ad
/***************************************************************************** /*****************************************************************************
* auhal.c: AUHAL and Coreaudio output plugin * auhal.c: AUHAL and Coreaudio output plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2005 the VideoLAN team * Copyright (C) 2005, 2011 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Derk-Jan Hartman <hartman at videolan dot org> * Authors: Derk-Jan Hartman <hartman at videolan dot org>
* Felix Paul Kühne <fkuehne at videolan dot org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -35,33 +36,14 @@ ...@@ -35,33 +36,14 @@
#include <vlc_dialog.h> #include <vlc_dialog.h>
#include <vlc_aout.h> #include <vlc_aout.h>
// By pass part of header which compile with some warnings,
// and that we don't require.
#define __MACHINEEXCEPTIONS__
#include <CoreAudio/CoreAudio.h> #include <CoreAudio/CoreAudio.h>
#include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnit.h>
#include <AudioUnit/AudioUnitProperties.h> #include <AudioToolbox/AudioFormat.h>
#include <AudioUnit/AudioUnitParameters.h>
#include <AudioUnit/AudioOutputUnit.h>
#include <AudioToolbox/AudioFormat.h>
#ifndef verify_noerr #ifndef verify_noerr
#define verify_noerr(a) assert((a) == noErr) #define verify_noerr(a) assert((a) == noErr)
#endif #endif
#if AUDIO_UNIT_VERSION < 1060
#define AudioComponent Component
#define AudioComponentDescription ComponentDescription
#define AudioComponentFindNext FindNextComponent
#define AudioComponentInstanceNew OpenAComponent
#define AudioComponentInstanceDispose CloseComponent
#define AudioComponentInstanceNew OpenAComponent
#define AudioComponentInstanceNew OpenAComponent
#else
#include <AudioUnit/AudioComponent.h>
#endif
#define STREAM_FORMAT_MSG( pre, sfm ) \ #define STREAM_FORMAT_MSG( pre, sfm ) \
pre "[%u][%4.4s][%u][%u][%u][%u][%u][%u]", \ pre "[%u][%4.4s][%u][%u][%u][%u][%u][%u]", \
(UInt32)sfm.mSampleRate, (char *)&sfm.mFormatID, \ (UInt32)sfm.mSampleRate, (char *)&sfm.mFormatID, \
...@@ -83,7 +65,6 @@ ...@@ -83,7 +65,6 @@
/* /*
* TODO: * TODO:
* - clean up the debug info * - clean up the debug info
* - clean up C99'isms
* - be better at changing stream setup or devices setup changes while playing. * - be better at changing stream setup or devices setup changes while playing.
* - fix 6.1 and 7.1 * - fix 6.1 and 7.1
*/ */
...@@ -98,13 +79,14 @@ struct aout_sys_t ...@@ -98,13 +79,14 @@ struct aout_sys_t
{ {
AudioDeviceID i_default_dev; /* Keeps DeviceID of defaultOutputDevice */ AudioDeviceID i_default_dev; /* Keeps DeviceID of defaultOutputDevice */
AudioDeviceID i_selected_dev; /* Keeps DeviceID of the selected device */ AudioDeviceID i_selected_dev; /* Keeps DeviceID of the selected device */
AudioDeviceIOProcID i_procID; /* DeviceID of current device */
UInt32 i_devices; /* Number of CoreAudio Devices */ UInt32 i_devices; /* Number of CoreAudio Devices */
bool b_supports_digital;/* Does the currently selected device support digital mode? */ bool b_supports_digital;/* Does the currently selected device support digital mode? */
bool b_digital; /* Are we running in digital mode? */ bool b_digital; /* Are we running in digital mode? */
mtime_t clock_diff; /* Difference between VLC clock and Device clock */ mtime_t clock_diff; /* Difference between VLC clock and Device clock */
/* AUHAL specific */ /* AUHAL specific */
AudioComponent au_component; /* The Audiocomponent we use */ Component au_component; /* The Audiocomponent we use */
AudioUnit au_unit; /* The AudioUnit we use */ AudioUnit au_unit; /* The AudioUnit we use */
uint8_t p_remainder_buffer[BUFSIZE]; uint8_t p_remainder_buffer[BUFSIZE];
uint32_t i_read_bytes; uint32_t i_read_bytes;
...@@ -116,8 +98,8 @@ struct aout_sys_t ...@@ -116,8 +98,8 @@ struct aout_sys_t
int i_stream_index; /* The index of i_stream_id in an AudioBufferList */ int i_stream_index; /* The index of i_stream_id in an AudioBufferList */
AudioStreamBasicDescription stream_format; /* The format we changed the stream to */ AudioStreamBasicDescription stream_format; /* The format we changed the stream to */
AudioStreamBasicDescription sfmt_revert; /* The original format of the stream */ AudioStreamBasicDescription sfmt_revert; /* The original format of the stream */
bool b_revert; /* Wether we need to revert the stream format */ bool b_revert; /* Wether we need to revert the stream format */
bool b_changed_mixing;/* Wether we need to set the mixing mode back */ bool b_changed_mixing;/* Wether we need to set the mixing mode back */
}; };
/***************************************************************************** /*****************************************************************************
...@@ -300,7 +282,7 @@ static int OpenAnalog( aout_instance_t *p_aout ) ...@@ -300,7 +282,7 @@ static int OpenAnalog( aout_instance_t *p_aout )
OSStatus err = noErr; OSStatus err = noErr;
UInt32 i_param_size = 0, i = 0; UInt32 i_param_size = 0, i = 0;
int i_original; int i_original;
AudioComponentDescription desc; ComponentDescription desc;
AudioStreamBasicDescription DeviceFormat; AudioStreamBasicDescription DeviceFormat;
AudioChannelLayout *layout; AudioChannelLayout *layout;
AudioChannelLayout new_layout; AudioChannelLayout new_layout;
...@@ -313,14 +295,14 @@ static int OpenAnalog( aout_instance_t *p_aout ) ...@@ -313,14 +295,14 @@ static int OpenAnalog( aout_instance_t *p_aout )
desc.componentFlags = 0; desc.componentFlags = 0;
desc.componentFlagsMask = 0; desc.componentFlagsMask = 0;
p_sys->au_component = AudioComponentFindNext( NULL, &desc ); p_sys->au_component = FindNextComponent( NULL, &desc );
if( p_sys->au_component == NULL ) if( p_sys->au_component == NULL )
{ {
msg_Warn( p_aout, "we cannot find our HAL component" ); msg_Warn( p_aout, "we cannot find our HAL component" );
return false; return false;
} }
err = AudioComponentInstanceNew( p_sys->au_component, &p_sys->au_unit ); err = OpenAComponent( p_sys->au_component, &p_sys->au_unit );
if( err != noErr ) if( err != noErr )
{ {
msg_Warn( p_aout, "we cannot open our HAL component" ); msg_Warn( p_aout, "we cannot open our HAL component" );
...@@ -802,13 +784,13 @@ static int OpenSPDIF( aout_instance_t * p_aout ) ...@@ -802,13 +784,13 @@ static int OpenSPDIF( aout_instance_t * p_aout )
aout_VolumeNoneInit( p_aout ); aout_VolumeNoneInit( p_aout );
/* Add IOProc callback */ /* Add IOProc callback */
err = AudioDeviceAddIOProc( p_sys->i_selected_dev, err = AudioDeviceCreateIOProcID( p_sys->i_selected_dev,
(AudioDeviceIOProc)RenderCallbackSPDIF, (AudioDeviceIOProc)RenderCallbackSPDIF,
(void *)p_aout ); (void *)p_aout,
&p_sys->i_procID );
if( err != noErr ) if( err != noErr )
{ {
msg_Err( p_aout, "AudioDeviceAddIOProc failed: [%4.4s]", (char *)&err ); msg_Err( p_aout, "AudioDeviceCreateIOProcID failed: [%4.4s]", (char *)&err );
return false; return false;
} }
...@@ -818,16 +800,16 @@ static int OpenSPDIF( aout_instance_t * p_aout ) ...@@ -818,16 +800,16 @@ static int OpenSPDIF( aout_instance_t * p_aout )
p_sys->clock_diff += mdate(); p_sys->clock_diff += mdate();
/* Start device */ /* Start device */
err = AudioDeviceStart( p_sys->i_selected_dev, (AudioDeviceIOProc)RenderCallbackSPDIF ); err = AudioDeviceStart( p_sys->i_selected_dev, p_sys->i_procID );
if( err != noErr ) if( err != noErr )
{ {
msg_Err( p_aout, "AudioDeviceStart failed: [%4.4s]", (char *)&err ); msg_Err( p_aout, "AudioDeviceStart failed: [%4.4s]", (char *)&err );
err = AudioDeviceRemoveIOProc( p_sys->i_selected_dev, err = AudioDeviceDestroyIOProcID( p_sys->i_selected_dev,
(AudioDeviceIOProc)RenderCallbackSPDIF ); p_sys->i_procID );
if( err != noErr ) if( err != noErr )
{ {
msg_Err( p_aout, "AudioDeviceRemoveIOProc failed: [%4.4s]", (char *)&err ); msg_Err( p_aout, "AudioDeviceDestroyIOProcID failed: [%4.4s]", (char *)&err );
} }
return false; return false;
} }
...@@ -850,25 +832,25 @@ static void Close( vlc_object_t * p_this ) ...@@ -850,25 +832,25 @@ static void Close( vlc_object_t * p_this )
{ {
verify_noerr( AudioOutputUnitStop( p_sys->au_unit ) ); verify_noerr( AudioOutputUnitStop( p_sys->au_unit ) );
verify_noerr( AudioUnitUninitialize( p_sys->au_unit ) ); verify_noerr( AudioUnitUninitialize( p_sys->au_unit ) );
verify_noerr( AudioComponentInstanceDispose( p_sys->au_unit ) ); verify_noerr( CloseComponent( p_sys->au_unit ) );
} }
if( p_sys->b_digital ) if( p_sys->b_digital )
{ {
/* Stop device */ /* Stop device */
err = AudioDeviceStop( p_sys->i_selected_dev, err = AudioDeviceStop( p_sys->i_selected_dev,
(AudioDeviceIOProc)RenderCallbackSPDIF ); p_sys->i_procID );
if( err != noErr ) if( err != noErr )
{ {
msg_Err( p_aout, "AudioDeviceStop failed: [%4.4s]", (char *)&err ); msg_Err( p_aout, "AudioDeviceStop failed: [%4.4s]", (char *)&err );
} }
/* Remove IOProc callback */ /* Remove IOProc callback */
err = AudioDeviceRemoveIOProc( p_sys->i_selected_dev, err = AudioDeviceDestroyIOProcID( p_sys->i_selected_dev,
(AudioDeviceIOProc)RenderCallbackSPDIF ); p_sys->i_procID );
if( err != noErr ) if( err != noErr )
{ {
msg_Err( p_aout, "AudioDeviceRemoveIOProc failed: [%4.4s]", (char *)&err ); msg_Err( p_aout, "AudioDeviceDestroyIOProcID failed: [%4.4s]", (char *)&err );
} }
if( p_sys->b_revert ) if( p_sys->b_revert )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment