2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <sys/types.h>
22 #include <tbm_bufmgr.h>
23 #include <tbm_surface.h>
24 #include <tbm_surface_internal.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"
39 #define INVALID_DEFAULT_VALUE -1
40 #define MAX_S_PATH_LEN 32
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,
50 static tizen_profile_t _get_tizen_profile()
53 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
55 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
58 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
59 switch (*profileName) {
62 profile = TIZEN_PROFILE_MOBILE;
66 profile = TIZEN_PROFILE_WEARABLE;
70 profile = TIZEN_PROFILE_TV;
74 profile = TIZEN_PROFILE_IVI;
76 default: // common or unknown ==> ALL ARE COMMON.
77 profile = TIZEN_PROFILE_COMMON;
85 tbm_fd tfd[MUSE_NUM_FD];
91 callback_cb_info_s *cb_info;
92 _player_recv_data *recv_data;
97 intptr_t remote_v_data;
101 } _media_pkt_fin_data;
108 * Internal Implementation
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);
120 static void _player_release_internal_memory(player_cli_s * pc);
122 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
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;
128 char *snd_msg = NULL;
132 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
136 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
137 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
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 */
148 /* LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf); */
149 tbm_surface_destroy(tsurf);
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() */
157 tbm_surface_h tsurf = NULL;
159 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
160 /* LOGD("tsurf set to null %p", tsurf); */
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);
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);
177 LOGE("[fd:%d] fail to send msg.", fin_data->fd);
179 LOGE("[fd:%d] is invalid.", fin_data->fd);
191 static bool _player_check_network_availability(void)
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;
199 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
200 LOGI("wifi status = %d", enabled);
204 LOGE("SYSTEM_INFO_ERROR");
207 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
208 LOGI("telephony status = %d", enabled);
212 LOGE("SYSTEM_INFO_ERROR");
215 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
216 LOGI("ethernet status = %d", enabled);
220 LOGE("SYSTEM_INFO_ERROR");
229 static void *_get_mem(player_cli_s * player, int size)
231 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
233 mem->data = g_new(void, size);
234 mem->next = player->head;
241 static void _del_mem(player_cli_s * player)
244 while (player->head) {
245 mem = player->head->next;
246 g_free(player->head->data);
247 g_free(player->head);
252 static int player_recv_msg(callback_cb_info_s * cb_info, tbm_fd *tfd)
255 msg_buff_s *buff = &cb_info->buff;
257 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
258 recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, tfd);
260 LOGE("failed to recv msg %d", recvLen);
264 /* check the first msg */
265 if (buff->part_of_msg && buff->recvMsg[0] != '{')
267 gchar *tmp = strndup(buff->recvMsg, recvLen);
269 LOGE("failed to copy msg.");
273 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
276 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
277 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
278 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
279 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
280 if (!buff->recvMsg) {
281 LOGE("failed renew buffer.");
286 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
288 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
289 recvLen += strlen(buff->part_of_msg);
291 free(buff->part_of_msg);
292 buff->part_of_msg = NULL;
297 /* check the last msg */
298 if (buff->recvMsg[recvLen-1] != '}') {
299 char *part_pos = strrchr(buff->recvMsg, '}');
300 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
303 buff->part_of_msg = strndup(part_pos+1, part_len);
304 if (!buff->part_of_msg) {
305 LOGE("failed to alloc buffer for part of msg.");
308 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
316 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
318 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
319 cb_info->user_cb[event] = NULL;
320 cb_info->user_data[event] = NULL;
324 /* Notice : have to be called via API to avoid deadlock
325 * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
327 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
332 LOGE("cb_info is NULL, event: %d", event);
336 lock = (g_thread_self() != cb_info->event_queue.thread);
339 g_mutex_lock(&cb_info->event_queue.mutex);
341 if (_player_need_sync_context(event))
342 _player_remove_idle_event(cb_info, event, false);
344 set_null_user_cb(cb_info, event);
347 g_mutex_unlock(&cb_info->event_queue.mutex);
350 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
352 PLAYER_INSTANCE_CHECK(player);
353 PLAYER_NULL_ARG_CHECK(callback);
354 int ret = PLAYER_ERROR_NONE;
355 player_cli_s *pc = (player_cli_s *) player;
356 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
359 if (MUSE_PLAYER_EVENT_TYPE_BUFFERING == type) {
360 if (!_player_check_network_availability())
361 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
364 LOGI("Event type : %d ", type);
365 player_msg_set_callback(api, pc, ret, type, set);
367 if (ret == PLAYER_ERROR_NONE) {
368 pc->cb_info->user_cb[type] = callback;
369 pc->cb_info->user_data[type] = user_data;
374 static int __unset_callback(muse_player_event_e type, player_h player)
376 PLAYER_INSTANCE_CHECK(player);
377 int ret = PLAYER_ERROR_NONE;
378 player_cli_s *pc = (player_cli_s *) player;
379 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
382 LOGI("Event type : %d ", type);
384 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
385 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
387 player_msg_set_callback(api, pc, ret, type, set);
388 ret = PLAYER_ERROR_NONE;
393 static void __prepare_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
395 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
397 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
399 set_null_user_cb(cb_info, ev);
402 static void __complete_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
404 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
405 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
408 #ifdef TIZEN_FEATURE_EVAS_RENDERER
409 static void __retrieve_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
412 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
413 ((player_retrieve_buffer_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
417 static char* _convert_code_to_str(int code)
420 case PLAYER_INTERRUPTED_COMPLETED: /* Deprecated since 3.0 */
421 return "PLAYER_INTERRUPTED_COMPLETED";
422 case PLAYER_INTERRUPTED_BY_MEDIA: /* Deprecated since 3.0 */
423 return "PLAYER_INTERRUPTED_BY_MEDIA";
424 case PLAYER_INTERRUPTED_BY_CALL: /* Deprecated since 3.0 */
425 return "PLAYER_INTERRUPTED_BY_CALL";
426 case PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG: /* Deprecated since 3.0 */
427 return "PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG";
428 case PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT:
429 return "PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT";
430 case PLAYER_INTERRUPTED_BY_ALARM: /* Deprecated since 3.0 */
431 return "PLAYER_INTERRUPTED_BY_ALARM";
432 case PLAYER_INTERRUPTED_BY_EMERGENCY: /* Deprecated since 3.0 */
433 return "PLAYER_INTERRUPTED_BY_EMERGENCY";
434 case PLAYER_INTERRUPTED_BY_NOTIFICATION: /* Deprecated since 3.0 */
435 return "PLAYER_INTERRUPTED_BY_NOTIFICATION";
437 LOGE("Invalid interrupted code %d (Never enter here)", code);
442 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
445 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
447 if (player_msg_get(code, recv_data->buffer)) {
449 if (code >= PLAYER_INTERRUPTED_COMPLETED &&
450 code <= PLAYER_INTERRUPTED_BY_NOTIFICATION &&
451 code != PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT) {
452 LOGW("DEPRECATION WARNING: %s is deprecated and will be removed from next release.", _convert_code_to_str(code));
455 ((player_interrupted_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
459 static void __error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
462 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
464 if (player_msg_get(code, recv_data->buffer)) {
465 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
466 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
467 LOGW("failed to pause, so prepare cb will be released soon");
468 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
471 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
475 static void __disconnected_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
477 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
479 ((player_error_cb) cb_info->user_cb[ev]) (PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
482 static void __buffering_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
485 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
487 if (player_msg_get(percent, recv_data->buffer))
488 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
491 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
494 char text[MUSE_URI_MAX_LENGTH] = { 0, };
495 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
498 player_msg_get1_string(recv_data->buffer, duration, INT, text, ret);
500 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
503 static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
505 unsigned char *data = NULL;
508 unsigned int size = 0;
510 tbm_bo_handle thandle;
511 int key = INVALID_DEFAULT_VALUE;
514 player_msg_get4(recv_data->buffer, width, INT, height, INT, size, INT, key, INT, ret_val);
516 if (recv_data->tfd[0] < 0) {
517 LOGE("There is no valid tbm_fd");
521 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
523 LOGE("TBM get error : bo is NULL");
526 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
527 if (thandle.ptr == NULL) {
528 LOGE("TBM get error : handle pointer is NULL");
531 data = g_new(unsigned char, size);
533 memcpy(data, thandle.ptr, size);
534 ((player_video_captured_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) (data, width, height, size, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE]);
537 LOGE("g_new failure");
543 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
544 close(recv_data->tfd[0]);
545 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
551 if (key > INVALID_DEFAULT_VALUE) {
552 LOGD("send msg to release buffer. key:%d", key);
553 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
556 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
559 static void __seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
561 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
562 #ifdef TIZEN_FEATURE_EVAS_RENDERER
564 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
566 g_mutex_lock(&cb_info->seek_cb_mutex);
567 if (cb_info->user_cb[ev] && cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_NONE) {
568 #ifdef TIZEN_FEATURE_EVAS_RENDERER
569 if (cb_info->evas_info && cb_info->evas_info->support_video) {
570 if (cb_info->evas_info->handle && cb_info->evas_info->visible != EVAS_VISIBLE_FALSE) {
571 dl_handle = dlopen(PATH_DISP_LIB, RTLD_LAZY);
572 if (dl_handle == NULL)
573 LOGW("not support video rendering");
574 PLAYER_DISP_DLSYM(dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
575 int ret = p_disp_set_evas_display_visible(cb_info->evas_info->handle, true);
577 if (ret != MM_ERROR_NONE)
578 LOGW("failed to set visible at evas 0x%x", ret);
580 cb_info->evas_info->visible = EVAS_VISIBLE_TRUE;
584 LOGD("call seek cb");
585 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
586 set_null_user_cb(cb_info, ev);
588 LOGW("ignored. seek cb %p", cb_info->user_cb[ev]);
590 g_mutex_unlock(&cb_info->seek_cb_mutex);
593 static void __player_remove_tsurf_list(player_cli_s * pc)
597 g_mutex_lock(&pc->cb_info->data_mutex);
598 if (pc->cb_info->tsurf_list) {
599 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
601 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
602 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
604 LOGD("%p will be removed", tmp);
607 tbm_surface_destroy(tmp->tsurf);
613 g_list_free(pc->cb_info->tsurf_list);
614 pc->cb_info->tsurf_list = NULL;
616 g_mutex_unlock(&pc->cb_info->data_mutex);
620 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, int height, int width)
624 g_mutex_lock(&cb_info->data_mutex);
625 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
626 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
627 if (tmp && key && (tmp->key[0] == key[0])) {
628 LOGD("found tsurf_data of tbm_key %d", key[0]);
630 /* need to check tsuf info to support DRC */
631 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
632 (tbm_surface_get_width(tmp->tsurf) != width)) {
634 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
635 LOGW("tsurf info is changed. need to create new tsurf.");
636 tbm_surface_destroy(tmp->tsurf);
639 g_mutex_unlock(&cb_info->data_mutex);
643 g_mutex_unlock(&cb_info->data_mutex);
648 g_mutex_unlock(&cb_info->data_mutex);
652 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
654 tbm_bo bo[4] = { NULL, };
655 int key[4] = { INVALID_DEFAULT_VALUE, };
656 tbm_surface_info_s sinfo;
657 char *surface_info = (char *)&sinfo;
658 media_packet_h pkt = NULL;
659 tbm_surface_h tsurf = NULL;
660 player_tsurf_info_t *tsurf_data = NULL;
662 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
663 bool make_pkt_fmt = false;
664 int ret = MEDIA_FORMAT_ERROR_NONE;
665 _media_pkt_fin_data *fin_data = NULL;
669 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
671 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
673 !muse_core_msg_object_get_value("key[0]", jobj, MUSE_TYPE_ANY, &key[0]) ||
674 !muse_core_msg_object_get_value("key[1]", jobj, MUSE_TYPE_ANY, &key[1]) ||
675 !muse_core_msg_object_get_value("key[2]", jobj, MUSE_TYPE_ANY, &key[2]) ||
676 !muse_core_msg_object_get_value("key[3]", jobj, MUSE_TYPE_ANY, &key[3]) ||
677 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
678 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
679 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
680 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
682 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
684 muse_core_msg_object_free(jobj);
687 muse_core_msg_object_free(jobj);
689 LOGD("width %d, height %d", sinfo.width, sinfo.height);
692 LOGE("cb_info is null");
696 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
697 /* send msg to release v_data. */
698 LOGE("_video_decoded_cb is not set");
702 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
703 LOGE("tbm fd is invalid");
707 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
709 for (i = 0; i < MUSE_NUM_FD; i++) {
710 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
714 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
717 tsurf_data = g_new(player_tsurf_info_t, 1);
719 LOGE("failed to alloc tsurf info");
722 memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
724 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
726 LOGE("failed to create tbm surface");
730 memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
731 tsurf_data->tsurf = tsurf;
732 if (cb_info->use_tsurf_pool) {
733 g_mutex_lock(&cb_info->data_mutex);
734 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
735 LOGD("key %d is added to the pool", key[0]);
736 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
737 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
738 g_mutex_unlock(&cb_info->data_mutex);
741 if (tsurf_data->tsurf) {
742 tsurf = tsurf_data->tsurf;
744 LOGE("tsurf_data->tsurf is null (never enter here)");
749 /* check media packet format */
750 if (cb_info->pkt_fmt) {
751 int pkt_fmt_width = 0;
752 int pkt_fmt_height = 0;
753 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
755 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
756 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
757 LOGW("different format. current 0x%x, %dx%d, new 0x%x, %dx%d", pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height, mimetype, sinfo.width, sinfo.height);
758 media_format_unref(cb_info->pkt_fmt);
759 cb_info->pkt_fmt = NULL;
765 /* create packet format */
767 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
768 ret = media_format_create(&cb_info->pkt_fmt);
769 if (ret == MEDIA_FORMAT_ERROR_NONE) {
770 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
771 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
772 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
773 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
775 LOGE("media_format_create failed");
779 fin_data = g_new0(_media_pkt_fin_data, 1);
781 LOGE("failed to alloc fin_data");
784 fin_data->remote_v_data = v_data;
785 fin_data->fd = cb_info->fd;
786 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
788 /* Keep the fd id to check validation when the pkt is destroyed. */
789 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
791 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
792 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
793 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
798 ret = media_packet_set_pts(pkt, (uint64_t) pts);
799 if (ret != MEDIA_PACKET_ERROR_NONE)
800 LOGE("media_packet_set_pts failed");
802 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
803 /* call media packet callback */
804 ((player_media_packet_video_decoded_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) (pkt, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]);
806 LOGE("_video_decoded_cb is not set");
807 media_packet_destroy(pkt);
810 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
811 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
812 close(recv_data->tfd[i]);
815 for (i = 0; i < bo_num; i++) {
820 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
825 media_packet_destroy(pkt);
830 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
831 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
832 close(recv_data->tfd[i]);
835 for (i = 0; i < bo_num; i++) {
839 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
841 if (cb_info && v_data)
842 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, POINTER, v_data);
847 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
850 tbm_bo_handle thandle;
851 int key = INVALID_DEFAULT_VALUE;
852 player_audio_raw_data_s audio;
854 if (!player_msg_get(key, recv_data->buffer)) {
855 LOGE("failed to get key value from msg.");
859 if (recv_data->tfd[0] < 0) {
860 LOGE("failed to get tbm_fd(key:%d)", key);
864 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
866 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
870 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
871 if (thandle.ptr == NULL) {
872 LOGE("TBM get error : handle pointer is NULL");
876 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
877 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
879 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
880 ((player_audio_pcm_extraction_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME]) (&audio, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME]);
884 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
885 close(recv_data->tfd[0]);
886 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
892 if (key > INVALID_DEFAULT_VALUE) {
893 /* LOGD("send msg to release buffer. key:%d", key); */
894 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
898 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
902 static void __pd_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
905 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
907 if (player_msg_get(type, recv_data->buffer))
908 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
911 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
915 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
919 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
923 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
925 /* player_media_stream_buffer_status_e status; */
928 if (player_msg_get(status, recv_data->buffer)) {
929 ((player_media_stream_buffer_status_cb)
930 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]) ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]);
934 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
936 /* player_media_stream_buffer_status_e status; */
939 if (player_msg_get(status, recv_data->buffer)) {
940 ((player_media_stream_buffer_status_cb)
941 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
942 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
947 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
949 /* player_media_stream_buffer_status_e status; */
951 unsigned long long bytes;
954 player_msg_get2(recv_data->buffer, status, INT, bytes, INT64, ret);
956 ((player_media_stream_buffer_status_cb_ex)
957 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
958 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
962 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
964 /* player_media_stream_buffer_status_e status; */
966 unsigned long long bytes;
969 player_msg_get2(recv_data->buffer, status, INT, bytes, INT64, ret);
971 ((player_media_stream_buffer_status_cb_ex)
972 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
973 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
978 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
980 unsigned long long offset;
982 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
983 ((player_media_stream_seek_cb)
984 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
985 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
989 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
991 unsigned long long offset;
993 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
994 ((player_media_stream_seek_cb)
995 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
996 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1000 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1006 bool ret_val = TRUE;
1008 player_msg_get4(recv_data->buffer, width, INT, height, INT, fps, INT, bit_rate, INT, ret_val);
1010 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1011 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1015 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, _player_recv_data *recv_data) = {
1016 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1017 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1018 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1019 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1020 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1021 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1022 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1023 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1024 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1025 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
1026 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1027 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
1028 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1029 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1030 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1031 #ifdef _PLAYER_FOR_PRODUCT
1032 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1033 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1035 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1036 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1037 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1038 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1039 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1040 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1041 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1042 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1043 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1044 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1046 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1049 gboolean _player_event_job_function(void *user_data)
1051 _player_cb_data *data = (_player_cb_data *)user_data;
1052 muse_player_event_e ev;
1055 LOGE("data is null");
1059 LOGD("enter ev:%d", data->int_data);
1061 g_mutex_lock(&data->event_mutex);
1062 ev = data->int_data;
1064 if (data->cb_info == NULL) {
1065 /* tried to remove before at _player_remove_idle_event */
1066 LOGW("cb_info is NULL. event %d", data->int_data);
1070 /* remove event from list */
1071 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1072 if (data->cb_info->event_queue.idle_ev_list) {
1073 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1074 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1076 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1078 if (data->cb_info->user_cb[ev])
1079 _user_callbacks[ev] (data->cb_info, data->recv_data);
1081 LOGW("user callback is unset. type : %d", ev);
1084 /* unlock and release event */
1085 g_mutex_unlock(&data->event_mutex);
1086 g_mutex_clear(&data->event_mutex);
1088 if (data->recv_data) {
1089 g_free(data->recv_data->buffer);
1090 g_free(data->recv_data);
1094 return FALSE; /* remove from the event list */
1097 static bool _player_need_sync_context(int event_id)
1099 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1100 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1101 (event_id == MUSE_PLAYER_EVENT_TYPE_PD) ||
1102 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1103 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1104 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1105 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1106 LOGD("%d callback will be issued in the mainloop.", event_id);
1113 static void *_player_event_queue_loop(void *param)
1116 LOGE("NULL parameter");
1119 callback_cb_info_s *cb_info = param;
1120 player_event_queue *ev = &cb_info->event_queue;
1121 _player_cb_data *event_data = NULL;
1123 g_mutex_lock(&ev->mutex);
1124 while (ev->running) {
1125 g_mutex_lock(&ev->qlock);
1126 if (g_queue_is_empty(ev->queue)) {
1127 g_mutex_unlock(&ev->qlock);
1128 g_cond_wait(&ev->cond, &ev->mutex);
1132 g_mutex_unlock(&ev->qlock);
1135 g_mutex_lock(&ev->qlock);
1136 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1137 g_mutex_unlock(&ev->qlock);
1139 muse_player_event_e event_type = ((_player_cb_data *)event_data)->int_data;
1141 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1142 g_mutex_lock(&cb_info->seek_cb_mutex);
1143 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1144 /* push event into queue again. */
1145 _player_event_queue_add(ev, event_data);
1146 g_mutex_unlock(&cb_info->seek_cb_mutex);
1149 g_mutex_unlock(&cb_info->seek_cb_mutex);
1152 if (_player_need_sync_context(event_data->int_data)) {
1153 if (cb_info->user_cb[event_data->int_data] &&
1154 _user_callbacks[event_data->int_data]) {
1155 g_mutex_lock(&ev->idle_ev_mutex);
1156 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1157 g_mutex_unlock(&ev->idle_ev_mutex);
1159 LOGD("add ev %d to main loop", event_data->int_data);
1161 g_idle_add_full(G_PRIORITY_DEFAULT,
1162 (GSourceFunc)_player_event_job_function,
1163 (gpointer)event_data,
1166 LOGW("there is no registered cb for ev:%d", event_data->int_data);
1167 if (event_data->recv_data) {
1168 g_free(event_data->recv_data->buffer);
1169 g_free(event_data->recv_data);
1174 _player_event_job_function(event_data);
1181 g_mutex_unlock(&ev->mutex);
1182 LOGI("Exit event loop");
1186 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1188 g_return_val_if_fail(cb_info, FALSE);
1189 player_event_queue *ev = &cb_info->event_queue;
1191 ev->queue = g_queue_new();
1192 g_return_val_if_fail(ev->queue, FALSE);
1193 g_mutex_init(&ev->qlock);
1195 g_mutex_init(&ev->mutex);
1196 g_cond_init(&ev->cond);
1199 g_mutex_init(&ev->idle_ev_mutex);
1201 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1202 g_return_val_if_fail(ev->thread, FALSE);
1203 LOGI("event queue thread %p", ev->thread);
1209 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1211 g_return_if_fail(cb_info);
1212 player_event_queue *ev = &cb_info->event_queue;
1213 _player_cb_data *event_data = NULL;
1216 g_mutex_lock(&ev->idle_ev_mutex);
1218 if (ev->idle_ev_list == NULL) {
1219 LOGD("No idle event is remained.");
1220 g_mutex_unlock(&ev->idle_ev_mutex);
1224 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1226 list = ev->idle_ev_list;
1228 event_data = list->data;
1229 list = g_list_next(list);
1232 LOGW("Fail to remove idle event. The data is NULL");
1236 if (g_mutex_trylock(&event_data->event_mutex)) {
1238 gboolean ret = FALSE;
1239 if (remove_all || (event_data->int_data == event_type)) {
1241 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1243 ret = g_idle_remove_by_data(event_data);
1245 /* will be handled at _player_event_job_function() as an exception */
1246 event_data->cb_info = NULL;
1247 LOGW("failed to remove, idle callback will be called later");
1250 /* set cb to null */
1251 set_null_user_cb(cb_info, event_data->int_data);
1252 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1254 g_mutex_unlock(&event_data->event_mutex);
1257 g_mutex_clear(&event_data->event_mutex);
1258 if (event_data->recv_data) {
1259 g_free(event_data->recv_data->buffer);
1260 g_free(event_data->recv_data);
1264 LOGD("remove idle event done");
1265 } /* else : will be handled if the cb is called. */
1267 g_mutex_unlock(&event_data->event_mutex);
1270 LOGW("event(%d) lock failed. it's being called...", event_data->int_data);
1273 /* continue: keep checking next event_data */
1277 g_list_free(ev->idle_ev_list);
1278 ev->idle_ev_list = NULL;
1281 g_mutex_unlock(&ev->idle_ev_mutex);
1287 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1289 g_return_if_fail(cb_info);
1290 player_event_queue *ev = &cb_info->event_queue;
1291 _player_cb_data *event_data;
1293 LOGI("event queue thread %p", ev->thread);
1295 g_mutex_lock(&ev->mutex);
1296 ev->running = FALSE;
1297 g_cond_broadcast(&ev->cond);
1298 g_mutex_unlock(&ev->mutex);
1300 g_thread_join(ev->thread);
1303 while (!g_queue_is_empty(ev->queue)) {
1304 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1306 g_free(event_data->recv_data->buffer);
1307 g_free(event_data->recv_data);
1311 g_queue_free(ev->queue);
1312 g_mutex_clear(&ev->qlock);
1313 g_mutex_clear(&ev->mutex);
1314 g_cond_clear(&ev->cond);
1315 g_mutex_clear(&ev->idle_ev_mutex);
1318 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1322 g_mutex_lock(&ev_queue->qlock);
1324 item = g_queue_peek_head_link(ev_queue->queue);
1326 GList *next = item->next;
1327 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1329 if (cb_data && cb_data->int_data == ev) {
1330 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1331 g_free(cb_data->recv_data->buffer);
1332 g_free(cb_data->recv_data);
1335 g_queue_delete_link(ev_queue->queue, item);
1339 g_mutex_unlock(&ev_queue->qlock);
1342 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1345 g_mutex_lock(&ev->qlock);
1346 g_queue_push_tail(ev->queue, (gpointer) data);
1347 g_mutex_unlock(&ev->qlock);
1348 g_cond_signal(&ev->cond);
1352 static bool _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1354 /* LOGD("get event %d", event); */
1356 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1357 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1358 _player_cb_data *data = NULL;
1359 data = g_new(_player_cb_data, 1);
1361 LOGE("fail to alloc mem");
1364 data->int_data = (int)event;
1365 data->cb_info = cb_info;
1366 data->recv_data = recv_data;
1367 g_mutex_init(&data->event_mutex);
1368 _player_event_queue_add(&cb_info->event_queue, data);
1374 LOGE("failed to add event to queue");
1378 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1380 ret_msg_s *msg = NULL;
1381 ret_msg_s *last = cb_info->buff.retMsgHead;
1383 msg = g_new(ret_msg_s, 1);
1386 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1389 cb_info->buff.retMsgHead = msg;
1396 LOGE("g_new failure");
1399 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1401 ret_msg_s *msg = cb_info->buff.retMsgHead;
1402 ret_msg_s *prev = NULL;
1404 if (msg->api == api) {
1406 cb_info->buff.retMsgHead = msg->next;
1408 prev->next = msg->next;
1417 static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
1419 ret_msg_s *msg = cb_info->buff.retMsgHead;
1420 ret_msg_s *prev = NULL;
1424 LOGI("Remove %s", prev->msg);
1431 static void _notify_disconnected(callback_cb_info_s * cb_info)
1433 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1434 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1437 if (_user_callbacks[event]) {
1438 _player_cb_data *data = NULL;
1439 data = g_new(_player_cb_data, 1);
1441 LOGE("fail to alloc mem");
1444 data->int_data = (int)event;
1445 data->cb_info = cb_info;
1446 data->recv_data = NULL;
1447 g_mutex_init(&data->event_mutex);
1448 _player_event_queue_add(&cb_info->event_queue, data);
1452 static void *client_cb_handler(gpointer data)
1458 callback_cb_info_s *cb_info = data;
1459 char *recvMsg = NULL;
1460 muse_core_msg_parse_err_e err;
1461 tbm_fd tfd[MUSE_NUM_FD];
1463 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(tfd));
1464 while (g_atomic_int_get(&cb_info->running)) {
1466 err = MUSE_MSG_PARSE_ERROR_NONE;
1468 len = player_recv_msg(cb_info, tfd);
1472 recvMsg = cb_info->buff.recvMsg;
1473 recvMsg[len] = '\0';
1477 while (offset < len) {
1478 api = MUSE_PLAYER_API_MAX;
1479 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1482 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1484 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1485 if (api < MUSE_PLAYER_API_MAX) {
1486 g_mutex_lock(&cb_info->player_mutex);
1487 cb_info->buff.recved++;
1488 _add_ret_msg(api, cb_info, offset, parse_len);
1489 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1490 LOGD("get tbm fd for album art.");
1491 cb_info->tfd = tfd[0];
1493 g_cond_signal(&cb_info->player_cond[api]);
1494 g_mutex_unlock(&cb_info->player_mutex);
1495 if (api == MUSE_PLAYER_API_DESTROY)
1496 g_atomic_int_set(&cb_info->running, 0);
1497 } else if (api == MUSE_PLAYER_CB_EVENT) {
1499 _player_recv_data *recv_data = NULL;
1500 g_mutex_lock(&cb_info->player_mutex);
1501 recv_data = g_new0(_player_recv_data, 1);
1502 if (recv_data != NULL) {
1503 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1504 recv_data->buffer = strndup(recvMsg+offset, parse_len);
1506 LOGE("failed to alloc recv_data.");
1507 g_mutex_unlock(&cb_info->player_mutex);
1508 muse_core_msg_object_free(jobj);
1511 g_mutex_unlock(&cb_info->player_mutex);
1512 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1513 !_user_callback_handler(cb_info, event, recv_data)) {
1514 LOGE("failed to get value or add event to the queue.");
1516 g_free(recv_data->buffer);
1520 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1521 g_mutex_lock(&cb_info->player_mutex);
1522 cb_info->buff.recved++;
1523 g_cond_signal(&cb_info->server_ack_cond);
1524 g_mutex_unlock(&cb_info->player_mutex);
1527 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1529 muse_core_msg_object_free(jobj);
1531 LOGE("Failed to get msg obj. err:%d", err);
1534 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1537 offset += parse_len;
1538 parse_len = len - offset;
1541 if (g_atomic_int_get(&cb_info->running))
1542 _notify_disconnected(cb_info);
1543 LOGD("client cb exit");
1548 static callback_cb_info_s *callback_new(gint sockfd)
1550 callback_cb_info_s *cb_info;
1554 g_return_val_if_fail(sockfd > 0, NULL);
1556 cb_info = g_new(callback_cb_info_s, 1);
1559 memset(cb_info, 0, sizeof(callback_cb_info_s));
1561 g_mutex_init(&cb_info->player_mutex);
1562 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1563 g_cond_init(&cb_info->player_cond[i]);
1564 g_cond_init(&cb_info->server_ack_cond);
1566 g_mutex_init(&cb_info->data_mutex);
1567 g_mutex_init(&cb_info->seek_cb_mutex);
1569 buff = &cb_info->buff;
1570 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1571 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1573 buff->retMsgHead = NULL;
1574 buff->part_of_msg = NULL;
1576 g_atomic_int_set(&cb_info->running, 1);
1577 cb_info->fd = sockfd;
1578 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1579 cb_info->tfd = INVALID_DEFAULT_VALUE;
1584 static void callback_destroy(callback_cb_info_s * cb_info)
1587 g_return_if_fail(cb_info);
1589 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1590 muse_client_close(cb_info->fd);
1591 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1592 muse_client_close(cb_info->data_fd);
1594 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1596 g_thread_join(cb_info->thread);
1597 cb_info->thread = NULL;
1599 LOGI("%p Callback destroyed", cb_info);
1601 g_mutex_clear(&cb_info->player_mutex);
1602 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1603 g_cond_clear(&cb_info->player_cond[i]);
1604 g_cond_clear(&cb_info->server_ack_cond);
1606 g_mutex_clear(&cb_info->data_mutex);
1607 g_mutex_clear(&cb_info->seek_cb_mutex);
1609 g_free(cb_info->buff.recvMsg);
1610 _remove_all_ret_msg(cb_info);
1611 if (cb_info->buff.part_of_msg)
1612 g_free(cb_info->buff.part_of_msg);
1616 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1621 case MUSE_PLAYER_API_PREPARE:
1622 case MUSE_PLAYER_API_PREPARE_ASYNC:
1623 case MUSE_PLAYER_API_UNPREPARE:
1624 case MUSE_PLAYER_API_START:
1625 case MUSE_PLAYER_API_STOP:
1626 case MUSE_PLAYER_API_PAUSE:
1627 timeout += SERVER_TIMEOUT(pc);
1630 /* check prepare async is done */
1631 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1632 timeout += SERVER_TIMEOUT(pc);
1635 timeout += CALLBACK_TIME_OUT;
1636 return timeout; /* ms */
1639 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1641 int ret = PLAYER_ERROR_NONE;
1642 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1643 msg_buff_s *buff = &cb_info->buff;
1644 ret_msg_s *msg = NULL;
1646 g_mutex_lock(&cb_info->player_mutex);
1648 msg = _get_ret_msg(api, cb_info);
1650 if (!buff->recved || !msg) {
1651 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1652 LOGW("api %d return msg does not received %dms", api, time_out);
1653 ret = PLAYER_ERROR_INVALID_OPERATION;
1658 msg = _get_ret_msg(api, cb_info);
1660 *ret_buf = msg->msg;
1663 if (!player_msg_get(ret, *ret_buf))
1664 ret = PLAYER_ERROR_INVALID_OPERATION;
1666 LOGE("api %d is the spurious wakeup", api);
1670 g_mutex_unlock(&cb_info->player_mutex);
1674 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1676 int ret = PLAYER_ERROR_NONE;
1677 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1678 msg_buff_s *buff = &cb_info->buff;
1680 g_mutex_lock(&cb_info->player_mutex);
1682 if (!buff->recved) {
1683 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1684 LOGW("server ack msg does not received %dms", time_out);
1686 ret = PLAYER_ERROR_INVALID_OPERATION;
1688 LOGD("Another msg is received, continue create handle");
1689 g_mutex_unlock(&cb_info->player_mutex);
1695 g_mutex_unlock(&cb_info->player_mutex);
1702 * Public Implementation
1705 int player_create(player_h * player)
1707 PLAYER_INSTANCE_CHECK(player);
1709 int ret = PLAYER_ERROR_NONE;
1710 int sock_fd = INVALID_DEFAULT_VALUE;
1713 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1714 muse_core_api_module_e module = MUSE_PLAYER;
1715 player_cli_s *pc = NULL;
1716 char *ret_buf = NULL;
1717 int retry_count = CONNECTION_RETRY;
1722 pc = g_new0(player_cli_s, 1);
1724 return PLAYER_ERROR_OUT_OF_MEMORY;
1726 while (--retry_count) {
1727 sock_fd = muse_client_new();
1728 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1729 LOGE("connection failure %d", errno);
1730 ret = PLAYER_ERROR_INVALID_OPERATION;
1732 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1736 player_msg_create_handle(api, sock_fd, INT, module, INT, pid);
1738 pc->cb_info = callback_new(sock_fd);
1740 LOGE("fail to create callback");
1741 ret = PLAYER_ERROR_INVALID_OPERATION;
1745 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1746 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1752 if (!_player_event_queue_new(pc->cb_info)) {
1753 LOGE("fail to create event queue");
1754 ret = PLAYER_ERROR_INVALID_OPERATION;
1758 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1759 if (ret == PLAYER_ERROR_NONE) {
1760 intptr_t module_addr = 0;
1761 *player = (player_h) pc;
1762 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1763 pc->cb_info->data_fd = muse_client_new_data_ch();
1764 muse_core_send_module_addr(module_addr, pc->cb_info->data_fd);
1765 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1767 ret = PLAYER_ERROR_INVALID_OPERATION;
1770 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1773 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1774 pc->cb_info->evas_info = g_new0(player_evas_info_s, 1);
1775 if (pc->cb_info->evas_info == NULL) {
1776 ret = PLAYER_ERROR_OUT_OF_MEMORY;
1779 EVAS_INFO(pc)->visible = EVAS_VISIBLE_NONE;
1781 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1782 pc->push_media_stream = FALSE;
1783 pc->support_video = FALSE;
1784 EVAS_INFO(pc)->support_video = FALSE;
1785 pc->is_audio_only = FALSE;
1787 PLAYER_DISP_DLOPEN(pc); /* update supported_video */
1793 if (pc && pc->cb_info) {
1794 if (pc->cb_info->event_queue.running)
1795 _player_event_queue_destroy(pc->cb_info);
1796 callback_destroy(pc->cb_info);
1801 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1810 int player_destroy(player_h player)
1812 PLAYER_INSTANCE_CHECK(player);
1814 int ret = PLAYER_ERROR_NONE;
1815 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1816 player_cli_s *pc = (player_cli_s *) player;
1817 char *ret_buf = NULL;
1818 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1819 int (*p_disp_destroy_evas_display)(void **) = NULL;
1823 /* clear cb and release mem */
1824 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1825 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1826 _player_release_internal_memory(pc);
1828 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1829 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
1830 if (EVAS_HANDLE(pc)) {
1831 player_unset_media_packet_video_frame_decoded_cb(player);
1832 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
1833 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
1834 LOGW("fail to unset evas client");
1835 __player_unset_retrieve_buffer_cb(player);
1836 g_free(pc->cb_info->evas_info);
1840 player_msg_send(api, pc, ret_buf, ret);
1842 if (CALLBACK_INFO(pc)) {
1843 __player_remove_tsurf_list(pc);
1844 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
1845 _player_event_queue_destroy(CALLBACK_INFO(pc));
1846 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
1848 callback_destroy(CALLBACK_INFO(pc));
1852 PLAYER_DISP_DLCLOSE(pc->dl_handle); /* update supported_video */
1859 LOGD("LEAVE 0x%X", ret);
1863 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
1865 PLAYER_INSTANCE_CHECK(player);
1866 int ret = PLAYER_ERROR_NONE;
1867 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
1868 player_cli_s *pc = (player_cli_s *) player;
1869 char *ret_buf = NULL;
1873 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
1874 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
1875 return PLAYER_ERROR_INVALID_OPERATION;
1877 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
1878 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
1880 player_msg_send(api, pc, ret_buf, ret);
1881 if (ret == PLAYER_ERROR_NONE) {
1883 player_msg_get_type(timeout, ret_buf, INT);
1885 LOGD("server timeout will be %d sec", timeout);
1886 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1888 LOGW("failed to realize, so prepare cb will be released soon");
1889 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1890 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1897 int player_prepare(player_h player)
1899 PLAYER_INSTANCE_CHECK(player);
1900 int ret = PLAYER_ERROR_NONE;
1901 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
1902 player_cli_s *pc = (player_cli_s *) player;
1903 char *ret_buf = NULL;
1907 player_msg_send(api, pc, ret_buf, ret);
1908 if (ret == PLAYER_ERROR_NONE) {
1910 player_msg_get_type(timeout, ret_buf, INT);
1912 LOGD("server timeout will be %d sec", timeout);
1913 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1920 int player_unprepare(player_h player)
1922 PLAYER_INSTANCE_CHECK(player);
1923 int ret = PLAYER_ERROR_NONE;
1924 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
1925 player_cli_s *pc = (player_cli_s *) player;
1926 char *ret_buf = NULL;
1930 if (!CALLBACK_INFO(pc))
1931 return PLAYER_ERROR_INVALID_STATE;
1933 player_msg_send(api, pc, ret_buf, ret);
1935 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1936 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1937 _player_release_internal_memory(pc);
1939 pc->cb_info->video_frame_pool_size = 0;
1940 __player_remove_tsurf_list(pc);
1941 pc->is_audio_only = FALSE;
1945 LOGD("LEAVE 0x%X", ret);
1949 /* 1. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx'
1950 * 2. remove 'file://' prefix */
1951 int _player_get_origin_internal_path(const char* uri, char* origin)
1953 gchar *file_path = NULL;
1956 if (!uri || !origin) {
1957 LOGD("invalid parameter");
1958 return PLAYER_ERROR_INVALID_PARAMETER;
1961 if (strstr(uri, "file://")) {
1962 file_path = g_filename_from_uri(uri, NULL, &err);
1964 if (!file_path || (err != NULL)) {
1965 LOGE("Invalid URI '%s', err: %s", uri,
1966 (err != NULL) ? err->message : "unknown error");
1968 if (err) g_error_free(err);
1969 if (file_path) g_free(file_path);
1971 return PLAYER_ERROR_INVALID_PARAMETER;
1973 LOGD("get file path from uri");
1976 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, origin) < 0) {
1977 /* cannot convert path. use the original one. */
1978 strncpy(origin, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
1980 /* need to use converted path. */
1981 LOGD("Converted path : %s -> %s", uri, origin);
1987 return PLAYER_ERROR_NONE;
1990 int player_set_uri(player_h player, const char *uri)
1992 PLAYER_INSTANCE_CHECK(player);
1993 PLAYER_NULL_ARG_CHECK(uri);
1994 int ret = PLAYER_ERROR_NONE;
1995 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
1996 player_cli_s *pc = (player_cli_s *) player;
1997 char *ret_buf = NULL;
1998 char path[MAX_URL_LEN] = {0, };
2002 if (_player_get_origin_internal_path(uri, path) != PLAYER_ERROR_NONE)
2003 return PLAYER_ERROR_INVALID_PARAMETER;
2005 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
2006 pc->push_media_stream = FALSE;
2012 int player_set_memory_buffer(player_h player, const void *data, int size)
2014 PLAYER_INSTANCE_CHECK(player);
2015 PLAYER_NULL_ARG_CHECK(data);
2016 int ret = PLAYER_ERROR_NONE;
2017 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2018 player_cli_s *pc = (player_cli_s *) player;
2019 char *ret_buf = NULL;
2021 tbm_bo_handle thandle;
2022 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2024 if (SERVER_TBM_BO(pc)) {
2025 LOGE("Already set the memory buffer. unprepare please");
2026 return PLAYER_ERROR_INVALID_OPERATION;
2029 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2031 LOGE("TBM get error : bo is NULL");
2032 return PLAYER_ERROR_INVALID_OPERATION;
2034 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2035 if (thandle.ptr == NULL) {
2036 LOGE("TBM get error : handle pointer is NULL");
2037 ret = PLAYER_ERROR_INVALID_OPERATION;
2040 memcpy(thandle.ptr, data, size);
2043 tfd = tbm_bo_export_fd(bo);
2045 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2046 ret = PLAYER_ERROR_INVALID_OPERATION;
2050 player_msg_send1_fd(api, pc, ret_buf, ret, INT, size, tfd);
2051 pc->push_media_stream = FALSE;
2054 if (tfd > INVALID_DEFAULT_VALUE)
2059 if (ret == PLAYER_ERROR_NONE) {
2060 intptr_t bo_addr = 0;
2061 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2062 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2069 static void _player_release_internal_memory(player_cli_s * pc)
2075 _player_deinit_memory_buffer(pc);
2078 static int _player_deinit_memory_buffer(player_cli_s * pc)
2080 PLAYER_INSTANCE_CHECK(pc);
2081 int ret = PLAYER_ERROR_NONE;
2082 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2083 intptr_t bo_addr = SERVER_TBM_BO(pc);
2088 player_msg_send1_async(api, pc, POINTER, bo_addr);
2090 SERVER_TBM_BO(pc) = 0;
2095 int player_get_state(player_h player, player_state_e * pstate)
2097 PLAYER_INSTANCE_CHECK(player);
2098 PLAYER_NULL_ARG_CHECK(pstate);
2099 int ret = PLAYER_ERROR_NONE;
2100 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
2101 player_cli_s *pc = (player_cli_s *) player;
2103 char *ret_buf = NULL;
2107 player_msg_send(api, pc, ret_buf, ret);
2109 if (ret == PLAYER_ERROR_NONE) {
2110 player_msg_get(state, ret_buf);
2118 int player_set_volume(player_h player, float left, float right)
2120 PLAYER_INSTANCE_CHECK(player);
2121 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2122 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2123 int ret = PLAYER_ERROR_NONE;
2124 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2125 player_cli_s *pc = (player_cli_s *) player;
2126 char *ret_buf = NULL;
2130 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, right, DOUBLE, left);
2135 int player_get_volume(player_h player, float *pleft, float *pright)
2137 PLAYER_INSTANCE_CHECK(player);
2138 PLAYER_NULL_ARG_CHECK(pleft && pright);
2139 int ret = PLAYER_ERROR_NONE;
2140 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2141 player_cli_s *pc = (player_cli_s *) player;
2144 char *ret_buf = NULL;
2148 player_msg_send(api, pc, ret_buf, ret);
2150 if (ret == PLAYER_ERROR_NONE) {
2151 bool ret_val = TRUE;
2152 player_msg_get2(ret_buf, left, DOUBLE, right, DOUBLE, ret_val);
2154 *pleft = (float)left;
2155 *pright = (float)right;
2157 LOGE("failed to get value from msg");
2158 ret = PLAYER_ERROR_INVALID_OPERATION;
2166 int player_set_sound_type(player_h player, sound_type_e type)
2168 PLAYER_INSTANCE_CHECK(player);
2169 int ret = PLAYER_ERROR_NONE;
2170 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_TYPE;
2171 player_cli_s *pc = (player_cli_s *) player;
2172 char *ret_buf = NULL;
2175 LOGW("DEPRECATION WARNING: player_set_sound_type() is deprecated and will be removed from next release. Use player_set_sound_stream_info() instead.");
2177 player_msg_send1(api, pc, ret_buf, ret, INT, type);
2182 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2184 PLAYER_INSTANCE_CHECK(player);
2186 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2187 player_cli_s *pc = (player_cli_s *) player;
2188 bool is_available = false;
2189 char *ret_buf = NULL;
2193 /* check if stream_info is valid */
2194 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2195 if (ret != SOUND_MANAGER_ERROR_NONE) {
2196 LOGE("failed to checking available stream info");
2197 return PLAYER_ERROR_INVALID_OPERATION;
2200 if (is_available == false) {
2201 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
2203 char *stream_type = NULL;
2204 int stream_index = 0;
2205 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2206 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2207 if (ret == SOUND_MANAGER_ERROR_NONE)
2208 player_msg_send2(api, pc, ret_buf, ret, STRING, stream_type, INT, stream_index);
2210 ret = PLAYER_ERROR_INVALID_OPERATION;
2213 LOGD("LEAVE ret: 0x%X", ret);
2220 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2222 PLAYER_INSTANCE_CHECK(player);
2223 int ret = PLAYER_ERROR_NONE;
2224 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2225 player_cli_s *pc = (player_cli_s *) player;
2226 char *ret_buf = NULL;
2230 player_msg_send1(api, pc, ret_buf, ret, INT, latency_mode);
2235 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2237 PLAYER_INSTANCE_CHECK(player);
2238 PLAYER_NULL_ARG_CHECK(platency_mode);
2239 int ret = PLAYER_ERROR_NONE;
2240 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2241 player_cli_s *pc = (player_cli_s *) player;
2242 char *ret_buf = NULL;
2243 int latency_mode = -1;
2247 player_msg_send(api, pc, ret_buf, ret);
2249 if (ret == PLAYER_ERROR_NONE) {
2250 player_msg_get(latency_mode, ret_buf);
2251 *platency_mode = latency_mode;
2259 int player_start(player_h player)
2261 PLAYER_INSTANCE_CHECK(player);
2262 int ret = PLAYER_ERROR_NONE;
2263 muse_player_api_e api = MUSE_PLAYER_API_START;
2264 player_cli_s *pc = (player_cli_s *) player;
2265 char *ret_buf = NULL;
2268 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2269 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2271 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2272 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2273 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2274 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2275 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), true);
2276 if (ret != MM_ERROR_NONE) {
2277 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2278 return PLAYER_ERROR_INVALID_OPERATION;
2280 /* avoid setting true at all times, when player is resumed */
2281 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2286 player_msg_send(api, pc, ret_buf, ret);
2292 int player_stop(player_h player)
2294 PLAYER_INSTANCE_CHECK(player);
2295 int ret = PLAYER_ERROR_NONE;
2296 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2297 player_cli_s *pc = (player_cli_s *) player;
2298 char *ret_buf = NULL;
2299 player_state_e state = PLAYER_STATE_NONE;
2300 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2301 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2305 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
2307 /* check player state */
2308 if (ret == PLAYER_ERROR_NONE) {
2309 player_msg_get(state, ret_buf);
2313 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2314 LOGE("Invalid state %d", state);
2315 return PLAYER_ERROR_INVALID_STATE;
2320 return PLAYER_ERROR_INVALID_OPERATION;
2323 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2324 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2325 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2326 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2327 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2328 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), false);
2329 if (ret != MM_ERROR_NONE) {
2330 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2331 return PLAYER_ERROR_INVALID_OPERATION;
2333 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2337 player_msg_send(api, pc, ret_buf, ret);
2338 if (ret == PLAYER_ERROR_NONE)
2339 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2345 int player_pause(player_h player)
2347 PLAYER_INSTANCE_CHECK(player);
2348 int ret = PLAYER_ERROR_NONE;
2349 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2350 player_cli_s *pc = (player_cli_s *) player;
2351 char *ret_buf = NULL;
2355 player_msg_send(api, pc, ret_buf, ret);
2360 int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data)
2362 PLAYER_INSTANCE_CHECK(player);
2363 PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2365 int ret = PLAYER_ERROR_NONE;
2366 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2367 player_cli_s *pc = (player_cli_s *) player;
2368 char *ret_buf = NULL;
2369 int pos = millisecond;
2373 LOGE("cb_info is null");
2374 return PLAYER_ERROR_INVALID_OPERATION;
2377 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2378 if ((pc->push_media_stream == FALSE) &&
2379 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2380 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2381 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2382 return PLAYER_ERROR_SEEK_FAILED;
2384 if (pc->push_media_stream == TRUE)
2385 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2387 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2388 LOGI("Event type : %d, pos : %d, accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond, accurate);
2389 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2390 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2392 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2394 player_msg_send2(api, pc, ret_buf, ret, INT, pos, INT, accurate);
2396 if (ret != PLAYER_ERROR_NONE) {
2397 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2398 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2399 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2402 if (pc->push_media_stream == TRUE)
2403 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2407 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2408 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2409 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2415 int player_get_play_position(player_h player, int *millisecond)
2417 PLAYER_INSTANCE_CHECK(player);
2418 PLAYER_NULL_ARG_CHECK(millisecond);
2420 int ret = PLAYER_ERROR_NONE;
2421 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2422 player_cli_s *pc = (player_cli_s *) player;
2424 char *ret_buf = NULL;
2428 player_msg_send(api, pc, ret_buf, ret);
2430 if (ret == PLAYER_ERROR_NONE) {
2431 player_msg_get(pos, ret_buf);
2439 int player_set_mute(player_h player, bool muted)
2441 PLAYER_INSTANCE_CHECK(player);
2442 int ret = PLAYER_ERROR_NONE;
2443 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2444 player_cli_s *pc = (player_cli_s *) player;
2445 char *ret_buf = NULL;
2446 int mute = (int)muted;
2450 player_msg_send1(api, pc, ret_buf, ret, INT, mute);
2455 int player_is_muted(player_h player, bool * muted)
2457 PLAYER_INSTANCE_CHECK(player);
2458 PLAYER_NULL_ARG_CHECK(muted);
2459 int ret = PLAYER_ERROR_NONE;
2460 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2461 player_cli_s *pc = (player_cli_s *) player;
2462 char *ret_buf = NULL;
2467 player_msg_send(api, pc, ret_buf, ret);
2468 if (ret == PLAYER_ERROR_NONE) {
2469 player_msg_get(mute, ret_buf);
2470 *muted = (bool) mute;
2477 int player_set_looping(player_h player, bool looping)
2479 PLAYER_INSTANCE_CHECK(player);
2480 int ret = PLAYER_ERROR_NONE;
2481 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2482 player_cli_s *pc = (player_cli_s *) player;
2483 char *ret_buf = NULL;
2487 player_msg_send1(api, pc, ret_buf, ret, INT, looping);
2492 int player_is_looping(player_h player, bool * plooping)
2494 PLAYER_INSTANCE_CHECK(player);
2495 PLAYER_NULL_ARG_CHECK(plooping);
2496 int ret = PLAYER_ERROR_NONE;
2497 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2498 player_cli_s *pc = (player_cli_s *) player;
2499 char *ret_buf = NULL;
2504 player_msg_send(api, pc, ret_buf, ret);
2505 if (ret == PLAYER_ERROR_NONE) {
2506 player_msg_get(looping, ret_buf);
2507 *plooping = looping;
2513 int player_get_duration(player_h player, int *pduration)
2515 PLAYER_INSTANCE_CHECK(player);
2516 PLAYER_NULL_ARG_CHECK(pduration);
2517 int ret = PLAYER_ERROR_NONE;
2518 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2519 player_cli_s *pc = (player_cli_s *) player;
2520 char *ret_buf = NULL;
2525 player_msg_send(api, pc, ret_buf, ret);
2526 if (ret == PLAYER_ERROR_NONE) {
2527 player_msg_get(duration, ret_buf);
2528 *pduration = duration;
2535 /* The player_display_type_e is different at wearable profile */
2536 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2538 int ret = PLAYER_ERROR_NONE;
2539 PLAYER_NULL_ARG_CHECK(out_type);
2542 case PLAYER_DISPLAY_TYPE_OVERLAY:
2543 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2545 case PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE:
2546 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2547 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2549 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2551 case PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS:
2552 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2553 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2555 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2557 case PLAYER_DISPLAY_TYPE_EVAS:
2558 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2560 case PLAYER_DISPLAY_TYPE_NONE:
2561 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2564 ret = PLAYER_ERROR_INVALID_PARAMETER;
2568 LOGD("display type(%d) -> (%d)", type, *out_type);
2572 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2574 PLAYER_INSTANCE_CHECK(player);
2575 int ret = PLAYER_ERROR_NONE;
2576 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2577 player_cli_s *pc = (player_cli_s *) player;
2578 char *ret_buf = NULL;
2579 wl_win_msg_type wl_win;
2580 char *wl_win_msg = (char *)&wl_win;
2581 unsigned int wl_surface_id;
2582 player_private_display_type_e conv_type;
2583 player_state_e state = PLAYER_STATE_NONE;
2584 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
2585 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2586 int (*p_disp_destroy_evas_display)(void **) = NULL;
2587 int (*p_disp_create_evas_display)(void *, void **) = NULL;
2588 int (*p_disp_set_evas_display_old_info)(void *, void *, int, int, int) = NULL;
2589 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2590 void (*p_disp_get_evas_display_geometry_info)(void *, int *, int *, int *, int *) = NULL;
2591 void (*p_disp_media_packet_video_decode_cb)(media_packet_h, void *) = NULL;
2595 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2598 wl_win.wl_window_x = 0;
2599 wl_win.wl_window_y = 0;
2600 wl_win.wl_window_width = 0;
2601 wl_win.wl_window_height = 0;
2603 LOGD("ENTER type: %d", type);
2604 if (type == PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE ||
2605 type == PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS) {
2606 LOGW("DEPRECATION WARNING: display type(%d) is deprecated and will be removed from next release. Use newly defined type value instead.", type);
2609 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
2611 /* check player state */
2612 if (ret == PLAYER_ERROR_NONE) {
2613 player_msg_get(state, ret_buf);
2617 if (state > PLAYER_STATE_IDLE) {
2618 LOGE("Invalid state %d", state);
2619 return PLAYER_ERROR_INVALID_STATE;
2624 return PLAYER_ERROR_INVALID_OPERATION;
2627 ret = _player_convert_display_type(type, &conv_type);
2628 if (ret != PLAYER_ERROR_NONE)
2631 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2633 return PLAYER_ERROR_INVALID_PARAMETER;
2635 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2637 * To support repeating play and stop, Evas_handle should not be destroyed in player_unprepare.
2638 * When the display type changes, Player need to destroy Evas_handle to set values of video output,
2639 * Otherwise, the values is not set because of checking Evas_handle.
2641 if (EVAS_HANDLE(pc)) {
2642 LOGW("evas client already exists");
2643 player_unset_media_packet_video_frame_decoded_cb(player);
2644 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2645 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2646 LOGW("fail to unset evas client");
2647 __player_unset_retrieve_buffer_cb(player);
2648 /* need to set display information again to new handle */
2649 EVAS_INFO(pc)->update_needed = TRUE;
2652 /* set evas_render or wayland */
2653 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
2654 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
2655 wl_surface_id = p_disp_set_wl_display(ELM_WAYLAND_WIN, display);
2656 if (wl_surface_id > 0) {
2657 wl_win.wl_surface_id = wl_surface_id;
2658 wl_win.type = conv_type;
2659 } else return PLAYER_ERROR_INVALID_OPERATION;
2661 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2662 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS) {
2663 if (!CALLBACK_INFO(pc)) {
2664 LOGE("there is no cb info in player handle");
2665 return PLAYER_ERROR_INVALID_OPERATION;
2668 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_create_evas_display, "disp_create_evas_display");
2669 ret = p_disp_create_evas_display(display, &EVAS_HANDLE(pc));
2670 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2672 /* before evas handle is created, user could set display information */
2673 if (EVAS_INFO(pc)->update_needed) {
2674 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_old_info, "disp_set_evas_display_old_info");
2675 ret = p_disp_set_evas_display_old_info(display, EVAS_HANDLE(pc), EVAS_INFO(pc)->mode, EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2676 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2677 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2678 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2679 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), EVAS_INFO(pc)->roi_x, EVAS_INFO(pc)->roi_y, EVAS_INFO(pc)->roi_w, EVAS_INFO(pc)->roi_h);
2680 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2682 EVAS_INFO(pc)->update_needed = FALSE;
2684 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_geometry_info, "disp_get_evas_display_geometry_info");
2685 p_disp_get_evas_display_geometry_info(display, &wl_win.wl_window_x, &wl_win.wl_window_y, &wl_win.wl_window_width, &wl_win.wl_window_height);
2686 wl_win.type = conv_type;
2688 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_media_packet_video_decode_cb, "disp_media_packet_video_decode_cb");
2689 ret = player_set_media_packet_video_frame_decoded_cb(player, p_disp_media_packet_video_decode_cb, (void *)EVAS_HANDLE(pc));
2690 if (ret != PLAYER_ERROR_NONE)
2691 LOGW("fail to set decoded callback");
2692 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2693 LOGW("fail to set __retrieve_buffer_cb");
2696 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2697 LOGI("Wayland surface type is NONE");
2698 wl_win.type = conv_type;
2700 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2706 int player_set_display_mode(player_h player, player_display_mode_e mode)
2708 PLAYER_INSTANCE_CHECK(player);
2709 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2710 int ret = PLAYER_ERROR_NONE;
2711 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
2712 player_cli_s *pc = (player_cli_s *) player;
2713 char *ret_buf = NULL;
2714 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2715 int (*p_disp_set_evas_display_disp_mode)(void *, int) = NULL;
2718 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2720 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2721 if (EVAS_HANDLE(pc)) {
2722 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_disp_mode, "disp_set_evas_display_disp_mode");
2723 ret = p_disp_set_evas_display_disp_mode(EVAS_HANDLE(pc), mode);
2724 if (ret != MM_ERROR_NONE)
2725 return PLAYER_ERROR_INVALID_OPERATION;
2727 return PLAYER_ERROR_NONE;
2729 EVAS_INFO(pc)->mode = mode;
2730 EVAS_INFO(pc)->update_needed = TRUE;
2733 player_msg_send1(api, pc, ret_buf, ret, INT, mode);
2738 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
2740 PLAYER_INSTANCE_CHECK(player);
2741 PLAYER_NULL_ARG_CHECK(pmode);
2742 int ret = PLAYER_ERROR_NONE;
2743 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
2744 player_cli_s *pc = (player_cli_s *) player;
2745 char *ret_buf = NULL;
2747 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2748 int (*p_disp_get_evas_display_disp_mode)(void *, int *) = NULL;
2752 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2754 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2755 if (EVAS_HANDLE(pc)) {
2756 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_disp_mode, "disp_get_evas_display_disp_mode");
2757 ret = p_disp_get_evas_display_disp_mode(EVAS_HANDLE(pc), &mode);
2758 *pmode = (player_display_mode_e) mode;
2759 if (ret != MM_ERROR_NONE)
2760 return PLAYER_ERROR_INVALID_OPERATION;
2762 return PLAYER_ERROR_NONE;
2765 player_msg_send(api, pc, ret_buf, ret);
2766 if (ret == PLAYER_ERROR_NONE) {
2767 player_msg_get_type(mode, ret_buf, INT);
2776 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
2778 PLAYER_INSTANCE_CHECK(player);
2779 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2781 int ret = PLAYER_ERROR_NONE;
2782 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
2783 player_cli_s *pc = (player_cli_s *) player;
2784 char *ret_buf = NULL;
2785 wl_win_msg_type wl_win;
2786 char *wl_win_msg = (char *)&wl_win;
2787 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2788 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2792 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2794 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2795 if (EVAS_HANDLE(pc)) {
2796 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2797 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), x, y, width, height);
2798 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
2799 return PLAYER_ERROR_INVALID_PARAMETER;
2800 else if (ret != MM_ERROR_NONE)
2801 return PLAYER_ERROR_INVALID_OPERATION;
2803 return PLAYER_ERROR_NONE;
2805 EVAS_INFO(pc)->roi_x = x;
2806 EVAS_INFO(pc)->roi_y = y;
2807 EVAS_INFO(pc)->roi_w = width;
2808 EVAS_INFO(pc)->roi_h = height;
2809 EVAS_INFO(pc)->update_needed = TRUE;
2812 wl_win.wl_window_x = x;
2813 wl_win.wl_window_y = y;
2814 wl_win.wl_window_width = width;
2815 wl_win.wl_window_height = height;
2817 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2822 int player_set_playback_rate(player_h player, float rate)
2824 PLAYER_INSTANCE_CHECK(player);
2825 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2826 int ret = PLAYER_ERROR_NONE;
2827 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
2828 player_cli_s *pc = (player_cli_s *) player;
2829 char *ret_buf = NULL;
2833 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
2838 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
2840 PLAYER_INSTANCE_CHECK(player);
2841 int ret = PLAYER_ERROR_NONE;
2842 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
2843 player_cli_s *pc = (player_cli_s *) player;
2844 char *ret_buf = NULL;
2845 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2846 int (*p_disp_set_evas_display_rotation)(void *, int) = NULL;
2850 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2852 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2853 if (EVAS_HANDLE(pc)) {
2854 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_rotation, "disp_set_evas_display_rotation");
2855 ret = p_disp_set_evas_display_rotation(EVAS_HANDLE(pc), rotation);
2856 if (ret != MM_ERROR_NONE)
2857 return PLAYER_ERROR_INVALID_OPERATION;
2859 return PLAYER_ERROR_NONE;
2861 EVAS_INFO(pc)->rotation = rotation;
2862 EVAS_INFO(pc)->update_needed = TRUE;
2865 player_msg_send1(api, pc, ret_buf, ret, INT, rotation);
2870 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
2872 PLAYER_INSTANCE_CHECK(player);
2873 PLAYER_NULL_ARG_CHECK(protation);
2874 int ret = PLAYER_ERROR_NONE;
2875 player_cli_s *pc = (player_cli_s *) player;
2876 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
2877 char *ret_buf = NULL;
2879 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2880 int (*p_disp_get_evas_display_rotation)(void *, int *) = NULL;
2884 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2886 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2887 if (EVAS_HANDLE(pc)) {
2888 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_rotation, "disp_get_evas_display_rotation");
2889 ret = p_disp_get_evas_display_rotation(EVAS_HANDLE(pc), &rotation);
2890 *protation = (player_display_rotation_e) rotation;
2891 if (ret != MM_ERROR_NONE)
2892 return PLAYER_ERROR_INVALID_OPERATION;
2894 return PLAYER_ERROR_NONE;
2897 player_msg_send(api, pc, ret_buf, ret);
2898 if (ret == PLAYER_ERROR_NONE) {
2899 player_msg_get_type(rotation, ret_buf, INT);
2900 *protation = rotation;
2907 int player_set_display_visible(player_h player, bool visible)
2909 PLAYER_INSTANCE_CHECK(player);
2910 int ret = PLAYER_ERROR_NONE;
2911 player_cli_s *pc = (player_cli_s *) player;
2912 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
2913 char *ret_buf = NULL;
2914 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2915 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2919 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2921 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2922 if (EVAS_HANDLE(pc)) {
2923 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2924 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), visible);
2925 if (ret != MM_ERROR_NONE)
2926 return PLAYER_ERROR_INVALID_OPERATION;
2928 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
2929 return PLAYER_ERROR_NONE;
2931 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
2932 EVAS_INFO(pc)->update_needed = TRUE;
2936 player_msg_send1(api, pc, ret_buf, ret, INT, visible);
2941 int player_is_display_visible(player_h player, bool * pvisible)
2943 PLAYER_INSTANCE_CHECK(player);
2944 PLAYER_NULL_ARG_CHECK(pvisible);
2945 int ret = PLAYER_ERROR_NONE;
2946 player_cli_s *pc = (player_cli_s *) player;
2947 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
2948 char *ret_buf = NULL;
2950 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2952 int (*p_disp_get_evas_display_visible)(void *, bool *) = NULL;
2956 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2958 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2959 if (EVAS_HANDLE(pc)) {
2960 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_visible, "disp_get_evas_display_visible");
2961 ret = p_disp_get_evas_display_visible(EVAS_HANDLE(pc), &visible);
2967 if (ret != MM_ERROR_NONE)
2968 return PLAYER_ERROR_INVALID_OPERATION;
2970 return PLAYER_ERROR_NONE;
2973 player_msg_send(api, pc, ret_buf, ret);
2974 if (ret == PLAYER_ERROR_NONE) {
2975 player_msg_get_type(value, ret_buf, INT);
2987 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
2989 PLAYER_INSTANCE_CHECK(player);
2990 PLAYER_NULL_ARG_CHECK(pvalue);
2991 int ret = PLAYER_ERROR_NONE;
2992 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
2993 player_cli_s *pc = (player_cli_s *) player;
2994 char *ret_buf = NULL;
2995 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
2999 player_msg_send1(api, pc, ret_buf, ret, INT, key);
3000 if (ret == PLAYER_ERROR_NONE) {
3001 player_msg_get_string(value, ret_buf);
3002 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3008 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3010 PLAYER_INSTANCE_CHECK(player);
3011 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3012 int ret = PLAYER_ERROR_NONE;
3013 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3014 player_cli_s *pc = (player_cli_s *) player;
3015 char *ret_buf = NULL;
3016 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3017 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3018 bool ret_val = TRUE;
3022 player_msg_send(api, pc, ret_buf, ret);
3023 if (ret == PLAYER_ERROR_NONE) {
3024 player_msg_get_string2(ret_buf, video_codec, audio_codec, ret_val);
3027 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3029 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3031 ret = PLAYER_ERROR_INVALID_OPERATION;
3038 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3040 PLAYER_INSTANCE_CHECK(player);
3041 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3042 int ret = PLAYER_ERROR_NONE;
3043 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3044 player_cli_s *pc = (player_cli_s *) player;
3045 char *ret_buf = NULL;
3046 int sample_rate = 0;
3052 player_msg_send(api, pc, ret_buf, ret);
3053 if (ret == PLAYER_ERROR_NONE) {
3054 bool ret_val = TRUE;
3055 player_msg_get3(ret_buf, sample_rate, INT, channel, INT, bit_rate, INT, ret_val);
3058 *psample_rate = sample_rate;
3060 *pchannel = channel;
3062 *pbit_rate = bit_rate;
3064 ret = PLAYER_ERROR_INVALID_OPERATION;
3071 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3073 PLAYER_INSTANCE_CHECK(player);
3074 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3075 int ret = PLAYER_ERROR_NONE;
3076 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3077 player_cli_s *pc = (player_cli_s *) player;
3078 char *ret_buf = NULL;
3084 player_msg_send(api, pc, ret_buf, ret);
3085 if (ret == PLAYER_ERROR_NONE) {
3086 bool ret_val = TRUE;
3087 player_msg_get2(ret_buf, fps, INT, bit_rate, INT, ret_val);
3092 *pbit_rate = bit_rate;
3094 ret = PLAYER_ERROR_INVALID_OPERATION;
3101 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3103 PLAYER_INSTANCE_CHECK(player);
3104 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3105 int ret = PLAYER_ERROR_NONE;
3106 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3107 player_cli_s *pc = (player_cli_s *) player;
3108 char *ret_buf = NULL;
3114 player_msg_send(api, pc, ret_buf, ret);
3115 if (ret == PLAYER_ERROR_NONE) {
3116 bool ret_val = TRUE;
3117 player_msg_get2(ret_buf, width, INT, height, INT, ret_val);
3122 ret = PLAYER_ERROR_INVALID_OPERATION;
3129 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3131 PLAYER_INSTANCE_CHECK(player);
3132 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3133 int ret = PLAYER_ERROR_NONE;
3134 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3135 player_cli_s *pc = (player_cli_s *) player;
3136 char *ret_buf = NULL;
3140 tbm_bo_handle thandle;
3141 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3142 int key = INVALID_DEFAULT_VALUE;
3147 player_msg_send(api, pc, ret_buf, ret);
3148 if (ret == PLAYER_ERROR_NONE) {
3149 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3150 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3152 LOGE("failed to get msg obj, err:%d", err);
3153 ret = PLAYER_ERROR_INVALID_OPERATION;
3157 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3158 LOGD("size : %d", size);
3159 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3160 LOGE("failed to get key value");
3161 ret = PLAYER_ERROR_INVALID_OPERATION;
3165 tfd = pc->cb_info->tfd;
3167 LOGE("failed to get tbm fd value");
3168 ret = PLAYER_ERROR_INVALID_OPERATION;
3172 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3174 LOGE("TBM get error : bo is NULL");
3175 ret = PLAYER_ERROR_INVALID_OPERATION;
3178 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3179 if (thandle.ptr == NULL) {
3180 LOGE("TBM get error : handle pointer is NULL");
3181 ret = PLAYER_ERROR_INVALID_OPERATION;
3184 album_art = _get_mem(pc, size);
3186 memcpy(album_art, thandle.ptr, size);
3187 *palbum_art = album_art;
3189 LOGE("g_new failure");
3190 ret = PLAYER_ERROR_INVALID_OPERATION;
3202 muse_core_msg_object_free(jobj);
3207 if (tfd > INVALID_DEFAULT_VALUE)
3210 if (CALLBACK_INFO(pc))
3211 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3217 if (key > INVALID_DEFAULT_VALUE) {
3218 LOGD("send msg to release buffer. key:%d", key);
3219 player_msg_send1_async(MUSE_PLAYER_API_RETURN_BUFFER, pc, INT, key);
3225 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3227 PLAYER_INSTANCE_CHECK(player);
3228 PLAYER_NULL_ARG_CHECK(pcount);
3229 int ret = PLAYER_ERROR_NONE;
3230 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3231 player_cli_s *pc = (player_cli_s *) player;
3232 char *ret_buf = NULL;
3237 player_msg_send(api, pc, ret_buf, ret);
3238 if (ret == PLAYER_ERROR_NONE) {
3239 player_msg_get(count, ret_buf);
3246 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3248 PLAYER_INSTANCE_CHECK(player);
3249 PLAYER_NULL_ARG_CHECK(band_levels);
3250 int ret = PLAYER_ERROR_NONE;
3251 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3252 player_cli_s *pc = (player_cli_s *) player;
3253 char *ret_buf = NULL;
3257 player_msg_send_array(api, pc, ret_buf, ret, band_levels, length, sizeof(int));
3264 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3266 PLAYER_INSTANCE_CHECK(player);
3267 int ret = PLAYER_ERROR_NONE;
3268 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3269 player_cli_s *pc = (player_cli_s *) player;
3270 char *ret_buf = NULL;
3274 player_msg_send2(api, pc, ret_buf, ret, INT, index, INT, level);
3280 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3282 PLAYER_INSTANCE_CHECK(player);
3283 PLAYER_NULL_ARG_CHECK(plevel);
3284 int ret = PLAYER_ERROR_NONE;
3285 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3286 player_cli_s *pc = (player_cli_s *) player;
3287 char *ret_buf = NULL;
3292 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3293 if (ret == PLAYER_ERROR_NONE) {
3294 player_msg_get(level, ret_buf);
3301 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3303 PLAYER_INSTANCE_CHECK(player);
3304 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3305 int ret = PLAYER_ERROR_NONE;
3306 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3307 player_cli_s *pc = (player_cli_s *) player;
3308 char *ret_buf = NULL;
3309 int min = 0, max = 0;
3313 player_msg_send(api, pc, ret_buf, ret);
3314 if (ret == PLAYER_ERROR_NONE) {
3315 bool ret_val = TRUE;
3316 player_msg_get2(ret_buf, min, INT, max, INT, ret_val);
3321 ret = PLAYER_ERROR_INVALID_OPERATION;
3328 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3330 PLAYER_INSTANCE_CHECK(player);
3331 PLAYER_NULL_ARG_CHECK(pfrequency);
3332 int ret = PLAYER_ERROR_NONE;
3333 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3334 player_cli_s *pc = (player_cli_s *) player;
3335 char *ret_buf = NULL;
3340 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3341 if (ret == PLAYER_ERROR_NONE) {
3342 player_msg_get(frequency, ret_buf);
3343 *pfrequency = frequency;
3349 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3351 PLAYER_INSTANCE_CHECK(player);
3352 PLAYER_NULL_ARG_CHECK(prange);
3353 int ret = PLAYER_ERROR_NONE;
3354 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3355 player_cli_s *pc = (player_cli_s *) player;
3356 char *ret_buf = NULL;
3361 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3362 if (ret == PLAYER_ERROR_NONE) {
3363 player_msg_get(range, ret_buf);
3370 int player_audio_effect_equalizer_clear(player_h player)
3372 PLAYER_INSTANCE_CHECK(player);
3373 int ret = PLAYER_ERROR_NONE;
3374 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3375 player_cli_s *pc = (player_cli_s *) player;
3376 char *ret_buf = NULL;
3380 player_msg_send(api, pc, ret_buf, ret);
3385 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3387 PLAYER_INSTANCE_CHECK(player);
3388 PLAYER_NULL_ARG_CHECK(pavailable);
3389 int ret = PLAYER_ERROR_NONE;
3390 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3391 player_cli_s *pc = (player_cli_s *) player;
3392 char *ret_buf = NULL;
3397 player_msg_send(api, pc, ret_buf, ret);
3398 if (ret == PLAYER_ERROR_NONE) {
3399 player_msg_get(available, ret_buf);
3400 *pavailable = available;
3406 int player_set_subtitle_path(player_h player, const char *path)
3408 PLAYER_INSTANCE_CHECK(player);
3409 int ret = PLAYER_ERROR_NONE;
3410 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3411 player_cli_s *pc = (player_cli_s *) player;
3412 char *ret_buf = NULL;
3413 char subtitle_path[MAX_URL_LEN] = {0, };
3417 if (path && _player_get_origin_internal_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3418 return PLAYER_ERROR_INVALID_PARAMETER;
3420 player_msg_send1(api, pc, ret_buf, ret, STRING, subtitle_path);
3425 int player_set_subtitle_position_offset(player_h player, int millisecond)
3427 PLAYER_INSTANCE_CHECK(player);
3428 int ret = PLAYER_ERROR_NONE;
3429 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3430 player_cli_s *pc = (player_cli_s *) player;
3431 char *ret_buf = NULL;
3435 player_msg_send1(api, pc, ret_buf, ret, INT, millisecond);
3441 int player_set_progressive_download_path(player_h player, const char *path)
3443 PLAYER_INSTANCE_CHECK(player);
3444 PLAYER_NULL_ARG_CHECK(path);
3445 int ret = PLAYER_ERROR_NONE;
3446 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
3447 player_cli_s *pc = (player_cli_s *) player;
3448 char *ret_buf = NULL;
3449 char dw_path[MAX_URL_LEN] = {0, };
3452 LOGW("DEPRECATION WARNING: player_set_progressive_download_path() is deprecated and will be removed from next release.");
3454 if (!_player_check_network_availability())
3455 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3457 if (_player_get_origin_internal_path(path, dw_path) != PLAYER_ERROR_NONE)
3458 return PLAYER_ERROR_INVALID_PARAMETER;
3460 player_msg_send1(api, pc, ret_buf, ret, STRING, dw_path);
3465 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
3467 PLAYER_INSTANCE_CHECK(player);
3468 PLAYER_NULL_ARG_CHECK(pcurrent && ptotal_size);
3469 int ret = PLAYER_ERROR_NONE;
3470 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
3471 player_cli_s *pc = (player_cli_s *) player;
3472 char *ret_buf = NULL;
3473 unsigned long current, total_size;
3476 LOGW("DEPRECATION WARNING: player_get_progressive_download_status() is deprecated and will be removed from next release.");
3478 player_msg_send(api, pc, ret_buf, ret);
3479 if (ret == PLAYER_ERROR_NONE) {
3480 bool ret_val = TRUE;
3481 player_msg_get2(ret_buf, current, POINTER, total_size, POINTER, ret_val);
3483 *pcurrent = current;
3484 *ptotal_size = total_size;
3486 ret = PLAYER_ERROR_INVALID_OPERATION;
3494 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3496 PLAYER_INSTANCE_CHECK(player);
3497 PLAYER_NULL_ARG_CHECK(callback);
3498 int ret = PLAYER_ERROR_NONE;
3499 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3500 player_cli_s *pc = (player_cli_s *) player;
3501 char *ret_buf = NULL;
3504 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3505 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3506 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3508 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3509 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3510 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3513 player_msg_send(api, pc, ret_buf, ret);
3515 if (ret != PLAYER_ERROR_NONE)
3516 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3522 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3524 PLAYER_INSTANCE_CHECK(player);
3525 PLAYER_NULL_ARG_CHECK(cookie);
3526 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3527 int ret = PLAYER_ERROR_NONE;
3528 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3529 player_cli_s *pc = (player_cli_s *) player;
3530 char *ret_buf = NULL;
3534 player_msg_send2(api, pc, ret_buf, ret, STRING, cookie, INT, size);
3539 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3541 PLAYER_INSTANCE_CHECK(player);
3542 PLAYER_NULL_ARG_CHECK(user_agent);
3543 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3544 int ret = PLAYER_ERROR_NONE;
3545 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3546 player_cli_s *pc = (player_cli_s *) player;
3547 char *ret_buf = NULL;
3551 player_msg_send2(api, pc, ret_buf, ret, STRING, user_agent, INT, size);
3556 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3558 PLAYER_INSTANCE_CHECK(player);
3559 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3560 int ret = PLAYER_ERROR_NONE;
3561 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3562 player_cli_s *pc = (player_cli_s *) player;
3563 char *ret_buf = NULL;
3564 int start = 0, current = 0;
3568 player_msg_send(api, pc, ret_buf, ret);
3569 if (ret == PLAYER_ERROR_NONE) {
3570 bool ret_val = TRUE;
3571 player_msg_get2(ret_buf, start, INT, current, INT, ret_val);
3574 *pcurrent = current;
3576 ret = PLAYER_ERROR_INVALID_OPERATION;
3584 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3586 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3589 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3590 static void __retrieve_buffer_cb(void *user_data)
3592 player_cli_s *player = (player_cli_s *)user_data;
3593 int ret = PLAYER_ERROR_NONE;
3594 bool gapless = false;
3595 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
3597 ret = player_is_gapless((player_h)user_data, &gapless);
3598 if (ret != PLAYER_ERROR_NONE) {
3599 LOGW("player_is_gapless is failed");
3603 PLAYER_DISP_DLSYM(player->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
3604 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3605 if (ret != PLAYER_ERROR_NONE)
3606 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3609 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3611 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3614 static int __player_unset_retrieve_buffer_cb(player_h player)
3616 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3620 int player_unset_completed_cb(player_h player)
3622 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3625 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3627 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3630 int player_unset_interrupted_cb(player_h player)
3632 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3635 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3637 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3640 int player_unset_error_cb(player_h player)
3642 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3645 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3647 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3650 int player_unset_buffering_cb(player_h player)
3652 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3655 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3657 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3660 int player_unset_subtitle_updated_cb(player_h player)
3662 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3665 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3667 PLAYER_INSTANCE_CHECK(player);
3668 PLAYER_NULL_ARG_CHECK(callback);
3669 int ret = PLAYER_ERROR_NONE;
3670 player_cli_s *pc = (player_cli_s *) player;
3671 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3672 char *ret_buf = NULL;
3673 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3677 LOGW("DEPRECATION WARNING: player_set_progressive_download_message_cb() is deprecated and will be removed from next release.");
3679 if (!_player_check_network_availability())
3680 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3682 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3684 if (ret == PLAYER_ERROR_NONE) {
3685 pc->cb_info->user_cb[type] = callback;
3686 pc->cb_info->user_data[type] = user_data;
3687 LOGI("Event type : %d ", type);
3694 int player_unset_progressive_download_message_cb(player_h player)
3696 PLAYER_INSTANCE_CHECK(player);
3697 int ret = PLAYER_ERROR_NONE;
3698 player_cli_s *pc = (player_cli_s *) player;
3699 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3700 char *ret_buf = NULL;
3701 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3705 LOGW("DEPRECATION WARNING: player_unset_progressive_download_message_cb() is deprecated and will be removed from next release.");
3707 set_null_user_cb_lock(pc->cb_info, type);
3709 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3716 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
3718 PLAYER_INSTANCE_CHECK(player);
3719 PLAYER_NULL_ARG_CHECK(callback);
3720 int ret = PLAYER_ERROR_NONE;
3721 player_cli_s *pc = (player_cli_s *) player;
3722 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3723 char *ret_buf = NULL;
3724 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3729 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3731 if (ret == PLAYER_ERROR_NONE) {
3732 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
3733 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
3734 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
3741 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
3743 PLAYER_INSTANCE_CHECK(player);
3744 int ret = PLAYER_ERROR_NONE;
3745 player_cli_s *pc = (player_cli_s *) player;
3746 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3747 char *ret_buf = NULL;
3748 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3753 set_null_user_cb_lock(pc->cb_info, type);
3755 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3761 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
3763 PLAYER_INSTANCE_CHECK(player);
3764 PLAYER_NULL_ARG_CHECK(callback);
3765 int ret = PLAYER_ERROR_NONE;
3766 player_cli_s *pc = (player_cli_s *) player;
3767 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3768 char *ret_buf = NULL;
3769 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3774 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3776 if (ret == PLAYER_ERROR_NONE) {
3777 pc->cb_info->user_cb[type] = callback;
3778 pc->cb_info->user_data[type] = user_data;
3779 LOGI("Event type : %d ", type);
3786 int player_unset_video_stream_changed_cb(player_h player)
3788 PLAYER_INSTANCE_CHECK(player);
3789 int ret = PLAYER_ERROR_NONE;
3790 player_cli_s *pc = (player_cli_s *) player;
3791 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3792 char *ret_buf = NULL;
3793 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3798 set_null_user_cb_lock(pc->cb_info, type);
3800 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3806 int player_set_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type, player_media_stream_buffer_status_cb callback, void *user_data)
3808 PLAYER_INSTANCE_CHECK(player);
3809 PLAYER_NULL_ARG_CHECK(callback);
3810 int ret = PLAYER_ERROR_NONE;
3811 player_cli_s *pc = (player_cli_s *) player;
3812 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3813 char *ret_buf = NULL;
3814 muse_player_event_e type;
3819 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3820 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3821 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3822 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3824 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3825 return PLAYER_ERROR_INVALID_PARAMETER;
3828 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3830 if (ret == PLAYER_ERROR_NONE) {
3831 pc->cb_info->user_cb[type] = callback;
3832 pc->cb_info->user_data[type] = user_data;
3833 LOGI("Event type : %d ", type);
3840 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
3842 PLAYER_INSTANCE_CHECK(player);
3843 int ret = PLAYER_ERROR_NONE;
3844 player_cli_s *pc = (player_cli_s *) player;
3845 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3846 char *ret_buf = NULL;
3847 muse_player_event_e type;
3852 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3853 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3854 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3855 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3857 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3858 return PLAYER_ERROR_INVALID_PARAMETER;
3861 set_null_user_cb_lock(pc->cb_info, type);
3863 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3869 int player_set_media_stream_seek_cb(player_h player, player_stream_type_e stream_type, player_media_stream_seek_cb callback, void *user_data)
3871 PLAYER_INSTANCE_CHECK(player);
3872 PLAYER_NULL_ARG_CHECK(callback);
3873 int ret = PLAYER_ERROR_NONE;
3874 player_cli_s *pc = (player_cli_s *) player;
3875 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3876 char *ret_buf = NULL;
3877 muse_player_event_e type;
3882 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3883 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3884 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3885 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3887 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3888 return PLAYER_ERROR_INVALID_PARAMETER;
3891 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3893 if (ret == PLAYER_ERROR_NONE) {
3894 pc->cb_info->user_cb[type] = callback;
3895 pc->cb_info->user_data[type] = user_data;
3896 LOGI("Event type : %d ", type);
3903 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
3905 PLAYER_INSTANCE_CHECK(player);
3906 int ret = PLAYER_ERROR_NONE;
3907 player_cli_s *pc = (player_cli_s *) player;
3908 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3909 char *ret_buf = NULL;
3910 muse_player_event_e type;
3915 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3916 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3917 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3918 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3920 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3921 return PLAYER_ERROR_INVALID_PARAMETER;
3924 set_null_user_cb_lock(pc->cb_info, type);
3926 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3932 /* TODO Implement raw data socket channel */
3933 int player_push_media_stream(player_h player, media_packet_h packet)
3935 PLAYER_INSTANCE_CHECK(player);
3936 PLAYER_NULL_ARG_CHECK(packet);
3937 int ret = PLAYER_ERROR_NONE;
3938 player_cli_s *pc = (player_cli_s *) player;
3939 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
3940 char *ret_buf = NULL;
3941 player_push_media_msg_type push_media;
3942 char *push_media_msg = (char *)&push_media;
3943 int msg_size = sizeof(player_push_media_msg_type);
3947 tbm_bo_handle thandle;
3948 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3951 media_format_h format;
3957 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
3958 media_packet_get_buffer_size(packet, &push_media.size);
3959 media_packet_get_pts(packet, &push_media.pts);
3960 media_packet_get_format(packet, &format);
3961 media_packet_get_flags(packet, &push_media.flags);
3963 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
3965 media_packet_is_video(packet, &is_video);
3966 media_packet_is_audio(packet, &is_audio);
3968 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
3970 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
3972 media_format_unref(format);
3975 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
3976 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
3978 LOGE("TBM get error : bo is NULL");
3979 return PLAYER_ERROR_INVALID_OPERATION;
3981 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
3982 if (thandle.ptr == NULL) {
3983 LOGE("TBM get error : handle pointer is NULL");
3984 ret = PLAYER_ERROR_INVALID_OPERATION;
3987 memcpy(thandle.ptr, buf, push_media.size);
3990 tfd = tbm_bo_export_fd(bo);
3992 LOGE("tbm_bo_export_fd err 0x%x", tfd);
3993 ret = PLAYER_ERROR_INVALID_OPERATION;
3997 player_msg_send_array_fd(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), tfd);
3998 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
3999 buf_size = (int)push_media.size;
4000 player_msg_send_array2(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), buf, buf_size, sizeof(char));
4003 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4004 buf_size = (int)push_media.size;
4005 muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts);
4006 player_msg_send_array(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char));
4009 LOGD("ret_buf %s", ret_buf);
4013 if (tfd > INVALID_DEFAULT_VALUE)
4016 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4024 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4026 PLAYER_INSTANCE_CHECK(player);
4027 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4028 int ret = PLAYER_ERROR_NONE;
4029 player_cli_s *pc = (player_cli_s *) player;
4030 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4031 char *ret_buf = NULL;
4032 media_format_mimetype_e mimetype;
4044 media_format_ref(format);
4045 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4046 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4047 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4048 LOGE("failed to get video info from format.");
4049 return PLAYER_ERROR_INVALID_PARAMETER;
4052 player_msg_send7(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, width, INT, height, INT, avg_bps, INT, max_bps, INT, frame_rate);
4053 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4054 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4055 LOGE("failed to get audio info from format.");
4056 return PLAYER_ERROR_INVALID_PARAMETER;
4058 player_msg_send6(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, channel, INT, samplerate, INT, avg_bps, INT, bit);
4060 media_format_unref(format);
4061 pc->push_media_stream = TRUE;
4067 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4069 int ret = PLAYER_ERROR_NONE;
4070 PLAYER_INSTANCE_CHECK(player);
4071 player_cli_s *pc = (player_cli_s *) player;
4072 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4073 char *ret_buf = NULL;
4077 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT64, max_size);
4083 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4085 int ret = PLAYER_ERROR_NONE;
4086 PLAYER_INSTANCE_CHECK(player);
4087 PLAYER_NULL_ARG_CHECK(pmax_size);
4088 player_cli_s *pc = (player_cli_s *) player;
4089 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4090 char *ret_buf = NULL;
4091 unsigned long long max_size;
4095 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4096 if (ret == PLAYER_ERROR_NONE) {
4097 player_msg_get_type(max_size, ret_buf, INT64);
4098 *pmax_size = max_size;
4104 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4106 int ret = PLAYER_ERROR_NONE;
4107 PLAYER_INSTANCE_CHECK(player);
4108 player_cli_s *pc = (player_cli_s *) player;
4109 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4110 char *ret_buf = NULL;
4114 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, percent);
4120 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4122 int ret = PLAYER_ERROR_NONE;
4123 PLAYER_INSTANCE_CHECK(player);
4124 PLAYER_NULL_ARG_CHECK(ppercent);
4125 player_cli_s *pc = (player_cli_s *) player;
4126 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4127 char *ret_buf = NULL;
4132 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4133 if (ret == PLAYER_ERROR_NONE) {
4134 player_msg_get(percent, ret_buf);
4135 *ppercent = percent;
4142 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4144 PLAYER_INSTANCE_CHECK(player);
4145 PLAYER_NULL_ARG_CHECK(pcount);
4146 int ret = PLAYER_ERROR_NONE;
4147 player_cli_s *pc = (player_cli_s *) player;
4148 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4149 char *ret_buf = NULL;
4154 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4155 if (ret == PLAYER_ERROR_NONE) {
4156 player_msg_get(count, ret_buf);
4164 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4166 PLAYER_INSTANCE_CHECK(player);
4167 PLAYER_NULL_ARG_CHECK(pindex);
4168 int ret = PLAYER_ERROR_NONE;
4169 player_cli_s *pc = (player_cli_s *) player;
4170 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4171 char *ret_buf = NULL;
4176 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4177 if (ret == PLAYER_ERROR_NONE) {
4178 player_msg_get(index, ret_buf);
4186 int player_select_track(player_h player, player_stream_type_e type, int index)
4188 PLAYER_INSTANCE_CHECK(player);
4189 int ret = PLAYER_ERROR_NONE;
4190 player_cli_s *pc = (player_cli_s *) player;
4191 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4192 char *ret_buf = NULL;
4196 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
4202 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4204 PLAYER_INSTANCE_CHECK(player);
4205 PLAYER_NULL_ARG_CHECK(pcode);
4206 int ret = PLAYER_ERROR_NONE;
4207 player_cli_s *pc = (player_cli_s *) player;
4208 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4209 char *ret_buf = NULL;
4210 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4215 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
4216 if (ret == PLAYER_ERROR_NONE) {
4217 bool recv_ret = TRUE;
4218 player_msg_get1_string(ret_buf, code_len, INT, code, recv_ret);
4220 *pcode = strndup(code, code_len);
4222 ret = PLAYER_ERROR_INVALID_OPERATION;
4228 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4230 PLAYER_INSTANCE_CHECK(player);
4231 PLAYER_NULL_ARG_CHECK(callback);
4232 int ret = PLAYER_ERROR_NONE;
4233 player_cli_s *pc = (player_cli_s *) player;
4234 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4235 char *ret_buf = NULL;
4236 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4237 int idx = 0, num = 0;
4238 int bandwidth = 0, width = 0, height = 0;
4244 player_msg_send(api, pc, ret_buf, ret);
4245 if (ret == PLAYER_ERROR_NONE) {
4246 player_msg_get_type(num, ret_buf, INT);
4248 player_msg_get_string(var_info, ret_buf);
4250 LOGW("There is no stream variant info.");
4253 for (idx = 0 ; idx < num ; idx++) {
4254 bandwidth = width = height = 0;
4256 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4258 bandwidth = atoi(token);
4260 token = strtok_r(NULL, ",", &ptr);
4262 width = atoi(token);
4264 token = strtok_r(NULL, ",", &ptr);
4266 height = atoi(token);
4268 callback(bandwidth, width, height, user_data);
4271 LOGD("LEAVE 0x%X", ret);
4276 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4278 int ret = PLAYER_ERROR_NONE;
4279 PLAYER_INSTANCE_CHECK(player);
4280 player_cli_s *pc = (player_cli_s *) player;
4281 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4282 char *ret_buf = NULL;
4286 player_msg_send3(api, pc, ret_buf, ret, INT, bandwidth, INT, width, INT, height);
4289 LOGD("LEAVE 0x%X", ret);
4294 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4296 int ret = PLAYER_ERROR_NONE;
4297 PLAYER_INSTANCE_CHECK(player);
4298 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4300 player_cli_s *pc = (player_cli_s *) player;
4301 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4302 char *ret_buf = NULL;
4303 int bandwidth = -1, width = -1, height = -1;
4307 player_msg_send(api, pc, ret_buf, ret);
4308 if (ret == PLAYER_ERROR_NONE) {
4309 bool ret_val = TRUE;
4311 player_msg_get3(ret_buf, bandwidth, INT, width, INT, height, INT, ret_val);
4313 if (pbandwidth) *pbandwidth = bandwidth;
4314 if (pwidth) *pwidth = width;
4315 if (pheight) *pheight = height;
4317 ret = PLAYER_ERROR_INVALID_OPERATION;
4322 LOGD("LEAVE 0x%X", ret);
4326 int player_set_audio_only(player_h player, bool audio_only)
4328 int ret = PLAYER_ERROR_NONE;
4329 PLAYER_INSTANCE_CHECK(player);
4330 player_cli_s *pc = (player_cli_s *) player;
4331 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4332 char *ret_buf = NULL;
4333 player_state_e state = PLAYER_STATE_NONE;
4335 LOGD("ENTER audio_only: %d", audio_only);
4337 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
4339 /* check player state */
4340 if (ret == PLAYER_ERROR_NONE) {
4341 player_msg_get(state, ret_buf);
4345 if (state < PLAYER_STATE_READY) {
4346 LOGE("Invalid state %d", state);
4347 return PLAYER_ERROR_INVALID_STATE;
4352 return PLAYER_ERROR_INVALID_OPERATION;
4355 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4356 if (EVAS_HANDLE(pc)) {
4357 pc->is_audio_only = (gboolean)audio_only;
4358 return PLAYER_ERROR_NONE;
4361 player_msg_send1(api, pc, ret_buf, ret, INT, audio_only);
4364 LOGD("LEAVE 0x%X", ret);
4369 int player_is_audio_only(player_h player, bool *paudio_only)
4371 PLAYER_INSTANCE_CHECK(player);
4372 PLAYER_NULL_ARG_CHECK(paudio_only);
4373 int ret = PLAYER_ERROR_NONE;
4374 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4375 player_cli_s *pc = (player_cli_s *) player;
4376 char *ret_buf = NULL;
4380 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4381 if (EVAS_HANDLE(pc)) {
4382 *paudio_only = (bool)pc->is_audio_only;
4383 return PLAYER_ERROR_NONE;
4387 player_msg_send(api, pc, ret_buf, ret);
4388 if (ret == PLAYER_ERROR_NONE) {
4389 player_msg_get(audio_only, ret_buf);
4390 *paudio_only = (bool)audio_only;
4394 LOGD("LEAVE 0x%X", ret);
4398 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4400 int ret = PLAYER_ERROR_NONE;
4401 PLAYER_INSTANCE_CHECK(player);
4402 player_cli_s *pc = (player_cli_s *) player;
4403 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4404 char *ret_buf = NULL;
4408 player_msg_send2(api, pc, ret_buf, ret, INT, buffer_ms, INT, rebuffer_ms);
4411 LOGD("LEAVE 0x%X", ret);
4415 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4417 PLAYER_INSTANCE_CHECK(player);
4418 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4420 int ret = PLAYER_ERROR_NONE;
4421 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4422 player_cli_s *pc = (player_cli_s *) player;
4423 int buffering_time = 0, rebuffering_time = 0;
4424 char *ret_buf = NULL;
4428 player_msg_send(api, pc, ret_buf, ret);
4430 if (ret == PLAYER_ERROR_NONE) {
4431 bool ret_val = true;
4433 player_msg_get2(ret_buf, buffering_time, INT, rebuffering_time, INT, ret_val);
4435 if (buffer_ms) *buffer_ms = buffering_time;
4436 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4438 ret = PLAYER_ERROR_INVALID_OPERATION;
4444 LOGD("LEAVE 0x%X", ret);
4448 int player_360_set_enable(player_h player, bool enable)
4450 PLAYER_INSTANCE_CHECK(player);
4451 int ret = PLAYER_ERROR_NONE;
4452 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLE;
4453 player_cli_s *pc = (player_cli_s *) player;
4454 char *ret_buf = NULL;
4455 int val = (int)enable;
4457 LOGD("ENTER %d", enable);
4459 player_msg_send1(api, pc, ret_buf, ret, INT, val);
4462 LOGD("LEAVE 0x%X", ret);
4466 int player_360_is_enabled(player_h player, bool *enabled)
4468 PLAYER_INSTANCE_CHECK(player);
4469 PLAYER_NULL_ARG_CHECK(enabled);
4470 int ret = PLAYER_ERROR_NONE;
4471 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4472 player_cli_s *pc = (player_cli_s *) player;
4473 char *ret_buf = NULL;
4478 player_msg_send(api, pc, ret_buf, ret);
4479 if (ret == PLAYER_ERROR_NONE) {
4480 player_msg_get(val, ret_buf);
4485 LOGD("LEAVE 0x%X", ret);
4489 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4491 PLAYER_INSTANCE_CHECK(player);
4492 int ret = PLAYER_ERROR_NONE;
4493 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4494 player_cli_s *pc = (player_cli_s *) player;
4495 char *ret_buf = NULL;
4497 LOGD("ENTER %f %f", yaw, pitch);
4499 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, yaw, DOUBLE, pitch);
4502 LOGD("LEAVE 0x%X", ret);
4506 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4508 PLAYER_INSTANCE_CHECK(player);
4509 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4510 int ret = PLAYER_ERROR_NONE;
4511 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4512 player_cli_s *pc = (player_cli_s *) player;
4513 double yaw_val = -1;
4514 double pitch_val = -1;
4515 char *ret_buf = NULL;
4519 player_msg_send(api, pc, ret_buf, ret);
4521 if (ret == PLAYER_ERROR_NONE) {
4522 bool ret_val = TRUE;
4523 player_msg_get2(ret_buf, yaw_val, DOUBLE, pitch_val, DOUBLE, ret_val);
4525 *yaw = (float)yaw_val;
4526 *pitch = (float)pitch_val;
4528 LOGE("failed to get value from msg");
4529 ret = PLAYER_ERROR_INVALID_OPERATION;
4535 LOGD("LEAVE 0x%X", ret);
4539 int player_360_set_zoom(player_h player, float level)
4541 PLAYER_INSTANCE_CHECK(player);
4542 int ret = PLAYER_ERROR_NONE;
4543 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4544 player_cli_s *pc = (player_cli_s *) player;
4545 char *ret_buf = NULL;
4547 LOGD("ENTER %f", level);
4549 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, level);
4552 LOGD("LEAVE 0x%X", ret);
4556 int player_360_get_zoom(player_h player, float *level)
4558 PLAYER_INSTANCE_CHECK(player);
4559 PLAYER_NULL_ARG_CHECK(level);
4560 int ret = PLAYER_ERROR_NONE;
4561 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
4562 player_cli_s *pc = (player_cli_s *) player;
4564 char *ret_buf = NULL;
4568 player_msg_send(api, pc, ret_buf, ret);
4570 if (ret == PLAYER_ERROR_NONE) {
4571 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
4572 *level = (float)zoom;
4574 LOGE("failed to get value from msg");
4575 ret = PLAYER_ERROR_INVALID_OPERATION;
4581 LOGD("LEAVE 0x%X", ret);
4586 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
4588 PLAYER_INSTANCE_CHECK(player);
4589 int ret = PLAYER_ERROR_NONE;
4590 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
4591 player_cli_s *pc = (player_cli_s *) player;
4592 char *ret_buf = NULL;
4594 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
4596 player_msg_send2(api, pc, ret_buf, ret, INT, horizontal_degrees, INT, vertical_degrees);
4599 LOGD("LEAVE 0x%X", ret);
4603 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
4605 PLAYER_INSTANCE_CHECK(player);
4606 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
4607 int ret = PLAYER_ERROR_NONE;
4608 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
4609 player_cli_s *pc = (player_cli_s *) player;
4612 char *ret_buf = NULL;
4616 player_msg_send(api, pc, ret_buf, ret);
4618 if (ret == PLAYER_ERROR_NONE) {
4619 bool ret_val = TRUE;
4620 player_msg_get2(ret_buf, h_val, INT, v_val, INT, ret_val);
4622 *horizontal_degrees = h_val;
4623 *vertical_degrees = v_val;
4625 LOGE("failed to get value from msg");
4626 ret = PLAYER_ERROR_INVALID_OPERATION;
4632 LOGD("LEAVE 0x%X", ret);