[v0.3.30] apply new muse send/recv interface for multiple fds 48/93148/3 accepted/tizen/3.0/ivi/20161028.122948 accepted/tizen/3.0/mobile/20161028.122223 accepted/tizen/3.0/tv/20161028.122524 accepted/tizen/3.0/wearable/20161028.122741 accepted/tizen/common/20161025.155118 accepted/tizen/common/20161027.073657 accepted/tizen/ivi/20161027.055027 accepted/tizen/mobile/20161027.054929 accepted/tizen/tv/20161027.055001 accepted/tizen/wearable/20161027.055017 submit/tizen/20161025.104308 submit/tizen/20161027.030209 submit/tizen_3.0/20161028.062323 submit/tizen_3.0/20161028.082323 submit/tizen_3.0_common/20161104.104000
authorEunhae Choi <eunhae1.choi@samsung.com>
Thu, 20 Oct 2016 12:14:28 +0000 (21:14 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Mon, 24 Oct 2016 09:50:13 +0000 (18:50 +0900)
Change-Id: I7eccf90d8907a97adf84e9cd80c602586fc961cf

include/player_msg.h
include/player_private.h
packaging/capi-media-player.spec
src/player.c

index d563f66..3f0df8d 100644 (file)
@@ -567,12 +567,15 @@ extern "C" {
                int __fd__; \
                int __timeout__ = client_get_api_timeout(player, api); \
                type1 __value1__ = (type1)param1; \
+               int __tfd__[MUSE_NUM_FD];\
+               memset(__tfd__, -1, sizeof(__tfd__)); \
+               __tfd__[0] = tfd; \
                if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
                else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type1, #param1, __value1__, \
                                0); \
-               __len__ = muse_core_ipc_send_fd_msg(__fd__, tfd, __sndMsg__); \
+               __len__ = muse_core_ipc_send_fd_msg(__fd__, __tfd__, __sndMsg__); \
                if (__len__ <= 0) { \
                        LOGE("sending message failed"); \
                        ret = PLAYER_ERROR_INVALID_OPERATION; \
@@ -600,6 +603,9 @@ do {        \
        int __fd__; \
        int __timeout__ = client_get_api_timeout(player, api); \
        int *__value__ = (int *)param; \
+       int __tfd__[MUSE_NUM_FD]; \
+       memset(__tfd__, -1, sizeof(__tfd__)); \
+       __tfd__[0] = tfd; \
        if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
        else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
        __sndMsg__ = muse_core_msg_json_factory_new(api, \
@@ -609,7 +615,7 @@ do {        \
                                length / sizeof(int) + (length % sizeof(int) ? 1 : 0), \
                                __value__, \
                        0); \
-       __len__ = muse_core_ipc_send_fd_msg(__fd__, tfd, __sndMsg__); \
+       __len__ = muse_core_ipc_send_fd_msg(__fd__, __tfd__, __sndMsg__); \
        if (__len__ <= 0) { \
                LOGE("sending message failed"); \
                ret = PLAYER_ERROR_INVALID_OPERATION; \
index d5978bc..b6c7211 100644 (file)
@@ -84,7 +84,7 @@ typedef struct {
 } player_event_queue;
 
 typedef struct {
-       tbm_key key;
+       int key[4];
        tbm_surface_h tsurf;
 } player_tsurf_info_t;
 
index 8095b24..7dafcd3 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-player
 Summary:    A Media Player API
-Version:    0.3.29
+Version:    0.3.30
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index b6baba6..b0e04fc 100644 (file)
@@ -48,7 +48,7 @@
 #define INVALID_DEFAULT_VALUE -1
 
 typedef struct {
-       tbm_fd tfd;
+       tbm_fd tfd[MUSE_NUM_FD];
        char* buffer;
 } _player_recv_data;
 
@@ -100,7 +100,7 @@ int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user
                        /* continue the remained job */
                }
                if (tsurf) {
-                       LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf);
+                       /* LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf); */
                        tbm_surface_destroy(tsurf);
                        tsurf = NULL;
                }
@@ -112,7 +112,7 @@ int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user
                tbm_surface_h tsurf = NULL;
 
                if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
-                       LOGD("tsurf set to null %p", tsurf);
+                       /* LOGD("tsurf set to null %p", tsurf); */
                        tsurf = NULL;
                }
        }
@@ -512,12 +512,12 @@ static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data
 
        player_msg_get4(recv_data->buffer, width, INT, height, INT, size, INT, key, INT, ret_val);
        if (ret_val) {
-               if (recv_data->tfd < 0) {
+               if (recv_data->tfd[0] < 0) {
                        LOGE("There is no valid tbm_fd");
                        goto EXIT;
                }
 
-               bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd);
+               bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
                if (bo == NULL) {
                        LOGE("TBM get error : bo is NULL");
                        goto EXIT;
@@ -539,9 +539,9 @@ static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data
        }
 
 EXIT:
-       if (recv_data->tfd > INVALID_DEFAULT_VALUE)
-               close(recv_data->tfd);
-       recv_data->tfd = INVALID_DEFAULT_VALUE;
+       if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
+               close(recv_data->tfd[0]);
+       memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
 
        if (bo)
                tbm_bo_unref(bo);
@@ -597,15 +597,15 @@ static void __player_remove_tsurf_list(player_cli_s * pc)
        return;
 }
 
-static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, tbm_key key, tbm_surface_info_s sinfo)
+static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, tbm_surface_info_s sinfo)
 {
        GList *l = NULL;
 
        g_mutex_lock(&cb_info->data_mutex);
        for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
                player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
-               if (tmp && (tmp->key == key)) { /* need to check fd, bo num, etc */
-                       LOGD("found tsurf_data of tbm_key %d", key);
+               if (tmp && key && (tmp->key[0] == key[0])) {
+                       LOGD("found tsurf_data of tbm_key %d", key[0]);
 
                        /* need to check tsuf info to support DRC */
                        if ((tbm_surface_get_height(tmp->tsurf) != sinfo.height) ||
@@ -626,14 +626,14 @@ static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb
                }
        }
        g_mutex_unlock(&cb_info->data_mutex);
-       LOGD("there is no tsurf_data for tbm_key:%d", key);
+       LOGD("there is no tsurf_data for tbm_key:%d", key[0]);
        return NULL;
 }
 
 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
 {
        tbm_bo bo[4] = { NULL, };
-       tbm_key key[4] = { 0, };
+       int key[4] = { INVALID_DEFAULT_VALUE, };
        tbm_surface_info_s sinfo;
        char *surface_info = (char *)&sinfo;
        media_packet_h pkt = NULL;
@@ -663,7 +663,7 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info,
                LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
                if (jobj)
                        muse_core_msg_json_object_free(jobj);
-               return;
+               goto ERROR;
        }
        muse_core_msg_json_object_free(jobj);
 
@@ -671,24 +671,28 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info,
 
        if (!cb_info) {
                LOGE("cb_info is null");
-               return;
+               goto ERROR;
        }
 
        if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
                /* send msg to release packet. */
                LOGE("_video_decoded_cb is not set");
-               player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
-               return;
+               goto ERROR;
        }
 
