Skip to content

Commit

Permalink
Merge pull request #4 from mhoeckner/master
Browse files Browse the repository at this point in the history
[video_player_avplay] Replace surface id with resource id when SetDis…
  • Loading branch information
mhoeckner authored Dec 11, 2023
2 parents c5bfd64 + e86f535 commit 09e559c
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 40 deletions.
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.1.2

* Replace surface id with resource id for fixing overlap issue.

## 0.1.1

* Fix load gstream libs fail issue when package name not same with app id.
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.1.1
video_player_avplay: ^0.1.2
```
Then you can import `video_player_avplay` in your Dart code:
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.1.1
version: 0.1.2

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
15 changes: 10 additions & 5 deletions packages/video_player_avplay/tizen/src/media_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ static player_stream_type_e ConvertTrackType(std::string track_type) {
}

MediaPlayer::MediaPlayer(flutter::BinaryMessenger *messenger,
void *native_window)
: VideoPlayer(messenger), native_window_(native_window) {
FlutterDesktopViewRef flutter_view)
: VideoPlayer(messenger, flutter_view) {
media_player_proxy_ = std::make_unique<MediaPlayerProxy>();
}

Expand Down Expand Up @@ -349,12 +349,17 @@ bool MediaPlayer::IsReady() {
}

bool MediaPlayer::SetDisplay() {
void *native_window = GetWindowHandle();
if (!native_window) {
LOG_ERROR("[MediaPlayer] Could not get a native window handle.");
return false;
}

int x = 0, y = 0, width = 0, height = 0;
ecore_wl2_window_proxy_->ecore_wl2_window_geometry_get(native_window_, &x, &y,
ecore_wl2_window_proxy_->ecore_wl2_window_geometry_get(native_window, &x, &y,
&width, &height);
int ret = media_player_proxy_->player_set_ecore_wl_display(
player_, PLAYER_DISPLAY_TYPE_OVERLAY, native_window_, x, y, width,
height);
player_, PLAYER_DISPLAY_TYPE_OVERLAY, native_window, x, y, width, height);
if (ret != PLAYER_ERROR_NONE) {
LOG_ERROR("[MediaPlayer] player_set_ecore_wl_display failed: %s.",
get_error_message(ret));
Expand Down
3 changes: 1 addition & 2 deletions packages/video_player_avplay/tizen/src/media_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class MediaPlayer : public VideoPlayer {
public:
explicit MediaPlayer(flutter::BinaryMessenger *messenger,
void *native_window);
FlutterDesktopViewRef flutter_view);
~MediaPlayer();

int64_t Create(const std::string &uri, int drm_type,
Expand Down Expand Up @@ -64,7 +64,6 @@ class MediaPlayer : public VideoPlayer {
std::unique_ptr<MediaPlayerProxy> media_player_proxy_ = nullptr;
std::unique_ptr<DrmManager> drm_manager_;
bool is_buffering_ = false;
void *native_window_ = nullptr;
SeekCompletedCallback on_seek_completed_;
};

Expand Down
23 changes: 13 additions & 10 deletions packages/video_player_avplay/tizen/src/plus_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ static plusplayer::TrackType ConvertTrackType(std::string track_type) {
}
}

PlusPlayer::PlusPlayer(flutter::BinaryMessenger *messenger, void *native_window,
PlusPlayer::PlusPlayer(flutter::BinaryMessenger *messenger,
FlutterDesktopViewRef flutter_view,
std::string &video_format)
: VideoPlayer(messenger),
native_window_(native_window),
video_format_(video_format) {}
: VideoPlayer(messenger, flutter_view), video_format_(video_format) {}

PlusPlayer::~PlusPlayer() { Dispose(); }

Expand Down Expand Up @@ -409,17 +408,21 @@ bool PlusPlayer::IsReady() {
}

bool PlusPlayer::SetDisplay() {
void *native_window = GetWindowHandle();
if (!native_window) {
LOG_ERROR("[PlusPlayer] Could not get a native window handle.");
return false;
}
int x = 0, y = 0, width = 0, height = 0;
ecore_wl2_window_proxy_->ecore_wl2_window_geometry_get(native_window_, &x, &y,
ecore_wl2_window_proxy_->ecore_wl2_window_geometry_get(native_window, &x, &y,
&width, &height);
int surface_id =
ecore_wl2_window_proxy_->ecore_wl2_window_surface_id_get(native_window_);
if (surface_id < 0) {
LOG_ERROR("[PlusPlayer] Fail to get surface id.");
uint32_t resource_id = FlutterDesktopViewGetResourceId(flutter_view_);
if (resource_id == 0) {
LOG_ERROR("[PlusPlayer] Fail to get resource id.");
return false;
}
bool ret = ::SetDisplay(player_, plusplayer::DisplayType::kOverlay,
surface_id, x, y, width, height);
resource_id, x, y, width, height);
if (!ret) {
LOG_ERROR("[PlusPlayer] Player fail to set display.");
return false;
Expand Down
5 changes: 2 additions & 3 deletions packages/video_player_avplay/tizen/src/plus_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

class PlusPlayer : public VideoPlayer {
public:
explicit PlusPlayer(flutter::BinaryMessenger *messenger, void *native_window,
explicit PlusPlayer(flutter::BinaryMessenger *messenger,
FlutterDesktopViewRef flutter_view,
std::string &video_format);
~PlusPlayer();

Expand Down Expand Up @@ -79,8 +80,6 @@ class PlusPlayer : public VideoPlayer {
PlusplayerRef player_ = nullptr;
PlusplayerListener listener_;
std::unique_ptr<DrmManager> drm_manager_;

void *native_window_;
std::string video_format_;
bool is_buffering_ = false;
bool is_prebuffer_mode_ = false;
Expand Down
10 changes: 8 additions & 2 deletions packages/video_player_avplay/tizen/src/video_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

static int64_t player_index = 1;

VideoPlayer::VideoPlayer(flutter::BinaryMessenger *messenger)
VideoPlayer::VideoPlayer(flutter::BinaryMessenger *messenger,
FlutterDesktopViewRef flutter_view)
: ecore_wl2_window_proxy_(std::make_unique<EcoreWl2WindowProxy>()),
binary_messenger_(messenger) {
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);
Expand Down Expand Up @@ -160,3 +162,7 @@ void VideoPlayer::SendError(const std::string &error_code,
ecore_pipe_write(sink_event_pipe_, nullptr, 0);
}
}

void *VideoPlayer::GetWindowHandle() {
return FlutterDesktopViewGetNativeHandle(flutter_view_);
}
8 changes: 5 additions & 3 deletions packages/video_player_avplay/tizen/src/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define FLUTTER_PLUGIN_VIDEO_PLAYER_H_

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

#include <memory>
#include <mutex>
Expand All @@ -22,7 +22,8 @@ class VideoPlayer {
public:
using SeekCompletedCallback = std::function<void()>;

explicit VideoPlayer(flutter::BinaryMessenger *messenger);
explicit VideoPlayer(flutter::BinaryMessenger *messenger,
FlutterDesktopViewRef flutter_view);
VideoPlayer(const VideoPlayer &) = delete;
VideoPlayer &operator=(const VideoPlayer &) = delete;
virtual ~VideoPlayer();
Expand Down Expand Up @@ -51,6 +52,7 @@ class VideoPlayer {

protected:
virtual void GetVideoSize(int32_t *width, int32_t *height) = 0;
void *GetWindowHandle();
int64_t SetUpEventChannel();
void SendInitialized();
void SendBufferingStart();
Expand All @@ -64,8 +66,8 @@ class VideoPlayer {
std::mutex queue_mutex_;
std::unique_ptr<EcoreWl2WindowProxy> ecore_wl2_window_proxy_ = nullptr;
flutter::BinaryMessenger *binary_messenger_;

bool is_initialized_ = false;
FlutterDesktopViewRef flutter_view_;

private:
void ExecuteSinkEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,9 @@ std::optional<FlutterError> VideoPlayerTizenPlugin::Initialize() {

ErrorOr<PlayerMessage> VideoPlayerTizenPlugin::Create(
const CreateMessage &msg) {
FlutterDesktopViewRef flutter_view =
FlutterDesktopPluginRegistrarGetView(registrar_ref_);
if (!flutter_view) {
if (!FlutterDesktopPluginRegistrarGetView(registrar_ref_)) {
return FlutterError("Operation failed", "Could not get a Flutter view.");
}
void *native_window = FlutterDesktopViewGetNativeHandle(flutter_view);
if (!native_window) {
return FlutterError("Operation failed",
"Could not get a native window handle.");
}

std::string uri;
int32_t drm_type = 0; // DRM_TYPE_NONE
std::string license_server_url;
Expand Down Expand Up @@ -174,17 +166,19 @@ ErrorOr<PlayerMessage> VideoPlayerTizenPlugin::Create(

int64_t player_id = 0;
if (uri.substr(0, 4) == "http") {
auto player = std::make_unique<PlusPlayer>(plugin_registrar_->messenger(),
native_window, format);
auto player = std::make_unique<PlusPlayer>(
plugin_registrar_->messenger(),
FlutterDesktopPluginRegistrarGetView(registrar_ref_), format);
player_id = player->Create(uri, drm_type, license_server_url,
prebuffer_mode, http_headers);
if (player_id == -1) {
return FlutterError("Operation failed", "Failed to create a player.");
}
players_[player_id] = std::move(player);
} else {
auto player = std::make_unique<MediaPlayer>(plugin_registrar_->messenger(),
native_window);
auto player = std::make_unique<MediaPlayer>(
plugin_registrar_->messenger(),
FlutterDesktopPluginRegistrarGetView(registrar_ref_));
player_id = player->Create(uri, drm_type, license_server_url,
prebuffer_mode, http_headers);
if (player_id == -1) {
Expand Down

0 comments on commit 09e559c

Please sign in to comment.