[0.2.116] check precondition about unsetting video decoded cb 46/206646/1
authorEunhye Choi <eunhae1.choi@samsung.com>
Wed, 22 May 2019 11:34:54 +0000 (20:34 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Wed, 22 May 2019 12:21:23 +0000 (21:21 +0900)
- unsetting video decoded callback api has state pre-condition
  which are idle and ready.
- legacy player need to keep the callback reference during preparing,
  so muse player set block not to export video data to client
  after idle state.

Change-Id: Icdb66d311c62bde434edceae03e13e3e17ad70d4

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

index 4a93195..d75d266 100644 (file)
@@ -39,6 +39,9 @@ extern "C" {
 #define PLAYER_STATE_CHECK(player, expected_state)       \
        PLAYER_CHECK_CONDITION(player->state == expected_state, PLAYER_ERROR_INVALID_STATE, "PLAYER_ERROR_INVALID_STATE")
 
+#define PLAYER_INTERNAL_STATE_CHECK(player, expected_state)    \
+       PLAYER_CHECK_CONDITION(player->internal_state == expected_state, PLAYER_ERROR_INVALID_STATE, "PLAYER_ERROR_INVALID_STATE")
+
 #define PLAYER_NULL_ARG_CHECK(arg)      \
        PLAYER_CHECK_CONDITION((arg), PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER")
 
@@ -95,7 +98,8 @@ typedef struct {
 
 typedef struct {
        muse_player_event_e type;
-       player_state_e state;
+       player_state_e set_state;
+       player_state_e unset_state;
 } legacy_player_callback_pre_state_t;
 
 int _lplayer_convert_error_code(int code, char *func_name);
index abf80d4..79964de 100644 (file)
@@ -547,19 +547,21 @@ static MMDisplaySurfaceType __lplayer_convert_display_type(player_display_type_e
        }
 }
 
-static int __lplayer_check_callback_precondition(legacy_player_t *handle, muse_player_event_e type)
+static int __lplayer_check_callback_precondition(legacy_player_t *handle, muse_player_event_e type, bool set)
 {
        int i = 0;
        int size = 0;
+       player_internal_state_e cb_state = PLAYER_INTERNAL_STATE_NONE;
+
        legacy_player_callback_pre_state_t callback_pre_state[] = {
-               {MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME, PLAYER_STATE_IDLE},
-               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS, PLAYER_STATE_IDLE},
-               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS, PLAYER_STATE_IDLE},
-               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO, PLAYER_STATE_IDLE},
-               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO, PLAYER_STATE_IDLE},
-               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK, PLAYER_STATE_IDLE},
-               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK, PLAYER_STATE_IDLE},
-               {MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, PLAYER_STATE_IDLE},
+               {MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME,                                       PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_IDLE},
+               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS,                       PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS,                       PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO,     PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO,     PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK,                                        PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+               {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK,                                        PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+               {MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED,                                           PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
        };
 
        size = sizeof(callback_pre_state)/sizeof(legacy_player_callback_pre_state_t);
@@ -567,7 +569,15 @@ static int __lplayer_check_callback_precondition(legacy_player_t *handle, muse_p
        /* check pre-state */
        for (; i < size; i++) {
                if (type == callback_pre_state[i].type) {
-                       PLAYER_STATE_CHECK(handle, callback_pre_state[i].state);
+                       if (set)
+                               cb_state = callback_pre_state[i].set_state;
+                       else
+                               cb_state = callback_pre_state[i].unset_state;
+
+                       if (cb_state == PLAYER_INTERNAL_STATE_NONE)
+                               break;
+
+                       PLAYER_INTERNAL_STATE_CHECK(handle, cb_state);
                        break;
                }
        }
@@ -1876,7 +1886,7 @@ int legacy_player_set_callback(legacy_player_h player, muse_player_event_e type,
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(callback);
 
-       ret = __lplayer_check_callback_precondition(handle, type);
+       ret = __lplayer_check_callback_precondition(handle, type, true);
        if (ret != PLAYER_ERROR_NONE) {
                LOGE("precondition failure, type %d", type);
                return ret;
@@ -1896,11 +1906,18 @@ int legacy_player_set_callback(legacy_player_h player, muse_player_event_e type,
 
 int legacy_player_unset_callback(legacy_player_h player, muse_player_event_e type)
 {
+       int ret = MM_ERROR_NONE;
        legacy_player_t *handle = (legacy_player_t *)player;
        PLAYER_INSTANCE_CHECK(player);
 
        LOGD("event type : %d ", type);
 
+       ret = __lplayer_check_callback_precondition(handle, type, false);
+       if (ret != PLAYER_ERROR_NONE) {
+               LOGE("precondition failure, type %d", type);
+               return ret;
+       }
+
        L_PLAYER_USER_CB_LOCK(player, type);
 
        handle->user_cb[type] = NULL;
index 5e07b2c..1897ce0 100644 (file)
@@ -851,14 +851,6 @@ static void __mplayer_buffering_cb(int percent, void *user_data)
        PLAYER_SEND_EVENT_MSG(api, ev, module, MUSE_TYPE_INT, "percent", percent);
 }
 
-static void __mplayer_set_enable_data_export(legacy_player_h player, void *data, bool set)
-{
-       muse_module_h module = (muse_module_h)data;
-       muse_player_handle_t *muse_player = (muse_player_handle_t *)muse_server_ipc_get_handle(module);
-
-       muse_player->export_video_data = set;
-}
-
 static void *__mplayer_callback_function[MUSE_PLAYER_EVENT_TYPE_NUM] = {
        NULL,                           /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
        __mplayer_default_callback,     /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
@@ -893,7 +885,7 @@ static void *__mplayer_callback_function[MUSE_PLAYER_EVENT_TYPE_NUM] = {
        NULL,                         /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME, DEPRECATED_PLAYER_INTERNAL_API */
 };
 
-static int __mplayer_set_callback_func(legacy_player_h player, muse_player_event_e type, bool set, void *user_data)
+static int __mplayer_set_callback_func(muse_player_handle_t *muse_player, muse_player_event_e type, bool set, void *user_data)
 {
        int ret = PLAYER_ERROR_NONE;
 
@@ -904,13 +896,24 @@ static int __mplayer_set_callback_func(legacy_player_h player, muse_player_event
                return PLAYER_ERROR_INVALID_OPERATION;
        }
 
-       if (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME)
-               __mplayer_set_enable_data_export(player, user_data, set);
-
        if (set)
-               ret = legacy_player_set_callback(player, type, __mplayer_callback_function[type], user_data);
+               ret = legacy_player_set_callback(muse_player->player_handle, type, __mplayer_callback_function[type], user_data);
        else
-               ret = legacy_player_unset_callback(player, type);
+               ret = legacy_player_unset_callback(muse_player->player_handle, type);
+
+       if (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) {
+
+               if (ret == PLAYER_ERROR_NONE) {
+                       muse_player->export_video_data = set;
+               } else if ((ret == PLAYER_ERROR_INVALID_STATE) && !set) {
+                       player_state_e curr_state = PLAYER_STATE_NONE;
+
+                       /* if current state is ready, data exporting need to be blocked */
+                       ret = legacy_player_get_state(muse_player->player_handle, &curr_state);
+                       if (ret == PLAYER_ERROR_NONE && (curr_state <= PLAYER_STATE_READY))
+                               muse_player->export_video_data = false;
+               }
+       }
 
        return ret;
 }
@@ -1273,14 +1276,21 @@ int player_disp_unprepare(muse_module_h module)
        int ret = PLAYER_ERROR_NONE;
        muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
        muse_player_handle_t *muse_player = NULL;
+       bool unset_cb = false;
 
        muse_player = (muse_player_handle_t *)muse_server_ipc_get_handle(module);
+       unset_cb = !muse_player->export_video_data;
 
        /* decoder buffer need to be released first to destroy pipeline */
        __mplayer_remove_export_media_packet(module);
 
        ret = legacy_player_unprepare(muse_player->player_handle);
 
+       /* if the data exporting was blocked, the legacy player callback need to be cleared.
+          clearing legacy player cb is possible in idle state only */
+       if (unset_cb)
+               legacy_player_unset_callback(muse_player->player_handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
+
        __mplayer_remove_export_data(module, 0, true);
 
        PLAYER_RETURN_MSG(api, ret, module);
@@ -2500,7 +2510,7 @@ int player_disp_set_callback(muse_module_h module)
        }
 
        muse_player = (muse_player_handle_t *)muse_server_ipc_get_handle(module);
-       ret = __mplayer_set_callback_func(muse_player->player_handle, type, set, module);
+       ret = __mplayer_set_callback_func(muse_player, type, set, module);
        if (ret != PLAYER_ERROR_NONE) {
                LOGE("failed to set callback type %d", type);
                /* goto EXIT; */
index dc7e9b7..30cd6e0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mmsvc-player
 Summary:    A Media Player module for muse server
-Version:    0.2.115
+Version:    0.2.116
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0