[vlc-devel] [PATCH] RFC: attempt to fix the NowPlaying issue #9960 #11796 #12850

Ludovic Fauvet etix at videolan.org
Wed Dec 17 15:38:35 CET 2014


Based on a discussion with Courmisch I splitted the NowPlaying meta in
two. NowPlaying for the input and ESNowPlaying for the elementary
stream. The new function input_item_GetNowPlayingFb is in charge of
returning the preferred meta.
---
 include/vlc_input_item.h     |  2 ++
 include/vlc_meta.h           |  1 +
 lib/media.c                  | 21 +++++++++++++++------
 modules/notify/growl.m       |  4 ++--
 src/input/es_out.c           | 10 +++++-----
 src/input/input.c            |  1 +
 src/input/item.c             | 11 +++++++++++
 src/input/meta.c             |  1 +
 src/input/resource.c         |  2 +-
 src/libvlccore.sym           |  1 +
 src/text/strings.c           | 36 +++++++++++++++++++++++++++---------
 src/video_output/video_epg.c |  2 +-
 12 files changed, 68 insertions(+), 24 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 1bfb2f9..8502dd3 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -192,6 +192,7 @@ VLC_API char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type
 VLC_API char * input_item_GetName( input_item_t * p_i ) VLC_USED;
 VLC_API char * input_item_GetTitleFbName( input_item_t * p_i ) VLC_USED;
 VLC_API char * input_item_GetURI( input_item_t * p_i ) VLC_USED;
+VLC_API char * input_item_GetNowPlayingFb( input_item_t *p_item ) VLC_USED;
 VLC_API void input_item_SetURI( input_item_t * p_i, const char *psz_uri );
 VLC_API mtime_t input_item_GetDuration( input_item_t * p_i );
 VLC_API void input_item_SetDuration( input_item_t * p_i, mtime_t i_duration );
@@ -223,6 +224,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 c87643e..bb82c3b 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 5e406a4..7d4bbb9 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -88,6 +88,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,
@@ -495,13 +496,21 @@ 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/modules/notify/growl.m b/modules/notify/growl.m
index 9501083..4c5c281 100644
--- a/modules/notify/growl.m
+++ b/modules/notify/growl.m
@@ -201,8 +201,8 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     }
 
     /* Playing something ... */
-    if( input_item_GetNowPlaying( p_item ) )
-        psz_title = input_item_GetNowPlaying( p_item );
+    if( input_item_GetNowPlayingFb( p_item ) )
+        psz_title = input_item_GetNowPlayingFb( p_item );
     else
         psz_title = input_item_GetTitleFbName( p_item );
     if( EMPTY_STR( psz_title ) )
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 29fee99..33e226a 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -1012,7 +1012,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 );
@@ -1154,7 +1154,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 )
     {
@@ -1293,20 +1293,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 6d64cdb..aa5a835 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -448,6 +448,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/item.c b/src/input/item.c
index 40b854e..33c7b26 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -386,6 +386,17 @@ void input_item_SetDuration( input_item_t *p_i, mtime_t i_duration )
     }
 }
 
+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;
+}
 
 bool input_item_IsPreparsed( input_item_t *p_item )
 {
diff --git a/src/input/meta.c b/src/input/meta.c
index f8d1ec9..50001ff 100644
--- a/src/input/meta.c
+++ b/src/input/meta.c
@@ -64,6 +64,7 @@ const char * vlc_meta_TypeToLocalizedString( vlc_meta_type_t meta_type )
         [vlc_meta_Setting]     = N_("Setting"),
         [vlc_meta_URL]         = N_("URL"),
         [vlc_meta_Language]    = N_("Language"),
+        [vlc_meta_ESNowPlaying]= N_("Now Playing"),
         [vlc_meta_NowPlaying]  = N_("Now Playing"),
         [vlc_meta_Publisher]   = N_("Publisher"),
         [vlc_meta_EncodedBy]   = N_("Encoded by"),
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/libvlccore.sym b/src/libvlccore.sym
index 10e036a..7f06ed6 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -189,6 +189,7 @@ input_item_GetDuration
 input_item_GetInfo
 input_item_GetMeta
 input_item_GetName
+input_item_GetNowPlayingFb
 input_item_GetTitleFbName
 input_item_GetURI
 input_item_HasErrorWhenReading
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);
-- 
2.1.3




More information about the vlc-devel mailing list