-
Notifications
You must be signed in to change notification settings - Fork 258
Live stream jump #2005
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
Live stream jump #2005
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |||||||||||||||||||||||||||
| #include "utils/log.h" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #include <array> | ||||||||||||||||||||||||||||
| #include <limits> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #include <kodi/addon-instance/Inputstream.h> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -1441,15 +1442,18 @@ int CSession::GetChapter() const | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| int CSession::GetChapterCount() const | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| if (m_adaptiveTree && m_adaptiveTree->m_periods.size() > 1) | ||||||||||||||||||||||||||||
| return static_cast<int>(m_adaptiveTree->m_periods.size()); | ||||||||||||||||||||||||||||
| if (!m_adaptiveTree) | ||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||
| int count = static_cast<int>(m_adaptiveTree->m_periods.size()); | ||||||||||||||||||||||||||||
| if (count > 0 && m_adaptiveTree->IsLive()) | ||||||||||||||||||||||||||||
| count += 1; | ||||||||||||||||||||||||||||
| return count; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| std::string CSession::GetChapterName(int ch) const | ||||||||||||||||||||||||||||
|
|
@@ -1459,6 +1463,8 @@ std::string CSession::GetChapterName(int ch) const | |||||||||||||||||||||||||||
| --ch; | ||||||||||||||||||||||||||||
| if (ch >= 0 && ch < static_cast<int>(m_adaptiveTree->m_periods.size())) | ||||||||||||||||||||||||||||
| return m_adaptiveTree->m_periods[ch]->GetId().data(); | ||||||||||||||||||||||||||||
| if (ch == static_cast<int>(m_adaptiveTree->m_periods.size()) && m_adaptiveTree->IsLive()) | ||||||||||||||||||||||||||||
| return "Live"; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return "[Unknown]"; | ||||||||||||||||||||||||||||
|
|
@@ -1469,6 +1475,14 @@ int64_t CSession::GetChapterPos(int ch) const | |||||||||||||||||||||||||||
| int64_t sum{0}; | ||||||||||||||||||||||||||||
| --ch; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (m_adaptiveTree && ch == static_cast<int>(m_adaptiveTree->m_periods.size()) && | ||||||||||||||||||||||||||||
| m_adaptiveTree->IsLive()) | ||||||||||||||||||||||||||||
| return static_cast<int64_t>(m_adaptiveTree->m_totalTime / 1000); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Chapter 1 of a live stream: return configured start offset | ||||||||||||||||||||||||||||
| if (ch == 0 && m_adaptiveTree && m_adaptiveTree->IsLive()) | ||||||||||||||||||||||||||||
| return static_cast<int64_t>(CSrvBroker::GetKodiProps().GetLiveOffset()); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| for (; ch; --ch) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| sum += (m_adaptiveTree->m_periods[ch - 1]->GetDuration() * STREAM_TIME_BASE) / | ||||||||||||||||||||||||||||
|
|
@@ -1516,23 +1530,40 @@ bool CSession::SeekChapter(int ch) | |||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| --ch; | ||||||||||||||||||||||||||||
| if (ch >= 0 && ch < static_cast<int>(m_adaptiveTree->m_periods.size()) && | ||||||||||||||||||||||||||||
| m_adaptiveTree->m_periods[ch].get() != m_adaptiveTree->m_currentPeriod) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (ch == static_cast<int>(m_adaptiveTree->m_periods.size()) && m_adaptiveTree->IsLive()) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| CPeriod* nextPeriod = m_adaptiveTree->m_periods[ch].get(); | ||||||||||||||||||||||||||||
| m_adaptiveTree->m_nextPeriod = nextPeriod; | ||||||||||||||||||||||||||||
| LOG::LogF(LOGDEBUG, "Switching to new Period (id=%s, start=%llu, seq=%u)", | ||||||||||||||||||||||||||||
| nextPeriod->GetId().data(), nextPeriod->GetStart(), nextPeriod->GetSequence()); | ||||||||||||||||||||||||||||
| LOG::LogF(LOGDEBUG, "Seeking to live edge (virtual chapter)"); | ||||||||||||||||||||||||||||
| SeekTime(std::numeric_limits<double>::max(), 0, false); | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| for (auto& stream : m_streams) | ||||||||||||||||||||||||||||
| if (ch >= 0 && ch < static_cast<int>(m_adaptiveTree->m_periods.size())) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| CPeriod* targetPeriod = m_adaptiveTree->m_periods[ch].get(); | ||||||||||||||||||||||||||||
| if (targetPeriod != m_adaptiveTree->m_currentPeriod) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| ISampleReader* sr{stream->GetReader()}; | ||||||||||||||||||||||||||||
| if (sr) | ||||||||||||||||||||||||||||
| m_adaptiveTree->m_nextPeriod = targetPeriod; | ||||||||||||||||||||||||||||
| LOG::LogF(LOGDEBUG, "Switching to new Period (id=%s, start=%llu, seq=%u)", | ||||||||||||||||||||||||||||
| targetPeriod->GetId().data(), targetPeriod->GetStart(), | ||||||||||||||||||||||||||||
| targetPeriod->GetSequence()); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| for (auto& stream : m_streams) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| sr->WaitReadSampleAsyncComplete(); | ||||||||||||||||||||||||||||
| sr->Reset(true); | ||||||||||||||||||||||||||||
| ISampleReader* sr{stream->GetReader()}; | ||||||||||||||||||||||||||||
| if (sr) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| sr->WaitReadSampleAsyncComplete(); | ||||||||||||||||||||||||||||
| sr->Reset(true); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| double startTime = GetChapterPos(ch + 1); | ||||||||||||||||||||||||||||
| LOG::LogF(LOGDEBUG, "Seeking to start of current Period (startTime=%.3f)", startTime); | ||||||||||||||||||||||||||||
| SeekTime(startTime, 0, false); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns
liveOffsetas the position for any live stream's chapter 1, including multi-period live streams. For period 2+, this is wrong —GetChapterPos(1)when the user is in period 2 should return 0 (start of that period), not the absolute stream-start offset. Consider guarding with a check that the stream has only one period, or only applying the offset whench == 0andm_adaptiveTree->m_periods.size() == 1.