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