[0.2.111] remove message queue 89/205689/3 accepted/tizen/unified/20190510.111043 submit/tizen/20190509.085544
authorEunhye Choi <eunhae1.choi@samsung.com>
Wed, 8 May 2019 11:06:29 +0000 (20:06 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Wed, 8 May 2019 11:22:50 +0000 (20:22 +0900)
- Remove message queue which was added to invoke client cb
  when there was no mused.
- Use attribute to get the number of buffer information
  instead of calling the libmm-player function to avoid deadlock.

Change-Id: Ia48c7370a5ec414ff856a7cc14a98e44aef52cf2

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

index e3f8166..5406dfa 100644 (file)
@@ -197,7 +197,7 @@ typedef void (*player_subtitle_updated_cb)(unsigned long duration, char *text, v
  * @post The player state will be #PLAYER_STATE_READY.
  * @see legacy_player_prepare_async()
  */
-typedef void (*player_prepared_cb)(void *user_data);
+typedef void (*legacy_player_prepared_cb)(void *user_data);
 
 /**
  * @brief Called when the media player is completed.
@@ -419,7 +419,7 @@ int legacy_player_prepare(legacy_player_h player);
  * @see legacy_player_unprepare()
  * @see legacy_player_set_uri()
  */
-int legacy_player_prepare_async(legacy_player_h player, player_prepared_cb callback, void *user_data);
+int legacy_player_prepare_async(legacy_player_h player, legacy_player_prepared_cb callback, void *user_data);
 
 /**
  * @brief Resets the media player.
index cbc5dda..1bf77de 100644 (file)
@@ -75,19 +75,6 @@ extern "C" {
 #endif
 
 typedef enum {
-       PLAYER_MESSAGE_NONE,
-       PLAYER_MESSAGE_PREPARED,
-       PLAYER_MESSAGE_ERROR,
-       PLAYER_MESSAGE_SEEK_DONE,
-       PLAYER_MESSAGE_EOS,
-       PLAYER_MESSAGE_LOOP_EXIT,
-#ifdef TIZEN_FEATURE_EVAS_RENDERER
-       PLAYER_MESSAGE_GAPLESS_CONSTRUCTION,
-#endif
-       PLAYER_MESSAGE_MAX
-} player_message_e;
-
-typedef enum {
        PLAYER_INTERNAL_STATE_NONE,
        PLAYER_INTERNAL_STATE_IDLE,
        PLAYER_INTERNAL_STATE_PRE_READY,
@@ -114,11 +101,6 @@ typedef struct {
        bool is_media_stream;
        bool is_shutdown;
        pthread_t prepare_async_thread;
-       pthread_t message_thread;
-       GQueue *message_queue;
-       GMutex message_queue_lock;
-       GCond message_queue_cond;
-       int current_message;
        player_error_e error_code;
        int64_t last_play_position;
 } legacy_player_t;
index 3bca057..3142ed3 100644 (file)
                } \
        } while (0)
 
-#define __RELEASEIF_MESSAGE_THREAD(thread_id) \
-       do { \
-               if (thread_id) { \
-                       pthread_join(thread_id, NULL); \
-                       thread_id = 0; \
-                       LOGI("message thread released\n"); \
-               } \
-       } while (0)
-
-#define        __GET_MESSAGE(handle) \
-       do { \
-               if (handle && handle->message_queue) { \
-                       g_mutex_lock(&handle->message_queue_lock); \
-                       if (g_queue_is_empty(handle->message_queue)) { \
-                               g_cond_wait(&handle->message_queue_cond, &handle->message_queue_lock); \
-                       } \
-                       handle->current_message = (int)(intptr_t)g_queue_pop_head(handle->message_queue); \
-                       g_mutex_unlock(&handle->message_queue_lock); \
-                       LOGI("Retrieved  message [%d] from queue", handle->current_message); \
-               } else { \
-                       LOGI("Failed to retrieve message from queue"); \
-                       handle->current_message = PLAYER_MESSAGE_NONE; \
-               } \
-       } while (0)
-
-#define        __ADD_MESSAGE(handle, message) \
-       do { \
-               if (handle && handle->message_queue) { \
-                       g_mutex_lock(&handle->message_queue_lock); \
-                       if (message == PLAYER_MESSAGE_LOOP_EXIT) \
-                               g_queue_clear(handle->message_queue); \
-                       g_queue_push_tail(handle->message_queue, (gpointer)message); \
-                       g_cond_signal(&handle->message_queue_cond); \
-                       g_mutex_unlock(&handle->message_queue_lock); \
-                       LOGI("Adding message [%d] to queue", message); \
-               } else { \
-                       LOGI("Failed to add message [%d] to queue", message); \
-               } \
-       } while (0)
-
 /*
  * Internal Implementation
  */
@@ -305,99 +265,6 @@ static int __unset_callback(muse_player_event_e type, legacy_player_h player)
        return PLAYER_ERROR_NONE;
 }
 
-static void __message_cb_loop(void *data)
-{
-       bool running = true;
-       legacy_player_t *handle = (legacy_player_t *)data;
-       if (!handle) {
-               LOGE("null handle in __message_cb_loop");
-               return;
-       }
-       do {
-               __GET_MESSAGE(handle);
-               switch (handle->current_message) {
-               case PLAYER_MESSAGE_NONE:
-                       {
-                               LOGW("PLAYER_MESSAGE_NONE");
-                               running = false;
-                       }
-                       break;
-               case PLAYER_MESSAGE_PREPARED:
-                       {
-                               LOGW("PLAYER_MESSAGE_PREPARED");
-
-                               LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
-                               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
-                                       __player_update_state(handle, PLAYER_INTERNAL_STATE_READY);
-                                       ((player_prepared_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
-                                       handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
-                                       handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
-                               } else {
-                                       LOGE("null handle in PLAYER_MESSAGE_PREPARED");
-                               }
-                               LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
-                       }
-                       break;
-               case PLAYER_MESSAGE_ERROR:
-                       {
-                               LOGW("PLAYER_MESSAGE_ERROR");
-                               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
-                                       ((player_error_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])(handle->error_code, handle->user_data[MUSE_PLAYER_EVENT_TYPE_ERROR]);
-                               else
-                                       LOGE("null handle in PLAYER_MESSAGE_ERROR");
-                       }
-                       break;
-               case PLAYER_MESSAGE_SEEK_DONE:
-                       {
-                               LOGW("PLAYER_MESSAGE_SEEK_DONE");
-                               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK]) {
-                                       ((player_seek_completed_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK]);
-                                       handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
-                                       handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
-                               } else {
-                                       LOGE("null handle in PLAYER_MESSAGE_SEEK_DONE");
-                               }
-                       }
-                       break;
-               case PLAYER_MESSAGE_EOS:
-                       {
-                               LOGW("PLAYER_MESSAGE_EOS");
-                               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE])
-                                       ((player_completed_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_COMPLETE]);
-                               else
-                                       LOGE("null handle in PLAYER_MESSAGE_EOS");
-                       }
-                       break;
-#ifdef TIZEN_FEATURE_EVAS_RENDERER
-               case PLAYER_MESSAGE_GAPLESS_CONSTRUCTION:
-                       {
-                               LOGW("PLAYER_MESSAGE_GAPLESS_CONSTRUCTION");
-                               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER])
-                                       ((player_retrieve_buffer_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER]);
-                               else
-                                       LOGE("null handle in PLAYER_MESSAGE_GAPLESS_CONSTRUCTION");
-                       }
-                       break;
-#endif
-               case PLAYER_MESSAGE_LOOP_EXIT:
-                       {
-                               LOGW("PLAYER_MESSAGE_LOOP_EXIT");
-                               running = false;
-                       }
-                       break;
-               case PLAYER_MESSAGE_MAX:
-                       {
-                               LOGW("PLAYER_MESSAGE_MAX");
-                               running = false;
-                       }
-                       break;
-               default:
-                       break;
-               }
-       } while (running);
-       return;
-}
-
 static player_state_e __convert_player_state(mmplayer_state_e state)
 {
        if (state == MM_PLAYER_STATE_NONE)
@@ -433,10 +300,15 @@ static int __msg_callback(int message, void *param, void *user_data)
                if (msg->state.previous == MM_PLAYER_STATE_READY && msg->state.current == MM_PLAYER_STATE_PAUSED) {
                        LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
                        if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
-                               /* asyc && prepared cb has been set */
-                               LOGI("Prepared! [current state : %d]", handle->state);
+                               /* async && prepared cb has been set */
+                               LOGD("Prepared! [current state : %d]", handle->state);
                                PLAYER_TRACE_ASYNC_END("MM:PLAYER:PREPARE_ASYNC", *(int *)handle);
-                               __ADD_MESSAGE(handle, PLAYER_MESSAGE_PREPARED);
+
+                               __player_update_state(handle, PLAYER_INTERNAL_STATE_READY);
+                               ((legacy_player_prepared_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
+
+                               handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
+                               handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
                        }
                        LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
                }
@@ -445,13 +317,15 @@ static int __msg_callback(int message, void *param, void *user_data)
                LOGI("Ready to streaming information (BOS) [current state : %d]", handle->state);
                break;
        case MM_MESSAGE_END_OF_STREAM:  /* 0x105 */
-               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE])
-                       __ADD_MESSAGE(handle, PLAYER_MESSAGE_EOS);
+               if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE]) {
+                       LOGD("Playback is completed.");
+                       ((player_completed_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_COMPLETE]);
+               }
                break;
 #ifdef TIZEN_FEATURE_EVAS_RENDERER
        case MM_MESSAGE_GAPLESS_CONSTRUCTION:   /* 0x105 */
                if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER])
