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