Reworked vlc.audio.channel API for JavaScript. All documentation is already updated.
authorJean-Paul Saman <jpsaman@videolan.org>
Sun, 7 Jan 2007 13:22:37 +0000 (13:22 +0000)
committerJean-Paul Saman <jpsaman@videolan.org>
Sun, 7 Jan 2007 13:22:37 +0000 (13:22 +0000)
activex/axvlc.idl
activex/vlccontrol2.cpp
activex/vlccontrol2.h
include/vlc/libvlc.h
mozilla/control/npolibvlc.cpp
src/control/audio.c

index 0d00541..cad9cde 100644 (file)
@@ -206,9 +206,9 @@ library AXVLC
         HRESULT track([in] long track);\r
 \r
         [propget, helpstring("Returns audio channel: reverse stereo, stereo, left, right, dolby.")]\r
-        HRESULT channel([out, retval] BSTR* channel);\r
+        HRESULT channel([out, retval] long* channel);\r
         [propput, helpstring("Sets audio channel to: reverse stereo, stereo, left, right, dolby.")]\r
-        HRESULT channel([in] BSTR channel);\r
+        HRESULT channel([in] long channel);\r
     };\r
 \r
     [\r
index 6fbe727..7e70774 100644 (file)
@@ -248,7 +248,7 @@ STDMETHODIMP VLCAudio::put_track(long track)
     return hr;
 };
 
-STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
+STDMETHODIMP VLCAudio::get_channel(long *channel)
 {
     if( NULL == channel )
         return E_POINTER;
@@ -257,53 +257,32 @@ STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
     HRESULT hr = _p_instance->getVLC(&p_libvlc);
     if( SUCCEEDED(hr) )
     {
-        char *psz_channel = NULL;
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        psz_channel = libvlc_audio_get_channel(p_libvlc, &ex);
-        if( libvlc_exception_raised(&ex) )
+        *channel = libvlc_audio_get_channel(p_libvlc, &ex);
+        if( libvlc_exception_raised(&ex) )
         {
-            if( NULL == psz_channel )
-                return E_OUTOFMEMORY;
-
-            *channel = BSTRFromCStr(CP_UTF8, psz_channel);
-            free( psz_channel );
-            psz_channel = NULL;
-            return (NULL == channel) ? E_OUTOFMEMORY : NOERROR;
+            _p_instance->setErrorInfo(IID_IVLCAudio,
+                        libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return E_FAIL;
         }
-        if( psz_channel ) free( psz_channel );
-        psz_channel = NULL;
-        _p_instance->setErrorInfo(IID_IVLCAudio,
-                    libvlc_exception_get_message(&ex));
-        libvlc_exception_clear(&ex);
-        return E_FAIL;
+        return NOERROR;
     }
     return hr;
 };
 
-STDMETHODIMP VLCAudio::put_channel(BSTR channel)
+STDMETHODIMP VLCAudio::put_channel(long channel)
 {
-    if( NULL == channel )
-        return E_POINTER;
-
-    if( 0 == SysStringLen(channel) )
-        return E_INVALIDARG;
-
     libvlc_instance_t* p_libvlc;
     HRESULT hr = _p_instance->getVLC(&p_libvlc);
     if( SUCCEEDED(hr) )
     {
-        char *psz_channel = NULL;
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        psz_channel = CStrFromBSTR(CP_UTF8, channel);
-        if( NULL == psz_channel )
-            return E_OUTOFMEMORY;
-
-        libvlc_audio_set_channel(p_libvlc, psz_channel, &ex);
-        CoTaskMemFree(psz_channel);
+        libvlc_audio_set_channel(p_libvlc, channel, &ex);
         if( libvlc_exception_raised(&ex) )
         {
             _p_instance->setErrorInfo(IID_IVLCAudio,
index eb23d84..37adc97 100644 (file)
@@ -68,8 +68,8 @@ public:
     STDMETHODIMP put_volume(long);
     STDMETHODIMP get_track(long*);
     STDMETHODIMP put_track(long);
-    STDMETHODIMP get_channel(BSTR*);
-    STDMETHODIMP put_channel(BSTR);
+    STDMETHODIMP get_channel(long*);
+    STDMETHODIMP put_channel(long);
     STDMETHODIMP toggleMute();
 
 protected:
index 5b1e864..8372e1d 100644 (file)
@@ -510,17 +510,17 @@ void libvlc_audio_set_track( libvlc_input_t *, int, libvlc_exception_t * );
  * Get current audio channel
  * \param p_instance input instance
  * \param p_exception an initialized exception
- * \return the audio channel (char *)
+ * \return the audio channel (int)
  */
-char *libvlc_audio_get_channel( libvlc_instance_t *, libvlc_exception_t * );
+int libvlc_audio_get_channel( libvlc_instance_t *, libvlc_exception_t * );
 
 /**
  * Set current audio channel
  * \param p_instance input instance
- * \param psz_channel the audio channel (char *)
+ * \param i_channel the audio channel (int)
  * \param p_exception an initialized exception
  */
-void libvlc_audio_set_channel( libvlc_instance_t *, char *, libvlc_exception_t * );
+void libvlc_audio_set_channel( libvlc_instance_t *, int, libvlc_exception_t * );
 
 /** @} */
 
index 1221d7f..f5ebe0e 100755 (executable)
@@ -250,7 +250,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
             }\r
             case ID_audio_channel:\r
             {\r
-                NPUTF8 *psz_channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);\r
+                int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);\r
                 libvlc_input_free(p_input);\r
                 if( libvlc_exception_raised(&ex) )\r
                 {\r
@@ -258,10 +258,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
                     libvlc_exception_clear(&ex);\r
                     return INVOKERESULT_GENERIC_ERROR;\r
                 }\r
-                if( !psz_channel )\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-\r
-                STRINGZ_TO_NPVARIANT(psz_channel, result);\r
+                INT32_TO_NPVARIANT(channel, result);\r
                 return INVOKERESULT_NO_ERROR;\r
             }\r
             default:\r
@@ -338,27 +335,20 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
                 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
-                    return INVOKERESULT_INVALID_VALUE;\r
-\r
-                psz_channel = stringValue(NPVARIANT_TO_STRING(value));\r
-                if( !psz_channel )\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-\r
-                libvlc_audio_set_channel(p_plugin->getVLC(), psz_channel, &ex);\r
-                if( psz_channel )\r
-                    free( psz_channel );\r
-\r
-                if( libvlc_exception_raised(&ex) )\r
+                if( isNumberValue(value) )\r
                 {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
+                    libvlc_audio_set_channel(p_plugin->getVLC(),\r
+                                         numberValue(value), &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
+                    return INVOKERESULT_NO_ERROR;\r
                 }\r
-                return INVOKERESULT_NO_ERROR;\r
+                return INVOKERESULT_INVALID_VALUE;\r
             }\r
             default:\r
                 ;\r
index 1c32afa..643edf8 100644 (file)
@@ -187,76 +187,47 @@ 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 )
-    {
-        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_object_release( p_aout );
-    return psz_channel;
+    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_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;
-    }
+    vlc_value_t val;
+    int i_ret = -1;
 
-    for( i = 0; i < val_list.p_list->i_count; i++ )
+    val.i_int = i_channel;
+    switch( i_channel )
     {
-        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 )
-        {
+        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 range" );
+                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;
     }
-    libvlc_exception_raise( p_e, "Audio channel out of range" );
     vlc_object_release( p_aout );
 }
-