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