vlc | branch: master | Francois Cartegnie <[email protected]> | Thu May 23 16:38:08 2019 +0200| [ea1838ef6b8401a690b07d4fdd6c3d034496c186] | committer: Francois Cartegnie
demux: adaptive: remove chunk to segment reference & refcounting Only copy all properties so we can prune playlist at will > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ea1838ef6b8401a690b07d4fdd6c3d034496c186 --- modules/demux/adaptive/playlist/Segment.cpp | 22 +++++++++------ modules/demux/adaptive/playlist/Segment.h | 8 ++---- modules/demux/adaptive/playlist/SegmentChunk.cpp | 9 +----- modules/demux/adaptive/playlist/SegmentChunk.hpp | 7 ++--- modules/demux/adaptive/playlist/SegmentList.cpp | 3 -- modules/demux/dash/mpd/DASHSegment.cpp | 33 ++++++++++++++++++---- modules/demux/dash/mpd/DASHSegment.h | 14 +++++++-- modules/demux/hls/playlist/HLSSegment.cpp | 1 - .../demux/smooth/playlist/ForgedInitSegment.cpp | 2 +- modules/demux/smooth/playlist/SmoothSegment.cpp | 30 ++++++++++++++++++-- modules/demux/smooth/playlist/SmoothSegment.hpp | 14 +++++++-- 11 files changed, 98 insertions(+), 45 deletions(-) diff --git a/modules/demux/adaptive/playlist/Segment.cpp b/modules/demux/adaptive/playlist/Segment.cpp index 21b0707286..fee0ffe4dc 100644 --- a/modules/demux/adaptive/playlist/Segment.cpp +++ b/modules/demux/adaptive/playlist/Segment.cpp @@ -51,7 +51,6 @@ ISegment::ISegment(const ICanonicalUrl *parent): classId = CLASSID_ISEGMENT; startTime.Set(0); duration.Set(0); - chunksuse.Set(0); sequence = SEQUENCE_INVALID; templated = false; discontinuity = false; @@ -59,12 +58,6 @@ ISegment::ISegment(const ICanonicalUrl *parent): ISegment::~ISegment() { - assert(chunksuse.Get() == 0); -} - -void ISegment::onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *) -{ - } bool ISegment::prepareChunk(SharedResources *res, SegmentChunk *chunk, BaseRepresentation *rep) @@ -96,9 +89,10 @@ SegmentChunk* ISegment::toChunk(SharedResources *res, AbstractConnectionManager if(startByte != endByte) source->setBytesRange(BytesRange(startByte, endByte)); - SegmentChunk *chunk = new (std::nothrow) SegmentChunk(this, source, rep); + SegmentChunk *chunk = createChunk(source, rep); if(chunk) { + chunk->discontinuity = discontinuity; if(!prepareChunk(res, chunk, rep)) { delete chunk; @@ -203,6 +197,12 @@ Segment::Segment(ICanonicalUrl *parent) : classId = CLASSID_SEGMENT; } +SegmentChunk* Segment::createChunk(AbstractChunkSource *source, BaseRepresentation *rep) +{ + /* act as factory */ + return new (std::nothrow) SegmentChunk(source, rep); +} + void Segment::addSubSegment(SubSegment *subsegment) { if(!subsegments.empty()) @@ -298,6 +298,12 @@ SubSegment::SubSegment(ISegment *main, size_t start, size_t end) : classId = CLASSID_SUBSEGMENT; } +SegmentChunk* SubSegment::createChunk(AbstractChunkSource *source, BaseRepresentation *rep) +{ + /* act as factory */ + return new (std::nothrow) SegmentChunk(source, rep); +} + Url SubSegment::getUrlSegment() const { return getParentUrlSegment(); diff --git a/modules/demux/adaptive/playlist/Segment.h b/modules/demux/adaptive/playlist/Segment.h index 28494ca2b6..10c481f041 100644 --- a/modules/demux/adaptive/playlist/Segment.h +++ b/modules/demux/adaptive/playlist/Segment.h @@ -64,6 +64,7 @@ namespace adaptive */ virtual SegmentChunk* toChunk (SharedResources *, AbstractConnectionManager *, size_t, BaseRepresentation *); + virtual SegmentChunk* createChunk (AbstractChunkSource *, BaseRepresentation *) = 0; virtual void setByteRange (size_t start, size_t end); virtual void setSequenceNumber(uint64_t); virtual uint64_t getSequenceNumber() const; @@ -78,14 +79,9 @@ namespace adaptive int getClassId () const; Property<stime_t> startTime; Property<stime_t> duration; - Property<unsigned> chunksuse; bool discontinuity; static const int CLASSID_ISEGMENT = 0; - /* callbacks */ - virtual void onChunkDownload (block_t **, - SegmentChunk *, - BaseRepresentation *); protected: virtual bool prepareChunk (SharedResources *, @@ -107,6 +103,7 @@ namespace adaptive public: Segment( ICanonicalUrl *parent ); ~Segment(); + virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* impl */ virtual void setSourceUrl( const std::string &url ); virtual Url getUrlSegment() const; /* impl */ virtual std::vector<ISegment*> subSegments(); @@ -138,6 +135,7 @@ namespace adaptive { public: SubSegment(ISegment *, size_t start, size_t end); + virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* impl */ virtual Url getUrlSegment() const; /* impl */ virtual std::vector<ISegment*> subSegments(); virtual void addSubSegment(SubSegment *); diff --git a/modules/demux/adaptive/playlist/SegmentChunk.cpp b/modules/demux/adaptive/playlist/SegmentChunk.cpp index 19ce1d5b74..666a9bef75 100644 --- a/modules/demux/adaptive/playlist/SegmentChunk.cpp +++ b/modules/demux/adaptive/playlist/SegmentChunk.cpp @@ -34,21 +34,15 @@ using namespace adaptive::playlist; using namespace adaptive::encryption; using namespace adaptive; -SegmentChunk::SegmentChunk(ISegment *segment_, AbstractChunkSource *source, - BaseRepresentation *rep_) : +SegmentChunk::SegmentChunk(AbstractChunkSource *source, BaseRepresentation *rep_) : AbstractChunk(source) { - segment = segment_; - segment->chunksuse.Set(segment->chunksuse.Get() + 1); rep = rep_; - discontinuity = segment_->discontinuity; encryptionSession = NULL; } SegmentChunk::~SegmentChunk() { - assert(segment->chunksuse.Get() > 0); - segment->chunksuse.Set(segment->chunksuse.Get() - 1); delete encryptionSession; } @@ -71,7 +65,6 @@ bool SegmentChunk::decrypt(block_t **pp_block) void SegmentChunk::onDownload(block_t **pp_block) { decrypt(pp_block); - segment->onChunkDownload(pp_block, this, rep); } StreamFormat SegmentChunk::getStreamFormat() const diff --git a/modules/demux/adaptive/playlist/SegmentChunk.hpp b/modules/demux/adaptive/playlist/SegmentChunk.hpp index 9807763a79..b4c90ab4db 100644 --- a/modules/demux/adaptive/playlist/SegmentChunk.hpp +++ b/modules/demux/adaptive/playlist/SegmentChunk.hpp @@ -21,7 +21,6 @@ #define SEGMENTCHUNK_HPP #include <string> -#include "ICanonicalUrl.hpp" #include "../http/Chunk.h" #include "../StreamFormat.hpp" @@ -38,12 +37,11 @@ namespace adaptive using namespace encryption; class BaseRepresentation; - class ISegment; class SegmentChunk : public AbstractChunk { public: - SegmentChunk(ISegment *segment, AbstractChunkSource *, BaseRepresentation *); + SegmentChunk(AbstractChunkSource *, BaseRepresentation *); virtual ~SegmentChunk(); void setEncryptionSession(CommonEncryptionSession *); StreamFormat getStreamFormat() const; @@ -51,8 +49,7 @@ namespace adaptive protected: bool decrypt(block_t **); - virtual void onDownload(block_t **); // reimpl - ISegment *segment; + virtual void onDownload(block_t **); /* impl */ BaseRepresentation *rep; CommonEncryptionSession *encryptionSession; }; diff --git a/modules/demux/adaptive/playlist/SegmentList.cpp b/modules/demux/adaptive/playlist/SegmentList.cpp index b359ff7753..4813425c7e 100644 --- a/modules/demux/adaptive/playlist/SegmentList.cpp +++ b/modules/demux/adaptive/playlist/SegmentList.cpp @@ -118,9 +118,6 @@ void SegmentList::pruneBySegmentNumber(uint64_t tobelownum) if(seg->getSequenceNumber() >= tobelownum) break; - if(seg->chunksuse.Get()) /* can't prune from here, still in use */ - break; - delete *it; it = segments.erase(it); } diff --git a/modules/demux/dash/mpd/DASHSegment.cpp b/modules/demux/dash/mpd/DASHSegment.cpp index c21b201e0d..455cf9132d 100644 --- a/modules/demux/dash/mpd/DASHSegment.cpp +++ b/modules/demux/dash/mpd/DASHSegment.cpp @@ -30,22 +30,45 @@ #include "../adaptive/playlist/BaseRepresentation.h" #include "../mp4/IndexReader.hpp" #include "../adaptive/playlist/AbstractPlaylist.hpp" -#include "../adaptive/playlist/SegmentChunk.hpp" using namespace adaptive::playlist; using namespace dash::mpd; using namespace dash::mp4; -DashIndexSegment::DashIndexSegment(ICanonicalUrl *parent) : - IndexSegment(parent) +DashIndexChunk::DashIndexChunk(AbstractChunkSource *source, BaseRepresentation *rep) + : SegmentChunk(source, rep) +{ + +} + +DashIndexChunk::~DashIndexChunk() { + } -void DashIndexSegment::onChunkDownload(block_t **pp_block, SegmentChunk *p_chunk, BaseRepresentation *rep) +void DashIndexChunk::onDownload(block_t **pp_block) { + decrypt(pp_block); + if(!rep || ((*pp_block)->i_flags & BLOCK_FLAG_HEADER) == 0 ) return; IndexReader br(rep->getPlaylist()->getVLCObject()); - br.parseIndex(*pp_block, rep, p_chunk->getStartByteInFile()); + br.parseIndex(*pp_block, rep, getStartByteInFile()); +} + +DashIndexSegment::DashIndexSegment(ICanonicalUrl *parent) : + IndexSegment(parent) +{ +} + +DashIndexSegment::~DashIndexSegment() +{ + +} + +SegmentChunk* DashIndexSegment::createChunk(AbstractChunkSource *source, BaseRepresentation *rep) +{ + /* act as factory */ + return new (std::nothrow) DashIndexChunk(source, rep); } diff --git a/modules/demux/dash/mpd/DASHSegment.h b/modules/demux/dash/mpd/DASHSegment.h index 70a2d21aed..5aa21db9d3 100644 --- a/modules/demux/dash/mpd/DASHSegment.h +++ b/modules/demux/dash/mpd/DASHSegment.h @@ -26,6 +26,7 @@ #define DASHSEGMENT_H_ #include "../adaptive/playlist/Segment.h" +#include "../adaptive/playlist/SegmentChunk.hpp" namespace dash { @@ -34,13 +35,20 @@ namespace dash using namespace adaptive::playlist; using namespace adaptive::http; + class DashIndexChunk : public SegmentChunk + { + public: + DashIndexChunk(AbstractChunkSource *, BaseRepresentation *); + ~DashIndexChunk(); + virtual void onDownload(block_t **); /* reimpl */ + }; + class DashIndexSegment : public IndexSegment { public: DashIndexSegment( ICanonicalUrl *parent ); - - protected: - virtual void onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *); //reimpl + ~DashIndexSegment(); + virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* reimpl */ }; } diff --git a/modules/demux/hls/playlist/HLSSegment.cpp b/modules/demux/hls/playlist/HLSSegment.cpp index 9b3f671851..6f7c13e7d1 100644 --- a/modules/demux/hls/playlist/HLSSegment.cpp +++ b/modules/demux/hls/playlist/HLSSegment.cpp @@ -22,7 +22,6 @@ #endif #include "HLSSegment.hpp" -#include "../adaptive/playlist/SegmentChunk.hpp" #include "../adaptive/playlist/BaseRepresentation.h" diff --git a/modules/demux/smooth/playlist/ForgedInitSegment.cpp b/modules/demux/smooth/playlist/ForgedInitSegment.cpp index cbd364fde9..4a7c2d3857 100644 --- a/modules/demux/smooth/playlist/ForgedInitSegment.cpp +++ b/modules/demux/smooth/playlist/ForgedInitSegment.cpp @@ -327,7 +327,7 @@ SegmentChunk* ForgedInitSegment::toChunk(SharedResources *, AbstractConnectionMa MemoryChunkSource *source = new (std::nothrow) MemoryChunkSource(moov); if( source ) { - SegmentChunk *chunk = new (std::nothrow) SegmentChunk(this, source, rep); + SegmentChunk *chunk = new (std::nothrow) SegmentChunk(source, rep); if( chunk ) return chunk; else diff --git a/modules/demux/smooth/playlist/SmoothSegment.cpp b/modules/demux/smooth/playlist/SmoothSegment.cpp index 186258b3a9..24d0665199 100644 --- a/modules/demux/smooth/playlist/SmoothSegment.cpp +++ b/modules/demux/smooth/playlist/SmoothSegment.cpp @@ -30,17 +30,41 @@ using namespace smooth::playlist; using namespace smooth::mp4; -SmoothSegment::SmoothSegment(SegmentInformation *parent) : - MediaSegmentTemplate( parent ) +SmoothSegmentChunk::SmoothSegmentChunk(AbstractChunkSource *source, BaseRepresentation *rep) + : SegmentChunk(source, rep) +{ + +} + +SmoothSegmentChunk::~SmoothSegmentChunk() { } -void SmoothSegment::onChunkDownload(block_t **pp_block, SegmentChunk *, BaseRepresentation *rep) +void SmoothSegmentChunk::onDownload(block_t **pp_block) { + decrypt(pp_block); + if(!rep || ((*pp_block)->i_flags & BLOCK_FLAG_HEADER) == 0) return; IndexReader br(rep->getPlaylist()->getVLCObject()); br.parseIndex(*pp_block, rep); } + +SmoothSegment::SmoothSegment(SegmentInformation *parent) : + MediaSegmentTemplate( parent ) +{ + +} + +SmoothSegment::~SmoothSegment() +{ + +} + +SegmentChunk* SmoothSegment::createChunk(AbstractChunkSource *source, BaseRepresentation *rep) +{ + /* act as factory */ + return new (std::nothrow) SmoothSegmentChunk(source, rep); +} diff --git a/modules/demux/smooth/playlist/SmoothSegment.hpp b/modules/demux/smooth/playlist/SmoothSegment.hpp index 307d8fdf31..8fb9f91cdc 100644 --- a/modules/demux/smooth/playlist/SmoothSegment.hpp +++ b/modules/demux/smooth/playlist/SmoothSegment.hpp @@ -21,6 +21,7 @@ #define SMOOTHSEGMENT_HPP #include "../adaptive/playlist/SegmentTemplate.h" +#include "../adaptive/playlist/SegmentChunk.hpp" namespace smooth { @@ -28,13 +29,20 @@ namespace smooth { using namespace adaptive::playlist; + class SmoothSegmentChunk : public SegmentChunk + { + public: + SmoothSegmentChunk(AbstractChunkSource *, BaseRepresentation *); + ~SmoothSegmentChunk(); + virtual void onDownload(block_t **); /* reimpl */ + }; + class SmoothSegment : public MediaSegmentTemplate { public: SmoothSegment(SegmentInformation * = NULL); - - protected: - virtual void onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *); //reimpl + ~SmoothSegment(); + virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* reimpl */ }; } } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
