Skip to content

Commit

Permalink
Merge pull request #1508 from CastagnaIT/mpd_fixes
Browse files Browse the repository at this point in the history
[DashTree] Rework to improve live streaming
  • Loading branch information
CastagnaIT authored Mar 29, 2024
2 parents c985efb + 7b7a403 commit 944c388
Show file tree
Hide file tree
Showing 36 changed files with 780 additions and 769 deletions.
14 changes: 5 additions & 9 deletions src/AdaptiveByteStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ AP4_Result CAdaptiveByteStream::WritePartial(const void* buffer,
return AP4_ERROR_NOT_SUPPORTED;
}

bool CAdaptiveByteStream::ReadFull(std::vector<uint8_t>& buffer)
{
return m_adStream->ReadFullBuffer(buffer);
}

AP4_Result CAdaptiveByteStream::Seek(AP4_Position position)
{
return m_adStream->seek(position) ? AP4_SUCCESS : AP4_ERROR_NOT_SUPPORTED;
Expand All @@ -41,15 +46,6 @@ AP4_Result CAdaptiveByteStream::GetSize(AP4_LargeSize& size)
return AP4_ERROR_NOT_SUPPORTED;
}

AP4_Result CAdaptiveByteStream::GetSegmentSize(size_t& size)
{
if (m_adStream->ensureSegment() && m_adStream->retrieveCurrentSegmentBufferSize(size))
{
return AP4_SUCCESS;
}
return AP4_ERROR_EOS;
}

bool CAdaptiveByteStream::waitingForSegment() const
{
return m_adStream->waitingForSegment();
Expand Down
9 changes: 8 additions & 1 deletion src/AdaptiveByteStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ class ATTR_DLL_LOCAL CAdaptiveByteStream : public AP4_ByteStream
AP4_Result WritePartial(const void* buffer,
AP4_Size bytesToWrite,
AP4_Size& bytesWritten) override;

/*!
* \brief Read in full the stream.
* \param buffer[OUT] The full data buffer bytes
* \return True if has success, otherwise false
*/
bool ReadFull(std::vector<uint8_t>& buffer);

AP4_Result Seek(AP4_Position position) override;
AP4_Result Tell(AP4_Position& position) override;
AP4_Result GetSize(AP4_LargeSize& size) override;
AP4_Result GetSegmentSize(size_t& size);

// AP4_Referenceable methods
void AddReference() override{};
Expand Down
29 changes: 2 additions & 27 deletions src/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ void CSession::PrepareStream(CStream* stream)
bool isDrmChanged{false};
if (m_adaptiveTree->PrepareRepresentation(stream->m_adStream.getPeriod(),
stream->m_adStream.getAdaptationSet(), repr,
isDrmChanged))
isDrmChanged, SEGMENT_NO_NUMBER))
{
if (isDrmChanged)
InitializeDRM();
Expand Down Expand Up @@ -1056,7 +1056,7 @@ bool CSession::GetNextSample(ISampleReader*& sampleReader)
{
if (!res || streamReader->DTSorPTS() < res->GetReader()->DTSorPTS())
{
if (stream->m_adStream.waitingForSegment(true))
if (stream->m_adStream.waitingForSegment())
{
waiting = stream.get();
}
Expand All @@ -1076,12 +1076,6 @@ bool CSession::GetNextSample(ISampleReader*& sampleReader)
}
else if (res)
{
if (res->m_hasSegmentChanged)
{
OnSegmentChangedRead(res);
res->m_hasSegmentChanged = false;
}

ISampleReader* sr{res->GetReader()};

if (sr->PTS() != STREAM_NOPTS_VALUE)
Expand Down Expand Up @@ -1242,7 +1236,6 @@ void CSession::OnSegmentChanged(adaptive::AdaptiveStream* adStream)
else
streamReader->SetPTSOffset(stream->m_adStream.GetCurrentPTSOffset());

stream->m_hasSegmentChanged = true;
break;
}
}
Expand All @@ -1260,24 +1253,6 @@ void CSession::OnStreamChange(adaptive::AdaptiveStream* adStream)
}
}

