diff --git a/packages/video_player_videohole/tizen/src/drm/drm_license_request.h b/packages/video_player_videohole/tizen/src/drm/drm_license_request.h index 429e88e26..e83c00023 100644 --- a/packages/video_player_videohole/tizen/src/drm/drm_license_request.h +++ b/packages/video_player_videohole/tizen/src/drm/drm_license_request.h @@ -12,8 +12,15 @@ using OnLicenseRequestDone = std::function& response_data)>; -class DrmLicenseRequest - : public std::enable_shared_from_this { + +struct DataForLicenseProcess { + DataForLicenseProcess(void* session_id, void* message, int message_length) + : session_id(static_cast(session_id)), + message(static_cast(message), message_length) {} + std::string session_id; + std::string message; +}; +class DrmLicenseRequest { public: explicit DrmLicenseRequest( OnLicenseRequestDone on_license_request_done_callback) @@ -21,11 +28,14 @@ class DrmLicenseRequest virtual ~DrmLicenseRequest() {} virtual void RequestLicense(void* session_id, int message_type, void* message, int message_length) = 0; - virtual void OnLicenseResponse(const std::string& session_id, - const std::vector& response_data) = 0; + void OnLicenseResponse(const std::string& session_id, + const std::vector& response_data) { + if (on_license_request_done_callback_) { + on_license_request_done_callback_(session_id, response_data); + } + } protected: - std::shared_ptr getShared() { return shared_from_this(); } OnLicenseRequestDone on_license_request_done_callback_ = nullptr; }; #endif // FLUTTER_PLUGIN_DRM_LICENSE_REQUEST_H_ diff --git a/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.cc b/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.cc index b4ad1a540..5b2b57e7f 100644 --- a/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.cc +++ b/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.cc @@ -31,7 +31,7 @@ void DrmLicenseRequestChannel::RequestLicense(void *session_id, int message_type, void *message, int message_length) { DataForLicenseProcess process_message(session_id, message, message_length); - PushLicenseRequestData(process_message); + PushLicenseRequest(process_message); } void DrmLicenseRequestChannel::ExecuteRequest() { @@ -43,7 +43,7 @@ void DrmLicenseRequestChannel::ExecuteRequest() { } } -void DrmLicenseRequestChannel::PushLicenseRequestData( +void DrmLicenseRequestChannel::PushLicenseRequest( const DataForLicenseProcess &data) { std::lock_guard lock(queue_mutex_); license_request_queue_.push(data); @@ -87,13 +87,6 @@ void DrmLicenseRequestChannel::RequestLicense(const std::string &session_id, std::move(result_handler)); } -void DrmLicenseRequestChannel::OnLicenseResponse( - const std::string &session_id, const std::vector &response_data) { - if (on_license_request_done_callback_) { - on_license_request_done_callback_(session_id, response_data); - } -} - DrmLicenseRequestChannel::~DrmLicenseRequestChannel() { if (license_request_pipe_) { ecore_pipe_del(license_request_pipe_); diff --git a/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.h b/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.h index 62ff3e859..d051d83ca 100644 --- a/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.h +++ b/packages/video_player_videohole/tizen/src/drm/drm_license_request_channel.h @@ -16,14 +16,6 @@ #include "drm_license_request.h" -struct DataForLicenseProcess { - DataForLicenseProcess(void *session_id, void *message, int message_length) - : session_id(static_cast(session_id)), - message(static_cast(message), message_length) {} - std::string session_id; - std::string message; -}; - class DrmLicenseRequestChannel : public DrmLicenseRequest { public: explicit DrmLicenseRequestChannel( @@ -32,12 +24,10 @@ class DrmLicenseRequestChannel : public DrmLicenseRequest { void RequestLicense(void *session_id, int message_type, void *message, int message_length) override; ~DrmLicenseRequestChannel(); - void OnLicenseResponse(const std::string &session_id, - const std::vector &response_data) override; private: void ExecuteRequest(); - void PushLicenseRequestData(const DataForLicenseProcess &data); + void PushLicenseRequest(const DataForLicenseProcess &data); void RequestLicense(const std::string &session_id, const std::string &message); std::unique_ptr> diff --git a/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.cc b/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.cc index 4df112a4c..e910ccbc1 100644 --- a/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.cc +++ b/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.cc @@ -16,26 +16,59 @@ constexpr int kMessageRequestLicense = 0; struct Message { Eina_Thread_Queue_Msg head; int event; - std::string license_server_url; - std::string challenge; - std::string session_id; - int drm_type; + DataForLicenseProcess* data_for_request = nullptr; }; +LicenseResponsePipe::LicenseResponsePipe( + OnLicenseRequestDone on_license_request_done_callback) + : on_license_request_done_callback_(on_license_request_done_callback) { + license_response_pipe_ = ecore_pipe_add( + [](void* data, void* buffer, unsigned int nbyte) -> void { + auto* self = static_cast(data); + self->ExecuteResponse(); + }, + this); +} + +void LicenseResponsePipe::ExecuteResponse() { + std::lock_guard lock(queue_mutex_); + while (!license_response_queue_.empty()) { + if (on_license_request_done_callback_) { + auto response_data = license_response_queue_.front(); + on_license_request_done_callback_(response_data.first, + response_data.second); + } + license_response_queue_.pop(); + } +} + +void LicenseResponsePipe::PushLicenseResponse( + const std::string& session_id, const std::vector& response_data) { + std::lock_guard lock(queue_mutex_); + license_response_queue_.push(std::make_pair(session_id, response_data)); + ecore_pipe_write(license_response_pipe_, nullptr, 0); +} + +LicenseResponsePipe::~LicenseResponsePipe() { + if (license_response_pipe_) { + ecore_pipe_del(license_response_pipe_); + license_response_pipe_ = nullptr; + } +} + DrmLicenseRequestNative::DrmLicenseRequestNative( int drm_type, const std::string& license_server_url, OnLicenseRequestDone on_license_request_done_callback) : DrmLicenseRequest(on_license_request_done_callback), drm_type_(drm_type), license_server_url_(license_server_url) { + license_response_pipe_ = std::make_shared( + [this](const std::string& session_id, + const std::vector& response_data) { + OnLicenseResponse(session_id, response_data); + }); license_request_thread_ = ecore_thread_feedback_run(RunLoop, nullptr, nullptr, nullptr, this, EINA_TRUE); - license_response_pipe_ = ecore_pipe_add( - [](void* data, void* buffer, unsigned int nbyte) -> void { - auto* self = static_cast(data); - self->ExecuteResponse(); - }, - this); } void DrmLicenseRequestNative::RequestLicense(void* session_id, int message_type, @@ -55,11 +88,8 @@ void DrmLicenseRequestNative::RequestLicense(void* session_id, int message_type, Message* request_message = static_cast( eina_thread_queue_send(license_request_queue_, sizeof(Message), &ref)); request_message->event = kMessageRequestLicense; - request_message->drm_type = drm_type_; - request_message->challenge = - std::string(static_cast(message), message_length); - request_message->license_server_url = license_server_url_; - request_message->session_id = std::string(static_cast(session_id)); + request_message->data_for_request = + new DataForLicenseProcess(session_id, message, message_length); eina_thread_queue_send_done(license_request_queue_, ref); } @@ -90,19 +120,25 @@ void DrmLicenseRequestNative::RunLoop(void* data, Ecore_Thread* thread) { } auto* self = static_cast(data); self->license_request_queue_ = license_request_queue; - std::weak_ptr weak_self = self->getShared(); + std::weak_ptr weak_pipe = self->license_response_pipe_; + std::string license_server_url = self->license_server_url_; + int drm_type = self->drm_type_; while (!ecore_thread_check(thread)) { void* ref; Message* message = static_cast( eina_thread_queue_wait(license_request_queue, &ref)); if (message->event == kMessageQuit) { + LOG_DEBUG("Receive kMessageQuit message"); eina_thread_queue_wait_done(license_request_queue, ref); break; } - std::string license_server_url = message->license_server_url; - std::string challenge = message->challenge; - std::string session_id = message->session_id; - int drm_type = message->drm_type; + if (message->data_for_request == nullptr) { + LOG_ERROR("data_for_request is null"); + continue; + } + std::string challenge = message->data_for_request->message; + std::string session_id = message->data_for_request->session_id; + delete message->data_for_request; eina_thread_queue_wait_done(license_request_queue, ref); // Get license via the license server. unsigned char* response_data = nullptr; @@ -112,18 +148,20 @@ void DrmLicenseRequestNative::RunLoop(void* data, Ecore_Thread* thread) { license_server_url.c_str(), challenge.c_str(), challenge.size(), &response_data, &response_len, static_cast(drm_type), nullptr, nullptr); + if (DRM_SUCCESS != ret || nullptr == response_data || 0 == response_len) { LOG_ERROR("Fail to get respone by license server url."); continue; } LOG_INFO("Response length : %lu", response_len); - if (weak_self.expired()) { + if (weak_pipe.expired()) { + LOG_DEBUG("weak_pipe expired"); free(response_data); break; } auto response_vec = std::vector(response_data, response_data + response_len); - weak_self.lock()->OnLicenseResponse(session_id, response_vec); + weak_pipe.lock()->PushLicenseResponse(session_id, response_vec); free(response_data); } if (license_request_queue) { @@ -131,25 +169,6 @@ void DrmLicenseRequestNative::RunLoop(void* data, Ecore_Thread* thread) { } } -void DrmLicenseRequestNative::ExecuteResponse() { - std::lock_guard lock(queue_mutex_); - while (!license_response_queue_.empty()) { - if (on_license_request_done_callback_) { - auto response_data = license_response_queue_.front(); - on_license_request_done_callback_(response_data.first, - response_data.second); - } - license_response_queue_.pop(); - } -} - -void DrmLicenseRequestNative::OnLicenseResponse( - const std::string& session_id, const std::vector& response_data) { - std::lock_guard lock(queue_mutex_); - license_response_queue_.push(std::make_pair(session_id, response_data)); - ecore_pipe_write(license_response_pipe_, nullptr, 0); -} - DrmLicenseRequestNative::~DrmLicenseRequestNative() { StopMessageQueue(); if (license_request_thread_) { diff --git a/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.h b/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.h index 04a6026e1..171016f05 100644 --- a/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.h +++ b/packages/video_player_videohole/tizen/src/drm/drm_license_request_native.h @@ -15,6 +15,23 @@ #include "drm_license_request.h" +class LicenseResponsePipe { + public: + explicit LicenseResponsePipe( + OnLicenseRequestDone on_license_request_done_callback); + virtual ~LicenseResponsePipe(); + void ExecuteResponse(); + void PushLicenseResponse(const std::string& session_id, + const std::vector& response_data); + + private: + std::mutex queue_mutex_; + Ecore_Pipe* license_response_pipe_ = nullptr; + std::queue>> + license_response_queue_; + OnLicenseRequestDone on_license_request_done_callback_ = nullptr; +}; + class DrmLicenseRequestNative : public DrmLicenseRequest { public: explicit DrmLicenseRequestNative( @@ -24,22 +41,14 @@ class DrmLicenseRequestNative : public DrmLicenseRequest { void RequestLicense(void* session_id, int message_type, void* message, int message_length) override; - protected: - void OnLicenseResponse(const std::string& session_id, - const std::vector& response_data) override; - private: - void StopMessageQueue(); - void ExecuteResponse(); static void RunLoop(void* data, Ecore_Thread* thread); + void StopMessageQueue(); + int drm_type_; Ecore_Thread* license_request_thread_ = nullptr; Eina_Thread_Queue* license_request_queue_ = nullptr; - int drm_type_; std::string license_server_url_; - std::mutex queue_mutex_; - Ecore_Pipe* license_response_pipe_ = nullptr; - std::queue>> - license_response_queue_; + std::shared_ptr license_response_pipe_; }; #endif diff --git a/packages/video_player_videohole/tizen/src/drm/drm_manager.cc b/packages/video_player_videohole/tizen/src/drm/drm_manager.cc index ee5e62381..0fcc70028 100644 --- a/packages/video_player_videohole/tizen/src/drm/drm_manager.cc +++ b/packages/video_player_videohole/tizen/src/drm/drm_manager.cc @@ -84,7 +84,7 @@ bool DrmManager::CreateDrmSession(int drm_type, bool local_mode) { bool DrmManager::SetChallenge(const std::string &media_url, flutter::BinaryMessenger *binary_messenger) { - drm_license_request_ = std::make_shared( + drm_license_request_ = std::make_unique( binary_messenger, [this](const std::string &session_id, const std::vector &response_data) { InstallKey(session_id, response_data); @@ -95,7 +95,7 @@ bool DrmManager::SetChallenge(const std::string &media_url, bool DrmManager::SetChallenge(const std::string &media_url, const std::string &license_server_url) { license_server_url_ = license_server_url; - drm_license_request_ = std::make_shared( + drm_license_request_ = std::make_unique( drm_type_, license_server_url, [this](const std::string &session_id, const std::vector &response_data) { diff --git a/packages/video_player_videohole/tizen/src/drm/drm_manager.h b/packages/video_player_videohole/tizen/src/drm/drm_manager.h index 2230ed0e4..6f95580e5 100644 --- a/packages/video_player_videohole/tizen/src/drm/drm_manager.h +++ b/packages/video_player_videohole/tizen/src/drm/drm_manager.h @@ -53,7 +53,7 @@ class DrmManager { std::string license_server_url_; bool initialized_ = false; - std::shared_ptr drm_license_request_; + std::unique_ptr drm_license_request_; }; #endif // FLUTTER_PLUGIN_DRM_MANAGER_H_