[v0.2.39] add user cb lock 68/106868/2
authorEunhae Choi <eunhae1.choi@samsung.com>
Fri, 23 Dec 2016 08:54:03 +0000 (17:54 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Fri, 23 Dec 2016 08:56:46 +0000 (17:56 +0900)
Change-Id: Id4faebbd5b9a04b5c749424414c690dc9e87a2bb
Signed-off-by: Eunhae Choi <eunhae1.choi@samsung.com>
legacy/include/legacy_player_private.h
legacy/src/legacy_player.c
legacy/src/legacy_player_internal.c
packaging/mmsvc-player.spec

index a022ac1e7e2f360e1e4b9310046b452aa20aaded..7919640a35af5eb6795427d0cbeba6a513b1e3b4 100644 (file)
@@ -48,6 +48,20 @@ extern "C" {
         PLAYER_CHECK_CONDITION(arg <= max,PLAYER_ERROR_INVALID_PARAMETER,"PLAYER_ERROR_INVALID_PARAMETER")             \
         PLAYER_CHECK_CONDITION(arg >= min,PLAYER_ERROR_INVALID_PARAMETER,"PLAYER_ERROR_INVALID_PARAMETER")
 
+/* user_cb_lock */
+#define LEGACY_PLAYER_USER_CB_LOCK(x_handle,type) \
+       do { \
+               if (_check_enabled_user_cb_lock(type))  \
+                       g_mutex_lock(&((player_s*)x_handle)->user_cb_lock[type]);       \
+       } while (0)
+
+#define LEGACY_PLAYER_USER_CB_UNLOCK(x_handle,type) \
+       do { \
+               if (_check_enabled_user_cb_lock(type))  \
+                       g_mutex_unlock(&((player_s*)x_handle)->user_cb_lock[type]);     \
+       } while (0)
+
+
 #ifdef TIZEN_TTRACE
 #include <ttrace.h>
 #define PLAYER_TRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_VIDEO, NAME)
@@ -77,6 +91,7 @@ typedef struct _player_s{
        MMHandleType mm_handle;
        const void* user_cb[MUSE_PLAYER_EVENT_TYPE_NUM];
        void* user_data[MUSE_PLAYER_EVENT_TYPE_NUM];
+       GMutex user_cb_lock[MUSE_PLAYER_EVENT_TYPE_NUM];
        void* wl_display;
        void* display_handle;
        player_display_type_e display_type;
@@ -114,6 +129,7 @@ int legacy_player_sound_register(player_h player, int pid);
 int legacy_player_get_timeout_for_muse(player_h player, int *timeout);
 int legacy_player_get_num_of_video_out_buffers(player_h player, int *num, int *extra_num);
 int legacy_player_set_file_buffering_path(player_h player, const char *file_path);
+bool _check_enabled_user_cb_lock(int event_id);
 
 #ifdef __cplusplus
 }
index 9ee6974242f43c0b5e0eca89d21c7edf26546b52..df27e49ed9ac68d618beec34891523f69dcc6781 100644 (file)
@@ -865,6 +865,8 @@ static bool __video_stream_callback(void *stream, void *user_data)
        player_s *handle = (player_s *)user_data;
        MMPlayerVideoStreamDataType *video_stream = (MMPlayerVideoStreamDataType *)stream;
 
+       LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
+
        if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
                /* media packet and zero-copy */
                media_packet_h pkt = NULL;
@@ -914,16 +916,20 @@ static bool __video_stream_callback(void *stream, void *user_data)
                        unsigned char *ptr = video_stream->data[0];
                        unsigned char *ptr2 = video_stream->data[1];
 
-                       if (!ptr)
+                       if (!ptr) {
+                               LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
                                return TRUE;
-                       if (!ptr2 && video_stream->format == MM_PIXEL_FORMAT_NV12T)
+                       }
+                       if (!ptr2 && video_stream->format == MM_PIXEL_FORMAT_NV12T) {
+                               LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
                                return TRUE;
-
+                       }
                        tsurf = tbm_surface_create(video_stream->width, video_stream->height, bo_format);
                        if (tsurf) {
                                /* map surface to set data */
                                if (tbm_surface_map(tsurf, TBM_SURF_OPTION_READ | TBM_SURF_OPTION_WRITE, &tsuri)) {
                                        LOGE("tbm_surface_map failed");
+                                       LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
                                        return TRUE;
                                }
 
@@ -1030,6 +1036,8 @@ static bool __video_stream_callback(void *stream, void *user_data)
                        }
                }
        }
