]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/auhal.c
ASF: help stupid compiler
[vlc] / modules / audio_output / auhal.c
index 9855ae4d6e2faab0d1847224e4c2d963c2619691..999771a3b9f0c1f1becdf7423e2d26048d88a58b 100644 (file)
@@ -36,8 +36,9 @@
 #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
@@ -192,7 +184,7 @@ static int Open( vlc_object_t * p_this )
     /* 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 */
@@ -609,6 +601,7 @@ static int OpenSPDIF( audio_output_t * p_aout )
     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;
@@ -626,23 +619,27 @@ static int OpenSPDIF( audio_output_t * p_aout )
         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 */
@@ -654,6 +651,7 @@ static int OpenSPDIF( audio_output_t * p_aout )
         return false;
     }
 
+    i_streams = i_param_size / sizeof( AudioStreamID );
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
         return false;
@@ -668,7 +666,7 @@ static int OpenSPDIF( audio_output_t * p_aout )
     }
 
     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;
@@ -700,7 +698,9 @@ static int OpenSPDIF( audio_output_t * p_aout )
         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;
@@ -719,9 +719,10 @@ static int OpenSPDIF( audio_output_t * p_aout )
 
             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, &currentPhysicalFormatAddress, 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 );
@@ -733,7 +734,9 @@ static int OpenSPDIF( audio_output_t * p_aout )
             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 )
                     {
@@ -860,13 +863,13 @@ static void Close( vlc_object_t * p_this )
         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;
@@ -899,6 +902,8 @@ static void Close( vlc_object_t * p_this )
         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 );
 }
@@ -1067,6 +1072,7 @@ static int AudioDeviceSupportsDigital( audio_output_t *p_aout, AudioDeviceID i_d
     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 */
@@ -1078,6 +1084,7 @@ static int AudioDeviceSupportsDigital( audio_output_t *p_aout, AudioDeviceID i_d
         return false;
     }
 
+    i_streams = i_param_size / sizeof( AudioStreamID );
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
         return VLC_ENOMEM;
@@ -1089,7 +1096,7 @@ static int AudioDeviceSupportsDigital( audio_output_t *p_aout, AudioDeviceID i_d
         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;
@@ -1140,7 +1147,9 @@ static int AudioStreamSupportsDigital( audio_output_t *p_aout, AudioStreamID i_s
         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;
         }
@@ -1158,7 +1167,7 @@ static int AudioStreamChangeFormat( audio_output_t *p_aout, AudioStreamID i_stre
     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;
 
@@ -1215,7 +1224,7 @@ static int AudioStreamChangeFormat( audio_output_t *p_aout, AudioStreamID i_stre
     }
 
     /* 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 );
@@ -1421,6 +1430,7 @@ static OSStatus StreamListener( AudioObjectID inObjectID,  UInt32 inNumberAddres
             vlc_mutex_lock( &w->lock );
             vlc_cond_signal( &w->cond );
             vlc_mutex_unlock( &w->lock );
+            break;
         }
     }
     return( err );