+       if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
+               LOGE("tbm fd is invalid");
+               goto ERROR;
+       }
 
-       tsurf_data = __player_get_tsurf_from_list(cb_info, key[0], sinfo);
+       tsurf_data = __player_get_tsurf_from_list(cb_info, key, sinfo);
        if (!tsurf_data) {
-               for (i = 0; i < 4; i++) {
-                       if (key[i]) {
-                               bo_num++;
-                               bo[i] = tbm_bo_import(cb_info->bufmgr, key[i]);
-                       }
+               for (i = 0; i < MUSE_NUM_FD; i++) {
+                       if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
+                               break;
+
+                       bo_num++;
+                       bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
                }
 
                tsurf_data = g_new(player_tsurf_info_t, 1);
@@ -696,6 +700,7 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info,
                        LOGE("failed to alloc tsurf info");
                        goto ERROR;
                }
+               memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
 
                tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
                if (!tsurf) {
@@ -703,7 +708,7 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info,
                        g_free(tsurf_data);
                        goto ERROR;
                }
-               tsurf_data->key = key[0];
+               memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
                tsurf_data->tsurf = tsurf;
                if (cb_info->use_tsurf_pool) {
                        g_mutex_lock(&cb_info->data_mutex);
@@ -779,10 +784,17 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info,
                media_packet_destroy(pkt);
        }
 
+       for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
+               if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
+                       close(recv_data->tfd[i]);
+       }
+
        for (i = 0; i < bo_num; i++) {
                if (bo[i])
                        tbm_bo_unref(bo[i]);
        }
