[vlc-commits] chromecast: Queue messages that aren't directly sent by the state machine
Hugo Beauzée-Luyssen
git at videolan.org
Thu Jul 20 10:45:40 CEST 2017
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Jul 20 10:19:50 2017 +0200| [58921590a200ab8cfbdbd6d9ef56995908f9c323] | committer: Hugo Beauzée-Luyssen
chromecast: Queue messages that aren't directly sent by the state machine
fix #18525
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=58921590a200ab8cfbdbd6d9ef56995908f9c323
---
modules/stream_out/chromecast/chromecast.h | 8 ++++
modules/stream_out/chromecast/chromecast_ctrl.cpp | 54 +++++++++++++++++------
2 files changed, 49 insertions(+), 13 deletions(-)
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index dcd705b9ca..1dba135997 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -36,6 +36,7 @@
#include <atomic>
#include <sstream>
+#include <queue>
#ifndef PROTOBUF_INLINE_NOT_IN_HEADERS
# define PROTOBUF_INLINE_NOT_IN_HEADERS 0
@@ -139,6 +140,11 @@ private:
*****************************************************************************/
struct intf_sys_t
{
+ enum QueueableMessages
+ {
+ Stop,
+ Seek
+ };
intf_sys_t(vlc_object_t * const p_this, int local_port, std::string device_addr, int device_port, vlc_interrupt_t *);
~intf_sys_t();
@@ -156,6 +162,7 @@ private:
void waitSeekDone();
void processMessage(const castchannel::CastMessage &msg);
+ void queueMessage( QueueableMessages msg );
void setPauseState(bool paused);
@@ -208,6 +215,7 @@ private:
vlc_thread_t m_chromecastThread;
ChromecastCommunication m_communication;
+ std::queue<QueueableMessages> m_msgQueue;
States m_state;
std::string m_artwork;
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 3b6603f146..75241c688c 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -198,6 +198,13 @@ void intf_sys_t::processMessage(const castchannel::CastMessage &msg)
}
}
+void intf_sys_t::queueMessage( QueueableMessages msg )
+{
+ // Assume lock is held by the called
+ m_msgQueue.push( msg );
+ vlc_interrupt_raise( m_ctl_thread_interrupt );
+}
+
/*****************************************************************************
@@ -218,8 +225,38 @@ void intf_sys_t::mainLoop()
// State was already initialized as Authenticating
m_communication.msgAuth();
- while ( !vlc_killed() && handleMessages() )
- ;
+ while ( !vlc_killed() )
+ {
+ if ( !handleMessages() )
+ break;
+ vlc_mutex_locker lock( &m_lock );
+ while ( m_msgQueue.empty() == false )
+ {
+ QueueableMessages msg = m_msgQueue.front();
+ switch ( msg )
+ {
+ case Stop:
+ m_communication.msgPlayerStop( m_appTransportId, m_mediaSessionId );
+ break;
+ case Seek:
+ {
+ char current_time[32];
+ mtime_t seek_request_time = mdate() + SEEK_FORWARD_OFFSET;
+ if( snprintf( current_time, sizeof(current_time), "%.3f",
+ double( seek_request_time ) / 1000000.0 ) >= (int)sizeof(current_time) )
+ {
+ msg_Err( m_module, "snprintf() truncated string for mediaSessionId" );
+ current_time[sizeof(current_time) - 1] = '\0';
+ }
+ /* send a fake time to seek to, to make sure the device flushes its buffers */
+ m_communication.msgPlayerSeek( m_appTransportId, m_mediaSessionId, current_time );
+ setState( Seeking );
+ break;
+ }
+ }
+ m_msgQueue.pop();
+ }
+ }
}
void intf_sys_t::processAuthMessage( const castchannel::CastMessage& msg )
@@ -578,7 +615,7 @@ void intf_sys_t::requestPlayerStop()
vlc_mutex_locker locker(&m_lock);
if ( m_mediaSessionId.empty() == true )
return;
- m_communication.msgPlayerStop( m_appTransportId, m_mediaSessionId );
+ queueMessage( Stop );
}
void intf_sys_t::requestPlayerSeek(mtime_t pos)
@@ -588,16 +625,7 @@ void intf_sys_t::requestPlayerSeek(mtime_t pos)
return;
if ( pos != VLC_TS_INVALID )
m_ts_local_start = pos;
- char current_time[32];
- mtime_t seek_request_time = mdate() + SEEK_FORWARD_OFFSET;
- if( snprintf( current_time, sizeof(current_time), "%.3f", double( seek_request_time ) / 1000000.0 ) >= (int)sizeof(current_time) )
- {
- msg_Err( m_module, "snprintf() truncated string for mediaSessionId" );
- current_time[sizeof(current_time) - 1] = '\0';
- }
- /* send a fake time to seek to, to make sure the device flushes its buffers */
- m_communication.msgPlayerSeek( m_appTransportId, m_mediaSessionId, current_time );
- setState( Seeking );
+ queueMessage( Seek );
}
void intf_sys_t::setPauseState(bool paused)
More information about the vlc-commits
mailing list