[vlc-devel] [PATCH 2/2] player: fix teletext handling

Francois Cartegnie fcvlcdev at free.fr
Fri Feb 7 15:08:35 CET 2020


---
 src/player/input.c  | 61 ++++++++++++++++++++++++++++-----------------
 src/player/player.h |  2 +-
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/src/player/input.c b/src/player/input.c
index 37a235664b..45ecb1c405 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -355,44 +355,61 @@ vlc_player_input_HandleProgramEvent(struct vlc_player_input *input,
 
 static void
 vlc_player_input_HandleTeletextMenu(struct vlc_player_input *input,
-                                    const struct vlc_input_event_es *ev)
+                                    const struct vlc_input_event_es *ev,
+                                    const struct vlc_player_track_priv *trackpriv)
 {
     vlc_player_t *player = input->player;
+    const struct vlc_player_track_priv *t;
+    if(ev->fmt->i_codec != VLC_CODEC_TELETEXT)
+        return;
     switch (ev->action)
     {
         case VLC_INPUT_ES_ADDED:
-            if (input->teletext_menu)
+            if(!input->teletext_menu || trackpriv->t.selected)
+                input->teletext_menu = trackpriv;
+            vlc_vector_foreach(t, &input->spu_track_vector)
             {
-                msg_Warn(player, "Can't handle more than one teletext menu "
-                         "track. Using the last one.");
-                vlc_player_track_priv_Delete(input->teletext_menu);
+                /* Did we have index teletext page before in spu list */
+                if(t->t.fmt.i_codec == VLC_CODEC_TELETEXT &&
+                   t->t.fmt.subs.teletext.i_type != 0x02 &&
+                   t->t.fmt.subs.teletext.i_type != 0x05 &&
+                   t != trackpriv)
+                    return;
             }
-            input->teletext_menu = vlc_player_track_priv_New(ev->id, ev->title,
-                                                             ev->fmt);
-            if (!input->teletext_menu)
-                return;
-
             vlc_player_SendEvent(player, on_teletext_menu_changed, true);
             break;
         case VLC_INPUT_ES_DELETED:
         {
-            if (input->teletext_menu && input->teletext_menu->t.es_id == ev->id)
+            if (input->teletext_menu == trackpriv)
             {
                 assert(!input->teletext_enabled);
-
-                vlc_player_track_priv_Delete(input->teletext_menu);
                 input->teletext_menu = NULL;
-                vlc_player_SendEvent(player, on_teletext_menu_changed, false);
             }
+            vlc_vector_foreach(t, &input->spu_track_vector)
+            {
+                /* Do we still have index teletext page in spu list */
+                if(t->t.fmt.i_codec == VLC_CODEC_TELETEXT &&
+                   t->t.fmt.subs.teletext.i_type != 0x02 &&
+                   t->t.fmt.subs.teletext.i_type != 0x05 &&
+                   t != trackpriv)
+                {
+                    input->teletext_menu = t;
+                    return;
+                }
+            }
+            vlc_player_SendEvent(player, on_teletext_menu_changed, false);
             break;
         }
         case VLC_INPUT_ES_UPDATED:
             break;
         case VLC_INPUT_ES_SELECTED:
         case VLC_INPUT_ES_UNSELECTED:
-            if (input->teletext_menu->t.es_id == ev->id)
+            if(trackpriv->t.fmt.subs.teletext.i_type != 0x02 &&
+               trackpriv->t.fmt.subs.teletext.i_type != 0x05)
             {
                 input->teletext_enabled = ev->action == VLC_INPUT_ES_SELECTED;
+                if(input->teletext_enabled)
+                    input->teletext_menu = trackpriv;
                 vlc_player_SendEvent(player, on_teletext_enabled_changed,
                                      input->teletext_enabled);
             }
@@ -408,14 +425,6 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
 {
     assert(ev->id && ev->title && ev->fmt);
 
-    if (ev->fmt->i_cat == SPU_ES && ev->fmt->i_codec == VLC_CODEC_TELETEXT
-     && (ev->fmt->subs.teletext.i_magazine == 1
-      || ev->fmt->subs.teletext.i_magazine > 8))
-    {
-        vlc_player_input_HandleTeletextMenu(input, ev);
-        return;
-    }
-
     vlc_player_track_vector *vec =
         vlc_player_input_GetTrackVector(input, ev->fmt->i_cat);
     if (!vec)
@@ -463,6 +472,7 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
                         input->ml.states.current_subtitle_track == ev->fmt->i_id)
                         vlc_player_SelectTrack(input->player, &trackpriv->t,
                                                VLC_PLAYER_SELECT_EXCLUSIVE);
+                    vlc_player_input_HandleTeletextMenu(input, ev, trackpriv);
                 default:
                     break;
             }
@@ -473,6 +483,8 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
             trackpriv = vlc_player_track_vector_FindById(vec, ev->id, &idx);
             if (trackpriv)
             {
+                if(trackpriv->t.fmt.i_cat == SPU_ES)
+                    vlc_player_input_HandleTeletextMenu(input, ev, trackpriv);
                 vlc_player_SendEvent(player, on_track_list_changed,
                                      VLC_PLAYER_LIST_REMOVED, &trackpriv->t);
                 vlc_vector_remove(vec, idx);
@@ -513,6 +525,7 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
                 case SPU_ES:
                     if (input->ml.default_subtitle_track == -2)
                         input->ml.default_subtitle_track = ev->fmt->i_id;
+                    vlc_player_input_HandleTeletextMenu(input, ev, trackpriv);
                     break;
                 default:
                     break;
@@ -526,6 +539,8 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
                 trackpriv->t.selected = false;
                 vlc_player_SendEvent(player, on_track_selection_changed,
                                      trackpriv->t.es_id, NULL);
+                if(trackpriv->t.fmt.i_cat == SPU_ES)
+                    vlc_player_input_HandleTeletextMenu(input, ev, trackpriv);
             }
             break;
         default:
diff --git a/src/player/player.h b/src/player/player.h
index d7e499a84e..e45cc1d510 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -83,7 +83,7 @@ struct vlc_player_input
     vlc_player_track_vector video_track_vector;
     vlc_player_track_vector audio_track_vector;
     vlc_player_track_vector spu_track_vector;
-    struct vlc_player_track_priv *teletext_menu;
+    const struct vlc_player_track_priv *teletext_menu;
 
     struct vlc_player_title_list *titles;
 
-- 
2.24.1



More information about the vlc-devel mailing list