[vlc-devel] [PATCH 08/10] chromecast: pass the title/artwork to the Chromecast when starting playback

Steve Lhomme robux4 at videolabs.io
Tue May 31 13:15:35 CEST 2016


---
 modules/stream_out/chromecast/chromecast.h         | 23 +++++++++
 modules/stream_out/chromecast/chromecast_common.h  |  4 ++
 modules/stream_out/chromecast/chromecast_ctrl.cpp  | 54 +++++++++++++++++++---
 modules/stream_out/chromecast/chromecast_demux.cpp | 15 ++++++
 4 files changed, 89 insertions(+), 7 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 18691f5..c99d527 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -161,6 +161,22 @@ private:
 
     void setInputState(input_state_e state);
 
+    void setTitle( const char *psz_title )
+    {
+        if ( psz_title )
+            title = psz_title;
+        else
+            title = "";
+    }
+
+    void setArtwork( const char *psz_artwork )
+    {
+        if ( psz_artwork )
+            artwork = psz_artwork;
+        else
+            artwork = "";
+    }
+
     int sendMessage(const castchannel::CastMessage &msg);
 
     void buildMessage(const std::string & namespace_,
@@ -187,6 +203,10 @@ private:
     bool           has_input;
     input_state_e  input_state;
 
+    std::string GetMedia();
+    std::string artwork;
+    std::string title;
+
     static void* ChromecastThread(void* p_data);
     vlc_interrupt_t *p_ctl_thread_interrupt;
 
@@ -247,6 +267,9 @@ private:
     static void wait_seek_done(void*);
 
     static void set_input_state(void*, input_state_e state);
+
+    static void set_title(void*, const char *psz_title);
+    static void set_artwork(void*, const char *psz_artwork);
 };
 
 #endif /* VLC_CHROMECAST_H */
diff --git a/modules/stream_out/chromecast/chromecast_common.h b/modules/stream_out/chromecast/chromecast_common.h
index 45d3ebc..8e1df84 100644
--- a/modules/stream_out/chromecast/chromecast_common.h
+++ b/modules/stream_out/chromecast/chromecast_common.h
@@ -47,6 +47,10 @@ typedef struct
     void (*pf_wait_seek_done)(void*);
 
     void (*pf_set_input_state)(void*, input_state_e state);
+
+    void (*pf_set_title)(void*, const char *psz_title);
+    void (*pf_set_artwork)(void*, const char *psz_artwork);
+
 } chromecast_common;
 
 # ifdef __cplusplus
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 62bd6c2..58dd4ad 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -129,6 +129,8 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
     common.pf_request_seek     = request_seek;
     common.pf_wait_seek_done   = wait_seek_done;
     common.pf_set_input_state  = set_input_state;
+    common.pf_set_artwork      = set_artwork;
+    common.pf_set_title        = set_title;
 
     assert( var_Type( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME) == 0 );
     if (var_Create( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME, VLC_VAR_ADDRESS ) == VLC_SUCCESS )
@@ -772,16 +774,42 @@ void intf_sys_t::msgPlayerGetStatus()
     pushMediaPlayerMessage( ss );
 }
 
+std::string intf_sys_t::GetMedia()
+{
+    std::stringstream ss;
+
+    if ( title.size() )
+    {
+        ss << "\"metadata\":{"
+           << " \"metadataType\":0"
+           << ",\"title\":\"" << title << "\"";
+
+        if ( artwork.size() && !strncmp(artwork.c_str(), "http", 4))
+            ss << ",\"images\":[\"" << artwork << "\"]";
+
+        ss << "},";
+    }
+
+    std::stringstream chromecast_url;
+    chromecast_url << "http://" << serverIP << ":" << i_port << "/stream";
+
+    msg_Dbg( p_module, "s_chromecast_url: %s", chromecast_url.str().c_str());
+
+    ss << "\"contentId\":\"" << chromecast_url.str() << "\""
+       << ",\"streamType\":\"LIVE\""
+       << ",\"contentType\":\"" << mime << "\"";
+
+    return ss.str();
+}
+
 void intf_sys_t::msgPlayerLoad()
 {
     std::stringstream ss;
     ss << "{\"type\":\"LOAD\","
-       <<  "\"media\":{\"contentId\":\"http://" << serverIP << ":"
-           << i_port
-           << "/stream\","
-       <<             "\"streamType\":\"LIVE\","
-       <<             "\"contentType\":\"" << mime << "\"},"
-       <<  "\"requestId\":" << i_requestId++ << "}";
+       <<  "\"media\":{" << GetMedia() << "},"
+       <<  "\"autoplay\":\"false\","
+       <<  "\"requestId\":" << i_requestId++
+       << "}";
 
     pushMediaPlayerMessage( ss );
 }
@@ -1034,7 +1062,7 @@ void intf_sys_t::requestPlayerSeek(mtime_t pos)
 void intf_sys_t::setInputState(input_state_e state)
 {
     input_state = state;
-    msg_Dbg( p_module, "new %d state", state );
+    msg_Dbg( p_module, "new %d state for %s", state, title.c_str() );
     switch( input_state )
     {
         case PLAYING_S:
@@ -1131,3 +1159,15 @@ void intf_sys_t::set_input_state(void *pt, input_state_e state)
     intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
     p_this->setInputState( state );
 }
+
+void intf_sys_t::set_title(void *pt, const char *psz_title)
+{
+    intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
+    p_this->setTitle( psz_title );
+}
+
+void intf_sys_t::set_artwork(void *pt, const char *psz_artwork)
+{
+    intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
+    p_this->setArtwork( psz_artwork );
+}
diff --git a/modules/stream_out/chromecast/chromecast_demux.cpp b/modules/stream_out/chromecast/chromecast_demux.cpp
index fb2e35d..c66735e 100644
--- a/modules/stream_out/chromecast/chromecast_demux.cpp
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -47,6 +47,18 @@ struct demux_sys_t
         ,m_seektime( VLC_TS_INVALID )
     {
         input_thread_t *p_input = demux_FilterDemuxer( p_demux )->p_input;
+        input_item_t *p_item = input_GetItem( p_input );
+        if ( p_item )
+        {
+            char *psz_title = input_item_GetTitleFbName( p_item );
+            p_renderer->pf_set_title( p_renderer->p_opaque, psz_title );
+            free( psz_title );
+
+            psz_title = input_item_GetArtworkURL( p_item );
+            p_renderer->pf_set_artwork( p_renderer->p_opaque, psz_title );
+            free( psz_title );
+        }
+
         p_renderer->pf_set_input_state( p_renderer->p_opaque,
                                         (input_state_e) var_GetInteger( p_input, "state" ) );
         var_AddCallback( p_input, "intf-event", InputEvent, this );
@@ -56,6 +68,9 @@ struct demux_sys_t
     {
         input_thread_t *p_input = demux_FilterDemuxer( p_demux )->p_input;
         var_DelCallback( p_input, "intf-event", InputEvent, this );
+
+        p_renderer->pf_set_title( p_renderer->p_opaque, NULL );
+        p_renderer->pf_set_artwork( p_renderer->p_opaque, NULL );
     }
 
     /**
-- 
2.7.0



More information about the vlc-devel mailing list