]> git.sesse.net Git - vlc/commitdiff
Audio track and channel support for JavaScript API. The ActiveX vlc.audio.channel...
authorJean-Paul Saman <jpsaman@videolan.org>
Wed, 20 Dec 2006 22:11:54 +0000 (22:11 +0000)
committerJean-Paul Saman <jpsaman@videolan.org>
Wed, 20 Dec 2006 22:11:54 +0000 (22:11 +0000)
activex/axvlc.idl
activex/vlccontrol2.cpp
include/vlc/libvlc.h
mozilla/control/npolibvlc.cpp
mozilla/control/npolibvlc.h
src/control/audio.c
src/control/video.c

index 4290902404f21b38b5ac88959bfa9b96f75c193c..0d0054176da690c527f4df54452626cf2ec62a02 100644 (file)
@@ -205,9 +205,9 @@ library AXVLC
         [propput, helpstring("Returns/sets audio track used/to use.")]\r
         HRESULT track([in] long track);\r
 \r
-        [propget, helpstring("Returns audio channel: reverse, stereo, left, right, dolby.")]\r
+        [propget, helpstring("Returns audio channel: reverse stereo, stereo, left, right, dolby.")]\r
         HRESULT channel([out, retval] BSTR* channel);\r
-        [propput, helpstring("Sets audio channel to: reverse, stereo, left, right, dolby.")]\r
+        [propput, helpstring("Sets audio channel to: reverse stereo, stereo, left, right, dolby.")]\r
         HRESULT channel([in] BSTR channel);\r
     };\r
 \r
index 4a1669afbddb3a8de26768b20ebe6b288ae1986c..d60e71266de8ed15fc3174788c5d20e433a0f520 100644 (file)
@@ -211,7 +211,9 @@ STDMETHODIMP VLCAudio::get_track(long* track)
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        *track = libvlc_audio_get_track(p_libvlc, &ex);
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+        *track = libvlc_audio_get_track(p_input, &ex);
+        libvlc_input_free(p_input);
         if( libvlc_exception_raised(&ex) )
         {
             _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
@@ -232,7 +234,9 @@ STDMETHODIMP VLCAudio::put_track(long track)
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        libvlc_audio_set_track(p_libvlc, track, &ex);
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+        libvlc_audio_set_track(p_input, track, &ex);
+        libvlc_input_free(p_input);
         if( libvlc_exception_raised(&ex) )
         {
             _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
@@ -265,9 +269,11 @@ STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
 
             *channel = BSTRFromCStr(CP_UTF8, psz_channel);
             free( psz_channel );
-            return NOERROR;
+            psz_channel = NULL;
+            return (NULL == *channel) ? E_OUTOFMEMORY : NOERROR;
         }
         if( psz_channel ) free( psz_channel );
+        psz_channel = NULL;
         _p_instance->setErrorInfo(IID_IVLCAudio,
                     libvlc_exception_get_message(&ex));
         libvlc_exception_clear(&ex);
@@ -297,7 +303,6 @@ STDMETHODIMP VLCAudio::put_channel(BSTR channel)
             return E_OUTOFMEMORY;
 
         libvlc_audio_set_channel(p_libvlc, psz_channel, &ex);
-
         CoTaskMemFree(psz_channel);
         if( libvlc_exception_raised(&ex) )
         {
@@ -2087,12 +2092,13 @@ STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
                 if( NULL == psz_aspect )
                     return E_OUTOFMEMORY;
 
-                *aspect = SysAllocStringByteLen(psz_aspect, strlen(psz_aspect));
+                *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
                 free( psz_aspect );
                 psz_aspect = NULL;
-                return NOERROR;
+                return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR;
             }
             if( psz_aspect ) free( psz_aspect );
+            psz_aspect = NULL;
         }
         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
         libvlc_exception_clear(&ex);
@@ -2466,4 +2472,3 @@ STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
     }
     return E_OUTOFMEMORY;
 };
