[vlc-commits] Add support for multiple video tracks

Daniel Amm git at videolan.org
Tue Jun 6 18:18:07 CEST 2017


npapi-vlc | branch: master | Daniel Amm <da2424 at t-online.de> | Tue Jun  6 17:30:59 2017 +0200| [8d974bf0364402963e3e743311e70970e055af8e] | committer: Hugo Beauzée-Luyssen

Add support for multiple video tracks

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

> https://code.videolan.org/videolan/npapi-vlc/commit/8d974bf0364402963e3e743311e70970e055af8e
---

 activex/axvlc.idl             | 10 +++++++++
 activex/vlccontrol2.cpp       | 40 +++++++++++++++++++++++++++++++++
 activex/vlccontrol2.h         |  4 ++++
 common/vlc_player.cpp         |  7 ++++++
 common/vlc_player.h           |  1 +
 npapi/npruntime/npolibvlc.cpp | 51 +++++++++++++++++++++++++++++++++++++++++--
 6 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/activex/axvlc.idl b/activex/axvlc.idl
index 12cf596..9202ab2 100644
--- a/activex/axvlc.idl
+++ b/activex/axvlc.idl
@@ -537,6 +537,16 @@ library AXVLC
         [helpstring("toggle teletext transparent state.")]
         HRESULT toggleTeletext();
 
+        [propget, helpstring("Returns/sets video track used/to use.")]
+        HRESULT track([out, retval] long* track);
+        [propput, helpstring("Returns/sets video track used/to use.")]
+        HRESULT track([in] long track);
+
+        [propget, helpstring("Returns the number of video tracks available.")]
+        HRESULT count([out, retval] long* trackNumber);
+        [helpstring("Returns video track name.")]
+        HRESULT description([in] long trackID, [out, retval] BSTR* name);
+
         [propget, helpstring("Returns the marquee object.")]
         HRESULT marquee([out, retval] IVLCMarquee** obj);
 
diff --git a/activex/vlccontrol2.cpp b/activex/vlccontrol2.cpp
index 2ec4f8c..b8c3bb3 100644
--- a/activex/vlccontrol2.cpp
+++ b/activex/vlccontrol2.cpp
@@ -1283,6 +1283,46 @@ STDMETHODIMP VLCVideo::toggleTeletext()
 #endif
 }
 
+STDMETHODIMP VLCVideo::get_track(long* track)
+{
+    if( NULL == track )
+        return E_POINTER;
+
+    *track = _plug->get_player().currentVideoTrack();
+    return S_OK;
+}
+
+STDMETHODIMP VLCVideo::put_track(long track)
+{
+    auto tracks = _plug->get_player().get_mp().videoTrackDescription();
+    if ( track >= tracks.size() )
+        return E_INVALIDARG;
+    _plug->get_player().get_mp().setVideoTrack( tracks[track].id() );
+    return S_OK;
+}
+
+STDMETHODIMP VLCVideo::get_count(long* trackNumber)
+{
+    if( NULL == trackNumber )
+        return E_POINTER;
+
+    *trackNumber = negativeToZero( _plug->get_player().get_mp().videoTrackCount() );
+
+    return S_OK;
+}
+
+STDMETHODIMP VLCVideo::description(long trackId, BSTR* name)
+{
+    if( NULL == name )
+        return E_POINTER;
+
+    auto tracks = _plug->get_player().get_mp().videoTrackDescription();
+    if ( trackId >= tracks.size() )
+        return E_INVALIDARG;
+    *name = BSTRFromCStr( CP_UTF8, tracks[trackId].name().c_str() );
+    return (NULL == *name) ? E_OUTOFMEMORY : S_OK;
+}
+
 STDMETHODIMP VLCVideo::get_marquee(IVLCMarquee** obj)
 {
     return object_get(obj,_p_vlcmarquee);
diff --git a/activex/vlccontrol2.h b/activex/vlccontrol2.h
index c5bc1cb..2a9bfc5 100644
--- a/activex/vlccontrol2.h
+++ b/activex/vlccontrol2.h
@@ -357,6 +357,10 @@ public:
     STDMETHODIMP takeSnapshot(LPPICTUREDISP*);
     STDMETHODIMP toggleFullscreen();
     STDMETHODIMP toggleTeletext();
+    STDMETHODIMP get_track(long*);
+    STDMETHODIMP put_track(long);
+    STDMETHODIMP get_count(long*);
+    STDMETHODIMP description(long, BSTR*);
 
 private:
     IVLCMarquee     *_p_vlcmarquee;
diff --git a/common/vlc_player.cpp b/common/vlc_player.cpp
index 12f09ef..3b64f3f 100644
--- a/common/vlc_player.cpp
+++ b/common/vlc_player.cpp
@@ -120,6 +120,13 @@ int vlc_player::currentSubtitleTrack()
     return getTrack( current, tracks );
 }
 
