From: NAMJEONGYOON Date: Wed, 24 Feb 2016 07:39:16 +0000 (+0900) Subject: modified player for evas X-Git-Tag: submit/tizen/20160226.084707^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94dee6be1c3634c33359f23ee29cdc1bef7daf2b;p=platform%2Fcore%2Fapi%2Fplayer.git modified player for evas Change-Id: Ib60acf7ef37bcc35381f882ed5de01a878094681 Signed-off-by: NAMJEONGYOON --- diff --git a/include/player_evas.h b/include/player_evas.h new file mode 100644 index 0000000..98ba911 --- /dev/null +++ b/include/player_evas.h @@ -0,0 +1,130 @@ +/* + * libmm-player + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JongHyuk Choi + * + * 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. + * + */ + +#ifndef __TIZEN_MEDIA_PLAYER_EVASCLIENT_H__ +#define __TIZEN_MEDIA_PLAYER_EVASCLIENT_H__ + +/*=========================================================================================== +| | +| INCLUDE FILES | +| | +========================================================================================== */ +#include + +#include +#include + +#include +#include +#include + +#include "mm_types.h" +#include "mm_debug.h" + +#include +#include + +#define MAX_PACKET_NUM 20 + +/*=========================================================================================== +| | +| GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE | +| | +========================================================================================== */ + +/*--------------------------------------------------------------------------- +| GLOBAL #defines: | +---------------------------------------------------------------------------*/ + +#ifdef __cplusplus + extern "C" { +#endif + typedef enum + { + UPDATE_VISIBILITY, + UPDATE_TBM_SURF + } update_info; + + typedef enum + { + VISIBLE_NONE, /* if user dont set visibility, it will be changed to true */ + VISIBLE_TRUE, + VISIBLE_FALSE + } visible_info; + + typedef struct { + gint x; + gint y; + gint w; + gint h; + } rect_info; + + /* evas info for evas surface type */ + typedef struct + { + Evas_Object *eo; + Ecore_Pipe *epipe; + + /* video width & height */ + gint w; + gint h; + + visible_info visible; + + /* geometry information */ + rect_info eo_size; + gboolean use_ratio; + guint rotate_angle; + guint display_geometry_method; + guint flip; + + tbm_surface_h tbm_surf; + + /* media packet */ + media_packet_h prev_mp; + media_packet_h cur_mp; + media_packet_h pkt[MAX_PACKET_NUM]; + gint prev_idx; + gint cur_idx; + + /* count undestroyed media packet */ + guint sent_buffer_cnt; + + /* lock */ + GMutex free_lock; + } mm_evas_info; + +int player_set_evas_info(MMHandleType *player, Evas_Object *eo); +int player_unset_evas_info(MMHandleType player); +int player_set_visible_evas_info (MMHandleType player, bool visible); +int player_get_visible_evas_info (MMHandleType player, bool *visible); +int player_set_rotation_evas_info (MMHandleType player, int rotate); +int player_get_rotation_evas_info (MMHandleType player, int *rotate); +int player_set_geometry_evas_info (MMHandleType player, int mode); +int player_get_geometry_evas_info (MMHandleType player, int *mode); +int player_update_video_param(MMHandleType player); +void decoded_callback_for_evas (media_packet_h packet, void *data); +#ifdef __cplusplus + } +#endif + +#endif /* __TIZEN_MEDIA_PLAYER_EVASCLIENT_H__ */ + diff --git a/include/player_private.h b/include/player_private.h index c3c86ee..fa75b96 100644 --- a/include/player_private.h +++ b/include/player_private.h @@ -87,7 +87,7 @@ typedef struct _callback_cb_info { msg_buff_s buff; player_event_queue event_queue; media_format_h pkt_fmt; -// MMHandleType local_handle; + MMHandleType local_handle; tbm_bufmgr bufmgr; } callback_cb_info_s; diff --git a/src/player.c b/src/player.c index 2f246ed..17a0a04 100644 --- a/src/player.c +++ b/src/player.c @@ -40,6 +40,7 @@ #include #include "player_internal.h" #include "player_private.h" +#include "player_evas.h" typedef struct { int int_data; @@ -1241,6 +1242,9 @@ int player_unprepare(player_h player) _player_deinit_memory_buffer(pc); } + if (player_unset_evas_info(INT_HANDLE(pc)) != MM_ERROR_NONE) + LOGW("fail to unset evas client"); + g_free(ret_buf); return ret; } @@ -1499,6 +1503,13 @@ int player_start(player_h player) LOGD("ENTER"); + if (INT_HANDLE(pc)) + { + ret = player_update_video_param(INT_HANDLE(pc)); + if (ret != PLAYER_ERROR_NONE) + return ret; + } + player_msg_send(api, pc, ret_buf, ret); g_free(ret_buf); @@ -1769,6 +1780,18 @@ int player_set_display(player_h player, player_display_type_e type, player_displ 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); + + if(INT_HANDLE(pc)) { + LOGW("evas client already exists"); + if (player_unset_evas_info(INT_HANDLE(pc)) != MM_ERROR_NONE) + LOGW("fail to unset evas client"); + } + if(player_set_evas_info(&INT_HANDLE(pc), obj) != MM_ERROR_NONE) { + LOGW("fail to set evas client"); + } + if(player_set_media_packet_video_frame_decoded_cb(player, decoded_callback_for_evas , (void*) INT_HANDLE(pc)) != PLAYER_ERROR_NONE) { + LOGW("fail to set decoded callback"); + } } #endif else @@ -1803,6 +1826,12 @@ int player_set_display_mode(player_h player, player_display_mode_e mode) char *ret_buf = NULL; LOGD("ENTER"); + + ret = player_set_geometry_evas_info (INT_HANDLE(pc), mode); + if (ret == PLAYER_ERROR_NONE) { + return ret; + }/* FIXME : devide server and client and consider which error code will be returned */ + player_msg_send1(api, pc, ret_buf, ret, INT, mode); g_free(ret_buf); return ret; @@ -1820,6 +1849,12 @@ int player_get_display_mode(player_h player, player_display_mode_e *pmode) LOGD("ENTER"); + ret = player_get_geometry_evas_info (INT_HANDLE(pc), &mode); + if (ret == PLAYER_ERROR_NONE && mode != -1) { + *pmode = (player_display_mode_e) mode; + return ret; + } + player_msg_send(api, pc, ret_buf, ret); if (ret == PLAYER_ERROR_NONE) { player_msg_get_type(mode, ret_buf, INT); @@ -1855,6 +1890,12 @@ int player_set_display_rotation(player_h player, player_display_rotation_e rotat char *ret_buf = NULL; LOGD("ENTER"); + + ret = player_set_rotation_evas_info (INT_HANDLE(pc), rotation); + if (ret == PLAYER_ERROR_NONE) { + return ret; + } + player_msg_send1(api, pc, ret_buf, ret, INT, rotation); g_free(ret_buf); return ret; @@ -1872,6 +1913,12 @@ int player_get_display_rotation(player_h player, player_display_rotation_e *prot LOGD("ENTER"); + ret = player_get_rotation_evas_info (INT_HANDLE(pc), &rotation); + if (ret == PLAYER_ERROR_NONE && rotation != -1) { + *protation = (player_display_rotation_e) rotation; + return ret; + } + player_msg_send(api, pc, ret_buf, ret); if (ret == PLAYER_ERROR_NONE) { player_msg_get_type(rotation, ret_buf, INT); @@ -1891,6 +1938,12 @@ int player_set_display_visible(player_h player, bool visible) char *ret_buf = NULL; LOGD("ENTER"); + + ret = player_set_visible_evas_info(INT_HANDLE(pc), visible); + if (ret == PLAYER_ERROR_NONE) { + return ret; + } + player_msg_send1(api, pc, ret_buf, ret, INT, visible); g_free(ret_buf); return ret; @@ -1905,9 +1958,19 @@ int player_is_display_visible(player_h player, bool *pvisible) muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE; char *ret_buf = NULL; int value = -1; + bool visible = 0; LOGD("ENTER"); + ret = player_get_visible_evas_info (INT_HANDLE(pc), &visible); + if (ret == PLAYER_ERROR_NONE) { + if (visible) + *pvisible = TRUE; + else + *pvisible = FALSE; + return ret; + } + player_msg_send(api, pc, ret_buf, ret); if (ret == PLAYER_ERROR_NONE) { player_msg_get_type(value, ret_buf, INT); diff --git a/src/player_evas.c b/src/player_evas.c new file mode 100644 index 0000000..37e803c --- /dev/null +++ b/src/player_evas.c @@ -0,0 +1,862 @@ +/* +* 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. +*/ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "player_evas.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_PLAYER_EVAS" + +#define MMPLAYER_CHECK_NULL( x_var ) \ +if ( ! x_var ) \ +{ \ + LOGE("[%s] is NULL\n", #x_var ); \ + return MM_ERROR_COMMON_INVALID_ARGUMENT; \ +} + +#define SET_EVAS_OBJECT_EVENT_CALLBACK( x_evas_image_object, x_usr_data ) \ + do \ + { \ + if (x_evas_image_object) { \ + LOGD("object callback add"); \ + evas_object_event_callback_add (x_evas_image_object, EVAS_CALLBACK_DEL, _evas_del_cb, x_usr_data); \ + evas_object_event_callback_add (x_evas_image_object, EVAS_CALLBACK_RESIZE, _evas_resize_cb, x_usr_data); \ + } \ + } while(0) + +#define UNSET_EVAS_OBJECT_EVENT_CALLBACK( x_evas_image_object ) \ + do \ + { \ + if (x_evas_image_object) { \ + LOGD("object callback del"); \ + evas_object_event_callback_del (x_evas_image_object, EVAS_CALLBACK_DEL, _evas_del_cb); \ + evas_object_event_callback_del (x_evas_image_object, EVAS_CALLBACK_RESIZE, _evas_resize_cb); \ + } \ + } while(0) + +#define SET_EVAS_EVENT_CALLBACK( x_evas, x_usr_data ) \ + do \ + { \ + if (x_evas) { \ + LOGD("callback add... evas_callback_render_pre.. evas : %p evas_info : %p", x_evas, x_usr_data); \ + evas_event_callback_add (x_evas, EVAS_CALLBACK_RENDER_PRE, _evas_render_pre_cb, x_usr_data); \ + } \ + } while(0) + +#define UNSET_EVAS_EVENT_CALLBACK( x_evas ) \ + do \ + { \ + if (x_evas) { \ + LOGD("callback del... evas_callback_render_pre"); \ + evas_event_callback_del (x_evas, EVAS_CALLBACK_RENDER_PRE, _evas_render_pre_cb); \ + } \ + } while(0) + +enum +{ + DISP_GEO_METHOD_LETTER_BOX = 0, + DISP_GEO_METHOD_ORIGIN_SIZE, + DISP_GEO_METHOD_FULL_SCREEN, + DISP_GEO_METHOD_CROPPED_FULL_SCREEN, + DISP_GEO_METHOD_ORIGIN_SIZE_OR_LETTER_BOX, + DISP_GEO_METHOD_NUM, +}; + +enum +{ + DEGREE_0 = 0, + DEGREE_90, + DEGREE_180, + DEGREE_270, + DEGREE_NUM, +}; + +enum +{ + FLIP_NONE = 0, + FLIP_HORIZONTAL, + FLIP_VERTICAL, + FLIP_BOTH, + FLIP_NUM, +}; +int _player_create_evas_info (mm_evas_info ** evas_info); +int _player_destroy_evas_info (mm_evas_info * evas_info); +int _player_set_evas_info (mm_evas_info * evas_info, Evas_Object *eo); +int _player_reset_evas_info (mm_evas_info * evas_info); +void _player_update_geometry_evas_info (mm_evas_info *evas_info, rect_info *result); +int _player_apply_geometry_evas_info (mm_evas_info *evas_info); + +static void +_evas_resize_cb (void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + int x, y, w, h, ret; + x = y = w = h = 0; + + mm_evas_info *evas_info = data; + LOGD ("[ENTER]"); + + if (!evas_info || !evas_info->eo) { + return; + } + + evas_object_geometry_get(evas_info->eo, &x, &y, &w, &h); + if (!w || !h) { + LOGW ("evas object size (w:%d,h:%d) was not set", w, h); + } else { + evas_info->eo_size.x = x; + evas_info->eo_size.y = y; + evas_info->eo_size.w = w; + evas_info->eo_size.h = h; + LOGW ("resize (x:%d, y:%d, w:%d, h:%d)", x, y, w, h) + ; + ret = _player_apply_geometry_evas_info(evas_info); + if(ret != MM_ERROR_NONE) + LOGW("fail to apply geometry info"); + } + LOGD ("[LEAVE]"); +} + +static void +_evas_render_pre_cb (void *data, Evas *e, void *event_info) +{ + mm_evas_info *evas_info = data; + if (!evas_info || !evas_info->eo) { + LOGW("there is no esink info.... esink : %p, or eo is NULL returning", evas_info); + return; + } + //LOGI("- test -"); //@@@@@ pre_cb will be deleted. actually it is useless +} + +static void +_evas_del_cb (void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + mm_evas_info *evas_info = data; + LOGD ("[ENTER]"); + if (!evas_info || !evas_info->eo) { + return; + } + /* FIXME:del callback will be called once again */ + _player_destroy_evas_info(evas_info); + LOGD ("[LEAVE]"); +} + +void +evas_pipe_cb (void *data, void *buffer, update_info info) +{ + mm_evas_info *evas_info = data; + int ret; + g_mutex_lock (&evas_info->free_lock); + LOGD ("[ENTER]"); + + if (!evas_info || !evas_info->eo) { + LOGW ("evas_info %p or eo %p is NULL", evas_info, evas_info->eo); + goto ERROR; + } + + LOGD("evas_info : %p, evas_info->eo : %p", evas_info, evas_info->eo); + if (info == UPDATE_VISIBILITY) { + if(evas_info->visible == VISIBLE_FALSE) { + evas_object_hide(evas_info->eo); + LOGI ("object hide.."); + } else { + evas_object_show(evas_info->eo); + LOGI ("object show.. %d", evas_info->visible); + } + LOGD ("[LEAVE]"); + g_mutex_unlock (&evas_info->free_lock); + return; + } + + if (info!=UPDATE_TBM_SURF) { + LOGW ("invalid info type : %d", info); + goto ERROR; + } + + /* normally get tbm surf in pipe callback. if not, we can get changed tbm surf by other threads */ + ret = media_packet_get_tbm_surface(evas_info->pkt[evas_info->cur_idx], &evas_info->tbm_surf); + if(ret != MEDIA_PACKET_ERROR_NONE || !evas_info->tbm_surf) { + LOGW("get_tbm_surface is failed"); + goto ERROR; + } + /* it is needed to skip setting when state is pause */ + LOGD("received (tbm_surf %p)", evas_info->tbm_surf); + + Evas_Native_Surface surf; + surf.type = EVAS_NATIVE_SURFACE_TBM; + surf.version = EVAS_NATIVE_SURFACE_VERSION; + surf.data.tbm.buffer = evas_info->tbm_surf; +// surf.data.tbm.rot = evas_info->rotate_angle; +// surf.data.tbm.flip = evas_info->flip; + + rect_info result = {0}; + + evas_object_geometry_get(evas_info->eo, &evas_info->eo_size.x, &evas_info->eo_size.y, &evas_info->eo_size.w, &evas_info->eo_size.h); + if (!evas_info->eo_size.w || !evas_info->eo_size.h) { + LOGE ("there is no information for evas object size"); + goto ERROR; + } + _player_update_geometry_evas_info(evas_info, &result); + if(!result.w || !result.h) + { + LOGE("no information about geometry (%d, %d)", result.w, result.h); + goto ERROR; + } + + if(evas_info->use_ratio) + { +// surf.data.tbm.ratio = (float) evas_info->w / evas_info->h; + LOGD("set ratio for letter mode"); + } + evas_object_size_hint_align_set(evas_info->eo, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(evas_info->eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + if (evas_info->w > 0 && evas_info->h > 0) + evas_object_image_size_set(evas_info->eo, evas_info->w, evas_info->h); + + evas_object_image_native_surface_set(evas_info->eo, &surf); + LOGD("native surface set finish"); + + if(result.x || result.y) + LOGD("coordinate x, y (%d, %d) for locating video to center", result.x, result.y); + evas_object_image_fill_set(evas_info->eo, result.x, result.y, result.w, result.h); + + evas_object_image_pixels_dirty_set(evas_info->eo, EINA_TRUE); + LOGD ("GEO_METHOD : src(%dx%d), dst(%dx%d), dst_x(%d), dst_y(%d), rotate(%d), flip(%d)", + evas_info->w, evas_info->h, evas_info->eo_size.w, evas_info->eo_size.h, evas_info->eo_size.x, evas_info->eo_size.y, evas_info->rotate_angle, evas_info->flip); + + /* when evas_pipe_cb is called sequentially, previous packet and current packet will be the same */ + if((evas_info->prev_idx!=-1) && evas_info->pkt[evas_info->prev_idx] && (evas_info->prev_idx!=evas_info->cur_idx)) { + LOGD("destroy previous packet [%p] idx %d", evas_info->pkt[evas_info->prev_idx], evas_info->prev_idx); + if(media_packet_destroy(evas_info->pkt[evas_info->prev_idx]) != MEDIA_PACKET_ERROR_NONE) + LOGE("media_packet_destroy failed %p", evas_info->pkt[evas_info->prev_idx]); + evas_info->pkt[evas_info->prev_idx] = NULL; + evas_info->sent_buffer_cnt--; + LOGD("sent packet %d", evas_info->sent_buffer_cnt); + } + evas_info->prev_idx = evas_info->cur_idx; + + LOGD ("[LEAVE]"); + g_mutex_unlock (&evas_info->free_lock); + + return; + +ERROR: + if((evas_info->prev_idx!=-1) && evas_info->pkt[evas_info->prev_idx]) { + LOGD("cant render. destroy previous packet [%p] idx %d", evas_info->pkt[evas_info->prev_idx], evas_info->prev_idx); + if(media_packet_destroy(evas_info->pkt[evas_info->prev_idx]) != MEDIA_PACKET_ERROR_NONE) + LOGE("media_packet_destroy failed %p", evas_info->pkt[evas_info->prev_idx]); + evas_info->pkt[evas_info->prev_idx] = NULL; + evas_info->sent_buffer_cnt--; + } + evas_info->prev_idx = evas_info->cur_idx; + g_mutex_unlock (&evas_info->free_lock); +} + +static void +_set_evas_callback (mm_evas_info * evas_info) +{ + if(evas_info->eo) + { + SET_EVAS_OBJECT_EVENT_CALLBACK (evas_info->eo, evas_info); + SET_EVAS_EVENT_CALLBACK (evas_object_evas_get(evas_info->eo), evas_info); + } +} + +static void +_unset_evas_callback (mm_evas_info * evas_info) +{ + if(evas_info->eo) + { + UNSET_EVAS_OBJECT_EVENT_CALLBACK (evas_info->eo); + UNSET_EVAS_EVENT_CALLBACK (evas_object_evas_get(evas_info->eo)); + } +} + +static int +_get_video_size(media_packet_h packet, mm_evas_info * evas_info) +{ + media_format_h fmt; + if (media_packet_get_format(packet, &fmt) == MEDIA_PACKET_ERROR_NONE) { + int w, h; + if (media_format_get_video_info(fmt, NULL, &w, &h, NULL, NULL) == MEDIA_PACKET_ERROR_NONE) { + LOGD("video width = %d, height =%d", w, h); + evas_info->w = w; + evas_info->h = h; + return true; + } + else + LOGW("media_format_get_video_info is failed."); + } else { + LOGW("media_packet_get_format is failed."); + } + return false; +} + +int _find_empty_index (mm_evas_info * evas_info) +{ + int i; + for(i=0; ipkt[i]) + { + LOGD("selected idx %d", i); + return i; + } + } + LOGE("there is no empty idx"); + + return -1; +} + +void _reset_pipe (mm_evas_info * evas_info) +{ + int i = 0; + int ret = MEDIA_PACKET_ERROR_NONE; + + /* delete old pipe */ + if (evas_info->epipe) { + LOGD("pipe will be deleted"); + ecore_pipe_del (evas_info->epipe); + evas_info->epipe = NULL; + } + + /* destroy all packets */ + for(i=0; ipkt[i]) + { + LOGD("destroy packet [%p]", evas_info->pkt[i]); + ret = media_packet_destroy(evas_info->pkt[i]); + if (ret != MEDIA_PACKET_ERROR_NONE) + LOGW("media_packet_destroy failed %p", evas_info->pkt[i]); + else + evas_info->sent_buffer_cnt--; + evas_info->pkt[i] = NULL; + } + } + + /* make new pipe */ + if (!evas_info->epipe) { + evas_info->epipe = ecore_pipe_add ((Ecore_Pipe_Cb)evas_pipe_cb, evas_info); + if (!evas_info->epipe) { + LOGE("pipe is not created"); + } + } + + return; +} + +void decoded_callback_for_evas (media_packet_h packet, void *data) +{ + if (!packet) { + LOGE ("packet %p is NULL", packet); + return; + } + mm_evas_info* handle = (mm_evas_info*) data; + int ret = MEDIA_PACKET_ERROR_NONE; + bool has; + + LOGD("packet [%p]", packet); + + if (!data || !handle) { + LOGE("handle %p or evas_info %p is NULL", data, handle); + goto ERROR; + } + + ret = media_packet_has_tbm_surface_buffer(packet, &has); + if(ret != MEDIA_PACKET_ERROR_NONE) { + LOGW("has_tbm_surface is failed"); + goto ERROR; + } + /* FIXME: when setCaps occurs, _get_video_size should be called */ + if(has && _get_video_size(packet, handle)) { + /* Attention! if this error occurs, we need to consider managing buffer */ + if(handle->sent_buffer_cnt>4) { + LOGE("too many buffers are not released %d", handle->sent_buffer_cnt); + /* FIXME: fix this logic*/ + /* destroy all media packets and reset pipe at present */ + g_mutex_lock (&handle->free_lock); + _reset_pipe(handle); + g_mutex_unlock (&handle->free_lock); + } + handle->cur_idx = _find_empty_index(handle); + if(handle->cur_idx == -1) + goto ERROR; + handle->pkt[handle->cur_idx] = packet; + handle->sent_buffer_cnt++; + LOGD("sent packet %d", handle->sent_buffer_cnt); + ret = ecore_pipe_write(handle->epipe, handle, UPDATE_TBM_SURF); + if (!ret) { + handle->pkt[handle->cur_idx] = NULL; + handle->cur_idx = handle->prev_idx; + handle->sent_buffer_cnt--; + LOGW ("Failed to ecore_pipe_write() for updating tbm surf\n"); + goto ERROR; + } + } else { + LOGW ("no tbm_surf"); + goto ERROR; + } + + return; + +ERROR: + /* destroy media_packet immediately */ + if(packet) { + g_mutex_lock (&handle->free_lock); + LOGD("cant write. destroy packet [%p]", packet); + if(media_packet_destroy(packet) != MEDIA_PACKET_ERROR_NONE) + LOGE("media_packet_destroy failed %p", packet); + packet = NULL; + g_mutex_unlock (&handle->free_lock); + } + return; +} + +int +_player_create_evas_info (mm_evas_info ** evas_info) +{ + mm_evas_info *ptr = NULL; + ptr = g_malloc0 (sizeof (mm_evas_info)); + + if (!ptr) { + LOGE ("Cannot allocate memory for evas_info\n"); + goto ERROR; + } else { + *evas_info = ptr; + LOGD ("Success create evas_info(%p)", *evas_info); + } + + return MM_ERROR_NONE; + +ERROR: + *evas_info = NULL; + return MM_ERROR_PLAYER_NO_FREE_SPACE; +} + +int +_player_destroy_evas_info (mm_evas_info * evas_info) +{ + MMPLAYER_CHECK_NULL(evas_info); + + LOGD ("finalize evas_info"); + + _player_reset_evas_info(evas_info); + + g_free(evas_info); + evas_info = NULL; + + return MM_ERROR_NONE; +} + +int +_player_set_evas_info (mm_evas_info * evas_info, Evas_Object *eo) +{ + MMPLAYER_CHECK_NULL(evas_info); + MMPLAYER_CHECK_NULL(eo); + + LOGD ("set evas_info"); + + evas_info->prev_idx = evas_info->cur_idx = -1; + evas_info->eo = eo; + evas_info->epipe = ecore_pipe_add ((Ecore_Pipe_Cb)evas_pipe_cb, evas_info); + if (!evas_info->epipe) { + LOGE("pipe is not created"); + return MM_ERROR_PLAYER_NO_OP; + } + g_mutex_init (&evas_info->free_lock); + _set_evas_callback(evas_info); + + evas_object_geometry_get(evas_info->eo, &evas_info->eo_size.x, &evas_info->eo_size.y, + &evas_info->eo_size.w, &evas_info->eo_size.h); + LOGI("evas object %p (%d ,%d ,%d ,%d)", evas_info->eo, evas_info->eo_size.x, evas_info->eo_size.y, + evas_info->eo_size.w, evas_info->eo_size.h); + + return MM_ERROR_NONE; +} + +int +_player_reset_evas_info (mm_evas_info * evas_info) +{ + MMPLAYER_CHECK_NULL(evas_info); + + _unset_evas_callback(evas_info); + + int i; + int ret = MEDIA_PACKET_ERROR_NONE; + if (evas_info->epipe) { + LOGD("pipe will be deleted"); + ecore_pipe_del (evas_info->epipe); + evas_info->epipe = NULL; + } + evas_object_image_data_set(evas_info->eo, NULL); + + evas_info->eo_size.x = evas_info->eo_size.y = + evas_info->eo_size.w = evas_info->eo_size.h = 0; + evas_info->w = evas_info->h = 0; + evas_info->eo = NULL; + evas_info->tbm_surf = NULL; + + g_mutex_lock (&evas_info->free_lock); + for(i=0; ipkt[i]) + { + /* destroy all packets */ + LOGD("destroy packet [%p]", evas_info->pkt[i]); + ret = media_packet_destroy(evas_info->pkt[i]); + if (ret != MEDIA_PACKET_ERROR_NONE) + LOGW("media_packet_destroy failed %p", evas_info->pkt[i]); + else + evas_info->sent_buffer_cnt--; + evas_info->pkt[i] = NULL; + } + } + g_mutex_unlock (&evas_info->free_lock); + + LOGW("it should be 0 --> [%d]", evas_info->sent_buffer_cnt); + evas_info->sent_buffer_cnt = 0; + evas_info->prev_idx = evas_info->cur_idx = -1; + g_mutex_clear (&evas_info->free_lock); + + return MM_ERROR_NONE; +} + +void +_player_update_geometry_evas_info (mm_evas_info *evas_info, rect_info *result) +{ + if (!evas_info || !evas_info->eo) { + LOGW("there is no evas_info or evas object"); + return; + } + + result->x = 0; + result->y = 0; + + switch (evas_info->display_geometry_method) + { + case DISP_GEO_METHOD_LETTER_BOX: + /* set black padding for letter box mode */ + LOGD("letter box mode"); + evas_info->use_ratio = TRUE; + result->w = evas_info->eo_size.w; + result->h = evas_info->eo_size.h; + break; + case DISP_GEO_METHOD_ORIGIN_SIZE: + LOGD("origin size mode"); + evas_info->use_ratio = FALSE; + /* set coordinate for each case */ + result->x = (evas_info->eo_size.w-evas_info->w) / 2; + result->y = (evas_info->eo_size.h-evas_info->h) / 2; + result->w = evas_info->w; + result->h = evas_info->h; + break; + case DISP_GEO_METHOD_FULL_SCREEN: + LOGD("full screen mode"); + evas_info->use_ratio = FALSE; + result->w = evas_info->eo_size.w; + result->h = evas_info->eo_size.h; + break; + case DISP_GEO_METHOD_CROPPED_FULL_SCREEN: + LOGD("cropped full screen mode"); + evas_info->use_ratio = FALSE; + /* compare evas object's ratio with video's */ + if((evas_info->eo_size.w/evas_info->eo_size.h) > (evas_info->w/evas_info->h)) + { + result->w = evas_info->eo_size.w; + result->h = evas_info->eo_size.w * evas_info->h / evas_info->w; + result->y = -(result->h-evas_info->eo_size.h) / 2; + } + else + { + result->w = evas_info->eo_size.h * evas_info->w / evas_info->h; + result->h = evas_info->eo_size.h; + result->x = -(result->w-evas_info->eo_size.w) / 2; + } + break; + case DISP_GEO_METHOD_ORIGIN_SIZE_OR_LETTER_BOX: + LOGD("origin size or letter box mode"); + /* if video size is smaller than evas object's, it will be set to origin size mode */ + if((evas_info->eo_size.w > evas_info->w) && (evas_info->eo_size.h > evas_info->h)) + { + LOGD("origin size mode"); + evas_info->use_ratio = FALSE; + /* set coordinate for each case */ + result->x = (evas_info->eo_size.w-evas_info->w) / 2; + result->y = (evas_info->eo_size.h-evas_info->h) / 2; + result->w = evas_info->w; + result->h = evas_info->h; + } + else + { + LOGD("letter box mode"); + evas_info->use_ratio = TRUE; + result->w = evas_info->eo_size.w; + result->h = evas_info->eo_size.h; + } + break; + default: + LOGW("unsupported mode."); + break; + } + LOGD("geometry result [%d, %d, %d, %d]", result->x, result->y, result->w, result->h); +} + +int +_player_apply_geometry_evas_info (mm_evas_info *evas_info) +{ + if (!evas_info || !evas_info->eo) { + LOGW("there is no evas_info or evas object"); + return MM_ERROR_NONE; + } + + Evas_Native_Surface *surf = evas_object_image_native_surface_get(evas_info->eo); + rect_info result = {0}; + + if(surf) + { + LOGD("native surface exists"); +// surf->data.tbm.rot = evas_info->rotate_angle; +// surf->data.tbm.flip = evas_info->flip; + evas_object_image_native_surface_set(evas_info->eo, surf); + + _player_update_geometry_evas_info(evas_info, &result); + + if(evas_info->use_ratio) + { +// surf->data.tbm.ratio = (float) evas_info->w / evas_info->h; + LOGD("set ratio for letter mode"); + } + + if(result.x || result.y) + LOGD("coordinate x, y (%d, %d) for locating video to center", result.x, result.y); + + evas_object_image_fill_set(evas_info->eo, result.x, result.y, result.w, result.h); + return MM_ERROR_NONE; + } + else + LOGW("there is no surf"); + /* FIXME: before pipe_cb is invoked, apply_geometry can be called. */ + return MM_ERROR_NONE; +} + +int player_update_video_param(MMHandleType player) +{ + int ret = MM_ERROR_NONE; + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type."); + return ret; + } + + /* when player is realized, we need to update all properties */ + if(handle) + { + LOGD("set video param : evas-object %x, method %d", handle->eo, handle->display_geometry_method); + LOGD("set video param : visible %d", handle->visible); + LOGD("set video param : rotate %d", handle->rotate_angle); + + ret = _player_apply_geometry_evas_info(handle); + if (ret != MM_ERROR_NONE) + return ret; + + if (handle->epipe) { + ret = ecore_pipe_write (handle->epipe, &handle->visible, UPDATE_VISIBILITY); + if (!ret) { + LOGW ("fail to ecore_pipe_write() for updating visibility\n"); + ret = MM_ERROR_PLAYER_NO_OP; + } else { + ret = MM_ERROR_NONE; + } + } + } + + return ret; +} + +int player_set_evas_info (MMHandleType *player, Evas_Object *eo) +{ + int ret = MM_ERROR_NONE; + mm_evas_info* handle = NULL; + + ret = _player_create_evas_info(&handle); + if ( ret != MM_ERROR_NONE ) { + LOGE("fail to create evas_info"); + return ret; + } + ret = _player_set_evas_info(handle, eo); + if ( ret != MM_ERROR_NONE ) { + LOGE("fail to set evas_info"); + if (_player_destroy_evas_info(handle) != MM_ERROR_NONE) + LOGE("fail to destroy evas_info"); + return ret; + } + + *player = (MMHandleType) handle; + + return MM_ERROR_NONE; +} + +int player_unset_evas_info (MMHandleType player) +{ + int ret = MM_ERROR_NONE; + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type."); + return ret; + } + + ret = _player_destroy_evas_info(handle); + if ( ret != MM_ERROR_NONE ) { + LOGE("fail to destroy evas_info"); + return ret; + } + handle = NULL; + + return MM_ERROR_NONE; +} + +int player_get_evas_info (MMHandleType player, mm_evas_info **evas_info) +{ + mm_evas_info* handle = (mm_evas_info*) player; + if(evas_info) { + *evas_info= handle; + LOGD("get evas_info %p", handle); + } + return MM_ERROR_NONE; +} + +int player_set_visible_evas_info (MMHandleType player, bool visible) +{ + int ret = MM_ERROR_NONE; + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type or player is not prepared"); + return MM_ERROR_RESOURCE_NOT_INITIALIZED; + } + + if(visible) + handle->visible = VISIBLE_TRUE; + else + handle->visible = VISIBLE_FALSE; + + if (handle->epipe) { + ret = ecore_pipe_write (handle->epipe, &visible, UPDATE_VISIBILITY); + if (!ret) { + LOGW ("fail to ecore_pipe_write() for updating visibility\n"); + ret = MM_ERROR_PLAYER_NO_OP; + } else { + ret = MM_ERROR_NONE; + } + } else { + LOGW("there is no epipe. we cant update it"); + } + + return ret; +} + +int player_get_visible_evas_info (MMHandleType player, bool *visible) +{ + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type or player is not prepared"); + return MM_ERROR_RESOURCE_NOT_INITIALIZED; + } + + if (handle->visible==VISIBLE_FALSE) + *visible = FALSE; + else + *visible = TRUE; + + return MM_ERROR_NONE; +} + +int player_set_rotation_evas_info (MMHandleType player, int rotate) +{ + int ret = MM_ERROR_NONE; + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type or player is not prepared"); + return MM_ERROR_RESOURCE_NOT_INITIALIZED; + } + + handle->rotate_angle = rotate; + ret = _player_apply_geometry_evas_info(handle); + + return ret; +} + +int player_get_rotation_evas_info (MMHandleType player, int *rotate) +{ + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type or player is not prepared"); + return MM_ERROR_RESOURCE_NOT_INITIALIZED; + } + *rotate = handle->rotate_angle; + + return MM_ERROR_NONE; +} + +int player_set_geometry_evas_info (MMHandleType player, int mode) +{ + int ret = MM_ERROR_NONE; + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type or player is not prepared"); + return MM_ERROR_RESOURCE_NOT_INITIALIZED; + } + + handle->display_geometry_method = mode; + ret = _player_apply_geometry_evas_info(handle); + + return ret; +} + +int player_get_geometry_evas_info (MMHandleType player, int *mode) +{ + mm_evas_info* handle = (mm_evas_info*) player; + + if (!handle) { + LOGW("skip it. it is not evas surface type or player is not prepared"); + return MM_ERROR_RESOURCE_NOT_INITIALIZED; + } + *mode = handle->display_geometry_method; + + return MM_ERROR_NONE; +} +