-
index 12406a36c52a6798c49f88726135b25e3a4f590f..8e4c51eb21f80aaca1490a0b9be8eb39c6a38bac 100644 (file)
@@ -492,33 +492,33 @@ int libvlc_audio_get_volume( libvlc_instance_t *, libvlc_exception_t * );
 void libvlc_audio_set_volume( libvlc_instance_t *, int, libvlc_exception_t *);
 
 /**
- * Get current audio track
- * \param p_instance libvlc instance
- * \param p_exception an initialized exception
- * \return the audio track (int)
- */
-int libvlc_audio_get_track( libvlc_instance_t *, libvlc_exception_t * );
+ * Get current audio track
++  * \param p_input input instance
+ * \param p_exception an initialized exception
+ * \return the audio track (int)
+ */
+int libvlc_audio_get_track( libvlc_input_t *, libvlc_exception_t * );
 
 /**
  * Set current audio track
- * \param p_instance libvlc instance
+ * \param p_input input instance
  * \param i_track the track (int)
  * \param p_exception an initialized exception
  * \return void
  */
-void libvlc_audio_set_track( libvlc_instance_t *, int, libvlc_exception_t * );
+void libvlc_audio_set_track( libvlc_input_t *, int, libvlc_exception_t * );
 
 /**
  * Get current audio channel
- * \param p_instance libvlc instance
+ * \param p_instance input instance
  * \param p_exception an initialized exception
  * \return the audio channel (char *)
  */
 char *libvlc_audio_get_channel( libvlc_instance_t *, libvlc_exception_t * );
 
 /**
- * Set current audio track
- * \param p_instance libvlc instance
+ * Set current audio channel
+ * \param p_instance input instance
  * \param psz_channel the audio channel (char *)
  * \param p_exception an initialized exception
  * \return void
index 597c21b1bb376da37231f4c71b1fe677a515daf9..1221d7fd87772656f54c6f2a300f09783785c2ee 100755 (executable)
@@ -199,11 +199,20 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
+        if( libvlc_exception_raised(&ex) )\r
+        {\r
+            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+            libvlc_exception_clear(&ex);\r
+            return INVOKERESULT_GENERIC_ERROR;\r
+        }\r
+\r
         switch( index )\r
         {\r
             case ID_audio_mute:\r
             {\r
                 vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);\r
+                libvlc_input_free(p_input);\r
                 if( libvlc_exception_raised(&ex) )\r
                 {\r
                     NPN_SetException(this, libvlc_exception_get_message(&ex));\r
@@ -216,6 +225,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
             case ID_audio_volume:\r
             {\r
                 int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);\r
+                libvlc_input_free(p_input);\r
                 if( libvlc_exception_raised(&ex) )\r
                 {\r
                     NPN_SetException(this, libvlc_exception_get_message(&ex));\r
@@ -227,7 +237,8 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
             }\r
             case ID_audio_track:\r
             {\r
-                int track = libvlc_audio_get_track(p_plugin->getVLC(), &ex);\r
+                int track = libvlc_audio_get_track(p_input, &ex);\r
+                libvlc_input_free(p_input);\r
                 if( libvlc_exception_raised(&ex) )\r
                 {\r
                     NPN_SetException(this, libvlc_exception_get_message(&ex));\r
@@ -239,35 +250,24 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
             }\r
             case ID_audio_channel:\r
             {\r
-                char *channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);\r
+                NPUTF8 *psz_channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);\r
+                libvlc_input_free(p_input);\r
                 if( libvlc_exception_raised(&ex) )\r
                 {\r
                     NPN_SetException(this, libvlc_exception_get_message(&ex));\r
                     libvlc_exception_clear(&ex);\r
                     return INVOKERESULT_GENERIC_ERROR;\r
                 }\r
-                if( channel )\r
-                {\r
-                    int len = strlen(channel);\r
-                    NPUTF8 *retval = (NPUTF8*)NPN_MemAlloc(len);\r
-                    if( retval )\r
-                    {\r
-                        memcpy(retval, channel, len);\r
-                        STRINGN_TO_NPVARIANT(retval, len, result);\r
-                    }\r
-                    else\r
-                    {\r
-                        NULL_TO_NPVARIANT(result);\r
-                    }\r
-                    free( channel );\r
-                    channel = NULL;\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
+                if( !psz_channel )\r
+                    return INVOKERESULT_GENERIC_ERROR;\r
+\r
+                STRINGZ_TO_NPVARIANT(psz_channel, result);\r
+                return INVOKERESULT_NO_ERROR;\r
             }\r
             default:\r
                 ;\r
         }\r
+        libvlc_input_free(p_input);\r
     }\r
     return INVOKERESULT_GENERIC_ERROR;\r
 }\r
@@ -280,6 +280,14 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
+        if( libvlc_exception_raised(&ex) )\r
+        {\r
+            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+            libvlc_exception_clear(&ex);\r
+            return INVOKERESULT_GENERIC_ERROR;\r
+        }\r
+\r
         switch( index )\r
         {\r
             case ID_audio_mute:\r
@@ -287,6 +295,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
                 {\r
                     libvlc_audio_set_mute(p_plugin->getVLC(),\r
                                           NPVARIANT_TO_BOOLEAN(value), &ex);\r
+                    libvlc_input_free(p_input);\r
                     if( libvlc_exception_raised(&ex) )\r
                     {\r
                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
@@ -297,6 +306,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
                 }\r
                 return INVOKERESULT_INVALID_VALUE;\r
             case ID_audio_volume:\r
+                libvlc_input_free(p_input);\r
                 if( isNumberValue(value) )\r
                 {\r
                     libvlc_audio_set_volume(p_plugin->getVLC(),\r
@@ -313,8 +323,9 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
             case ID_audio_track:\r
                 if( isNumberValue(value) )\r
                 {\r
-                    libvlc_audio_set_track(p_plugin->getVLC(),\r
+                    libvlc_audio_set_track(p_input,\r
                                            numberValue(value), &ex);\r
+                    libvlc_input_free(p_input);\r
                     if( libvlc_exception_raised(&ex) )\r
                     {\r
                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
@@ -323,15 +334,15 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
                     }\r
                     return INVOKERESULT_NO_ERROR;\r
                 }\r
+                libvlc_input_free(p_input);\r
                 return INVOKERESULT_INVALID_VALUE;\r
             case ID_audio_channel:\r
             {\r
                 char *psz_channel = NULL;\r
 \r
+                libvlc_input_free(p_input);\r
                 if( ! NPVARIANT_IS_STRING(value) )\r
-                {\r
                     return INVOKERESULT_INVALID_VALUE;\r
-                }\r
 \r
                 psz_channel = stringValue(NPVARIANT_TO_STRING(value));\r
                 if( !psz_channel )\r
@@ -352,6 +363,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
             default:\r
                 ;\r
         }\r
+        libvlc_input_free(p_input);\r
     }\r
     return INVOKERESULT_GENERIC_ERROR;\r
 }\r
@@ -1900,7 +1912,10 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
 \r
                 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));\r
                 if( !psz_aspect )\r
+                {\r
+                    libvlc_input_free(p_input);\r
                     return INVOKERESULT_GENERIC_ERROR;\r
+                }\r
 \r
                 libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);\r
                 if( psz_aspect )\r
index d9f635fb01fcd3ac90e0ab721c93a49038cd63f7..b0639ff5803d4d3fa042e45aa037d08165f27355 100755 (executable)
@@ -80,7 +80,7 @@ protected:
 \r
     LibvlcInputNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass) {};\r
-        \r
+\r
     virtual ~LibvlcInputNPObject() {};\r
 \r
     static const int propertyCount;\r
@@ -106,7 +106,7 @@ protected:
 \r
     LibvlcMessageNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass) {};\r
-        \r
+\r
     virtual ~LibvlcMessageNPObject() {};\r
 \r
     static const int propertyCount;\r
@@ -152,7 +152,7 @@ protected:
 \r
     LibvlcMessagesNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass) {};\r
-        \r
+\r
     virtual ~LibvlcMessagesNPObject() {};\r
 \r
     static const int propertyCount;\r
index 52033cadc95f42b99ab5beec709ec56045b094bc..f6b7bdc61944b304df47b30249eca7c5c8c2abb0 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,12 +142,14 @@ 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 )
 {
+    input_thread_t *p_input_thread = GetInput( p_input, p_e );
     int i_track = 0;
 
-    i_track = var_GetInteger( p_instance->p_libvlc_int, "audio-track" );
+    i_track = var_GetInteger( p_input_thread, "audio-es" );
+    vlc_object_release( p_input_thread );
 
     return i_track;
 }
@@ -107,17 +157,31 @@ int libvlc_audio_get_track( libvlc_instance_t *p_instance,
 /*****************************************************************************
  * 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( 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 == val.i_int )
+        {
+            i_ret = var_SetInteger( p_input_thread, "audio-es", i_track );
+            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 );
 }
 
 /*****************************************************************************
@@ -126,14 +190,15 @@ void libvlc_audio_set_track( libvlc_instance_t *p_instance, int i_track,
 char *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;
-    int i_channel = 0;
+    vlc_value_t val;
 
-    i_channel = var_GetInteger( p_instance->p_libvlc_int, "audio-channel" );
-    switch( i_channel )
+    var_Get( p_aout, "audio-channels", &val );
+    switch( val.i_int )
     {
         case AOUT_VAR_CHAN_RSTEREO:
-            psz_channel = strdup("reverse");
+            psz_channel = strdup("reverse stereo");
             break;
         case AOUT_VAR_CHAN_STEREO:
             psz_channel = strdup("stereo");
@@ -151,6 +216,7 @@ char *libvlc_audio_get_channel( libvlc_instance_t *p_instance,
             psz_channel = strdup("disabled");
             break;
     }
+    vlc_object_release( p_aout );
     return psz_channel;
 }
 
@@ -160,30 +226,33 @@ char *libvlc_audio_get_channel( libvlc_instance_t *p_instance,
 void libvlc_audio_set_channel( libvlc_instance_t *p_instance, char *psz_channel,
                                libvlc_exception_t *p_e )
 {
-    int i_ret = -1;
-    int i_channel = 0;
+    aout_instance_t *p_aout = GetAOut( p_instance, p_e );
+    vlc_value_t val_list, text_list;
+    int i_ret = -1, i;
 
-    if( !psz_channel )
+    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 track out of range" );
+        libvlc_exception_raise( p_e, "Audio channel out of range" );
+        vlc_object_release( p_aout );
+        return;
     }
-    else
+
+    for( i = 0; i < val_list.p_list->i_count; i++ )
     {
-        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 )
+        vlc_value_t val = val_list.p_list->p_values[i];
+        vlc_value_t text = text_list.p_list->p_values[i];
+
+        if( strncasecmp( psz_channel, text.psz_string, strlen(text.psz_string) ) == 0 )
         {
-            libvlc_exception_raise( p_e, "Audio track out of range" );
+            i_ret = var_Set( p_aout, "audio-channels", val );
+            if( i_ret < 0 )
+            {
+                break;
+            }
         }
     }
+    libvlc_exception_raise( p_e, "Audio channel out of range" );
+    vlc_object_release( p_aout );
 }
+
index 371739f645220fca9de5986ee78edcf4b7cec7a7..d6d850bbf117b663e844d1f8d7952a812ff659e6 100644 (file)
@@ -200,10 +200,10 @@ vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
     if ( libvlc_exception_raised( p_e ) )
     {
         if ( strcmp( "No active video output", libvlc_exception_get_message( p_e ) ) == 0 )
-       {
-           libvlc_exception_clear( p_e );
-       }
-       return VLC_FALSE;
+        {
+            libvlc_exception_clear( p_e );
+        }
+        return VLC_FALSE;
     }
 
     vlc_object_release( p_vout );
@@ -221,7 +221,7 @@ int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
         /// \todo: set exception
         return 0;
     }
-    
+
     vout_Control( p_vout , VOUT_REPARENT, d);
     vlc_object_release( p_vout );