17
17
#include " common/Chooser.h"
18
18
#include " decrypters/DrmFactory.h"
19
19
#include " decrypters/Helpers.h"
20
+ #include " parser/PRProtectionParser.h"
20
21
#include " utils/Base64Utils.h"
21
22
#include " utils/CurlUtils.h"
22
23
#include " utils/StringUtils.h"
@@ -418,7 +419,7 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
418
419
if (sessionPsshset.adaptation_set_ ->GetStreamType () == StreamType::NOTYPE)
419
420
continue ;
420
421
421
- const std::vector< uint8_t > defaultKid = DRM::ConvertKidStrToBytes ( sessionPsshset.defaultKID_ ) ;
422
+ std::string defaultKidStr = sessionPsshset.defaultKID_ ;
422
423
std::string_view licenseDataStr = CSrvBroker::GetKodiProps ().GetLicenseData ();
423
424
424
425
if (m_adaptiveTree->GetTreeType () == adaptive::TreeType::SMOOTH_STREAMING)
@@ -441,7 +442,7 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
441
442
licenseData.empty () ? " " : " (with custom data)" );
442
443
443
444
std::vector<uint8_t > wvPsshData;
444
- if (DRM::MakeWidevinePsshData (defaultKid , licenseData, wvPsshData))
445
+ if (DRM::MakeWidevinePsshData (DRM::ConvertKidStrToBytes (defaultKidStr) , licenseData, wvPsshData))
445
446
DRM::MakePssh (DRM::ID_WIDEVINE, wvPsshData, initData);
446
447
}
447
448
}
@@ -469,6 +470,17 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
469
470
initData = BASE64::Decode (licenseDataStr);
470
471
}
471
472
473
+ // If no KID, but init data, extract the KID from init data
474
+ if (!initData.empty () && defaultKidStr.empty ())
475
+ {
476
+ CPsshParser parser;
477
+ if (parser.Parse (initData) && !parser.GetKeyIds ().empty ())
478
+ {
479
+ LOG::Log (LOGDEBUG, " Default KID parsed from init data" );
480
+ defaultKidStr = STRING::ToHexadecimal (parser.GetKeyIds ()[0 ]);
481
+ }
482
+ }
483
+
472
484
if (initData.empty () && sessionPsshset.m_licenseUrl .empty ())
473
485
{
474
486
if (!sessionPsshset.pssh_ .empty ())
@@ -485,6 +497,8 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
485
497
}
486
498
}
487
499
500
+ const std::vector<uint8_t > defaultKid = DRM::ConvertKidStrToBytes (defaultKidStr);
501
+
488
502
if (addDefaultKID && ses == 1 && session.m_cencSingleSampleDecrypter )
489
503
{
490
504
// If the CDM has been pre-initialized, on non-android systems
0 commit comments