Commit 9afcfad3 authored by Thomas Guillem's avatar Thomas Guillem

chromecast: fetch all metas

parent 00b1bc0f
......@@ -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;
......
......@@ -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;
......
......@@ -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++
<< "}";
......
......@@ -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 );
}
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment