[vlc-commits] chromecast: drain sout_access when empty

Thomas Guillem git at videolan.org
Thu Feb 1 11:26:26 CET 2018


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jan 30 10:50:21 2018 +0100| [ab1b40757dc42cce24716e4b683b903ff23a3570] | committer: Thomas Guillem

chromecast: drain sout_access when empty

This will close the sout chain and the chromecast-http sout_access that will
send an EOF instead of closing the http stream.

(cherry picked from commit ffe06453bcb028d718a7dc30255ea58ef502eb81)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/stream_out/chromecast/cast.cpp | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index 9e4a23132c..1f946cb98f 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -60,6 +60,7 @@ struct sout_stream_sys_t
         , es_changed( true )
         , cc_has_input( false )
         , out_force_reload( false )
+        , drained( false )
         , out_streams_added( 0 )
         , transcode_attempt_idx( 0 )
         , previous_state( Authenticating )
@@ -108,6 +109,7 @@ struct sout_stream_sys_t
     bool                               es_changed;
     bool                               cc_has_input;
     bool                               out_force_reload;
+    bool                               drained;
     std::vector<sout_stream_id_sys_t*> streams;
     std::vector<sout_stream_id_sys_t*> out_streams;
     unsigned int                       out_streams_added;
@@ -536,6 +538,7 @@ static void DelInternal(sout_stream_t *p_stream, sout_stream_id_sys_t *id,
         p_sys->clearAccessOut();
         p_sys->sout = "";
         p_sys->transcode_attempt_idx = 0;
+        p_sys->drained = false;
     }
 }
 
@@ -892,7 +895,7 @@ static int Send(sout_stream_t *p_stream, sout_stream_id_sys_t *id,
     States s = p_sys->p_intf->state();
     if ( p_sys->previous_state != s )
     {
-        if ( s == LoadFailed && p_sys->es_changed == false )
+        if ( !p_sys->drained && s == LoadFailed && p_sys->es_changed == false )
         {
             if ( p_sys->transcode_attempt_idx > MAX_TRANSCODE_PASS - 1 )
             {
@@ -917,6 +920,9 @@ static int Send(sout_stream_t *p_stream, sout_stream_id_sys_t *id,
     int ret = sout_StreamIdSend(p_sys->p_out, next_id, p_buffer);
     if (ret != VLC_SUCCESS)
         DelInternal(p_stream, id, false);
+
+    p_sys->drained = false;
+
     return ret;
 }
 
@@ -924,8 +930,18 @@ static void Flush( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
 
+    if( p_sys->out_streams.empty() && p_sys->drained )
+    {
+        /* Worst case scenario that won't happen often: we terminated
+         * everything since we were draining but the user requested a seek.
+         * Change the es_changed value in order to re-create everything again.
+         * */
+
+        p_sys->es_changed = true;
+    }
+
     id = p_sys->GetSubId( p_stream, id );
-    if ( id == NULL )
+    if ( id == NULL || p_sys->drained )
         return;
 
     /* a seek on the Chromecast flushes its buffers */
@@ -941,6 +957,17 @@ static int Control(sout_stream_t *p_stream, int i_query, va_list args)
     if (i_query == SOUT_STREAM_EMPTY)
     {
         bool *b = va_arg( args, bool * );
+
+        /* Close the whole sout chain. This will drain every streams, and send
+         * the last data to the chromecast-http sout_access. This sout_access
+         * won't close the http connection but will send an EOF in order to let
+         * the CC download the last remaining data. */
+        if( !p_sys->drained )
+        {
+            p_sys->stopSoutChain( p_stream );
+            p_sys->drained = true;
+        }
+
         /* check if the Chromecast to be done playing */
         *b = p_sys->p_intf->isFinishedPlaying();
         return VLC_SUCCESS;



More information about the vlc-commits mailing list