-                       __ADD_MESSAGE(handle, PLAYER_MESSAGE_GAPLESS_CONSTRUCTION);
+                       ((player_retrieve_buffer_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER]);
                break;
 #endif
        case MM_MESSAGE_BUFFERING:      /* 0x103 */
@@ -526,7 +400,10 @@ static int __msg_callback(int message, void *param, void *user_data)
                        }
                }
                if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK]) {
-                       __ADD_MESSAGE(handle, PLAYER_MESSAGE_SEEK_DONE);
+                       LOGD("Seek is completed");
+                       ((player_seek_completed_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK]);
+                       handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
+                       handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
                }
                break;
        case MM_MESSAGE_PLAY_POSITION:
@@ -550,7 +427,8 @@ static int __msg_callback(int message, void *param, void *user_data)
 
        if (err_code != PLAYER_ERROR_NONE && handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR]) {
                handle->error_code = err_code;
-               __ADD_MESSAGE(handle, PLAYER_MESSAGE_ERROR);
+               LOGE("ERROR is occurred 0x%X", err_code);
+               ((player_error_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])(err_code, handle->user_data[MUSE_PLAYER_EVENT_TYPE_ERROR]);
        }
 
        LPLAYER_FLEAVE();
@@ -623,15 +501,6 @@ int legacy_player_create(legacy_player_h *player)
                        g_mutex_init(&handle->user_cb_lock[type]);
        }
 
