[vlc-devel] [PATCH 05/16] Update QT track selection to support dual subtitles

Roland Bewick roland.bewick at gmail.com
Tue May 21 20:08:29 CEST 2019


---
 modules/gui/qt/util/input_models.cpp | 44 +++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/modules/gui/qt/util/input_models.cpp b/modules/gui/qt/util/input_models.cpp
index e381fbb917..1a33142375 100644
--- a/modules/gui/qt/util/input_models.cpp
+++ b/modules/gui/qt/util/input_models.cpp
@@ -62,7 +62,49 @@ bool TrackListModel::setData(const QModelIndex &index, const QVariant &value, in
     vlc_player_locker lock{ m_player };
 
     if (select)
-        vlc_player_SelectTrack(m_player, m_data[row].m_id.get());
+    {
+        vlc_es_id_t *esId = m_data[row].m_id.get();
+        const struct vlc_player_track *trackToSelect =
+            vlc_player_GetTrack(m_player, esId);
+        assert(trackToSelect);
+
+        if (trackToSelect->fmt.i_cat != SPU_ES ||
+            !vlc_player_AreDualSubtitlesEnabled(m_player))
+        {
+            vlc_player_SelectTrack(m_player, esId);
+        }
+        else
+        {
+            /* Allow a maximum of two selected subtitle tracks
+               when dual subtitles are enabled */
+            const int maxIds = 2;
+            enum es_format_category_e cat = trackToSelect->fmt.i_cat;
+            vlc_es_id_t *esIds[maxIds + 1] = { esId };  /* null terminated */
+
+            size_t count = vlc_player_GetTrackCount(m_player, cat);
+            if (!count)
+                return false;
+
+            unsigned int index = 1;
+            for (size_t i = 0; i < count; ++i)
+            {
+                const struct vlc_player_track *track =
+                    vlc_player_GetTrackAt(m_player, cat, i);
+                assert(track);
+
+                if (track->selected)
+                {
+                    if (index == maxIds)
+                    {
+                        updateTrackSelection(trackToSelect->es_id, false);
+                        return false;
+                    }
+                    esIds[index++] = track->es_id;
+                }
+            }
+            vlc_player_SelectTrackList(m_player, cat, esIds);
+        }
+    }
     else
         vlc_player_UnselectTrack(m_player, m_data[row].m_id.get());
     return true;
-- 
2.11.0



More information about the vlc-devel mailing list