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