[vlc-commits] chromecast: fetch all metas
Thomas Guillem
git at videolan.org
Wed Jan 31 16:25:54 CET 2018
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jan 30 14:31:33 2018 +0100| [9afcfad3428fd62e5b9f340c0a8fb93e630d998a] | committer: Thomas Guillem
chromecast: fetch all metas
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9afcfad3428fd62e5b9f340c0a8fb93e630d998a
---
modules/stream_out/chromecast/chromecast.h | 18 +++---
modules/stream_out/chromecast/chromecast_common.h | 3 +-
.../chromecast/chromecast_communication.cpp | 67 ++++++++++++++++++----
modules/stream_out/chromecast/chromecast_ctrl.cpp | 36 ++++--------
modules/stream_out/chromecast/chromecast_demux.cpp | 41 +++++++++----
5 files changed, 103 insertions(+), 62 deletions(-)
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 2f13f5a2b6..a1925c9ea5 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -109,8 +109,8 @@ public:
void msgReceiverGetStatus();
void msgReceiverClose(const std::string& destinationId);
void msgAuth();
- void msgPlayerLoad( const std::string& destinationId, unsigned int i_port, const std::string& title,
- const std::string& artwork, const std::string& mime );
+ void msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
+ const std::string& mime, const vlc_meta_t *p_meta );
void msgPlayerPlay( const std::string& destinationId, const std::string& mediaSessionId );
void msgPlayerStop( const std::string& destinationId, const std::string& mediaSessionId );
void msgPlayerPause( const std::string& destinationId, const std::string& mediaSessionId );
@@ -128,8 +128,8 @@ private:
const std::string & destinationId = DEFAULT_CHOMECAST_RECEIVER,
castchannel::CastMessage_PayloadType payloadType = castchannel::CastMessage_PayloadType_STRING);
void pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload );
- std::string GetMedia( unsigned int i_port, const std::string& title,
- const std::string& artwork, const std::string& mime );
+ std::string GetMedia( unsigned int i_port, const std::string& mime,
+ const vlc_meta_t *p_meta );
private:
vlc_object_t* m_module;
@@ -172,9 +172,7 @@ private:
void setPauseState(bool paused);
- void setTitle( const char *psz_title );
-
- void setArtwork( const char *psz_artwork );
+ void setMeta( vlc_meta_t *p_meta );
mtime_t getPlaybackTimestamp() const;
@@ -207,8 +205,7 @@ private:
static void set_pause_state(void*, bool paused);
- static void set_title(void*, const char *psz_title);
- static void set_artwork(void*, const char *psz_artwork);
+ static void set_meta(void*, vlc_meta_t *p_meta);
private:
@@ -228,8 +225,7 @@ private:
States m_state;
bool m_eof;
- std::string m_artwork;
- std::string m_title;
+ vlc_meta_t *m_meta;
vlc_interrupt_t *m_ctl_thread_interrupt;
diff --git a/modules/stream_out/chromecast/chromecast_common.h b/modules/stream_out/chromecast/chromecast_common.h
index 0a96f81cf8..38897c0fda 100644
--- a/modules/stream_out/chromecast/chromecast_common.h
+++ b/modules/stream_out/chromecast/chromecast_common.h
@@ -49,8 +49,7 @@ typedef struct
void (*pf_set_pause_state)(void*, bool paused);
- void (*pf_set_title)(void*, const char *psz_title);
- void (*pf_set_artwork)(void*, const char *psz_artwork);
+ void (*pf_set_meta)(void*, vlc_meta_t *p_meta);
} chromecast_common;
diff --git a/modules/stream_out/chromecast/chromecast_communication.cpp b/modules/stream_out/chromecast/chromecast_communication.cpp
index 53ac92038c..2da8bc346d 100644
--- a/modules/stream_out/chromecast/chromecast_communication.cpp
+++ b/modules/stream_out/chromecast/chromecast_communication.cpp
@@ -235,21 +235,65 @@ void ChromecastCommunication::msgPlayerGetStatus( const std::string& destination
}
std::string ChromecastCommunication::GetMedia( unsigned int i_port,
- const std::string& title, const std::string& artwork,
- const std::string& mime )
+ const std::string& mime,
+ const vlc_meta_t *p_meta )
{
std::stringstream ss;
- if ( title.size() )
+ bool b_music = strncmp(mime.c_str(), "audio", strlen("audio")) == 0;
+
+ const char *psz_title = NULL;
+ const char *psz_artwork = NULL;
+ const char *psz_artist = NULL;
+ const char *psz_album = NULL;
+ const char *psz_albumartist = NULL;
+ const char *psz_tracknumber = NULL;
+ const char *psz_discnumber = NULL;
+
+ if( p_meta )
{
- ss << "\"metadata\":{"
- << " \"metadataType\":0"
- << ",\"title\":\"" << title << "\"";
+ psz_title = vlc_meta_Get( p_meta, vlc_meta_Title );
+ psz_artwork = vlc_meta_Get( p_meta, vlc_meta_ArtworkURL );
+
+ if( b_music && psz_title )
+ {
+ psz_artist = vlc_meta_Get( p_meta, vlc_meta_Artist );
+ psz_album = vlc_meta_Get( p_meta, vlc_meta_Album );
+ psz_albumartist = vlc_meta_Get( p_meta, vlc_meta_AlbumArtist );
+ psz_tracknumber = vlc_meta_Get( p_meta, vlc_meta_TrackNumber );
+ psz_discnumber = vlc_meta_Get( p_meta, vlc_meta_DiscNumber );
+ }
+ if( !psz_title )
+ {
+ psz_title = vlc_meta_Get( p_meta, vlc_meta_NowPlaying );
+ if( !psz_title )
+ psz_title = vlc_meta_Get( p_meta, vlc_meta_ESNowPlaying );
+ }
+
+ if ( psz_title )
+ {
+ ss << "\"metadata\":{"
+ << " \"metadataType\":" << ( b_music ? "3" : "0" )
+ << ",\"title\":\"" << psz_title << "\"";
+ if( b_music )
+ {
+ if( psz_artist )
+ ss << ",\"artist\":\"" << psz_artist << "\"";
+ if( psz_album )
+ ss << ",\"album\":\"" << psz_album << "\"";
+ if( psz_albumartist )
+ ss << ",\"albumArtist\":\"" << psz_albumartist << "\"";
+ if( psz_tracknumber )
+ ss << ",\"trackNumber\":\"" << psz_tracknumber << "\"";
+ if( psz_discnumber )
+ ss << ",\"discNumber\":\"" << psz_discnumber << "\"";
+ }
- if ( artwork.size() && !strncmp(artwork.c_str(), "http", 4))
- ss << ",\"images\":[\"" << artwork << "\"]";
+ if ( psz_artwork && !strncmp( psz_artwork, "http", 4 ) )
+ ss << ",\"images\":[\"" << psz_artwork << "\"]";
- ss << "},";
+ ss << "},";
+ }
}
std::stringstream chromecast_url;
@@ -265,12 +309,11 @@ std::string ChromecastCommunication::GetMedia( unsigned int i_port,
}
void ChromecastCommunication::msgPlayerLoad( const std::string& destinationId, unsigned int i_port,
- const std::string& title, const std::string& artwork,
- const std::string& mime )
+ const std::string& mime, const vlc_meta_t *p_meta )
{
std::stringstream ss;
ss << "{\"type\":\"LOAD\","
- << "\"media\":{" << GetMedia( i_port, title, artwork, mime ) << "},"
+ << "\"media\":{" << GetMedia( i_port, mime, p_meta ) << "},"
<< "\"autoplay\":\"false\","
<< "\"requestId\":" << m_requestId++
<< "}";
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 1976b51b80..887103c816 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -87,6 +87,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
, m_communication( p_this, device_addr.c_str(), device_port )
, m_state( Authenticating )
, m_eof( false )
+ , m_meta( NULL )
, m_ctl_thread_interrupt(p_interrupt)
, m_time_playback_started( VLC_TS_INVALID )
, m_ts_local_start( VLC_TS_INVALID )
@@ -105,8 +106,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
m_common.pf_request_seek = request_seek;
m_common.pf_wait_seek_done = wait_seek_done;
m_common.pf_set_pause_state = set_pause_state;
- m_common.pf_set_artwork = set_artwork;
- m_common.pf_set_title = set_title;
+ m_common.pf_set_meta = set_meta;
assert( var_Type( m_module->obj.parent->obj.parent, CC_SHARED_VAR_NAME) == 0 );
if (var_Create( m_module->obj.parent->obj.parent, CC_SHARED_VAR_NAME, VLC_VAR_ADDRESS ) == VLC_SUCCESS )
@@ -175,7 +175,7 @@ void intf_sys_t::setHasInput( const std::string mime_type )
// We should now be in the ready state, and therefor have a valid transportId
assert( m_appTransportId.empty() == false );
// we cannot start a new load when the last one is still processing
- m_communication.msgPlayerLoad( m_appTransportId, m_streaming_port, m_title, m_artwork, mime_type );
+ m_communication.msgPlayerLoad( m_appTransportId, m_streaming_port, mime_type, m_meta );
setState( Loading );
m_eof = false;
}
@@ -673,7 +673,7 @@ void intf_sys_t::requestPlayerSeek(mtime_t pos)
void intf_sys_t::setPauseState(bool paused)
{
- msg_Dbg( m_module, "%s state for %s", paused ? "paused" : "playing", m_title.c_str() );
+ msg_Dbg( m_module, "%s state", paused ? "paused" : "playing" );
vlc_mutex_locker locker( &m_lock );
if ( !paused )
{
@@ -731,20 +731,12 @@ bool intf_sys_t::isFinishedPlaying()
return m_state == LoadFailed || m_state == Dead || m_eof;
}
-void intf_sys_t::setTitle(const char* psz_title)
+void intf_sys_t::setMeta(vlc_meta_t *p_meta)
{
- if ( psz_title )
- m_title = psz_title;
- else
- m_title = "";
-}
-
-void intf_sys_t::setArtwork(const char* psz_artwork)
-{
- if ( psz_artwork )
- m_artwork = psz_artwork;
- else
- m_artwork = "";
+ vlc_mutex_locker locker(&m_lock);
+ if (m_meta != NULL)
+ vlc_meta_Delete(m_meta);
+ m_meta = p_meta;
}
mtime_t intf_sys_t::getPlaybackTimestamp() const
@@ -847,14 +839,8 @@ void intf_sys_t::set_pause_state(void *pt, bool paused)
p_this->setPauseState( paused );
}
-void intf_sys_t::set_title(void *pt, const char *psz_title)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- p_this->setTitle( psz_title );
-}
-
-void intf_sys_t::set_artwork(void *pt, const char *psz_artwork)
+void intf_sys_t::set_meta(void *pt, vlc_meta_t *p_meta)
{
intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- p_this->setArtwork( psz_artwork );
+ p_this->setMeta( p_meta );
}
diff --git a/modules/stream_out/chromecast/chromecast_demux.cpp b/modules/stream_out/chromecast/chromecast_demux.cpp
index ff4e2b319f..8cefd063c1 100644
--- a/modules/stream_out/chromecast/chromecast_demux.cpp
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -50,16 +50,36 @@ struct demux_sys_t
vlc_meta_t *p_meta = vlc_meta_New();
if( likely(p_meta != NULL) )
{
- if (demux_Control( demux->p_next, DEMUX_GET_META, p_meta) == VLC_SUCCESS)
+ input_item_t *p_item = demux->p_next->p_input ?
+ input_GetItem( demux->p_next->p_input ) : NULL;
+ if( p_item )
{
- const char *meta = vlc_meta_Get( p_meta, vlc_meta_Title );
- if ( meta != NULL )
- p_renderer->pf_set_title( p_renderer->p_opaque, meta );
- meta = vlc_meta_Get( p_meta, vlc_meta_ArtworkURL );
- if ( meta != NULL )
- p_renderer->pf_set_artwork( p_renderer->p_opaque, meta );
+ /* Favor Meta from the input item of the input_thread since
+ * it's pre-processed by the meta fetcher */
+ for( int i = 0; i < VLC_META_TYPE_COUNT; ++i )
+ {
+ char *psz_meta = input_item_GetMeta( p_item, (vlc_meta_type_t)i );
+ if( psz_meta )
+ {
+ vlc_meta_Set( p_meta, (vlc_meta_type_t)i, psz_meta );
+ free( psz_meta );
+ }
+ }
+ if( vlc_meta_Get( p_meta, vlc_meta_Title ) == NULL )
+ {
+ char *psz_meta = input_item_GetName( p_item );
+ if( psz_meta )
+ {
+ vlc_meta_Set( p_meta, vlc_meta_Title, psz_meta );
+ free( psz_meta );
+ }
+ }
+ p_renderer->pf_set_meta( p_renderer->p_opaque, p_meta );
}
- vlc_meta_Delete(p_meta);
+ else if (demux_Control( demux->p_next, DEMUX_GET_META, p_meta) == VLC_SUCCESS)
+ p_renderer->pf_set_meta( p_renderer->p_opaque, p_meta );
+ else
+ vlc_meta_Delete( p_meta );
}
if (demux_Control( demux->p_next, DEMUX_CAN_SEEK, &canSeek ) != VLC_SUCCESS)
canSeek = false;
@@ -105,10 +125,7 @@ struct demux_sys_t
~demux_sys_t()
{
if( p_renderer )
- {
- p_renderer->pf_set_title( p_renderer->p_opaque, NULL );
- p_renderer->pf_set_artwork( p_renderer->p_opaque, NULL );
- }
+ p_renderer->pf_set_meta( p_renderer->p_opaque, NULL );
}
void setPauseState(bool paused)
More information about the vlc-commits
mailing list