[vlc-devel] [RFC PATCH 09/10] chromecast: Handle pause/position/time from the stream_output
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Thu Sep 7 15:46:05 CEST 2017
This makes the demux_filter unrequired
---
modules/stream_out/chromecast/cast.cpp | 43 ++++++++-
modules/stream_out/chromecast/chromecast.h | 28 ++----
modules/stream_out/chromecast/chromecast_ctrl.cpp | 105 +++++++---------------
3 files changed, 77 insertions(+), 99 deletions(-)
diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index b4b1fd9a84..575abaa763 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -394,15 +394,54 @@ static int Control(sout_stream_t *p_stream, int i_query, va_list args)
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
- if (i_query == SOUT_STREAM_EMPTY)
+ switch ( i_query )
+ {
+ case SOUT_STREAM_EMPTY:
{
bool *b = va_arg( args, bool * );
/* check if the Chromecast to be done playing */
*b = p_sys->p_intf == NULL || p_sys->p_intf->isFinishedPlaying();
return VLC_SUCCESS;
}
+ case SOUT_STREAM_GET_TIME:
+ {
+ mtime_t* pi_time = va_arg( args, mtime_t* );
+ if( !pi_time )
+ return VLC_EGENERIC;
+ *pi_time = p_sys->p_intf->getPlaybackTimestamp();
+ return VLC_SUCCESS;
+ }
+ case SOUT_STREAM_SET_TIME:
+ {
+ mtime_t i_time = va_arg( args, mtime_t );
+ p_sys->p_intf->requestPlayerSeek( i_time );
+ return VLC_SUCCESS;
+ }
+ case SOUT_STREAM_SET_PAUSE_STATE:
+ {
+ bool b_paused = va_arg( args, int );
+ p_sys->p_intf->setPauseState( b_paused );
+ return VLC_SUCCESS;
+ }
+ case SOUT_STREAM_GET_POSITION:
+ {
+ double *pf_pos = va_arg( args, double* );
+ if( !pf_pos )
+ return VLC_EGENERIC;
+ *pf_pos = p_sys->p_intf->getPlaybackPosition();
+ return VLC_SUCCESS;
+ }
+ case SOUT_STREAM_SET_POSITION:
+ {
+ double f_pos = va_arg( args, double );
+ p_sys->p_intf->requestSetPos( f_pos );
+ return VLC_SUCCESS;
+ }
+ default:
+ break;
+ }
- if ( !p_sys->p_out->pf_control )
+ if ( !p_sys->p_out || !p_sys->p_out->pf_control )
return VLC_EGENERIC;
return p_sys->p_out->pf_control( p_sys->p_out, i_query, args );
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 1dba135997..b16dd3b997 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -153,7 +153,11 @@ struct intf_sys_t
void setHasInput(const std::string mime_type = "");
void requestPlayerSeek(mtime_t pos);
+ void requestSetPos( double pos );
void requestPlayerStop();
+ mtime_t getPlaybackTimestamp() const;
+ double getPlaybackPosition() const;
+ void setPauseState(bool paused);
private:
bool handleMessages();
@@ -164,15 +168,11 @@ private:
void processMessage(const castchannel::CastMessage &msg);
void queueMessage( QueueableMessages msg );
- void setPauseState(bool paused);
-
void setTitle( const char *psz_title );
void setArtwork( const char *psz_artwork );
+ void fetchMeta();
- mtime_t getPlaybackTimestamp() const;
-
- double getPlaybackPosition() const;
// Sets the current state and signal the associated wait cond.
// This must be called with the lock held
void setState( States state );
@@ -187,21 +187,6 @@ private:
private:
static void* ChromecastThread(void* p_data);
- static void set_length(void*, mtime_t length);
- static mtime_t get_time(void*);
- static double get_position(void*);
-
- static void wait_app_started(void*);
-
- static void request_seek(void*, mtime_t pos);
- static void wait_seek_done(void*);
-
- 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);
-
-
private:
vlc_object_t * const m_module;
const int m_streaming_port;
@@ -229,9 +214,6 @@ private:
mtime_t m_ts_local_start;
mtime_t m_length;
- /* shared structure with the demux-filter */
- chromecast_common m_common;
-
/* Heartbeat */
uint8_t m_pingRetriesLeft;
};
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 75241c688c..fe6104d9af 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -38,6 +38,9 @@
#include "../../misc/webservices/json.h"
+#include <vlc_playlist.h>
+#include <vlc_input.h>
+
/* deadline regarding pings sent from receiver */
#define PING_WAIT_TIME 6000
#define PING_WAIT_RETRIES 1
@@ -91,21 +94,6 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
vlc_mutex_init(&m_lock);
vlc_cond_init( &m_stateChangedCond );
- m_common.p_opaque = this;
- m_common.pf_get_position = get_position;
- m_common.pf_get_time = get_time;
- m_common.pf_set_length = set_length;
- m_common.pf_wait_app_started = wait_app_started;
- 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;
-
- 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 )
- var_SetAddress( m_module->obj.parent->obj.parent, CC_SHARED_VAR_NAME, &m_common );
-
// Start the Chromecast event thread.
if (vlc_clone(&m_chromecastThread, ChromecastThread, this,
VLC_THREAD_PRIORITY_LOW))
@@ -116,8 +104,6 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
intf_sys_t::~intf_sys_t()
{
- var_Destroy( m_module->obj.parent->obj.parent, CC_SHARED_VAR_NAME );
-
switch ( m_state )
{
case Ready:
@@ -150,6 +136,8 @@ intf_sys_t::~intf_sys_t()
void intf_sys_t::setHasInput( const std::string mime_type )
{
+ fetchMeta();
+
vlc_mutex_locker locker(&m_lock);
msg_Dbg( m_module, "Loading content for session:%s", m_mediaSessionId.c_str() );
@@ -628,6 +616,11 @@ void intf_sys_t::requestPlayerSeek(mtime_t pos)
queueMessage( Seek );
}
+void intf_sys_t::requestSetPos(double pos)
+{
+ requestPlayerSeek( pos * m_length );
+}
+
void intf_sys_t::setPauseState(bool paused)
{
msg_Dbg( m_module, "%s state for %s", paused ? "paused" : "playing", m_title.c_str() );
@@ -702,6 +695,27 @@ void intf_sys_t::setArtwork(const char* psz_artwork)
m_artwork = "";
}
+void intf_sys_t::fetchMeta()
+{
+ playlist_t *p_playlist = reinterpret_cast<playlist_t*>( m_module->obj.parent->obj.parent );
+ if( !p_playlist )
+ return;
+ playlist_Lock( p_playlist );
+ input_thread_t *p_input = playlist_CurrentInputLocked( p_playlist );
+ if( !p_input )
+ {
+ playlist_Unlock( p_playlist );
+ return;
+ }
+ input_item_t *p_item = input_GetItem( p_input );
+ if( p_item )
+ {
+ m_length = input_item_GetDuration( p_item );
+ }
+ playlist_Unlock( p_playlist );
+ vlc_object_release( p_input );
+}
+
mtime_t intf_sys_t::getPlaybackTimestamp() const
{
switch( m_state )
@@ -741,60 +755,3 @@ void intf_sys_t::setState( States state )
vlc_cond_signal( &m_stateChangedCond );
}
}
-
-mtime_t intf_sys_t::get_time(void *pt)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- vlc_mutex_locker locker( &p_this->m_lock );
- return p_this->getPlaybackTimestamp();
-}
-
-double intf_sys_t::get_position(void *pt)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- vlc_mutex_locker locker( &p_this->m_lock );
- return p_this->getPlaybackPosition();
-}
-
-void intf_sys_t::set_length(void *pt, mtime_t length)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- p_this->m_length = length;
-}
-
-void intf_sys_t::wait_app_started(void *pt)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- vlc_mutex_locker locker( &p_this->m_lock);
- p_this->waitAppStarted();
-}
-
-void intf_sys_t::request_seek(void *pt, mtime_t pos)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- p_this->requestPlayerSeek(pos);
-}
-
-void intf_sys_t::wait_seek_done(void *pt)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- p_this->waitSeekDone();
-}
-
-void intf_sys_t::set_pause_state(void *pt, bool paused)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- 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)
-{
- intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
- p_this->setArtwork( psz_artwork );
-}
--
2.11.0
More information about the vlc-devel
mailing list