@@ -66,9 +66,7 @@ CSession::CSession(const PROPERTIES::KodiProperties& kodiProps,
6666
6767 if (!kodiProps.m_serverCertificate .empty ())
6868 {
69- std::string decCert{BASE64::DecodeToStr (kodiProps.m_serverCertificate )};
70- m_serverCertificate.SetData (reinterpret_cast <const AP4_Byte*>(decCert.data ()),
71- static_cast <AP4_Size>(decCert.size ()));
69+ m_serverCertificate = BASE64::Decode (kodiProps.m_serverCertificate );
7270 }
7371}
7472
@@ -106,7 +104,7 @@ void CSession::SetSupportedDecrypterURN(std::string& key_system)
106104 return ;
107105 }
108106
109- key_system = m_decrypter->SelectKeySytem (m_kodiProps.m_licenseType . c_str () );
107+ key_system = m_decrypter->SelectKeySytem (m_kodiProps.m_licenseType );
110108 m_decrypter->SetLibraryPath (kodi::vfs::TranslateSpecialProtocol (specialpath).c_str ());
111109 m_decrypter->SetProfilePath (m_profilePath);
112110 m_decrypter->SetDebugSaveLicense (kodi::addon::GetSettingBoolean (" debug.save.license" ));
@@ -310,20 +308,18 @@ bool CSession::PreInitializeDRM(std::string& challengeB64,
310308
311309 if (!m_decrypter->IsInitialised ())
312310 {
313- if (!m_decrypter->OpenDRMSystem (m_kodiProps.m_licenseKey . c_str () , m_serverCertificate,
311+ if (!m_decrypter->OpenDRMSystem (m_kodiProps.m_licenseKey , m_serverCertificate,
314312 m_drmConfig))
315313 {
316314 LOG::LogF (LOGERROR, " OpenDRMSystem failed" );
317315 return false ;
318316 }
319317 }
320318
321- AP4_DataBuffer init_data;
322- init_data.SetBufferSize (1024 );
319+ std::vector<uint8_t > initData;
323320
324321 // Set the provided PSSH
325- std::vector<uint8_t > decPsshData = BASE64::Decode (psshData);
326- init_data.SetData (decPsshData.data (), static_cast <AP4_Size>(decPsshData.size ()));
322+ initData = BASE64::Decode (psshData);
327323
328324 // Decode the provided KID
329325 std::string decKid{BASE64::DecodeToStr (kidData)};
@@ -333,9 +329,9 @@ bool CSession::PreInitializeDRM(std::string& challengeB64,
333329 std::string hexKid{StringUtils::ToHexadecimal (decKid)};
334330 LOG::LogF (LOGDEBUG, " Initializing session with KID: %s" , hexKid.c_str ());
335331
336- if (m_decrypter && init_data. GetDataSize () >= 4 &&
332+ if (m_decrypter && initData. size () >= 4 &&
337333 (session.m_cencSingleSampleDecrypter = m_decrypter->CreateSingleSampleDecrypter (
338- init_data , " " , decKid, true , CryptoMode::AES_CTR)) != 0 )
334+ initData , " " , decKid, true , CryptoMode::AES_CTR)) != 0 )
339335 {
340336 session.m_cdmSessionStr = session.m_cencSingleSampleDecrypter ->GetSessionId ();
341337 sessionId = session.m_cdmSessionStr ;
@@ -387,7 +383,7 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
387383
388384 if (!m_decrypter->IsInitialised ())
389385 {
390- if (!m_decrypter->OpenDRMSystem (licenseKey. c_str () , m_serverCertificate, m_drmConfig))
386+ if (!m_decrypter->OpenDRMSystem (licenseKey, m_serverCertificate, m_drmConfig))
391387 {
392388 LOG::Log (LOGERROR, " OpenDRMSystem failed" );
393389 return false ;
@@ -404,7 +400,7 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
404400 // cdmSession 0 is reserved for unencrypted streams
405401 for (size_t ses{1 }; ses < m_cdmSessions.size (); ++ses)
406402 {
407- AP4_DataBuffer init_data ;
403+ std::vector< uint8_t > initData ;
408404 std::string drmOptionalKeyParam;
409405
410406 CPeriod::PSSHSet& sessionPsshset = m_adaptiveTree->m_currentPeriod ->GetPSSHSets ()[ses];
@@ -428,9 +424,7 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
428424 LOG::Log (LOGDEBUG, " License data: Create Widevine PSSH for SmoothStreaming, based on "
429425 " license data property" );
430426 }
431- std::vector<uint8_t > init_data_v;
432- CreateISMlicense (sessionPsshset.defaultKID_ , licenseData, init_data_v);
433- init_data.SetData (init_data_v.data (), static_cast <AP4_Size>(init_data_v.size ()));
427+ CreateISMlicense (sessionPsshset.defaultKID_ , licenseData, initData);
434428 }
435429 else if (m_kodiProps.m_licenseType == " com.microsoft.playready" )
436430 {
@@ -453,22 +447,20 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
453447 // This can allow to initialize a DRM that could be also not specified
454448 // as supported in the manifest (e.g. missing DASH ContentProtection tags)
455449 LOG::Log (LOGDEBUG, " License data: Use PSSH data provided by the license data property" );
456- std::vector<uint8_t > licenseData = BASE64::Decode (m_kodiProps.m_licenseData );
457- init_data.SetData (licenseData.data (), static_cast <AP4_Size>(licenseData.size ()));
450+ initData = BASE64::Decode (m_kodiProps.m_licenseData );
458451 }
459452
460- if (init_data. GetDataSize () == 0 )
453+ if (initData. size () == 0 )
461454 {
462455 if (!sessionPsshset.pssh_ .empty ())
463456 {
464457 // Use the PSSH provided by manifest
465- init_data.SetData (sessionPsshset.pssh_ .data (),
466- static_cast <AP4_Size>(sessionPsshset.pssh_ .size ()));
458+ initData = sessionPsshset.pssh_ ;
467459 }
468460 else
469461 {
470462 // Try extract the PSSH/KID from the stream
471- if (!ExtractStreamProtectionData (sessionPsshset, init_data , keySystem))
463+ if (!ExtractStreamProtectionData (sessionPsshset, initData , keySystem))
472464 LOG::Log (LOGERROR, " License data: Cannot extract PSSH/KID data from the stream" );
473465 }
474466 }
@@ -518,10 +510,10 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
518510 }
519511 }
520512
521- if (m_decrypter && init_data. GetDataSize () >= 4 &&
513+ if (m_decrypter && initData. size () >= 4 &&
522514 (session.m_cencSingleSampleDecrypter ||
523515 (session.m_cencSingleSampleDecrypter = m_decrypter->CreateSingleSampleDecrypter (
524- init_data , drmOptionalKeyParam, defaultKid, false ,
516+ initData , drmOptionalKeyParam, defaultKid, false ,
525517 sessionPsshset.m_cryptoMode == CryptoMode::NONE ? CryptoMode::AES_CTR
526518 : sessionPsshset.m_cryptoMode )) !=
527519 0 ))
@@ -736,8 +728,8 @@ void CSession::UpdateStream(CStream& stream)
736728
737729 if (!rep->GetCodecPrivateData ().empty ())
738730 {
739- std::string annexb;
740- const std::string * extraData (&annexb);
731+ std::vector< uint8_t > annexb;
732+ const std::vector< uint8_t > * extraData (&annexb);
741733
742734 const DRM::IDecrypter::DecrypterCapabilites& caps{GetDecrypterCaps (rep->m_psshSetPos )};
743735
@@ -751,8 +743,7 @@ void CSession::UpdateStream(CStream& stream)
751743 {
752744 extraData = &rep->GetCodecPrivateData ();
753745 }
754- stream.m_info .SetExtraData (reinterpret_cast <const uint8_t *>(extraData->c_str ()),
755- extraData->size ());
746+ stream.m_info .SetExtraData (extraData->data (), extraData->size ());
756747 }
757748
758749 stream.m_info .SetCodecFourCC (0 );
@@ -1452,30 +1443,27 @@ AP4_Movie* CSession::CreateMovieAtom(CStream* stream)
14521443 if (repr->GetContainerType () == ContainerType::MP4 && !repr->HasInitSegment ())
14531444 {
14541445 AP4_SampleDescription* sampleDesc;
1455- const std::string & extradata = repr->GetCodecPrivateData ();
1446+ const std::vector< uint8_t > & extradata = repr->GetCodecPrivateData ();
14561447
14571448 if (stream->m_info .GetCodecName () == CODEC::NAME_H264)
14581449 {
1459- AP4_MemoryByteStream ms{reinterpret_cast <const uint8_t *>(extradata.data ()),
1460- static_cast <const AP4_Size>(extradata.size ())};
1450+ AP4_MemoryByteStream ms{extradata.data (), static_cast <const AP4_Size>(extradata.size ())};
14611451 AP4_AvccAtom* atom =
14621452 AP4_AvccAtom::Create (static_cast <AP4_Size>(AP4_ATOM_HEADER_SIZE + extradata.size ()), ms);
14631453 sampleDesc = new AP4_AvcSampleDescription (AP4_SAMPLE_FORMAT_AVC1, stream->m_info .GetWidth (),
14641454 stream->m_info .GetHeight (), 0 , nullptr , atom);
14651455 }
14661456 else if (stream->m_info .GetCodecName () == CODEC::NAME_HEVC)
14671457 {
1468- AP4_MemoryByteStream ms{reinterpret_cast <const AP4_UI08*>(extradata.data ()),
1469- static_cast <const AP4_Size>(extradata.size ())};
1458+ AP4_MemoryByteStream ms{extradata.data (), static_cast <const AP4_Size>(extradata.size ())};
14701459 AP4_HvccAtom* atom =
14711460 AP4_HvccAtom::Create (static_cast <AP4_Size>(AP4_ATOM_HEADER_SIZE + extradata.size ()), ms);
14721461 sampleDesc = new AP4_HevcSampleDescription (AP4_SAMPLE_FORMAT_HEV1, stream->m_info .GetWidth (),
14731462 stream->m_info .GetHeight (), 0 , nullptr , atom);
14741463 }
14751464 else if (stream->m_info .GetCodecName () == CODEC::NAME_AV1)
14761465 {
1477- AP4_MemoryByteStream ms{reinterpret_cast <const AP4_UI08*>(extradata.data ()),
1478- static_cast <AP4_Size>(extradata.size ())};
1466+ AP4_MemoryByteStream ms{extradata.data (), static_cast <const AP4_Size>(extradata.size ())};
14791467 AP4_Av1cAtom* atom =
14801468 AP4_Av1cAtom::Create (static_cast <AP4_Size>(AP4_ATOM_HEADER_SIZE + extradata.size ()), ms);
14811469 sampleDesc = new AP4_Av1SampleDescription (AP4_SAMPLE_FORMAT_AV01, stream->m_info .GetWidth (),
@@ -1525,7 +1513,7 @@ AP4_Movie* CSession::CreateMovieAtom(CStream* stream)
15251513}
15261514
15271515bool CSession::ExtractStreamProtectionData (PLAYLIST::CPeriod::PSSHSet& sessionPsshset,
1528- AP4_DataBuffer& init_data ,
1516+ std::vector< uint8_t >& initData ,
15291517 std::string keySystem)
15301518{
15311519 keySystem = STRING::ToHexadecimal (keySystem);
@@ -1547,11 +1535,13 @@ bool CSession::ExtractStreamProtectionData(PLAYLIST::CPeriod::PSSHSet& sessionPs
15471535 }
15481536 AP4_Array<AP4_PsshAtom>& pssh{movie->GetPsshAtoms ()};
15491537
1550- for (unsigned int i = 0 ; init_data. GetDataSize () == 0 && i < pssh.ItemCount (); i++)
1538+ for (unsigned int i = 0 ; initData. size () == 0 && i < pssh.ItemCount (); i++)
15511539 {
15521540 if (std::memcmp (pssh[i].GetSystemId (), keySystem.c_str (), 16 ) == 0 )
15531541 {
1554- init_data.AppendData (pssh[i].GetData ().GetData (), pssh[i].GetData ().GetDataSize ());
1542+ const AP4_DataBuffer& dataBuf = pssh[i].GetData ();
1543+ initData.insert (initData.end (), dataBuf.GetData (), dataBuf.GetData () + dataBuf.GetDataSize ());
1544+
15551545 if (sessionPsshset.defaultKID_ .empty ())
15561546 {
15571547 if (pssh[i].GetKid (0 ))
@@ -1592,5 +1582,5 @@ bool CSession::ExtractStreamProtectionData(PLAYLIST::CPeriod::PSSHSet& sessionPs
15921582 }
15931583
15941584 stream.Disable ();
1595- return init_data. GetDataSize () > 0 ;
1585+ return initData. size () > 0 ;
15961586}
0 commit comments