Permalink
Browse files

reduce #psshsets by using use_count

  • Loading branch information...
peak3d committed Aug 19, 2017
1 parent 3a9bda1 commit 0c7e97540419f15e80a7d46bf85fa3cc321a53e2
@@ -312,7 +312,7 @@ uint32_t AdaptiveStream::read(void* buffer, uint32_t bytesToRead)
std::unique_lock<std::mutex> lckrw(thread_data_->mutex_rw_);
NEXTSEGMENT:
if (ensureSegment() && bytesToRead)
if (!stopped_ && ensureSegment() && bytesToRead)
{
while (true)
{
@@ -347,7 +347,7 @@ bool AdaptiveStream::seek(uint64_t const pos)
{
std::unique_lock<std::mutex> lckrw(thread_data_->mutex_rw_);
// we seek only in the current segment
if (pos >= absolute_position_ - segment_read_pos_)
if (!stopped_ && pos >= absolute_position_ - segment_read_pos_)
{
segment_read_pos_ = static_cast<uint32_t>(pos - (absolute_position_ - segment_read_pos_));
@@ -141,7 +141,7 @@ namespace adaptive
memcpy(dst + dstOffset, src, dataSize);
}
uint8_t AdaptiveTree::insert_psshset(StreamType type)
uint16_t AdaptiveTree::insert_psshset(StreamType type)
{
if (!current_pssh_.empty())
{
@@ -162,8 +162,12 @@ namespace adaptive
pos = psshSets_.insert(psshSets_.end(), pssh);
else
pos->media_ |= pssh.media_;
return static_cast<uint8_t>(pos - psshSets_.begin());
++psshSets_[pos - psshSets_.begin()].use_count_;
return static_cast<uint16_t>(pos - psshSets_.begin());
}
else
++psshSets_[0].use_count_;
return 0;
}
View
@@ -112,7 +112,7 @@ namespace adaptive
const char *url;
};
uint64_t startPTS_;
uint8_t pssh_set_;
uint16_t pssh_set_;
};
struct SegmentTemplate
@@ -156,7 +156,7 @@ namespace adaptive
uint32_t indexRangeMin_, indexRangeMax_;
uint8_t channelCount_, nalLengthSize_;
uint8_t pssh_set_;
uint16_t pssh_set_;
uint32_t expired_segments_;
ContainerType containerType_;
SegmentTemplate segtpl_;
@@ -187,7 +187,7 @@ namespace adaptive
return segment ? segments_.data.empty() ? 0 : segments_.pos(segment) : ~0;
}
const uint8_t get_psshset() const
const uint16_t get_psshset() const
{
return pssh_set_;
}
@@ -271,12 +271,13 @@ namespace adaptive
static const uint32_t MEDIA_VIDEO = 1;
static const uint32_t MEDIA_AUDIO = 2;
PSSH() {};
bool operator == (const PSSH &other) const { return pssh_ == other.pssh_ && defaultKID_ == other.defaultKID_ && iv == other.iv; };
PSSH() :media_(0), use_count_(0) {};
bool operator == (const PSSH &other) const { return !use_count_ || (pssh_ == other.pssh_ && defaultKID_ == other.defaultKID_ && iv == other.iv); };
std::string pssh_;
std::string defaultKID_;
std::string iv;
uint32_t media_;
uint32_t use_count_;
};
std::vector<PSSH> psshSets_;
@@ -308,7 +309,7 @@ namespace adaptive
virtual void OnDataArrived(Representation *rep, const Segment *seg, const uint8_t *src, uint8_t *dst, size_t dstOffset, size_t dataSize);
virtual void RefreshSegments(Representation *rep, const Segment *seg) {};
uint8_t insert_psshset(StreamType type);
uint16_t insert_psshset(StreamType type);
bool has_type(StreamType t);
uint32_t estimate_segcount(uint32_t duration, uint32_t timescale);
double get_download_speed() const { return download_speed_; };
View
@@ -922,7 +922,7 @@ class FragmentedSampleReader : public SampleReader, public AP4_LinearReader
virtual uint64_t Elapsed(uint64_t basePTS)
{
int64_t manifestPTS = m_pts - m_ptsDiff;
uint64_t manifestPTS = (m_pts > m_ptsDiff) ? m_pts - m_ptsDiff : 0;
return manifestPTS > basePTS ? manifestPTS - basePTS : 0;
};
@@ -1250,7 +1250,7 @@ class TSSampleReader : public SampleReader, public TSReader
virtual uint64_t Elapsed(uint64_t basePTS)
{
// TSReader::GetPTSDiff() is the difference between playlist PTS and real PTS relative to current segment
int64_t playlistPTS = m_pts - m_ptsDiff;
uint64_t playlistPTS = (static_cast<int64_t>(m_pts) > m_ptsDiff) ? m_pts - m_ptsDiff : 0;
return playlistPTS > basePTS ? playlistPTS - basePTS : 0;
};
@@ -2041,7 +2041,7 @@ void Session::CheckFragmentDuration(STREAM &stream)
stream.segmentChanged = false;
}
const AP4_UI08 *Session::GetDefaultKeyId(const uint8_t index) const
const AP4_UI08 *Session::GetDefaultKeyId(const uint16_t index) const
{
static const AP4_UI08 default_key[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
if (adaptiveTree_->psshSets_[index].defaultKID_.size() == 16)
@@ -2328,7 +2328,7 @@ struct INPUTSTREAM_INFO CInputStreamAdaptive::GetStream(int streamid)
if (stream)
{
uint8_t cdmId(stream->stream_.getRepresentation()->pssh_set_);
uint8_t cdmId(static_cast<uint8_t>(stream->stream_.getRepresentation()->pssh_set_));
if (stream->encrypted && m_session->GetCDMSession(cdmId) != nullptr)
{
kodi::Log(ADDON_LOG_DEBUG, "GetStream(%d): initalizing crypto session", streamid);
View
@@ -123,7 +123,7 @@ class Session: public adaptive::AdaptiveStreamObserver
bool SeekTime(double seekTime, unsigned int streamId = 0, bool preceeding=true);
bool IsLive() const { return adaptiveTree_->has_timeshift_buffer_; };
MANIFEST_TYPE GetManifestType() const { return manifest_type_; };
const AP4_UI08 *GetDefaultKeyId(const uint8_t index) const;
const AP4_UI08 *GetDefaultKeyId(const uint16_t index) const;
uint32_t GetIncludedStreamMask() const;
CRYPTO_INFO::CRYPTO_KEY_SYSTEM GetCryptoKeySystem() const;
View
@@ -923,7 +923,7 @@ end(void *data, const char *el)
{
if (dash->current_pssh_.empty())
dash->current_pssh_ = "FILE";
dash->current_representation_->pssh_set_ = dash->insert_psshset(dash->current_adaptationset_->type_);
dash->current_representation_->pssh_set_ = static_cast<uint8_t>(dash->insert_psshset(dash->current_adaptationset_->type_));
dash->currentNode_ &= ~DASHTree::MPDNODE_CONTENTPROTECTION;
}
}
@@ -938,7 +938,7 @@ end(void *data, const char *el)
if (!dash->current_hasRepURN_)
{
dash->current_pssh_ = "FILE";
dash->current_representation_->pssh_set_ = dash->insert_psshset(dash->current_adaptationset_->type_);
dash->current_representation_->pssh_set_ = static_cast<uint8_t>(dash->insert_psshset(dash->current_adaptationset_->type_));
dash->encryptionState_ |= DASHTree::ENCRYTIONSTATE_SUPPORTED;
}
else
@@ -1059,7 +1059,7 @@ end(void *data, const char *el)
{
if (dash->current_pssh_.empty())
dash->current_pssh_ = "FILE";
dash->adp_pssh_set_ = dash->insert_psshset(dash->current_adaptationset_->type_);
dash->adp_pssh_set_ = static_cast<uint8_t>(dash->insert_psshset(dash->current_adaptationset_->type_));
dash->currentNode_ &= ~DASHTree::MPDNODE_CONTENTPROTECTION;
}
}
View
@@ -262,7 +262,10 @@ bool HLSTree::prepareRepresentation(Representation *rep, bool update)
SPINCACHE<Segment> &segments(update ? rep->newSegments_ : rep->segments_);
if (rep->flags_ & Representation::URLSEGMENTS)
for (auto &s : segments.data)
{
--psshSets_[s.pssh_set_].use_count_;
delete[] s.url;
}
segments.clear();
if (download(rep->source_url_.c_str(), manifest_headers_))
@@ -370,7 +370,7 @@ bool SmoothTree::open(const char *url)
uint8_t psshset(0);
if (!current_defaultKID_.empty())
psshset = insert_psshset(STREAM_TYPE_COUNT);
psshset = static_cast<uint8_t>(insert_psshset(STREAM_TYPE_COUNT));
for (std::vector<AdaptationSet*>::iterator ba(current_period_->adaptationSets_.begin()), ea(current_period_->adaptationSets_.end()); ba != ea; ++ba)
{

0 comments on commit 0c7e975

Please sign in to comment.