]> git.sesse.net Git - vlc/blobdiff - src/control/audio.c
Preferences: don't show empty boxes ('zoom' box bug)
[vlc] / src / control / audio.c
index 1c32afa1bc27b3bba0b25f04b21424d776c6aa30..22a886ef43bff20357921c57daf34f110886a350 100644 (file)
 #include <vlc_input.h>
 #include <vlc_aout.h>
 
-/*
- * Remember to release the returned input_thread_t since it is locked at
- * the end of this function.
- */
-static input_thread_t *GetInput( libvlc_input_t *p_input,
-                                 libvlc_exception_t *p_exception )
-{
-    input_thread_t *p_input_thread = NULL;
-
-    if( !p_input )
-    {
-        libvlc_exception_raise( p_exception, "Input is NULL" );
-        return NULL;
-    }
-
-    p_input_thread = (input_thread_t*)vlc_object_get(
-                                 p_input->p_instance->p_libvlc_int,
-                                 p_input->i_input_id );
-    if( !p_input_thread )
-    {
-        libvlc_exception_raise( p_exception, "Input does not exist" );
-        return NULL;
-    }
-
-    return p_input_thread;
-}
 
 /*
  * Remember to release the returned aout_instance_t since it is locked at
@@ -81,11 +55,13 @@ static aout_instance_t *GetAOut( libvlc_instance_t *p_instance,
 void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance,
                                libvlc_exception_t *p_e )
 {
+    VLC_UNUSED(p_e);
+
     aout_VolumeMute( p_instance->p_libvlc_int, NULL );
 }
 
-vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
-                                  libvlc_exception_t *p_e )
+int libvlc_audio_get_mute( libvlc_instance_t *p_instance,
+                           libvlc_exception_t *p_e )
 {
     /*
      * If the volume level is 0, then the channel is muted
@@ -94,11 +70,11 @@ vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
 
     i_volume = libvlc_audio_get_volume(p_instance, p_e);
     if ( i_volume == 0 )
-        return VLC_TRUE;
-    return VLC_FALSE;
+        return true;
+    return false;
 }
 
-void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute,
+void libvlc_audio_set_mute( libvlc_instance_t *p_instance, int mute,
                             libvlc_exception_t *p_e )
 {
     if ( mute ^ libvlc_audio_get_mute( p_instance, p_e ) )
@@ -113,6 +89,8 @@ void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute,
 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
                              libvlc_exception_t *p_e )
 {
+    VLC_UNUSED(p_e);
+
     audio_volume_t i_volume;
 
     aout_VolumeGet( p_instance->p_libvlc_int, &i_volume );
@@ -139,39 +117,83 @@ void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
     }
 }
 
+/*****************************************************************************
+ * libvlc_audio_get_track_count : Get the number of available audio tracks
+ *****************************************************************************/
+int libvlc_audio_get_track_count( libvlc_media_player_t *p_mi, 
+                                  libvlc_exception_t *p_e )
+{
+    input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
+    vlc_value_t val_list;
+
+    if( !p_input_thread )
+        return -1;
+
+    var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
+    vlc_object_release( p_input_thread );
+    return val_list.p_list->i_count;
+}
+
 /*****************************************************************************
  * libvlc_audio_get_track : Get the current audio track
  *****************************************************************************/
