[0.2.98] avoid duplicated player releasement 95/197095/3
authorEunhae Choi <eunhae1.choi@samsung.com>
Wed, 9 Jan 2019 11:34:18 +0000 (20:34 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Wed, 9 Jan 2019 12:16:43 +0000 (21:16 +0900)
- the prepare_async thread is different from the
  dispatcher thread. so duplicated player releasement
  can cause crash by accessing invalid pointer.

Change-Id: I1aae3bd17be4c49a037485d5be72dbf0936a389d

legacy/include/legacy_player_private.h
legacy/src/legacy_player.c
packaging/mmsvc-player.spec

index f638d70..0b72b1a 100644 (file)
@@ -23,6 +23,9 @@
 extern "C" {
 #endif
 
+#define LPLAYER_FENTER() LOGI("<ENTER>");
+#define LPLAYER_FLEAVE() LOGI("<LEAVE>");
+
 #define PLAYER_CHECK_CONDITION(condition, error, msg)     \
        do {    \
                if (condition) {} else \
@@ -109,6 +112,7 @@ typedef struct _player_s {
        player_internal_state_e internal_state;
        bool is_display_visible;
        bool is_media_stream;
+       bool is_shutdown;
        pthread_t prepare_async_thread;
        pthread_t message_thread;
        GQueue *message_queue;
index b4f4269..5f5477e 100644 (file)
@@ -640,6 +640,8 @@ int legacy_player_destroy(player_h player)
        PLAYER_TRACE_BEGIN("MM:PLAYER:DESTROY");
        PLAYER_INSTANCE_CHECK(player);
 
+       handle->is_shutdown = true;
+
        __ADD_MESSAGE(handle, PLAYER_MESSAGE_LOOP_EXIT);
 
        LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
@@ -693,24 +695,28 @@ static void *__prepare_async_thread_func(void *data)
 {
        player_s *handle = data;
        int ret = MM_ERROR_NONE;
-       LOGI("[%s]", __FUNCTION__);
+       LPLAYER_FENTER();
 
        ret = mm_player_pause(handle->mm_handle);
        if (ret != MM_ERROR_NONE) {
-               LOGE("[%s] Failed to pause - core fw error(0x%x)", __FUNCTION__, ret);
+               LOGE("Failed to pause - core fw error(0x%x)", ret);
+               __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
+
                if (handle->error_code == PLAYER_ERROR_NONE) {
-                       /*MM_MESSAGE_ERROR will not be posted as legacy_player_prepare(sync API) works with return value
-                          of mm_player_pause So in case of async API we post the error message to application from here */
+                       /* if there is no received error msg, it has to be posted here. */
                        MMMessageParamType msg_param;
                        msg_param.code = ret;
                        __msg_callback(MM_MESSAGE_ERROR, (void *)&msg_param, (void *)handle);
                }
-               ret = mm_player_unrealize(handle->mm_handle);
-               if (ret != MM_ERROR_NONE)
-                       LOGE("[%s] Failed to unrealize - 0x%x", __FUNCTION__, ret);
-               __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
+
+               if (!handle->is_shutdown) {
+                       ret = mm_player_unrealize(handle->mm_handle);
+                       if (ret != MM_ERROR_NONE)
+                               LOGE("Failed to unrealize - 0x%x", ret);
+               }
        }
-       LOGI("[%s], done", __FUNCTION__);
+
+       LPLAYER_FLEAVE();
        return NULL;
 }
 
@@ -867,10 +873,13 @@ int legacy_player_unprepare(player_h player)
 {
        player_s *handle = (player_s *)player;
        int ret = MM_ERROR_NONE;
-       LOGI("[%s] Start", __FUNCTION__);
+
+       LPLAYER_FENTER();
        PLAYER_TRACE_BEGIN("MM:PLAYER:UNPREPARE");
        PLAYER_INSTANCE_CHECK(player);
 
+       handle->is_shutdown = true;
+
        /* Initialize the setting regardless of error return */
        if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK]) {
                handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
@@ -903,7 +912,8 @@ int legacy_player_unprepare(player_h player)
 
        __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
        handle->is_display_visible = true;
-       LOGI("[%s] End", __FUNCTION__);
+
+       LPLAYER_FLEAVE();
        PLAYER_TRACE_END();
        return PLAYER_ERROR_NONE;
 }
index d61b417..87a94c0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mmsvc-player
 Summary:    A Media Player module for muse server
-Version:    0.2.97
+Version:    0.2.98
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0