Skip to content

Commit

Permalink
Merge pull request #1653 from CastagnaIT/fix_sessions_init
Browse files Browse the repository at this point in the history
[Session][CDM] Dont initialize already initialized sessions
  • Loading branch information
CastagnaIT authored Aug 26, 2024
2 parents 5a756be + d5ebd7d commit d5dbbe4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,17 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
// cdmSession 0 is reserved for unencrypted streams
for (size_t ses{1}; ses < m_cdmSessions.size(); ++ses)
{
CCdmSession& session{m_cdmSessions[ses]};

// Check if the decrypter has been previously initialized, if so skip it,
// sessions are collected and never removed and InitializeDRM can be called more times
// depending on how it is used:
// 1) CSession::Initialize->InitializePeriod->InitializeDRM - Used by DASH/SS (single call)
// 2) CInputStreamAdaptive::DemuxRead->m_session->InitializePeriod()->InitializeDRM - On chapter change (single call)
// 3) CInputStreamAdaptive::OpenStream->m_session->PrepareStream->InitializeDRM - Used by HLS (a call for each stream)
if (session.m_cencSingleSampleDecrypter)
continue;

std::vector<uint8_t> initData;
std::string drmOptionalKeyParam;

Expand Down Expand Up @@ -456,8 +467,6 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
}
}

CCdmSession& session{m_cdmSessions[ses]};

if (addDefaultKID && ses == 1 && session.m_cencSingleSampleDecrypter)
{
// If the CDM has been pre-initialized, on non-android systems
Expand Down

0 comments on commit d5dbbe4

Please sign in to comment.