Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Session] Use total segments duration to check the period #1607

Open
wants to merge 1 commit into
base: Piers
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "CompSettings.h"
#include "SrvBroker.h"
#include "aes_decrypter.h"
#include "common/AdaptationSet.h"
#include "common/AdaptiveDecrypter.h"
#include "common/AdaptiveTreeFactory.h"
#include "common/Chooser.h"
Expand Down Expand Up @@ -1120,15 +1121,15 @@ bool CSession::SeekTime(double seekTime, unsigned int streamId, bool preceeding)

for (; pi != m_adaptiveTree->m_periods.cend(); pi++)
{
chapterTime += double((*pi)->GetDuration()) / (*pi)->GetTimescale();
chapterTime += double((*pi)->GetSegDuration()) / (*pi)->GetTimescale();
if (chapterTime > seekTime)
break;
}

if (pi == m_adaptiveTree->m_periods.cend())
--pi;

chapterTime -= double((*pi)->GetDuration()) / (*pi)->GetTimescale();
chapterTime -= double((*pi)->GetSegDuration()) / (*pi)->GetTimescale();

if ((*pi).get() != m_adaptiveTree->m_currentPeriod)
{
Expand Down Expand Up @@ -1369,7 +1370,7 @@ int64_t CSession::GetChapterPos(int ch) const

for (; ch; --ch)
{
sum += (m_adaptiveTree->m_periods[ch - 1]->GetDuration() * STREAM_TIME_BASE) /
sum += (m_adaptiveTree->m_periods[ch - 1]->GetSegDuration() * STREAM_TIME_BASE) /
m_adaptiveTree->m_periods[ch - 1]->GetTimescale();
}

Expand All @@ -1384,7 +1385,7 @@ uint64_t CSession::GetChapterStartTime() const
if (p.get() == m_adaptiveTree->m_currentPeriod)
break;
else
start_time += (p->GetDuration() * STREAM_TIME_BASE) / p->GetTimescale();
start_time += (p->GetSegDuration() * STREAM_TIME_BASE) / p->GetTimescale();
}
return start_time;
}
Expand Down
13 changes: 13 additions & 0 deletions src/common/Period.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ PLAYLIST::CPeriod::~CPeriod()
{
}

uint64_t PLAYLIST::CPeriod::GetSegDuration()
{
CAdaptationSet* adp = CAdaptationSet::FindByFirstAVStream(m_adaptationSets);
if (adp && !adp->GetRepresentations().empty())
{
auto& rep = adp->GetRepresentations().front();
return rep->Timeline().GetDuration() * m_timescale / rep->GetTimescale();
}
return 0;
}

void PLAYLIST::CPeriod::CopyHLSData(const CPeriod* other)
{
m_adaptationSets.reserve(other->m_adaptationSets.size());
Expand Down Expand Up @@ -99,3 +110,5 @@ void PLAYLIST::CPeriod::AddAdaptationSet(std::unique_ptr<CAdaptationSet>& adapta
{
m_adaptationSets.push_back(std::move(adaptationSet));
}


13 changes: 12 additions & 1 deletion src/common/Period.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ class ATTR_DLL_LOCAL CPeriod : public CCommonSegAttribs
void SetStart(uint64_t start) { m_start = start; }

/*!
* \brief Get the duration, in timescale units.
* \brief Get a precise duration of all segments, in timescale units.
* Value is taken from the first A/V representation timeline.
* The value can differ from GetDuration, because GetDuration take in account
* the duration from "start" time of period,
* and may be affected by inaccurate estimates of ADS streams.
* \return The duration value.
*/
uint64_t GetSegDuration();

/*!
* \brief Get the duration, in timescale units,
* (value may be affected by inaccurate estimates of ADS streams).
* \return The duration value.
*/
uint64_t GetDuration() const { return m_duration; }
Expand Down