@@ -45,36 +45,7 @@ STREAM_CRYPTO_KEY_SYSTEM KSToCryptoKeySystem(std::string_view keySystem)
4545 else
4646 return STREAM_CRYPTO_KEY_SYSTEM_NONE;
4747}
48- /*
49- SResult CreateDRM(std::string_view keySystem, std::shared_ptr<DRM::IDecrypter>& drm)
50- {
51- std::string decrypterPath = CSrvBroker::GetSettings().GetDecrypterPath();
52- if (decrypterPath.empty())
53- {
54- LOG::LogF(LOGERROR, "No decrypter path set in the add-on settings");
55- return SResult::Error(GUI::GetLocalizedString(30302));
56- }
57-
58- drm = DRM::FACTORY::GetDecrypter(KSToCryptoKeySystem(keySystem));
59-
60- if (!drm)
61- {
62- LOG::LogF(LOGERROR, "Unable to create the DRM decrypter");
63- return SResult::Error(GUI::GetLocalizedString(30303));
64- }
65-
66- drm->SetLibraryPath(decrypterPath);
67-
68- if (!drm->Initialize())
69- {
70- drm = nullptr;
71- LOG::LogF(LOGERROR, "Unable to initialize the DRM decrypter");
72- return SResult::Error(GUI::GetLocalizedString(30303));
73- }
7448
75- return SResultCode::OK;
76- }
77- */
7849/* !
7950 * \brief Get a DRMInfo by Key System
8051 * \param drmInfos The manifest DRM info
@@ -128,10 +99,10 @@ bool GetCapabilities(const std::optional<bool> isForceSecureDecoder,
12899}
129100} // unnamed namespace
130101
131- void DRM::CDRMEngine::Initialize ()
102+ bool DRM::CDRMEngine::Initialize ()
132103{
133104 if (!m_drms.empty ())
134- return ; // assume as already initialized
105+ return true ; // assume as already initialized
135106
136107 // ! @todo: to test a way to initialize DRM when manifest is downloaded/parsed
137108 // ! in the hoping to have a more smoother playback transition from unencrypted->to->encrypted periods
@@ -169,7 +140,8 @@ void DRM::CDRMEngine::Initialize()
169140 {
170141 LOG::LogF (LOGERROR,
171142 " Cannot initialize DrmEngine, no decrypter path set in the add-on settings" );
172- return ;
143+ m_status = EngineStatus::DRM_ERROR;
144+ return false ;
173145 }
174146
175147 // Initialize DRMs
@@ -178,7 +150,10 @@ void DRM::CDRMEngine::Initialize()
178150 (*it)->SetLibraryPath (decrypterPath);
179151
180152 if (!(*it)->Initialize ()) // Failed to initialize DRM, delete it and go on
153+ {
154+ LOG::LogF (LOGERROR, " Unable to initialize %s DRM" , (*it)->GetName ().c_str ());
181155 it = drms.erase (it);
156+ }
182157 else
183158 ++it;
184159 }
@@ -193,6 +168,14 @@ void DRM::CDRMEngine::Initialize()
193168 m_drms.emplace_back (ks, drm);
194169 }
195170 }
171+
172+ if (m_drms.empty ())
173+ {
174+ LOG::LogF (LOGWARNING, " No DRM available" );
175+ return false ;
176+ }
177+
178+ return true ;
196179}
197180
198181bool DRM::CDRMEngine::PreInitializeDRM (DRMSession& session)
@@ -204,7 +187,8 @@ bool DRM::CDRMEngine::PreInitializeDRM(DRMSession& session)
204187 if (!propDrmCfg.priority .has_value () || propDrmCfg.priority != 1 || propDrmCfg.preInitData .empty ())
205188 return false ;
206189
207- Initialize ();
190+ if (!Initialize ())
191+ return false ;
208192
209193 // Pre-initialize the DRM is available for Widevine only.
210194 // Since the manifest will be downloaded later its assumed that
@@ -237,30 +221,31 @@ bool DRM::CDRMEngine::PreInitializeDRM(DRMSession& session)
237221 if (!drm)
238222 {
239223 m_status = EngineStatus::DRM_ERROR;
240- LOG::LogF (LOGERROR, " Cannot get the DRM instance" );
224+ LOG::LogF (LOGERROR, " Cannot get the DRM instance for keysystem %s " , m_keySystem. c_str () );
241225 GUI::ErrorDialog (GUI::GetLocalizedString (30303 ));
242226 return false ;
243227 }
244228
229+ LOG::LogF (LOGDEBUG, " Initializing session with KID: %s" , STRING::ToHexadecimal (kidData).c_str ());
230+
245231 DRM::Config drmCfg = CreateDRMConfig (m_keySystem, kodiProps.GetDrmConfig (m_keySystem));
246232
247- SResult ret = drm->OpenDRMSystem (drmCfg);
248- if (ret.IsFailed ())
233+ auto dec = drm->CreateSingleSampleDecrypter (drmCfg, kidData, CryptoMode::AES_CTR);
234+
235+ if (!dec)
249236 {
250- LOG::LogF (LOGERROR, " Failed to open the DRM" );
251- m_status = EngineStatus::DRM_ERROR;
252- GUI::ErrorDialog (ret.Message ());
237+ LOG::Log (LOGERROR, " Failed to initialize the %s DRM decrypter" , drm->GetName ().c_str ());
238+ m_status = EngineStatus::DECRYPTER_ERROR;
253239 return false ;
254240 }
255241
256- LOG::LogF (LOGDEBUG, " Initializing session with KID: %s" , STRING::ToHexadecimal (kidData).c_str ());
257-
258- auto dec = drm->CreateSingleSampleDecrypter (initData, kidData, " " , true , CryptoMode::AES_CTR);
242+ const SResult ret = dec->CreateSession (initData, " " , true );
259243
260- if (!dec )
244+ if (ret. IsFailed () )
261245 {
262- LOG::LogF (LOGERROR, " Failed to initialize the decrypter" );
263- m_status = EngineStatus::DECRYPTER_ERROR;
246+ LOG::LogF (LOGERROR, " Failed to create the DRM session" );
247+ m_status = EngineStatus::DRM_ERROR;
248+ GUI::ErrorDialog (ret.Message ());
264249 return false ;
265250 }
266251
@@ -291,7 +276,8 @@ bool DRM::CDRMEngine::InitializeSession(std::vector<DRM::DRMInfo> drmInfos,
291276 if (drmInfos.empty ())
292277 return false ;
293278
294- Initialize ();
279+ if (!Initialize ())
280+ return false ;
295281
296282 LOG::Log (LOGDEBUG, " Initialize crypto session" );
297283
@@ -428,7 +414,7 @@ bool DRM::CDRMEngine::InitializeSession(std::vector<DRM::DRMInfo> drmInfos,
428414 if (!drm)
429415 {
430416 m_status = EngineStatus::DRM_ERROR;
431- LOG::LogF (LOGERROR, " Cannot get the DRM instance" );
417+ LOG::LogF (LOGERROR, " Cannot get the DRM instance for keysystem %s " , m_keySystem. c_str () );
432418 GUI::ErrorDialog (GUI::GetLocalizedString (30303 ));
433419 return false ;
434420 }
@@ -438,26 +424,29 @@ bool DRM::CDRMEngine::InitializeSession(std::vector<DRM::DRMInfo> drmInfos,
438424 newSes.mediaType = mediaType;
439425 newSes.kid = drmInfo.defaultKid ;
440426
441- if (!newSes.drm ->IsInitialised ())
442- {
443- DRM::Config drmCfg = DRM::CreateDRMConfig (m_keySystem, drmPropCfg);
444- const SResult ret = newSes.drm ->OpenDRMSystem (drmCfg);
445- if (ret.IsFailed ())
446- {
447- LOG::LogF (LOGERROR, " Failed to open the DRM" );
448- m_status = EngineStatus::DRM_ERROR;
449- GUI::ErrorDialog (ret.Message ());
450- return false ;
451- }
452- }
427+ DRM::Config drmCfg = DRM::CreateDRMConfig (m_keySystem, drmPropCfg);
453428
454429 newSes.decrypter = newSes.drm ->CreateSingleSampleDecrypter (
455- drmInfo. initData , drmInfoKidBytes, drmInfo. licenseServerUri , false ,
430+ drmCfg , drmInfoKidBytes,
456431 drmInfo.cryptoMode == CryptoMode::NONE ? CryptoMode::AES_CTR : drmInfo.cryptoMode );
432+
457433 if (!newSes.decrypter )
458434 {
459- LOG::Log (LOGERROR, " Failed to initialize the decrypter" );
460435 m_status = EngineStatus::DECRYPTER_ERROR;
436+ LOG::Log (LOGERROR, " Failed to initialize the %s DRM decrypter" ,
437+ newSes.drm ->GetName ().c_str ());
438+ GUI::ErrorDialog (GUI::GetLocalizedString (30303 ));
439+ return false ;
440+ }
441+
442+ const SResult ret =
443+ newSes.decrypter ->CreateSession (drmInfo.initData , drmInfo.licenseServerUri , false );
444+
445+ if (ret.IsFailed ())
446+ {
447+ LOG::LogF (LOGERROR, " Failed to create the DRM session" );
448+ m_status = EngineStatus::DRM_ERROR;
449+ GUI::ErrorDialog (ret.Message ());
461450 return false ;
462451 }
463452
@@ -660,6 +649,7 @@ bool DRM::CDRMEngine::SelectDRM(std::vector<DRM::DRMInfo>& drmInfos)
660649 if (drmInfo)
661650 {
662651 m_keySystem = drm.keySystem ;
652+ LOG::LogF (LOGDEBUG, " Selected DRM key system: %s" , m_keySystem.c_str ());
663653 break ;
664654 }
665655 }
0 commit comments