demux: adaptive: add drain (GET_EMPTY)
authorFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 4 Jul 2016 10:10:06 +0000 (12:10 +0200)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Sat, 9 Jul 2016 11:10:55 +0000 (13:10 +0200)
Required to correctly switch to another period,
as we disable es on period end.

modules/demux/adaptive/PlaylistManager.cpp
modules/demux/adaptive/PlaylistManager.h
modules/demux/adaptive/Streams.cpp
modules/demux/adaptive/Streams.hpp
modules/demux/adaptive/plumbing/FakeESOut.cpp
modules/demux/adaptive/plumbing/FakeESOut.hpp

index 95a27ef..cb05910 100644 (file)
@@ -195,6 +195,30 @@ AbstractStream::status PlaylistManager::demux(mtime_t *pi_nzbarrier, bool send)
     return i_return;
 }
 
+void PlaylistManager::drain()
+{
+    for(;;)
+    {
+        bool b_drained = true;
+        std::vector<AbstractStream *>::iterator it;
+        for(it=streams.begin(); it!=streams.end(); ++it)
+        {
+            AbstractStream *st = *it;
+
+            if (st->isDisabled())
+                continue;
+
+            b_drained &= st->drain();
+        }
+
+        if(b_drained)
+            break;
+
+        msleep(20*1000); /* ugly, but we have no way to get feedback */
+    }
+    es_out_Control(p_demux->out, ES_OUT_RESET_PCR);
+}
+
 mtime_t PlaylistManager::getPCR() const
 {
     mtime_t pcr = VLC_TS_INVALID;
index 2124dba..b059eb9 100644 (file)
@@ -54,6 +54,8 @@ namespace adaptive
             bool    start();
 
             AbstractStream::status demux(mtime_t *, bool);
+            void drain();
+
             virtual bool needsUpdate() const;
             virtual bool updatePlaylist();
             virtual void scheduleNextUpdate();
index d1860e0..03cac14 100644 (file)
@@ -224,6 +224,11 @@ bool AbstractStream::isDisabled() const
     return disabled;
 }
 
+bool AbstractStream::drain()
+{
+    return fakeesout->drain();
+}
+
 AbstractStream::status AbstractStream::demux(mtime_t nz_deadline, bool send)
 {
     /* Ensure it is configured */
@@ -279,10 +284,6 @@ AbstractStream::status AbstractStream::demux(mtime_t nz_deadline, bool send)
                 commandsqueue->setFlush();
                 return AbstractStream::status_buffering;
             }
-
-            commandsqueue->Commit();
-            if(commandsqueue->isEmpty())
-                return AbstractStream::status_eof;
         }
         else if(nz_deadline + VLC_TS_0 > getBufferingLevel()) /* need to read more */
         {
index 73823dc..b3163c2 100644 (file)
@@ -76,6 +76,7 @@ namespace adaptive
                       status_buffering_ahead, /* Special case for live waiting new segments */
                       status_demuxed} status;
         status demux(mtime_t, bool);
+        bool drain();
         virtual bool setPosition(mtime_t, bool);
         mtime_t getPlaybackTime() const;
         void runUpdates();
index bb53dbc..6b77f50 100644 (file)
@@ -237,6 +237,25 @@ bool FakeESOut::hasSelectedEs() const
     return b_selected;
 }
 
+bool FakeESOut::drain()
+{
+    bool b_drained = true;
+    std::list<FakeESOutID *>::const_iterator it;
+    vlc_mutex_lock(&lock);
+    for( it=fakeesidlist.begin(); it!=fakeesidlist.end(); ++it )
+    {
+        FakeESOutID *esID = *it;
+        if( esID->realESID() )
+        {
+            bool b_empty;
+            es_out_Control( real_es_out, ES_OUT_GET_EMPTY, &b_empty );
+            b_drained &= b_empty;
+        }
+    }
+    vlc_mutex_unlock(&lock);
+    return b_drained;
+}
+
 bool FakeESOut::restarting() const
 {
     vlc_mutex_lock(const_cast<vlc_mutex_t *>(&lock));
index d678046..e3ca81b 100644 (file)
@@ -43,6 +43,7 @@ namespace adaptive
             void setTimestampOffset( mtime_t );
             size_t esCount() const;
             bool hasSelectedEs() const;
+            bool drain();
             bool restarting() const;
             void setExtraInfoProvider( ExtraFMTInfoInterface * );