[vlc-commits] demux: adaptive: simplify first pcr handling

Francois Cartegnie git at videolan.org
Sat Jul 9 18:42:45 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul  7 19:42:40 2016 +0200| [40608ad1d8d90598bdc8d5bdcfbbb4dfd1a5a697] | committer: Francois Cartegnie

demux: adaptive: simplify first pcr handling

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

 modules/demux/adaptive/PlaylistManager.cpp        |   28 ++++++++++-----------
 modules/demux/adaptive/Streams.cpp                |   20 +++++++++++++--
 modules/demux/adaptive/plumbing/CommandsQueue.cpp |   10 +++++---
 3 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index f2b822b..ef8375e 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -208,8 +208,6 @@ AbstractStream::buffering_status PlaylistManager::bufferize(mtime_t i_nzdeadline
        i_return != AbstractStream::buffering_lessthanmin /* prevents starting before buffering is reached */ )
     {
         demux.i_nzpcr = getFirstDTS();
-        if(demux.i_nzpcr == VLC_TS_INVALID)
-            demux.i_nzpcr = getPCR();
     }
     vlc_mutex_unlock(&demux.lock);
 
@@ -265,30 +263,32 @@ void PlaylistManager::drain()
 
 mtime_t PlaylistManager::getPCR() const
 {
-    mtime_t pcr = VLC_TS_INVALID;
+    mtime_t minpcr = VLC_TS_INVALID;
     std::vector<AbstractStream *>::const_iterator it;
     for(it=streams.begin(); it!=streams.end(); ++it)
     {
-        if ((*it)->isDisabled() || (*it)->isDead())
-            continue;
-        if(pcr == VLC_TS_INVALID || pcr > (*it)->getPCR())
-            pcr = (*it)->getPCR();
+        const mtime_t pcr = (*it)->getPCR();
+        if(minpcr == VLC_TS_INVALID)
+            minpcr = pcr;
+        else if(pcr > VLC_TS_INVALID)
+            minpcr = std::min(minpcr, pcr);
     }
-    return pcr;
+    return minpcr;
 }
 
 mtime_t PlaylistManager::getFirstDTS() const
 {
-    mtime_t dts = VLC_TS_INVALID;
+    mtime_t mindts = VLC_TS_INVALID;
     std::vector<AbstractStream *>::const_iterator it;
     for(it=streams.begin(); it!=streams.end(); ++it)
     {
-        if ((*it)->isDisabled() || (*it)->isDead())
-            continue;
-        if(dts == VLC_TS_INVALID || dts > (*it)->getFirstDTS())
-            dts = (*it)->getFirstDTS();
+        const mtime_t dts = (*it)->getFirstDTS();
+        if(mindts == VLC_TS_INVALID)
+            mindts = dts;
+        else if(dts > VLC_TS_INVALID)
+            mindts = std::min(mindts, dts);
     }
-    return dts;
+    return mindts;
 }
 
 mtime_t PlaylistManager::getDuration() const
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index e593af7..9fa986e 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -140,7 +140,10 @@ bool AbstractStream::isDead() const
 
 mtime_t AbstractStream::getPCR() const
 {
-    return commandsqueue->getPCR();
+    vlc_mutex_lock(const_cast<vlc_mutex_t *>(&lock));
+    mtime_t pcr = (dead || disabled) ? VLC_TS_INVALID : commandsqueue->getPCR();
+    vlc_mutex_unlock(const_cast<vlc_mutex_t *>(&lock));
+    return pcr;
 }
 
 mtime_t AbstractStream::getMinAheadTime() const
@@ -152,7 +155,20 @@ mtime_t AbstractStream::getMinAheadTime() const
 
 mtime_t AbstractStream::getFirstDTS() const
 {
-    return commandsqueue->getFirstDTS();
+    mtime_t dts;
+    vlc_mutex_lock(const_cast<vlc_mutex_t *>(&lock));
+    if(dead || disabled)
+    {
+        dts = VLC_TS_INVALID;
+    }
+    else
+    {
+        dts = commandsqueue->getFirstDTS();
+        if(dts == VLC_TS_INVALID)
+            dts = commandsqueue->getPCR();
+    }
+    vlc_mutex_unlock(const_cast<vlc_mutex_t *>(&lock));
+    return dts;
 }
 
 int AbstractStream::esCount() const
diff --git a/modules/demux/adaptive/plumbing/CommandsQueue.cpp b/modules/demux/adaptive/plumbing/CommandsQueue.cpp
index 8b74e6c..140bc6a 100644
--- a/modules/demux/adaptive/plumbing/CommandsQueue.cpp
+++ b/modules/demux/adaptive/plumbing/CommandsQueue.cpp
@@ -376,19 +376,21 @@ mtime_t CommandsQueue::getBufferingLevel() const
 
 mtime_t CommandsQueue::getFirstDTS() const
 {
-    mtime_t i_dts = VLC_TS_INVALID;
     std::list<AbstractCommand *>::const_iterator it;
     vlc_mutex_lock(const_cast<vlc_mutex_t *>(&lock));
+    mtime_t i_firstdts = pcr;
     for( it = commands.begin(); it != commands.end(); ++it )
     {
-        if( (*it)->getTime() > VLC_TS_INVALID )
+        const mtime_t i_dts = (*it)->getTime();
+        if( i_dts > VLC_TS_INVALID )
         {
-            i_dts = (*it)->getTime();
+            if( i_dts < i_firstdts || i_firstdts == VLC_TS_INVALID )
+                i_firstdts = i_dts;
             break;
         }
     }
     vlc_mutex_unlock(const_cast<vlc_mutex_t *>(&lock));
-    return i_dts;
+    return i_firstdts;
 }
 
 mtime_t CommandsQueue::getPCR() const



More information about the vlc-commits mailing list