[vlc-devel] Sending synced text to the Qt4 interface

ogg.k.ogg.k at googlemail.com ogg.k.ogg.k at googlemail.com
Mon Nov 3 13:29:07 CET 2008


Hi,

I am currently trying to display song lyrics in the VLC main interface
window (Qt4). This works fine, but I have two points I want to submit
to this list:

- the system I worked out to convey synced text to the rest of VLC uses
  input_item_SetMeta and a new metadata type (synced text), and tells
  VLC about it via an item-change event. Is this an OK way to do it ?

- when the Kate module is selected with no active vout (eg, by using
  --sub-track or --sub-track-id), VLC seems to wait quite a while when
  trying to get a new SPU buffer (a few seconds). To avoid the temporary
  freeze, I had to use vlc_object_find to know if there's a vout (I do
  not do anything with it though, I just need to know if there is one
  around, so I can avoid asking for a SPU buffer is there isn't one).
  Is this a known problem with a known solution, and is there another
  way to know if VLC will freeze when asking for a SPU buffer ?

See below patch for the current code to give you an idea.

Thanks


diff --git a/include/vlc/libvlc_structures.h b/include/vlc/libvlc_structures.h
index 3339afb..49c2d81 100644
--- a/include/vlc/libvlc_structures.h
+++ b/include/vlc/libvlc_structures.h
@@ -103,7 +103,8 @@ typedef enum libvlc_meta_t {
     libvlc_meta_Publisher,
     libvlc_meta_EncodedBy,
     libvlc_meta_ArtworkURL,
-    libvlc_meta_TrackID
+    libvlc_meta_TrackID,
+    libvlc_meta_SyncedText
 } libvlc_meta_t;

 /**@} */
diff --git a/include/vlc_input.h b/include/vlc_input.h
index bb2a263..0285f21 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -158,6 +158,7 @@ VLC_EXPORT( void,   input_item_MetaMerge, (
input_item_t *p_i, const vlc_meta_t
 #define input_item_SetEncodedBy( item, b )   input_item_SetMeta(
item, vlc_meta_EncodedBy, b )
 #define input_item_SetArtURL( item, b )      input_item_SetMeta(
item, vlc_meta_ArtworkURL, b )
 #define input_item_SetTrackID( item, b )     input_item_SetMeta(
item, vlc_meta_TrackID, b )
+#define input_item_SetSyncedText( item, b )  input_item_SetMeta(
item, vlc_meta_SyncedText, b )

 #define input_item_GetTitle( item )          input_item_GetMeta(
item, vlc_meta_Title )
 #define input_item_GetArtist( item )         input_item_GetMeta(
item, vlc_meta_Artist )
@@ -176,6 +177,7 @@ VLC_EXPORT( void,   input_item_MetaMerge, (
input_item_t *p_i, const vlc_meta_t
 #define input_item_GetEncodedBy( item )      input_item_GetMeta(
item, vlc_meta_EncodedBy )
 #define input_item_GetArtURL( item )         input_item_GetMeta(
item, vlc_meta_ArtworkURL )
 #define input_item_GetTrackID( item )        input_item_GetMeta(
item, vlc_meta_TrackID )
+#define input_item_GetSyncedText( item )     input_item_GetMeta(
item, vlc_meta_SyncedText )
 #define input_item_GetSetting( item )        input_item_GetMeta(
item, vlc_meta_Setting )

 VLC_EXPORT( char *, input_item_GetInfo, ( input_item_t *p_i, const
char *psz_cat,const char *psz_name ) );
diff --git a/include/vlc_meta.h b/include/vlc_meta.h
index b5fc8c3..8ea2bc8 100644
--- a/include/vlc_meta.h
+++ b/include/vlc_meta.h
@@ -50,7 +50,8 @@ typedef enum vlc_meta_type_t
     vlc_meta_Publisher,
     vlc_meta_EncodedBy,
     vlc_meta_ArtworkURL,
-    vlc_meta_TrackID
+    vlc_meta_TrackID,
+    vlc_meta_SyncedText
 } vlc_meta_type_t;

 #define VLC_META_TYPE_COUNT 17
@@ -92,6 +93,7 @@ struct vlc_meta_t
 #define vlc_meta_SetEncodedBy( meta, b )   vlc_meta_Set( meta,
vlc_meta_EncodedBy, b )
 #define vlc_meta_SetArtURL( meta, b )      vlc_meta_Set( meta,
vlc_meta_ArtworkURL, b )
 #define vlc_meta_SetTrackID( meta, b )     vlc_meta_Set( meta,
vlc_meta_TrackID, b )
+#define vlc_meta_SetSyncedText( meta, b )  vlc_meta_Set( meta,
vlc_meta_SyncedText, b )

 /* Free a dictonary key allocated by strdup() in vlc_meta_AddExtra() */
 static inline void vlc_meta_FreeExtraKey( void *p_data, void *p_obj )
@@ -191,6 +193,7 @@ static inline void vlc_meta_Merge( vlc_meta_t
*dst, const vlc_meta_t *src )
 #define VLC_META_ENCODED_BY         input_MetaTypeToLocalizedString(
