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