+int vlc_player::currentVideoTrack()
+{
+    auto current = _mp.videoTrack();
+    auto tracks = _mp.videoTrackDescription();
+    return getTrack( current, tracks );
+}
+
 int vlc_player::getTrack( int currentId, const std::vector<VLC::TrackDescription>& tracks )
 {
     if ( tracks.empty() )
diff --git a/common/vlc_player.h b/common/vlc_player.h
index 8a09945..9d48c62 100644
--- a/common/vlc_player.h
+++ b/common/vlc_player.h
@@ -60,6 +60,7 @@ public:
 
     int currentAudioTrack();
     int currentSubtitleTrack();
+    int currentVideoTrack();
 
 private:
     // Returns a 0-based track index, instead of the internal libvlc one
diff --git a/npapi/npruntime/npolibvlc.cpp b/npapi/npruntime/npolibvlc.cpp
index 81bab1d..f096b4c 100644
--- a/npapi/npruntime/npolibvlc.cpp
+++ b/npapi/npruntime/npolibvlc.cpp
@@ -1332,6 +1332,8 @@ const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
     "subtitle",
     "crop",
     "teletext",
+    "track",
+    "count",
     "marquee",
     "logo",
     "deinterlace",
@@ -1346,6 +1348,8 @@ enum LibvlcVideoNPObjectPropertyIds
     ID_video_subtitle,
     ID_video_crop,
     ID_video_teletext,
+    ID_video_track,
+    ID_video_count,
     ID_video_marquee,
     ID_video_logo,
     ID_video_deinterlace,
@@ -1407,6 +1411,16 @@ LibvlcVideoNPObject::getProperty(int index, npapi::OutVariant& result)
                 result = i_page;
                 return INVOKERESULT_NO_ERROR;
             }
+            case ID_video_track:
+            {
+                result = p_plugin->player().currentVideoTrack();
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_count:
+            {
+                result = negativeToZero( mp.videoTrackCount() );
+                return INVOKERESULT_NO_ERROR;
+            }
             case ID_video_marquee:
             {
                 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
@@ -1503,6 +1517,18 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
                 }
                 return INVOKERESULT_INVALID_VALUE;
             }
+            case ID_video_track:
+            {
+                if( v.is<int>() )
+                {
+                    auto tracks = mp.videoTrackDescription();
+                    if ( v >= tracks.size() )
+                        return INVOKERESULT_INVALID_VALUE;
+                    mp.setVideoTrack( tracks[v].id() );
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_INVALID_VALUE;
+            }
         }
     }
     return INVOKERESULT_GENERIC_ERROR;
@@ -1512,6 +1538,7 @@ const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
 {
     "toggleFullscreen",
     "toggleTeletext",
+    "description",
 };
 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
 
@@ -1519,16 +1546,20 @@ enum LibvlcVideoNPObjectMethodIds
 {
     ID_video_togglefullscreen,
     ID_video_toggleteletext,
+    ID_video_description,
 };
 
 RuntimeNPObject::InvokeResult
-LibvlcVideoNPObject::invoke(int index, const NPVariant *,
-                            uint32_t argCount, npapi::OutVariant&)
+LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
+                            uint32_t argCount, npapi::OutVariant& result)
 {
     /* is plugin still running */
     if( isPluginRunning() )
     {
         VlcPluginBase* p_plugin = getPrivate<VlcPluginBase>();
+        auto& mp = p_plugin->getMD();
+        if( !mp )
+            RETURN_ON_ERROR;
 
         switch( index )
         {
@@ -1557,6 +1588,22 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *,
                 }
                 return INVOKERESULT_NO_SUCH_METHOD;
             }
+            case ID_video_description:
+            {
+                if ( argCount < 1 )
+                    return INVOKERESULT_INVALID_ARGS;
+                const npapi::Variant v( args[0] );
+                if( v.is<int>() )
+                {
+                    auto tracks = mp.videoTrackDescription();
+                    if ( v >= tracks.size() )
+                        return INVOKERESULT_INVALID_VALUE;
+                    /* display the name of the track chosen */
+                    result = tracks[v].name();
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            }
             default:
                 return INVOKERESULT_NO_SUCH_METHOD;
         }



More information about the vlc-commits mailing list