Merge "Add checking invalid wl_surface_id" into tizen
authoreunhae choi <eunhae1.choi@samsung.com>
Tue, 5 Jul 2016 04:25:29 +0000 (21:25 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 5 Jul 2016 04:25:29 +0000 (21:25 -0700)
1  2 
src/player.c

diff --combined src/player.c
index ad0646e,73a9412..10da14d
mode 100644,100755..100644
@@@ -40,7 -40,7 +40,7 @@@
  #include "player_private.h"
  #include "player_display.h"
  #include "player_msg.h"
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
  #include <mm_evas_renderer.h>
  #endif
  #define INVALID_SOCKET -1
@@@ -448,8 -448,9 +448,8 @@@ static void __subtitle_cb_handler(callb
        bool ret = TRUE;
  
        player_msg_get1_string(recvMsg, duration, INT, text, ret);
 -      if (ret) {
 +      if (ret)
                ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
 -      }
  }
  
  static void __capture_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
@@@ -641,8 -642,9 +641,8 @@@ static void __media_packet_video_frame_
                g_mutex_lock(&cb_info->data_mutex);
                cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
                LOGD("key %d is added to the pool", key[0]);
 -              if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list)) {
 +              if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
                        LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
 -              }
                g_mutex_unlock(&cb_info->data_mutex);
        } else {
                if (tsurf_data->tsurf) {
@@@ -1404,7 -1406,7 +1404,7 @@@ int player_destroy(player_h player
        LOGD("ENTER");
  
        player_msg_send(api, pc, ret_buf, ret);
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
                player_unset_media_packet_video_frame_decoded_cb(player);
                if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
@@@ -1503,7 -1505,7 +1503,7 @@@ int player_unprepare(player_h player
  
        if (!CALLBACK_INFO(pc))
                return PLAYER_ERROR_INVALID_STATE;
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                player_unset_media_packet_video_frame_decoded_cb(player);
                if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
@@@ -1786,7 -1788,7 +1786,7 @@@ int player_start(player_h player
        char *ret_buf = NULL;
  
        LOGD("ENTER");
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                ret = mm_evas_renderer_update_param(EVAS_HANDLE(pc));
                if (ret != PLAYER_ERROR_NONE)
@@@ -1855,8 -1857,9 +1855,8 @@@ int player_set_play_position(player_h p
                return PLAYER_ERROR_SEEK_FAILED;
        } else {
                g_mutex_lock(&pc->cb_info->seek_cb_mutex);
 -              if (pc->push_media_stream == TRUE) {
 +              if (pc->push_media_stream == TRUE)
                        pc->cb_info->block_seek_cb = TRUE;
 -              }
                LOGI("Event type : %d, pos : %d ", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond);
                pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
                pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
                g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
        }
  
 -      if (pc->push_media_stream == TRUE) {
 +      if (pc->push_media_stream == TRUE)
                _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
 -      }
  
        pc->cb_info->block_seek_cb = FALSE;
        g_free(ret_buf);
@@@ -2039,40 -2043,41 +2039,40 @@@ int player_set_display(player_h player
                                        LOGE("Fail to get window geometry");
                                        return ret;
                                }
 -                              if (_wl_window_evas_object_cb_add(player, obj) != MM_ERROR_NONE) {
 +                              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);
+                               return_val_if_fail(wl_surface != NULL, PLAYER_ERROR_INVALID_OPERATION);
  
                                /* get wl_display */
                                wl_display = (struct wl_display *)ecore_wl_display_get();
+                               return_val_if_fail(wl_display != NULL, PLAYER_ERROR_INVALID_OPERATION);
  
-                               if (!pc->wlclient) {
-                                       ret = _wl_client_create(&pc->wlclient);
-                                       if (ret != MM_ERROR_NONE) {
-                                               LOGE("Wayland client create failure");
-                                               return ret;
-                                       }
-                               }
-                               if (wl_surface && wl_display) {
-                                       LOGD("surface = %p, wl_display = %p", 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);
-                               } else {
-                                       LOGE("Fail to get wl_surface or wl_display");
-                                       return PLAYER_ERROR_INVALID_OPERATION;
+                               LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
+                               ret = _wl_client_create(&pc->wlclient);
+                               if (ret != MM_ERROR_NONE) {
+                                       LOGE("Wayland client create failure");
+                                       return ret;
                                }
+                               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);
+                               /* need to free always */
                                if (pc->wlclient) {
                                        g_free(pc->wlclient);
                                        pc->wlclient = NULL;
                                }
+                               return_val_if_fail(wl_surface_id > 0, PLAYER_ERROR_INVALID_OPERATION);
+                               wl_win.wl_surface_id = wl_surface_id;
                        }
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
                        else if (type == PLAYER_DISPLAY_TYPE_EVAS && !strcmp(object_type, "image")) {
                                /* evas object surface */
                                LOGI("evas surface type");
                                        if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
                                                LOGW("fail to unset evas client");
                                }
 -                              if (mm_evas_renderer_create(&EVAS_HANDLE(pc), obj) != MM_ERROR_NONE) {
 +                              if (mm_evas_renderer_create(&EVAS_HANDLE(pc), obj) != MM_ERROR_NONE)
                                        LOGW("fail to set evas client");
 -                              }
 -                              if (player_set_media_packet_video_frame_decoded_cb(player, mm_evas_renderer_write, (void *)EVAS_HANDLE(pc)) != PLAYER_ERROR_NONE) {
 +
 +                              if (player_set_media_packet_video_frame_decoded_cb(player, mm_evas_renderer_write, (void *)EVAS_HANDLE(pc)) != PLAYER_ERROR_NONE)
                                        LOGW("fail to set decoded callback");
 -                              }
                        }
  #endif
                        else
@@@ -2120,7 -2126,7 +2120,7 @@@ int player_set_display_mode(player_h pl
        char *ret_buf = NULL;
  
        LOGD("ENTER");
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                ret = mm_evas_renderer_set_geometry(EVAS_HANDLE(pc), mode);
                return ret;
@@@ -2142,7 -2148,7 +2142,7 @@@ int player_get_display_mode(player_h pl
        int mode = -1;
  
        LOGD("ENTER");
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                ret = mm_evas_renderer_get_geometry(EVAS_HANDLE(pc), &mode);
                *pmode = (player_display_mode_e) mode;
@@@ -2184,7 -2190,7 +2184,7 @@@ int player_set_display_rotation(player_
        char *ret_buf = NULL;
  
        LOGD("ENTER");
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                ret = mm_evas_renderer_set_rotation(EVAS_HANDLE(pc), rotation);
                return ret;
@@@ -2206,7 -2212,7 +2206,7 @@@ int player_get_display_rotation(player_
        int rotation = -1;
  
        LOGD("ENTER");
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                ret = mm_evas_renderer_get_rotation(EVAS_HANDLE(pc), &rotation);
                *protation = (player_display_rotation_e) rotation;
@@@ -2232,7 -2238,7 +2232,7 @@@ int player_set_display_visible(player_
        char *ret_buf = NULL;
  
        LOGD("ENTER");
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                ret = mm_evas_renderer_set_visible(EVAS_HANDLE(pc), visible);
                return ret;
@@@ -2252,11 -2258,11 +2252,11 @@@ int player_is_display_visible(player_h 
        muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
        char *ret_buf = NULL;
        int value = -1;
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        bool visible = 0;
  #endif
        LOGD("ENTER");
 -#ifdef EVAS_RENDERER_SUPPORT
 +#ifdef TIZEN_FEATURE_EVAS_RENDERER
        if (EVAS_HANDLE(pc)) {
                ret = mm_evas_renderer_get_visible(EVAS_HANDLE(pc), &visible);
                if (visible)