From b405f991a6be35d09cd03258a33ea417f3035ede Mon Sep 17 00:00:00 2001 From: peak3d Date: Thu, 17 Aug 2017 23:32:26 +0200 Subject: [PATCH] [HLS] break segment refresh loop rep based --- src/common/AdaptiveStream.cpp | 6 ++++++ src/common/AdaptiveTree.h | 20 ++++++++++---------- src/main.cpp | 1 - src/parser/HLSTree.cpp | 2 +- src/parser/HLSTree.h | 2 -- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/common/AdaptiveStream.cpp b/src/common/AdaptiveStream.cpp index 7042370fe..a34a8fbcc 100755 --- a/src/common/AdaptiveStream.cpp +++ b/src/common/AdaptiveStream.cpp @@ -451,9 +451,13 @@ bool AdaptiveStream::select_stream(bool force, bool justInit, unsigned int repId return false; uint32_t segid(current_rep_ ? current_rep_->get_segment_pos(current_seg_) : 0); + if (current_rep_) + const_cast(current_rep_)->flags_ &= ~adaptive::AdaptiveTree::Representation::ENABLED; current_rep_ = new_rep; + const_cast(current_rep_)->flags_ |= adaptive::AdaptiveTree::Representation::ENABLED; + if (observer_) observer_->OnStreamChange(this, segid); @@ -485,6 +489,8 @@ void AdaptiveStream::info(std::ostream &s) void AdaptiveStream::stop() { stopped_ = true; + if (current_rep_) + const_cast(current_rep_)->flags_ &= ~adaptive::AdaptiveTree::Representation::ENABLED; if (thread_data_) { delete thread_data_; diff --git a/src/common/AdaptiveTree.h b/src/common/AdaptiveTree.h index ad8a145ca..6dd21cbb6 100755 --- a/src/common/AdaptiveTree.h +++ b/src/common/AdaptiveTree.h @@ -128,15 +128,16 @@ namespace adaptive uint32_t fpsRate_, fpsScale_; float aspect_; //Flags - static const unsigned int BYTERANGE = 0; - static const unsigned int INDEXRANGEEXACT = 1; - static const unsigned int TEMPLATE = 2; - static const unsigned int TIMELINE = 4; - static const unsigned int INITIALIZATION = 8; - static const unsigned int SEGMENTBASE = 16; - static const unsigned int SUBTITLESTREAM = 32; - static const unsigned int INCLUDEDSTREAM = 64; - static const unsigned int URLSEGMENTS = 128; + static const uint16_t BYTERANGE = 0; + static const uint16_t INDEXRANGEEXACT = 1; + static const uint16_t TEMPLATE = 2; + static const uint16_t TIMELINE = 4; + static const uint16_t INITIALIZATION = 8; + static const uint16_t SEGMENTBASE = 16; + static const uint16_t SUBTITLESTREAM = 32; + static const uint16_t INCLUDEDSTREAM = 64; + static const uint16_t URLSEGMENTS = 128; + static const uint16_t ENABLED = 256; uint16_t flags_; uint16_t hdcpVersion_; @@ -290,7 +291,6 @@ namespace adaptive virtual ~AdaptiveTree(); virtual bool open(const char *url) = 0; - virtual void close() {}; virtual bool prepareRepresentation(Representation *rep, uint64_t segmentId = 0) { return true; }; virtual void OnDataArrived(Representation *rep, const Segment *seg, const uint8_t *src, uint8_t *dst, size_t dstOffset, size_t dataSize); virtual void OnSegmentDownloaded(Representation *rep, const Segment *seg) {}; diff --git a/src/main.cpp b/src/main.cpp index 106db1218..32e8d0654 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1438,7 +1438,6 @@ Session::Session(MANIFEST_TYPE manifestType, const char *strURL, const char *str Session::~Session() { kodi::Log(ADDON_LOG_DEBUG, "Session::~Session()"); - adaptiveTree_->close(); for (std::vector::iterator b(streams_.begin()), e(streams_.end()); b != e; ++b) SAFE_DELETE(*b); streams_.clear(); diff --git a/src/parser/HLSTree.cpp b/src/parser/HLSTree.cpp index dddfe83ac..1cf5c46ef 100644 --- a/src/parser/HLSTree.cpp +++ b/src/parser/HLSTree.cpp @@ -458,7 +458,7 @@ bool HLSTree::prepareRepresentation(Representation *rep, uint64_t segmentId) for (unsigned int i(0); i < 20; ++i) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); - if (!m_closing) + if (!(rep->flags_ & Representation::ENABLED)) return false; } numRetries -= 2; diff --git a/src/parser/HLSTree.h b/src/parser/HLSTree.h index 2680aadb2..5cfcb055d 100644 --- a/src/parser/HLSTree.h +++ b/src/parser/HLSTree.h @@ -34,7 +34,6 @@ namespace adaptive virtual ~HLSTree(); virtual bool open(const char *url) override; - virtual void close() override { m_closing = true; }; virtual bool prepareRepresentation(Representation *rep, uint64_t segmentId = 0) override; virtual bool write_data(void *buffer, size_t buffer_size) override; virtual void OnDataArrived(Representation *rep, const Segment *seg, const uint8_t *src, uint8_t *dst, size_t dstOffset, size_t dataSize) override; @@ -62,7 +61,6 @@ namespace adaptive std::map m_extGroups; bool m_refreshPlayList = true; - bool m_closing = false; uint8_t m_segmentIntervalSec = 2; AESDecrypter *m_decrypter; uint8_t m_iv[16];