461f6bb360eb7d548b2f7649df8c7cbad1935669
[platform/core/api/player.git] / src / player.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sched.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <syscall.h>
24 #include <inttypes.h>
25 #include <unistd.h>
26 #include <tbm_bufmgr.h>
27 #include <tbm_surface.h>
28 #include <tbm_surface_internal.h>
29 #include <dlog.h>
30 #include <mm_error.h>
31 #include <muse_core.h>
32 #include <muse_client.h>
33 #include <muse_player.h>
34 #include <muse_player_msg.h>
35 #include <sound_manager.h>
36 #include <sound_manager_internal.h>
37 #include <storage-internal.h>
38 #include <system_info.h>
39 #include "player_internal.h"
40 #include "player_private.h"
41 #include "player_msg.h"
42
43 #define INVALID_MUSE_TYPE_VALUE 0
44 #define MAX_S_PATH_LEN 32
45 #define MODULE_NAME                      "player"
46 #define PLAYER_FEATURE_SOUND_STREAM      "http://tizen.org/feature/multimedia.player.stream_info"
47 #define PLAYER_FEATURE_OPENGL            "http://tizen.org/feature/opengles.version.2_0"
48 #define PLAYER_FEATURE_SPHERICAL_VIDEO   "http://tizen.org/feature/multimedia.player.spherical_video"
49 #define PLAYER_FEATURE_AUDIO_OFFLOAD     "http://tizen.org/feature/multimedia.player.audio_offload"
50 #ifndef M_PI
51 #define M_PI  3.14159265358979323846
52 #endif
53
54 typedef struct {
55         tbm_fd tfd[MUSE_NUM_FD];
56         char *buffer;
57 } _player_recv_data;
58
59 typedef struct {
60         int int_data;
61         callback_cb_info_s *cb_info;
62         _player_recv_data *recv_data;
63 } _player_cb_data;
64
65 typedef struct {
66         intptr_t remote_v_data;
67         gint fd;
68         gint fd_id;
69         bool use_tsurf_pool;
70 } _media_pkt_video_fin_data;
71
72 typedef struct {
73         gint key;
74         gint fd;
75         gint fd_id;
76         tbm_bo bo;
77 } _media_pkt_audio_fin_data;
78
79 static int _player_deinit_memory_buffer(player_cli_s *pc);
80 static void _player_event_queue_add(player_event_queue *ev, _player_cb_data *data);
81 static bool _player_need_sync_context(int event_id);
82 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all);
83 typedef void (*player_retrieve_buffer_cb)(void *user_data);
84 static void __retrieve_buffer_cb(void *user_data);
85 static void __player_media_packet_video_decoded_cb(media_packet_h packet, void *user_data);
86 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data);
87 static int __player_unset_retrieve_buffer_cb(player_h player);
88 static void _player_release_internal_memory(player_cli_s *pc, bool deinit_server_mem);
89
90 /*
91 * Internal Implementation
92 */
93 int _player_send_msg(muse_player_api_e api, player_cli_s *player, char *msg, tbm_fd tfd, char **retbuf)
94 {
95         int ret = PLAYER_ERROR_NONE;
96         int send_len = 0;
97         int send_fd = INVALID_DEFAULT_VALUE;
98         int send_tfd[MUSE_NUM_FD];
99         int timeout = client_get_api_timeout(player, api);
100
101         memset(send_tfd, INVALID_DEFAULT_VALUE, sizeof(send_tfd));
102
103         if (player && CALLBACK_INFO(player)) {
104                 send_fd = MSG_FD(player);
105         } else {
106                 LOGE("can not access to cb_info");
107                 return PLAYER_ERROR_INVALID_STATE;
108         }
109
110         if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
111                 LOGE("invalid socket fd %d", send_fd);
112                 return PLAYER_ERROR_INVALID_OPERATION;
113         }
114
115         if (tfd != INVALID_DEFAULT_VALUE) {
116                 send_tfd[0] = tfd;
117                 send_len = muse_core_msg_send_fd(send_fd, send_tfd, msg);
118         } else {
119                 send_len = muse_core_msg_send(send_fd, msg);
120         }
121         if (send_len <= 0) {
122                 LOGE("sending message failed");
123                 return PLAYER_ERROR_INVALID_OPERATION;
124         } else {
125                 ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), retbuf, timeout);
126         }
127
128         return ret;
129 }
130
131 int _player_send_msg_async(int send_fd, char *msg)
132 {
133         int send_len = 0;
134
135         if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
136                 LOGE("invalid socket fd %d", send_fd);
137                 return PLAYER_ERROR_INVALID_OPERATION;
138         }
139
140         send_len = muse_core_msg_send(send_fd, msg);
141         if (send_len <= 0) {
142                 LOGE("sending message failed");
143                 return PLAYER_ERROR_INVALID_OPERATION;
144         }
145
146         return PLAYER_ERROR_NONE;
147 }
148
149 static int _get_current_state(player_cli_s *pc, player_state_e *pstate)
150 {
151         PLAYER_INSTANCE_CHECK(pc);
152         PLAYER_NULL_ARG_CHECK(pstate);
153         muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
154         int ret = PLAYER_ERROR_NONE;
155         int state = PLAYER_STATE_NONE;
156         char *ret_buf = NULL;
157
158         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
159
160         if (ret == PLAYER_ERROR_NONE) {
161                 player_msg_get(state, ret_buf);
162                 *pstate = state;
163                 LOGD("current state %d", *pstate);
164         }
165
166         g_free(ret_buf);
167         return ret;
168 }
169
170 static bool _player_get_param_value(char *buf, ...)
171 {
172         muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
173         bool ret = true;
174         va_list var_args;
175         int type = MUSE_TYPE_ANY;
176         char *param_name = NULL;
177         void *value = NULL;
178
179         void *jobj = muse_core_msg_object_new(buf, NULL, &err);
180
181         if (!jobj) {
182                 LOGE("failed to get msg object. err:%d", err);
183                 return false;
184         }
185
186         va_start(var_args, buf);
187
188         while ((type = va_arg(var_args, int)) != INVALID_MUSE_TYPE_VALUE) {
189                 param_name = va_arg(var_args, char *);
190                 switch (type) {
191                 case MUSE_TYPE_INT:
192                 case MUSE_TYPE_INT64:
193                 case MUSE_TYPE_DOUBLE:
194                 case MUSE_TYPE_STRING:
195                 case MUSE_TYPE_POINTER:
196                         value = va_arg(var_args, void *);
197
198                         if (!muse_core_msg_object_get_value(param_name, jobj, type, value)) {
199                                 ret = false;
200                                 LOGE("failed to get %s value", param_name);
201                         }
202                         break;
203                 default:
204                         LOGE("Unexpected type");
205                         ret = false;
206                         break;
207                 }
208         }
209
210         muse_core_msg_object_free(jobj);
211
212         va_end(var_args);
213         return ret;
214 }
215
216 int _player_video_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
217 {
218         int ret = MEDIA_PACKET_FINALIZE;
219         muse_player_api_e api = MUSE_PLAYER_API_RETURN_VIDEO_DATA;
220         _media_pkt_video_fin_data *fin_data = (_media_pkt_video_fin_data *)user_data;
221         intptr_t v_data = 0;
222         char *snd_msg = NULL;
223         int snd_len = 0;
224
225         if (!pkt) {
226                 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
227                 return ret;
228         }
229
230         if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
231                 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
232                 goto EXIT;
233         }
234
235         if (!fin_data->use_tsurf_pool) {
236                 tbm_surface_h tsurf = NULL;
237                 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
238                         LOGE("media_packet_get_tbm_surface failed");
239                         /* continue the remained job */
240                 }
241                 if (tsurf) {
242                         /* LOGD("tsurf destroy %p", tsurf); */
243                         tbm_surface_destroy(tsurf);
244                         tsurf = NULL;
245                 }
246         } else {
247                 /* Do not destroy tbm surface here to reuse during playback          *
248                  * they will be destroyed at player_unprepare() or player_destroy(). *
249                  * ref: __player_remove_tsurf_list()                                 */
250
251                 tbm_surface_h tsurf = NULL;
252
253                 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
254                         /* LOGD("tsurf set to null %p", tsurf); */
255                         tsurf = NULL;
256                 }
257         }
258
259         if (muse_core_fd_is_valid(fin_data->fd)) {
260                 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
261                         LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
262                         goto EXIT;
263                 }
264
265                 v_data = fin_data->remote_v_data;
266                 snd_msg = muse_core_msg_new(api, MUSE_TYPE_POINTER, "v_data", v_data, 0);
267                 snd_len = muse_core_msg_send(fin_data->fd, snd_msg);
268                 muse_core_msg_free(snd_msg);
269
270                 if (snd_len <= 0)
271                         LOGE("[fd:%d] fail to send msg.", fin_data->fd);
272         } else {
273                 LOGE("[fd:%d] is invalid.", fin_data->fd);
274         }
275
276 EXIT:
277         if (fin_data) {
278                 g_free(fin_data);
279                 fin_data = NULL;
280         }
281
282         return ret;
283 }
284
285 int _player_audio_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
286 {
287         int ret = MEDIA_PACKET_FINALIZE;
288         muse_player_api_e api = MUSE_PLAYER_API_RETURN_BUFFER;
289         _media_pkt_audio_fin_data *fin_data = (_media_pkt_audio_fin_data *)user_data;
290
291         if (!pkt) {
292                 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
293                 return ret;
294         }
295
296         if (!fin_data) {
297                 LOGE("invalid fin_data");
298                 goto EXIT;
299         }
300
301         if (fin_data->bo) {
302                 /* LOGD("release memory - %p", fin_data->bo); */
303                 tbm_bo_unref(fin_data->bo);
304         }
305
306         if (fin_data->fd > INVALID_DEFAULT_VALUE && muse_core_fd_is_valid(fin_data->fd)) {
307                 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
308                         LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
309                         goto EXIT;
310                 }
311
312                 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(api, fin_data->fd, MUSE_TYPE_INT, "key", fin_data->key);
313         } else {
314                 LOGE("[fd:%d] is invalid.", fin_data->fd);
315         }
316
317 EXIT:
318         if (fin_data) {
319                 g_free(fin_data);
320                 fin_data = NULL;
321         }
322
323         return ret;
324 }
325
326 static bool _player_video_roi_area_is_valid(double x_scale, double y_scale,
327         double w_scale, double h_scale)
328 {
329         if (x_scale >= 0.0 && x_scale <= 1.0 && y_scale >= 0.0 && y_scale <= 1.0
330                         && w_scale > 0.0 && w_scale <= 1.0 && h_scale > 0.0 && h_scale <= 1.0)
331                 return true;
332
333         LOGE("Video roi area is not valid");
334         return false;
335 }
336
337 static bool _player_check_network_availability(void)
338 {
339 #define _FEATURE_NAME_WIFI              "http://tizen.org/feature/network.wifi"
340 #define _FEATURE_NAME_TELEPHONY "http://tizen.org/feature/network.telephony"
341 #define _FEATURE_NAME_ETHERNET  "http://tizen.org/feature/network.ethernet"
342         bool enabled = FALSE;
343         bool supported = FALSE;
344
345         if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
346                 LOGI("wifi status = %d", enabled);
347                 if (enabled)
348                         supported = TRUE;
349         } else {
350                 LOGE("SYSTEM_INFO_ERROR");
351         }
352
353         if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
354                 LOGI("telephony status = %d", enabled);
355                 if (enabled)
356                         supported = TRUE;
357         } else {
358                 LOGE("SYSTEM_INFO_ERROR");
359         }
360
361         if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
362                 LOGI("ethernet status = %d", enabled);
363                 if (enabled)
364                         supported = TRUE;
365         } else {
366                 LOGE("SYSTEM_INFO_ERROR");
367         }
368
369         if (!supported)
370                 return FALSE;
371
372         return TRUE;
373 }
374
375 static void *_get_mem(player_cli_s *player, int size)
376 {
377         player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
378         if (mem) {
379                 mem->data = g_new(void, size);
380                 mem->next = player->head;
381                 player->head = mem;
382                 return mem->data;
383         }
384         return NULL;
385 }
386
387 static void _del_mem(player_cli_s *player)
388 {
389         player_data_s *mem;
390         while (player->head) {
391                 mem = player->head->next;
392                 g_free(player->head->data);
393                 g_free(player->head);
394                 player->head = mem;
395         }
396 }
397
398 static int player_recv_msg(callback_cb_info_s *cb_info, tbm_fd *tfd)
399 {
400         int recvLen = 0;
401         msg_buff_s *buff = &cb_info->buff;
402
403         memset(buff->recvMsg, 0x00, sizeof(char) * buff->bufLen);
404         memset(tfd, INVALID_DEFAULT_VALUE, sizeof(*tfd) * MUSE_NUM_FD);
405         recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, MUSE_MSG_MAX_LENGTH, tfd);
406         if (recvLen <= 0) {
407                 LOGE("failed to recv msg %d", recvLen);
408                 return 0;
409         }
410
411         /* check the first msg */
412         if (buff->part_of_msg && buff->recvMsg[0] != '{')
413         {
414                 gchar *tmp = g_strndup(buff->recvMsg, recvLen);
415                 if (!tmp) {
416                         LOGE("failed to copy msg.");
417                         return 0;
418                 }
419
420                 LOGD("get remained part of msg %d + %zu, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
421
422                 /* realloc buffer */
423                 if (recvLen + strlen(buff->part_of_msg) >= buff->bufLen) {
424                         LOGD("realloc Buffer %d -> %d", buff->bufLen, (int)(recvLen + strlen(buff->part_of_msg) + 1));
425                         buff->bufLen = recvLen + strlen(buff->part_of_msg) + 1;
426                         buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
427                         if (!buff->recvMsg) {
428                                 LOGE("failed renew buffer.");
429                                 g_free(tmp);
430                                 return 0;
431                         }
432                         memset(buff->recvMsg, 0x00, sizeof(char) * buff->bufLen);
433                 }
434                 g_snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
435                 recvLen += strlen(buff->part_of_msg);
436
437                 g_free(buff->part_of_msg);
438                 buff->part_of_msg = NULL;
439                 g_free(tmp);
440                 tmp = NULL;
441         }
442
443         /* check the last msg */
444         if (buff->recvMsg[recvLen - 1] != '}') {
445                 char *part_pos = strrchr(buff->recvMsg, '}');
446                 int part_len = ((part_pos) ? (strlen(part_pos + 1)) : (0));
447
448                 if (part_len > 0) {
449                         buff->part_of_msg = g_strndup(part_pos + 1, part_len);
450                         if (!buff->part_of_msg) {
451                                 LOGE("failed to alloc buffer for part of msg.");
452                                 return 0;
453                         }
454                         LOGD("get part of msg: %zu, %s", strlen(buff->part_of_msg), buff->part_of_msg);
455                         recvLen -= part_len;
456                 }
457         }
458
459         return recvLen;
460 }
461
462 static void set_null_user_cb(callback_cb_info_s *cb_info, muse_player_event_e event)
463 {
464         if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
465                 cb_info->user_cb[event] = NULL;
466                 cb_info->user_data[event] = NULL;
467         }
468 }
469
470 /* Notice : have to be called via API to avoid deadlock
471  * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
472  */
473 static void set_null_user_cb_lock(callback_cb_info_s *cb_info, muse_player_event_e event)
474 {
475         bool lock = false;
476
477         LOGD("event %d cb will be cleared", event);
478
479         if (!cb_info) {
480                 LOGE("cb_info is NULL, event: %d", event);
481                 return;
482         }
483
484         lock = (g_thread_self() != cb_info->event_queue.thread);
485
486         if (lock)
487                 g_mutex_lock(&cb_info->event_queue.mutex);
488
489         if (_player_need_sync_context(event))
490                 _player_remove_idle_event(cb_info, event, false);
491
492         set_null_user_cb(cb_info, event);
493
494         if (lock)
495                 g_mutex_unlock(&cb_info->event_queue.mutex);
496 }
497
498 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
499 {
500         int ret = PLAYER_ERROR_NONE;
501         player_cli_s *pc = (player_cli_s *)player;
502         muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
503         char *ret_buf = NULL;
504         int set = 1;
505
506         PLAYER_INSTANCE_CHECK(player);
507         PLAYER_NULL_ARG_CHECK(callback);
508
509         if (type == MUSE_PLAYER_EVENT_TYPE_BUFFERING) {
510                 if (!_player_check_network_availability())
511                         return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
512                 pc->cb_info->drop_buffering_message = FALSE;
513         }
514
515         if (!CALLBACK_INFO(pc))
516                 return PLAYER_ERROR_INVALID_OPERATION;
517
518         LOGI("Event type : %d ", type);
519         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
520                                         MUSE_TYPE_INT, "type", type,
521                                         MUSE_TYPE_INT, "set", set);
522
523         if (ret == PLAYER_ERROR_NONE) {
524                 pc->cb_info->user_cb[type] = callback;
525                 pc->cb_info->user_data[type] = user_data;
526         }
527
528         g_free(ret_buf);
529         return ret;
530 }
531
532 static int __unset_callback(muse_player_event_e type, player_h player)
533 {
534         int ret = PLAYER_ERROR_NONE;
535         player_cli_s *pc = (player_cli_s *)player;
536         muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
537         char *ret_buf = NULL;
538         int set = 0;
539
540         PLAYER_INSTANCE_CHECK(player);
541
542         LOGI("Event type : %d ", type);
543
544         PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
545
546         if ((type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) ||
547                 (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME)) {
548                 /* check state condition */
549                 player_state_e state = PLAYER_STATE_NONE;
550
551                 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
552                         LOGE("Failed to get current state");
553                         return PLAYER_ERROR_INVALID_OPERATION;
554                 }
555
556                 if (state > PLAYER_STATE_READY) {
557                         LOGE("Invalid state %d", state);
558                         return PLAYER_ERROR_INVALID_STATE;
559                 }
560         }
561
562         set_null_user_cb_lock(CALLBACK_INFO(pc), type);
563
564         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
565                                         MUSE_TYPE_INT, "type", type,
566                                         MUSE_TYPE_INT, "set", set);
567
568         g_free(ret_buf);
569         return ret;
570 }
571
572 static void __prepare_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
573 {
574         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
575
576         ((player_prepared_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
577
578         set_null_user_cb(cb_info, ev);
579 }
580
581 static void __complete_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
582 {
583         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
584         ((player_completed_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
585 }
586
587 static void __player_media_packet_video_decoded_cb(media_packet_h packet, void *user_data)
588 {
589         if (!packet || !user_data) {
590                 LOGE("invalid param [packet:%p, user_data:%p]", packet, user_data);
591                 return;
592         }
593
594         LOGD("render packet %p", packet);
595
596         mm_display_interface_evas_render(DP_INTERFACE((player_cli_s *)user_data), packet);
597 }
598
599 static void __retrieve_buffer_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
600
601 {
602         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
603         ((player_retrieve_buffer_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
604 }
605
606 static void __interrupt_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
607 {
608         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
609         ((player_interrupted_cb)cb_info->user_cb[ev])(PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT, cb_info->user_data[ev]);
610 }
611
612 static void __error_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
613 {
614         int code;
615         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
616
617         if (player_msg_get(code, recv_data->buffer)) {
618                 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
619                         if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
620                                 LOGW("failed to pause, so prepare cb will be released soon");
621                                 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
622                         }
623                 }
624                 ((player_error_cb)cb_info->user_cb[ev])(code, cb_info->user_data[ev]);
625         }
626 }
627
628 static void __disconnected_error_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
629 {
630         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
631
632         ((player_error_cb)cb_info->user_cb[ev])(PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
633 }
634
635 static void __buffering_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
636 {
637         int percent;
638         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
639
640         if (player_msg_get(percent, recv_data->buffer)) {
641                 g_mutex_lock(&cb_info->buffering_cb_mutex);
642                 if (cb_info->drop_buffering_message) {
643                         LOGD("Drop buffering callback");
644                         g_mutex_unlock(&cb_info->buffering_cb_mutex);
645                         return;
646                 }
647                 g_mutex_unlock(&cb_info->buffering_cb_mutex);
648                 ((player_buffering_cb)cb_info->user_cb[ev])(percent, cb_info->user_data[ev]);
649         }
650
651 }
652
653 static void __subtitle_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
654 {
655         int duration = 0;
656         char text[MUSE_URI_MAX_LENGTH] = { 0, };
657         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
658         bool ret = true;
659
660         ret = _player_get_param_value(recv_data->buffer,
661                                                                 MUSE_TYPE_INT, "duration", (void *)&duration,
662                                                                 MUSE_TYPE_STRING, "text", (void *)text,
663                                                                 INVALID_MUSE_TYPE_VALUE);
664         if (ret)
665                 ((player_subtitle_updated_cb)cb_info->user_cb[ev])(duration, text, cb_info->user_data[ev]);
666 }
667
668 static void __capture_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
669 {
670         unsigned char *data = NULL;
671         int width = 0;
672         int height = 0;
673         unsigned int size = 0;
674         tbm_bo bo = NULL;
675         tbm_bo_handle thandle;
676         int key = INVALID_DEFAULT_VALUE;
677         bool get_ret = true;
678         get_ret = _player_get_param_value(recv_data->buffer,
679                                                                         MUSE_TYPE_INT, "width", (void *)&width,
680                                                                         MUSE_TYPE_INT, "height", (void *)&height,
681                                                                         MUSE_TYPE_INT, "size", (void *)&size,
682                                                                         MUSE_TYPE_INT, "key", (void *)&key,
683                                                                         INVALID_MUSE_TYPE_VALUE);
684         if (get_ret) {
685                 if (recv_data->tfd[0] < 0) {
686                         LOGE("There is no valid tbm_fd");
687                         goto EXIT;
688                 }
689
690                 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
691                 if (bo == NULL) {
692                         LOGE("TBM get error : bo is NULL");
693                         goto EXIT;
694                 }
695                 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
696                 if (thandle.ptr == NULL) {
697                         LOGE("TBM get error : handle pointer is NULL");
698                         goto EXIT;
699                 }
700                 data = g_new(unsigned char, size);
701                 if (data) {
702                         memcpy(data, thandle.ptr, size);
703                         ((player_video_captured_cb)cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE])(data, width, height, size, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE]);
704                         g_free(data);
705                 } else {
706                         LOGE("g_new failure");
707                 }
708
709                 tbm_bo_unmap(bo);
710         }
711
712 EXIT:
713         PLAYER_CLOSE_FD(recv_data->tfd[0]);
714
715         memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
716
717         if (bo)
718                 tbm_bo_unref(bo);
719
720         /* return buffer */
721         if (key > INVALID_DEFAULT_VALUE) {
722                 LOGD("send msg to release buffer. key:%d", key);
723                 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
724         }
725
726         set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
727 }
728
729 static void __seek_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
730 {
731         int ret = MM_ERROR_NONE;
732         muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
733         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
734
735         g_mutex_lock(&cb_info->seek_cb_mutex);
736
737         switch (cb_info->seek_cb_state) {
738         case PLAYER_SEEK_CB_STATE_NONE:
739         {
740                 if (!cb_info->user_cb[ev]) {
741                         LOGW("invalid seek callback info, skip");
742                         break;
743                 }
744
745                 ret = mm_display_interface_get_type(cb_info->dp_info.interface, &display_type);
746                 if (ret == MM_ERROR_NONE && display_type == MM_DISPLAY_TYPE_EVAS &&
747                         cb_info->dp_info.visible != PLAYER_VISIBLE_INFO_FALSE) {
748                         LOGW("set display visible true for EVAS");
749                         if (mm_display_interface_evas_set_visible(cb_info->dp_info.interface, true) != MM_ERROR_NONE)
750                                 LOGE("mm_display_interface_evas_set_visible failed");
751                 } else {
752                         LOGW("get display type ret 0x%x, type %d", ret, display_type);
753                 }
754
755                 LOGD("call seek cb");
756                 ((player_seek_completed_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
757                 set_null_user_cb(cb_info, ev);
758
759                 break;
760         }
761         case PLAYER_SEEK_CB_STATE_DROP:
762         case PLAYER_SEEK_CB_STATE_WAIT: /* not expected */
763                 LOGW("ignored. seek cb %p, state %d", cb_info->user_cb[ev], cb_info->seek_cb_state);
764                 break;
765         default:
766                 LOGE("invalid state value");
767                 break;
768         }
769
770         g_mutex_unlock(&cb_info->seek_cb_mutex);
771 }
772
773 static void __player_remove_tsurf_list(player_cli_s *pc)
774 {
775         GList *l = NULL;
776
777         g_mutex_lock(&pc->cb_info->data_mutex);
778         if (pc->cb_info->tsurf_list) {
779                 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
780
781                 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
782                         player_tsurf_info_s *tmp = (player_tsurf_info_s *)l->data;
783
784                         LOGD("%p will be removed", tmp);
785                         if (tmp) {
786                                 if (tmp->tsurf) {
787                                         tbm_surface_destroy(tmp->tsurf);
788                                         tmp->tsurf = NULL;
789                                 }
790                                 g_free(tmp);
791                         }
792                 }
793                 g_list_free(pc->cb_info->tsurf_list);
794                 pc->cb_info->tsurf_list = NULL;
795         }
796         g_mutex_unlock(&pc->cb_info->data_mutex);
797         return;
798 }
799
800 static player_tsurf_info_s *__player_get_tsurf_from_list(callback_cb_info_s *cb_info, intptr_t key, int height, int width)
801 {
802         GList *l = NULL;
803
804         g_mutex_lock(&cb_info->data_mutex);
805         for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
806                 player_tsurf_info_s *tmp = (player_tsurf_info_s *)l->data;
807                 if (tmp && key && (tmp->key == key)) {
808                         LOGD("found tsurf_data of tbm_key %" PRIdPTR, key);
809
810                         /* need to check tsuf info to support DRC */
811                         if ((tbm_surface_get_height(tmp->tsurf) != height) ||
812                                 (tbm_surface_get_width(tmp->tsurf) != width)) {
813
814                                 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
815                                 LOGW("tsurf info is changed. need to create new tsurf.");
816                                 tbm_surface_destroy(tmp->tsurf);
817                                 g_free(tmp);
818
819                                 g_mutex_unlock(&cb_info->data_mutex);
820                                 return NULL;
821
822                         } else {
823                                 g_mutex_unlock(&cb_info->data_mutex);
824                                 return tmp;
825                         }
826                 }
827         }
828         g_mutex_unlock(&cb_info->data_mutex);
829         return NULL;
830 }
831
832 static media_packet_rotate_method_e __convert_packet_orient_info(int orientation)
833 {
834         media_packet_rotate_method_e rotate = MEDIA_PACKET_ROTATE_IDENTITY;
835
836         switch (orientation) {
837         case 90:
838                 rotate = MEDIA_PACKET_ROTATE_90;
839         break;
840         case 180:
841                 rotate = MEDIA_PACKET_ROTATE_180;
842         break;
843         case 270:
844                 rotate = MEDIA_PACKET_ROTATE_270;
845         break;
846         default:
847                 rotate = MEDIA_PACKET_ROTATE_IDENTITY;
848         break;
849         }
850
851         return rotate;
852 }
853
854 static void __media_packet_video_frame_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
855 {
856         tbm_bo bo[4] = { NULL, };
857         tbm_surface_info_s sinfo;
858         char *surface_info = (char *)&sinfo;
859         media_packet_h pkt = NULL;
860         tbm_surface_h tsurf = NULL;
861         player_tsurf_info_s *tsurf_data = NULL;
862         int bo_num = 0;
863         media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
864         bool make_pkt_fmt = false;
865         int ret = MEDIA_FORMAT_ERROR_NONE;
866         _media_pkt_video_fin_data *fin_data = NULL;
867         intptr_t key = 0;
868         intptr_t v_data = 0;
869         uint64_t pts = 0;
870         int i = 0, orientation = 0;
871         muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
872
873         void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
874         if (!jobj ||
875                 !muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_POINTER, &key) ||
876                 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
877                 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
878                 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
879                 !muse_core_msg_object_get_value("orientation", jobj, MUSE_TYPE_INT, &orientation) ||
880                 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
881
882                 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
883                 if (jobj)
884                         muse_core_msg_object_free(jobj);
885                 goto ERROR;
886         }
887         muse_core_msg_object_free(jobj);
888
889         LOGD("width %d, height %d", sinfo.width, sinfo.height);
890
891         if (!cb_info) {
892                 LOGE("cb_info is null");
893                 goto ERROR;
894         }
895
896         if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
897                 /* send msg to release v_data. */
898                 LOGE("_video_decoded_cb is not set");
899                 goto ERROR;
900         }
901
902         if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
903                 LOGE("tbm fd is invalid");
904                 goto ERROR;
905         }
906
907         tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
908         if (!tsurf_data) {
909                 for (i = 0; i < MUSE_NUM_FD; i++) {
910                         if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
911                                 break;
912
913                         bo_num++;
914                         bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
915                 }
916
917                 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
918                 if (!tsurf) {
919                         LOGE("failed to create tbm surface");
920                         goto ERROR;
921                 }
922
923                 if (cb_info->use_tsurf_pool) {
924                         tsurf_data = g_try_new(player_tsurf_info_s, 1);
925                         if (!tsurf_data) {
926                                 LOGE("failed to alloc tsurf info");
927                                 goto ERROR;
928                         }
929                         tsurf_data->key = key;
930                         tsurf_data->tsurf = tsurf;
931
932                         g_mutex_lock(&cb_info->data_mutex);
933                         cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
934                         LOGD("key %" PRIdPTR " is added to the pool", key);
935                         if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
936                                 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
937                         g_mutex_unlock(&cb_info->data_mutex);
938                 }
939         } else {
940                 if (tsurf_data->tsurf) {
941                         tsurf = tsurf_data->tsurf;
942                 } else {
943                         LOGE("tsurf_data->tsurf is null (never enter here)");
944                         goto ERROR;
945                 }
946         }
947
948         /* check media packet format */
949         if (cb_info->pkt_fmt) {
950                 int pkt_fmt_width = 0;
951                 int pkt_fmt_height = 0;
952                 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
953
954                 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
955                 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
956                         LOGW("different format. current 0x%x, %dx%d, new 0x%x, %dx%d", pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height, mimetype, sinfo.width, sinfo.height);
957                         media_format_unref(cb_info->pkt_fmt);
958                         cb_info->pkt_fmt = NULL;
959                         make_pkt_fmt = true;
960                 }
961         } else {
962                 make_pkt_fmt = true;
963         }
964         /* create packet format */
965         if (make_pkt_fmt) {
966                 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
967                 ret = media_format_create(&cb_info->pkt_fmt);
968                 if (ret == MEDIA_FORMAT_ERROR_NONE) {
969                         ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
970                         ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
971                         ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
972                         LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
973                 } else {
974                         LOGE("media_format_create failed");
975                 }
976         }
977
978         fin_data = g_try_new0(_media_pkt_video_fin_data, 1);
979         if (!fin_data) {
980                 LOGE("failed to alloc fin_data");
981                 goto ERROR;
982         }
983         fin_data->remote_v_data = v_data;
984         fin_data->fd = cb_info->fd;
985         fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
986
987         /* Keep the fd id to check validation when the pkt is destroyed. */
988         fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
989
990         ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb)_player_video_media_packet_finalize, (void *)fin_data, &pkt);
991         if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
992                 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
993                 goto ERROR;
994         }
995
996         if (pts != 0) {
997                 ret = media_packet_set_pts(pkt, (uint64_t)pts);
998                 if (ret != MEDIA_PACKET_ERROR_NONE)
999                         LOGE("media_packet_set_pts failed");
1000         }
1001
1002         ret = media_packet_set_rotate_method(pkt, __convert_packet_orient_info(orientation));
1003         if (ret != MEDIA_PACKET_ERROR_NONE)
1004                 LOGE("media_packet_set_rotate_method failed");
1005
1006         if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
1007                 /* call media packet callback */
1008                 ((player_media_packet_video_decoded_cb)cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME])(pkt, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]);
1009         } else {
1010                 LOGE("_video_decoded_cb is not set");
1011                 media_packet_destroy(pkt);
1012         }
1013
1014         /* if tsruf pool is enabled, bo_num can be zero. */
1015         for (i = 0; i < MUSE_NUM_FD; i++)
1016                 PLAYER_CLOSE_FD(recv_data->tfd[i]);
1017
1018         for (i = 0; i < bo_num; i++) {
1019                 if (bo[i])
1020                         tbm_bo_unref(bo[i]);
1021         }
1022
1023         memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1024         return;
1025
1026 ERROR:
1027         if (pkt)
1028                 media_packet_destroy(pkt);
1029         else if (!tsurf_data && tsurf)
1030                 tbm_surface_destroy(tsurf);
1031
1032         if (fin_data)
1033                 g_free(fin_data);
1034
1035         /* if tsruf pool is enabled, bo_num can be zero. */
1036         for (i = 0; i < MUSE_NUM_FD; i++)
1037                 PLAYER_CLOSE_FD(recv_data->tfd[i]);
1038
1039         for (i = 0; i < bo_num; i++) {
1040                 if (bo[i])
1041                         tbm_bo_unref(bo[i]);
1042         }
1043         memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1044
1045         if (cb_info && v_data)
1046                 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, MUSE_TYPE_POINTER, "v_data", v_data);
1047
1048         return;
1049 }
1050
1051 static void __media_packet_audio_frame_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1052 {
1053         int ret = MEDIA_FORMAT_ERROR_NONE;
1054         tbm_bo bo = NULL;
1055         tbm_bo_handle thandle;
1056         int key = INVALID_DEFAULT_VALUE;
1057         player_audio_decoded_data_info_t audio;
1058         media_packet_h pkt = NULL;
1059         media_format_h fmt = NULL;
1060         _media_pkt_audio_fin_data *fin_data = NULL;
1061
1062         if (!player_msg_get(key, recv_data->buffer)) {
1063                 LOGE("failed to get key value from msg.");
1064                 return;
1065         }
1066
1067         if (recv_data->tfd[0] < 0) {
1068                 LOGE("failed to get tbm_fd(key:%d)", key);
1069                 goto EXIT;
1070         }
1071
1072         bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
1073         if (bo == NULL) {
1074                 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
1075                 goto EXIT;
1076         }
1077
1078         thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
1079         if (thandle.ptr == NULL) {
1080                 LOGE("TBM get error : handle pointer is NULL");
1081                 goto EXIT;
1082         }
1083
1084         memcpy(&audio, thandle.ptr, sizeof(player_audio_decoded_data_info_t));
1085         audio.data = thandle.ptr + sizeof(player_audio_decoded_data_info_t);
1086         tbm_bo_unmap(bo);
1087
1088         /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
1089         if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME]) {
1090                 ret = media_format_create(&fmt);
1091                 if (ret != MEDIA_FORMAT_ERROR_NONE || !fmt) {
1092                         LOGE("failed to create media format 0x%X %p", ret, fmt);
1093                         goto EXIT;
1094                 }
1095
1096                 ret = media_format_set_audio_mime(fmt, audio.pcm_format);
1097                 ret |= media_format_set_audio_samplerate(fmt, audio.rate);
1098                 ret |= media_format_set_audio_channel(fmt, audio.channel);
1099                 ret |= media_format_set_audio_channel_mask(fmt, audio.channel_mask);
1100                 if (ret != MEDIA_FORMAT_ERROR_NONE) {
1101                         LOGE("failed to set audio format 0x%X", ret);
1102                         goto EXIT;
1103                 }
1104
1105                 fin_data = g_new0(_media_pkt_audio_fin_data, 1);
1106                 if (!fin_data) {
1107                         LOGE("failed to alloc fin_data");
1108                         goto EXIT;
1109                 }
1110
1111                 fin_data->key = key;
1112                 fin_data->fd = cb_info->fd;
1113                 fin_data->bo = bo;
1114
1115                 /* Keep the fd id to check validation when the pkt is destroyed. */
1116                 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
1117
1118                 ret = media_packet_create_from_external_memory(fmt, audio.data, audio.size,
1119                                 (media_packet_finalize_cb)_player_audio_media_packet_finalize, (void *)fin_data, &pkt);
1120                 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
1121                         LOGE("failed to create media packet 0x%X %p", ret, pkt);
1122                         if (pkt)
1123                                 media_packet_destroy(pkt); /* fin_data will be free in finalize function. */
1124                         else
1125                                 g_free(fin_data);
1126                         goto EXIT;
1127                 }
1128
1129                 media_format_unref(fmt);
1130                 fmt = NULL;
1131
1132                 ((player_media_packet_audio_decoded_cb)cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME])
1133                                         (pkt, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME]);
1134         } else {
1135                 LOGE("there is no registered cb");
1136                 goto EXIT;
1137         }
1138
1139 EXIT:
1140         PLAYER_CLOSE_FD(recv_data->tfd[0]);
1141
1142         memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1143
1144         if (fmt)
1145                 media_format_unref(fmt);
1146
1147         /* return buffer */
1148         if ((cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] == NULL) &&
1149                 (key > INVALID_DEFAULT_VALUE)) {
1150
1151                 if (bo) tbm_bo_unref(bo);
1152
1153                 /* LOGD("send msg to release buffer. key:%d", key); */
1154                 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
1155         }
1156
1157         return;
1158 }
1159
1160 static void __video_frame_render_error_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1161 {
1162 }
1163
1164 static void __supported_audio_effect_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1165 {
1166 }
1167
1168 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1169 {
1170 }
1171
1172 static void __missed_plugin_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1173 {
1174 }
1175
1176 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1177 {
1178         /* player_media_stream_buffer_status_e status; */
1179         int status;
1180
1181         if (player_msg_get(status, recv_data->buffer)) {
1182                 ((player_media_stream_buffer_status_cb)
1183                         cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS])
1184                                 ((player_media_stream_buffer_status_e)status,
1185                                 cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]);
1186         }
1187 }
1188
1189 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1190 {
1191         /* player_media_stream_buffer_status_e status; */
1192         int status;
1193
1194         if (player_msg_get(status, recv_data->buffer)) {
1195                 ((player_media_stream_buffer_status_cb)
1196                         cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
1197                                 ((player_media_stream_buffer_status_e) status,
1198                                 cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
1199         }
1200
1201 }
1202
1203 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1204 {
1205         /* player_media_stream_buffer_status_e status; */
1206         int status;
1207         unsigned long long bytes;
1208         bool ret = true;
1209
1210         ret = _player_get_param_value(recv_data->buffer,
1211                                                                 MUSE_TYPE_INT, "status", (void *)&status,
1212                                                                 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1213                                                                 INVALID_MUSE_TYPE_VALUE);
1214         if (ret == true) {
1215                 ((player_media_stream_buffer_status_cb_ex)
1216                         cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
1217                         ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
1218         }
1219 }
1220
1221 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1222 {
1223         /* player_media_stream_buffer_status_e status; */
1224         int status;
1225         unsigned long long bytes;
1226         bool ret = true;
1227
1228         ret = _player_get_param_value(recv_data->buffer,
1229                                                                 MUSE_TYPE_INT, "status", (void *)&status,
1230                                                                 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1231                                                                 INVALID_MUSE_TYPE_VALUE);
1232         if (ret == true) {
1233                 ((player_media_stream_buffer_status_cb_ex)
1234                         cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
1235                         ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
1236         }
1237
1238 }
1239
1240 static void __media_stream_video_seek_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1241 {
1242         unsigned long long offset;
1243
1244         if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1245                 ((player_media_stream_seek_cb)
1246                         cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
1247                         (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
1248         }
1249 }
1250
1251 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1252 {
1253         unsigned long long offset;
1254
1255         if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1256                 ((player_media_stream_seek_cb)
1257                         cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
1258                         (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1259         }
1260 }
1261
1262 static void __video_stream_changed_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1263 {
1264         int width;
1265         int height;
1266         int fps;
1267         int bit_rate;
1268         bool ret_val = TRUE;
1269         ret_val = _player_get_param_value(recv_data->buffer,
1270                                                                         MUSE_TYPE_INT, "width", (void *)&width,
1271                                                                         MUSE_TYPE_INT, "height", (void *)&height,
1272                                                                         MUSE_TYPE_INT, "fps", (void *)&fps,
1273                                                                         MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
1274                                                                         INVALID_MUSE_TYPE_VALUE);
1275         if (ret_val) {
1276                 ((player_video_stream_changed_cb)cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1277                         (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1278         }
1279 }
1280
1281 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM])(callback_cb_info_s *cb_info, _player_recv_data *recv_data) = {
1282         __prepare_cb_handler,   /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1283         __complete_cb_handler,  /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1284         __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1285         __error_cb_handler,             /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1286         __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1287         __subtitle_cb_handler,  /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1288         __capture_cb_handler,   /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1289         __seek_cb_handler,              /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1290         __media_packet_video_frame_cb_handler,  /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1291         __media_packet_audio_frame_cb_handler,  /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME */
1292         __video_frame_render_error_cb_handler,  /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1293         __supported_audio_effect_cb_handler,    /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1294         __supported_audio_effect_preset_cb_handler,     /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1295         __missed_plugin_cb_handler,     /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1296 #ifdef _PLAYER_FOR_PRODUCT
1297         NULL,   /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1298         NULL,   /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1299 #endif
1300         __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1301         __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1302         __media_stream_video_buffer_cb_handler_ex,      /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1303         __media_stream_audio_buffer_cb_handler_ex,      /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1304         __media_stream_video_seek_cb_handler,   /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1305         __media_stream_audio_seek_cb_handler,   /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1306         NULL,   /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1307         __video_stream_changed_cb_handler,              /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1308         __retrieve_buffer_cb_handler,           /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1309         __disconnected_error_cb_handler,                /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1310 };
1311
1312 gboolean _player_event_job_function(void *user_data)
1313 {
1314         _player_cb_data *data = (_player_cb_data *)user_data;
1315         muse_player_event_e ev;
1316
1317         if (!data || !data->cb_info) {
1318                 LOGE("invalid user data");
1319                 return FALSE;
1320         }
1321
1322         ev = data->int_data;
1323         if ((ev != MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) &&
1324                 (ev != MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME))
1325                 LOGD("enter ev:%d(%p)", ev, data);
1326
1327         /* remove event from list */
1328         g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1329         if (data->cb_info->event_queue.idle_ev_list) {
1330                 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1331                 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1332         }
1333         g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1334
1335         if ((data->cb_info->user_cb[ev] || ev == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) &&
1336                 (_user_callbacks[ev]))
1337                 _user_callbacks[ev](data->cb_info, data->recv_data);
1338         else
1339                 LOGW("user callback is unset. type : %d", ev);
1340
1341         return FALSE; /* remove from the event list */
1342 }
1343
1344 static bool _player_need_sync_context(int event_id)
1345 {
1346         if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1347                 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1348                 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1349                 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1350                 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1351                 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1352                 LOGD("%d callback will be issued in the mainloop.", event_id);
1353                 return TRUE;
1354         } else {
1355                 return FALSE;
1356         }
1357 }
1358
1359 static void _destroy_event_data(gpointer user_data)
1360 {
1361         _player_cb_data *data = (_player_cb_data *)user_data;
1362
1363         if (data == NULL) {
1364                 LOGW("data is null");
1365                 return;
1366         }
1367
1368         LOGD("remove event data %p (%d)", data, data->int_data);
1369         if (data->recv_data) {
1370                 g_free(data->recv_data->buffer);
1371                 data->recv_data->buffer = NULL;
1372                 g_free(data->recv_data);
1373                 data->recv_data = NULL;
1374         }
1375
1376         g_free(data);
1377 }
1378
1379 static void *_player_event_queue_loop(void *param)
1380 {
1381         if (!param) {
1382                 LOGE("NULL parameter");
1383                 return NULL;
1384         }
1385         callback_cb_info_s *cb_info = param;
1386         player_event_queue *ev = &cb_info->event_queue;
1387         _player_cb_data *event_data = NULL;
1388
1389         g_mutex_lock(&ev->mutex);
1390         while (ev->running) {
1391                 g_mutex_lock(&ev->qlock);
1392                 if (g_queue_is_empty(ev->queue)) {
1393                         g_mutex_unlock(&ev->qlock);
1394                         g_cond_wait(&ev->cond, &ev->mutex);
1395                         if (!ev->running)
1396                                 break;
1397                 } else
1398                         g_mutex_unlock(&ev->qlock);
1399
1400                 while (1) {
1401                         g_mutex_lock(&ev->qlock);
1402                         event_data = (_player_cb_data *)g_queue_pop_head(ev->queue);
1403                         g_mutex_unlock(&ev->qlock);
1404
1405                         if (!event_data)
1406                                 break;
1407
1408                         muse_player_event_e event_type = event_data->int_data;
1409
1410                         if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1411                                 g_mutex_lock(&cb_info->seek_cb_mutex);
1412                                 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1413                                         /* push event into queue again. */
1414                                         _player_event_queue_add(ev, event_data);
1415                                         g_mutex_unlock(&cb_info->seek_cb_mutex);
1416                                         break;
1417                                 }
1418                                 g_mutex_unlock(&cb_info->seek_cb_mutex);
1419                         } else if (event_type == MUSE_PLAYER_EVENT_TYPE_BUFFERING) {
1420                                 g_mutex_lock(&cb_info->buffering_cb_mutex);
1421                                 if (cb_info->drop_buffering_message) {
1422                                         LOGD("Drop buffering event");
1423                                         g_mutex_unlock(&cb_info->buffering_cb_mutex);
1424
1425                                         _destroy_event_data(event_data);
1426                                         break;
1427                                 }
1428                                 g_mutex_unlock(&cb_info->buffering_cb_mutex);
1429                         }
1430
1431                         if (_player_need_sync_context(event_type)) {
1432                                 if ((cb_info->user_cb[event_type] || (event_type == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED)) &&
1433                                         _user_callbacks[event_type]) {
1434                                         g_mutex_lock(&ev->idle_ev_mutex);
1435                                         ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1436                                         g_mutex_unlock(&ev->idle_ev_mutex);
1437
1438                                         LOGD("add ev %d to main loop", event_type);
1439
1440                                         g_idle_add_full(G_PRIORITY_DEFAULT,
1441                                                                         (GSourceFunc)_player_event_job_function,
1442                                                                         (gpointer)event_data,
1443                                                                         (GDestroyNotify)_destroy_event_data);
1444                                 } else {
1445                                         LOGW("there is no registered cb for ev:%d", event_type);
1446                                         _destroy_event_data(event_data);
1447                                 }
1448                         } else {
1449                                 _player_event_job_function(event_data);
1450                                 _destroy_event_data(event_data);
1451                         }
1452                 }
1453         }
1454         g_mutex_unlock(&ev->mutex);
1455         LOGI("Exit event loop");
1456         return NULL;
1457 }
1458
1459 static gboolean _player_event_queue_new(callback_cb_info_s *cb_info)
1460 {
1461         g_return_val_if_fail(cb_info, FALSE);
1462         player_event_queue *ev = &cb_info->event_queue;
1463
1464         ev->queue = g_queue_new();
1465         g_return_val_if_fail(ev->queue, FALSE);
1466         g_mutex_init(&ev->qlock);
1467
1468         g_mutex_init(&ev->mutex);
1469         g_cond_init(&ev->cond);
1470         ev->running = TRUE;
1471
1472         g_mutex_init(&ev->idle_ev_mutex);
1473
1474         ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer)cb_info);
1475         g_return_val_if_fail(ev->thread, FALSE);
1476         LOGI("event queue thread %p", ev->thread);
1477
1478         return TRUE;
1479
1480 }
1481
1482 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1483 {
1484         g_return_if_fail(cb_info);
1485         player_event_queue *ev = &cb_info->event_queue;
1486         _player_cb_data *event_data = NULL;
1487         GList *list = NULL;
1488
1489         g_mutex_lock(&ev->idle_ev_mutex);
1490
1491         if (ev->idle_ev_list == NULL) {
1492                 LOGD("No idle event is remained.");
1493                 g_mutex_unlock(&ev->idle_ev_mutex);
1494                 return;
1495         }
1496
1497         LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1498
1499         list = ev->idle_ev_list;
1500         while (list) {
1501                 event_data = list->data;
1502                 list = g_list_next(list);
1503
1504                 if (!event_data) {
1505                         LOGW("Fail to remove idle event. The data is NULL");
1506                         continue;
1507                 }
1508
1509                 if ((event_data->int_data != event_type) && !remove_all)
1510                         continue;
1511
1512                 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1513
1514                 /* set cb to null */
1515                 if (remove_all)
1516                         set_null_user_cb(cb_info, event_data->int_data);
1517
1518                 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1519
1520                 if (!g_idle_remove_by_data(event_data))
1521                         LOGW("failed to find source with %p", event_data);
1522         }
1523
1524         if (remove_all) {
1525                 g_list_free(ev->idle_ev_list);
1526                 ev->idle_ev_list = NULL;
1527         }
1528
1529         g_mutex_unlock(&ev->idle_ev_mutex);
1530
1531         LOGD("LEAVE");
1532         return;
1533 }
1534
1535 static void _player_event_queue_destroy(callback_cb_info_s *cb_info)
1536 {
1537         g_return_if_fail(cb_info);
1538         player_event_queue *ev = &cb_info->event_queue;
1539         _player_cb_data *event_data;
1540
1541         LOGI("event queue thread %p", ev->thread);
1542
1543         g_mutex_lock(&ev->mutex);
1544         ev->running = FALSE;
1545         g_cond_broadcast(&ev->cond);
1546         g_mutex_unlock(&ev->mutex);
1547
1548         g_thread_join(ev->thread);
1549         ev->thread = NULL;
1550
1551         while (!g_queue_is_empty(ev->queue)) {
1552                 event_data = (_player_cb_data *)g_queue_pop_head(ev->queue);
1553                 if (event_data) {
1554                         g_free(event_data->recv_data->buffer);
1555                         g_free(event_data->recv_data);
1556                         g_free(event_data);
1557                 }
1558         }
1559         g_queue_free(ev->queue);
1560         g_mutex_clear(&ev->qlock);
1561         g_mutex_clear(&ev->mutex);
1562         g_cond_clear(&ev->cond);
1563         g_mutex_clear(&ev->idle_ev_mutex);
1564 }
1565
1566 static void _player_event_queue_remove(player_event_queue *ev_queue, int ev)
1567 {
1568         GList *item;
1569
1570         g_mutex_lock(&ev_queue->qlock);
1571
1572         item = g_queue_peek_head_link(ev_queue->queue);
1573         while (item) {
1574                 GList *next = item->next;
1575                 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1576
1577                 if (cb_data && cb_data->int_data == ev) {
1578                         LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1579                         g_free(cb_data->recv_data->buffer);
1580                         g_free(cb_data->recv_data);
1581                         g_free(cb_data);
1582
1583                         g_queue_delete_link(ev_queue->queue, item);
1584                 }
1585                 item = next;
1586         }
1587         g_mutex_unlock(&ev_queue->qlock);
1588 }
1589
1590 static void _player_event_queue_add(player_event_queue *ev, _player_cb_data *data)
1591 {
1592         if (ev->running) {
1593                 g_mutex_lock(&ev->qlock);
1594                 g_queue_push_tail(ev->queue, (gpointer)data);
1595                 g_mutex_unlock(&ev->qlock);
1596                 g_cond_signal(&ev->cond);
1597         }
1598 }
1599
1600 static bool _user_callback_handler(callback_cb_info_s *cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1601 {
1602         /* LOGD("get event %d", event); */
1603
1604         if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1605                 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1606                         _player_cb_data *data = NULL;
1607                         data = g_new(_player_cb_data, 1);
1608                         if (!data) {
1609                                 LOGE("fail to alloc mem");
1610                                 return false;
1611                         }
1612                         data->int_data = (int)event;
1613                         data->cb_info = cb_info;
1614                         data->recv_data = recv_data;
1615                         _player_event_queue_add(&cb_info->event_queue, data);
1616
1617                         return true;
1618                 }
1619         }
1620
1621         LOGE("failed to add event to queue %d", event);
1622         return false;
1623 }
1624
1625 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s *cb_info, int offset, int parse_len)
1626 {
1627         ret_msg_s *msg = NULL;
1628         ret_msg_s *last = cb_info->buff.retMsgHead;
1629
1630         msg = g_new(ret_msg_s, 1);
1631         if (msg) {
1632                 msg->api = api;
1633                 msg->msg = g_strndup(cb_info->buff.recvMsg + offset, parse_len);
1634                 msg->next = NULL;
1635                 if (last == NULL)
1636                         cb_info->buff.retMsgHead = msg;
1637                 else {
1638                         while (last->next)
1639                                 last = last->next;
1640                         last->next = msg;
1641                 }
1642         } else
1643                 LOGE("g_new failure");
1644 }
1645
1646 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s *cb_info)
1647 {
1648         ret_msg_s *msg = cb_info->buff.retMsgHead;
1649         ret_msg_s *prev = NULL;
1650         while (msg) {
1651                 if (msg->api == api) {
1652                         if (!prev)
1653                                 cb_info->buff.retMsgHead = msg->next;
1654                         else
1655                                 prev->next = msg->next;
1656                         return msg;
1657                 }
1658                 prev = msg;
1659                 msg = msg->next;
1660         }
1661         return NULL;
1662 }
1663
1664 static void _remove_all_ret_msg(callback_cb_info_s *cb_info)
1665 {
1666         ret_msg_s *msg = cb_info->buff.retMsgHead;
1667         ret_msg_s *prev = NULL;
1668         while (msg) {
1669                 prev = msg;
1670                 msg = msg->next;
1671                 LOGI("Remove %s", prev->msg);
1672                 g_free(prev->msg);
1673                 prev->msg = NULL;
1674                 g_free(prev);
1675         }
1676 }
1677
1678 static void _notify_disconnected(callback_cb_info_s *cb_info)
1679 {
1680         muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1681         if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1682                 return;
1683
1684         if (_user_callbacks[event]) {
1685                 _player_cb_data *data = NULL;
1686                 data = g_new(_player_cb_data, 1);
1687                 if (!data) {
1688                         LOGE("fail to alloc mem");
1689                         return;
1690                 }
1691                 data->int_data = (int)event;
1692                 data->cb_info = cb_info;
1693                 data->recv_data = NULL;
1694                 _player_event_queue_add(&cb_info->event_queue, data);
1695         }
1696 }
1697
1698 static void *client_cb_handler(gpointer data)
1699 {
1700         int api;
1701         int len = 0;
1702         int parse_len = 0;
1703         int offset = 0;
1704         callback_cb_info_s *cb_info = data;
1705         char *recvMsg = NULL;
1706         muse_core_msg_parse_err_e err;
1707         tbm_fd tfd[MUSE_NUM_FD];
1708
1709         while (g_atomic_int_get(&cb_info->running)) {
1710                 len = 0;
1711                 err = MUSE_MSG_PARSE_ERROR_NONE;
1712
1713                 len = player_recv_msg(cb_info, tfd);
1714                 if (len <= 0)
1715                         break;
1716
1717                 recvMsg = cb_info->buff.recvMsg;
1718                 recvMsg[len] = '\0';
1719
1720                 parse_len = len;
1721                 offset = 0;
1722                 while (offset < len) {
1723                         api = MUSE_PLAYER_API_MAX;
1724 //                      LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1725 //                      usleep(10 * 1000);
1726
1727                         void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1728                         if (jobj) {
1729                                 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1730                                         if (api < MUSE_PLAYER_API_MAX) {
1731                                                 g_mutex_lock(&cb_info->player_mutex);
1732                                                 cb_info->buff.recved++;
1733                                                 _add_ret_msg(api, cb_info, offset, parse_len);
1734                                                 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1735                                                         LOGD("get tbm fd for album art.");
1736                                                         cb_info->tfd = tfd[0];
1737                                                 }
1738                                                 g_cond_signal(&cb_info->player_cond[api]);
1739                                                 g_mutex_unlock(&cb_info->player_mutex);
1740                                                 if (api == MUSE_PLAYER_API_DESTROY)
1741                                                         g_atomic_int_set(&cb_info->running, 0);
1742                                         } else if (api == MUSE_PLAYER_CB_EVENT) {
1743                                                 int event;
1744                                                 _player_recv_data *recv_data = NULL;
1745                                                 g_mutex_lock(&cb_info->player_mutex);
1746                                                 recv_data = g_new0(_player_recv_data, 1);
1747                                                 if (recv_data != NULL) {
1748                                                         memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1749                                                         recv_data->buffer = g_strndup(recvMsg + offset, parse_len);
1750                                                 } else {
1751                                                         LOGE("failed to alloc recv_data.");
1752                                                         g_mutex_unlock(&cb_info->player_mutex);
1753                                                         muse_core_msg_object_free(jobj);
1754                                                         break;
1755                                                 }
1756                                                 g_mutex_unlock(&cb_info->player_mutex);
1757                                                 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1758                                                         !_user_callback_handler(cb_info, event, recv_data)) {
1759                                                         LOGE("failed to get value or add event to the queue.");
1760                                                         if (recv_data) {
1761                                                                 g_free(recv_data->buffer);
1762                                                                 g_free(recv_data);
1763                                                         }
1764                                                 }
1765                                         } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1766                                                 g_mutex_lock(&cb_info->player_mutex);
1767                                                 cb_info->buff.recved++;
1768                                                 g_cond_signal(&cb_info->server_ack_cond);
1769                                                 g_mutex_unlock(&cb_info->player_mutex);
1770                                         }
1771                                 } else {
1772                                         LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg + offset));
1773                                 }
1774                                 muse_core_msg_object_free(jobj);
1775                         } else {
1776                                 LOGE("Failed to get msg obj. err:%d", err);
1777                         }
1778
1779                         if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1780                                 break;
1781
1782                         offset += parse_len;
1783                         parse_len = len - offset;
1784                 }
1785         }
1786         if (g_atomic_int_get(&cb_info->running))
1787                 _notify_disconnected(cb_info);
1788
1789         g_atomic_int_set(&cb_info->running, 0);
1790         LOGD("client cb exit");
1791
1792         return NULL;
1793 }
1794
1795 static callback_cb_info_s *callback_new(gint sockfd)
1796 {
1797         callback_cb_info_s *cb_info;
1798         msg_buff_s *buff;
1799         int i;
1800
1801         g_return_val_if_fail(sockfd > 0, NULL);
1802
1803         cb_info = g_new(callback_cb_info_s, 1);
1804         if (!cb_info)
1805                 return NULL;
1806         memset(cb_info, 0, sizeof(callback_cb_info_s));
1807
1808         g_mutex_init(&cb_info->player_mutex);
1809         for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1810                 g_cond_init(&cb_info->player_cond[i]);
1811         g_cond_init(&cb_info->server_ack_cond);
1812
1813         g_mutex_init(&cb_info->data_mutex);
1814         g_mutex_init(&cb_info->seek_cb_mutex);
1815         g_mutex_init(&cb_info->buffering_cb_mutex);
1816         cb_info->drop_buffering_message = FALSE;
1817
1818         buff = &cb_info->buff;
1819         buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1820         buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1821         buff->recved = 0;
1822         buff->retMsgHead = NULL;
1823         buff->part_of_msg = NULL;
1824
1825         g_atomic_int_set(&cb_info->running, 1);
1826         cb_info->fd = sockfd;
1827         cb_info->tfd = INVALID_DEFAULT_VALUE;
1828         cb_info->data_fd = INVALID_DEFAULT_VALUE;
1829         cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1830
1831         return cb_info;
1832 }
1833
1834 static void callback_destroy(callback_cb_info_s *cb_info)
1835 {
1836         int i;
1837         g_return_if_fail(cb_info);
1838
1839         if (cb_info->fd > INVALID_DEFAULT_VALUE)
1840                 muse_client_close(cb_info->fd);
1841         if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1842                 muse_client_close(cb_info->data_fd);
1843
1844         cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1845
1846         g_thread_join(cb_info->thread);
1847         cb_info->thread = NULL;
1848
1849         LOGI("%p Callback destroyed", cb_info);
1850
1851         for (i = 0; i < MUSE_PLAYER_API_MAX; i++) {
1852                 g_mutex_lock(&cb_info->player_mutex);
1853                 g_cond_signal(&cb_info->player_cond[i]);
1854                 g_mutex_unlock(&cb_info->player_mutex);
1855                 g_cond_clear(&cb_info->player_cond[i]);
1856         }
1857
1858         /* to make sure the return of other pending api */
1859         sched_yield();
1860         g_mutex_lock(&cb_info->player_mutex);
1861         g_mutex_unlock(&cb_info->player_mutex);
1862         g_mutex_clear(&cb_info->player_mutex);
1863
1864         g_cond_clear(&cb_info->server_ack_cond);
1865
1866         g_mutex_clear(&cb_info->data_mutex);
1867         g_mutex_clear(&cb_info->seek_cb_mutex);
1868         g_mutex_clear(&cb_info->buffering_cb_mutex);
1869
1870         g_free(cb_info->buff.recvMsg);
1871         _remove_all_ret_msg(cb_info);
1872         g_free(cb_info->buff.part_of_msg);
1873
1874         g_free(cb_info);
1875 }
1876
1877 int client_get_api_timeout(player_cli_s *pc, muse_player_api_e api)
1878 {
1879         int timeout = 0;
1880
1881         switch (api) {
1882         case MUSE_PLAYER_API_PREPARE:
1883         case MUSE_PLAYER_API_PREPARE_ASYNC:
1884         case MUSE_PLAYER_API_UNPREPARE:
1885         case MUSE_PLAYER_API_START:
1886         case MUSE_PLAYER_API_STOP:
1887         case MUSE_PLAYER_API_PAUSE:
1888                 timeout += SERVER_TIMEOUT(pc);
1889                 break;
1890         default:
1891                 /* check prepare async is done */
1892                 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1893                         timeout += SERVER_TIMEOUT(pc);
1894                 break;
1895         }
1896         timeout += CALLBACK_TIME_OUT;
1897         return timeout; /* ms */
1898 }
1899
1900 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s *cb_info, char **ret_buf, int time_out)
1901 {
1902         int ret = PLAYER_ERROR_NONE;
1903         gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1904         msg_buff_s *buff = &cb_info->buff;
1905         ret_msg_s *msg = NULL;
1906
1907         g_mutex_lock(&cb_info->player_mutex);
1908
1909         msg = _get_ret_msg(api, cb_info);
1910         do {
1911                 if (!buff->recved || !msg) {
1912                         if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1913                                 LOGW("api %d return msg does not received %dms", api, time_out);
1914                                 ret = PLAYER_ERROR_INVALID_OPERATION;
1915                                 break;
1916                         }
1917                 }
1918
1919                 if (!msg)
1920                         msg = _get_ret_msg(api, cb_info);
1921                 if (msg) {
1922                         *ret_buf = msg->msg;
1923                         buff->recved--;
1924                         g_free(msg);
1925                         if (!player_msg_get(ret, *ret_buf))
1926                                 ret = PLAYER_ERROR_INVALID_OPERATION;
1927                         else if (ret != PLAYER_ERROR_NONE)
1928                                 LOGE("Get error return from server 0x%X", ret);
1929                         break;
1930                 }
1931
1932                 if (!g_atomic_int_get(&cb_info->running)) {
1933                         LOGE("callback thread is stopped. %d api did not get return in time", api);
1934                         ret = PLAYER_ERROR_INVALID_OPERATION;
1935                         break;
1936                 } else {
1937                         LOGW("api %d is the spurious wakeup, wait again", api);
1938                 }
1939         } while (!msg && g_atomic_int_get(&cb_info->running));
1940
1941         g_mutex_unlock(&cb_info->player_mutex);
1942         return ret;
1943 }
1944
1945 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s *cb_info, int time_out)
1946 {
1947         int ret = PLAYER_ERROR_NONE;
1948         gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1949         msg_buff_s *buff = &cb_info->buff;
1950
1951         g_mutex_lock(&cb_info->player_mutex);
1952
1953         if (!buff->recved) {
1954                 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1955                         LOGW("server ack msg does not received %dms", time_out);
1956                         if (!buff->recved)
1957                                 ret =  PLAYER_ERROR_INVALID_OPERATION;
1958                         else
1959                                 LOGD("Another msg is received, continue create handle");
1960                         g_mutex_unlock(&cb_info->player_mutex);
1961                         return ret;
1962                 }
1963         }
1964         buff->recved--;
1965
1966         g_mutex_unlock(&cb_info->player_mutex);
1967
1968         return ret;
1969 }
1970
1971
1972 /*
1973 * Public Implementation
1974 */
1975
1976 int player_create(player_h *player)
1977 {
1978         int ret = PLAYER_ERROR_NONE;
1979         int sock_fd = INVALID_DEFAULT_VALUE;
1980         int pid = getpid();
1981
1982         muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1983         int module_index = INVALID_DEFAULT_VALUE;
1984         player_cli_s *pc = NULL;
1985         gchar *ret_buf = NULL;
1986         int retry_count = CONNECTION_RETRY;
1987
1988         PLAYER_INSTANCE_CHECK(player);
1989
1990         LOGD("ENTER");
1991
1992         pc = g_new0(player_cli_s, 1);
1993         if (pc == NULL)
1994                 return PLAYER_ERROR_OUT_OF_MEMORY;
1995
1996         while (retry_count--) {
1997                 ret = PLAYER_ERROR_NONE;
1998                 sock_fd = muse_client_new();
1999                 if (sock_fd <= INVALID_DEFAULT_VALUE) {
2000                         LOGE("connection failure %d", errno);
2001                         ret = PLAYER_ERROR_INVALID_OPERATION;
2002                         usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
2003                         goto ERROR_RETRY;
2004                 }
2005
2006                 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2007                         LOGE("muse client get module index failed");
2008                         ret = PLAYER_ERROR_INVALID_OPERATION;
2009                         goto ERROR;
2010                 }
2011
2012                 PLAYER_SEND_MSG_ASYNC(api, sock_fd, ret,
2013                                                         MUSE_TYPE_INT, "module", module_index,
2014                                                         MUSE_TYPE_INT, "pid", pid);
2015                 if (ret == PLAYER_ERROR_INVALID_OPERATION)
2016                         goto ERROR;
2017
2018                 pc->cb_info = callback_new(sock_fd);
2019                 if (!pc->cb_info) {
2020                         LOGE("fail to create callback");
2021                         ret = PLAYER_ERROR_INVALID_OPERATION;
2022                         goto ERROR;
2023                 }
2024
2025                 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
2026                 if (ret == PLAYER_ERROR_INVALID_OPERATION)
2027                         goto ERROR_RETRY;
2028
2029                 if (!_player_event_queue_new(pc->cb_info)) {
2030                         LOGE("fail to create event queue");
2031                         ret = PLAYER_ERROR_INVALID_OPERATION;
2032                         goto ERROR;
2033                 }
2034
2035                 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
2036                 if (ret == PLAYER_ERROR_NONE) {
2037                         intptr_t module_addr = 0;
2038                         *player = (player_h)pc;
2039                         if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
2040                                 pc->cb_info->data_fd = muse_client_new_data_ch();
2041                                 if ((pc->cb_info->data_fd < 0) || (!muse_core_fd_is_valid(pc->cb_info->data_fd))) {
2042                                         LOGE("Failed to get data_fd");
2043                                         ret = PLAYER_ERROR_INVALID_OPERATION;
2044                                         goto ERROR;
2045                                 }
2046
2047                                 /* share the module addr info to the data_fd */
2048                                 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_CREATE, pc->cb_info->data_fd, ret,
2049                                                                         MUSE_TYPE_POINTER, "module_addr", module_addr);
2050                                 if (ret != PLAYER_ERROR_NONE) {
2051                                         LOGE("Failed to send module address to the data fd");
2052                                         goto ERROR;
2053                                 }
2054                                 LOGD("Data channel fd %d, muse module addr %"PRIxPTR, pc->cb_info->data_fd, module_addr);
2055                         } else {
2056                                 ret = PLAYER_ERROR_INVALID_OPERATION;
2057                                 goto ERROR;
2058                         }
2059                         SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
2060                 } else {
2061                         goto ERROR;
2062                 }
2063
2064                 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
2065                 pc->push_media_stream = FALSE;
2066
2067                 /* get display interface handle */
2068                 if (mm_display_interface_init(&DP_INTERFACE(pc)) != MM_ERROR_NONE)
2069                         LOGW("display interface init failed");
2070
2071                 g_free(ret_buf);
2072
2073                 LOGD("LEAVE 0x%X", ret);
2074                 return ret;
2075
2076 ERROR:
2077                 retry_count = 0;
2078 ERROR_RETRY:
2079                 if (pc && pc->cb_info) {
2080                         if (pc->cb_info->event_queue.running)
2081                                 _player_event_queue_destroy(pc->cb_info);
2082                         callback_destroy(pc->cb_info);
2083                         pc->cb_info = NULL;
2084                 } else if (sock_fd > INVALID_DEFAULT_VALUE) {
2085                         muse_client_close(sock_fd);
2086                 }
2087                 sock_fd = INVALID_DEFAULT_VALUE;
2088
2089                 g_free(ret_buf);
2090                 ret_buf = NULL;
2091                 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
2092         }
2093         g_free(pc);
2094         pc = NULL;
2095         *player = NULL;
2096
2097         LOGD("LEAVE 0x%X", ret);
2098         return ret;
2099 }
2100
2101 int player_destroy(player_h player)
2102 {
2103         int ret = PLAYER_ERROR_NONE;
2104         muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
2105         player_cli_s *pc = (player_cli_s *)player;
2106         char *ret_buf = NULL;
2107         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2108
2109         PLAYER_INSTANCE_CHECK(player);
2110
2111         LOGD("ENTER %p", pc);
2112
2113         /* clear cb and release mem */
2114         set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2115         set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2116         _player_release_internal_memory(pc, true);
2117
2118         if (DP_INTERFACE(pc)) {
2119                 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2120
2121                 if (display_type == MM_DISPLAY_TYPE_EVAS) {
2122                         player_unset_media_packet_video_frame_decoded_cb(player);
2123                         __player_unset_retrieve_buffer_cb(player);
2124                 }
2125
2126                 mm_display_interface_deinit(DP_INTERFACE(pc));
2127                 DP_INTERFACE(pc) = NULL;
2128         }
2129
2130         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2131
2132         if (CALLBACK_INFO(pc)) {
2133                 __player_remove_tsurf_list(pc);
2134                 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
2135                 _player_event_queue_destroy(CALLBACK_INFO(pc));
2136                 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
2137
2138                 callback_destroy(CALLBACK_INFO(pc));
2139         }
2140
2141         g_free(pc);
2142         pc = NULL;
2143
2144         g_free(ret_buf);
2145
2146         LOGD("LEAVE 0x%X", ret);
2147         return ret;
2148 }
2149
2150 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
2151 {
2152         int ret = PLAYER_ERROR_NONE;
2153         muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
2154         player_cli_s *pc = (player_cli_s *)player;
2155         char *ret_buf = NULL;
2156
2157         PLAYER_INSTANCE_CHECK(player);
2158
2159         LOGD("ENTER %p %p", pc, callback);
2160
2161         if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
2162                 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
2163                 return PLAYER_ERROR_INVALID_OPERATION;
2164         } else {
2165                 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
2166                 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
2167         }
2168         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2169         if (ret == PLAYER_ERROR_NONE) {
2170                 int timeout = 0;
2171                 player_msg_get_type(timeout, ret_buf, INT);
2172
2173                 LOGD("server timeout will be %d sec", timeout);
2174                 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2175         } else {
2176                 LOGW("failed to realize, so prepare cb will be released soon");
2177                 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
2178                         set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2179         }
2180
2181         g_free(ret_buf);
2182         return ret;
2183 }
2184
2185 int player_prepare(player_h player)
2186 {
2187         int ret = PLAYER_ERROR_NONE;
2188         muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
2189         player_cli_s *pc = (player_cli_s *)player;
2190         char *ret_buf = NULL;
2191
2192         PLAYER_INSTANCE_CHECK(player);
2193
2194         LOGD("ENTER %p", pc);
2195
2196         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2197         if (ret == PLAYER_ERROR_NONE) {
2198                 int timeout = 0;
2199                 player_msg_get_type(timeout, ret_buf, INT);
2200
2201                 LOGD("server timeout will be %d sec", timeout);
2202                 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2203         }
2204
2205         g_free(ret_buf);
2206
2207         LOGD("LEAVE 0x%X", ret);
2208         return ret;
2209 }
2210
2211 int player_unprepare(player_h player)
2212 {
2213         int ret = PLAYER_ERROR_NONE;
2214         int mm_ret = MM_ERROR_NONE;
2215         muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
2216         player_cli_s *pc = (player_cli_s *)player;
2217         char *ret_buf = NULL;
2218         player_state_e state = PLAYER_STATE_NONE;
2219         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2220
2221         PLAYER_INSTANCE_CHECK(player);
2222
2223         LOGD("ENTER %p", pc);
2224
2225         if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2226                 LOGE("Failed to get state");
2227                 ret = PLAYER_ERROR_INVALID_OPERATION;
2228                 goto EXIT;
2229         }
2230
2231         if (state < PLAYER_STATE_READY) {
2232                 if ((!CALLBACK_INFO(pc)) || (!CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])) {
2233                         LOGE("Invalid state %d", state);
2234                         ret = PLAYER_ERROR_INVALID_STATE;
2235                         goto EXIT;
2236                 }
2237         }
2238
2239         set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2240         set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2241
2242         if (!DP_INTERFACE(pc))
2243                 goto _PLAYER_UNPREPARE;
2244
2245
2246         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2247
2248         if (display_type != MM_DISPLAY_TYPE_EVAS)
2249                 goto _PLAYER_UNPREPARE;
2250
2251         if (CALLBACK_INFO(pc)->dp_info.visible != PLAYER_VISIBLE_INFO_FALSE) {
2252                 mm_ret = mm_display_interface_evas_set_visible(DP_INTERFACE(pc), false);
2253                 if (mm_ret != MM_ERROR_NONE) {
2254                         LOGE("mm_display_interface_evas_set_visible failed 0x%x", mm_ret);
2255                         return PLAYER_ERROR_INVALID_OPERATION;
2256                 }
2257         }
2258
2259         mm_ret = mm_display_interface_evas_flush(DP_INTERFACE(pc), false);
2260         if (mm_ret != MM_ERROR_NONE) {
2261                 LOGE("mm_display_interface_evas_flush failed 0x%x", mm_ret);
2262                 return PLAYER_ERROR_INVALID_OPERATION;
2263         }
2264
2265 _PLAYER_UNPREPARE:
2266         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2267
2268         _player_release_internal_memory(pc, false);
2269         pc->cb_info->video_frame_pool_size = 0;
2270         __player_remove_tsurf_list(pc);
2271
2272         g_free(ret_buf);
2273
2274 EXIT:
2275         LOGD("LEAVE 0x%X", ret);
2276         return ret;
2277 }
2278
2279 /* 1. correct the protocol prefix to lower case
2280  * 2. remove 'file://' prefix
2281  * 3. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' */
2282 int _player_get_valid_path(const char *uri, char *valid_path)
2283 {
2284         gchar *file_path = NULL;
2285         GError *err = NULL;
2286         gchar *colon = NULL;
2287
2288         if (!uri || !valid_path) {
2289                 LOGD("invalid parameter");
2290                 return PLAYER_ERROR_INVALID_PARAMETER;
2291         }
2292
2293         if ((colon = strstr(uri, "://")) != NULL) {
2294                 gchar *protocol = g_ascii_strdown(uri, colon - uri);
2295
2296                 if (protocol) {
2297
2298                         file_path = g_strconcat(protocol, uri + strlen(protocol), NULL);
2299                         strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN - 1);
2300
2301                         g_free(protocol);
2302                         g_free(file_path);
2303                         file_path = NULL;
2304
2305                         if (strstr(valid_path, "file://")) { /* handle the 'file://' prefix */
2306
2307                                 file_path = g_filename_from_uri(valid_path, NULL, &err);
2308                                 if (!file_path || (err != NULL)) {
2309                                         SECURE_LOGE("Invalid URI '%s', err: %s", uri,
2310                                                         (err != NULL) ? err->message : "unknown error");
2311
2312                                         g_error_free(err);
2313                                         g_free(file_path);
2314
2315                                         return PLAYER_ERROR_INVALID_PARAMETER;
2316                                 }
2317                                 LOGD("get file path from uri");
2318                         } else {
2319                                 LOGD("use the original path.");
2320                                 return PLAYER_ERROR_NONE;
2321                         }
2322                 }
2323         }
2324
2325         if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, valid_path) < 0) {
2326                 /* cannot convert path. use the original one. */
2327                 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN - 1);
2328         } else {
2329                 /* need to use converted path. */
2330                 SECURE_LOGD("Converted path : %s -> %s", uri, valid_path);
2331         }
2332
2333         g_free(file_path);
2334
2335         return PLAYER_ERROR_NONE;
2336 }
2337
2338 int player_set_uri(player_h player, const char *uri)
2339 {
2340         int ret = PLAYER_ERROR_NONE;
2341         muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2342         player_cli_s *pc = (player_cli_s *)player;
2343         char *ret_buf = NULL;
2344         char path[MAX_URL_LEN] = {0, };
2345
2346         PLAYER_INSTANCE_CHECK(player);
2347         PLAYER_NULL_ARG_CHECK(uri);
2348
2349         LOGD("ENTER");
2350
2351         if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
2352                 return PLAYER_ERROR_INVALID_PARAMETER;
2353
2354         SECURE_LOGD("new path : %s", path);
2355
2356         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", (const char *)path);
2357         pc->push_media_stream = FALSE;
2358
2359         g_free(ret_buf);
2360         return ret;
2361 }
2362
2363 int player_set_memory_buffer(player_h player, const void *data, int size)
2364 {
2365         int ret = PLAYER_ERROR_NONE;
2366         muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2367         player_cli_s *pc = (player_cli_s *)player;
2368         char *ret_buf = NULL;
2369         tbm_bo bo = NULL;
2370         tbm_bo_handle thandle;
2371         tbm_fd tfd = INVALID_DEFAULT_VALUE;
2372
2373         PLAYER_INSTANCE_CHECK(player);
2374         PLAYER_NULL_ARG_CHECK(data);
2375
2376         LOGD("ENTER");
2377
2378         /* before setting mem buffer, player state have to be checked. */
2379         PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2380
2381         if (SERVER_TBM_BO(pc)) {
2382                 LOGW("The previous memory buffer will be cleared.");
2383                 _player_deinit_memory_buffer(pc);
2384         }
2385
2386         bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2387         if (bo == NULL) {
2388                 LOGE("TBM get error : bo is NULL");
2389                 return PLAYER_ERROR_INVALID_OPERATION;
2390         }
2391         thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2392         if (thandle.ptr == NULL) {
2393                 LOGE("TBM get error : handle pointer is NULL");
2394                 ret = PLAYER_ERROR_INVALID_OPERATION;
2395                 goto EXIT;
2396         }
2397         memcpy(thandle.ptr, data, size);
2398         tbm_bo_unmap(bo);
2399
2400         tfd = tbm_bo_export_fd(bo);
2401         if (tfd < 0) {
2402                 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2403                 ret = PLAYER_ERROR_INVALID_OPERATION;
2404                 goto EXIT;
2405         }
2406
2407         PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret, MUSE_TYPE_INT, "size", size);
2408         pc->push_media_stream = FALSE;
2409
2410  EXIT:
2411         PLAYER_CLOSE_FD(tfd);
2412
2413         tbm_bo_unref(bo);
2414
2415         if (ret == PLAYER_ERROR_NONE) {
2416                 intptr_t bo_addr = 0;
2417                 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2418                         SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2419         }
2420
2421         g_free(ret_buf);
2422         return ret;
2423 }
2424
2425 static void _player_release_internal_memory(player_cli_s *pc, bool deinit_server_mem)
2426 {
2427         if (!pc)
2428                 return;
2429
2430         _del_mem(pc);
2431
2432         if (deinit_server_mem)
2433                 _player_deinit_memory_buffer(pc);
2434 }
2435
2436 static int _player_deinit_memory_buffer(player_cli_s *pc)
2437 {
2438         PLAYER_INSTANCE_CHECK(pc);
2439         int ret = PLAYER_ERROR_NONE;
2440         muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2441         intptr_t bo_addr = SERVER_TBM_BO(pc);
2442
2443         if (!bo_addr || !CALLBACK_INFO(pc))
2444                 return ret;
2445
2446         PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_POINTER, "bo_addr", bo_addr);
2447         SERVER_TBM_BO(pc) = 0;
2448
2449         return ret;
2450 }
2451
2452 int player_get_state(player_h player, player_state_e *pstate)
2453 {
2454         int ret = PLAYER_ERROR_NONE;
2455         player_cli_s *pc = (player_cli_s *)player;
2456
2457         PLAYER_INSTANCE_CHECK(player);
2458         PLAYER_NULL_ARG_CHECK(pstate);
2459
2460         LOGD("ENTER");
2461
2462         ret = _get_current_state(pc, pstate);
2463         return ret;
2464 }
2465
2466 int player_set_volume(player_h player, float left, float right)
2467 {
2468         int ret = PLAYER_ERROR_NONE;
2469         muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2470         player_cli_s *pc = (player_cli_s *)player;
2471         char *ret_buf = NULL;
2472
2473         PLAYER_INSTANCE_CHECK(player);
2474         PLAYER_RANGE_ARG_CHECK(left, 0, 1.0);
2475         PLAYER_RANGE_ARG_CHECK(right, 0, 1.0);
2476
2477         /* not support to set different value into each channel */
2478         PLAYER_CHECK_CONDITION(left == right, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2479
2480         LOGD("ENTER %f", left);
2481
2482         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2483                                         MUSE_TYPE_DOUBLE, "volume", (double)left);
2484
2485         g_free(ret_buf);
2486         return ret;
2487 }
2488
2489 int player_get_volume(player_h player, float *left, float *right)
2490 {
2491         int ret = PLAYER_ERROR_NONE;
2492         muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2493         player_cli_s *pc = (player_cli_s *)player;
2494         double volume = 0.0;
2495         char *ret_buf = NULL;
2496
2497         PLAYER_INSTANCE_CHECK(player);
2498         PLAYER_NULL_ARG_CHECK(left && right);
2499
2500         LOGD("ENTER");
2501
2502         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2503
2504         if (ret == PLAYER_ERROR_NONE) {
2505                 bool ret_val = true;
2506                 ret_val = _player_get_param_value(ret_buf,
2507                                                                         MUSE_TYPE_DOUBLE, "volume", (void *)&volume,
2508                                                                         INVALID_MUSE_TYPE_VALUE);
2509                 if (ret_val) {
2510                         *left = (float)volume;
2511                         *right = (float)volume;
2512                 } else {
2513                         LOGE("failed to get value from msg");
2514                         ret = PLAYER_ERROR_INVALID_OPERATION;
2515                 }
2516         }
2517
2518         g_free(ret_buf);
2519         return ret;
2520 }
2521
2522 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2523 {
2524         muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2525         player_cli_s *pc = (player_cli_s *)player;
2526         bool is_available = false;
2527         char *ret_buf = NULL;
2528
2529         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SOUND_STREAM);
2530         PLAYER_INSTANCE_CHECK(player);
2531         PLAYER_NULL_ARG_CHECK(stream_info);
2532
2533         LOGD("ENTER");
2534
2535         /* check if stream_info is valid */
2536         int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2537         if (ret != SOUND_MANAGER_ERROR_NONE) {
2538                 LOGE("failed to checking available stream info");
2539                 return PLAYER_ERROR_INVALID_OPERATION;
2540         }
2541
2542         if (is_available == false) {
2543                 ret = PLAYER_ERROR_INVALID_PARAMETER;
2544         } else {
2545                 char *stream_type = NULL;
2546                 int stream_index = 0;
2547                 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2548                 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2549                 if (ret == SOUND_MANAGER_ERROR_NONE)
2550                         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2551                                                         MUSE_TYPE_STRING, "stream_type", (const char *)stream_type,
2552                                                         MUSE_TYPE_INT, "stream_index", stream_index);
2553                 else
2554                         ret = PLAYER_ERROR_INVALID_OPERATION;
2555         }
2556
2557         LOGD("LEAVE ret: 0x%X", ret);
2558
2559         g_free(ret_buf);
2560         return ret;
2561
2562 }
2563
2564 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2565 {
2566         int ret = PLAYER_ERROR_NONE;
2567         muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2568         player_cli_s *pc = (player_cli_s *)player;
2569         char *ret_buf = NULL;
2570
2571         PLAYER_INSTANCE_CHECK(player);
2572         PLAYER_RANGE_ARG_CHECK(latency_mode, AUDIO_LATENCY_MODE_LOW, AUDIO_LATENCY_MODE_HIGH);
2573
2574         LOGD("ENTER");
2575
2576         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "latency_mode", (int)latency_mode);
2577         g_free(ret_buf);
2578         return ret;
2579 }
2580
2581 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e *platency_mode)
2582 {
2583         int ret = PLAYER_ERROR_NONE;
2584         muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2585         player_cli_s *pc = (player_cli_s *)player;
2586         char *ret_buf = NULL;
2587         int latency_mode = -1;
2588
2589         PLAYER_INSTANCE_CHECK(player);
2590         PLAYER_NULL_ARG_CHECK(platency_mode);
2591
2592         LOGD("ENTER");
2593
2594         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2595
2596         if (ret == PLAYER_ERROR_NONE) {
2597                 player_msg_get(latency_mode, ret_buf);
2598                 *platency_mode = latency_mode;
2599         }
2600
2601         g_free(ret_buf);
2602         return ret;
2603
2604 }
2605
2606 int player_start(player_h player)
2607 {
2608         int ret = PLAYER_ERROR_NONE;
2609         muse_player_api_e api = MUSE_PLAYER_API_START;
2610         player_cli_s *pc = (player_cli_s *)player;
2611         char *ret_buf = NULL;
2612         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2613
2614         PLAYER_INSTANCE_CHECK(player);
2615
2616         LOGD("ENTER %p", pc);
2617
2618         if (!DP_INTERFACE(pc))
2619                 goto _PLAYER_START;
2620
2621         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2622
2623         if (display_type != MM_DISPLAY_TYPE_EVAS ||
2624                 CALLBACK_INFO(pc)->dp_info.visible == PLAYER_VISIBLE_INFO_FALSE)
2625                 goto _PLAYER_START;
2626
2627         /* set proper visible to evas renderer */
2628         if (mm_display_interface_evas_set_visible(DP_INTERFACE(pc), true) != MM_ERROR_NONE) {
2629                 LOGE("mm_display_interface_evas_set_visible failed");
2630                 return PLAYER_ERROR_INVALID_OPERATION;
2631         }
2632
2633         /* avoid setting true at all times, when player is resumed */
2634         CALLBACK_INFO(pc)->dp_info.visible = PLAYER_VISIBLE_INFO_TRUE;
2635
2636 _PLAYER_START:
2637         g_mutex_lock(&pc->cb_info->buffering_cb_mutex);
2638         pc->cb_info->drop_buffering_message = TRUE;
2639         g_mutex_unlock(&pc->cb_info->buffering_cb_mutex);
2640
2641         _player_remove_idle_event(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_BUFFERING, false);
2642
2643         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2644
2645         g_mutex_lock(&pc->cb_info->buffering_cb_mutex);
2646         pc->cb_info->drop_buffering_message = FALSE;
2647         g_mutex_unlock(&pc->cb_info->buffering_cb_mutex);
2648
2649         g_free(ret_buf);
2650
2651         LOGD("LEAVE 0x%X", ret);
2652         return ret;
2653 }
2654
2655 int player_stop(player_h player)
2656 {
2657         int ret = PLAYER_ERROR_NONE;
2658         int mm_ret = MM_ERROR_NONE;
2659         muse_player_api_e api = MUSE_PLAYER_API_STOP;
2660         player_cli_s *pc = (player_cli_s *)player;
2661         char *ret_buf = NULL;
2662         player_state_e state = PLAYER_STATE_NONE;
2663         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2664
2665         PLAYER_INSTANCE_CHECK(player);
2666
2667         LOGD("ENTER %p", pc);
2668
2669         /* check player state */
2670         if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2671                 LOGE("Failed to get state");
2672                 return PLAYER_ERROR_INVALID_OPERATION;
2673         }
2674
2675         if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2676                 LOGE("Invalid state %d", state);
2677                 return PLAYER_ERROR_INVALID_STATE;
2678         }
2679
2680         if (!DP_INTERFACE(pc))
2681                 goto _PLAYER_STOP;
2682
2683         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2684
2685         if (display_type != MM_DISPLAY_TYPE_EVAS ||
2686                 CALLBACK_INFO(pc)->dp_info.visible == PLAYER_VISIBLE_INFO_FALSE)
2687                 goto _PLAYER_STOP;
2688
2689         mm_ret = mm_display_interface_evas_set_visible(DP_INTERFACE(pc), false);
2690         if (mm_ret != MM_ERROR_NONE) {
2691                 LOGE("mm_display_interface_evas_set_visible failed 0x%x", mm_ret);
2692                 return PLAYER_ERROR_INVALID_OPERATION;
2693         }
2694
2695 _PLAYER_STOP:
2696         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2697         if (ret == PLAYER_ERROR_NONE)
2698                 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2699
2700         g_free(ret_buf);
2701
2702         LOGD("LEAVE 0x%X", ret);
2703         return ret;
2704 }
2705
2706 int player_pause(player_h player)
2707 {
2708         int ret = PLAYER_ERROR_NONE;
2709         muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2710         player_cli_s *pc = (player_cli_s *)player;
2711         char *ret_buf = NULL;
2712
2713         PLAYER_INSTANCE_CHECK(player);
2714
2715         LOGD("ENTER %p", pc);
2716
2717         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2718         g_free(ret_buf);
2719
2720         LOGD("LEAVE 0x%X", ret);
2721         return ret;
2722 }
2723
2724 static int _set_play_position(player_h player, int64_t pos, bool accurate, player_seek_completed_cb callback, void *user_data)
2725 {
2726         int ret = PLAYER_ERROR_NONE;
2727         muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2728         player_cli_s *pc = (player_cli_s *)player;
2729         char *ret_buf = NULL;
2730
2731         PLAYER_INSTANCE_CHECK(player);
2732         PLAYER_CHECK_CONDITION(pos >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2733
2734         LOGD("ENTER %p", pc);
2735
2736         if (!pc->cb_info) {
2737                 LOGE("cb_info is null");
2738                 return PLAYER_ERROR_INVALID_OPERATION;
2739         }
2740
2741         g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2742         if ((pc->push_media_stream == FALSE) &&
2743                 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2744                 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2745                 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2746                 return PLAYER_ERROR_SEEK_FAILED;
2747         } else {
2748                 if (pc->push_media_stream == TRUE)
2749                         pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2750                 else
2751                         pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2752                 LOGI("Event type : %d, pos : %"PRId64", accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, pos, accurate);
2753                 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2754                 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2755         }
2756         g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2757
2758         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2759                                         MUSE_TYPE_INT64, "pos", pos,
2760                                         MUSE_TYPE_INT, "accurate", (int)accurate);
2761
2762         if (ret != PLAYER_ERROR_NONE) {
2763                 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2764                 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2765                 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2766         }
2767
2768         if (pc->push_media_stream == TRUE)
2769                 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2770
2771         g_free(ret_buf);
2772
2773         g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2774         pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2775         g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2776
2777         LOGD("LEAVE 0x%X", ret);
2778         return ret;
2779 }
2780
2781
2782 int player_set_play_position(player_h player, int milliseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2783 {
2784         int ret = PLAYER_ERROR_NONE;
2785         int64_t pos = (int64_t)(milliseconds * G_GINT64_CONSTANT(1000000));
2786
2787         PLAYER_INSTANCE_CHECK(player);
2788         PLAYER_CHECK_CONDITION(milliseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2789
2790         LOGD("ENTER");
2791
2792         ret = _set_play_position(player, pos, accurate, callback, user_data);
2793
2794         LOGD("LEAVE 0x%X", ret);
2795         return ret;
2796 }
2797
2798 int player_set_play_position_nsec(player_h player, int64_t nanoseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2799 {
2800         int ret = PLAYER_ERROR_NONE;
2801         int64_t pos = nanoseconds;
2802
2803         PLAYER_INSTANCE_CHECK(player);
2804         PLAYER_CHECK_CONDITION(nanoseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2805
2806         LOGD("ENTER");
2807
2808         ret = _set_play_position(player, pos, accurate, callback, user_data);
2809
2810         LOGD("LEAVE 0x%X", ret);
2811         return ret;
2812 }
2813
2814 static int _get_play_position(player_h player, int64_t *pos)
2815 {
2816         int ret = PLAYER_ERROR_NONE;
2817         muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2818         player_cli_s *pc = (player_cli_s *)player;
2819         char *ret_buf = NULL;
2820
2821         PLAYER_INSTANCE_CHECK(player);
2822         PLAYER_NULL_ARG_CHECK(pos);
2823
2824         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2825
2826         if (ret == PLAYER_ERROR_NONE) {
2827                 bool ret_val = true;
2828                 ret_val = _player_get_param_value(ret_buf,
2829                                                                         MUSE_TYPE_INT64, "pos", (void *)pos,
2830                                                                         INVALID_MUSE_TYPE_VALUE);
2831                 if (!ret_val)
2832                         ret = PLAYER_ERROR_INVALID_OPERATION;
2833         }
2834
2835         g_free(ret_buf);
2836         return ret;
2837 }
2838
2839
2840 int player_get_play_position(player_h player, int *milliseconds)
2841 {
2842         int ret = PLAYER_ERROR_NONE;
2843         int64_t pos = 0;
2844
2845         PLAYER_INSTANCE_CHECK(player);
2846         PLAYER_NULL_ARG_CHECK(milliseconds);
2847
2848         /* LOGD("ENTER"); */
2849
2850         ret = _get_play_position(player, &pos);
2851         if (ret == PLAYER_ERROR_NONE)
2852                 *milliseconds = (int)(pos / G_GINT64_CONSTANT(1000000));
2853
2854         return ret;
2855 }
2856
2857 int player_get_play_position_nsec(player_h player, int64_t *nanoseconds)
2858 {
2859         int ret = PLAYER_ERROR_NONE;
2860         int64_t pos = 0;
2861
2862         PLAYER_INSTANCE_CHECK(player);
2863         PLAYER_NULL_ARG_CHECK(nanoseconds);
2864
2865         /* LOGD("ENTER"); */
2866
2867         ret = _get_play_position(player, &pos);
2868         if (ret == PLAYER_ERROR_NONE)
2869                 *nanoseconds = pos;
2870
2871         return ret;
2872 }
2873
2874 int player_set_mute(player_h player, bool muted)
2875 {
2876         int ret = PLAYER_ERROR_NONE;
2877         muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2878         player_cli_s *pc = (player_cli_s *)player;
2879         char *ret_buf = NULL;
2880         int mute = (int)muted;
2881
2882         PLAYER_INSTANCE_CHECK(player);
2883
2884         LOGD("ENTER");
2885
2886         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mute", mute);
2887         g_free(ret_buf);
2888         return ret;
2889 }
2890
2891 int player_is_muted(player_h player, bool *muted)
2892 {
2893         int ret = PLAYER_ERROR_NONE;
2894         muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2895         player_cli_s *pc = (player_cli_s *)player;
2896         char *ret_buf = NULL;
2897         int mute = -1;
2898
2899         PLAYER_INSTANCE_CHECK(player);
2900         PLAYER_NULL_ARG_CHECK(muted);
2901
2902         LOGD("ENTER");
2903
2904         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2905         if (ret == PLAYER_ERROR_NONE) {
2906                 player_msg_get(mute, ret_buf);
2907                 *muted = (bool)mute;
2908         }
2909
2910         g_free(ret_buf);
2911         return ret;
2912 }
2913
2914 int player_set_looping(player_h player, bool looping)
2915 {
2916         int ret = PLAYER_ERROR_NONE;
2917         muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2918         player_cli_s *pc = (player_cli_s *)player;
2919         char *ret_buf = NULL;
2920
2921         PLAYER_INSTANCE_CHECK(player);
2922
2923         LOGD("ENTER");
2924
2925         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "looping", (int)looping);
2926         g_free(ret_buf);
2927         return ret;
2928 }
2929
2930 int player_is_looping(player_h player, bool *plooping)
2931 {
2932         int ret = PLAYER_ERROR_NONE;
2933         muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2934         player_cli_s *pc = (player_cli_s *)player;
2935         char *ret_buf = NULL;
2936         int looping = 0;
2937
2938         PLAYER_INSTANCE_CHECK(player);
2939         PLAYER_NULL_ARG_CHECK(plooping);
2940
2941         LOGD("ENTER");
2942
2943         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2944         if (ret == PLAYER_ERROR_NONE) {
2945                 player_msg_get(looping, ret_buf);
2946                 *plooping = looping;
2947         }
2948         g_free(ret_buf);
2949         return ret;
2950 }
2951
2952 static int _get_duration(player_h player, int64_t *duration)
2953 {
2954         int ret = PLAYER_ERROR_NONE;
2955         muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2956         player_cli_s *pc = (player_cli_s *)player;
2957         char *ret_buf = NULL;
2958
2959         PLAYER_INSTANCE_CHECK(player);
2960         PLAYER_NULL_ARG_CHECK(duration);
2961
2962         LOGD("ENTER");
2963
2964         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2965         if (ret == PLAYER_ERROR_NONE) {
2966                 bool ret_val = true;
2967                 ret_val = _player_get_param_value(ret_buf,
2968                                                                         MUSE_TYPE_INT64, "duration", (void *)duration,
2969                                                                         INVALID_MUSE_TYPE_VALUE);
2970                 if (!ret_val)
2971                         ret = PLAYER_ERROR_INVALID_OPERATION;
2972         }
2973
2974         g_free(ret_buf);
2975         return ret;
2976 }
2977
2978
2979 int player_get_duration(player_h player, int *milliseconds)
2980 {
2981         int ret = PLAYER_ERROR_NONE;
2982         int64_t duration = 0; /* nsec */
2983
2984         PLAYER_INSTANCE_CHECK(player);
2985         PLAYER_NULL_ARG_CHECK(milliseconds);
2986
2987         LOGD("ENTER");
2988
2989         ret = _get_duration(player, &duration);
2990         if (ret == PLAYER_ERROR_NONE) {
2991                 /* convert time from ns to ms */
2992                 *milliseconds = (int)(duration / G_GINT64_CONSTANT(1000000));
2993         }
2994
2995         LOGD("LEAVE 0x%X", ret);
2996         return ret;
2997 }
2998
2999 int player_get_duration_nsec(player_h player, int64_t *nanoseconds)
3000 {
3001         int ret = PLAYER_ERROR_NONE;
3002         int64_t duration = 0; /* nsec */
3003
3004         PLAYER_INSTANCE_CHECK(player);
3005         PLAYER_NULL_ARG_CHECK(nanoseconds);
3006
3007         LOGD("ENTER");
3008
3009         ret = _get_duration(player, &duration);
3010         if (ret == PLAYER_ERROR_NONE)
3011                 *nanoseconds = duration;
3012
3013         LOGD("LEAVE 0x%X", ret);
3014         return ret;
3015 }
3016
3017 /* The player_display_type_e is different at wearable profile */
3018 int _player_convert_display_type(player_display_type_e type, mm_display_type_e *out_type)
3019 {
3020         int ret = PLAYER_ERROR_NONE;
3021
3022         PLAYER_NULL_ARG_CHECK(out_type);
3023
3024         switch (type) {
3025         case PLAYER_DISPLAY_TYPE_OVERLAY:
3026                 *out_type = MM_DISPLAY_TYPE_OVERLAY;
3027                 break;
3028         case PLAYER_DISPLAY_TYPE_OVERLAY_SYNC_UI:
3029                 *out_type = MM_DISPLAY_TYPE_OVERLAY_SYNC_UI;
3030                 break;
3031         case PLAYER_DISPLAY_TYPE_EVAS:
3032                 *out_type = MM_DISPLAY_TYPE_EVAS;
3033                 break;
3034         case PLAYER_DISPLAY_TYPE_NONE:
3035                 *out_type = MM_DISPLAY_TYPE_NONE;
3036                 break;
3037         default:
3038                 ret = PLAYER_ERROR_INVALID_PARAMETER;
3039                 break;
3040         }
3041
3042         LOGD("display type(%d) -> (%d)", type, *out_type);
3043
3044         return ret;
3045 }
3046
3047 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
3048 {
3049         int ret = PLAYER_ERROR_NONE;
3050         int mm_ret = MM_ERROR_NONE;
3051         muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
3052         player_cli_s *pc = (player_cli_s *)player;
3053         char *ret_buf = NULL;
3054         wl_win_msg_type wl_win;
3055         char *wl_win_msg = (char *)&wl_win;
3056         mm_display_type_e conv_type = MM_DISPLAY_TYPE_NONE;
3057         int arr_msg_len = 0;
3058         pid_t pid = getpid();
3059         pid_t tid = syscall(SYS_gettid);
3060
3061         PLAYER_INSTANCE_CHECK(player);
3062
3063         if (type != PLAYER_DISPLAY_TYPE_NONE) {
3064                 LOGD("Check if API is called in main thread. pid [%d], tid [%d]", pid, tid);
3065                 if (pid != tid) {
3066                         LOGE("API isn't called in main thread");
3067                         return PLAYER_ERROR_INVALID_OPERATION;
3068                 }
3069         }
3070
3071         /* check display interface handle */
3072         if (!DP_INTERFACE(pc)) {
3073                 LOGE("display interface not supported");
3074                 return PLAYER_ERROR_INVALID_OPERATION;
3075         }
3076
3077         LOGD("ENTER type: %d", type);
3078
3079         /* before setting display, player state have to be checked. */
3080         PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
3081
3082         ret = _player_convert_display_type(type, &conv_type);
3083         if (ret != PLAYER_ERROR_NONE)
3084                 return ret;
3085
3086         if (conv_type != MM_DISPLAY_TYPE_NONE) {
3087                 if (!display) {
3088                         LOGE("type[%d] NULL handle for display", type);
3089                         return PLAYER_ERROR_INVALID_PARAMETER;
3090                 }
3091
3092                 mm_ret = mm_display_interface_set_display(DP_INTERFACE(pc), conv_type, display, &wl_win.surface_id);
3093                 if (mm_ret != MM_ERROR_NONE) {
3094                         LOGE("[INVALID_OPERATION] set display failed[0x%x]", mm_ret);
3095                         return PLAYER_ERROR_INVALID_OPERATION;
3096                 }
3097
3098                 if (conv_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3099                         g_strlcpy(wl_win.exported_shell_handle, (char *)display, MAX_EXPORTED_SHELL_HANDLE_LEN);
3100                 } else if (conv_type == MM_DISPLAY_TYPE_EVAS) {
3101                         /* before evas handle is created, user could set display information */
3102                         player_display_mode_e mode = PLAYER_DISPLAY_MODE_LETTER_BOX;
3103                         player_display_rotation_e rotation = PLAYER_DISPLAY_ROTATION_NONE;
3104                         bool visible = false;
3105
3106                         ret = player_get_display_mode(player, &mode);
3107                         ret |= player_get_display_rotation(player, &rotation);
3108                         ret |= player_is_display_visible(player, &visible);
3109
3110                         if (ret != PLAYER_ERROR_NONE) {
3111                                 LOGE("get current display settings");
3112                                 return PLAYER_ERROR_INVALID_OPERATION;
3113                         }
3114
3115                         LOGD("current setting : mode %d, rotation %d, visible %d, roi %d,%d,%dx%d",
3116                                 mode, rotation, visible,
3117                                 CALLBACK_INFO(pc)->dp_info.roi_x,
3118                                 CALLBACK_INFO(pc)->dp_info.roi_y,
3119                                 CALLBACK_INFO(pc)->dp_info.roi_w,
3120                                 CALLBACK_INFO(pc)->dp_info.roi_h);
3121
3122                         mm_ret = mm_display_interface_evas_set_mode(DP_INTERFACE(pc), mode);
3123                         mm_ret |= mm_display_interface_evas_set_rotation(DP_INTERFACE(pc), rotation);
3124                         mm_ret |= mm_display_interface_evas_set_visible(DP_INTERFACE(pc), visible);
3125                         if (mode == PLAYER_DISPLAY_MODE_DST_ROI) {
3126                                 mm_ret |= mm_display_interface_evas_set_roi_area(DP_INTERFACE(pc),
3127                                         CALLBACK_INFO(pc)->dp_info.roi_x, CALLBACK_INFO(pc)->dp_info.roi_y,
3128                                         CALLBACK_INFO(pc)->dp_info.roi_w, CALLBACK_INFO(pc)->dp_info.roi_h);
3129                         }
3130
3131                         if (mm_ret != MM_ERROR_NONE) {
3132                                 LOGE("set mm_display_interface failed");
3133                                 return PLAYER_ERROR_INVALID_OPERATION;
3134                         }
3135
3136                         if (player_set_media_packet_video_frame_decoded_cb(player,
3137                                 __player_media_packet_video_decoded_cb, player) != MM_ERROR_NONE) {
3138                                 LOGE("fail to set decoded callback");
3139                                 return PLAYER_ERROR_INVALID_OPERATION;
3140                         }
3141
3142                         if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
3143                                 LOGW("fail to set __retrieve_buffer_cb");
3144                 }
3145         }
3146
3147         wl_win.type = conv_type;
3148
3149         arr_msg_len = (sizeof(wl_win_msg_type) / sizeof(int) + (sizeof(wl_win_msg_type) % sizeof(int) ? 1 : 0));
3150         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3151                 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int *)wl_win_msg);
3152
3153         g_free(ret_buf);
3154
3155         return ret;
3156 }
3157
3158 int player_set_display_mode(player_h player, player_display_mode_e mode)
3159 {
3160         int ret = PLAYER_ERROR_NONE;
3161         int mm_ret = MM_ERROR_NONE;
3162         muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
3163         player_cli_s *pc = (player_cli_s *)player;
3164         char *ret_buf = NULL;
3165         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3166
3167         PLAYER_INSTANCE_CHECK(player);
3168         PLAYER_RANGE_ARG_CHECK(mode, PLAYER_DISPLAY_MODE_LETTER_BOX, PLAYER_DISPLAY_MODE_DST_ROI);
3169
3170         LOGD("ENTER");
3171
3172         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3173
3174         if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3175                 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3176                 return PLAYER_ERROR_NOT_AVAILABLE;
3177         }
3178
3179         if (display_type == MM_DISPLAY_TYPE_EVAS) {
3180                 mm_ret = mm_display_interface_evas_set_mode(DP_INTERFACE(pc), mode);
3181                 if (mm_ret != MM_ERROR_NONE) {
3182                         LOGE("mm_display_interface_evas_set_mode failed 0x%x", mm_ret);
3183                         return PLAYER_ERROR_INVALID_OPERATION;
3184                 }
3185         }
3186
3187         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mode", (int)mode);
3188
3189         g_free(ret_buf);
3190
3191         return ret;
3192 }
3193
3194 int player_get_display_mode(player_h player, player_display_mode_e *pmode)
3195 {
3196         int ret = PLAYER_ERROR_NONE;
3197         muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
3198         player_cli_s *pc = (player_cli_s *)player;
3199         char *ret_buf = NULL;
3200         int mode = -1;
3201         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3202
3203         PLAYER_INSTANCE_CHECK(player);
3204         PLAYER_NULL_ARG_CHECK(pmode);
3205
3206         LOGD("ENTER");
3207
3208         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3209
3210         if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3211                 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3212                 return PLAYER_ERROR_NOT_AVAILABLE;
3213         }
3214
3215         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3216
3217         if (ret == PLAYER_ERROR_NONE) {
3218                 player_msg_get_type(mode, ret_buf, INT);
3219                 *pmode = mode;
3220         }
3221
3222         g_free(ret_buf);
3223
3224         return ret;
3225 }
3226
3227 int player_set_video_roi_area(player_h player, double x_scale, double y_scale,
3228                 double w_scale, double h_scale)
3229 {
3230         int ret = PLAYER_ERROR_NONE;
3231         muse_player_api_e api = MUSE_PLAYER_API_SET_VIDEO_ROI_AREA;
3232         player_cli_s *pc = (player_cli_s *)player;
3233         char *ret_buf = NULL;
3234         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3235
3236         PLAYER_INSTANCE_CHECK(player);
3237
3238         LOGD("ENTER");
3239
3240         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3241
3242         if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3243                 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3244                 return PLAYER_ERROR_NOT_AVAILABLE;
3245         }
3246
3247         if (display_type == MM_DISPLAY_TYPE_EVAS) {
3248                 LOGE("Display type is EVAS, video display interface is not supported");
3249                 return PLAYER_ERROR_INVALID_OPERATION;
3250         }
3251
3252         if (!_player_video_roi_area_is_valid(x_scale, y_scale, w_scale, h_scale))
3253                 return PLAYER_ERROR_INVALID_PARAMETER;
3254
3255         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3256                         MUSE_TYPE_DOUBLE, "x_scale", x_scale,
3257                         MUSE_TYPE_DOUBLE, "y_scale", y_scale,
3258                         MUSE_TYPE_DOUBLE, "w_scale", w_scale,
3259                         MUSE_TYPE_DOUBLE, "h_scale", h_scale);
3260
3261         g_free(ret_buf);
3262
3263         return ret;
3264 }
3265
3266
3267 int player_get_video_roi_area(player_h player, double *x_scale, double *y_scale,
3268                 double *w_scale, double *h_scale)
3269 {
3270         int ret = PLAYER_ERROR_NONE;
3271         muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_ROI_AREA;
3272         player_cli_s *pc = (player_cli_s *)player;
3273         char *ret_buf = NULL;
3274         double scale_x = 0, scale_y = 0, scale_w = 0, scale_h = 0;
3275         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3276
3277         PLAYER_INSTANCE_CHECK(player);
3278         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3279
3280         if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3281                 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3282                 return PLAYER_ERROR_NOT_AVAILABLE;
3283         }
3284
3285         PLAYER_NULL_ARG_CHECK(x_scale && y_scale && w_scale && h_scale);
3286
3287         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3288
3289         if (ret == PLAYER_ERROR_NONE) {
3290                 if (player_msg_get_type(scale_x, ret_buf, DOUBLE))
3291                         *x_scale = scale_x;
3292                 else
3293                         LOGE("failed to get value from msg");
3294                 if (player_msg_get_type(scale_y, ret_buf, DOUBLE))
3295                         *y_scale = scale_y;
3296                 else
3297                         LOGE("failed to get value from msg");
3298                 if (player_msg_get_type(scale_w, ret_buf, DOUBLE))
3299                         *w_scale = scale_w;
3300                 else
3301                         LOGE("failed to get value from msg");
3302                 if (player_msg_get_type(scale_h, ret_buf, DOUBLE))
3303                         *h_scale = scale_h;
3304                 else
3305                         LOGE("failed to get value from msg");
3306         }
3307
3308         g_free(ret_buf);
3309
3310         return ret;
3311 }
3312
3313
3314 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
3315 {
3316         int ret = PLAYER_ERROR_NONE;
3317         int mm_ret = MM_ERROR_NONE;
3318         muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
3319         player_cli_s *pc = (player_cli_s *)player;
3320         char *ret_buf = NULL;
3321         wl_win_msg_type wl_win;
3322         char *wl_win_msg = (char *)&wl_win;
3323         int arr_msg_len = 0;
3324         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3325
3326         PLAYER_INSTANCE_CHECK(player);
3327         PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3328
3329         LOGD("ENTER");
3330
3331         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3332
3333         if (display_type == MM_DISPLAY_TYPE_EVAS) {
3334                 mm_ret = mm_display_interface_evas_set_roi_area(DP_INTERFACE(pc), x, y, width, height);
3335                 if (mm_ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
3336                         return PLAYER_ERROR_INVALID_PARAMETER;
3337                 else if (mm_ret != MM_ERROR_NONE)
3338                         return PLAYER_ERROR_INVALID_OPERATION;
3339         }
3340
3341         wl_win.win_roi_x = x;
3342         wl_win.win_roi_y = y;
3343         wl_win.win_roi_width = width;
3344         wl_win.win_roi_height = height;
3345
3346         arr_msg_len = (sizeof(wl_win_msg_type) / sizeof(int) + (sizeof(wl_win_msg_type) % sizeof(int) ? 1 : 0));
3347         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3348                 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int *)wl_win_msg);
3349
3350         if (ret == PLAYER_ERROR_NONE) {
3351                 CALLBACK_INFO(pc)->dp_info.roi_x = x;
3352                 CALLBACK_INFO(pc)->dp_info.roi_y = y;
3353                 CALLBACK_INFO(pc)->dp_info.roi_w = width;
3354                 CALLBACK_INFO(pc)->dp_info.roi_h = height;
3355         }
3356
3357         g_free(ret_buf);
3358
3359         return ret;
3360 }
3361
3362 int player_set_playback_rate(player_h player, float rate)
3363 {
3364         int ret = PLAYER_ERROR_NONE;
3365         muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
3366         player_cli_s *pc = (player_cli_s *)player;
3367         char *ret_buf = NULL;
3368
3369         PLAYER_INSTANCE_CHECK(player);
3370         PLAYER_RANGE_ARG_CHECK(rate, -5.0, 5.0);
3371
3372         LOGD("ENTER");
3373         if (rate != 0) {
3374                 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", (double)rate);
3375                 g_free(ret_buf);
3376         }
3377         LOGD("LEAVE 0x%X", ret);
3378         return ret;
3379 }
3380
3381 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
3382 {
3383         int ret = PLAYER_ERROR_NONE;
3384         int mm_ret = MM_ERROR_NONE;
3385         muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
3386         player_cli_s *pc = (player_cli_s *)player;
3387         char *ret_buf = NULL;
3388         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3389
3390         PLAYER_INSTANCE_CHECK(player);
3391         PLAYER_RANGE_ARG_CHECK(rotation, PLAYER_DISPLAY_ROTATION_NONE, PLAYER_DISPLAY_ROTATION_270);
3392
3393         LOGD("ENTER");
3394
3395         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3396
3397         if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3398                 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3399                 return PLAYER_ERROR_NOT_AVAILABLE;
3400         }
3401
3402         if (display_type == MM_DISPLAY_TYPE_EVAS) {
3403                 mm_ret = mm_display_interface_evas_set_rotation(DP_INTERFACE(pc), rotation);
3404                 if (mm_ret != MM_ERROR_NONE) {
3405                         LOGE("mm_display_interface_evas_set_rotation failed 0x%x", mm_ret);
3406                         return PLAYER_ERROR_INVALID_OPERATION;
3407                 }
3408         }
3409
3410         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "rotation", (int)rotation);
3411
3412         g_free(ret_buf);
3413
3414         return ret;
3415 }
3416
3417 int player_get_display_rotation(player_h player, player_display_rotation_e *protation)
3418 {
3419         int ret = PLAYER_ERROR_NONE;
3420         player_cli_s *pc = (player_cli_s *)player;
3421         muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
3422         char *ret_buf = NULL;
3423         int rotation = -1;
3424         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3425
3426         PLAYER_INSTANCE_CHECK(player);
3427         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3428
3429         if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3430                 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3431                 return PLAYER_ERROR_NOT_AVAILABLE;
3432         }
3433
3434         PLAYER_NULL_ARG_CHECK(protation);
3435
3436         LOGD("ENTER");
3437
3438         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3439
3440         if (ret == PLAYER_ERROR_NONE) {
3441                 player_msg_get_type(rotation, ret_buf, INT);
3442                 *protation = rotation;
3443         }
3444
3445         g_free(ret_buf);
3446
3447         return ret;
3448 }
3449
3450 int player_set_display_visible(player_h player, bool visible)
3451 {
3452         int ret = PLAYER_ERROR_NONE;
3453         int mm_ret = MM_ERROR_NONE;
3454         player_cli_s *pc = (player_cli_s *)player;
3455         muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
3456         char *ret_buf = NULL;
3457         mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3458
3459         PLAYER_INSTANCE_CHECK(player);
3460
3461         LOGD("ENTER");
3462
3463         PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3464
3465         if (display_type == MM_DISPLAY_TYPE_EVAS) {
3466                 mm_ret = mm_display_interface_evas_set_visible(DP_INTERFACE(pc), visible);
3467                 if (mm_ret != MM_ERROR_NONE) {
3468                         LOGE("mm_display_interface_evas_set_visible failed 0x%x", mm_ret);
3469                         return PLAYER_ERROR_INVALID_OPERATION;
3470                 }
3471         }
3472
3473         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "visible", (int)visible);
3474
3475         g_free(ret_buf);
3476
3477         if (ret == PLAYER_ERROR_NONE)
3478                 CALLBACK_INFO(pc)->dp_info.visible = visible ? PLAYER_VISIBLE_INFO_TRUE : PLAYER_VISIBLE_INFO_FALSE;
3479
3480         return ret;
3481 }
3482
3483 int player_is_display_visible(player_h player, bool *pvisible)
3484 {
3485         int ret = PLAYER_ERROR_NONE;
3486         player_cli_s *pc = (player_cli_s *)player;
3487         muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
3488         char *ret_buf = NULL;
3489         int value = -1;
3490
3491         PLAYER_INSTANCE_CHECK(player);
3492         PLAYER_NULL_ARG_CHECK(pvisible);
3493
3494         LOGD("ENTER");
3495
3496         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3497
3498         if (ret == PLAYER_ERROR_NONE) {
3499                 player_msg_get_type(value, ret_buf, INT);
3500
3501                 if (value)
3502                         *pvisible = TRUE;
3503                 else
3504                         *pvisible = FALSE;
3505         }
3506
3507         g_free(ret_buf);
3508
3509         return ret;
3510 }
3511
3512 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3513 {
3514         int ret = PLAYER_ERROR_NONE;
3515         muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3516         player_cli_s *pc = (player_cli_s *)player;
3517         char *ret_buf = NULL;
3518         char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3519
3520         PLAYER_INSTANCE_CHECK(player);
3521         PLAYER_NULL_ARG_CHECK(pvalue);
3522
3523         LOGD("ENTER");
3524
3525         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "key", (int)key);
3526         if (ret == PLAYER_ERROR_NONE) {
3527                 player_msg_get_string(value, ret_buf);
3528                 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3529         }
3530         g_free(ret_buf);
3531         return ret;
3532 }
3533
3534 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3535 {
3536         int ret = PLAYER_ERROR_NONE;
3537         muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3538         player_cli_s *pc = (player_cli_s *)player;
3539         char *ret_buf = NULL;
3540         char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3541         char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3542         bool ret_val = TRUE;
3543
3544         PLAYER_INSTANCE_CHECK(player);
3545         PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3546
3547         LOGD("ENTER");
3548
3549         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3550         if (ret == PLAYER_ERROR_NONE) {
3551                 ret_val = _player_get_param_value(ret_buf,
3552                                                                         MUSE_TYPE_STRING, "video_codec", (void *)video_codec,
3553                                                                         MUSE_TYPE_STRING, "audio_codec", (void *)audio_codec,
3554                                                                         INVALID_MUSE_TYPE_VALUE);
3555                 if (ret_val) {
3556                         if (pvideo_codec)
3557                                 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3558                         if (paudio_codec)
3559                                 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3560                 } else {
3561                         ret = PLAYER_ERROR_INVALID_OPERATION;
3562                 }
3563         }
3564         g_free(ret_buf);
3565         return ret;
3566 }
3567
3568 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3569 {
3570         int ret = PLAYER_ERROR_NONE;
3571         muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3572         player_cli_s *pc = (player_cli_s *)player;
3573         char *ret_buf = NULL;
3574         int sample_rate = 0;
3575         int channel = 0;
3576         int bit_rate = 0;
3577
3578         PLAYER_INSTANCE_CHECK(player);
3579         PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3580
3581         LOGD("ENTER");
3582
3583         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3584         if (ret == PLAYER_ERROR_NONE) {
3585                 bool ret_val = true;
3586                 ret_val = _player_get_param_value(ret_buf,
3587                                                                                 MUSE_TYPE_INT, "sample_rate", (void *)&sample_rate,
3588                                                                                 MUSE_TYPE_INT, "channel", (void *)&channel,
3589                                                                                 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3590                                                                                 INVALID_MUSE_TYPE_VALUE);
3591                 if (ret_val) {
3592                         if (psample_rate)
3593                                 *psample_rate = sample_rate;
3594                         if (pchannel)
3595                                 *pchannel = channel;
3596                         if (pbit_rate)
3597                                 *pbit_rate = bit_rate;
3598                 } else {
3599                         ret = PLAYER_ERROR_INVALID_OPERATION;
3600                 }
3601         }
3602         g_free(ret_buf);
3603         return ret;
3604 }
3605
3606 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3607 {
3608         int ret = PLAYER_ERROR_NONE;
3609         muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3610         player_cli_s *pc = (player_cli_s *)player;
3611         char *ret_buf = NULL;
3612         int fps = 0;
3613         int bit_rate = 0;
3614
3615         PLAYER_INSTANCE_CHECK(player);
3616         PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3617
3618         LOGD("ENTER");
3619
3620         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3621         if (ret == PLAYER_ERROR_NONE) {
3622                 bool ret_val = true;
3623                 ret_val = _player_get_param_value(ret_buf,
3624                                                                         MUSE_TYPE_INT, "fps", (void *)&fps,
3625                                                                         MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3626                                                                         INVALID_MUSE_TYPE_VALUE);
3627                 if (ret_val) {
3628                         if (pfps)
3629                                 *pfps = fps;
3630                         if (pbit_rate)
3631                                 *pbit_rate = bit_rate;
3632                 } else {
3633                         ret = PLAYER_ERROR_INVALID_OPERATION;
3634                 }
3635         }
3636         g_free(ret_buf);
3637         return ret;
3638 }
3639
3640 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3641 {
3642         int ret = PLAYER_ERROR_NONE;
3643         muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3644         player_cli_s *pc = (player_cli_s *)player;
3645         char *ret_buf = NULL;
3646         int width = 0;
3647         int height = 0;
3648
3649         PLAYER_INSTANCE_CHECK(player);
3650         PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3651
3652         LOGD("ENTER");
3653
3654         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3655         if (ret == PLAYER_ERROR_NONE) {
3656                 bool ret_val = true;
3657                 ret_val = _player_get_param_value(ret_buf,
3658                                                                         MUSE_TYPE_INT, "width", (void *)&width,
3659                                                                         MUSE_TYPE_INT, "height", (void *)&height,
3660                                                                         INVALID_MUSE_TYPE_VALUE);
3661                 if (ret_val) {
3662                         *pwidth = width;
3663                         *pheight = height;
3664                 } else {
3665                         ret = PLAYER_ERROR_INVALID_OPERATION;
3666                 }
3667         }
3668         g_free(ret_buf);
3669         return ret;
3670 }
3671
3672 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3673 {
3674         int ret = PLAYER_ERROR_NONE;
3675         muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3676         player_cli_s *pc = (player_cli_s *)player;
3677         char *ret_buf = NULL;
3678         char *album_art;
3679         int size = 0;
3680         tbm_bo bo = NULL;
3681         tbm_bo_handle thandle;
3682         tbm_fd tfd = INVALID_DEFAULT_VALUE;
3683         int key = INVALID_DEFAULT_VALUE;
3684         void *jobj = NULL;
3685
3686         PLAYER_INSTANCE_CHECK(player);
3687         PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3688
3689         LOGD("ENTER");
3690
3691         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3692         if (ret == PLAYER_ERROR_NONE) {
3693                 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3694                 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3695                 if (!jobj) {
3696                         LOGE("failed to get msg obj, err:%d", err);
3697                         ret = PLAYER_ERROR_INVALID_OPERATION;
3698                         goto EXIT;
3699                 }
3700
3701                 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3702                         LOGD("size : %d", size);
3703                         if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3704                                 LOGE("failed to get key value");
3705                                 ret = PLAYER_ERROR_INVALID_OPERATION;
3706                                 goto EXIT;
3707                         }
3708
3709                         tfd = pc->cb_info->tfd;
3710                         if (tfd < 0) {
3711                                 LOGE("failed to get tbm fd value");
3712                                 ret = PLAYER_ERROR_INVALID_OPERATION;
3713                                 goto EXIT;
3714                         }
3715
3716                         bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3717                         if (bo == NULL) {
3718                                 LOGE("TBM get error : bo is NULL");
3719                                 ret = PLAYER_ERROR_INVALID_OPERATION;
3720                                 goto EXIT;
3721                         }
3722                         thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3723                         if (thandle.ptr == NULL) {
3724                                 LOGE("TBM get error : handle pointer is NULL");
3725                                 ret = PLAYER_ERROR_INVALID_OPERATION;
3726                                 goto EXIT;
3727                         }
3728                         album_art = _get_mem(pc, size);
3729                         if (album_art) {
3730                                 memcpy(album_art, thandle.ptr, size);
3731                                 *palbum_art = album_art;
3732                         } else {
3733                                 LOGE("g_new failure");
3734                                 ret = PLAYER_ERROR_INVALID_OPERATION;
3735                         }
3736                         tbm_bo_unmap(bo);
3737                         *psize = size;
3738                 } else {
3739                         *palbum_art = NULL;
3740                         *psize = 0;
3741                 }
3742         }
3743
3744 EXIT:
3745         if (jobj)
3746                 muse_core_msg_object_free(jobj);
3747
3748         g_free(ret_buf);
3749
3750         PLAYER_CLOSE_FD(tfd);
3751
3752         if (CALLBACK_INFO(pc))
3753                 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3754
3755         if (bo)
3756                 tbm_bo_unref(bo);
3757
3758         /* return buffer */
3759         if (key > INVALID_DEFAULT_VALUE && CALLBACK_INFO(pc)) {
3760                 LOGD("send msg to release buffer. key:%d", key);
3761                 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_RETURN_BUFFER, MSG_FD(pc), ret, MUSE_TYPE_INT, "key", key);
3762         }
3763
3764         return ret;
3765 }
3766
3767 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3768 {
3769         int ret = PLAYER_ERROR_NONE;
3770         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3771         player_cli_s *pc = (player_cli_s *)player;
3772         char *ret_buf = NULL;
3773         int count;
3774
3775         PLAYER_INSTANCE_CHECK(player);
3776         PLAYER_NULL_ARG_CHECK(pcount);
3777
3778         LOGD("ENTER");
3779
3780         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3781         if (ret == PLAYER_ERROR_NONE) {
3782                 player_msg_get(count, ret_buf);
3783                 *pcount = count;
3784         }
3785         g_free(ret_buf);
3786         return ret;
3787 }
3788
3789 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3790 {
3791         int ret = PLAYER_ERROR_NONE;
3792         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3793         player_cli_s *pc = (player_cli_s *)player;
3794         char *ret_buf = NULL;
3795
3796         PLAYER_INSTANCE_CHECK(player);
3797         PLAYER_NULL_ARG_CHECK(band_levels);
3798
3799         LOGD("ENTER");
3800
3801         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3802                                         MUSE_TYPE_INT, "length", length,
3803                                         MUSE_TYPE_ARRAY, "band_levels", length, band_levels);
3804
3805         g_free(ret_buf);
3806         return ret;
3807
3808 }
3809
3810 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3811 {
3812         int ret = PLAYER_ERROR_NONE;
3813         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3814         player_cli_s *pc = (player_cli_s *)player;
3815         char *ret_buf = NULL;
3816
3817         PLAYER_INSTANCE_CHECK(player);
3818
3819         LOGD("ENTER");
3820
3821         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3822                                         MUSE_TYPE_INT, "index", index,
3823                                         MUSE_TYPE_INT, "level", level);
3824
3825         g_free(ret_buf);
3826         return ret;
3827 }
3828
3829 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3830 {
3831         int ret = PLAYER_ERROR_NONE;
3832         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3833         player_cli_s *pc = (player_cli_s *)player;
3834         char *ret_buf = NULL;
3835         int level;
3836
3837         PLAYER_INSTANCE_CHECK(player);
3838         PLAYER_NULL_ARG_CHECK(plevel);
3839
3840         LOGD("ENTER");
3841
3842         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3843         if (ret == PLAYER_ERROR_NONE) {
3844                 player_msg_get(level, ret_buf);
3845                 *plevel = level;
3846         }
3847         g_free(ret_buf);
3848         return ret;
3849 }
3850
3851 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3852 {
3853         int ret = PLAYER_ERROR_NONE;
3854         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3855         player_cli_s *pc = (player_cli_s *)player;
3856         char *ret_buf = NULL;
3857         int min = 0, max = 0;
3858
3859         PLAYER_INSTANCE_CHECK(player);
3860         PLAYER_NULL_ARG_CHECK(pmin && pmax);
3861
3862         LOGD("ENTER");
3863
3864         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3865         if (ret == PLAYER_ERROR_NONE) {
3866                 bool ret_val = true;
3867                 ret_val = _player_get_param_value(ret_buf,
3868                                                                         MUSE_TYPE_INT, "min", (void *)&min,
3869                                                                         MUSE_TYPE_INT, "max", (void *)&max,
3870                                                                         INVALID_MUSE_TYPE_VALUE);
3871                 if (ret_val) {
3872                         *pmin = min;
3873                         *pmax = max;
3874                 } else {
3875                         ret = PLAYER_ERROR_INVALID_OPERATION;
3876                 }
3877         }
3878         g_free(ret_buf);
3879         return ret;
3880 }
3881
3882 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3883 {
3884         int ret = PLAYER_ERROR_NONE;
3885         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3886         player_cli_s *pc = (player_cli_s *)player;
3887         char *ret_buf = NULL;
3888         int frequency;
3889
3890         PLAYER_INSTANCE_CHECK(player);
3891         PLAYER_NULL_ARG_CHECK(pfrequency);
3892
3893         LOGD("ENTER");
3894
3895         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3896         if (ret == PLAYER_ERROR_NONE) {
3897                 player_msg_get(frequency, ret_buf);
3898                 *pfrequency = frequency;
3899         }
3900         g_free(ret_buf);
3901         return ret;
3902 }
3903
3904 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3905 {
3906         int ret = PLAYER_ERROR_NONE;
3907         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3908         player_cli_s *pc = (player_cli_s *)player;
3909         char *ret_buf = NULL;
3910         int range;
3911
3912         PLAYER_INSTANCE_CHECK(player);
3913         PLAYER_NULL_ARG_CHECK(prange);
3914
3915         LOGD("ENTER");
3916
3917         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3918         if (ret == PLAYER_ERROR_NONE) {
3919                 player_msg_get(range, ret_buf);
3920                 *prange = range;
3921         }
3922         g_free(ret_buf);
3923         return ret;
3924 }
3925
3926 int player_audio_effect_equalizer_clear(player_h player)
3927 {
3928         int ret = PLAYER_ERROR_NONE;
3929         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3930         player_cli_s *pc = (player_cli_s *)player;
3931         char *ret_buf = NULL;
3932
3933         PLAYER_INSTANCE_CHECK(player);
3934
3935         LOGD("ENTER");
3936
3937         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3938         g_free(ret_buf);
3939         return ret;
3940 }
3941
3942 int player_audio_effect_equalizer_is_available(player_h player, bool *pavailable)
3943 {
3944         int ret = PLAYER_ERROR_NONE;
3945         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3946         player_cli_s *pc = (player_cli_s *)player;
3947         char *ret_buf = NULL;
3948         int available;
3949
3950         PLAYER_INSTANCE_CHECK(player);
3951         PLAYER_NULL_ARG_CHECK(pavailable);
3952
3953         LOGD("ENTER");
3954
3955         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3956         if (ret == PLAYER_ERROR_NONE) {
3957                 player_msg_get(available, ret_buf);
3958                 *pavailable = available;
3959         }
3960         g_free(ret_buf);
3961         return ret;
3962 }
3963
3964 int player_set_subtitle_path(player_h player, const char *path)
3965 {
3966         int ret = PLAYER_ERROR_NONE;
3967         muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3968         player_cli_s *pc = (player_cli_s *)player;
3969         char *ret_buf = NULL;
3970         char subtitle_path[MAX_URL_LEN] = {0, };
3971
3972         PLAYER_INSTANCE_CHECK(player);
3973
3974         LOGD("ENTER");
3975
3976         if (path && _player_get_valid_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3977                 return PLAYER_ERROR_INVALID_PARAMETER;
3978
3979         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "subtitle_path", (const char *)subtitle_path);
3980         g_free(ret_buf);
3981         return ret;
3982 }
3983
3984 int player_set_subtitle_position_offset(player_h player, int milliseconds)
3985 {
3986         int ret = PLAYER_ERROR_NONE;
3987         muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3988         player_cli_s *pc = (player_cli_s *)player;
3989         char *ret_buf = NULL;
3990
3991         PLAYER_INSTANCE_CHECK(player);
3992
3993         LOGD("ENTER");
3994
3995         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "milliseconds", milliseconds);
3996
3997         g_free(ret_buf);
3998         return ret;
3999 }
4000
4001 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
4002 {
4003         int ret = PLAYER_ERROR_NONE;
4004         muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
4005         player_cli_s *pc = (player_cli_s *)player;
4006         char *ret_buf = NULL;
4007
4008         PLAYER_INSTANCE_CHECK(player);
4009         PLAYER_NULL_ARG_CHECK(callback);
4010
4011         LOGD("ENTER");
4012         if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
4013                 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
4014                 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
4015         } else {
4016                 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
4017                 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
4018                 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
4019         }
4020
4021         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4022
4023         if (ret != PLAYER_ERROR_NONE)
4024                 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
4025
4026         g_free(ret_buf);
4027         return ret;
4028 }
4029
4030 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
4031 {
4032         int ret = PLAYER_ERROR_NONE;
4033         muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
4034         player_cli_s *pc = (player_cli_s *)player;
4035         char *ret_buf = NULL;
4036
4037         PLAYER_INSTANCE_CHECK(player);
4038         PLAYER_NULL_ARG_CHECK(cookie);
4039         PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4040
4041         LOGD("ENTER");
4042
4043         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4044                                         MUSE_TYPE_STRING, "cookie", cookie,
4045                                         MUSE_TYPE_INT, "size", size);
4046         g_free(ret_buf);
4047         return ret;
4048 }
4049
4050 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
4051 {
4052         int ret = PLAYER_ERROR_NONE;
4053         muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
4054         player_cli_s *pc = (player_cli_s *)player;
4055         char *ret_buf = NULL;
4056
4057         PLAYER_INSTANCE_CHECK(player);
4058         PLAYER_NULL_ARG_CHECK(user_agent);
4059         PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4060
4061         LOGD("ENTER");
4062
4063         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4064                                         MUSE_TYPE_STRING, "user_agent", user_agent,
4065                                         MUSE_TYPE_INT, "size", size);
4066         g_free(ret_buf);
4067         return ret;
4068 }
4069
4070 int player_get_streaming_download_progress(player_h player, int *start, int *end)
4071 {
4072         int ret = PLAYER_ERROR_NONE;
4073         muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
4074         player_cli_s *pc = (player_cli_s *)player;
4075         char *ret_buf = NULL;
4076         int start_pos = 0, end_pos = 0;
4077
4078         PLAYER_INSTANCE_CHECK(player);
4079         PLAYER_NULL_ARG_CHECK(start && end);
4080
4081         LOGD("ENTER");
4082
4083         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4084         if (ret == PLAYER_ERROR_NONE) {
4085                 bool ret_val = true;
4086                 ret_val = _player_get_param_value(ret_buf,
4087                                                                         MUSE_TYPE_INT, "start_pos", (void *)&start_pos,
4088                                                                         MUSE_TYPE_INT, "end_pos", (void *)&end_pos,
4089                                                                         INVALID_MUSE_TYPE_VALUE);
4090                 if (ret_val) {
4091                         *start = start_pos;
4092                         *end = end_pos;
4093                 } else {
4094                         ret = PLAYER_ERROR_INVALID_OPERATION;
4095                 }
4096         }
4097         g_free(ret_buf);
4098         return ret;
4099 }
4100
4101 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
4102 {
4103         return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
4104 }
4105
4106 static void __retrieve_buffer_cb(void *user_data)
4107 {
4108         player_cli_s *player = (player_cli_s *)user_data;
4109         int ret = PLAYER_ERROR_NONE;
4110         bool gapless = false;
4111
4112         ret = player_is_gapless((player_h)player, &gapless);
4113         if (ret != PLAYER_ERROR_NONE) {
4114                 LOGW("player_is_gapless is failed");
4115                 return;
4116         }
4117
4118         ret = mm_display_interface_evas_flush(DP_INTERFACE(player), gapless);
4119
4120         LOGW("flush all packet : 0x%x [gapless %d]", ret, gapless);
4121 }
4122
4123 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
4124 {
4125         return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
4126 }
4127
4128 static int __player_unset_retrieve_buffer_cb(player_h player)
4129 {
4130         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
4131 }
4132
4133 int player_unset_completed_cb(player_h player)
4134 {
4135         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
4136 }
4137
4138 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
4139 {
4140         return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
4141 }
4142
4143 int player_unset_interrupted_cb(player_h player)
4144 {
4145         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
4146 }
4147
4148 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
4149 {
4150         return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
4151 }
4152
4153 int player_unset_error_cb(player_h player)
4154 {
4155         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
4156 }
4157
4158 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
4159 {
4160         return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
4161 }
4162
4163 int player_unset_buffering_cb(player_h player)
4164 {
4165         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
4166 }
4167
4168 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
4169 {
4170         return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
4171 }
4172
4173 int player_unset_subtitle_updated_cb(player_h player)
4174 {
4175         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
4176 }
4177
4178 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
4179 {
4180         return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME, player, callback, user_data);
4181 }
4182
4183 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
4184 {
4185         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME, player);
4186 }
4187
4188 int player_set_media_packet_audio_frame_decoded_cb(player_h player, media_format_h format,
4189                 player_audio_extract_option_e opt, player_media_packet_audio_decoded_cb callback, void *user_data)
4190 {
4191         int ret = PLAYER_ERROR_NONE;
4192         player_cli_s *pc = (player_cli_s *)player;
4193         muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_PACKET_AUDIO_FRAME_DECODED_CB;
4194         char *ret_buf = NULL;
4195         media_format_mimetype_e mimetype = MEDIA_FORMAT_MAX;
4196         int channel = 0;
4197         int samplerate = 0;
4198
4199         PLAYER_INSTANCE_CHECK(player);
4200         PLAYER_NULL_ARG_CHECK(callback);
4201         PLAYER_RANGE_ARG_CHECK(opt, PLAYER_AUDIO_EXTRACT_DEFAULT, PLAYER_AUDIO_EXTRACT_NO_SYNC_AND_DEINTERLEAVE);
4202
4203         LOGD("ENTER");
4204
4205         if (format) {
4206                 media_format_ref(format);
4207                 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE) {
4208                         LOGE("failed to get audio info from media format.");
4209                         media_format_unref(format);
4210                         return PLAYER_ERROR_INVALID_PARAMETER;
4211                 }
4212                 media_format_unref(format);
4213
4214                 if (mimetype < MEDIA_FORMAT_PCM || mimetype > MEDIA_FORMAT_PCM_U32BE) {
4215                         LOGW("Not supported audio format type : 0x%X", mimetype);
4216                         return PLAYER_ERROR_INVALID_PARAMETER;
4217                 }
4218         }
4219
4220         LOGD("pcm spec : 0x%X, %d, %d", mimetype, channel, samplerate);
4221
4222         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4223                                         MUSE_TYPE_INT, "opt", opt,
4224                                         MUSE_TYPE_INT, "mimetype", mimetype,
4225                                         MUSE_TYPE_INT, "channel", channel,
4226                                         MUSE_TYPE_INT, "samplerate", samplerate);
4227
4228         if (ret == PLAYER_ERROR_NONE) {
4229                 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] = callback;
4230                 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] = user_data;
4231                 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME);
4232         }
4233
4234         g_free(ret_buf);
4235         return ret;
4236 }
4237
4238 int player_unset_media_packet_audio_frame_decoded_cb(player_h player)
4239 {
4240         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME, player);
4241 }
4242
4243 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
4244 {
4245         return __set_callback(MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, player, callback, user_data);
4246 }
4247
4248 int player_unset_video_stream_changed_cb(player_h player)
4249 {
4250         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, player);
4251 }
4252
4253 int player_set_media_stream_buffer_status_cb(player_h player,
4254                 player_stream_type_e stream_type, player_media_stream_buffer_status_cb callback, void *user_data)
4255 {
4256         muse_player_event_e type;
4257
4258         PLAYER_INSTANCE_CHECK(player);
4259         PLAYER_NULL_ARG_CHECK(callback);
4260
4261         LOGD("ENTER");
4262
4263         if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4264                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4265         } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4266                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4267         } else {
4268                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4269                 return PLAYER_ERROR_INVALID_PARAMETER;
4270         }
4271
4272         return __set_callback(type, player, callback, user_data);
4273 }
4274
4275 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
4276 {
4277         muse_player_event_e type;
4278
4279         PLAYER_INSTANCE_CHECK(player);
4280
4281         LOGD("ENTER");
4282
4283         if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4284                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4285         } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4286                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4287         } else {
4288                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4289                 return PLAYER_ERROR_INVALID_PARAMETER;
4290         }
4291
4292         return __unset_callback(type, player);
4293 }
4294
4295 int player_set_media_stream_seek_cb(player_h player,
4296                 player_stream_type_e stream_type, player_media_stream_seek_cb callback, void *user_data)
4297 {
4298         muse_player_event_e type;
4299
4300         PLAYER_INSTANCE_CHECK(player);
4301         PLAYER_NULL_ARG_CHECK(callback);
4302
4303         LOGD("ENTER");
4304
4305         if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4306                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4307         } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4308                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4309         } else {
4310                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4311                 return PLAYER_ERROR_INVALID_PARAMETER;
4312         }
4313
4314         return __set_callback(type, player, callback, user_data);
4315 }
4316
4317 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
4318 {
4319         muse_player_event_e type;
4320
4321         PLAYER_INSTANCE_CHECK(player);
4322
4323         LOGD("ENTER");
4324
4325         if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4326                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4327         } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4328                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4329         } else {
4330                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4331                 return PLAYER_ERROR_INVALID_PARAMETER;
4332         }
4333
4334         return __unset_callback(type, player);
4335 }
4336
4337 /* TODO Implement raw data socket channel */
4338 int player_push_media_stream(player_h player, media_packet_h packet)
4339 {
4340         int ret = PLAYER_ERROR_NONE;
4341         int packet_ret = MEDIA_PACKET_ERROR_NONE;
4342         player_cli_s *pc = (player_cli_s *)player;
4343         muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
4344         char *ret_buf = NULL;
4345         player_push_media_msg_type push_media;
4346         char *push_media_msg = (char *)&push_media;
4347         int msg_size = sizeof(player_push_media_msg_type);
4348         int buf_size = 0;
4349 #ifdef __UN_USED
4350         tbm_bo bo = NULL;
4351         tbm_bo_handle thandle;
4352         tbm_fd tfd = INVALID_DEFAULT_VALUE;
4353 #endif
4354         char *buf;
4355         media_format_h format;
4356         bool is_video;
4357         bool is_audio;
4358         bool is_eos;
4359         int arr_msg_len = 0;
4360         char *codec_data = NULL;
4361         unsigned int codec_data_size = 0;
4362
4363         PLAYER_INSTANCE_CHECK(player);
4364         PLAYER_NULL_ARG_CHECK(packet);
4365
4366         LOGD("ENTER");
4367
4368         if (media_packet_get_buffer_data_ptr(packet, (void **)&buf) != MEDIA_PACKET_ERROR_NONE) {
4369                 LOGE("failed to get buffer data ptr");
4370                 return PLAYER_ERROR_INVALID_OPERATION;
4371         }
4372
4373         if (media_packet_get_buffer_size(packet, &push_media.size) != MEDIA_PACKET_ERROR_NONE) {
4374                 LOGE("failed to get buffer size");
4375                 return PLAYER_ERROR_INVALID_OPERATION;
4376         }
4377
4378         if (media_packet_get_pts(packet, &push_media.pts) != MEDIA_PACKET_ERROR_NONE) {
4379                 LOGE("failed to get buffer pts");
4380                 return PLAYER_ERROR_INVALID_OPERATION;
4381         }
4382
4383         if (media_packet_get_format(packet, &format) != MEDIA_PACKET_ERROR_NONE) {   /* format ref count is increased */
4384                 LOGE("failed to get media format");
4385                 return PLAYER_ERROR_INVALID_OPERATION;
4386         }
4387
4388         packet_ret = media_packet_get_flags(packet, &push_media.flags);
4389         packet_ret |= media_packet_is_video(packet, &is_video);
4390         packet_ret |= media_packet_is_audio(packet, &is_audio);
4391         packet_ret |= media_packet_is_end_of_stream(packet, &is_eos);
4392         if (is_video)
4393                 packet_ret |= media_format_get_video_info(format, &push_media.mimetype,
4394                                                         &push_media.width, &push_media.height, NULL, NULL);
4395         else if (is_audio)
4396                 packet_ret |= media_format_get_audio_info(format, &push_media.mimetype,
4397                                                         &push_media.channels, &push_media.samplerate, NULL, NULL);
4398
4399         media_format_unref(format);
4400
4401         if (packet_ret != MEDIA_PACKET_ERROR_NONE) {
4402                 LOGE("failed to get media packet info");
4403                 return PLAYER_ERROR_INVALID_OPERATION;
4404         }
4405
4406         if (media_packet_get_codec_data(packet, (void **)&codec_data, &codec_data_size) == MEDIA_PACKET_ERROR_NONE) {
4407                 if (codec_data_size > 0 && codec_data_size <= sizeof(push_media.codec_data))
4408                         memcpy(push_media.codec_data, codec_data, codec_data_size);
4409         }
4410
4411         push_media.codec_data_size = codec_data_size;
4412         push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
4413
4414 #ifdef __UN_USED
4415         int arr_buf_len = 0;
4416
4417         if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
4418                 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
4419                 if (bo == NULL) {
4420                         LOGE("TBM get error : bo is NULL");
4421                         return PLAYER_ERROR_INVALID_OPERATION;
4422                 }
4423                 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4424                 if (thandle.ptr == NULL) {
4425                         LOGE("TBM get error : handle pointer is NULL");
4426                         ret = PLAYER_ERROR_INVALID_OPERATION;
4427                         goto ERROR;
4428                 }
4429                 memcpy(thandle.ptr, buf, push_media.size);
4430                 tbm_bo_unmap(bo);
4431
4432                 tfd = tbm_bo_export_fd(bo);
4433                 if (tfd < 0) {
4434                         LOGE("tbm_bo_export_fd err 0x%x", tfd);
4435                         ret = PLAYER_ERROR_INVALID_OPERATION;
4436                         goto ERROR;
4437                 }
4438
4439                 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4440                 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret,
4441                                                                 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4442
4443         } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4444                 buf_size = (int)push_media.size;
4445
4446                 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4447                 arr_buf_len = (buf_size / sizeof(int) + (buf_size % sizeof(int) ? 1 : 0));
4448                 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4449                                                 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg,
4450                                                 MUSE_TYPE_ARRAY, "buf", arr_buf_len, (int *)buf);
4451
4452         } else
4453 #endif
4454         if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4455                 buf_size = (int)push_media.size;
4456                 if ((muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts) < 0) && (!is_eos)) {
4457                         LOGE("failed to send data");
4458                         return PLAYER_ERROR_INVALID_OPERATION;
4459                 }
4460
4461                 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4462                 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4463                                                 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4464         }
4465
4466         LOGD("ret_buf %s", ret_buf);
4467
4468 #ifdef __UN_USED
4469 ERROR:
4470
4471         PLAYER_CLOSE_FD(tfd);
4472
4473         if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4474                 tbm_bo_unref(bo);
4475 #endif
4476
4477         g_free(ret_buf);
4478         return ret;
4479 }
4480
4481 int player_foreach_media_stream_supported_format(player_h player, player_supported_media_format_cb callback, void *user_data)
4482 {
4483         int ret = PLAYER_ERROR_NONE;
4484         player_cli_s *pc = (player_cli_s *)player;
4485         muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_SUPPORTED_FORMAT;
4486         char *ret_buf = NULL;
4487         int format_info[MAX_SUPPORTED_MEDIA_FORMAT] = {0,};
4488         int len = 0, idx = 0;
4489
4490         PLAYER_INSTANCE_CHECK(player);
4491         PLAYER_NULL_ARG_CHECK(callback);
4492
4493         LOGD("ENTER");
4494
4495         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4496
4497         player_msg_get_type(len, ret_buf, INT);
4498         player_msg_get_array(format_info, ret_buf);
4499
4500         LOGD("num of format %d", len);
4501         for (idx = 0 ; idx < len ; idx++) {
4502                 if (!callback(format_info[idx], user_data)) {
4503                         LOGW("stop foreach callback");
4504                         break;
4505                 }
4506         }
4507
4508         LOGD("LEAVE 0x%X", ret);
4509         g_free(ret_buf);
4510         return ret;
4511 }
4512
4513 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4514 {
4515         g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4516         int ret = PLAYER_ERROR_NONE;
4517         player_cli_s *pc = (player_cli_s *)player;
4518         muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4519         char *ret_buf = NULL;
4520         media_format_mimetype_e mimetype;
4521         int width = 0;
4522         int height = 0;
4523         int avg_bps = 0;
4524         int max_bps = 0;
4525         int channel = 0;
4526         int samplerate = 0;
4527         int bit = 0;
4528         int frame_rate = 0;
4529
4530         PLAYER_INSTANCE_CHECK(player);
4531
4532         LOGD("ENTER");
4533
4534         media_format_ref(format);
4535         if (type == PLAYER_STREAM_TYPE_VIDEO) {
4536                 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4537                         media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4538                         LOGE("failed to get video info from format.");
4539                         return PLAYER_ERROR_INVALID_PARAMETER;
4540                 }
4541
4542                 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4543                                                 MUSE_TYPE_INT, "type", type,
4544                                                 MUSE_TYPE_INT, "mimetype", mimetype,
4545                                                 MUSE_TYPE_INT, "width", width,
4546                                                 MUSE_TYPE_INT, "height", height,
4547                                                 MUSE_TYPE_INT, "avg_bps", avg_bps,
4548                                                 MUSE_TYPE_INT, "max_bps", max_bps,
4549                                                 MUSE_TYPE_INT, "frame_rate", frame_rate);
4550
4551         } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4552                 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4553                         LOGE("failed to get audio info from format.");
4554                         return PLAYER_ERROR_INVALID_PARAMETER;
4555                 }
4556
4557                 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4558                                                 MUSE_TYPE_INT, "type", type,
4559                                                 MUSE_TYPE_INT, "mimetype", mimetype,
4560                                                 MUSE_TYPE_INT, "channel", channel,
4561                                                 MUSE_TYPE_INT, "samplerate", samplerate,
4562                                                 MUSE_TYPE_INT, "avg_bps", avg_bps,
4563                                                 MUSE_TYPE_INT, "bit", bit);
4564
4565         }
4566         media_format_unref(format);
4567         pc->push_media_stream = TRUE;
4568
4569         g_free(ret_buf);
4570         return ret;
4571 }
4572
4573 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4574 {
4575         int ret = PLAYER_ERROR_NONE;
4576         player_cli_s *pc = (player_cli_s *)player;
4577         muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4578         char *ret_buf = NULL;
4579
4580         PLAYER_INSTANCE_CHECK(player);
4581         PLAYER_RANGE_ARG_CHECK(type, PLAYER_STREAM_TYPE_AUDIO, PLAYER_STREAM_TYPE_VIDEO);
4582         PLAYER_CHECK_CONDITION(max_size > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4583
4584         LOGD("ENTER");
4585
4586         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4587                                         MUSE_TYPE_INT, "type", type,
4588                                         MUSE_TYPE_INT64, "max_size", (INT64)max_size);
4589
4590         g_free(ret_buf);
4591         return ret;
4592 }
4593
4594 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4595 {
4596         int ret = PLAYER_ERROR_NONE;
4597         player_cli_s *pc = (player_cli_s *)player;
4598         muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4599         char *ret_buf = NULL;
4600         unsigned long long max_size;
4601
4602         PLAYER_INSTANCE_CHECK(player);
4603         PLAYER_NULL_ARG_CHECK(pmax_size);
4604         PLAYER_RANGE_ARG_CHECK(type, PLAYER_STREAM_TYPE_AUDIO, PLAYER_STREAM_TYPE_VIDEO);
4605
4606         LOGD("ENTER");
4607
4608         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4609         if (ret == PLAYER_ERROR_NONE) {
4610                 player_msg_get_type(max_size, ret_buf, INT64);
4611                 *pmax_size = max_size;
4612         }
4613         g_free(ret_buf);
4614         return ret;
4615 }
4616
4617 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4618 {
4619         int ret = PLAYER_ERROR_NONE;
4620         player_cli_s *pc = (player_cli_s *)player;
4621         muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4622         char *ret_buf = NULL;
4623
4624         PLAYER_INSTANCE_CHECK(player);
4625         PLAYER_RANGE_ARG_CHECK(type, PLAYER_STREAM_TYPE_DEFAULT, PLAYER_STREAM_TYPE_TEXT);
4626
4627         LOGD("ENTER");
4628
4629         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4630                                         MUSE_TYPE_INT, "type", type,
4631                                         MUSE_TYPE_INT, "percent", (int)percent);
4632
4633         g_free(ret_buf);
4634         return ret;
4635 }
4636
4637 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4638 {
4639         int ret = PLAYER_ERROR_NONE;
4640         player_cli_s *pc = (player_cli_s *)player;
4641         muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4642         char *ret_buf = NULL;
4643         unsigned int percent;
4644
4645         PLAYER_INSTANCE_CHECK(player);
4646         PLAYER_NULL_ARG_CHECK(ppercent);
4647
4648         LOGD("ENTER");
4649
4650         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4651         if (ret == PLAYER_ERROR_NONE) {
4652                 player_msg_get(percent, ret_buf);
4653                 *ppercent = percent;
4654         }
4655
4656         g_free(ret_buf);
4657         return ret;
4658 }
4659
4660 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4661 {
4662         int ret = PLAYER_ERROR_NONE;
4663         player_cli_s *pc = (player_cli_s *)player;
4664         muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4665         char *ret_buf = NULL;
4666         int count;
4667
4668         PLAYER_INSTANCE_CHECK(player);
4669         PLAYER_NULL_ARG_CHECK(pcount);
4670
4671         LOGD("ENTER");
4672
4673         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4674         if (ret == PLAYER_ERROR_NONE) {
4675                 player_msg_get(count, ret_buf);
4676                 *pcount = count;
4677         }
4678
4679         g_free(ret_buf);
4680         return ret;
4681 }
4682
4683 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4684 {
4685         int ret = PLAYER_ERROR_NONE;
4686         player_cli_s *pc = (player_cli_s *)player;
4687         muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4688         char *ret_buf = NULL;
4689         int index;
4690
4691         PLAYER_INSTANCE_CHECK(player);
4692         PLAYER_NULL_ARG_CHECK(pindex);
4693
4694         LOGD("ENTER");
4695
4696         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4697         if (ret == PLAYER_ERROR_NONE) {
4698                 player_msg_get(index, ret_buf);
4699                 *pindex = index;
4700         }
4701
4702         g_free(ret_buf);
4703         return ret;
4704 }
4705
4706 int player_select_track(player_h player, player_stream_type_e type, int index)
4707 {
4708         int ret = PLAYER_ERROR_NONE;
4709         player_cli_s *pc = (player_cli_s *)player;
4710         muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4711         char *ret_buf = NULL;
4712
4713         PLAYER_INSTANCE_CHECK(player);
4714
4715         LOGD("ENTER");
4716
4717         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4718
4719         g_free(ret_buf);
4720         return ret;
4721 }
4722
4723 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4724 {
4725         int ret = PLAYER_ERROR_NONE;
4726         player_cli_s *pc = (player_cli_s *)player;
4727         muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4728         char *ret_buf = NULL;
4729         char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4730         int code_len = 0;
4731
4732         PLAYER_INSTANCE_CHECK(player);
4733         PLAYER_NULL_ARG_CHECK(pcode);
4734
4735         LOGD("ENTER");
4736
4737         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4738         if (ret == PLAYER_ERROR_NONE) {
4739                 bool recv_ret = true;
4740                 recv_ret = _player_get_param_value(ret_buf,
4741                                                                                 MUSE_TYPE_INT, "code_len", (void *)&code_len,
4742                                                                                 MUSE_TYPE_STRING, "code", (void *)code,
4743                                                                                 INVALID_MUSE_TYPE_VALUE);
4744                 if (recv_ret)
4745                         *pcode = strndup(code, code_len);
4746                 else
4747                         ret = PLAYER_ERROR_INVALID_OPERATION;
4748         }
4749         g_free(ret_buf);
4750         return ret;
4751 }
4752
4753 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4754 {
4755         int ret = PLAYER_ERROR_NONE;
4756         player_cli_s *pc = (player_cli_s *)player;
4757         muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4758         char *ret_buf = NULL;
4759         char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4760         int idx = 0, num = 0;
4761         int bandwidth = 0, width = 0, height = 0;
4762         char *token = NULL;
4763         char *ptr = NULL;
4764
4765         PLAYER_INSTANCE_CHECK(player);
4766         PLAYER_NULL_ARG_CHECK(callback);
4767
4768         LOGD("ENTER");
4769
4770         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4771         if (ret == PLAYER_ERROR_NONE) {
4772                 player_msg_get_type(num, ret_buf, INT);
4773                 if (num > 0)
4774                         player_msg_get_string(var_info, ret_buf);
4775                 else
4776                         LOGW("There is no stream variant info.");
4777         }
4778
4779         for (idx = 0 ; idx < num ; idx++) {
4780                 bandwidth = width = height = 0;
4781
4782                 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4783                 if (!token) break;
4784                 bandwidth = atoi(token);
4785
4786                 token = strtok_r(NULL, ",", &ptr);
4787                 if (!token) break;
4788                 width = atoi(token);
4789
4790                 token = strtok_r(NULL, ",", &ptr);
4791                 if (!token) break;
4792                 height = atoi(token);
4793
4794                 callback(bandwidth, width, height, user_data);
4795         }
4796
4797         LOGD("LEAVE 0x%X", ret);
4798         g_free(ret_buf);
4799         return ret;
4800 }
4801
4802 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4803 {
4804         int ret = PLAYER_ERROR_NONE;
4805         player_cli_s *pc = (player_cli_s *)player;
4806         muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4807         char *ret_buf = NULL;
4808
4809         PLAYER_INSTANCE_CHECK(player);
4810         PLAYER_CHECK_CONDITION(bandwidth >= -1 && width >= -1 && height >= -1,
4811                         PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4812
4813         LOGD("ENTER");
4814
4815         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4816                                         MUSE_TYPE_INT, "bandwidth", bandwidth,
4817                                         MUSE_TYPE_INT, "width", width,
4818                                         MUSE_TYPE_INT, "height", height);
4819         g_free(ret_buf);
4820
4821         LOGD("LEAVE 0x%X", ret);
4822         return ret;
4823
4824 }
4825
4826 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4827 {
4828         int ret = PLAYER_ERROR_NONE;
4829         player_cli_s *pc = (player_cli_s *)player;
4830         muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4831         char *ret_buf = NULL;
4832         int bandwidth = -1, width = -1, height = -1;
4833
4834         PLAYER_INSTANCE_CHECK(player);
4835         PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4836
4837         LOGD("ENTER");
4838
4839         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4840         if (ret == PLAYER_ERROR_NONE) {
4841                 bool ret_val = true;
4842                 ret_val = _player_get_param_value(ret_buf,
4843                                                                                 MUSE_TYPE_INT, "bandwidth", (void *)&bandwidth,
4844                                                                                 MUSE_TYPE_INT, "width", (void *)&width,
4845                                                                                 MUSE_TYPE_INT, "height", (void *)&height,
4846                                                                                 INVALID_MUSE_TYPE_VALUE);
4847                 if (ret_val) {
4848                         if (pbandwidth) *pbandwidth = bandwidth;
4849                         if (pwidth) *pwidth = width;
4850                         if (pheight) *pheight = height;
4851                 } else {
4852                         ret = PLAYER_ERROR_INVALID_OPERATION;
4853                 }
4854         }
4855         g_free(ret_buf);
4856
4857         LOGD("LEAVE 0x%X", ret);
4858         return ret;
4859 }
4860
4861 int player_set_audio_only(player_h player, bool audio_only)
4862 {
4863         int ret = PLAYER_ERROR_NONE;
4864         player_cli_s *pc = (player_cli_s *)player;
4865         muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4866         char *ret_buf = NULL;
4867         player_state_e state = PLAYER_STATE_NONE;
4868
4869         PLAYER_INSTANCE_CHECK(player);
4870
4871         LOGD("ENTER audio_only: %d", audio_only);
4872
4873         /* check player state */
4874         if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
4875                 LOGE("Failed to get state");
4876                 return PLAYER_ERROR_INVALID_OPERATION;
4877         }
4878
4879         if (state < PLAYER_STATE_READY) {
4880                 LOGE("Invalid state %d", state);
4881                 return PLAYER_ERROR_INVALID_STATE;
4882         }
4883
4884         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "audio_only", (int)audio_only);
4885
4886         g_free(ret_buf);
4887
4888         LOGD("LEAVE 0x%X", ret);
4889
4890         return ret;
4891 }
4892
4893 int player_is_audio_only(player_h player, bool *paudio_only)
4894 {
4895         int ret = PLAYER_ERROR_NONE;
4896         muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4897         player_cli_s *pc = (player_cli_s *)player;
4898         char *ret_buf = NULL;
4899         int audio_only = 0;
4900
4901         PLAYER_INSTANCE_CHECK(player);
4902         PLAYER_NULL_ARG_CHECK(paudio_only);
4903
4904         LOGD("ENTER");
4905
4906         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4907
4908         if (ret == PLAYER_ERROR_NONE) {
4909                 player_msg_get(audio_only, ret_buf);
4910                 *paudio_only = (bool)audio_only;
4911         }
4912
4913         g_free(ret_buf);
4914
4915         LOGD("LEAVE 0x%X", ret);
4916
4917         return ret;
4918 }
4919
4920 int player_set_streaming_buffering_time(player_h player, int prebuffer_ms, int rebuffer_ms)
4921 {
4922 #define MIN_BUFFER_TIME -1
4923         int ret = PLAYER_ERROR_NONE;
4924         player_cli_s *pc = (player_cli_s *)player;
4925         muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4926         char *ret_buf = NULL;
4927
4928         PLAYER_INSTANCE_CHECK(player);
4929         PLAYER_CHECK_CONDITION(prebuffer_ms >= MIN_BUFFER_TIME && rebuffer_ms >= MIN_BUFFER_TIME,
4930                         PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4931
4932         LOGD("ENTER");
4933
4934         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4935                                         MUSE_TYPE_INT, "prebuffer_ms", prebuffer_ms,
4936                                         MUSE_TYPE_INT, "rebuffer_ms", rebuffer_ms);
4937         g_free(ret_buf);
4938
4939         LOGD("LEAVE 0x%X", ret);
4940         return ret;
4941 }
4942
4943 int player_get_streaming_buffering_time(player_h player, int *prebuffer_ms, int *rebuffer_ms)
4944 {
4945         int ret = PLAYER_ERROR_NONE;
4946         muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4947         player_cli_s *pc = (player_cli_s *)player;
4948         int prebuffering_time = 0, rebuffering_time = 0;
4949         char *ret_buf = NULL;
4950
4951         PLAYER_INSTANCE_CHECK(player);
4952         PLAYER_NULL_ARG_CHECK(prebuffer_ms || rebuffer_ms);
4953
4954         LOGD("ENTER");
4955
4956         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4957
4958         if (ret == PLAYER_ERROR_NONE) {
4959                 bool ret_val = true;
4960                 ret_val = _player_get_param_value(ret_buf,
4961                                                                                 MUSE_TYPE_INT, "prebuffer_ms", (void *)&prebuffering_time,
4962                                                                                 MUSE_TYPE_INT, "rebuffer_ms", (void *)&rebuffering_time,
4963                                                                                 INVALID_MUSE_TYPE_VALUE);
4964                 if (ret_val) {
4965                         if (prebuffer_ms) *prebuffer_ms = prebuffering_time;
4966                         if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4967                 } else {
4968                         ret = PLAYER_ERROR_INVALID_OPERATION;
4969                 }
4970         }
4971
4972         g_free(ret_buf);
4973
4974         LOGD("LEAVE 0x%X", ret);
4975         return ret;
4976 }
4977
4978 int player_360_is_content_spherical(player_h player, bool *is_spherical)
4979 {
4980         int ret = PLAYER_ERROR_NONE;
4981         muse_player_api_e api = MUSE_PLAYER_API_360_IS_CONTENT_SPHERICAL;
4982         player_cli_s *pc = (player_cli_s *)player;
4983         char *ret_buf = NULL;
4984         int val = 0;
4985
4986         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4987         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4988         PLAYER_INSTANCE_CHECK(player);
4989         PLAYER_NULL_ARG_CHECK(is_spherical);
4990
4991         LOGD("ENTER");
4992
4993         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4994         if (ret == PLAYER_ERROR_NONE) {
4995                 player_msg_get(val, ret_buf);
4996                 *is_spherical = val;
4997         }
4998         g_free(ret_buf);
4999
5000         LOGD("LEAVE 0x%X", ret);
5001         return ret;
5002 }
5003
5004 int player_360_set_enabled(player_h player, bool enabled)
5005 {
5006         int ret = PLAYER_ERROR_NONE;
5007         muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLED;
5008         player_cli_s *pc = (player_cli_s *)player;
5009         char *ret_buf = NULL;
5010         int val = (int)enabled;
5011
5012         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5013         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5014         PLAYER_INSTANCE_CHECK(player);
5015
5016         LOGD("ENTER %d", enabled);
5017
5018         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5019         g_free(ret_buf);
5020
5021         LOGD("LEAVE 0x%X", ret);
5022         return ret;
5023 }
5024
5025 int player_360_is_enabled(player_h player, bool *enabled)
5026 {
5027         int ret = PLAYER_ERROR_NONE;
5028         muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
5029         player_cli_s *pc = (player_cli_s *)player;
5030         char *ret_buf = NULL;
5031         int val = 0;
5032
5033         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5034         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5035         PLAYER_INSTANCE_CHECK(player);
5036         PLAYER_NULL_ARG_CHECK(enabled);
5037
5038         LOGD("ENTER");
5039
5040         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5041         if (ret == PLAYER_ERROR_NONE) {
5042                 player_msg_get(val, ret_buf);
5043                 *enabled = val;
5044         }
5045         g_free(ret_buf);
5046
5047         LOGD("LEAVE 0x%X", ret);
5048         return ret;
5049 }
5050
5051 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
5052 {
5053         int ret = PLAYER_ERROR_NONE;
5054         muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
5055         player_cli_s *pc = (player_cli_s *)player;
5056         char *ret_buf = NULL;
5057
5058         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5059         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5060         PLAYER_INSTANCE_CHECK(player);
5061         PLAYER_RANGE_ARG_CHECK(yaw, (float)-M_PI, (float)M_PI);
5062         PLAYER_RANGE_ARG_CHECK(pitch, ((float)-M_PI / 2), ((float)M_PI / 2));
5063
5064         LOGD("ENTER %f %f", yaw, pitch);
5065
5066         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5067                                         MUSE_TYPE_DOUBLE, "yaw", (double)yaw,
5068                                         MUSE_TYPE_DOUBLE, "pitch", (double)pitch);
5069
5070         g_free(ret_buf);
5071
5072         LOGD("LEAVE 0x%X", ret);
5073         return ret;
5074 }
5075
5076 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
5077 {
5078         int ret = PLAYER_ERROR_NONE;
5079         muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
5080         player_cli_s *pc = (player_cli_s *)player;
5081         double yaw_val = -1;
5082         double pitch_val = -1;
5083         char *ret_buf = NULL;
5084
5085         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5086         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5087         PLAYER_INSTANCE_CHECK(player);
5088         PLAYER_NULL_ARG_CHECK(yaw && pitch);
5089
5090         LOGD("ENTER");
5091
5092         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5093
5094         if (ret == PLAYER_ERROR_NONE) {
5095                 bool ret_val = true;
5096                 ret_val = _player_get_param_value(ret_buf,
5097                                                                                 MUSE_TYPE_DOUBLE, "yaw_val", (void *)&yaw_val,
5098                                                                                 MUSE_TYPE_DOUBLE, "pitch_val", (void *)&pitch_val,
5099                                                                                 INVALID_MUSE_TYPE_VALUE);
5100                 if (ret_val) {
5101                         *yaw = (float)yaw_val;
5102                         *pitch = (float)pitch_val;
5103                 } else {
5104                         LOGE("failed to get value from msg");
5105                         ret = PLAYER_ERROR_INVALID_OPERATION;
5106                 }
5107         }
5108
5109         g_free(ret_buf);
5110
5111         LOGD("LEAVE 0x%X", ret);
5112         return ret;
5113 }
5114
5115 int player_360_set_zoom(player_h player, float level)
5116 {
5117         int ret = PLAYER_ERROR_NONE;
5118         muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
5119         player_cli_s *pc = (player_cli_s *)player;
5120         char *ret_buf = NULL;
5121
5122         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5123         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5124         PLAYER_INSTANCE_CHECK(player);
5125         PLAYER_RANGE_ARG_CHECK(level, 1.0, 10.0);
5126
5127         LOGD("ENTER %f", level);
5128
5129         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "level", (double)level);
5130         g_free(ret_buf);
5131
5132         LOGD("LEAVE 0x%X", ret);
5133         return ret;
5134 }
5135
5136 int player_360_get_zoom(player_h player, float *level)
5137 {
5138         int ret = PLAYER_ERROR_NONE;
5139         muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
5140         player_cli_s *pc = (player_cli_s *)player;
5141         double zoom = -1;
5142         char *ret_buf = NULL;
5143
5144         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5145         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5146         PLAYER_INSTANCE_CHECK(player);
5147         PLAYER_NULL_ARG_CHECK(level);
5148
5149         LOGD("ENTER");
5150
5151         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5152
5153         if (ret == PLAYER_ERROR_NONE) {
5154                 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
5155                         *level = (float)zoom;
5156                 } else {
5157                         LOGE("failed to get value from msg");
5158                         ret = PLAYER_ERROR_INVALID_OPERATION;
5159                 }
5160         }
5161
5162         g_free(ret_buf);
5163
5164         LOGD("LEAVE 0x%X", ret);
5165         return ret;
5166 }
5167
5168 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
5169 {
5170         int ret = PLAYER_ERROR_NONE;
5171         muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
5172         player_cli_s *pc = (player_cli_s *)player;
5173         char *ret_buf = NULL;
5174
5175         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5176         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5177         PLAYER_INSTANCE_CHECK(player);
5178         PLAYER_RANGE_ARG_CHECK(horizontal_degrees, 1, 360);
5179         PLAYER_RANGE_ARG_CHECK(vertical_degrees, 1, 180);
5180
5181         LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
5182
5183         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5184                                         MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5185                                         MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5186         g_free(ret_buf);
5187
5188         LOGD("LEAVE 0x%X", ret);
5189         return ret;
5190 }
5191
5192 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
5193 {
5194         int ret = PLAYER_ERROR_NONE;
5195         muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
5196         player_cli_s *pc = (player_cli_s *)player;
5197         int h_val = -1;
5198         int v_val = -1;
5199         char *ret_buf = NULL;
5200
5201         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5202         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5203         PLAYER_INSTANCE_CHECK(player);
5204         PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
5205
5206         LOGD("ENTER");
5207
5208         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5209
5210         if (ret == PLAYER_ERROR_NONE) {
5211                 bool ret_val = true;
5212                 ret_val = _player_get_param_value(ret_buf,
5213                                                                                 MUSE_TYPE_INT, "h_val", (void *)&h_val,
5214                                                                                 MUSE_TYPE_INT, "v_val", (void *)&v_val,
5215                                                                                 INVALID_MUSE_TYPE_VALUE);
5216                 if (ret_val) {
5217                         *horizontal_degrees = h_val;
5218                         *vertical_degrees = v_val;
5219                 } else {
5220                         LOGE("failed to get value from msg");
5221                         ret = PLAYER_ERROR_INVALID_OPERATION;
5222                 }
5223         }
5224
5225         g_free(ret_buf);
5226
5227         LOGD("LEAVE 0x%X", ret);
5228         return ret;
5229 }
5230
5231 int player_360_set_zoom_with_field_of_view(player_h player, float level, int horizontal_degrees, int vertical_degrees)
5232 {
5233         int ret = PLAYER_ERROR_NONE;
5234         muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM_WITH_FIELD_OF_VIEW;
5235         player_cli_s *pc = (player_cli_s *)player;
5236         char *ret_buf = NULL;
5237
5238         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5239         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5240         PLAYER_INSTANCE_CHECK(player);
5241         PLAYER_RANGE_ARG_CHECK(horizontal_degrees, 1, 360);
5242         PLAYER_RANGE_ARG_CHECK(vertical_degrees, 1, 180);
5243         PLAYER_RANGE_ARG_CHECK(level, 1.0, 10.0);
5244
5245         LOGD("ENTER %f %d %d", level, horizontal_degrees, vertical_degrees);
5246
5247         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5248                                         MUSE_TYPE_DOUBLE, "level", (double)level,
5249                                         MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5250                                         MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5251
5252         g_free(ret_buf);
5253         LOGD("LEAVE 0x%X", ret);
5254         return ret;
5255 }
5256
5257 int player_set_replaygain_enabled(player_h player, bool enabled)
5258 {
5259         int ret = PLAYER_ERROR_NONE;
5260         muse_player_api_e api = MUSE_PLAYER_API_SET_REPLAYGAIN_ENABLED;
5261         player_cli_s *pc = (player_cli_s *)player;
5262         char *ret_buf = NULL;
5263         int val = (int)enabled;
5264
5265         PLAYER_INSTANCE_CHECK(player);
5266
5267         LOGD("ENTER");
5268
5269         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5270         g_free(ret_buf);
5271         return ret;
5272 }
5273
5274 int player_is_replaygain_enabled(player_h player, bool *enabled)
5275 {
5276         int ret = PLAYER_ERROR_NONE;
5277         muse_player_api_e api = MUSE_PLAYER_API_IS_REPLAYGAIN_ENABLED;
5278         player_cli_s *pc = (player_cli_s *)player;
5279         char *ret_buf = NULL;
5280         int val = -1;
5281
5282         PLAYER_INSTANCE_CHECK(player);
5283         PLAYER_NULL_ARG_CHECK(enabled);
5284
5285         LOGD("ENTER");
5286
5287         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5288         if (ret == PLAYER_ERROR_NONE) {
5289                 player_msg_get(val, ret_buf);
5290                 *enabled = (bool)val;
5291         }
5292
5293         g_free(ret_buf);
5294         return ret;
5295 }
5296
5297 int player_audio_pitch_set_enabled(player_h player, bool enabled)
5298 {
5299         int ret = PLAYER_ERROR_NONE;
5300         muse_player_api_e api = MUSE_PLAYER_API_PITCH_SET_ENABLED;
5301         player_cli_s *pc = (player_cli_s *)player;
5302         char *ret_buf = NULL;
5303         int val = (int)enabled;
5304
5305         PLAYER_INSTANCE_CHECK(player);
5306
5307         LOGD("ENTER");
5308
5309         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5310         g_free(ret_buf);
5311         return ret;
5312 }
5313
5314 int player_audio_pitch_is_enabled(player_h player, bool *enabled)
5315 {
5316         int ret = PLAYER_ERROR_NONE;
5317         muse_player_api_e api = MUSE_PLAYER_API_PITCH_IS_ENABLED;
5318         player_cli_s *pc = (player_cli_s *)player;
5319         char *ret_buf = NULL;
5320         int val = -1;
5321
5322         PLAYER_INSTANCE_CHECK(player);
5323         PLAYER_NULL_ARG_CHECK(enabled);
5324
5325         LOGD("ENTER");
5326
5327         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5328         if (ret == PLAYER_ERROR_NONE) {
5329                 player_msg_get(val, ret_buf);
5330                 *enabled = (bool)val;
5331         }
5332
5333         g_free(ret_buf);
5334         return ret;
5335 }
5336
5337 int player_audio_pitch_set_value(player_h player, float value)
5338 {
5339         int ret = PLAYER_ERROR_NONE;
5340         muse_player_api_e api = MUSE_PLAYER_API_PITCH_SET_VALUE;
5341         player_cli_s *pc = (player_cli_s *)player;
5342         char *ret_buf = NULL;
5343
5344         PLAYER_INSTANCE_CHECK(player);
5345         PLAYER_RANGE_ARG_CHECK(value, 0.5, 2.0);
5346
5347         LOGD("ENTER %1.3f", value);
5348
5349         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "pitch", (double)value);
5350         g_free(ret_buf);
5351
5352         LOGD("LEAVE 0x%X", ret);
5353         return ret;
5354 }
5355
5356 int player_audio_pitch_get_value(player_h player, float *value)
5357 {
5358         int ret = PLAYER_ERROR_NONE;
5359         muse_player_api_e api = MUSE_PLAYER_API_PITCH_GET_VALUE;
5360         player_cli_s *pc = (player_cli_s *)player;
5361         double pitch = 0.0;
5362         char *ret_buf = NULL;
5363
5364         PLAYER_INSTANCE_CHECK(player);
5365         PLAYER_NULL_ARG_CHECK(value);
5366
5367         LOGD("ENTER");
5368
5369         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5370
5371         if (ret == PLAYER_ERROR_NONE) {
5372                 if (player_msg_get_type(pitch, ret_buf, DOUBLE)) {
5373                         *value = (float)pitch;
5374                 } else {
5375                         LOGE("failed to get pitch value");
5376                         ret = PLAYER_ERROR_INVALID_OPERATION;
5377                 }
5378         }
5379
5380         g_free(ret_buf);
5381
5382         LOGD("LEAVE 0x%X", ret);
5383         return ret;
5384 }
5385
5386 int player_audio_offload_foreach_supported_format(player_h player, player_supported_media_format_cb callback, void *user_data)
5387 {
5388         int ret = PLAYER_ERROR_NONE;
5389         player_cli_s *pc = (player_cli_s *)player;
5390         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_GET_SUPPORTED_FORMAT;
5391         char *ret_buf = NULL;
5392         int format_info[MAX_SUPPORTED_MEDIA_FORMAT] = {0,};
5393         int len = 0, idx = 0;
5394
5395         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5396         PLAYER_INSTANCE_CHECK(player);
5397         PLAYER_NULL_ARG_CHECK(callback);
5398
5399         LOGD("ENTER");
5400
5401         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5402
5403         player_msg_get_type(len, ret_buf, INT);
5404         player_msg_get_array(format_info, ret_buf);
5405
5406         LOGD("num of format %d", len);
5407         for (idx = 0 ; idx < len ; idx++) {
5408                 if (!callback(format_info[idx], user_data)) {
5409                         LOGW("stop foreach callback");
5410                         break;
5411                 }
5412         }
5413
5414         LOGD("LEAVE 0x%X", ret);
5415         g_free(ret_buf);
5416         return ret;
5417 }
5418
5419 int player_audio_offload_set_enabled(player_h player, bool enabled)
5420 {
5421         int ret = PLAYER_ERROR_NONE;
5422         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_SET_ENABLED;
5423         player_cli_s *pc = (player_cli_s *)player;
5424         char *ret_buf = NULL;
5425         int val = (int)enabled;
5426
5427         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5428         PLAYER_INSTANCE_CHECK(player);
5429
5430         LOGD("ENTER");
5431
5432         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5433         g_free(ret_buf);
5434         return ret;
5435 }
5436
5437 int player_audio_offload_is_enabled(player_h player, bool *enabled)
5438 {
5439         int ret = PLAYER_ERROR_NONE;
5440         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_IS_ENABLED;
5441         player_cli_s *pc = (player_cli_s *)player;
5442         char *ret_buf = NULL;
5443         int val = -1;
5444
5445         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5446         PLAYER_INSTANCE_CHECK(player);
5447         PLAYER_NULL_ARG_CHECK(enabled);
5448
5449         LOGD("ENTER");
5450
5451         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5452         if (ret == PLAYER_ERROR_NONE) {
5453                 player_msg_get(val, ret_buf);
5454                 *enabled = (bool)val;
5455         }
5456
5457         g_free(ret_buf);
5458         return ret;
5459 }
5460
5461 int player_audio_offload_is_activated(player_h player, bool *activated)
5462 {
5463         int ret = PLAYER_ERROR_NONE;
5464         muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_IS_ACTIVATED;
5465         player_cli_s *pc = (player_cli_s *)player;
5466         char *ret_buf = NULL;
5467         int val = -1;
5468
5469         PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5470         PLAYER_INSTANCE_CHECK(player);
5471         PLAYER_NULL_ARG_CHECK(activated);
5472
5473         LOGD("ENTER");
5474
5475         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5476         if (ret == PLAYER_ERROR_NONE) {
5477                 player_msg_get(val, ret_buf);
5478                 *activated = (bool)val;
5479         }
5480
5481         g_free(ret_buf);
5482         return ret;
5483 }
5484
5485 int player_set_audio_codec_type(player_h player, player_codec_type_e codec_type)
5486 {
5487         PLAYER_INSTANCE_CHECK(player);
5488         PLAYER_RANGE_ARG_CHECK(codec_type, PLAYER_CODEC_TYPE_HW, PLAYER_CODEC_TYPE_SW);
5489
5490         int ret = PLAYER_ERROR_NONE;
5491         muse_player_api_e api = MUSE_PLAYER_API_SET_CODEC_TYPE;
5492         player_cli_s *pc = (player_cli_s *)player;
5493         char *ret_buf = NULL;
5494
5495         LOGD("ENTER codec: %d", codec_type);
5496
5497         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5498                         MUSE_TYPE_INT, "stream_type", PLAYER_STREAM_TYPE_AUDIO,
5499                         MUSE_TYPE_INT, "codec_type", codec_type);
5500
5501         g_free(ret_buf);
5502         LOGD("LEAVE");
5503         return ret;
5504
5505 }
5506
5507 int player_get_audio_codec_type(player_h player, player_codec_type_e *codec_type)
5508 {
5509         PLAYER_INSTANCE_CHECK(player);
5510         PLAYER_NULL_ARG_CHECK(codec_type);
5511
5512         int ret = PLAYER_ERROR_NONE;
5513         muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_TYPE;
5514         player_cli_s *pc = (player_cli_s *)player;
5515         char *ret_buf = NULL;
5516         int type = 0;
5517
5518         LOGD("ENTER");
5519
5520         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5521                         MUSE_TYPE_INT, "stream_type", PLAYER_STREAM_TYPE_AUDIO);
5522         if (ret == PLAYER_ERROR_NONE) {
5523                 player_msg_get(type, ret_buf);
5524                 *codec_type = type;
5525         }
5526
5527         g_free(ret_buf);
5528         LOGD("LEAVE codec: %d", *codec_type);
5529         return ret;
5530 }