+
+       memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
        return;
 
 ERROR:
@@ -792,12 +804,20 @@ ERROR:
        if (fin_data)
                g_free(fin_data);
 
+       for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
+               if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
+                       close(recv_data->tfd[i]);
+       }
+
        for (i = 0; i < bo_num; i++) {
                if (bo[i])
                        tbm_bo_unref(bo[i]);
        }
+       memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
+
+       if (cb_info && packet)
+               player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
 
-       player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
        return;
 }
 
@@ -813,14 +833,14 @@ static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_
                return;
        }
 
-       if (recv_data->tfd < 0) {
+       if (recv_data->tfd[0] < 0) {
                LOGE("failed to get tbm_fd(key:%d)", key);
                goto EXIT;
        }
 
-       bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd);
+       bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
        if (bo == NULL) {
-               LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd, key);
+               LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
                goto EXIT;
        }
 
@@ -838,9 +858,9 @@ static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_
        tbm_bo_unmap(bo);
 
 EXIT:
-       if (recv_data->tfd > INVALID_DEFAULT_VALUE)
-               close(recv_data->tfd);
-       recv_data->tfd = INVALID_DEFAULT_VALUE;
+       if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
+               close(recv_data->tfd[0]);
+       memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
 
        if (bo)
                tbm_bo_unref(bo);
@@ -1328,13 +1348,14 @@ static void *client_cb_handler(gpointer data)
        callback_cb_info_s *cb_info = data;
        char *recvMsg = NULL;
        muse_core_msg_parse_err_e err;
-       tbm_fd tfd = INVALID_DEFAULT_VALUE;
+       tbm_fd tfd[MUSE_NUM_FD];
 
+       memset(tfd, INVALID_DEFAULT_VALUE, sizeof(tfd));
        while (g_atomic_int_get(&cb_info->running)) {
                len = 0;
                err = MUSE_MSG_PARSE_ERROR_NONE;
 
-               len = player_recv_msg(cb_info, &tfd);
+               len = player_recv_msg(cb_info, tfd);
                if (len <= 0)
                        break;
 
@@ -1355,9 +1376,9 @@ static void *client_cb_handler(gpointer data)
                                                g_mutex_lock(&cb_info->player_mutex);
                                                cb_info->buff.recved++;
                                                _add_ret_msg(api, cb_info, offset, parse_len);
-                                               if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd != INVALID_DEFAULT_VALUE) {
+                                               if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
                                                        LOGD("get tbm fd for album art.");
-                                                       cb_info->tfd = tfd;
+                                                       cb_info->tfd = tfd[0];
                                                }
                                                g_cond_signal(&cb_info->player_cond[api]);
                                                g_mutex_unlock(&cb_info->player_mutex);
@@ -1369,7 +1390,7 @@ static void *client_cb_handler(gpointer data)
                                                g_mutex_lock(&cb_info->player_mutex);
                                                recv_data = g_new0(_player_recv_data, 1);
                                                if (recv_data != NULL) {
-                                                       recv_data->tfd = tfd;
+                                                       memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
                                                        recv_data->buffer = strndup(recvMsg+offset, parse_len);
                                                } else {
                                                        LOGE("failed to alloc recv_data.");