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