#include <vlc_aout.h> // aout_*
#include <AudioUnit/AudioUnit.h> // AudioUnit
-#include <CoreAudio/AudioHardware.h> // AudioDeviceID
+#include <CoreAudio/CoreAudio.h> // AudioDeviceID
#include <AudioToolbox/AudioFormat.h> // AudioFormatGetProperty
+#include <CoreServices/CoreServices.h>
#ifndef verify_noerr
# define verify_noerr(a) assert((a) == noErr)
(unsigned int)sfm.mFramesPerPacket, (unsigned int)sfm.mBytesPerFrame, \
(unsigned int)sfm.mChannelsPerFrame, (unsigned int)sfm.mBitsPerChannel
-#ifndef NDEBUG
-#define STREAM_FORMAT_MSG_FULL( pre, sfm ) \
- pre ":\nsamplerate: [%"PRIu32"]\nFormatID: [%4.4s]\nFormatFlags: [%"PRIu32"]\nBypesPerPacket: [%"PRIu32"]\nFramesPerPacket: [%"PRIu32"]\nBytesPerFrame: [%u]\nChannelsPerFrame: [%u]\nBitsPerChannel[%u]", \
- (UInt32)sfm.mSampleRate, (char *)&sfm.mFormatID, \
- sfm.mFormatFlags, sfm.mBytesPerPacket, \
- sfm.mFramesPerPacket, sfm.mBytesPerFrame, \
- sfm.mChannelsPerFrame, sfm.mBitsPerChannel
-#endif
-
#define FRAMESIZE 2048
#define BUFSIZE (FRAMESIZE * 8) * 8
#define AOUT_VAR_SPDIF_FLAG 0xf00000
/* Persistent device variable */
if( var_Type( p_aout->p_libvlc, "macosx-audio-device" ) == 0 )
{
- var_CreateGetInteger( p_aout->p_libvlc, "macosx-audio-device" );
+ var_Create( p_aout->p_libvlc, "macosx-audio-device", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
}
/* Build a list of devices */
UInt32 i_param_size = 0, b_mix = 0;
Boolean b_writeable = false;
AudioStreamID *p_streams = NULL;
+ int i_streams = 0;
/* Start doing the SPDIF setup proces */
p_sys->b_digital = true;
return false;
}
- /* Set mixable to false if we are allowed to */
- AudioObjectPropertyAddress audioDeviceSupportsMixingAddress = { kAudioDevicePropertySupportsMixing , kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
- err = AudioObjectIsPropertySettable( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, &b_writeable );
- err = AudioObjectGetPropertyDataSize( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, 0, NULL, &i_param_size );
- err = AudioObjectGetPropertyData( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, 0, NULL, &i_param_size, &b_mix );
+ AudioObjectPropertyAddress audioDeviceSupportsMixingAddress = { kAudioDevicePropertySupportsMixing , kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
- if( !err && b_writeable )
+ if (AudioObjectHasProperty(p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress))
{
- b_mix = 0;
- err = AudioObjectSetPropertyData( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, 0, NULL, i_param_size, &b_mix );
- p_sys->b_changed_mixing = true;
- }
+ /* Set mixable to false if we are allowed to */
+ err = AudioObjectIsPropertySettable( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, &b_writeable );
+ err = AudioObjectGetPropertyDataSize( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, 0, NULL, &i_param_size );
+ err = AudioObjectGetPropertyData( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, 0, NULL, &i_param_size, &b_mix );
- if( err != noErr )
- {
- msg_Err( p_aout, "failed to set mixmode: [%4.4s]", (char *)&err );
- return false;
+ if( err == noErr && b_writeable )
+ {
+ b_mix = 0;
+ err = AudioObjectSetPropertyData( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, 0, NULL, i_param_size, &b_mix );
+ p_sys->b_changed_mixing = true;
+ }
+
+ if( err != noErr )
+ {
+ msg_Err( p_aout, "failed to set mixmode: [%4.4s]", (char *)&err );
+ return false;
+ }
}
/* Get a list of all the streams on this device */
return false;
}
+ i_streams = i_param_size / sizeof( AudioStreamID );
p_streams = (AudioStreamID *)malloc( i_param_size );
if( p_streams == NULL )
return false;
}
AudioObjectPropertyAddress physicalFormatsAddress = { kAudioStreamPropertyAvailablePhysicalFormats, kAudioObjectPropertyScopeGlobal, 0 };
- for( unsigned i = 0; i < i_param_size / sizeof( AudioStreamID ) && p_sys->i_stream_index < 0 ; i++ )
+ for( unsigned i = 0; i < i_streams && p_sys->i_stream_index < 0 ; i++ )
{
/* Find a stream with a cac3 stream */
AudioStreamRangedDescription *p_format_list = NULL;
for( int j = 0; j < i_formats; j++ )
{
if( p_format_list[j].mFormat.mFormatID == 'IAC3' ||
- p_format_list[j].mFormat.mFormatID == kAudioFormat60958AC3 )
+ p_format_list[j].mFormat.mFormatID == 'iac3' ||
+ p_format_list[j].mFormat.mFormatID == kAudioFormat60958AC3 ||
+ p_format_list[j].mFormat.mFormatID == kAudioFormatAC3 )
{
b_digital = true;
break;
if( !p_sys->b_revert )
{
+ AudioObjectPropertyAddress currentPhysicalFormatAddress = { kAudioStreamPropertyPhysicalFormat, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
/* Retrieve the original format of this stream first if not done so already */
i_param_size = sizeof( p_sys->sfmt_revert );
- err = AudioObjectGetPropertyData( p_sys->i_stream_id, &physicalFormatsAddress, 0, NULL, &i_param_size, &p_sys->sfmt_revert );
+ err = AudioObjectGetPropertyData( p_sys->i_stream_id, ¤tPhysicalFormatAddress, 0, NULL, &i_param_size, &p_sys->sfmt_revert );
if( err != noErr )
{
msg_Err( p_aout, "could not retrieve the original streamformat: [%4.4s]", (char *)&err );
for( int j = 0; j < i_formats; j++ )
{
if( p_format_list[j].mFormat.mFormatID == 'IAC3' ||
- p_format_list[j].mFormat.mFormatID == kAudioFormat60958AC3 )
+ p_format_list[j].mFormat.mFormatID == 'iac3' ||
+ p_format_list[j].mFormat.mFormatID == kAudioFormat60958AC3 ||
+ p_format_list[j].mFormat.mFormatID == kAudioFormatAC3 )
{
if( p_format_list[j].mFormat.mSampleRate == p_aout->format.i_rate )
{
if( p_sys->b_changed_mixing && p_sys->sfmt_revert.mFormatID != kAudioFormat60958AC3 )
{
int b_mix;
- Boolean b_writeable;
+ Boolean b_writeable = false;
/* Revert mixable to true if we are allowed to */
AudioObjectPropertyAddress audioDeviceSupportsMixingAddress = { kAudioDevicePropertySupportsMixing , kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
err = AudioObjectIsPropertySettable( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, &b_writeable );
err = AudioObjectGetPropertyData( p_sys->i_selected_dev, &audioDeviceSupportsMixingAddress, 0, NULL, &i_param_size, &b_mix );
- if( !err && b_writeable )
+ if( err == noErr && b_writeable )
{
msg_Dbg( p_aout, "mixable is: %d", b_mix );
b_mix = 1;
if( err != noErr ) msg_Err( p_aout, "Could not release hogmode: [%4.4s]", (char *)&err );
}
+ var_DelCallback( p_aout, "audio-device", AudioDeviceCallback, NULL );
+
aout_PacketDestroy( p_aout );
free( p_sys );
}
OSStatus err = noErr;
UInt32 i_param_size = 0;
AudioStreamID *p_streams = NULL;
+ int i_streams = 0;
bool b_return = false;
/* Retrieve all the output streams */
return false;
}
+ i_streams = i_param_size / sizeof( AudioStreamID );
p_streams = (AudioStreamID *)malloc( i_param_size );
if( p_streams == NULL )
return VLC_ENOMEM;
return false;
}
- for( unsigned i = 0; i < i_param_size / sizeof( AudioStreamID ); i++ )
+ for( int i = 0; i < i_streams; i++ )
{
if( AudioStreamSupportsDigital( p_aout, p_streams[i] ) )
b_return = true;
msg_Dbg( p_aout, STREAM_FORMAT_MSG( "supported format: ", p_format_list[i].mFormat ) );
if( p_format_list[i].mFormat.mFormatID == 'IAC3' ||
- p_format_list[i].mFormat.mFormatID == kAudioFormat60958AC3 )
+ p_format_list[i].mFormat.mFormatID == 'iac3' ||
+ p_format_list[i].mFormat.mFormatID == kAudioFormat60958AC3 ||
+ p_format_list[i].mFormat.mFormatID == kAudioFormatAC3 )
{
b_return = true;
}
OSStatus err = noErr;
UInt32 i_param_size = 0;
- AudioObjectPropertyAddress physicalFormatAddress = { kAudioStreamPropertyPhysicalFormat, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
+ AudioObjectPropertyAddress physicalFormatAddress = { kAudioStreamPropertyPhysicalFormat, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
struct { vlc_mutex_t lock; vlc_cond_t cond; } w;
}
/* Removing the property listener */
- err = AudioObjectRemovePropertyListener( i_stream_id, &physicalFormatAddress, StreamListener, NULL );
+ err = AudioObjectRemovePropertyListener( i_stream_id, &physicalFormatAddress, StreamListener, (void *)&w );
if( err != noErr )
{
msg_Err( p_aout, "AudioStreamRemovePropertyListener failed: [%4.4s]", (char *)&err );
vlc_mutex_lock( &w->lock );
vlc_cond_signal( &w->cond );
vlc_mutex_unlock( &w->lock );
+ break;
}
}
return( err );