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