From 0433dcfa35be6dec305d3910da275326a302594c Mon Sep 17 00:00:00 2001 From: CastagnaIT Date: Fri, 5 Jul 2024 14:52:12 +0200 Subject: [PATCH] temp --- src/Session.cpp | 9 +++++---- src/common/Period.cpp | 13 +++++++++++++ src/common/Period.h | 13 ++++++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Session.cpp b/src/Session.cpp index 076dbdeea..0322177dc 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -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" @@ -1120,7 +1121,7 @@ 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; } @@ -1128,7 +1129,7 @@ bool CSession::SeekTime(double seekTime, unsigned int streamId, bool preceeding) 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) { @@ -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(); } @@ -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; } diff --git a/src/common/Period.cpp b/src/common/Period.cpp index c8cfac6b8..617a08156 100644 --- a/src/common/Period.cpp +++ b/src/common/Period.cpp @@ -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()); @@ -99,3 +110,5 @@ void PLAYLIST::CPeriod::AddAdaptationSet(std::unique_ptr& adapta { m_adaptationSets.push_back(std::move(adaptationSet)); } + + diff --git a/src/common/Period.h b/src/common/Period.h index f885fffc0..7c9e4a06f 100644 --- a/src/common/Period.h +++ b/src/common/Period.h @@ -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; }