[vlc-commits] Fix broken NowPlaying (close #9960, #11796, #12850)

Ludovic Fauvet git at videolan.org
Thu Dec 18 15:58:11 CET 2014


vlc/vlc-2.2 | branch: master | Ludovic Fauvet <etix at videolan.org> | Wed Dec 17 18:27:42 2014 +0100| [6583dd3af930a1f6a5edaf6b4ac122ba6247c3a5] | committer: Ludovic Fauvet

Fix broken NowPlaying (close #9960, #11796, #12850)

Prevent the es_out from overriding the NowPlaying state by splitting
the meta into NowPlaying and ESNowPlaying.

The internal function input_item_GetNowPlayingFb can be used to return
the preferred meta value.

Stripped-down version of d4ccd7a5b404f62435c60ecc65f772dab83f5937
available on master.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=6583dd3af930a1f6a5edaf6b4ac122ba6247c3a5
---

 include/vlc_input_item.h     |   12 ++++++++++++
 include/vlc_meta.h           |    1 +
 lib/media.c                  |   23 +++++++++++++++++------
 src/input/es_out.c           |    9 +++++----
 src/input/input.c            |    1 +
 src/input/meta.c             |    1 +
 src/input/resource.c         |    2 +-
 src/text/strings.c           |   36 +++++++++++++++++++++++++++---------
 src/video_output/video_epg.c |    2 +-
 9 files changed, 66 insertions(+), 21 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index bc5b2e5..f4eb4bb 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -200,6 +200,17 @@ VLC_API void input_item_SetDuration( input_item_t * p_i, mtime_t i_duration );
 VLC_API bool input_item_IsPreparsed( input_item_t *p_i );
 VLC_API bool input_item_IsArtFetched( input_item_t *p_i );
 
+static inline char *input_item_GetNowPlayingFb( input_item_t *p_item )
+{
+    char *psz_meta = input_item_GetMeta( p_item, vlc_meta_NowPlaying );
+    if( !psz_meta || strlen( psz_meta ) == 0 )
+    {
+        free( psz_meta );
+        return input_item_GetMeta( p_item, vlc_meta_ESNowPlaying );
+    }
+    return psz_meta;
+}
+
 #define INPUT_META( name ) \
 static inline \
 void input_item_Set ## name (input_item_t *p_input, const char *val) \
@@ -225,6 +236,7 @@ INPUT_META(Setting)
 INPUT_META(URL)
 INPUT_META(Language)
 INPUT_META(NowPlaying)
+INPUT_META(ESNowPlaying)
 INPUT_META(Publisher)
 INPUT_META(EncodedBy)
 INPUT_META(ArtworkURL)
diff --git a/include/vlc_meta.h b/include/vlc_meta.h
index c3bf801..15ef2af 100644
--- a/include/vlc_meta.h
+++ b/include/vlc_meta.h
@@ -45,6 +45,7 @@ typedef enum vlc_meta_type_t
     vlc_meta_URL,
     vlc_meta_Language,
     vlc_meta_NowPlaying,
+    vlc_meta_ESNowPlaying,
     vlc_meta_Publisher,
     vlc_meta_EncodedBy,
     vlc_meta_ArtworkURL,
diff --git a/lib/media.c b/lib/media.c
index 1f6fb9e..c2a4ef5 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -86,6 +86,7 @@ static const libvlc_meta_t vlc_to_libvlc_meta[] =
     [vlc_meta_URL]          = libvlc_meta_URL,
     [vlc_meta_Language]     = libvlc_meta_Language,
     [vlc_meta_NowPlaying]   = libvlc_meta_NowPlaying,
+    [vlc_meta_ESNowPlaying] = libvlc_meta_NowPlaying,
     [vlc_meta_Publisher]    = libvlc_meta_Publisher,
     [vlc_meta_EncodedBy]    = libvlc_meta_EncodedBy,
     [vlc_meta_ArtworkURL]   = libvlc_meta_ArtworkURL,
@@ -491,12 +492,22 @@ libvlc_media_get_mrl( libvlc_media_t * p_md )
 
 char *libvlc_media_get_meta( libvlc_media_t *p_md, libvlc_meta_t e_meta )
 {
-    char *psz_meta = input_item_GetMeta( p_md->p_input_item,
-                                         libvlc_to_vlc_meta[e_meta] );
-    /* Should be integrated in core */
-    if( psz_meta == NULL && e_meta == libvlc_meta_Title
-     && p_md->p_input_item->psz_name != NULL )
-        psz_meta = strdup( p_md->p_input_item->psz_name );
+    char *psz_meta = NULL;
+
+    if( e_meta == libvlc_meta_NowPlaying )
+    {
+        psz_meta = input_item_GetNowPlayingFb( p_md->p_input_item );
+    }
+    else
+    {
+        psz_meta = input_item_GetMeta( p_md->p_input_item,
+                                             libvlc_to_vlc_meta[e_meta] );
+
+        /* Should be integrated in core */
+        if( psz_meta == NULL && e_meta == libvlc_meta_Title
+            && p_md->p_input_item->psz_name != NULL )
+            psz_meta = strdup( p_md->p_input_item->psz_name );
+    }
 
     return psz_meta;
 }
diff --git a/src/input/es_out.c b/src/input/es_out.c
index ab09254..ddf01e1 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -1014,7 +1014,7 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
     }
 
     /* Update now playing */
-    input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
+    input_item_SetESNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
     input_item_SetPublisher( p_input->p->p_item, p_pgrm->psz_publisher );
 
     input_SendEventMeta( p_input );
@@ -1157,6 +1157,7 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, const vlc_meta_t *p_me
     /* Check against empty meta data (empty for what we handle) */
     if( !vlc_meta_Get( p_meta, vlc_meta_Title) &&
         !vlc_meta_Get( p_meta, vlc_meta_NowPlaying) &&
+        !vlc_meta_Get( p_meta, vlc_meta_ESNowPlaying) &&
         !vlc_meta_Get( p_meta, vlc_meta_Publisher) &&
         vlc_meta_GetExtraCount( p_meta ) <= 0 )
     {
@@ -1295,20 +1296,20 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg
 
     if( p_pgrm == p_sys->p_pgrm )
     {
-        input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
+        input_item_SetESNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
         input_SendEventMeta( p_input );
     }
 
     if( p_pgrm->psz_now_playing )
     {
         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-            vlc_meta_TypeToLocalizedString(vlc_meta_NowPlaying), "%s",
+            vlc_meta_TypeToLocalizedString(vlc_meta_ESNowPlaying), "%s",
             p_pgrm->psz_now_playing );
     }
     else
     {
         input_Control( p_input, INPUT_DEL_INFO, psz_cat,
-            vlc_meta_TypeToLocalizedString(vlc_meta_NowPlaying) );
+            vlc_meta_TypeToLocalizedString(vlc_meta_ESNowPlaying) );
     }
 
     free( psz_cat );
