From de77b7c56cb94645a19eac6460fa474b279da90b Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 28 Jun 2016 13:20:23 +0900 Subject: [PATCH] 1. Modify getting evas object geometry values. 2. Modify filename from player_wayland to player_display 3. Move wl window functions to player_display file If __evas_resize_cb is not called, player can't collect window geometry value. Change-Id: I39bbb06cb1a9233eeb7c145b46381bb441ed848f Signed-off-by: Hyunil --- include/{player_wayland.h => player_display.h} | 10 +- include/player_private.h | 4 +- packaging/capi-media-player.spec | 2 +- src/player.c | 21 ++- src/player_display.c | 250 +++++++++++++++++++++++++ src/player_internal.c | 92 +-------- src/player_wayland.c | 141 -------------- 7 files changed, 278 insertions(+), 242 deletions(-) rename include/{player_wayland.h => player_display.h} (71%) create mode 100644 src/player_display.c delete mode 100644 src/player_wayland.c diff --git a/include/player_wayland.h b/include/player_display.h similarity index 71% rename from include/player_wayland.h rename to include/player_display.h index 860bf34..ad55ce5 100644 --- a/include/player_wayland.h +++ b/include/player_display.h @@ -22,6 +22,7 @@ #include #include #include +#include "player.h" #ifdef __cplusplus extern "C" { @@ -34,9 +35,12 @@ typedef struct { struct tizen_resource *tz_resource; } wl_client; -int _wlclient_create(wl_client ** wlclient); -int _wlclient_get_wl_window_wl_surface_id(wl_client * wlclient, struct wl_surface *surface, struct wl_display *display); -void _wlclient_finalize(wl_client * wlclient); +int _wl_client_create(wl_client ** wlclient); +int _wl_client_get_wl_window_wl_surface_id(wl_client * wlclient, struct wl_surface *surface, struct wl_display *display); +void _wl_client_finalize(wl_client * wlclient); +int _wl_window_geometry_get(Evas_Object *eo, Evas *e, int *x, int *y, int *width, int *height); +int _wl_window_evas_object_cb_add(player_h player, Evas_Object *eo); +int _wl_window_evas_object_cb_del(player_h player); #ifdef __cplusplus } diff --git a/include/player_private.h b/include/player_private.h index 78adcd8..8e90bab 100644 --- a/include/player_private.h +++ b/include/player_private.h @@ -21,7 +21,7 @@ #include #include #include "player.h" -#include "player_wayland.h" +#include "player_display.h" #ifdef __cplusplus extern "C" { @@ -134,8 +134,6 @@ typedef struct _player_cli_s { /* server state change timeout (sec) */ #define SERVER_TIMEOUT(h) ((h)->server.timeout) -int player_set_evas_object_cb(player_h player, Evas_Object * eo); -int player_unset_evas_object_cb(player_h player); int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api); int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out); diff --git a/packaging/capi-media-player.spec b/packaging/capi-media-player.spec index 52a3282..0d4c9b8 100644 --- a/packaging/capi-media-player.spec +++ b/packaging/capi-media-player.spec @@ -1,6 +1,6 @@ Name: capi-media-player Summary: A Media Player API -Version: 0.3.12 +Version: 0.3.13 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/player.c b/src/player.c index cd95c44..5bcf7e2 100755 --- a/src/player.c +++ b/src/player.c @@ -38,6 +38,7 @@ #include #include "player_internal.h" #include "player_private.h" +#include "player_display.h" #include "player_msg.h" #ifdef EVAS_RENDERER_SUPPORT #include @@ -1421,7 +1422,7 @@ int player_destroy(player_h player) g_mutex_unlock(&pc->cb_info->data_mutex); } - if (player_unset_evas_object_cb(player) != MM_ERROR_NONE) + if (_wl_window_evas_object_cb_del(player) != MM_ERROR_NONE) LOGW("fail to unset evas object callback"); if (CALLBACK_INFO(pc)) { @@ -2017,6 +2018,7 @@ int player_set_display(player_h player, player_display_type_e type, player_displ struct wl_surface *wl_surface; struct wl_display *wl_display; Ecore_Wl_Window *wl_window = NULL; + Evas *e; LOGD("ENTER"); @@ -2032,20 +2034,29 @@ int player_set_display(player_h player, player_display_type_e type, player_displ LOGI("Wayland overlay surface type"); wl_win.type = type; - evas_object_geometry_get(obj, &wl_win.wl_window_x, &wl_win.wl_window_y, &wl_win.wl_window_width, &wl_win.wl_window_height); + e = evas_object_evas_get(obj); + return_val_if_fail(e != NULL, PLAYER_ERROR_INVALID_OPERATION); - if (player_set_evas_object_cb(player, obj) != MM_ERROR_NONE) { + ret = _wl_window_geometry_get(obj, e, &wl_win.wl_window_x, &wl_win.wl_window_y, + &wl_win.wl_window_width, &wl_win.wl_window_height); + if (ret != MM_ERROR_NONE) { + LOGE ("Fail to get window geometry"); + return ret; + } + if (_wl_window_evas_object_cb_add(player, obj) != MM_ERROR_NONE) { LOGW("fail to set evas object callback"); } wl_window = elm_win_wl_window_get(obj); + return_val_if_fail(wl_window != NULL, PLAYER_ERROR_INVALID_OPERATION); + wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window); /* get wl_display */ wl_display = (struct wl_display *)ecore_wl_display_get(); if (!pc->wlclient) { - ret = _wlclient_create(&pc->wlclient); + ret = _wl_client_create(&pc->wlclient); if (ret != MM_ERROR_NONE) { LOGE("Wayland client create failure"); return ret; @@ -2053,7 +2064,7 @@ int player_set_display(player_h player, player_display_type_e type, player_displ } if (wl_surface && wl_display) { LOGD("surface = %p, wl_display = %p", wl_surface, wl_display); - wl_surface_id = _wlclient_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display); + wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display); LOGD("wl_surface_id = %d", wl_surface_id); wl_win.wl_surface_id = wl_surface_id; LOGD("wl_win.wl_surface_id = %d", wl_win.wl_surface_id); diff --git a/src/player_display.c b/src/player_display.c new file mode 100644 index 0000000..102d741 --- /dev/null +++ b/src/player_display.c @@ -0,0 +1,250 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "player_msg.h" +#include "player_display.h" +#include "player_private.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_PLAYER" + +#define goto_if_fail(expr, label) \ +{ \ + if (!(expr)) { \ + debug_error(" failed [%s]\n", #expr); \ + goto label; \ + } \ +} + +void handle_resource_id(void *data, struct tizen_resource *tizen_resource, uint32_t id) +{ + unsigned int *wl_surface_id = data; + + *wl_surface_id = id; + + LOGD("[CLIENT] got wl_surface_id(%d) from server\n", id); +} + +static const struct tizen_resource_listener tz_resource_listener = { + handle_resource_id, +}; + +static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) +{ + return_if_fail(data != NULL); + wl_client *wlclient = data; + + if (strcmp(interface, "tizen_surface") == 0) { + LOGD("binding tizen_surface"); + wlclient->tz_surface = wl_registry_bind(registry, name, &tizen_surface_interface, version); + return_if_fail(wlclient->tz_surface != NULL); + } +} + +static const struct wl_registry_listener registry_listener = { + handle_global, +}; + +int _wl_client_create(wl_client ** wlclient) +{ + wl_client *ptr = NULL; + + ptr = g_malloc0(sizeof(wl_client)); + if (!ptr) { + LOGE("Cannot allocate memory for wlclient\n"); + goto ERROR; + } else { + *wlclient = ptr; + LOGD("Success create wlclient(%p)", *wlclient); + } + return MM_ERROR_NONE; + + ERROR: + *wlclient = NULL; + return MM_ERROR_PLAYER_NO_FREE_SPACE; +} + +int _wl_client_get_wl_window_wl_surface_id(wl_client * wlclient, struct wl_surface *surface, struct wl_display *display) +{ + goto_if_fail(wlclient != NULL, failed); + goto_if_fail(surface != NULL, failed); + goto_if_fail(display != NULL, failed); + + unsigned int wl_surface_id = 0; + + wlclient->display = display; + goto_if_fail(wlclient->display != NULL, failed); + + wlclient->registry = wl_display_get_registry(wlclient->display); + goto_if_fail(wlclient->registry != NULL, failed); + + wl_registry_add_listener(wlclient->registry, ®istry_listener, wlclient); + wl_display_dispatch(wlclient->display); + wl_display_roundtrip(wlclient->display); + + /* check global objects */ + goto_if_fail(wlclient->tz_surface != NULL, failed); + + /* Get wl_surface_id which is unique in a entire systemw. */ + wlclient->tz_resource = tizen_surface_get_tizen_resource(wlclient->tz_surface, surface); + goto_if_fail(wlclient->tz_resource != NULL, failed); + + tizen_resource_add_listener(wlclient->tz_resource, &tz_resource_listener, &wl_surface_id); + wl_display_roundtrip(wlclient->display); + goto_if_fail(wl_surface_id > 0, failed); + + _wl_client_finalize(wlclient); + + return wl_surface_id; + + failed: + LOGE("Failed to get wl_surface_id"); + + return 0; +} + +void _wl_client_finalize(wl_client * wlclient) +{ + LOGD("start finalize wlclient"); + return_if_fail(wlclient != NULL) + + if (wlclient->tz_surface) + tizen_surface_destroy(wlclient->tz_surface); + + if (wlclient->tz_resource) + tizen_resource_destroy(wlclient->tz_resource); + + /* destroy registry */ + if (wlclient->registry) + wl_registry_destroy(wlclient->registry); + return; +} + +static void __evas_resize_cb(void *data, Evas * e, Evas_Object * eo, void *event_info) +{ + player_cli_s *pc = (player_cli_s *) data; + wl_win_msg_type wl_win; + char *wl_win_msg = (char *)&wl_win; + char *ret_buf = NULL; + muse_player_api_e api = MUSE_PLAYER_API_RESIZE_VIDEO_RENDER_RECT; + int ret = PLAYER_ERROR_NONE; + LOGD("ret =%d", ret); + + ret = _wl_window_geometry_get(eo, e, &wl_win.wl_window_x, &wl_win.wl_window_y, + &wl_win.wl_window_width, &wl_win.wl_window_height); + if (ret != PLAYER_ERROR_NONE) { + LOGE("Fail to get window geometry"); + return; + } + wl_win.type = 0; /*init but not use */ + wl_win.wl_surface_id = 0; /*init but not use */ + + player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char)); + + g_free(ret_buf); + return; + +} + +static void __evas_del_cb(void *data, Evas * e, Evas_Object * eo, void *event_info) +{ + + player_cli_s *pc = (player_cli_s *) data; + + evas_object_event_callback_del(eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb); + evas_object_event_callback_del(eo, EVAS_CALLBACK_DEL, __evas_del_cb); + + LOGD("evas callback del %p", eo); + pc->have_evas_callback = FALSE; + + return; +} + +int _wl_window_geometry_get(Evas_Object *eo, Evas *e, int *x, int *y, int *width, int *height) +{ + Ecore_Evas *ecore_evas; + int rotation; + return_val_if_fail(eo != NULL || e != NULL || x != NULL || y != NULL || width != NULL || height != NULL, + PLAYER_ERROR_INVALID_OPERATION); + + evas_object_geometry_get(eo, x, y, width, height); + LOGD("get window geometroy : x(%d) y(%d) width(%d) height(%d)", *x, *y, *width, *height); + /* get rotaion */ + ecore_evas = ecore_evas_ecore_evas_get(e); + return_val_if_fail(ecore_evas != NULL, PLAYER_ERROR_INVALID_OPERATION); + rotation = ecore_evas_rotation_get(ecore_evas); + + LOGD("rotation(%d)", rotation); + /* swap */ + if (rotation == 270 || rotation == 90) { + LOGD("swap width with height"); + int temp; + temp = *width; + *width = *height; + *height = temp; + LOGD("get window geometroy : x(%d) y(%d) width(%d) height(%d)", *x, *y, *width, *height); + } + + return MM_ERROR_NONE; +} + +int _wl_window_evas_object_cb_add(player_h player, Evas_Object *eo) +{ + + PLAYER_INSTANCE_CHECK(player); + return_val_if_fail(eo != NULL, MM_ERROR_INVALID_ARGUMENT); + + player_cli_s *pc = (player_cli_s *) player; + + if (pc->have_evas_callback && pc->eo == eo) { + LOGW("evas object had callback already %p", pc->eo); + return MM_ERROR_UNKNOWN; + } + pc->eo = eo; + evas_object_event_callback_add(eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb, player); + evas_object_event_callback_add(eo, EVAS_CALLBACK_DEL, __evas_del_cb, player); + LOGD("evas callback add %p", pc->eo); + pc->have_evas_callback = TRUE; + + return MM_ERROR_NONE; +} + +int _wl_window_evas_object_cb_del(player_h player) +{ + PLAYER_INSTANCE_CHECK(player); + player_cli_s *pc = (player_cli_s *) player; + return_val_if_fail(pc->eo != NULL, MM_ERROR_INVALID_ARGUMENT); + + evas_object_event_callback_del(pc->eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb); + evas_object_event_callback_del(pc->eo, EVAS_CALLBACK_DEL, __evas_del_cb); + LOGD("evas callback del %p", pc->eo); + pc->eo = NULL; + pc->have_evas_callback = FALSE; + + return MM_ERROR_NONE; +} + diff --git a/src/player_internal.c b/src/player_internal.c index 3c90401..1a44395 100644 --- a/src/player_internal.c +++ b/src/player_internal.c @@ -30,6 +30,7 @@ #include "player_private.h" #include "player_msg.h" #include "player_internal.h" +#include "player_display.h" int player_set_pcm_extraction_mode(player_h player, bool sync, player_audio_pcm_extraction_cb callback, void *user_data) { @@ -170,93 +171,6 @@ int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream return ret; } -static void __evas_resize_cb(void *data, Evas * e, Evas_Object * eo, void *event_info) -{ - player_cli_s *pc = (player_cli_s *) data; - wl_win_msg_type wl_win; - char *wl_win_msg = (char *)&wl_win; - char *ret_buf = NULL; - int rotation; - Ecore_Evas *ecore_evas; - muse_player_api_e api = MUSE_PLAYER_API_RESIZE_VIDEO_RENDER_RECT; - int ret = PLAYER_ERROR_NONE; - LOGD("ret =%d", ret); - - evas_object_geometry_get(eo, &wl_win.wl_window_x, &wl_win.wl_window_y, &wl_win.wl_window_width, &wl_win.wl_window_height); - ecore_evas = ecore_evas_ecore_evas_get(e); - rotation = ecore_evas_rotation_get(ecore_evas); - LOGD("rotation(%d)", rotation); - LOGD("get window rectangle: x(%d) y(%d) width(%d) height(%d)", - wl_win.wl_window_x, wl_win.wl_window_y, wl_win.wl_window_width, wl_win.wl_window_height); - if (rotation == 270 || rotation == 90) { - LOGD("swap w and h"); - int temp; - temp = wl_win.wl_window_width; - wl_win.wl_window_width = wl_win.wl_window_height; - wl_win.wl_window_height = temp; - } - LOGD("get window rectangle: x(%d) y(%d) width(%d) height(%d)", - wl_win.wl_window_x, wl_win.wl_window_y, wl_win.wl_window_width, wl_win.wl_window_height); - wl_win.type = 0; /*init but not use */ - wl_win.wl_surface_id = 0; /*init but not use */ - - player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char)); - - g_free(ret_buf); - return; - -} - -static void __evas_del_cb(void *data, Evas * e, Evas_Object * eo, void *event_info) -{ - - player_cli_s *pc = (player_cli_s *) data; - - evas_object_event_callback_del(eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb); - evas_object_event_callback_del(eo, EVAS_CALLBACK_DEL, __evas_del_cb); - - LOGD("evas callback del %p", eo); - pc->have_evas_callback = FALSE; - - return; -} - -int player_set_evas_object_cb(player_h player, Evas_Object * eo) -{ - - PLAYER_INSTANCE_CHECK(player); - return_val_if_fail(eo != NULL, MM_ERROR_INVALID_ARGUMENT); - - player_cli_s *pc = (player_cli_s *) player; - - if (pc->have_evas_callback && pc->eo == eo) { - LOGW("evas object had callback already %p", pc->eo); - return MM_ERROR_UNKNOWN; - } - pc->eo = eo; - evas_object_event_callback_add(eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb, player); - evas_object_event_callback_add(eo, EVAS_CALLBACK_DEL, __evas_del_cb, player); - LOGD("evas callback add %p", pc->eo); - pc->have_evas_callback = TRUE; - - return MM_ERROR_NONE; -} - -int player_unset_evas_object_cb(player_h player) -{ - PLAYER_INSTANCE_CHECK(player); - player_cli_s *pc = (player_cli_s *) player; - return_val_if_fail(pc->eo != NULL, MM_ERROR_INVALID_ARGUMENT); - - evas_object_event_callback_del(pc->eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb); - evas_object_event_callback_del(pc->eo, EVAS_CALLBACK_DEL, __evas_del_cb); - LOGD("evas callback del %p", pc->eo); - pc->eo = NULL; - pc->have_evas_callback = FALSE; - - return MM_ERROR_NONE; -} - int player_set_media_stream_dynamic_resolution(player_h player, bool drc) { PLAYER_INSTANCE_CHECK(player); @@ -310,7 +224,7 @@ int player_set_ecore_wl_display(player_h player, player_display_type_e type, Eco wl_display = (struct wl_display *)ecore_wl_display_get(); if (!pc->wlclient) { - ret = _wlclient_create(&pc->wlclient); + ret = _wl_client_create(&pc->wlclient); if (ret != MM_ERROR_NONE) { LOGE("Wayland client create failure"); return ret; @@ -319,7 +233,7 @@ int player_set_ecore_wl_display(player_h player, player_display_type_e type, Eco if (wl_surface && wl_display) { LOGD("surface = %p, wl_display = %p", wl_surface, wl_display); - wl_surface_id = _wlclient_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display); + wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display); LOGD("wl_surface_id = %d", wl_surface_id); wl_win.wl_surface_id = wl_surface_id; LOGD("wl_win.wl_surface_id = %d", wl_win.wl_surface_id); diff --git a/src/player_wayland.c b/src/player_wayland.c deleted file mode 100644 index 6e009eb..0000000 --- a/src/player_wayland.c +++ /dev/null @@ -1,141 +0,0 @@ -/* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include -#include -#include -#include -#include - -#include "player_wayland.h" - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "TIZEN_N_PLAYER" - -#define goto_if_fail(expr, label) \ -{ \ - if (!(expr)) { \ - debug_error(" failed [%s]\n", #expr); \ - goto label; \ - } \ -} - -void handle_resource_id(void *data, struct tizen_resource *tizen_resource, uint32_t id) -{ - unsigned int *wl_surface_id = data; - - *wl_surface_id = id; - - LOGD("[CLIENT] got wl_surface_id(%d) from server\n", id); -} - -static const struct tizen_resource_listener tz_resource_listener = { - handle_resource_id, -}; - -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) -{ - return_if_fail(data != NULL); - wl_client *wlclient = data; - - if (strcmp(interface, "tizen_surface") == 0) { - LOGD("binding tizen_surface"); - wlclient->tz_surface = wl_registry_bind(registry, name, &tizen_surface_interface, version); - return_if_fail(wlclient->tz_surface != NULL); - } -} - -static const struct wl_registry_listener registry_listener = { - handle_global, -}; - -int _wlclient_create(wl_client ** wlclient) -{ - wl_client *ptr = NULL; - - ptr = g_malloc0(sizeof(wl_client)); - if (!ptr) { - LOGE("Cannot allocate memory for wlclient\n"); - goto ERROR; - } else { - *wlclient = ptr; - LOGD("Success create wlclient(%p)", *wlclient); - } - return MM_ERROR_NONE; - - ERROR: - *wlclient = NULL; - return MM_ERROR_PLAYER_NO_FREE_SPACE; -} - -int _wlclient_get_wl_window_wl_surface_id(wl_client * wlclient, struct wl_surface *surface, struct wl_display *display) -{ - goto_if_fail(wlclient != NULL, failed); - goto_if_fail(surface != NULL, failed); - goto_if_fail(display != NULL, failed); - - unsigned int wl_surface_id = 0; - - wlclient->display = display; - goto_if_fail(wlclient->display != NULL, failed); - - wlclient->registry = wl_display_get_registry(wlclient->display); - goto_if_fail(wlclient->registry != NULL, failed); - - wl_registry_add_listener(wlclient->registry, ®istry_listener, wlclient); - wl_display_dispatch(wlclient->display); - wl_display_roundtrip(wlclient->display); - - /* check global objects */ - goto_if_fail(wlclient->tz_surface != NULL, failed); - - /* Get wl_surface_id which is unique in a entire systemw. */ - wlclient->tz_resource = tizen_surface_get_tizen_resource(wlclient->tz_surface, surface); - goto_if_fail(wlclient->tz_resource != NULL, failed); - - tizen_resource_add_listener(wlclient->tz_resource, &tz_resource_listener, &wl_surface_id); - wl_display_roundtrip(wlclient->display); - goto_if_fail(wl_surface_id > 0, failed); - - _wlclient_finalize(wlclient); - - return wl_surface_id; - - failed: - LOGE("Failed to get wl_surface_id"); - - return 0; -} - -void _wlclient_finalize(wl_client * wlclient) -{ - LOGD("start finalize wlclient"); - return_if_fail(wlclient != NULL) - - if (wlclient->tz_surface) - tizen_surface_destroy(wlclient->tz_surface); - - if (wlclient->tz_resource) - tizen_resource_destroy(wlclient->tz_resource); - - /* destroy registry */ - if (wlclient->registry) - wl_registry_destroy(wlclient->registry); - return; -} -- 2.7.4