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