diff --git a/src/input/input.c b/src/input/input.c
index 41c1a99..05e4ff3 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -449,6 +449,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
 
     /* Remove 'Now playing' info as it is probably outdated */
     input_item_SetNowPlaying( p_item, NULL );
+    input_item_SetESNowPlaying( p_item, NULL );
     input_SendEventMeta( p_input );
 
     /* */
diff --git a/src/input/meta.c b/src/input/meta.c
index 892b4af..2fb14d8 100644
--- a/src/input/meta.c
+++ b/src/input/meta.c
@@ -65,6 +65,7 @@ const char * vlc_meta_TypeToLocalizedString( vlc_meta_type_t meta_type )
         [vlc_meta_URL]         = N_("URL"),
         [vlc_meta_Language]    = N_("Language"),
         [vlc_meta_NowPlaying]  = N_("Now Playing"),
+        [vlc_meta_ESNowPlaying]= N_("Now Playing"),
         [vlc_meta_Publisher]   = N_("Publisher"),
         [vlc_meta_EncodedBy]   = N_("Encoded by"),
         [vlc_meta_ArtworkURL]  = N_("Artwork URL"),
diff --git a/src/input/resource.c b/src/input/resource.c
index 779c921..3440288 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -158,7 +158,7 @@ static void DisplayVoutTitle( input_resource_t *p_resource,
 
     input_item_t *p_item = input_GetItem( p_resource->p_input );
 
-    char *psz_nowplaying = input_item_GetNowPlaying( p_item );
+    char *psz_nowplaying = input_item_GetNowPlayingFb( p_item );
     if( psz_nowplaying && *psz_nowplaying )
     {
         vout_DisplayTitle( p_vout, psz_nowplaying );
diff --git a/src/text/strings.c b/src/text/strings.c
index a57014b..fefc984 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -603,7 +603,16 @@ char *str_format_meta(input_thread_t *input, const char *s)
                 write_meta(stream, item, vlc_meta_TrackNumber);
                 break;
             case 'p':
-                write_meta(stream, item, vlc_meta_NowPlaying);
+                if (item == NULL)
+                    break;
+                {
+                    char *value = input_item_GetNowPlayingFb(item);
+                    if (value == NULL)
+                        break;
+
+                    fputs(value, stream);
+                    free(value);
+                }
                 break;
             case 'r':
                 write_meta(stream, item, vlc_meta_Rating);
@@ -763,18 +772,27 @@ char *str_format_meta(input_thread_t *input, const char *s)
             case 'Z':
                 if (item == NULL)
                     break;
-                if (write_meta(stream, item, vlc_meta_NowPlaying) == EOF)
                 {
-                    char *title = input_item_GetTitleFbName(item);
+                    char *value = input_item_GetNowPlayingFb(item);
+                    if (value == NULL)
+                        break;
 
-                    if (write_meta(stream, item, vlc_meta_Artist) >= 0
-                     && title != NULL)
-                        fputs(" - ", stream);
+                    int ret = fputs(value, stream);
+                    free(value);
 
-                    if (title != NULL)
+                    if (ret == EOF)
                     {
-                        fputs(title, stream);
-                        free(title);
+                        char *title = input_item_GetTitleFbName(item);
+
+                        if (write_meta(stream, item, vlc_meta_Artist) >= 0
+                            && title != NULL)
+                            fputs(" - ", stream);
+
+                        if (title != NULL)
+                        {
+                            fputs(title, stream);
+                            free(title);
+                        }
                     }
                 }
                 break;
diff --git a/src/video_output/video_epg.c b/src/video_output/video_epg.c
index 471d52c..a0b5c6f 100644
--- a/src/video_output/video_epg.c
+++ b/src/video_output/video_epg.c
@@ -263,7 +263,7 @@ static void OSDEpgDestroy(subpicture_t *subpic)
  */
 int vout_OSDEpg(vout_thread_t *vout, input_item_t *input)
 {
-    char *now_playing = input_item_GetNowPlaying(input);
+    char *now_playing = input_item_GetNowPlayingFb(input);
     vlc_epg_t *epg = NULL;
 
     vlc_mutex_lock(&input->lock);



More information about the vlc-commits mailing list