Skip to content

Commit

Permalink
cdm_adapter: do not SetTimer when session get closed
Browse files Browse the repository at this point in the history
Block SetTimer while CloseSession is active to avoid endless loop.
  • Loading branch information
Portisch committed Jul 8, 2021
1 parent 212f16e commit 224e49c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
15 changes: 12 additions & 3 deletions wvdecrypter/cdm/media/cdm/cdm_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "cdm_adapter.h"
#include <chrono>
#include <thread>
#include <atomic>

#define DCHECK(condition) assert(condition)

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions wvdecrypter/cdm/media/cdm/cdm_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <inttypes.h>
#include <memory>
#include <mutex>
#include <atomic>

#include "../../base/native_library.h"
#include "../../base/compiler_specific.h"
Expand Down Expand Up @@ -100,6 +101,8 @@ class CdmAdapter : public std::enable_shared_from_this<CdmAdapter>
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);
Expand Down Expand Up @@ -238,6 +241,8 @@ class CdmAdapter : public std::enable_shared_from_this<CdmAdapter>
cdm::ContentDecryptionModule_10 *cdm10_;
cdm::ContentDecryptionModule_11 *cdm11_;

std::atomic<bool> session_active_;

DISALLOW_COPY_AND_ASSIGN(CdmAdapter);
};

Expand Down
9 changes: 9 additions & 0 deletions wvdecrypter/wvdecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 224e49c

Please sign in to comment.