[vlc-commits] chromecast: send a dummy SEEK message when flushing is needed

Steve Lhomme git at videolan.org
Mon May 9 14:39:13 CEST 2016


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Mon May  9 12:53:20 2016 +0200| [782a10dc5dfa5c11fadd639f5721b344af934e3b] | committer: Jean-Baptiste Kempf

chromecast: send a dummy SEEK message when flushing is needed

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=782a10dc5dfa5c11fadd639f5721b344af934e3b
---

 modules/stream_out/chromecast/cast.cpp            |    3 ++
 modules/stream_out/chromecast/chromecast.h        |    2 ++
 modules/stream_out/chromecast/chromecast_ctrl.cpp |   32 +++++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index 5bc962a..ee8f97b 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 93b72fb..c1684c9 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -87,6 +87,7 @@ struct intf_sys_t
 
     void setHasInput( bool has_input, const std::string mime_type = "");
 
+    void requestPlayerSeek();
     void requestPlayerStop();
 
 private:
@@ -150,6 +151,7 @@ private:
 
     void notifySendRequest();
     bool requested_stop;
+    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 e9af82a..5f7de8d 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -53,6 +53,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";
@@ -103,6 +105,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)
@@ -890,6 +893,22 @@ bool intf_sys_t::handleMessages()
         requested_stop = false;
     }
 
+    if ( requested_seek )
+    {
+        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';
+        }
+        setPlayerStatus(CMD_SEEK_SENT);
+        /* send a fake time to seek to, to make sure the device flushes its buffers */
+        msgPlayerSeek( current_time );
+
+        requested_seek = false;
+    }
+
     /* dummy socket that we close to unblock the receiver, so we can send data */
     i_send_ready_fd = vlc_socket( AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, true );
     if (i_send_ready_fd == -1)
@@ -962,3 +981,16 @@ void intf_sys_t::requestPlayerStop()
     requested_stop = true;
     notifySendRequest();
 }
+
+void intf_sys_t::requestPlayerSeek()
+{
+    vlc_mutex_locker locker(&lock);
+    if ( conn_status == CHROMECAST_CONNECTION_DEAD )
+        return;
+
+    if ( mediaSessionId.empty() )
+        return;
+
+    requested_seek = true;
+    notifySendRequest();
+}



More information about the vlc-commits mailing list