[vlc-devel] [PATCH] player: Add a policy to vlc_player_SelectEsId

Thomas Guillem thomas at gllm.fr
Mon Jun 24 14:08:59 CEST 2019


This will replace the future vlc_player_AddEsId() function (simultaneous).
---
 include/vlc_player.h                          | 30 +++++++++++++++----
 lib/audio.c                                   |  2 +-
 lib/video.c                                   |  4 +--
 modules/control/rc.c                          |  2 +-
 .../gui/macosx/playlist/VLCPlayerController.m |  2 +-
 modules/gui/qt/util/input_models.cpp          |  3 +-
 modules/lua/libs/input.c                      |  2 +-
 src/input/player.c                            |  9 ++++--
 test/src/input/player.c                       |  2 +-
 9 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index 2fe226ab70..0390201d1c 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -297,6 +297,21 @@ enum vlc_player_whence
     VLC_PLAYER_WHENCE_RELATIVE,
 };
 
+/**
+ * Player selection policy
+ *
+ * @see vlc_player_SelectEsId()
+ */
+enum vlc_player_select_policy
+{
+    /**
+     * Only one track per category is selected. Selecting a track with this
+     * policy will disable all other tracks for the same category.
+     */
+    VLC_PLAYER_SELECT_EXCLUSIVE,
+    /* XXX VLC_PLAYER_SELECT_SIMULTANEOUS, */
+};
+
 /**
  * Action when the player is stopped
  *
@@ -1724,9 +1739,11 @@ vlc_player_GetSelectedTrack(vlc_player_t *player, enum es_format_category_e cat)
  * @param player locked player instance
  * @param id an ES ID (retrieved from vlc_player_cbs.on_track_list_changed or
  * vlc_player_GetTrackAt())
+ * @param policy exclusive or simultaneous
  */
 VLC_API void
-vlc_player_SelectEsId(vlc_player_t *player, vlc_es_id_t *es_id);
+vlc_player_SelectEsId(vlc_player_t *player, vlc_es_id_t *es_id,
+                      enum vlc_player_select_policy policy);
 
 
 /**
@@ -1734,9 +1751,10 @@ vlc_player_SelectEsId(vlc_player_t *player, vlc_es_id_t *es_id);
  */
 static inline void
 vlc_player_SelectTrack(vlc_player_t *player,
-                       const struct vlc_player_track *track)
+                       const struct vlc_player_track *track,
+                       enum vlc_player_select_policy policy)
 {
-    vlc_player_SelectEsId(player, track->es_id);
+    vlc_player_SelectEsId(player, track->es_id, policy);
 }
 
 /**
@@ -1746,7 +1764,8 @@ vlc_player_SelectTrack(vlc_player_t *player,
  * this last track. And a second call will select the first track.
  *
  * @warning This function has no effects if there are several tracks selected
- * for a same category.
+ * for a same category. Therefore the default policy is
+ * VLC_PLAYER_SELECT_EXCLUSIVE.
  *
  * @param player locked player instance
  * @param cat VIDEO_ES, AUDIO_ES or SPU_ES
@@ -1762,7 +1781,8 @@ vlc_player_SelectNextTrack(vlc_player_t *player,
  * this first track. And a second call will select the last track.
  *
  * @warning This function has no effects if there are several tracks selected
- * for a same category.
+ * for a same category. Therefore the default policy is
+ * VLC_PLAYER_SELECT_EXCLUSIVE.
  *
  * @param player locked player instance
  * @param cat VIDEO_ES, AUDIO_ES or SPU_ES
diff --git a/lib/audio.c b/lib/audio.c
index 52fa9d5c47..aab84cd47a 100644
--- a/lib/audio.c
+++ b/lib/audio.c
@@ -383,7 +383,7 @@ int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track )
         if (i_track == vlc_es_id_GetInputId(track->es_id))
         {
             /* found */
-            vlc_player_SelectTrack(player, track);
+            vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
             i_ret = 0;
             goto end;
         }
diff --git a/lib/video.c b/lib/video.c
index 2b6511d26c..1446cbeab5 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -325,7 +325,7 @@ int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
         if (i_spu == vlc_es_id_GetInputId(track->es_id))
         {
             /* found */
-            vlc_player_SelectTrack(player, track);
+            vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
             i_ret = 0;
             goto end;
         }
@@ -496,7 +496,7 @@ int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
         if (i_track == vlc_es_id_GetInputId(track->es_id))
         {
             /* found */
-            vlc_player_SelectTrack(player, track);
+            vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
             i_ret = 0;
             goto end;
         }
