From 224e49c1a7701f35d0cf07dc1c7f4bf908de5792 Mon Sep 17 00:00:00 2001 From: Portisch Date: Wed, 7 Jul 2021 09:14:29 +0200 Subject: [PATCH] cdm_adapter: do not SetTimer when session get closed Block SetTimer while CloseSession is active to avoid endless loop. --- wvdecrypter/cdm/media/cdm/cdm_adapter.cc | 15 ++++++++++++--- wvdecrypter/cdm/media/cdm/cdm_adapter.h | 5 +++++ wvdecrypter/wvdecrypter.cpp | 9 +++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/wvdecrypter/cdm/media/cdm/cdm_adapter.cc b/wvdecrypter/cdm/media/cdm/cdm_adapter.cc index 96a4b6982..c48f2aade 100644 --- a/wvdecrypter/cdm/media/cdm/cdm_adapter.cc +++ b/wvdecrypter/cdm/media/cdm/cdm_adapter.cc @@ -5,7 +5,6 @@ #include "cdm_adapter.h" #include #include -#include #define DCHECK(condition) assert(condition) @@ -135,6 +134,7 @@ CdmAdapter::CdmAdapter( , cdm_config_(cdm_config) , active_buffer_(0) , cdm9_(0), cdm10_(0), cdm11_(0) +, session_active_(false) { //DCHECK(!key_system_.empty()); Initialize(); @@ -328,10 +328,16 @@ void CdmAdapter::UpdateSession(uint32_t promise_id, response, response_size); } +void CdmAdapter::SetSessionActive() +{ + session_active_ = true; +} + void CdmAdapter::CloseSession(uint32_t promise_id, const char* session_id, uint32_t session_id_size) { + session_active_ = false; exit_thread_flag = true; while (timer_thread_running) { @@ -506,8 +512,11 @@ cdm::Buffer* CdmAdapter::Allocate(uint32_t capacity) void CdmAdapter::SetTimer(int64_t delay_ms, void* context) { //LICENSERENEWAL - exit_thread_flag = false; - std::thread(timerfunc, shared_from_this(), delay_ms, context).detach(); + if (session_active_) + { + exit_thread_flag = false; + std::thread(timerfunc, shared_from_this(), delay_ms, context).detach(); + } } cdm::Time CdmAdapter::GetCurrentWallTime() diff --git a/wvdecrypter/cdm/media/cdm/cdm_adapter.h b/wvdecrypter/cdm/media/cdm/cdm_adapter.h index d722f6cf0..89afef688 100644 --- a/wvdecrypter/cdm/media/cdm/cdm_adapter.h +++ b/wvdecrypter/cdm/media/cdm/cdm_adapter.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "../../base/native_library.h" #include "../../base/compiler_specific.h" @@ -100,6 +101,8 @@ class CdmAdapter : public std::enable_shared_from_this const uint8_t* response, uint32_t response_size); + void SetSessionActive(); + void CloseSession(uint32_t promise_id, const char* session_id, uint32_t session_id_size); @@ -238,6 +241,8 @@ class CdmAdapter : public std::enable_shared_from_this cdm::ContentDecryptionModule_10 *cdm10_; cdm::ContentDecryptionModule_11 *cdm11_; + std::atomic session_active_; + DISALLOW_COPY_AND_ASSIGN(CdmAdapter); }; diff --git a/wvdecrypter/wvdecrypter.cpp b/wvdecrypter/wvdecrypter.cpp index 88b961f1f..08a3d30ad 100644 --- a/wvdecrypter/wvdecrypter.cpp +++ b/wvdecrypter/wvdecrypter.cpp @@ -174,6 +174,7 @@ class WV_CencSingleSampleDecrypter : public AP4_CencSingleSampleDecrypter void GetCapabilities(const uint8_t* key, uint32_t media, SSD_DECRYPTER::SSD_CAPS &caps); virtual const char *GetSessionId() override; + void SetSessionActive(); void CloseSessionId(); void SetSession(const char* session, uint32_t session_size, const uint8_t *data, size_t data_size) { @@ -390,7 +391,10 @@ void WV_DRM::OnCDMMessage(const char* session, uint32_t session_size, CDMADPMSG return; if (msg == CDMADPMSG::kSessionMessage) + { (*b)->SetSession(session, session_size, data, data_size); + (*b)->SetSessionActive(); + } else if (msg == CDMADPMSG::kSessionKeysChange) (*b)->AddSessionKey(data, data_size, status); }; @@ -572,6 +576,11 @@ const char *WV_CencSingleSampleDecrypter::GetSessionId() return session_.empty()? nullptr : session_.c_str(); } +void WV_CencSingleSampleDecrypter::SetSessionActive() +{ + drm_.GetCdmAdapter()->SetSessionActive(); +} + void WV_CencSingleSampleDecrypter::CloseSessionId() { if (!session_.empty())