]> git.sesse.net Git - vlc/commitdiff
Add support to the activex, mozilla, firefox, safari plugin for changing audio track...
authorJean-Paul Saman <jpsaman@videolan.org>
Tue, 12 Dec 2006 11:18:38 +0000 (11:18 +0000)
committerJean-Paul Saman <jpsaman@videolan.org>
Tue, 12 Dec 2006 11:18:38 +0000 (11:18 +0000)
activex/axvlc.idl
activex/vlccontrol2.cpp
activex/vlccontrol2.h
include/vlc/libvlc.h
mozilla/control/npolibvlc.cpp
src/control/audio.c

index 8faef08c2e04fb5b03884a7fe7571e507bfba3b4..4290902404f21b38b5ac88959bfa9b96f75c193c 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 the VideoLAN team\r
  *\r
  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
+ *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>\r
  *\r
  * This program is free software; you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
@@ -198,6 +199,16 @@ library AXVLC
 \r
         [helpstring("Mute/unmute audio playback.")]\r
         HRESULT toggleMute();\r
+\r
+        [propget, helpstring("Returns/sets audio track used/to use.")]\r
+        HRESULT track([out, retval] long* track);\r
+        [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
+        HRESULT channel([out, retval] BSTR* channel);\r
+        [propput, helpstring("Sets audio channel to: reverse, stereo, left, right, dolby.")]\r
+        HRESULT channel([in] BSTR channel);\r
     };\r
 \r
     [\r
index 54709ee4a7b14c8785be1f5e579281d1abe50f6f..addee00639ffbb863cacbc881810dfcb5e8c4902 100755 (executable)
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 the VideoLAN team
  *
  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -198,6 +199,119 @@ STDMETHODIMP VLCAudio::put_volume(long volume)
     return hr;
 };
 
+STDMETHODIMP VLCAudio::get_track(long* track)
+{
+    if( NULL == track )
+        return E_POINTER;
+
+    libvlc_instance_t* p_libvlc;
+    HRESULT hr = _p_instance->getVLC(&p_libvlc);
+    if( SUCCEEDED(hr) )
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        *track = libvlc_audio_get_track(p_libvlc, &ex);
+        if( libvlc_exception_raised(&ex) )
+        {
+            _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return E_FAIL;
+        }
+        return NOERROR;
+    }
+    return hr;
+};
+
+STDMETHODIMP VLCAudio::put_track(long track)
+{
+    libvlc_instance_t* p_libvlc;
+    HRESULT hr = _p_instance->getVLC(&p_libvlc);
+    if( SUCCEEDED(hr) )
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_audio_set_track(p_libvlc, track, &ex);
+        if( libvlc_exception_raised(&ex) )
+        {
+            _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return E_FAIL;
+        }
+        return NOERROR;
+    }
+    return hr;
+};
+
+STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
+{
+    if( NULL == channel )
+        return E_POINTER;
+
+    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 = libvlc_audio_get_channel(p_libvlc, &ex);
+        if( ! libvlc_exception_raised(&ex) )
+        {
+            if( NULL == psz_channel )
+                return E_OUTOFMEMORY;
+
+            *channel = SysAllocStringByteLen(psz_channel, strlen(psz_channel));
+            free( psz_channel );
+            psz_channel = NULL;
+            return NOERROR;
+        }
+        if( psz_channel ) free( psz_channel );
+        _p_instance->setErrorInfo(IID_IVLCAudio,
+                    libvlc_exception_get_message(&ex));
+        libvlc_exception_clear(&ex);
+        return E_FAIL;
+    }
+    return hr;
+};
+
+STDMETHODIMP VLCAudio::put_channel(BSTR 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);
+        if( libvlc_exception_raised(&ex) )
+        {
+            _p_instance->setErrorInfo(IID_IVLCAudio,
+                         libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return E_FAIL;
+        }
+        return NOERROR;
+    }
+    return hr;
+};
+
 STDMETHODIMP VLCAudio::toggleMute()
 {
     libvlc_instance_t* p_libvlc;
@@ -2261,7 +2375,7 @@ STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
 
     return NOERROR;
 };
-        
+
 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
 {
     _p_instance->setVisible(isVisible != VARIANT_FALSE);
@@ -2277,7 +2391,7 @@ STDMETHODIMP VLCControl2::get_Volume(long *volume)
     *volume  = _p_instance->getVolume();
     return NOERROR;
 };
