Skip to content

Commit

Permalink
[DASHTree] handle new Period better
Browse files Browse the repository at this point in the history
(cherry picked from commit 13b58b5)
  • Loading branch information
tmm1 committed Feb 28, 2023
1 parent 04af9e3 commit bf7cbf1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
22 changes: 21 additions & 1 deletion src/common/AdaptiveStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,28 @@ bool AdaptiveStream::ensureSegment()
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return false;
}
else if (tree_.HasUpdateThread() && current_period_ != tree_.periods_.back())
{
auto itPer = std::find(tree_.periods_.begin(), tree_.periods_.end(), current_period_);
if (itPer == tree_.periods_.end())
{
LOG::LogF(LOGWARNING, "Current Period (id=%s, start=%ld) missing from tree!",
current_period_->id_.c_str(), current_period_->start_);
state_ = STOPPED;
return false;
}

auto pos = std::distance(tree_.periods_.begin(), itPer);
auto newPd = tree_.periods_[pos + 1];
LOG::LogF(LOGDEBUG, "Switching to new Period (id=%s, start=%ld)", newPd->id_.c_str(),
newPd->start_);
tree_.next_period_ = newPd;
state_ = STOPPED;
return false;
}
else
{
LOG::LogF(LOGDEBUG, "Transition to STOPPED");
state_ = STOPPED;
return false;
}
Expand Down Expand Up @@ -1112,7 +1132,7 @@ bool AdaptiveStream::seek_time(double seek_seconds, bool preceeding, bool& needR

bool AdaptiveStream::waitingForSegment(bool checkTime) const
{
if (tree_.HasUpdateThread())
if (tree_.HasUpdateThread() && state_ == RUNNING)
{
std::lock_guard<std::mutex> lckTree(tree_.GetTreeMutex());
if (current_rep_ && (current_rep_->flags_ & AdaptiveTree::Representation::WAITFORSEGMENT) != 0)
Expand Down
37 changes: 34 additions & 3 deletions src/parser/DASHTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,19 +1775,50 @@ void DASHTree::RefreshLiveSegments()

for (size_t index{0}; index < updateTree->periods_.size(); index++)
{
if (index == periods_.size()) // Exceeded periods
break;
auto updPeriod = updateTree->periods_[index];
if (!updPeriod)
continue;

Period* period{nullptr};
// find matching period based on ID
auto itPd = std::find_if(periods_.begin(), periods_.end(),
[&updPeriod](const Period* item)
{ return !item->id_.empty() && item->id_ == updPeriod->id_; });
if (itPd == periods_.end())
{
// not found, try matching period based on start
itPd = std::find_if(periods_.begin(), periods_.end(),
[&updPeriod](const Period* item)
{ return item->start_ && item->start_ == updPeriod->start_; });
}
// found!
if (itPd != periods_.end())
period = *itPd;
if (!period && updPeriod->id_.empty() && updPeriod->start_ == 0)
{
// not found, fallback match based on position
if (index < periods_.size())
period = periods_[index];
}
// new period, insert it
if (!period)
{
LOG::LogF(LOGDEBUG, "Inserting new Period (id=%s, start=%ld)", updPeriod->id_.c_str(),
updPeriod->start_);
std::vector<Period*> tmp = periods_;
updateTree->periods_[index] = nullptr;
tmp.push_back(updPeriod);
periods_ = tmp;
continue;
}

for (auto updAdaptationSet : updPeriod->adaptationSets_)
{
// Locate adaptationset
if (!updAdaptationSet)
continue;

for (auto adaptationSet : periods_[index]->adaptationSets_)
for (auto adaptationSet : period->adaptationSets_)
{
if (!(adaptationSet->id_ == updAdaptationSet->id_ &&
adaptationSet->group_ == updAdaptationSet->group_ &&
Expand Down

0 comments on commit bf7cbf1

Please sign in to comment.