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
1 change: 1 addition & 0 deletions packages/video_player_avplay/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Omit obvious local variable types.
* Reformat with a line length of 100.
* Replace Ecore pipes with GLib idle callbacks.

## 0.8.18

Expand Down
27 changes: 15 additions & 12 deletions packages/video_player_avplay/tizen/src/drm_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@ static std::string GetDrmSubType(int drm_type) {
}
}

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);
self->ExecuteRequest();
},
this);
}
DrmManager::DrmManager() : drm_type_(DM_TYPE_NONE) {}

DrmManager::~DrmManager() {
ReleaseDrmSession();
if (license_request_pipe_) {
ecore_pipe_del(license_request_pipe_);
license_request_pipe_ = nullptr;
std::lock_guard<std::mutex> lock(queue_mutex_);
if (license_request_source_) {
g_source_remove(license_request_source_);
}
}

Expand Down Expand Up @@ -344,11 +337,21 @@ void DrmManager::RequestLicense(std::string &session_id, std::string &message) {
void DrmManager::PushLicenseRequestData(DataForLicenseProcess &data) {
std::lock_guard<std::mutex> lock(queue_mutex_);
license_request_queue_.push(data);
ecore_pipe_write(license_request_pipe_, nullptr, 0);
if (license_request_source_ == 0) {
license_request_source_ = g_idle_add_full(
G_PRIORITY_DEFAULT,
[](gpointer data) -> gboolean {
auto *self = static_cast<DrmManager *>(data);
self->ExecuteRequest();
return G_SOURCE_REMOVE;
},
this, nullptr);
}
}

void DrmManager::ExecuteRequest() {
std::lock_guard<std::mutex> lock(queue_mutex_);
license_request_source_ = 0;
while (!license_request_queue_.empty()) {
DataForLicenseProcess data = license_request_queue_.front();
ProcessLicense(data);
Expand Down
4 changes: 2 additions & 2 deletions packages/video_player_avplay/tizen/src/drm_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef FLUTTER_PLUGIN_DRM_MANAGER_H_
#define FLUTTER_PLUGIN_DRM_MANAGER_H_

#include <Ecore.h>
#include <flutter/method_channel.h>
#include <glib.h>

#include <mutex>
#include <queue>
Expand Down Expand Up @@ -68,7 +68,7 @@ class DrmManager {
int drm_type_;
std::string license_server_url_;
std::mutex queue_mutex_;
Ecore_Pipe *license_request_pipe_ = nullptr;
guint license_request_source_ = 0;
std::queue<DataForLicenseProcess> license_request_queue_;
ErrorCallback error_callback_;
};
Expand Down
1 change: 1 addition & 0 deletions packages/video_player_avplay/tizen/src/plus_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <app_manager.h>
#include <system_info.h>
#include <unistd.h>

#include <sstream>

Expand Down
40 changes: 25 additions & 15 deletions packages/video_player_avplay/tizen/src/video_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@ static int64_t player_index = 1;

VideoPlayer::VideoPlayer(flutter::BinaryMessenger *messenger,
FlutterDesktopViewRef flutter_view)
: binary_messenger_(messenger), flutter_view_(flutter_view) {
sink_event_pipe_ = ecore_pipe_add(
[](void *data, void *buffer, unsigned int nbyte) -> void {
auto *self = static_cast<VideoPlayer *>(data);
self->ExecuteSinkEvents();
},
this);
}
: binary_messenger_(messenger), flutter_view_(flutter_view) {}

VideoPlayer::~VideoPlayer() {
if (sink_event_pipe_) {
ecore_pipe_del(sink_event_pipe_);
sink_event_pipe_ = nullptr;
std::lock_guard<std::mutex> lock(queue_mutex_);
if (sink_event_source_) {
g_source_remove(sink_event_source_);
}
}

void VideoPlayer::ClearUpEventChannel() {
is_initialized_ = false;
event_sink_ = nullptr;
{
std::lock_guard<std::mutex> lock(queue_mutex_);
event_sink_ = nullptr;
}
if (event_channel_) {
event_channel_->SetStreamHandler(nullptr);
}
Expand Down Expand Up @@ -72,6 +68,7 @@ int64_t VideoPlayer::SetUpEventChannel() {

void VideoPlayer::ExecuteSinkEvents() {
std::lock_guard<std::mutex> lock(queue_mutex_);
sink_event_source_ = 0;
while (!encodable_event_queue_.empty()) {
if (event_sink_) {
event_sink_->Success(encodable_event_queue_.front());
Expand All @@ -88,14 +85,27 @@ void VideoPlayer::ExecuteSinkEvents() {
}
}

void VideoPlayer::RequestEventDispatch() {
if (sink_event_source_ == 0) {
sink_event_source_ = g_idle_add_full(
G_PRIORITY_DEFAULT,
[](gpointer data) -> gboolean {
auto *self = static_cast<VideoPlayer *>(data);
self->ExecuteSinkEvents();
return G_SOURCE_REMOVE;
},
this, nullptr);
}
}

void VideoPlayer::PushEvent(flutter::EncodableValue encodable_value) {
std::lock_guard<std::mutex> lock(queue_mutex_);
if (event_sink_ == nullptr) {
LOG_ERROR("[VideoPlayer] event sink is nullptr.");
return;
}
encodable_event_queue_.push(encodable_value);
ecore_pipe_write(sink_event_pipe_, nullptr, 0);
RequestEventDispatch();
}

void VideoPlayer::SendInitialized() {
Expand Down Expand Up @@ -219,10 +229,10 @@ void VideoPlayer::SendManifestInfo(std::string manifest_info) {

void VideoPlayer::SendError(const std::string &error_code,
const std::string &error_message) {
std::lock_guard<std::mutex> lock(queue_mutex_);
if (event_sink_) {
std::lock_guard<std::mutex> lock(queue_mutex_);
error_event_queue_.push(std::make_pair(error_code, error_message));
ecore_pipe_write(sink_event_pipe_, nullptr, 0);
RequestEventDispatch();
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/video_player_avplay/tizen/src/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#ifndef FLUTTER_PLUGIN_VIDEO_PLAYER_H_
#define FLUTTER_PLUGIN_VIDEO_PLAYER_H_

#include <Ecore.h>
#include <flutter/encodable_value.h>
#include <flutter/event_channel.h>
#include <flutter_tizen.h>
#include <glib.h>

#include <memory>
#include <mutex>
Expand Down Expand Up @@ -100,14 +100,15 @@ class VideoPlayer {

private:
void ExecuteSinkEvents();
void RequestEventDispatch();
void PushEvent(flutter::EncodableValue encodable_value);

std::queue<flutter::EncodableValue> encodable_event_queue_;
std::queue<std::pair<std::string, std::string>> error_event_queue_;
std::unique_ptr<flutter::EventChannel<flutter::EncodableValue>>
event_channel_;
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> event_sink_;
Ecore_Pipe *sink_event_pipe_ = nullptr;
guint sink_event_source_ = 0;
};

} // namespace video_player_avplay_tizen
Expand Down
Loading