[vlc-commits] demux: adaptive: add buffering target info

Francois Cartegnie git at videolan.org
Thu Mar 4 15:38:26 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Feb 27 16:50:05 2021 +0100| [f2e76681111e82d84c616b6a7c1a718583d89b2c] | committer: Francois Cartegnie

demux: adaptive: add buffering target info

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

 modules/demux/adaptive/PlaylistManager.cpp           | 13 +++++++++----
 modules/demux/adaptive/PlaylistManager.h             |  3 ++-
 modules/demux/adaptive/SegmentTracker.cpp            |  9 ++++++---
 modules/demux/adaptive/SegmentTracker.hpp            |  6 ++++--
 modules/demux/adaptive/Streams.cpp                   | 19 ++++++++++---------
 modules/demux/adaptive/Streams.hpp                   |  6 ++++--
 modules/demux/adaptive/logic/BufferingLogic.cpp      | 11 +++++++++++
 modules/demux/adaptive/logic/BufferingLogic.hpp      |  2 ++
 modules/demux/adaptive/test/logic/BufferingLogic.cpp |  2 ++
 9 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index 4d72342388..cc5106d013 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -215,7 +215,9 @@ static bool streamCompare(const PrioritizedAbstractStream &a,  const Prioritized
 }
 
 AbstractStream::BufferingStatus PlaylistManager::bufferize(vlc_tick_t i_nzdeadline,
-                                                            vlc_tick_t i_min_buffering, vlc_tick_t i_extra_buffering)
+                                                           vlc_tick_t i_min_buffering,
+                                                           vlc_tick_t i_max_buffering,
+                                                           vlc_tick_t i_target_buffering)
 {
     AbstractStream::BufferingStatus i_return = AbstractStream::BufferingStatus::End;
 
@@ -252,7 +254,8 @@ AbstractStream::BufferingStatus PlaylistManager::bufferize(vlc_tick_t i_nzdeadli
 
         AbstractStream::BufferingStatus i_ret = st->bufferize(i_nzdeadline,
                                                                i_min_buffering,
-                                                               i_extra_buffering,
+                                                               i_max_buffering,
+                                                               i_target_buffering,
                                                                getActiveStreamsCount() <= 1);
         if(i_return != AbstractStream::BufferingStatus::Ongoing) /* Buffering streams need to keep going */
         {
@@ -655,7 +658,8 @@ void PlaylistManager::Run()
 {
     mutex_locker locker {lock};
     const vlc_tick_t i_min_buffering = bufferingLogic->getMinBuffering(playlist);
-    const vlc_tick_t i_extra_buffering = bufferingLogic->getMaxBuffering(playlist) - i_min_buffering;
+    const vlc_tick_t i_max_buffering = bufferingLogic->getMaxBuffering(playlist);
+    const vlc_tick_t i_target_buffering = bufferingLogic->getStableBuffering(playlist);
     while(1)
     {
         while(!b_buffering && !b_canceled)
@@ -675,7 +679,8 @@ void PlaylistManager::Run()
         vlc_tick_t i_nzpcr = demux.i_nzpcr;
         vlc_mutex_unlock(&demux.lock);
 
-        AbstractStream::BufferingStatus i_return = bufferize(i_nzpcr, i_min_buffering, i_extra_buffering);
+        AbstractStream::BufferingStatus i_return = bufferize(i_nzpcr, i_min_buffering,
+                                                             i_max_buffering, i_target_buffering);
 
         if(i_return != AbstractStream::BufferingStatus::Lessthanmin)
         {
diff --git a/modules/demux/adaptive/PlaylistManager.h b/modules/demux/adaptive/PlaylistManager.h
index 3de091a5f5..5ed5899e28 100644
--- a/modules/demux/adaptive/PlaylistManager.h
+++ b/modules/demux/adaptive/PlaylistManager.h
@@ -59,7 +59,8 @@ namespace adaptive
             bool    started() const;
             void    stop();
 
-            AbstractStream::BufferingStatus bufferize(vlc_tick_t, vlc_tick_t, vlc_tick_t);
+            AbstractStream::BufferingStatus bufferize(vlc_tick_t, vlc_tick_t,
+                                                      vlc_tick_t, vlc_tick_t);
             AbstractStream::Status dequeue(vlc_tick_t, vlc_tick_t *);
 
             virtual bool needsUpdate() const;
diff --git a/modules/demux/adaptive/SegmentTracker.cpp b/modules/demux/adaptive/SegmentTracker.cpp
index 84c4f257d8..35853c1d56 100644
--- a/modules/demux/adaptive/SegmentTracker.cpp
+++ b/modules/demux/adaptive/SegmentTracker.cpp
@@ -87,12 +87,14 @@ BufferingStateUpdatedEvent::BufferingStateUpdatedEvent(const ID &id, bool enable
     this->enabled = enabled;
 }
 
-BufferingLevelChangedEvent::BufferingLevelChangedEvent(const ID &id, vlc_tick_t minimum,
+BufferingLevelChangedEvent::BufferingLevelChangedEvent(const ID &id,
+                                                       vlc_tick_t minimum, vlc_tick_t maximum,
                                                        vlc_tick_t current, vlc_tick_t target)
     : TrackerEvent(Type::BufferingLevelChange)
 {
     this->id = &id;
     this->minimum = minimum;
+    this->maximum = maximum;
     this->current = current;
     this->target = target;
 }
@@ -481,9 +483,10 @@ void SegmentTracker::notifyBufferingState(bool enabled) const
     notify(BufferingStateUpdatedEvent(adaptationSet->getID(), enabled));
 }
 
-void SegmentTracker::notifyBufferingLevel(vlc_tick_t min, vlc_tick_t current, vlc_tick_t target) const
+void SegmentTracker::notifyBufferingLevel(vlc_tick_t min, vlc_tick_t max,
+                                          vlc_tick_t current, vlc_tick_t target) const
 {
-    notify(BufferingLevelChangedEvent(adaptationSet->getID(), min, current, target));
+    notify(BufferingLevelChangedEvent(adaptationSet->getID(), min, max, current, target));
 }
 
 void SegmentTracker::registerListener(SegmentTrackerListenerInterface *listener)
diff --git a/modules/demux/adaptive/SegmentTracker.hpp b/modules/demux/adaptive/SegmentTracker.hpp
index 3171e7ccf9..4dde71cdc6 100644
--- a/modules/demux/adaptive/SegmentTracker.hpp
+++ b/modules/demux/adaptive/SegmentTracker.hpp
@@ -132,11 +132,13 @@ namespace adaptive
     {
         public:
             BufferingLevelChangedEvent() = delete;
-            BufferingLevelChangedEvent(const ID &, vlc_tick_t, vlc_tick_t, vlc_tick_t);
+            BufferingLevelChangedEvent(const ID &,
+                                       vlc_tick_t, vlc_tick_t, vlc_tick_t, vlc_tick_t);
             virtual ~BufferingLevelChangedEvent() = default;
 
             const ID *id;
             vlc_tick_t minimum;
+            vlc_tick_t maximum;
             vlc_tick_t current;
             vlc_tick_t target;
     };
@@ -191,7 +193,7 @@ namespace adaptive
             bool getMediaPlaybackRange(vlc_tick_t *, vlc_tick_t *, vlc_tick_t *) const;
             vlc_tick_t getMinAheadTime() const;
             void notifyBufferingState(bool) const;
-            void notifyBufferingLevel(vlc_tick_t, vlc_tick_t, vlc_tick_t) const;
+            void notifyBufferingLevel(vlc_tick_t, vlc_tick_t, vlc_tick_t, vlc_tick_t) const;
             void registerListener(SegmentTrackerListenerInterface *);
             void updateSelected();
             bool bufferingAvailable() const;
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 88dcb3b929..01f3effc66 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -344,15 +344,18 @@ vlc_tick_t AbstractStream::getDemuxedAmount(vlc_tick_t from) const
 AbstractStream::BufferingStatus AbstractStream::bufferize(vlc_tick_t nz_deadline,
                                                            vlc_tick_t i_min_buffering,
                                                            vlc_tick_t i_extra_buffering,
+                                                           vlc_tick_t i_target_buffering,
                                                            bool b_keep_alive)
 {
-    last_buffer_status = doBufferize(nz_deadline, i_min_buffering, i_extra_buffering, b_keep_alive);
+    last_buffer_status = doBufferize(nz_deadline, i_min_buffering, i_extra_buffering,
+                                     i_target_buffering, b_keep_alive);
     return last_buffer_status;
 }
 
 AbstractStream::BufferingStatus AbstractStream::doBufferize(vlc_tick_t nz_deadline,
                                                              vlc_tick_t i_min_buffering,
-                                                             vlc_tick_t i_extra_buffering,
+                                                             vlc_tick_t i_max_buffering,
+                                                             vlc_tick_t i_target_buffering,
                                                              bool b_keep_alive)
 {
     vlc_mutex_lock(&lock);
@@ -413,14 +416,12 @@ AbstractStream::BufferingStatus AbstractStream::doBufferize(vlc_tick_t nz_deadli
         }
     }
 
-    const vlc_tick_t i_total_buffering = i_min_buffering + i_extra_buffering;
-
     vlc_tick_t i_demuxed = fakeEsOut()->commandsQueue()->getDemuxedAmount(nz_deadline);
-    segmentTracker->notifyBufferingLevel(i_min_buffering, i_demuxed, i_total_buffering);
-    if(i_demuxed < i_total_buffering) /* not already demuxed */
+    segmentTracker->notifyBufferingLevel(i_min_buffering, i_max_buffering, i_demuxed, i_target_buffering);
+    if(i_demuxed < i_max_buffering) /* not already demuxed */
     {
         vlc_tick_t nz_extdeadline = fakeEsOut()->commandsQueue()->getBufferingLevel() +
-                                    (i_total_buffering - i_demuxed) / 4;
+                                    (i_max_buffering - i_demuxed) / 4;
         nz_deadline = std::max(nz_deadline, nz_extdeadline);
 
         /* need to read, demuxer still buffering, ... */
@@ -448,11 +449,11 @@ AbstractStream::BufferingStatus AbstractStream::doBufferize(vlc_tick_t nz_deadli
             return BufferingStatus::End;
         }
         i_demuxed = fakeEsOut()->commandsQueue()->getDemuxedAmount(nz_deadline);
-        segmentTracker->notifyBufferingLevel(i_min_buffering, i_demuxed, i_total_buffering);
+        segmentTracker->notifyBufferingLevel(i_min_buffering, i_max_buffering, i_demuxed, i_target_buffering);
     }
     vlc_mutex_unlock(&lock);
 
-    if(i_demuxed < i_total_buffering) /* need to read more */
+    if(i_demuxed < i_max_buffering) /* need to read more */
     {
         if(i_demuxed < i_min_buffering)
             return BufferingStatus::Lessthanmin; /* high prio */
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index 325c65c036..2e5cf214e3 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -83,7 +83,8 @@ namespace adaptive
             Ongoing,
             Lessthanmin,
         };
-        BufferingStatus bufferize(vlc_tick_t, vlc_tick_t, vlc_tick_t, bool = false);
+        BufferingStatus bufferize(vlc_tick_t, vlc_tick_t, vlc_tick_t,
+                                  vlc_tick_t, bool = false);
         BufferingStatus getLastBufferStatus() const;
         vlc_tick_t getDemuxedAmount(vlc_tick_t) const;
         Status dequeue(vlc_tick_t, vlc_tick_t *);
@@ -139,7 +140,8 @@ namespace adaptive
 
     private:
         void declaredCodecs();
-        BufferingStatus doBufferize(vlc_tick_t, vlc_tick_t, vlc_tick_t, bool);
+        BufferingStatus doBufferize(vlc_tick_t, vlc_tick_t, vlc_tick_t,
+                                    vlc_tick_t, bool);
         BufferingStatus last_buffer_status;
         bool valid;
         bool disabled;
diff --git a/modules/demux/adaptive/logic/BufferingLogic.cpp b/modules/demux/adaptive/logic/BufferingLogic.cpp
index a1041ad2db..f4b713d80e 100644
--- a/modules/demux/adaptive/logic/BufferingLogic.cpp
+++ b/modules/demux/adaptive/logic/BufferingLogic.cpp
@@ -129,6 +129,17 @@ vlc_tick_t DefaultBufferingLogic::getLiveDelay(const BasePlaylist *p) const
     return std::max(delay, getMinBuffering(p));
 }
 
+vlc_tick_t DefaultBufferingLogic::getStableBuffering(const BasePlaylist *p) const
+{
+    vlc_tick_t min = getMinBuffering(p);
+    if(isLowLatency(p))
+        return min;
+    if(p->isLive())
+        return std::max(min, getLiveDelay(p) * 6/10);
+    vlc_tick_t max = getMaxBuffering(p);
+    return std::min(getMinBuffering(p) * 2, max);
+}
+
 uint64_t DefaultBufferingLogic::getLiveStartSegmentNumber(BaseRepresentation *rep) const
 {
     BasePlaylist *playlist = rep->getPlaylist();
diff --git a/modules/demux/adaptive/logic/BufferingLogic.hpp b/modules/demux/adaptive/logic/BufferingLogic.hpp
index 56d9d81232..280417ee32 100644
--- a/modules/demux/adaptive/logic/BufferingLogic.hpp
+++ b/modules/demux/adaptive/logic/BufferingLogic.hpp
@@ -46,6 +46,7 @@ namespace adaptive
                 virtual vlc_tick_t getMinBuffering(const BasePlaylist *) const = 0;
                 virtual vlc_tick_t getMaxBuffering(const BasePlaylist *) const = 0;
                 virtual vlc_tick_t getLiveDelay(const BasePlaylist *) const = 0;
+                virtual vlc_tick_t getStableBuffering(const BasePlaylist *) const = 0;
                 void setUserMinBuffering(vlc_tick_t);
                 void setUserMaxBuffering(vlc_tick_t);
                 void setUserLiveDelay(vlc_tick_t);
@@ -71,6 +72,7 @@ namespace adaptive
                 virtual vlc_tick_t getMinBuffering(const BasePlaylist *) const override;
                 virtual vlc_tick_t getMaxBuffering(const BasePlaylist *) const override;
                 virtual vlc_tick_t getLiveDelay(const BasePlaylist *) const override;
+                virtual vlc_tick_t getStableBuffering(const BasePlaylist *) const override;
                 static const unsigned SAFETY_BUFFERING_EDGE_OFFSET;
                 static const unsigned SAFETY_EXPURGING_OFFSET;
 
diff --git a/modules/demux/adaptive/test/logic/BufferingLogic.cpp b/modules/demux/adaptive/test/logic/BufferingLogic.cpp
index 12bbdca744..00175873ed 100644
--- a/modules/demux/adaptive/test/logic/BufferingLogic.cpp
+++ b/modules/demux/adaptive/test/logic/BufferingLogic.cpp
@@ -107,6 +107,8 @@ int BufferingLogic_test()
         Expect(bufferinglogic.getStartSegmentNumber(rep) == number);
         Expect(bufferinglogic.getMinBuffering(playlist) == DefaultBufferingLogic::DEFAULT_MIN_BUFFERING);
         Expect(bufferinglogic.getMaxBuffering(playlist) == DefaultBufferingLogic::DEFAULT_MAX_BUFFERING);
+        Expect(bufferinglogic.getStableBuffering(playlist) <= bufferinglogic.getMaxBuffering(playlist));
+        Expect(bufferinglogic.getStableBuffering(playlist) >= bufferinglogic.getMinBuffering(playlist));
 
         bufferinglogic.setUserMinBuffering(DefaultBufferingLogic::DEFAULT_MIN_BUFFERING / 2);
         Expect(bufferinglogic.getMinBuffering(playlist) == std::max(DefaultBufferingLogic::DEFAULT_MIN_BUFFERING / 2,



More information about the vlc-commits mailing list