]> git.sesse.net Git - vlc/blobdiff - src/control/audio.c
Fix bug in vlc.audio.track and add new properties vlc.video.subtitle
[vlc] / src / control / audio.c
index 52033cadc95f42b99ab5beec709ec56045b094bc..9c0185caae6d417bc94816af38a86f7676102add 100644 (file)
 #include "libvlc_internal.h"
 #include <vlc/libvlc.h>
 
+#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
+ * the end of this function.
+ */
+static aout_instance_t *GetAOut( libvlc_instance_t *p_instance,
+                                 libvlc_exception_t *p_exception )
+{
+    aout_instance_t * p_aout = NULL;
+
+    p_aout = vlc_object_find( p_instance->p_libvlc_int, VLC_OBJECT_AOUT, FIND_CHILD );
+    if( !p_aout )
+    {
+        libvlc_exception_raise( p_exception, "No active audio output" );
+        return NULL;
+    }
+
+    return p_aout;
+}
+
+
 /*****************************************************************************
  * libvlc_audio_get_mute : Get the volume state, true if muted
  *****************************************************************************/
@@ -94,96 +142,118 @@ void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
 /*****************************************************************************
  * libvlc_audio_get_track : Get the current audio track
  *****************************************************************************/
-int libvlc_audio_get_track( libvlc_instance_t *p_instance,
+int libvlc_audio_get_track( libvlc_input_t *p_input,
                             libvlc_exception_t *p_e )
 {
-    int i_track = 0;
+    input_thread_t *p_input_thread = GetInput( p_input, 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_instance->p_libvlc_int, "audio-track" );
+    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_instance_t *p_instance, int i_track,
+void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track,
                              libvlc_exception_t *p_e )
 {
+    input_thread_t *p_input_thread = GetInput( p_input, p_e );
+    vlc_value_t val_list;
     int i_ret = -1;
+    int i;
 
-    i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-track", i_track );
+    if( !p_input_thread )
+        return;
 
-    if( i_ret < 0 )
+    var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
+    for( i = 0; i < val_list.p_list->i_count; i++ )
     {
-        libvlc_exception_raise( p_e, "Setting audio track failed" );
+        vlc_value_t val = val_list.p_list->p_values[i];
+        if( i_track == i )
+        {
+            i_ret = var_Set( p_input_thread, "audio-es", val );
+            if( i_ret < 0 )
+            {
+                libvlc_exception_raise( p_e, "Setting audio track failed" );
+            }
+            vlc_object_release( p_input_thread );
+            return;
+        }
     }
+    libvlc_exception_raise( p_e, "Audio track out of range" );
+    vlc_object_release( p_input_thread );
 }
 
 /*****************************************************************************
  * 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 )
 {
-    char *psz_channel = NULL;
-    int i_channel = 0;
+    aout_instance_t *p_aout = GetAOut( p_instance, p_e );
+    vlc_value_t val;
 
-    i_channel = var_GetInteger( p_instance->p_libvlc_int, "audio-channel" );
-    switch( i_channel )
-    {
-        case AOUT_VAR_CHAN_RSTEREO:
-            psz_channel = strdup("reverse");
-            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;
-    }
-    return psz_channel;
+    var_Get( p_aout, "audio-channels", &val );
+    vlc_object_release( p_aout );
+    return val.i_int;
 }
 
 /*****************************************************************************
  * 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;
     int i_ret = -1;
-    int i_channel = 0;
 
-    if( !psz_channel )
-    {
-        libvlc_exception_raise( p_e, "Audio track out of range" );
-    }
-    else
+    val.i_int = i_channel;
+    switch( i_channel )
     {
-        if( strncmp( psz_channel, "reverse", 7 ) == 0 )
-            i_channel = AOUT_VAR_CHAN_RSTEREO;
-        else if( strncmp( psz_channel, "stereo", 6 ) == 0 )
-            i_channel = AOUT_VAR_CHAN_STEREO;
-        else if( strncmp( psz_channel, "left", 4 ) == 0 )
-            i_channel = AOUT_VAR_CHAN_LEFT;
-        else if( strncmp( psz_channel, "right", 5 ) == 0 )
-            i_channel = AOUT_VAR_CHAN_RIGHT;
-        else if( strncmp( psz_channel, "dolby", 5 ) == 0 )
-            i_channel = AOUT_VAR_CHAN_DOLBYS;
-
-        i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-channel", i_channel );
-        if( i_ret < 0 )
-        {
-            libvlc_exception_raise( p_e, "Audio track out of 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; /* Found */
+        default:
+            libvlc_exception_raise( p_e, "Audio channel out of range" );
+            break;
     }
+    vlc_object_release( p_aout );
 }