]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/auhal.c
Menu key triggers the popup menu
[vlc] / modules / audio_output / auhal.c
index 06783b8e6ed63506621bbcd80e2bbdc0b72f98d2..22f671d81006abfe1c837266335cebe9f5421761 100644 (file)
@@ -30,7 +30,8 @@
 
 #include <unistd.h>
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_aout.h>
 
@@ -132,15 +133,15 @@ static int      AudioDeviceCallback     ( vlc_object_t *, const char *,
     "audio device, as listed in your 'Audio Device' menu. This device will " \
     "then be used by default for audio playback.")
 
-vlc_module_begin();
-    set_shortname( "auhal" );
-    set_description( _("HAL AudioUnit output") );
-    set_capability( "audio output", 101 );
-    set_category( CAT_AUDIO );
-    set_subcategory( SUBCAT_AUDIO_AOUT );
-    set_callbacks( Open, Close );
-    add_integer( "macosx-audio-device", 0, NULL, ADEV_TEXT, ADEV_LONGTEXT, false );
-vlc_module_end();
+vlc_module_begin ()
+    set_shortname( "auhal" )
+    set_description( N_("HAL AudioUnit output") )
+    set_capability( "audio output", 101 )
+    set_category( CAT_AUDIO )
+    set_subcategory( SUBCAT_AUDIO_AOUT )
+    set_callbacks( Open, Close )
+    add_integer( "macosx-audio-device", 0, NULL, ADEV_TEXT, ADEV_LONGTEXT, false )
+vlc_module_end ()
 
 /*****************************************************************************
  * Open: open macosx audio output
@@ -160,10 +161,7 @@ static int Open( vlc_object_t * p_this )
     /* Allocate structure */
     p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) );
     if( p_aout->output.p_sys == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
-        return( VLC_ENOMEM );
-    }
+        return VLC_ENOMEM;
 
     p_sys = p_aout->output.p_sys;
     p_sys->i_default_dev = 0;
@@ -648,10 +646,7 @@ static int OpenSPDIF( aout_instance_t * p_aout )
     i_streams = i_param_size / sizeof( AudioStreamID );
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
         return false;
-    }
  
     err = AudioDeviceGetProperty( p_sys->i_selected_dev, 0, FALSE,
                                     kAudioDevicePropertyStreams,
@@ -684,10 +679,7 @@ static int OpenSPDIF( aout_instance_t * p_aout )
         i_formats = i_param_size / sizeof( AudioStreamBasicDescription );
         p_format_list = (AudioStreamBasicDescription *)malloc( i_param_size );
         if( p_format_list == NULL )
-        {
-            msg_Err( p_aout, "could not malloc the memory" );
             continue;
-        }
  
         err = AudioStreamGetProperty( p_streams[i], 0,
                                           kAudioStreamPropertyPhysicalFormats,
@@ -950,10 +942,7 @@ static void Probe( aout_instance_t * p_aout )
     /* Allocate DeviceID array */
     p_devices = (AudioDeviceID*)malloc( sizeof(AudioDeviceID) * p_sys->i_devices );
     if( p_devices == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
         goto error;
-    }
 
     /* Populate DeviceID array */
     err = AudioHardwareGetProperty( kAudioHardwarePropertyDevices,
@@ -976,7 +965,7 @@ static void Probe( aout_instance_t * p_aout )
     p_sys->i_default_dev = devid_def;
  
     var_Create( p_aout, "audio-device", VLC_VAR_INTEGER|VLC_VAR_HASCHOICE );
-    text.psz_string = _("Audio Device");
+    text.psz_string = (char*)_("Audio Device");
     var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL );
  
     for( i = 0; i < p_sys->i_devices; i++ )
@@ -1009,8 +998,9 @@ static void Probe( aout_instance_t * p_aout )
 
         /* Add the menu entries */
         val.i_int = (int)p_devices[i];
-        text.psz_string = strdup( psz_name );
+        text.psz_string = psz_name;
         var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
+        text.psz_string = NULL;
         if( p_sys->i_default_dev == p_devices[i] )
         {
             /* The default device is the selected device normally */
@@ -1021,14 +1011,17 @@ static void Probe( aout_instance_t * p_aout )
         if( AudioDeviceSupportsDigital( p_aout, p_devices[i] ) )
         {
             val.i_int = (int)p_devices[i] | AOUT_VAR_SPDIF_FLAG;
-            asprintf( &text.psz_string, _("%s (Encoded Output)"), psz_name );
-            var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
-            if( p_sys->i_default_dev == p_devices[i] && config_GetInt( p_aout, "spdif" ) )
+            if( asprintf( &text.psz_string, _("%s (Encoded Output)"), psz_name ) != -1 )
             {
-                /* We selected to prefer SPDIF output if available
-                 * then this "dummy" entry should be selected */
-                var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL );
-                var_Set( p_aout, "audio-device", val );
+                var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
+                free( text.psz_string );
+                if( p_sys->i_default_dev == p_devices[i] && config_GetInt( p_aout, "spdif" ) )
+                {
+                    /* We selected to prefer SPDIF output if available
+                     * then this "dummy" entry should be selected */
+                    var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL );
+                    var_Set( p_aout, "audio-device", val );
+                }
             }
         }
  
@@ -1100,10 +1093,7 @@ static int AudioDeviceSupportsDigital( aout_instance_t *p_aout, AudioDeviceID i_
     i_streams = i_param_size / sizeof( AudioStreamID );
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
         return VLC_ENOMEM;
-    }
  
     err = AudioDeviceGetProperty( i_dev_id, 0, FALSE,
                                     kAudioDevicePropertyStreams,
@@ -1149,10 +1139,7 @@ static int AudioStreamSupportsDigital( aout_instance_t *p_aout, AudioStreamID i_
     i_formats = i_param_size / sizeof( AudioStreamBasicDescription );
     p_format_list = (AudioStreamBasicDescription *)malloc( i_param_size );
     if( p_format_list == NULL )
-    {
-        msg_Err( p_aout, "could not malloc the memory" );
         return false;
-    }
  
     err = AudioStreamGetProperty( i_stream_id, 0,
                                       kAudioStreamPropertyPhysicalFormats,
@@ -1194,7 +1181,7 @@ static int AudioStreamChangeFormat( aout_instance_t *p_aout, AudioStreamID i_str
     msg_Dbg( p_aout, STREAM_FORMAT_MSG( "setting stream format: ", change_format ) );
 
     /* Condition because SetProperty is asynchronious */
-    vlc_cond_init( p_aout, &w.cond );
+    vlc_cond_init( &w.cond );
     vlc_mutex_init( &w.lock );
     vlc_mutex_lock( &w.lock );
 
@@ -1424,7 +1411,7 @@ static OSStatus HardwareListener( AudioHardwarePropertyID inPropertyID,
         {
             /* something changed in the list of devices */
             /* We trigger the audio-device's aout_ChannelsRestart callback */
-            var_Change( p_aout, "audio-device", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
+            var_TriggerCallback( p_aout, "audio-device" );
             var_Destroy( p_aout, "audio-device" );
         }
         break;