vlc_meta_EncodedBy )
 #define VLC_META_ART_URL            input_MetaTypeToLocalizedString(
vlc_meta_ArtworkURL )
 #define VLC_META_TRACKID            input_MetaTypeToLocalizedString(
vlc_meta_TrackID )
+#define VLC_META_SYNCED_TEXT        input_MetaTypeToLocalizedString(
vlc_meta_SyncedText )

 enum {
     ALBUM_ART_WHEN_ASKED,
diff --git a/modules/codec/kate.c b/modules/codec/kate.c
index e218e39..71c54b1 100644
--- a/modules/codec/kate.c
+++ b/modules/codec/kate.c
@@ -33,6 +33,8 @@
 #include <vlc_input.h>
 #include <vlc_codec.h>
 #include <vlc_osd.h>
+#include <vlc_meta.h>
+#include <vlc_playlist.h>

 #include <kate/kate.h>

@@ -471,6 +473,21 @@ static void GetVideoSize( decoder_t *p_dec, int
*w, int *h )
 #endif
 }

+static bool IsVideoOutPresent( decoder_t *p_dec )
+{
+    vout_thread_t *p_vout;
+    p_vout = vlc_object_find( (vlc_object_t*)p_dec, VLC_OBJECT_VOUT,
FIND_CHILD );
+    if( p_vout )
+    {
+        vlc_object_release( p_vout );
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
 #ifdef ENABLE_BITMAPS

 static void CreateKateBitmap( picture_t *pic, const kate_bitmap *bitmap )
@@ -583,6 +600,30 @@ static subpicture_t *DecodePacket( decoder_t
*p_dec, kate_packet *p_kp, block_t

     /* we have an event */

+    if (ev->text && ev->len > 0 && ev->text_encoding == kate_utf8)
+    {
+        /* if we have UTF-8 text with this event, send it as meta */
+        input_thread_t *p_input = (input_thread_t *)p_dec->p_parent;
+        if( p_input && p_input->i_object_type == VLC_OBJECT_INPUT )
+        {
+            input_item_t *p_item = input_GetItem( p_input );
+            if (p_item)
+            {
+                input_item_SetMeta( p_item, vlc_meta_SyncedText, ev->text );
+                var_SetInteger( pl_Hold( p_input ), "item-change",
p_item->i_id );
+                pl_Release( p_input );
+            }
+        }
+    }
+
+    /* Do not go any further if we don't have video out, or VLC seems to spend
+       quite a bit of time trying to create the SPU buffer we request below,
+       quite possibly trying to load modules */
+    if (!IsVideoOutPresent( p_dec ))
+    {
+        return NULL;
+    }
+
     /* Get a new spu */
     p_spu = p_dec->pf_spu_buffer_new( p_dec );
     if( !p_spu )
diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c
index c09377e..b078d7a 100644
--- a/modules/gui/ncurses.c
+++ b/modules/gui/ncurses.c
@@ -1851,6 +1851,8 @@ static void Redraw( intf_thread_t *p_intf,
time_t *t_last_refresh )
                             psz_meta_title = VLC_META_ART_URL; break;
                         case 16:
                             psz_meta_title = VLC_META_TRACKID; break;
+                        case 17:
+                            psz_meta_title = VLC_META_SYNCED_TEXT; break;
                         default:
                             psz_meta_title = ""; break;
                     }
diff --git a/modules/gui/qt4/input_manager.cpp
b/modules/gui/qt4/input_manager.cpp
index 9f65f79..4170251 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -67,6 +67,7 @@ InputManager::InputManager( QObject *parent,
intf_thread_t *_p_intf) :
 {
     i_old_playing_status = END_S;
     oldName      = "";
+    oldSyncedText = "";
     artUrl       = "";
     p_input      = NULL;
     i_rate       = 0;
@@ -120,6 +121,7 @@ void InputManager::delInput()
         i_old_playing_status = END_S;
         i_input_id = 0;
         oldName    = "";
+        oldSyncedText = "";
         artUrl     = "";
         b_video    = false;
         timeA      = 0;
@@ -127,6 +129,7 @@ void InputManager::delInput()
         emit positionUpdated( -1.0, 0 ,0 );
         emit statusChanged( END_S );
         emit nameChanged( "" );
+        emit syncedTextChanged( "" );
         emit artChanged( NULL );
         emit rateChanged( INPUT_RATE_DEFAULT );
         emit voutChanged( false );
@@ -371,6 +374,15 @@ void InputManager::UpdateMeta()
         emit nameChanged( text );
         oldName=text;
     }
+
+    /* synced text - if the right config var is set, will display in
text box */
+    char *psz_text = input_item_GetMeta( input_GetItem( p_input ),
vlc_meta_SyncedText );
+    text = psz_text ? psz_text : "";
+    if( oldSyncedText != text )
+    {
+        emit syncedTextChanged( text );
+        oldSyncedText=text;
+    }
 }

 bool InputManager::hasAudio()
diff --git a/modules/gui/qt4/input_manager.hpp
b/modules/gui/qt4/input_manager.hpp
index 8e728cb..d47c387 100644
--- a/modules/gui/qt4/input_manager.hpp
+++ b/modules/gui/qt4/input_manager.hpp
@@ -82,6 +82,7 @@ public:
     bool hasVideo() { return hasInput() && b_video; }

     QString getName() { return oldName; }
+    QString getSyncedText() { return oldSyncedText; }

 private:
     intf_thread_t  *p_intf;
@@ -89,6 +90,7 @@ private:
     int             i_input_id;
     int             i_old_playing_status;
     QString         oldName;
+    QString         oldSyncedText;
     QString         artUrl;
     int             i_rate;
     bool            b_video;
@@ -140,6 +142,7 @@ signals:
     void positionUpdated( float , int, int );
     void rateChanged( int );
     void nameChanged( QString );
+    void syncedTextChanged( QString );
     /// Used to signal whether we should show navigation buttons
     void titleChanged( bool );
     void chapterChanged( bool );
diff --git a/modules/gui/qt4/main_interface.cpp
b/modules/gui/qt4/main_interface.cpp
index 1ce149e..89f7dac 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -178,6 +178,15 @@ MainInterface::MainInterface( intf_thread_t
*_p_intf ) : QVLCMW( _p_intf )
     }

     /**
+     * Connects on syncedTextChanged()
+     */
+    if( config_GetInt( p_intf, "qt-synced-text-in-name" ) )
+    {
+        CONNECT( THEMIM->getIM(), syncedTextChanged( QString ), this,
+                 setName( QString ) );
+    }
+
+    /**
      * CONNECTS on PLAY_STATUS
      **/
     /* Status on the main controller */
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 4308ab4..371797a 100755
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -88,6 +88,10 @@ static void ShowDialog   ( intf_thread_t *, int,
int, intf_dialog_args_t * );
 #define TITLE_LONGTEXT N_( "Show the name of the song or video in the " \
                            "controler window title." )