-       handle->message_queue = g_queue_new();
-       g_mutex_init(&handle->message_queue_lock);
-       g_cond_init(&handle->message_queue_cond);
-       ret = pthread_create(&handle->message_thread, NULL, (void *)__message_cb_loop, (void *)handle);
-       if (ret != 0) {
-               LOGE("Failed to create message thread 0x%X", ret);
-               return PLAYER_ERROR_OUT_OF_MEMORY;
-       }
-
        LOGI("new handle : %p", *player);
        PLAYER_TRACE_END();
        return PLAYER_ERROR_NONE;
@@ -648,8 +517,6 @@ int legacy_player_destroy(legacy_player_h player)
 
        handle->is_shutdown = true;
 
-       __ADD_MESSAGE(handle, PLAYER_MESSAGE_LOOP_EXIT);
-
        LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
        if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
                handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
@@ -663,7 +530,6 @@ int legacy_player_destroy(legacy_player_h player)
                mm_player_abort_pause(handle->mm_handle);
 
        __RELEASEIF_PREPARE_THREAD(handle->prepare_async_thread);
-       __RELEASEIF_MESSAGE_THREAD(handle->message_thread);
 
        ret = mm_player_destroy(handle->mm_handle);
        if (ret != MM_ERROR_NONE) {
@@ -681,15 +547,6 @@ int legacy_player_destroy(legacy_player_h player)
                        g_mutex_clear(&handle->user_cb_lock[type]);
        }
 
-       if (handle->message_queue) {
-               g_queue_free(handle->message_queue);
-               handle->message_queue = NULL;
-       }
-
-       g_cond_broadcast(&handle->message_queue_cond);
-       g_mutex_clear(&handle->message_queue_lock);
-       g_cond_clear(&handle->message_queue_cond);
-
        g_free(handle);
        handle = NULL;
 
@@ -727,7 +584,7 @@ static void *__prepare_async_thread_func(void *data)
        return NULL;
 }
 
-int legacy_player_prepare_async(legacy_player_h player, player_prepared_cb callback, void *user_data)
+int legacy_player_prepare_async(legacy_player_h player, legacy_player_prepared_cb callback, void *user_data)
 {
        legacy_player_t *handle = (legacy_player_t *)player;
        int ret = MM_ERROR_NONE;
@@ -2549,7 +2406,8 @@ int legacy_player_get_num_of_video_out_buffers(legacy_player_h player, int *num,
        PLAYER_NULL_ARG_CHECK(num);
        PLAYER_NULL_ARG_CHECK(extra_num);
 
-       ret = mm_player_get_num_of_video_out_buffers(handle->mm_handle, num, extra_num);
+       ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_VIDEO_BUFFER_TOTAL_SIZE, num,
+               MM_PLAYER_VIDEO_BUFFER_EXTRA_SIZE, extra_num, (char *)NULL);
        if (ret != MM_ERROR_NONE)
                return __player_convert_error_code(ret, (char *)__FUNCTION__);
 
index 0a6f05d..5a2f4f3 100644 (file)
@@ -508,7 +508,7 @@ static void __player_callback(muse_player_event_e ev, muse_module_h module)
 {
        muse_player_cb_e api = MUSE_PLAYER_CB_EVENT;
 
-       LOGD("ENTER");
+       LOGD("ENTER event: %d", ev);
 
        PLAYER_SEND_EVENT_MSG(api, ev, module);
 }
index 8c235c5..8e3f77e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mmsvc-player
 Summary:    A Media Player module for muse server
-Version:    0.2.110
+Version:    0.2.111
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0