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