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