[1.0.1] Clean up buffers when receive pipeline removed event 02/314102/4 accepted/tizen_unified accepted/tizen_unified_dev accepted/tizen_unified_x tizen accepted/tizen/unified/20240711.011439 accepted/tizen/unified/dev/20240711.085714 accepted/tizen/unified/x/20240711.084613
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 5 Jul 2024 07:35:02 +0000 (16:35 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Tue, 9 Jul 2024 02:16:46 +0000 (11:16 +0900)
Change-Id: I08a3d56a4d81872c3102ab4cb56e0e86b9eb91a3
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/player_private.h
packaging/capi-media-player.spec
src/player.c

index 5b54dc2..f2029b0 100644 (file)
@@ -180,6 +180,7 @@ typedef struct _callback_cb_info {
        int video_frame_pool_size;
        bool use_tsurf_pool;
        player_display_info_s dp_info;
+       void *pc;
 } callback_cb_info_s;
 
 typedef struct {
index 06fb1f6..4fe92c3 100644 (file)
@@ -1,7 +1,7 @@
 Name:       capi-media-player
 Summary:    A Media Player API
-Version:    1.0.0
-Release:    1
+Version:    1.0.1
+Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index ea82154..ed79280 100644 (file)
@@ -1600,29 +1600,87 @@ static void _player_event_queue_add(player_event_queue *ev, _player_cb_data *dat
        }
 }
 
+static void _player_internal_buffer_release(player_cli_s *pc)
+{
+       mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
+
+       if (!pc || !pc->cb_info) {
+               LOGE("NULL handle[%p]", pc);
+               return;
+       }
+
+       LOGI("ENTER");
+
+       if (!DP_INTERFACE(pc)) {
+               LOGW("display port interface is NULL");
+               goto RELEASE_INTERNAL_MOMORY;
+       }
+
+       if (mm_display_interface_get_type(DP_INTERFACE(pc), &display_type) != MM_ERROR_NONE) {
+               LOGE("get display type failed");
+               return;
+       }
+
+       if (display_type != MM_DISPLAY_TYPE_EVAS)
+               goto RELEASE_INTERNAL_MOMORY;
+
+       if (CALLBACK_INFO(pc)->dp_info.visible != PLAYER_VISIBLE_INFO_FALSE) {
+               if (mm_display_interface_evas_set_visible(DP_INTERFACE(pc), false) != MM_ERROR_NONE) {
+                       LOGE("mm_display_interface_evas_set_visible failed");
+                       return;
+               }
+       }
+
+       if (mm_display_interface_evas_flush(DP_INTERFACE(pc), false) != MM_ERROR_NONE) {
+               LOGE("mm_display_interface_evas_flush failed");
+               return;
+       }
+
+RELEASE_INTERNAL_MOMORY:
+       _player_release_internal_memory(pc, false);
+       pc->cb_info->video_frame_pool_size = 0;
+       __player_remove_tsurf_list(pc);
+
+       LOGI("LEAVE");
+}
+
 static bool _user_callback_handler(callback_cb_info_s *cb_info, muse_player_event_e event, _player_recv_data *recv_data)
 {
+       if (!cb_info->user_cb[event] || !_user_callbacks[event]) {
+               LOGE("failed to get callback for event %d", event);
+               return false;
+       }
+
+       _player_cb_data *data = NULL;
+       data = g_new(_player_cb_data, 1);
+       data->int_data = (int)event;
+       data->cb_info = cb_info;
+       data->recv_data = recv_data;
+       _player_event_queue_add(&cb_info->event_queue, data);
+
+       return true;
+}
+
+static bool _event_callback_handler(callback_cb_info_s *cb_info, muse_player_event_e event, _player_recv_data *recv_data)
+{
        /* LOGD("get event %d", event); */
 
-       if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
-               if (cb_info->user_cb[event] && _user_callbacks[event]) {
-                       _player_cb_data *data = NULL;
-                       data = g_new(_player_cb_data, 1);
-                       if (!data) {
-                               LOGE("fail to alloc mem");
-                               return false;
-                       }
-                       data->int_data = (int)event;
-                       data->cb_info = cb_info;
-                       data->recv_data = recv_data;
-                       _player_event_queue_add(&cb_info->event_queue, data);
+       if (event >= MUSE_PLAYER_EVENT_TYPE_NUM) {
+               LOGE("invalid event %d", event);
+               return false;
+       }
 
+       if (event == MUSE_PLAYER_EVENT_TYPE_STATE_CHANGED ||
+               event == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) {
+               _player_internal_buffer_release((player_cli_s *)cb_info->pc);
+               if (event == MUSE_PLAYER_EVENT_TYPE_STATE_CHANGED) {
+                       g_free(recv_data->buffer);
+                       g_free(recv_data);
                        return true;
                }
        }
 
-       LOGE("failed to add event to queue %d", event);
-       return false;
+       return _user_callback_handler(cb_info, event, recv_data);
 }
 
 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s *cb_info, int offset, int parse_len)
@@ -1642,8 +1700,9 @@ static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s *cb_info, int
                                last = last->next;
                        last->next = msg;
                }