void CSession::OnSegmentChangedRead(CStream* stream)
{
if (m_adaptiveTree->IsLive())
{
ISampleReader* sr = stream->GetReader();
uint64_t duration;

if (sr->GetFragmentInfo(duration))
{
adaptive::AdaptiveStream& adStream = stream->m_adStream;

m_adaptiveTree->InsertLiveSegment(adStream.getPeriod(), adStream.getAdaptationSet(),
adStream.getRepresentation(), adStream.getSegmentPos(),
0, duration, sr->GetTimeScale());
}
}
}

Adaptive_CencSingleSampleDecrypter* CSession::GetSingleSampleDecrypter(std::string sessionId)
{
for (std::vector<CCdmSession>::iterator b(m_cdmSessions.begin() + 1), e(m_cdmSessions.end());
Expand Down
9 changes: 1 addition & 8 deletions src/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
/*! \brief Get the total time in ms of the stream
* \return The total time in ms of the stream
*/
uint64_t GetTotalTimeMs() const { return m_adaptiveTree->m_totalTimeSecs * 1000; };
uint64_t GetTotalTimeMs() const { return m_adaptiveTree->m_totalTime; };

/*! \brief Get the elapsed time in ms of the stream including all chapters
* \return The elapsed time in ms of the stream including all chapters
Expand Down Expand Up @@ -307,13 +307,6 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
void OnStreamChange(adaptive::AdaptiveStream* adStream) override;

protected:
/*!
* \brief Event raised when the current segment is changed and
* the data has already been read by the sample reader.
* \param stream The stream for which segment has changed.
*/
void OnSegmentChangedRead(CStream* stream);

/*! \brief Check for and load decrypter module matching the supplied key system
* \param key_system [OUT] Will be assigned to if a decrypter is found matching
* the set license type
Expand Down
2 changes: 0 additions & 2 deletions src/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ATTR_DLL_LOCAL CStream
m_isEncrypted{false},
m_mainId{0},
m_adStream{tree, adp, initialRepr},
m_hasSegmentChanged{false},
m_isValid{true} {};


Expand Down Expand Up @@ -87,7 +86,6 @@ class ATTR_DLL_LOCAL CStream
uint16_t m_mainId;
adaptive::AdaptiveStream m_adStream;
kodi::addon::InputstreamInfo m_info;
bool m_hasSegmentChanged;
bool m_isValid;

private:
Expand Down
2 changes: 0 additions & 2 deletions src/common/AdaptationSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ void PLAYLIST::CAdaptationSet::CopyHLSData(const CAdaptationSet* other)

m_baseUrl = other->m_baseUrl;
m_streamType = other->m_streamType;
m_duration = other->m_duration;
m_startPts = other->m_startPts;
m_startNumber = other->m_startNumber;
m_isImpaired = other->m_isImpaired;
m_isOriginal = other->m_isOriginal;
Expand Down
4 changes: 0 additions & 4 deletions src/common/AdaptationSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class ATTR_DLL_LOCAL CAdaptationSet : public CCommonSegAttribs, public CCommonAt
uint64_t GetStartNumber() const { return m_startNumber; }
void SetStartNumber(uint64_t startNumber) { m_startNumber = startNumber; }

uint64_t GetStartPTS() const { return m_startPts; }
void SetStartPTS(uint64_t startPts) { m_startPts = startPts; }

void AddCodecs(std::string_view codecs);
const std::set<std::string>& GetCodecs() { return m_codecs; }

Expand Down Expand Up @@ -170,7 +167,6 @@ class ATTR_DLL_LOCAL CAdaptationSet : public CCommonSegAttribs, public CCommonAt
std::string m_group;
std::string m_baseUrl;
uint64_t m_startNumber{1};
uint64_t m_startPts{0};
uint64_t m_duration{0};

std::set<std::string> m_codecs;
Expand Down
Loading

0 comments on commit 944c388

Please sign in to comment.