-int libvlc_audio_get_track( libvlc_input_t *p_input,
+int libvlc_audio_get_track( libvlc_media_player_t *p_mi,
                             libvlc_exception_t *p_e )
 {
-    input_thread_t *p_input_thread = GetInput( p_input, p_e );
-    int i_track = 0;
+    input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
+    vlc_value_t val_list;
+    vlc_value_t val;
+    int i_track = -1;
+    int i_ret = -1;
+    int i;
 
-    i_track = var_GetInteger( p_input_thread, "audio-es" );
-    vlc_object_release( p_input_thread );
+    if( !p_input_thread )
+        return -1;
 
+    i_ret = var_Get( p_input_thread, "audio-es", &val );
+    if( i_ret < 0 )
+    {
+        libvlc_exception_raise( p_e, "Getting Audio track information failed" );
+        vlc_object_release( p_input_thread );
+        return i_ret;
+    }
+
+    var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
+    for( i = 0; i < val_list.p_list->i_count; i++ )
+    {
+        vlc_value_t track_val = val_list.p_list->p_values[i];
+        if( track_val.i_int == val.i_int )
+        {
+            i_track = i;
+            break;
+       }
+    }
+    vlc_object_release( p_input_thread );
     return i_track;
 }
 
+
 /*****************************************************************************
  * libvlc_audio_set_track : Set the current audio track
  *****************************************************************************/
-void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track,
+void libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track,
                              libvlc_exception_t *p_e )
 {
-    input_thread_t *p_input_thread = GetInput( p_input, p_e );
+    input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
     vlc_value_t val_list;
     int i_ret = -1;
     int i;
 
+    if( !p_input_thread )
+        return;
+
     var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
     for( i = 0; i < val_list.p_list->i_count; i++ )
     {
         vlc_value_t val = val_list.p_list->p_values[i];
         if( i_track == val.i_int )
         {
-            i_ret = var_SetInteger( p_input_thread, "audio-es", i_track );
+            i_ret = var_Set( p_input_thread, "audio-es", val );
             if( i_ret < 0 )
             {
                 libvlc_exception_raise( p_e, "Setting audio track failed" );
@@ -187,76 +209,54 @@ void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track,
 /*****************************************************************************
  * libvlc_audio_get_channel : Get the current audio channel
  *****************************************************************************/
-char *libvlc_audio_get_channel( libvlc_instance_t *p_instance,
+int libvlc_audio_get_channel( libvlc_instance_t *p_instance,
                                 libvlc_exception_t *p_e )
 {
     aout_instance_t *p_aout = GetAOut( p_instance, p_e );
-    char *psz_channel = NULL;
-    vlc_value_t val;
-
-    var_Get( p_aout, "audio-channels", &val );
-    switch( val.i_int )
+    if( p_aout )
     {
-        case AOUT_VAR_CHAN_RSTEREO:
-            psz_channel = strdup("reverse stereo");
-            break;
-        case AOUT_VAR_CHAN_STEREO:
-            psz_channel = strdup("stereo");
-            break;
-        case AOUT_VAR_CHAN_LEFT:
-            psz_channel = strdup("left");
-            break;
-        case AOUT_VAR_CHAN_RIGHT:
-            psz_channel = strdup("right");
-            break;
-        case AOUT_VAR_CHAN_DOLBYS:
-            psz_channel = strdup("dolby");
-            break;
-        default:
-            psz_channel = strdup("disabled");
-            break;
+        vlc_value_t val;
+
+        var_Get( p_aout, "audio-channels", &val );
+        vlc_object_release( p_aout );
+        return val.i_int;
     }
-    vlc_object_release( p_aout );
-    return psz_channel;
+    return -1;
 }
 
 /*****************************************************************************
  * libvlc_audio_set_channel : Set the current audio channel
  *****************************************************************************/
-void libvlc_audio_set_channel( libvlc_instance_t *p_instance, char *psz_channel,
+void libvlc_audio_set_channel( libvlc_instance_t *p_instance, int i_channel,
                                libvlc_exception_t *p_e )
 {
     aout_instance_t *p_aout = GetAOut( p_instance, p_e );
-    vlc_value_t val_list, text_list;
-    int i_ret = -1, i;
-
-    i_ret = var_Change( p_aout, "audio-channels", VLC_VAR_GETCHOICES, &val_list, &text_list );
-    if( (i_ret < 0) || !psz_channel )
-    {
-        libvlc_exception_raise( p_e, "Audio channel out of range" );
-        vlc_object_release( p_aout );
-        return;
-    }
-
-    for( i = 0; i < val_list.p_list->i_count; i++ )
+    if( p_aout )
     {
-        vlc_value_t val = val_list.p_list->p_values[i];
-        vlc_value_t text = text_list.p_list->p_values[i];
+        vlc_value_t val;
+        int i_ret = -1;
 
-        if( strncasecmp( psz_channel, text.psz_string, strlen(text.psz_string) ) == 0 )
+        val.i_int = i_channel;
+        switch( i_channel )
         {
-            i_ret = var_Set( p_aout, "audio-channels", val );
-            if( i_ret < 0 )
-            {
-                libvlc_exception_raise( p_e, "failed setting audio range" );
+            case AOUT_VAR_CHAN_RSTEREO:
+            case AOUT_VAR_CHAN_STEREO:
+            case AOUT_VAR_CHAN_LEFT:
+            case AOUT_VAR_CHAN_RIGHT:
+            case AOUT_VAR_CHAN_DOLBYS:
+                i_ret = var_Set( p_aout, "audio-channels", val );
+                if( i_ret < 0 )
+                {
+                    libvlc_exception_raise( p_e, "Failed setting audio channel" );
+                    vlc_object_release( p_aout );
+                    return;
+                }
                 vlc_object_release( p_aout );
-                return;
-            }
-            vlc_object_release( p_aout );
-            return; /* Found */
+                return; /* Found */
+            default:
+                libvlc_exception_raise( p_e, "Audio channel out of range" );
+                break;
         }
+        vlc_object_release( p_aout );
     }
-    libvlc_exception_raise( p_e, "Audio channel out of range" );
-    vlc_object_release( p_aout );
 }
-