+#define SYNCED_TEXT_TEXT N_( "Show synced text (eg, lyrics)" )
+#define SYNCED_TEXT_LONGTEXT N_( "Show timed text (eg, song lyrics)
in sync with" \
+                           "the audio/video in the the text bar." )
+
 #define FILEDIALOG_PATH_TEXT N_( "Path to use in openfile dialog" )

 #define NOTIFICATION_TEXT N_( "Show notification popup on track change" )
@@ -181,6 +185,8 @@ vlc_module_begin();
               MINIMIZED_LONGTEXT, true);
     add_bool( "qt-name-in-title", true, NULL, TITLE_TEXT,
               TITLE_LONGTEXT, false );
+    add_bool( "qt-synced-text-in-name", true, NULL, SYNCED_TEXT_TEXT,
+              SYNCED_TEXT_LONGTEXT, true );
     add_bool( "qt-fs-controller", true, NULL, QT_FULLSCREEN_TEXT,
               QT_FULLSCREEN_TEXT, false );

diff --git a/src/control/media.c b/src/control/media.c
index 0192227..4134845 100644
--- a/src/control/media.c
+++ b/src/control/media.c
@@ -48,7 +48,8 @@ static const vlc_meta_type_t libvlc_to_vlc_meta[] =
     [libvlc_meta_Publisher]    = vlc_meta_Publisher,
     [libvlc_meta_EncodedBy]    = vlc_meta_EncodedBy,
     [libvlc_meta_ArtworkURL]   = vlc_meta_ArtworkURL,
-    [libvlc_meta_TrackID]      = vlc_meta_TrackID
+    [libvlc_meta_TrackID]      = vlc_meta_TrackID,
+    [libvlc_meta_SyncedText]   = vlc_meta_SyncedText
 };

 static const libvlc_meta_t vlc_to_libvlc_meta[] =
@@ -69,7 +70,8 @@ static const libvlc_meta_t vlc_to_libvlc_meta[] =
     [vlc_meta_Publisher]    = libvlc_meta_Publisher,
     [vlc_meta_EncodedBy]    = libvlc_meta_EncodedBy,
     [vlc_meta_ArtworkURL]   = libvlc_meta_ArtworkURL,
-    [vlc_meta_TrackID]      = libvlc_meta_TrackID
+    [vlc_meta_TrackID]      = libvlc_meta_TrackID,
+    [vlc_meta_SyncedText]   = libvlc_meta_SyncedText
 };

 /**************************************************************************
diff --git a/src/input/meta.c b/src/input/meta.c
index b8ab5ac..fbbe026 100644
--- a/src/input/meta.c
+++ b/src/input/meta.c
@@ -66,6 +66,7 @@ input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type )
     case vlc_meta_EncodedBy:    return _("Encoded by");
     case vlc_meta_ArtworkURL:   return _("Artwork URL");
     case vlc_meta_TrackID:      return _("Track ID");
+    case vlc_meta_SyncedText:   return _("Synced text");

     default: abort();
     }



More information about the vlc-devel mailing list