[vlc-commits] demux: adaptive: enable start without probing all alternatives
Francois Cartegnie
git at videolan.org
Mon Mar 30 16:15:46 CEST 2020
vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Apr 29 17:26:12 2019 +0200| [228caf88a400970549a47113fb6d68d8b65962a6] | committer: Francois Cartegnie
demux: adaptive: enable start without probing all alternatives
(cherry picked from commit 6ae1fd2d0e37b02bc132857ee3f82eab3a8147f7)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=228caf88a400970549a47113fb6d68d8b65962a6
---
modules/demux/adaptive/PlaylistManager.cpp | 13 +++++++---
modules/demux/adaptive/SegmentTracker.cpp | 29 ++++++++++++++++++++++
modules/demux/adaptive/SegmentTracker.hpp | 3 +++
modules/demux/adaptive/Streams.cpp | 40 ++++++++++++++++++++++++++----
modules/demux/adaptive/Streams.hpp | 3 ++-
5 files changed, 79 insertions(+), 9 deletions(-)
diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index 5f979f2493..bf4f8aba25 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -243,9 +243,16 @@ AbstractStream::buffering_status PlaylistManager::bufferize(mtime_t i_nzdeadline
if(!st->isValid())
continue;
- if (st->isDisabled() &&
- (!st->isSelected() || !reactivateStream(st)))
- continue;
+ if(st->esCount())
+ {
+ if (st->isDisabled() &&
+ (!st->isSelected() || !reactivateStream(st)))
+ continue;
+ }
+ else
+ {
+ /* initial */
+ }
AbstractStream::buffering_status i_ret = st->bufferize(i_nzdeadline, i_min_buffering, i_extra_buffering);
if(i_return != AbstractStream::buffering_ongoing) /* Buffering streams need to keep going */
diff --git a/modules/demux/adaptive/SegmentTracker.cpp b/modules/demux/adaptive/SegmentTracker.cpp
index ed06443f3f..a342fc577c 100644
--- a/modules/demux/adaptive/SegmentTracker.cpp
+++ b/modules/demux/adaptive/SegmentTracker.cpp
@@ -117,6 +117,26 @@ StreamFormat SegmentTracker::getCurrentFormat() const
return StreamFormat();
}
+std::list<std::string> SegmentTracker::getCurrentCodecs() const
+{
+ BaseRepresentation *rep = curRepresentation;
+ if(!rep)
+ rep = logic->getNextRepresentation(adaptationSet, NULL);
+ if(rep)
+ return rep->getCodecs();
+ return std::list<std::string>();
+}
+
+const std::string & SegmentTracker::getStreamDescription() const
+{
+ return adaptationSet->description.Get();
+}
+
+const std::string & SegmentTracker::getStreamLanguage() const
+{
+ return adaptationSet->getLang();
+}
+
const Role & SegmentTracker::getStreamRole() const
{
return adaptationSet->getRole();
@@ -299,6 +319,15 @@ bool SegmentTracker::setPositionByTime(mtime_t time, bool restarted, bool tryonl
if(!rep)
rep = logic->getNextRepresentation(adaptationSet, NULL);
+ /* Stream might not have been loaded at all (HLS) or expired */
+ if(rep && rep->needsUpdate() &&
+ !rep->runLocalUpdates(resources, time, curNumber, false))
+ {
+ msg_Err(rep->getAdaptationSet()->getPlaylist()->getVLCObject(),
+ "Failed to update Representation %s", rep->getID().str().c_str());
+ return false;
+ }
+
if(rep &&
rep->getSegmentNumberByTime(time, &segnumber))
{
diff --git a/modules/demux/adaptive/SegmentTracker.hpp b/modules/demux/adaptive/SegmentTracker.hpp
index f7c691731e..3beb770d4a 100644
--- a/modules/demux/adaptive/SegmentTracker.hpp
+++ b/modules/demux/adaptive/SegmentTracker.hpp
@@ -119,6 +119,9 @@ namespace adaptive
~SegmentTracker();
StreamFormat getCurrentFormat() const;
+ std::list<std::string> getCurrentCodecs() const;
+ const std::string & getStreamDescription() const;
+ const std::string & getStreamLanguage() const;
const Role & getStreamRole() const;
bool segmentsListReady() const;
void reset();
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 869baf67c3..c00cf67a15 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -31,6 +31,7 @@
#include "playlist/SegmentChunk.hpp"
#include "plumbing/SourceStream.hpp"
#include "plumbing/CommandsQueue.hpp"
+#include "tools/FormatNamespace.hpp"
#include "tools/Debug.hpp"
#include <vlc_demux.h>
@@ -88,6 +89,8 @@ bool AbstractStream::init(const StreamFormat &format_, SegmentTracker *tracker,
segmentTracker->registerListener(this);
segmentTracker->notifyBufferingState(true);
connManager = conn;
+ setTimeOffset(segmentTracker->getPlaybackTime());
+ declaredCodecs();
return true;
}
delete commandsqueue;
@@ -191,7 +194,7 @@ bool AbstractStream::seekAble() const
"discontinuity %d, commandsqueue draining %d, commandsqueue eof %d",
static_cast<void *>(demuxer), restarting, discontinuity, draining, eof);
- if(!demuxer || restarting || discontinuity || (!eof && draining))
+ if(!valid || restarting || discontinuity || (!eof && draining))
{
msg_Warn(p_realdemux, "not seekable");
return false;
@@ -240,6 +243,7 @@ bool AbstractStream::restartDemux()
bool b_ret = true;
if(!demuxer)
{
+ fakeesout->recycleAll();
b_ret = startDemux();
}
else if(demuxer->needsRestartOnSeek())
@@ -301,7 +305,7 @@ AbstractStream::buffering_status AbstractStream::bufferize(mtime_t nz_deadline,
}
AbstractStream::buffering_status AbstractStream::doBufferize(mtime_t nz_deadline,
- unsigned i_min_buffering, unsigned i_extra_buffering)
+ mtime_t i_min_buffering, mtime_t i_extra_buffering)
{
vlc_mutex_lock(&lock);
@@ -506,12 +510,13 @@ bool AbstractStream::setPosition(mtime_t time, bool tryonly)
if(!seekAble())
return false;
- bool ret = segmentTracker->setPositionByTime(time, demuxer->needsRestartOnSeek(), tryonly);
+ bool b_needs_restart = demuxer ? demuxer->needsRestartOnSeek() : true;
+ bool ret = segmentTracker->setPositionByTime(time, b_needs_restart, tryonly);
if(!tryonly && ret)
{
// clear eof flag before restartDemux() to prevent readNextBlock() fail
eof = false;
- if(demuxer->needsRestartOnSeek())
+ if(b_needs_restart)
{
if(currentChunk)
delete currentChunk;
@@ -568,7 +573,7 @@ void AbstractStream::setTimeOffset(mtime_t i_offset)
{
fakeEsOut()->setExpectedTimestampOffset(0);
}
- else if(demuxer)
+ else
{
fakeEsOut()->setExpectedTimestampOffset(i_offset);
}
@@ -653,6 +658,31 @@ void AbstractStream::trackerEvent(const SegmentTrackerEvent &event)
}
}
+void AbstractStream::declaredCodecs()
+{
+ const std::string & streamDesc = segmentTracker->getStreamDescription();
+ const std::string & streamLang = segmentTracker->getStreamLanguage();
+ std::list<std::string> codecs = segmentTracker->getCurrentCodecs();
+ for(std::list<std::string>::const_iterator it = codecs.begin();
+ it != codecs.end(); ++it)
+ {
+ FormatNamespace fnsp(*it);
+
+ es_format_t fmt;
+ es_format_Init(&fmt, fnsp.getFmt()->i_cat, fnsp.getFmt()->i_codec);
+ es_format_Copy(&fmt, fnsp.getFmt());
+
+ if(!streamLang.empty())
+ fmt.psz_language = strdup(streamLang.c_str());
+ if(!streamDesc.empty())
+ fmt.psz_description = strdup(streamDesc.c_str());
+
+ fakeEsOut()->declareEs( &fmt );
+
+ es_format_Clean(&fmt);
+ }
+}
+
FakeESOut::LockedFakeEsOut AbstractStream::fakeEsOut()
{
return fakeesout->WithLock();
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index a9e37dc0dc..76d40f5701 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -135,7 +135,8 @@ namespace adaptive
vlc_mutex_t lock; /* lock for everything accessed by dequeuing */
private:
- buffering_status doBufferize(mtime_t, unsigned, unsigned);
+ void declaredCodecs();
+ buffering_status doBufferize(mtime_t, mtime_t, mtime_t);
buffering_status last_buffer_status;
bool valid;
bool disabled;
More information about the vlc-commits
mailing list