+
+       LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
        return TRUE;
 }
 
@@ -1048,9 +1056,13 @@ static int __pd_message_callback(int message, void *param, void *user_data)
                return 0;
        }
 
+       LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PD);
+
        if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PD])
                ((player_pd_message_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PD])(type, handle->user_data[MUSE_PLAYER_EVENT_TYPE_PD]);
 
+       LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PD);
+
        return 0;
 }
 
@@ -1084,6 +1096,18 @@ static MMDisplaySurfaceType __player_convet_display_type(player_display_type_e t
        }
 }
 
+bool _check_enabled_user_cb_lock(int type)
+{
+       if ((type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) ||
+               (type == MUSE_PLAYER_EVENT_TYPE_PD) ||
+               (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO) ||
+               (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO)) {
+               return TRUE;
+       } else {
+               return FALSE;
+       }
+}
+
 /*
 * Public Implementation
 */
@@ -1108,12 +1132,20 @@ int legacy_player_create(player_h *player)
                handle = NULL;
                return __player_convert_error_code(ret, (char *)__FUNCTION__);
        } else {
+               muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PREPARE;
+
                *player = (player_h)handle;
                handle->state = PLAYER_STATE_IDLE;
                handle->display_type = PLAYER_DISPLAY_TYPE_NONE;
                handle->is_stopped = FALSE;
                handle->is_display_visible = TRUE;
                handle->is_media_stream = FALSE;
+
+               for (type = MUSE_PLAYER_EVENT_TYPE_PREPARE; type < MUSE_PLAYER_EVENT_TYPE_NUM; type++) {
+                       if (_check_enabled_user_cb_lock(type)) {
+                               g_mutex_init(&handle->user_cb_lock[type]);
+                       }
+               }
 #ifdef USE_ECORE_FUNCTIONS
                handle->ecore_jobs = g_hash_table_new_full(g_str_hash, g_str_equal, __job_key_to_remove, __job_value_to_destroy);
 #else
@@ -1168,7 +1200,16 @@ int legacy_player_destroy(player_h player)
                LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, PLAYER_ERROR_INVALID_OPERATION);
                return PLAYER_ERROR_INVALID_OPERATION;
        } else {
+               muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PREPARE;
+
                handle->state = PLAYER_STATE_NONE;
+
+               for (type = MUSE_PLAYER_EVENT_TYPE_PREPARE; type < MUSE_PLAYER_EVENT_TYPE_NUM; type++) {
+                       if (_check_enabled_user_cb_lock(type)) {
+                               g_mutex_clear(&handle->user_cb_lock[type]);
+                       }
+               }
+
 #ifndef USE_ECORE_FUNCTIONS
                if (handle->message_queue) {
                        g_queue_free(handle->message_queue);
@@ -2565,8 +2606,10 @@ int legacy_player_unset_progressive_download_message_cb(player_h player)
        PLAYER_INSTANCE_CHECK(player);
        player_s *handle = (player_s *)player;
 
+       LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PD);
        handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PD] = NULL;
        handle->user_data[MUSE_PLAYER_EVENT_TYPE_PD] = NULL;
+       LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PD);
        LOGI("[%s] Event type : %d ", __FUNCTION__, MUSE_PLAYER_EVENT_TYPE_PD);
 
        int ret = mm_player_set_pd_message_callback(handle->mm_handle, NULL, NULL);
@@ -2603,9 +2646,13 @@ int legacy_player_unset_media_packet_video_frame_decoded_cb(player_h player)
        PLAYER_INSTANCE_CHECK(player);
        player_s *handle = (player_s *)player;
 
+       LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
+
        handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = NULL;
        handle->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = NULL;
 
