Skip to content

Commit

Permalink
Change drm manager proxy to a singleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei-guan committed Jan 22, 2024
1 parent d6dcd0d commit 8b09967
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
40 changes: 20 additions & 20 deletions packages/video_player_avplay/tizen/src/drm_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ static std::string GetDrmSubType(int drm_type) {
}
}

DrmManager::DrmManager()
: drm_manager_proxy_(std::make_unique<DrmManagerProxy>()),
drm_type_(DM_TYPE_NONE) {
DrmManager::DrmManager() : drm_type_(DM_TYPE_NONE) {
license_request_pipe_ = ecore_pipe_add(
[](void *data, void *buffer, unsigned int nbyte) -> void {
auto *self = static_cast<DrmManager *>(data);
Expand All @@ -42,14 +40,14 @@ DrmManager::~DrmManager() {

bool DrmManager::CreateDrmSession(int drm_type, bool local_mode) {
if (local_mode) {
drm_manager_proxy_->DMGRSetDRMLocalMode();
DrmManagerProxy::GetInstance().DMGRSetDRMLocalMode();
}

drm_type_ = drm_type;
std::string sub_type = GetDrmSubType(drm_type);
LOG_INFO("[DrmManager] drm type is %s", sub_type.c_str());
drm_session_ =
drm_manager_proxy_->DMGRCreateDRMSession(DM_TYPE_EME, sub_type.c_str());
drm_session_ = DrmManagerProxy::GetInstance().DMGRCreateDRMSession(
DM_TYPE_EME, sub_type.c_str());
if (!drm_session_) {
LOG_ERROR("[DrmManager] Fail to create drm session.");
return false;
Expand All @@ -60,7 +58,7 @@ bool DrmManager::CreateDrmSession(int drm_type, bool local_mode) {
SetDataParam_t configure_param = {};
configure_param.param1 = reinterpret_cast<void *>(OnDrmManagerError);
configure_param.param2 = drm_session_;
int ret = drm_manager_proxy_->DMGRSetData(
int ret = DrmManagerProxy::GetInstance().DMGRSetData(
drm_session_, "error_event_callback", &configure_param);
if (ret != DM_ERROR_NONE) {
LOG_ERROR(
Expand Down Expand Up @@ -97,21 +95,22 @@ void DrmManager::ReleaseDrmSession() {
SetDataParam_t challenge_data_param = {};
challenge_data_param.param1 = nullptr;
challenge_data_param.param2 = nullptr;
int ret = drm_manager_proxy_->DMGRSetData(
int ret = DrmManagerProxy::GetInstance().DMGRSetData(
drm_session_, "eme_request_key_callback", &challenge_data_param);
if (ret != DM_ERROR_NONE) {
LOG_ERROR("[DrmManager] Fail to unset eme_request_key_callback: %s",
get_error_message(ret));
}

ret = drm_manager_proxy_->DMGRSetData(drm_session_, "Finalize", nullptr);
ret = DrmManagerProxy::GetInstance().DMGRSetData(drm_session_, "Finalize",
nullptr);

if (ret != DM_ERROR_NONE) {
LOG_ERROR("[DrmManager] Fail to set finalize to drm session: %s",
get_error_message(ret));
}

ret = drm_manager_proxy_->DMGRReleaseDRMSession(drm_session_);
ret = DrmManagerProxy::GetInstance().DMGRReleaseDRMSession(drm_session_);
if (ret != DM_ERROR_NONE) {
LOG_ERROR("[DrmManager] Fail to release drm session: %s",
get_error_message(ret));
Expand All @@ -122,8 +121,8 @@ void DrmManager::ReleaseDrmSession() {
bool DrmManager::GetDrmHandle(int *handle) {
if (drm_session_) {
*handle = 0;
int ret =
drm_manager_proxy_->DMGRGetData(drm_session_, "drm_handle", handle);
int ret = DrmManagerProxy::GetInstance().DMGRGetData(drm_session_,
"drm_handle", handle);
if (ret != DM_ERROR_NONE) {
LOG_ERROR("[DrmManager] Fail to get drm_handle from drm session: %s",
get_error_message(ret));
Expand All @@ -146,8 +145,8 @@ int DrmManager::UpdatePsshData(const void *data, int length) {
SetDataParam_t pssh_data_param = {};
pssh_data_param.param1 = const_cast<void *>(data);
pssh_data_param.param2 = reinterpret_cast<void *>(length);
int ret = drm_manager_proxy_->DMGRSetData(drm_session_, "update_pssh_data",
&pssh_data_param);
int ret = DrmManagerProxy::GetInstance().DMGRSetData(
drm_session_, "update_pssh_data", &pssh_data_param);
if (DM_ERROR_NONE != ret) {
LOG_ERROR("[DrmManager] Fail to set update_pssh_data to drm session: %s",
get_error_message(ret));
Expand All @@ -167,7 +166,7 @@ bool DrmManager::SecurityInitCompleteCB(int *drm_handle, unsigned int len,
}
security_param.param2 = drm_session_;

return drm_manager_proxy_->DMGRSecurityInitCompleteCB(
return DrmManagerProxy::GetInstance().DMGRSecurityInitCompleteCB(
drm_handle, len, pssh_data, &security_param);
}

Expand All @@ -180,7 +179,7 @@ int DrmManager::SetChallenge(const std::string &media_url) {
SetDataParam_t challenge_data_param = {};
challenge_data_param.param1 = reinterpret_cast<void *>(OnChallengeData);
challenge_data_param.param2 = this;
int ret = drm_manager_proxy_->DMGRSetData(
int ret = DrmManagerProxy::GetInstance().DMGRSetData(
drm_session_, "eme_request_key_callback", &challenge_data_param);
if (ret != DM_ERROR_NONE) {
LOG_ERROR(
Expand All @@ -190,7 +189,7 @@ int DrmManager::SetChallenge(const std::string &media_url) {
return ret;
}

ret = drm_manager_proxy_->DMGRSetData(
ret = DrmManagerProxy::GetInstance().DMGRSetData(
drm_session_, "set_playready_manifest",
static_cast<void *>(const_cast<char *>(media_url.c_str())));
if (ret != DM_ERROR_NONE) {
Expand All @@ -200,7 +199,8 @@ int DrmManager::SetChallenge(const std::string &media_url) {
return ret;
}

ret = drm_manager_proxy_->DMGRSetData(drm_session_, "Initialize", nullptr);
ret = DrmManagerProxy::GetInstance().DMGRSetData(drm_session_, "Initialize",
nullptr);
if (ret != DM_ERROR_NONE) {
LOG_ERROR("[DrmManager] Fail to set initialize to drm session: %s",
get_error_message(ret));
Expand Down Expand Up @@ -266,8 +266,8 @@ void DrmManager::InstallKey(void *session_id, void *response_data,
license_param.param1 = session_id;
license_param.param2 = response_data;
license_param.param3 = response_len;
int ret = drm_manager_proxy_->DMGRSetData(drm_session_, "install_eme_key",
&license_param);
int ret = DrmManagerProxy::GetInstance().DMGRSetData(
drm_session_, "install_eme_key", &license_param);
if (ret != DM_ERROR_NONE) {
LOG_ERROR("[DrmManager] Fail to install eme key: %s",
get_error_message(ret));
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplay/tizen/src/drm_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DrmManager {
request_license_channel_;

void *drm_session_ = nullptr;
std::unique_ptr<DrmManagerProxy> drm_manager_proxy_;
//std::unique_ptr<DrmManagerProxy> drm_manager_proxy_;

int drm_type_;
std::string license_server_url_;
Expand Down
12 changes: 10 additions & 2 deletions packages/video_player_avplay/tizen/src/drm_manager_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ typedef int (*FuncDMGRReleaseDRMSession)(DRMSessionHandle_t drm_session);

class DrmManagerProxy {
public:
explicit DrmManagerProxy();
~DrmManagerProxy();
static DrmManagerProxy& GetInstance() {
static DrmManagerProxy instance;
return instance;
}
DrmManagerProxy(const DrmManagerProxy&) = delete;
DrmManagerProxy(const DrmManagerProxy&&) = delete;
DrmManagerProxy& operator=(const DrmManagerProxy&) = delete;

int DMGRSetData(DRMSessionHandle_t drm_session, const char* data_type,
void* input_data);
int DMGRGetData(DRMSessionHandle_t drm_session, const char* data_type,
Expand All @@ -123,6 +129,8 @@ class DrmManagerProxy {
int DMGRReleaseDRMSession(DRMSessionHandle_t drm_session);

private:
DrmManagerProxy();
~DrmManagerProxy();
void* drm_manager_handle_ = nullptr;
FuncDMGRSetData dmgr_set_data_ = nullptr;
FuncDMGRGetData dmgr_get_data_ = nullptr;
Expand Down

0 comments on commit 8b09967

Please sign in to comment.