From e86f535b833fded366d27d81f9002d12855e72e0 Mon Sep 17 00:00:00 2001 From: xiaowei guan <60122246+xiaowei-guan@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:32:29 +0800 Subject: [PATCH] [video_player_avplay] Replace surface id with resource id when SetDisplay (#636) --- packages/video_player_avplay/CHANGELOG.md | 4 ++++ packages/video_player_avplay/README.md | 2 +- packages/video_player_avplay/pubspec.yaml | 2 +- .../tizen/src/media_player.cc | 15 ++++++++---- .../tizen/src/media_player.h | 3 +-- .../tizen/src/plus_player.cc | 23 +++++++++++-------- .../tizen/src/plus_player.h | 5 ++-- .../tizen/src/video_player.cc | 10 ++++++-- .../tizen/src/video_player.h | 8 ++++--- .../tizen/src/video_player_tizen_plugin.cc | 20 ++++++---------- 10 files changed, 52 insertions(+), 40 deletions(-) diff --git a/packages/video_player_avplay/CHANGELOG.md b/packages/video_player_avplay/CHANGELOG.md index c2613f120..746b6bb8f 100644 --- a/packages/video_player_avplay/CHANGELOG.md +++ b/packages/video_player_avplay/CHANGELOG.md @@ -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. diff --git a/packages/video_player_avplay/README.md b/packages/video_player_avplay/README.md index bff17e5cd..d7a42cfee 100644 --- a/packages/video_player_avplay/README.md +++ b/packages/video_player_avplay/README.md @@ -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: diff --git a/packages/video_player_avplay/pubspec.yaml b/packages/video_player_avplay/pubspec.yaml index 72dd58b5b..cb6812495 100644 --- a/packages/video_player_avplay/pubspec.yaml +++ b/packages/video_player_avplay/pubspec.yaml @@ -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" diff --git a/packages/video_player_avplay/tizen/src/media_player.cc b/packages/video_player_avplay/tizen/src/media_player.cc index 39a702743..115a5a2bf 100644 --- a/packages/video_player_avplay/tizen/src/media_player.cc +++ b/packages/video_player_avplay/tizen/src/media_player.cc @@ -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(); } @@ -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)); diff --git a/packages/video_player_avplay/tizen/src/media_player.h b/packages/video_player_avplay/tizen/src/media_player.h index e8860c3d9..01e0e91c6 100644 --- a/packages/video_player_avplay/tizen/src/media_player.h +++ b/packages/video_player_avplay/tizen/src/media_player.h @@ -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, @@ -64,7 +64,6 @@ class MediaPlayer : public VideoPlayer { std::unique_ptr media_player_proxy_ = nullptr; std::unique_ptr drm_manager_; bool is_buffering_ = false; - void *native_window_ = nullptr; SeekCompletedCallback on_seek_completed_; }; diff --git a/packages/video_player_avplay/tizen/src/plus_player.cc b/packages/video_player_avplay/tizen/src/plus_player.cc index 27bec246d..ec6085746 100644 --- a/packages/video_player_avplay/tizen/src/plus_player.cc +++ b/packages/video_player_avplay/tizen/src/plus_player.cc @@ -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(); } @@ -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; diff --git a/packages/video_player_avplay/tizen/src/plus_player.h b/packages/video_player_avplay/tizen/src/plus_player.h index 399ef059b..01dfc2dea 100644 --- a/packages/video_player_avplay/tizen/src/plus_player.h +++ b/packages/video_player_avplay/tizen/src/plus_player.h @@ -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(); @@ -79,8 +80,6 @@ class PlusPlayer : public VideoPlayer { PlusplayerRef player_ = nullptr; PlusplayerListener listener_; std::unique_ptr drm_manager_; - - void *native_window_; std::string video_format_; bool is_buffering_ = false; bool is_prebuffer_mode_ = false; diff --git a/packages/video_player_avplay/tizen/src/video_player.cc b/packages/video_player_avplay/tizen/src/video_player.cc index ef5ac6b8d..38decd391 100644 --- a/packages/video_player_avplay/tizen/src/video_player.cc +++ b/packages/video_player_avplay/tizen/src/video_player.cc @@ -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()), - 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(data); @@ -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_); +} diff --git a/packages/video_player_avplay/tizen/src/video_player.h b/packages/video_player_avplay/tizen/src/video_player.h index 7ea6a62e7..53a522288 100644 --- a/packages/video_player_avplay/tizen/src/video_player.h +++ b/packages/video_player_avplay/tizen/src/video_player.h @@ -6,9 +6,9 @@ #define FLUTTER_PLUGIN_VIDEO_PLAYER_H_ #include -#include #include #include +#include #include #include @@ -22,7 +22,8 @@ class VideoPlayer { public: using SeekCompletedCallback = std::function; - explicit VideoPlayer(flutter::BinaryMessenger *messenger); + explicit VideoPlayer(flutter::BinaryMessenger *messenger, + FlutterDesktopViewRef flutter_view); VideoPlayer(const VideoPlayer &) = delete; VideoPlayer &operator=(const VideoPlayer &) = delete; virtual ~VideoPlayer(); @@ -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(); @@ -64,8 +66,8 @@ class VideoPlayer { std::mutex queue_mutex_; std::unique_ptr ecore_wl2_window_proxy_ = nullptr; flutter::BinaryMessenger *binary_messenger_; - bool is_initialized_ = false; + FlutterDesktopViewRef flutter_view_; private: void ExecuteSinkEvents(); diff --git a/packages/video_player_avplay/tizen/src/video_player_tizen_plugin.cc b/packages/video_player_avplay/tizen/src/video_player_tizen_plugin.cc index e0d2d03f5..10cb39eb4 100644 --- a/packages/video_player_avplay/tizen/src/video_player_tizen_plugin.cc +++ b/packages/video_player_avplay/tizen/src/video_player_tizen_plugin.cc @@ -104,17 +104,9 @@ std::optional VideoPlayerTizenPlugin::Initialize() { ErrorOr 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; @@ -174,8 +166,9 @@ ErrorOr VideoPlayerTizenPlugin::Create( int64_t player_id = 0; if (uri.substr(0, 4) == "http") { - auto player = std::make_unique(plugin_registrar_->messenger(), - native_window, format); + auto player = std::make_unique( + 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) { @@ -183,8 +176,9 @@ ErrorOr VideoPlayerTizenPlugin::Create( } players_[player_id] = std::move(player); } else { - auto player = std::make_unique(plugin_registrar_->messenger(), - native_window); + auto player = std::make_unique( + plugin_registrar_->messenger(), + FlutterDesktopPluginRegistrarGetView(registrar_ref_)); player_id = player->Create(uri, drm_type, license_server_url, prebuffer_mode, http_headers); if (player_id == -1) {