Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player_avplay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.1

* Update the error callback when DRM license acquisition fails.

## 0.8.0

* Support parsing SMPE-TT subtitle attributes for DASH.
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To use this package, add `video_player_avplay` as a dependency in your `pubspec.

```yaml
dependencies:
video_player_avplay: ^0.8.0
video_player_avplay: ^0.8.1
```
Then you can import `video_player_avplay` in your Dart code:
Expand Down
9 changes: 8 additions & 1 deletion packages/video_player_avplay/lib/src/drm_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ class DrmConfigs {
this.type = DrmType.none,
this.licenseServerUrl,
this.licenseCallback,
});
}) : assert(
(licenseServerUrl != null) ^ (licenseCallback != null),
'Either licenseServerUrl or licenseCallback should be specified, but not both.',
),
assert(
licenseServerUrl == null || licenseServerUrl != '',
'License server URL cannot be empty.',
);

/// The DRM type.
final DrmType type;
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplay/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avplay
description: Flutter plugin for displaying inline video on Tizen TV devices.
homepage: https://github.com/flutter-tizen/plugins
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_avplay
version: 0.8.0
version: 0.8.1

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down
51 changes: 40 additions & 11 deletions packages/video_player_avplay/tizen/src/drm_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool DrmManager::SetChallenge(const std::string &media_url,
return DM_ERROR_NONE == SetChallenge(media_url);
}

void DrmManager::ReleaseDrmSession() {
void DrmManager::StopDrmSession() {
if (drm_session_ == nullptr) {
LOG_ERROR("[DrmManager] Already released.");
return;
Expand All @@ -109,8 +109,15 @@ void DrmManager::ReleaseDrmSession() {
LOG_ERROR("[DrmManager] Fail to set finalize to drm session: %s",
get_error_message(ret));
}
}

ret = DrmManagerProxy::GetInstance().DMGRReleaseDRMSession(drm_session_);
void DrmManager::ReleaseDrmSession() {
if (drm_session_ == nullptr) {
LOG_ERROR("[DrmManager] Already released.");
return;
}

int 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 Down Expand Up @@ -241,13 +248,16 @@ bool DrmManager::ProcessLicense(DataForLicenseProcess &data) {
static_cast<DrmLicenseHelper::DrmType>(drm_type_), nullptr, nullptr);
if (DRM_SUCCESS != ret || nullptr == response_data || 0 == response_len) {
LOG_ERROR("[DrmManager] Fail to get respone by license server url.");
SendInstallKeyError();
return false;
}
LOG_INFO("[DrmManager] Response length : %lu", response_len);
InstallKey(const_cast<void *>(
reinterpret_cast<const void *>(data.session_id.c_str())),
static_cast<void *>(response_data),
reinterpret_cast<void *>(response_len));
if (!InstallKey(const_cast<void *>(reinterpret_cast<const void *>(
data.session_id.c_str())),
static_cast<void *>(response_data),
reinterpret_cast<void *>(response_len))) {
SendInstallKeyError();
}
free(response_data);
} else if (request_license_channel_) {
// Get license via the Dart callback.
Expand All @@ -258,7 +268,7 @@ bool DrmManager::ProcessLicense(DataForLicenseProcess &data) {
return false;
}

void DrmManager::InstallKey(void *session_id, void *response_data,
bool DrmManager::InstallKey(void *session_id, void *response_data,
void *response_len) {
LOG_INFO("[DrmManager] Start install license.");

Expand All @@ -271,6 +281,22 @@ void DrmManager::InstallKey(void *session_id, void *response_data,
if (ret != DM_ERROR_NONE) {
LOG_ERROR("[DrmManager] Fail to install eme key: %s",
get_error_message(ret));
return false;
}
return true;
}

void DrmManager::SetErrorCallback(ErrorCallback callback) {
error_callback_ = callback;
}

void DrmManager::SendInstallKeyError() {
if (error_callback_) {
std::string error_code = "[DrmManager] error";
std::string error_message =
"Error: install drm key failed, please check licenseURL or network "
"connection.";
error_callback_(error_code, error_message);
}
}

Expand All @@ -296,13 +322,16 @@ void DrmManager::RequestLicense(std::string &session_id, std::string &message) {
response = std::get<std::vector<uint8_t>>(*success_value);
} else {
LOG_ERROR("[DrmManager] Fail to get response.");
SendInstallKeyError();
return;
}
LOG_INFO("[DrmManager] Response length : %d", response.size());
InstallKey(const_cast<void *>(
reinterpret_cast<const void *>(session_id.c_str())),
reinterpret_cast<void *>(response.data()),
reinterpret_cast<void *>(response.size()));
if (!InstallKey(const_cast<void *>(reinterpret_cast<const void *>(
session_id.c_str())),
reinterpret_cast<void *>(response.data()),
reinterpret_cast<void *>(response.size()))) {
SendInstallKeyError();
}
},
nullptr, nullptr);
request_license_channel_->InvokeMethod(
Expand Down
9 changes: 8 additions & 1 deletion packages/video_player_avplay/tizen/src/drm_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class DrmManager {
DRM_TYPE_WIDEVINECDM,
} DrmType;

using ErrorCallback =
std::function<void(const std::string &, const std::string &)>;

explicit DrmManager();
~DrmManager();

Expand All @@ -31,7 +34,10 @@ class DrmManager {
bool SecurityInitCompleteCB(int *drm_handle, unsigned int len,
unsigned char *pssh_data, void *user_data);
int UpdatePsshData(const void *data, int length);
void StopDrmSession();
void ReleaseDrmSession();
void SetErrorCallback(ErrorCallback callback);
void SendInstallKeyError();

private:
struct DataForLicenseProcess {
Expand All @@ -43,7 +49,7 @@ class DrmManager {
};

void RequestLicense(std::string &session_id, std::string &message);
void InstallKey(void *session_id, void *response_data, void *response_len);
bool InstallKey(void *session_id, void *response_data, void *response_len);
int SetChallenge(const std::string &media_url);

static int OnChallengeData(void *session_id, int message_type, void *message,
Expand All @@ -64,6 +70,7 @@ class DrmManager {
std::mutex queue_mutex_;
Ecore_Pipe *license_request_pipe_ = nullptr;
std::queue<DataForLicenseProcess> license_request_queue_;
ErrorCallback error_callback_;
};

#endif // FLUTTER_PLUGIN_DRM_MANAGER_H_
16 changes: 16 additions & 0 deletions packages/video_player_avplay/tizen/src/plus_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ PlusPlayer::PlusPlayer(flutter::BinaryMessenger *messenger,

PlusPlayer::~PlusPlayer() {
if (player_) {
if (drm_manager_) {
drm_manager_->StopDrmSession();
}
Stop(player_);
Close(player_);
UnregisterListener(player_);
Expand Down Expand Up @@ -249,6 +252,9 @@ bool PlusPlayer::Activate() {

bool PlusPlayer::Deactivate() {
if (is_prebuffer_mode_) {
if (drm_manager_) {
drm_manager_->StopDrmSession();
}
Stop(player_);
return true;
}
Expand Down Expand Up @@ -638,6 +644,12 @@ bool PlusPlayer::SetTrackSelection(int32_t track_id, std::string track_type) {
bool PlusPlayer::SetDrm(const std::string &uri, int drm_type,
const std::string &license_server_url) {
drm_manager_ = std::make_unique<DrmManager>();
DrmManager::ErrorCallback drm_error_callback =
[this](const std::string &error_code, const std::string &error_message) {
this->SendError(error_code, error_message);
};
drm_manager_->SetErrorCallback(drm_error_callback);

if (!drm_manager_->CreateDrmSession(drm_type, true)) {
LOG_ERROR("[PlusPlayer] Fail to create drm session.");
return false;
Expand Down Expand Up @@ -798,6 +810,10 @@ bool PlusPlayer::StopAndClose() {
return true;
}

if (drm_manager_) {
drm_manager_->StopDrmSession();
}

if (!::Stop(player_)) {
LOG_ERROR("[PlusPlayer] Player fail to stop.");
return false;
Expand Down
Loading