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