-       } else
+       } else {
                LOGE("g_new failure");
+       }
 }
 
 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s *cb_info)
@@ -1758,7 +1817,7 @@ static void *client_cb_handler(gpointer data)
                                                }
                                                g_mutex_unlock(&cb_info->player_mutex);
                                                if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
-                                                       !_user_callback_handler(cb_info, event, recv_data)) {
+                                                       !_event_callback_handler(cb_info, event, recv_data)) {
                                                        LOGE("failed to get value or add event to the queue.");
                                                        if (recv_data) {
                                                                g_free(recv_data->buffer);
@@ -1806,6 +1865,7 @@ static callback_cb_info_s *callback_new(gint sockfd)
        cb_info = g_new(callback_cb_info_s, 1);
        if (!cb_info)
                return NULL;
+
        memset(cb_info, 0, sizeof(callback_cb_info_s));
 
        g_mutex_init(&cb_info->player_mutex);
@@ -2028,6 +2088,8 @@ int player_create(player_h *player)
                        goto ERROR;
                }
 
+               pc->cb_info->pc = pc;
+
                ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
                if (ret == PLAYER_ERROR_INVALID_OPERATION)
                        goto ERROR_RETRY;
@@ -2217,12 +2279,10 @@ int player_prepare(player_h player)
 int player_unprepare(player_h player)
 {
        int ret = PLAYER_ERROR_NONE;
-       int mm_ret = MM_ERROR_NONE;
        muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
        player_cli_s *pc = (player_cli_s *)player;
        char *ret_buf = NULL;
        player_state_e state = PLAYER_STATE_NONE;
-       mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
 
        PLAYER_INSTANCE_CHECK(player);
 
@@ -2245,36 +2305,7 @@ int player_unprepare(player_h player)
        set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
        set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
 
-       if (!DP_INTERFACE(pc))
-               goto _PLAYER_UNPREPARE;
-
-
-       PLAYER_GET_DISPLAY_TYPE(pc, display_type);
-
-       if (display_type != MM_DISPLAY_TYPE_EVAS)
-               goto _PLAYER_UNPREPARE;
-
-       if (CALLBACK_INFO(pc)->dp_info.visible != PLAYER_VISIBLE_INFO_FALSE) {
-               mm_ret = mm_display_interface_evas_set_visible(DP_INTERFACE(pc), false);
-               if (mm_ret != MM_ERROR_NONE) {
-                       LOGE("mm_display_interface_evas_set_visible failed 0x%x", mm_ret);
-                       return PLAYER_ERROR_INVALID_OPERATION;
-               }
-       }
-
-       mm_ret = mm_display_interface_evas_flush(DP_INTERFACE(pc), false);
-       if (mm_ret != MM_ERROR_NONE) {
-               LOGE("mm_display_interface_evas_flush failed 0x%x", mm_ret);
-               return PLAYER_ERROR_INVALID_OPERATION;
-       }
-
-_PLAYER_UNPREPARE:
        PLAYER_SEND_MSG(api, pc, ret_buf, ret);
-
-       _player_release_internal_memory(pc, false);
-       pc->cb_info->video_frame_pool_size = 0;
-       __player_remove_tsurf_list(pc);
-
        g_free(ret_buf);
 
 EXIT: