[vlc-devel] [PATCH 10/11] chromecast: pass the title/artwork to the Chromecast when starting playback
Steve Lhomme
robux4 at videolabs.io
Mon May 2 18:24:09 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 11eccbd..0cd1b77 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -160,6 +160,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_,
@@ -186,6 +202,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);
mtime_t getPlaybackTimestamp() const
@@ -241,6 +261,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 f1bec5f..3133061 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -130,6 +130,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 )
@@ -774,16 +776,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 );
}
@@ -1084,7 +1112,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:
@@ -1181,3 +1209,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 0fb9df6..1bce98b 100644
--- a/modules/stream_out/chromecast/chromecast_demux.cpp
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -46,6 +46,18 @@ struct demux_filter_sys_t
,canSeek(false)
,m_seektime( VLC_TS_INVALID )
{
+ input_item_t *p_item = input_GetItem( p_demux->p_demux->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_demux->p_demux->p_input, "state" ) );
var_AddCallback( p_demux->p_demux->p_input, "intf-event", InputEvent, this );
@@ -54,6 +66,9 @@ struct demux_filter_sys_t
~demux_filter_sys_t()
{
var_DelCallback( p_demux->p_demux->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