Skip to content

Commit

Permalink
[HLSTree] Cleanups to EXT-X-DISCONTINUITY code
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed May 8, 2024
1 parent a002757 commit ba99820
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/common/AdaptationSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ void PLAYLIST::CAdaptationSet::CopyHLSData(const CAdaptationSet* other)

m_baseUrl = other->m_baseUrl;
m_streamType = other->m_streamType;
m_startNumber = other->m_startNumber;
m_isImpaired = other->m_isImpaired;
m_isOriginal = other->m_isOriginal;
m_isDefault = other->m_isDefault;
Expand Down
2 changes: 0 additions & 2 deletions src/common/Period.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ void PLAYLIST::CPeriod::CopyHLSData(const CPeriod* other)
m_baseUrl = other->m_baseUrl;
m_id = other->m_id;
m_timescale = other->m_timescale;
m_encryptionState = other->m_encryptionState;
m_includedStreamType = other->m_includedStreamType;
m_isSecureDecoderNeeded = other->m_isSecureDecoderNeeded;
}

uint16_t PLAYLIST::CPeriod::InsertPSSHSet(const PSSHSet& psshSet)
Expand Down
2 changes: 0 additions & 2 deletions src/common/Representation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ void PLAYLIST::CRepresentation::CopyHLSData(const CRepresentation* other)

m_isIncludedStream = other->m_isIncludedStream;
m_isEnabled = other->m_isEnabled;
m_isWaitForSegment = other->m_isWaitForSegment;
m_initSegment = other->m_initSegment;
}

void PLAYLIST::CRepresentation::SetScaling()
Expand Down
62 changes: 34 additions & 28 deletions src/parser/HLSTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,12 @@ void adaptive::CHLSTree::FixDiscSequence(std::stringstream& streamData, uint32_t
{
currentEncryptionType = EncryptionType::WIDEVINE;
period->SetEncryptionState(EncryptionState::ENCRYPTED_DRM);

rep->m_psshSetPos = InsertPsshSet(adp->GetStreamType(), period, adp, m_currentPssh,
m_currentDefaultKID, m_currentKidUrl, m_currentIV);
}
break;
case EncryptionType::NOT_SUPPORTED:
// Set only if a supported encrypton has not previously been parsed
// Set only if a supported encryption has not previously been parsed
if (period->GetEncryptionState() != EncryptionState::ENCRYPTED_DRM &&
period->GetEncryptionState() != EncryptionState::ENCRYPTED_CK)
{
Expand Down Expand Up @@ -784,44 +783,51 @@ void adaptive::CHLSTree::FixDiscSequence(std::stringstream& streamData, uint32_t
isSkipUntilDiscont = false;
++discontCount;

// Create a new period or update an existing one
mediaSequenceNbr += rep->SegmentTimeline().GetSize();
currentSegNumber = mediaSequenceNbr;

CPeriod* newPeriod = FindDiscontinuityPeriod(m_discontSeq + discontCount);

CPeriod* foundPeriod = FindDiscontinuityPeriod(m_discontSeq + discontCount);
if (foundPeriod) // Update existing period
if (!newPeriod) // Create new period
{
period = foundPeriod;
auto newPeriodPtr = CPeriod::MakeUniquePtr();

// Clone same data structure from previous period (no segment will be copied)
newPeriodPtr->CopyHLSData(period);
newPeriod = newPeriodPtr.get();
m_periods.push_back(std::move(newPeriodPtr));
}
else // Create new period
{
auto newPeriod = CPeriod::MakeUniquePtr();
// CopyHLSData will copy also the init segment in the representations
// that must persist to next period until overrided by new EXT-X-MAP tag
newPeriod->CopyHLSData(m_currentPeriod);

period = newPeriod.get();
period->SetStart(0);
newPeriod->SetStart(0);

m_periods.push_back(std::move(newPeriod));
}
CAdaptationSet* newAdpSet = newPeriod->GetAdaptationSets()[adpSetPos].get();
CRepresentation* newRep = newAdpSet->GetRepresentations()[reprPos].get();

mediaSequenceNbr += rep->SegmentTimeline().GetSize();
currentSegNumber = mediaSequenceNbr;
// Copy the base url from previous period/representation
newRep->SetBaseUrl(rep->GetBaseUrl());

adp = period->GetAdaptationSets()[adpSetPos].get();
// When we switch to a repr of another period we need to set current base url
CRepresentation* switchRep = adp->GetRepresentations()[reprPos].get();
switchRep->SetBaseUrl(rep->GetBaseUrl());
rep = switchRep;
// Copy init segment from previous period/representation
// it must persist until overrided by a new EXT-X-MAP tag
if (rep->GetInitSegment().has_value())
{
newRep->SetInitSegment(*rep->GetInitSegment());
newRep->SetContainerType(rep->GetContainerType());
}

// Copy encryption data from previous period/representation
// it must persist until overrided by a new EXT-X-KEY tag
newPeriod->SetEncryptionState(period->GetEncryptionState());
if (currentEncryptionType == EncryptionType::WIDEVINE)
{
rep->m_psshSetPos = InsertPsshSet(adp->GetStreamType(), period, adp, m_currentPssh,
m_currentDefaultKID, m_currentKidUrl, m_currentIV);
period->SetEncryptionState(EncryptionState::ENCRYPTED_DRM);
newRep->m_psshSetPos =
InsertPsshSet(newAdpSet->GetStreamType(), newPeriod, newAdpSet, m_currentPssh,
m_currentDefaultKID, m_currentKidUrl, m_currentIV);
}

if (rep->HasInitSegment())
rep->SetContainerType(ContainerType::MP4);
// Set the new period as current
period = newPeriod;
adp = newAdpSet;
rep = newRep;
}
else if (tagName == "#EXT-X-ENDLIST")
{
Expand Down

0 comments on commit ba99820

Please sign in to comment.