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