Skip to content

Commit

Permalink
Fix graphic UI disappear issue on Tizen 6.0 image
Browse files Browse the repository at this point in the history
Replace surface id with resource id when SetDispaly.
  • Loading branch information
xiaowei-guan committed Dec 5, 2023
1 parent 755bf0d commit f3cff83
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 39 deletions.
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
13 changes: 11 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,10 @@ void VideoPlayer::SendError(const std::string &error_code,
ecore_pipe_write(sink_event_pipe_, nullptr, 0);
}
}

void *VideoPlayer::GetWindowHandle() {
if (!flutter_view_) {
return nullptr;
}
return FlutterDesktopViewGetNativeHandle(flutter_view_);
}
7 changes: 5 additions & 2 deletions packages/video_player_avplay/tizen/src/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#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 +23,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 +53,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 +67,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,6 @@ std::optional<FlutterError> VideoPlayerTizenPlugin::Initialize() {

ErrorOr<PlayerMessage> VideoPlayerTizenPlugin::Create(
const CreateMessage &msg) {
FlutterDesktopViewRef flutter_view =
FlutterDesktopPluginRegistrarGetView(registrar_ref_);
if (!flutter_view) {
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 +163,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 f3cff83

Please sign in to comment.