-        
+
 STDMETHODIMP VLCControl2::put_Volume(long volume)
 {
     _p_instance->setVolume(volume);
index 2d0fd750767f380cf0e55b3ec78b62a1f403363e..eb23d84549166eb149cf7a91948fa4e1b2406fe3 100755 (executable)
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 the VideoLAN team
  *
  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -65,8 +66,12 @@ public:
     STDMETHODIMP put_mute(VARIANT_BOOL);
     STDMETHODIMP get_volume(long*);
     STDMETHODIMP put_volume(long);
+    STDMETHODIMP get_track(long*);
+    STDMETHODIMP put_track(long);
+    STDMETHODIMP get_channel(BSTR*);
+    STDMETHODIMP put_channel(BSTR);
     STDMETHODIMP toggleMute();
+
 protected:
     HRESULT loadTypeInfo();
 
@@ -75,7 +80,7 @@ private:
     ITypeInfo*      _p_typeinfo;
 
 };
+
 class VLCInput : public IVLCInput
 {
 public:
@@ -130,7 +135,7 @@ private:
     ITypeInfo*      _p_typeinfo;
 
 };
+
 class VLCMessage: public IVLCMessage
 {
 public:
@@ -184,7 +189,7 @@ public:
     STDMETHODIMP get_name(BSTR *);
     STDMETHODIMP get_header(BSTR *);
     STDMETHODIMP get_message(BSTR *);
-    
+
 protected:
     HRESULT loadTypeInfo();
 
@@ -195,7 +200,7 @@ private:
 
     struct libvlc_log_message_t _msg;
 };
+
 class VLCLog;
 
 class VLCMessageIterator : public IVLCMessageIterator
@@ -255,7 +260,7 @@ private:
     VLCLog*                 _p_vlclog;
     libvlc_log_iterator_t*  _p_iter;
 };
+
 class VLCMessages : public IVLCMessages
 {
 public:
@@ -297,7 +302,7 @@ public:
     STDMETHODIMP clear();
     STDMETHODIMP get_count(long*);
     STDMETHODIMP iterator(IVLCMessageIterator**);
-    
+
 protected:
     HRESULT loadTypeInfo();
 
@@ -355,7 +360,7 @@ public:
     STDMETHODIMP get_messages(IVLCMessages**);
     STDMETHODIMP get_verbosity(long *);
     STDMETHODIMP put_verbosity(long);
-    
+
 protected:
     HRESULT loadTypeInfo();
 
@@ -367,7 +372,7 @@ private:
 
     VLCMessages*    _p_vlcmessages;
 };
+
 class VLCPlaylistItems : public IVLCPlaylistItems
 {
 public:
@@ -405,7 +410,7 @@ public:
     STDMETHODIMP get_count(long*);
     STDMETHODIMP clear();
     STDMETHODIMP remove(long);
+
 protected:
     HRESULT loadTypeInfo();
 
@@ -414,7 +419,7 @@ private:
     ITypeInfo*  _p_typeinfo;
 
 };
+
 class VLCPlaylist : public IVLCPlaylist
 {
 public:
@@ -466,7 +471,7 @@ public:
     STDMETHODIMP clear();
     STDMETHODIMP removeItem(long);
     STDMETHODIMP get_items(IVLCPlaylistItems**);
+
 protected:
     HRESULT loadTypeInfo();
 
@@ -476,7 +481,7 @@ private:
 
     VLCPlaylistItems*    _p_vlcplaylistitems;
 };
+
 class VLCVideo : public IVLCVideo
 {
 public:
@@ -518,7 +523,7 @@ public:
     STDMETHODIMP get_aspectRatio(BSTR*);
     STDMETHODIMP put_aspectRatio(BSTR);
     STDMETHODIMP toggleFullscreen();
+
 protected:
     HRESULT loadTypeInfo();
 
@@ -527,10 +532,9 @@ private:
     ITypeInfo*      _p_typeinfo;
 
 };
+
 class VLCControl2 : public IVLCControl2
 {
-    
 public:
 
     VLCControl2(VLCPlugin *p_instance);
@@ -597,6 +601,5 @@ private:
     VLCPlaylist*    _p_vlcplaylist;
     VLCVideo*       _p_vlcvideo;
 };