diff --git a/modules/control/rc.c b/modules/control/rc.c
index 67b1193596..d150de891d 100644
--- a/modules/control/rc.c
+++ b/modules/control/rc.c
@@ -549,7 +549,7 @@ static void Input(intf_thread_t *intf, char const *psz_cmd,
                 vlc_player_GetTrackAt(player, cat, (size_t)idx);
             if (!track)
                 goto out;
-            vlc_player_SelectTrack(player, track);
+            vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
         }
         else
         {
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index f53cdc9027..a1fae94533 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -1373,7 +1373,7 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
 - (void)selectTrack:(VLCTrackMetaData *)track
 {
     vlc_player_Lock(_p_player);
-    vlc_player_SelectEsId(_p_player, track.esID);
+    vlc_player_SelectEsId(_p_player, track.esID, VLC_PLAYER_SELECT_EXCLUSIVE);
     vlc_player_Unlock(_p_player);
 }
 
diff --git a/modules/gui/qt/util/input_models.cpp b/modules/gui/qt/util/input_models.cpp
index b740bfafb6..0a0e450852 100644
--- a/modules/gui/qt/util/input_models.cpp
+++ b/modules/gui/qt/util/input_models.cpp
@@ -62,7 +62,8 @@ bool TrackListModel::setData(const QModelIndex &index, const QVariant &value, in
     vlc_player_locker lock{ m_player };
 
     if (select)
-        vlc_player_SelectEsId(m_player, m_data[row].m_id.get());
+        vlc_player_SelectEsId(m_player, m_data[row].m_id.get(),
+                              VLC_PLAYER_SELECT_EXCLUSIVE);
     else
         vlc_player_UnselectEsId(m_player, m_data[row].m_id.get());
     return true;
diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index 79e1f24eed..6a4b14cf2e 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -372,7 +372,7 @@ static int vlclua_player_toggle_track_(lua_State *L,
         if (track->selected)
             vlc_player_UnselectTrack(player, track);
         else
-            vlc_player_SelectTrack(player, track);
+            vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
     }
 
     vlc_player_Unlock(player);
diff --git a/src/input/player.c b/src/input/player.c
index a038ae67d6..80c334ed9b 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -1380,8 +1380,10 @@ vlc_player_vout_OSDTrack(vlc_player_t *player, vlc_es_id_t *id, bool select)
 }
 
 void
-vlc_player_SelectEsId(vlc_player_t *player, vlc_es_id_t *id)
+vlc_player_SelectEsId(vlc_player_t *player, vlc_es_id_t *id,
+                      enum vlc_player_select_policy policy)
 {
+    assert(policy == VLC_PLAYER_SELECT_EXCLUSIVE); /* TODO */
     struct vlc_player_input *input = vlc_player_get_input_locked(player);
     if (!input)
         return;
@@ -1436,7 +1438,7 @@ vlc_player_CycleTrack(vlc_player_t *player, enum es_format_category_e cat,
     const struct vlc_player_track *track =
         vlc_player_GetTrackAt(player, cat, index);
     if (selected)
-        vlc_player_SelectTrack(player, track);
+        vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
     else
         vlc_player_UnselectTrack(player, track);
 }
@@ -1566,7 +1568,8 @@ vlc_player_SetTeletextEnabled(vlc_player_t *player, bool enabled)
     if (!input || !input->teletext_menu)
         return;
     if (enabled)
-        vlc_player_SelectEsId(player, input->teletext_menu->t.es_id);
+        vlc_player_SelectEsId(player, input->teletext_menu->t.es_id,
+                              VLC_PLAYER_SELECT_EXCLUSIVE);
     else
         vlc_player_UnselectEsId(player, input->teletext_menu->t.es_id);
 }
diff --git a/test/src/input/player.c b/test/src/input/player.c
index c7174cafc8..012f1990aa 100644
--- a/test/src/input/player.c
+++ b/test/src/input/player.c
@@ -1144,7 +1144,7 @@ player_select_next_unselected_track(struct ctx *ctx,
     old_id = old_track ? vlc_es_id_Hold(old_track->es_id) : NULL;
 
     if (new_id)
-        vlc_player_SelectEsId(player, new_id);
+        vlc_player_SelectEsId(player, new_id, VLC_PLAYER_SELECT_EXCLUSIVE);
     else
     {
         assert(old_id);
-- 
2.20.1



More information about the vlc-devel mailing list