+       LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
+
        LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
 
        int ret = mm_player_set_video_stream_callback(handle->mm_handle, NULL, NULL);
index 7f00f95584d566cc5da8e3d8b01817a6ae807501..d8be58337986fd3eb549d93e4dd4e83c1f954458 100644 (file)
@@ -38,7 +38,7 @@ do { \
        handle->user_cb[event_type] = callback; \
        handle->user_data[event_type] = user_data; \
        LOGI("[%s] Event type : %d ", __FUNCTION__, event_type); \
-} while (0) \
+} while (0)
 
 bool __audio_stream_callback_ex(MMPlayerAudioStreamDataType *stream, void *user_data)
 {
@@ -137,13 +137,18 @@ static bool __media_stream_buffer_status_callback_ex(player_stream_type_e type,
 
        LOGE("[%s] event type %d, status %d, bytes %llu", __FUNCTION__, event_type, status, bytes);
 
+       LEGACY_PLAYER_USER_CB_LOCK(handle, event_type);
+
        if (handle->user_cb[event_type]) {
                ((player_media_stream_buffer_status_cb_ex)handle->user_cb[event_type])(status, bytes, handle->user_data[event_type]);
        } else {
                LOGE("[%s][type:%d] buffer status cb was not set.", __FUNCTION__, type);
+               LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
                return FALSE;
        }
 
+       LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
+
        return TRUE;
 }
 
@@ -166,21 +171,27 @@ int legacy_player_set_media_stream_buffer_status_cb_ex(player_h player, player_s
                return PLAYER_ERROR_INVALID_PARAMETER;
        }
 
-       ret = mm_player_set_media_stream_buffer_status_callback(handle->mm_handle, type, (mm_player_media_stream_buffer_status_callback)__media_stream_buffer_status_callback_ex, (void *)handle);
-
-       if (ret != MM_ERROR_NONE)
-               return __player_convert_error_code(ret, (char *)__FUNCTION__);
-
        if (type == PLAYER_STREAM_TYPE_VIDEO)
                event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
        else
                event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
 
-       LOGI("[%s] Event type : %d ", __FUNCTION__, type);
+
+       ret = mm_player_set_media_stream_buffer_status_callback(handle->mm_handle, type, (mm_player_media_stream_buffer_status_callback)__media_stream_buffer_status_callback_ex, (void *)handle);
+
+       if (ret != MM_ERROR_NONE) {
+               LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
+               return __player_convert_error_code(ret, (char *)__FUNCTION__);
+       }
+
+       LEGACY_PLAYER_USER_CB_LOCK(handle, event_type);
 
        handle->user_cb[event_type] = callback;
        handle->user_data[event_type] = user_data;
 
+       LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
+
+       LOGI("[%s] Event type : %d ", __FUNCTION__, type);
        return PLAYER_ERROR_NONE;
 }
 
@@ -198,12 +209,17 @@ int legacy_player_unset_media_stream_buffer_status_cb_ex(player_h player, player
        else
                return PLAYER_ERROR_INVALID_PARAMETER;
 
+       LEGACY_PLAYER_USER_CB_LOCK(handle, event_type);
+
        handle->user_cb[event_type] = NULL;
        handle->user_data[event_type] = NULL;
 
+       LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
+
        LOGI("[%s] Event type : %d ", __FUNCTION__, type);
 
        ret = mm_player_set_media_stream_buffer_status_callback(handle->mm_handle, type, NULL, NULL);
+
        if (ret != MM_ERROR_NONE)
                return __player_convert_error_code(ret, (char *)__FUNCTION__);
        else
@@ -320,4 +336,4 @@ int legacy_player_enable_media_packet_video_frame_decoded_cb(player_h player, bo
                return __player_convert_error_code(ret, (char *)__FUNCTION__);
        else
                return PLAYER_ERROR_NONE;
-}
\ No newline at end of file
+}
index 6bcc1eea8eb82eae2f866eab878650ed6f652a23..d7587db68152247f6336e64d4ac8e859be342df8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mmsvc-player
 Summary:    A Media Player module for muse server
-Version:    0.2.38
+Version:    0.2.39
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0