-#endif
 
+#endif
index 10a8b7400dd1418bfc9b8e6e971c05c177e5aee1..688d940fa01992c6bb8e3273ee4e028a0221dec8 100644 (file)
@@ -5,6 +5,7 @@
  * $Id: vlc.h 13701 2005-12-12 17:58:56Z zorglub $
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
+ *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -486,7 +487,41 @@ int libvlc_audio_get_volume( libvlc_instance_t *, libvlc_exception_t * );
  * \param p_exception an initialized exception
  * \return void
  */
-void libvlc_audio_set_volume( libvlc_instance_t *, int , 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 * );
+
+/**
+ * Set current audio track
+ * \param p_instance libvlc 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 * );
+
+/**
+ * Get current audio channel
+ * \param p_instance libvlc 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
+ * \param psz_channel the audio channel (char *)
+ * \param p_exception an initialized exception
+ * \return void
+ */
+void libvlc_audio_set_channel( libvlc_instance_t *, char *, libvlc_exception_t * );
 
 /** @} */
 
index 15837078ce50ffff0d2f049da96ea1dc6903cd21..597c21b1bb376da37231f4c71b1fe677a515daf9 100755 (executable)
@@ -177,6 +177,8 @@ const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
 {\r
     "mute",\r
     "volume",\r
+    "track",\r
+    "channel",\r
 };\r
 \r
 const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);\r
@@ -185,6 +187,8 @@ enum LibvlcAudioNPObjectPropertyIds
 {\r
     ID_audio_mute,\r
     ID_audio_volume,\r
+    ID_audio_track,\r
+    ID_audio_channel,\r
 };\r
 \r
 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)\r
@@ -221,6 +225,46 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
                 INT32_TO_NPVARIANT(volume, result);\r
                 return INVOKERESULT_NO_ERROR;\r
             }\r
+            case ID_audio_track:\r
+            {\r
+                int track = libvlc_audio_get_track(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
+                INT32_TO_NPVARIANT(track, result);\r
+                return INVOKERESULT_NO_ERROR;\r
+            }\r
+            case ID_audio_channel:\r
+            {\r
+                char *channel = libvlc_audio_get_channel(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
+                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
+            }\r
             default:\r
                 ;\r
         }\r
@@ -266,6 +310,45 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
                     return INVOKERESULT_NO_ERROR;\r
                 }\r
                 return INVOKERESULT_INVALID_VALUE;\r
+            case ID_audio_track:\r
+                if( isNumberValue(value) )\r
+                {\r
+                    libvlc_audio_set_track(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_INVALID_VALUE;\r
+            case ID_audio_channel:\r
+            {\r
+                char *psz_channel = NULL;\r
+\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
+                    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
+                {\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
             default:\r
                 ;\r
         }\r
index 9f2b6ab47bd7e4db61783184e7701fc432a9dce9..60f359d3ad848abc06f082ab72ac0bc1ea3498e5 100644 (file)
@@ -5,6 +5,7 @@
  * $Id$
  *
  * Authors: Filippo Carone <filippo@carone.org>
+ *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -90,3 +91,99 @@ 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,
+                            libvlc_exception_t *p_e )
+{
+    int i_track = 0;
+
+    i_track = var_GetInteger( p_instance->p_libvlc_int, "audio-track" );
+
+    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,
+                             libvlc_exception_t *p_e )
+{
+    int i_ret = -1;
+
+    i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-track", i_track );
+
+    if( i_ret < 0 )
+    {
+        libvlc_exception_raise( p_e, "Audio track out of range" );
+    }
+}
+
+/*****************************************************************************
+ * libvlc_audio_get_channel : Get the current audio channel
+ *****************************************************************************/
+char *libvlc_audio_get_channel( libvlc_instance_t *p_instance,
+                                libvlc_exception_t *p_e )
+{
+    char *psz_channel = NULL;
+    int i_channel = 0;
+
+    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;
+}
+
+/*****************************************************************************
+ * libvlc_audio_set_channel : Set the current audio channel
+ *****************************************************************************/
+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;
+
+    if( !psz_channel )
+    {
+        libvlc_exception_raise( p_e, "Audio track out of range" );
+    }
+    else
+    {
+        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" );
+        }
+    }
+}