[vlc-devel] [PATCH 4/4] chromecast: send a dummy SEEK message when flushing is needed

Steve Lhomme robux4 at videolabs.io
Mon May 9 22:08:49 CEST 2016


---
 modules/stream_out/chromecast/cast.cpp            |  3 +++
 modules/stream_out/chromecast/chromecast.h        |  2 ++
 modules/stream_out/chromecast/chromecast_ctrl.cpp | 24 +++++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index bc4c462..69747f4 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -374,6 +374,9 @@ static void Flush( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
     if ( id == NULL )
         return;
 
+    /* a seek on the Chromecast flushes its buffers */
+    p_sys->p_intf->requestPlayerSeek();
+
     sout_StreamFlush( p_sys->p_out, id );
 }
 
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index b174a00..bab8318 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -89,6 +89,7 @@ struct intf_sys_t
 
     void setHasInput( bool has_input, const std::string mime_type = "");
 
+    void requestPlayerSeek();
     void requestPlayerStop();
 
 private:
@@ -151,6 +152,7 @@ private:
 
     void notifySendRequest();
     std::atomic_bool requested_stop;
+    std::atomic_bool requested_seek;
 
     int sendMessage(const castchannel::CastMessage &msg);
 
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 367aa37..6285085 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -52,6 +52,8 @@
 #define PONG_WAIT_TIME 500
 #define PONG_WAIT_RETRIES 2
 
+static const mtime_t SEEK_FORWARD_OFFSET = 1000000;
+
 #define CONTROL_CFG_PREFIX "chromecast-"
 
 static const std::string NAMESPACE_DEVICEAUTH       = "urn:x-cast:com.google.cast.tp.deviceauth";
@@ -101,6 +103,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
  , p_creds(NULL)
  , p_tls(NULL)
  , requested_stop(false)
+ , requested_seek(false)
  , conn_status(CHROMECAST_DISCONNECTED)
  , cmd_status(NO_CMD_PENDING)
  , i_receiver_requestId(0)
@@ -877,6 +880,21 @@ bool intf_sys_t::handleMessages()
         msgPlayerStop();
     }
 
+    if ( requested_seek.exchange(false) && !mediaSessionId.empty() )
+    {
+        char current_time[32];
+        mtime_t m_seek_request_time = mdate() + SEEK_FORWARD_OFFSET;
+        if( snprintf( current_time, sizeof(current_time), "%.3f", double( m_seek_request_time ) / 1000000.0 ) >= (int)sizeof(current_time) )
+        {
+            msg_Err( p_module, "snprintf() truncated string for mediaSessionId" );
+            current_time[sizeof(current_time) - 1] = '\0';
+        }
+        vlc_mutex_locker locker(&lock);
+        setPlayerStatus(CMD_SEEK_SENT);
+        /* send a fake time to seek to, to make sure the device flushes its buffers */
+        msgPlayerSeek( current_time );
+    }
+
     int i_ret = recvPacket( b_msgReceived, i_payloadSize,
                             &i_received, p_packet, &b_pingTimeout,
                             &i_waitdelay, &i_retries);
@@ -920,3 +938,9 @@ void intf_sys_t::requestPlayerStop()
     requested_stop = true;
     notifySendRequest();
 }
+
+void intf_sys_t::requestPlayerSeek()
+{
+    requested_seek = true;
+    notifySendRequest();
+}
-- 
2.7.0



More information about the vlc-devel mailing list