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
563 void *dl_handle = NULL;
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);
573 PLAYER_DISP_DLSYM(dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
574 int ret = p_disp_set_evas_display_visible(cb_info->evas_info->handle, true);
576 if (ret != MM_ERROR_NONE)
577 LOGW("failed to set visible at evas 0x%x", ret);
579 cb_info->evas_info->visible = EVAS_VISIBLE_TRUE;
581 LOGW("not support video rendering");
586 LOGD("call seek cb");
587 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
588 set_null_user_cb(cb_info, ev);
590 LOGW("ignored. seek cb %p", cb_info->user_cb[ev]);
592 g_mutex_unlock(&cb_info->seek_cb_mutex);
595 static void __player_remove_tsurf_list(player_cli_s * pc)
599 g_mutex_lock(&pc->cb_info->data_mutex);
600 if (pc->cb_info->tsurf_list) {
601 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
603 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
604 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
606 LOGD("%p will be removed", tmp);
609 tbm_surface_destroy(tmp->tsurf);
615 g_list_free(pc->cb_info->tsurf_list);
616 pc->cb_info->tsurf_list = NULL;
618 g_mutex_unlock(&pc->cb_info->data_mutex);
622 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, int height, int width)
626 g_mutex_lock(&cb_info->data_mutex);
627 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
628 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
629 if (tmp && key && (tmp->key[0] == key[0])) {
630 LOGD("found tsurf_data of tbm_key %d", key[0]);
632 /* need to check tsuf info to support DRC */
633 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
634 (tbm_surface_get_width(tmp->tsurf) != width)) {
636 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
637 LOGW("tsurf info is changed. need to create new tsurf.");
638 tbm_surface_destroy(tmp->tsurf);
641 g_mutex_unlock(&cb_info->data_mutex);
645 g_mutex_unlock(&cb_info->data_mutex);
650 g_mutex_unlock(&cb_info->data_mutex);
654 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
656 tbm_bo bo[4] = { NULL, };
657 int key[4] = { INVALID_DEFAULT_VALUE, };
658 tbm_surface_info_s sinfo;
659 char *surface_info = (char *)&sinfo;
660 media_packet_h pkt = NULL;
661 tbm_surface_h tsurf = NULL;
662 player_tsurf_info_t *tsurf_data = NULL;
664 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
665 bool make_pkt_fmt = false;
666 int ret = MEDIA_FORMAT_ERROR_NONE;
667 _media_pkt_fin_data *fin_data = NULL;
671 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
673 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
675 !muse_core_msg_object_get_value("key[0]", jobj, MUSE_TYPE_ANY, &key[0]) ||
676 !muse_core_msg_object_get_value("key[1]", jobj, MUSE_TYPE_ANY, &key[1]) ||
677 !muse_core_msg_object_get_value("key[2]", jobj, MUSE_TYPE_ANY, &key[2]) ||
678 !muse_core_msg_object_get_value("key[3]", jobj, MUSE_TYPE_ANY, &key[3]) ||
679 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
680 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
681 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
682 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
684 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
686 muse_core_msg_object_free(jobj);
689 muse_core_msg_object_free(jobj);
691 LOGD("width %d, height %d", sinfo.width, sinfo.height);
694 LOGE("cb_info is null");
698 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
699 /* send msg to release v_data. */
700 LOGE("_video_decoded_cb is not set");
704 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
705 LOGE("tbm fd is invalid");
709 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
711 for (i = 0; i < MUSE_NUM_FD; i++) {
712 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
716 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
719 tsurf_data = g_new(player_tsurf_info_t, 1);
721 LOGE("failed to alloc tsurf info");
724 memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
726 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
728 LOGE("failed to create tbm surface");
732 memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
733 tsurf_data->tsurf = tsurf;
734 if (cb_info->use_tsurf_pool) {
735 g_mutex_lock(&cb_info->data_mutex);
736 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
737 LOGD("key %d is added to the pool", key[0]);
738 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
739 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
740 g_mutex_unlock(&cb_info->data_mutex);
743 if (tsurf_data->tsurf) {
744 tsurf = tsurf_data->tsurf;
746 LOGE("tsurf_data->tsurf is null (never enter here)");
751 /* check media packet format */
752 if (cb_info->pkt_fmt) {
753 int pkt_fmt_width = 0;
754 int pkt_fmt_height = 0;
755 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
757 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
758 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
759 LOGW("different format. current 0x%x, %dx%d, new 0x%x, %dx%d", pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height, mimetype, sinfo.width, sinfo.height);
760 media_format_unref(cb_info->pkt_fmt);
761 cb_info->pkt_fmt = NULL;
767 /* create packet format */
769 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
770 ret = media_format_create(&cb_info->pkt_fmt);
771 if (ret == MEDIA_FORMAT_ERROR_NONE) {
772 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
773 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
774 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
775 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
777 LOGE("media_format_create failed");
781 fin_data = g_new0(_media_pkt_fin_data, 1);
783 LOGE("failed to alloc fin_data");
786 fin_data->remote_v_data = v_data;
787 fin_data->fd = cb_info->fd;
788 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
790 /* Keep the fd id to check validation when the pkt is destroyed. */
791 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
793 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
794 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
795 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
800 ret = media_packet_set_pts(pkt, (uint64_t) pts);
801 if (ret != MEDIA_PACKET_ERROR_NONE)
802 LOGE("media_packet_set_pts failed");
804 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
805 /* call media packet callback */
806 ((player_media_packet_video_decoded_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) (pkt, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]);
808 LOGE("_video_decoded_cb is not set");
809 media_packet_destroy(pkt);
812 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
813 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
814 close(recv_data->tfd[i]);
817 for (i = 0; i < bo_num; i++) {
822 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
827 media_packet_destroy(pkt);
832 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
833 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
834 close(recv_data->tfd[i]);
837 for (i = 0; i < bo_num; i++) {
841 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
843 if (cb_info && v_data)
844 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, POINTER, v_data);
849 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
852 tbm_bo_handle thandle;
853 int key = INVALID_DEFAULT_VALUE;
854 player_audio_raw_data_s audio;
856 if (!player_msg_get(key, recv_data->buffer)) {
857 LOGE("failed to get key value from msg.");
861 if (recv_data->tfd[0] < 0) {
862 LOGE("failed to get tbm_fd(key:%d)", key);
866 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
868 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
872 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
873 if (thandle.ptr == NULL) {
874 LOGE("TBM get error : handle pointer is NULL");
878 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
879 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
881 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
882 ((player_audio_pcm_extraction_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME]) (&audio, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME]);
886 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
887 close(recv_data->tfd[0]);
888 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
894 if (key > INVALID_DEFAULT_VALUE) {
895 /* LOGD("send msg to release buffer. key:%d", key); */
896 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
900 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
904 static void __pd_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
907 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
909 if (player_msg_get(type, recv_data->buffer))
910 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
913 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
917 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
921 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
925 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
927 /* player_media_stream_buffer_status_e status; */
930 if (player_msg_get(status, recv_data->buffer)) {
931 ((player_media_stream_buffer_status_cb)
932 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]) ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]);
936 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
938 /* player_media_stream_buffer_status_e status; */
941 if (player_msg_get(status, recv_data->buffer)) {
942 ((player_media_stream_buffer_status_cb)
943 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
944 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
949 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
951 /* player_media_stream_buffer_status_e status; */
953 unsigned long long bytes;
956 player_msg_get2(recv_data->buffer, status, INT, bytes, INT64, ret);
958 ((player_media_stream_buffer_status_cb_ex)
959 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
960 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
964 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
966 /* player_media_stream_buffer_status_e status; */
968 unsigned long long bytes;
971 player_msg_get2(recv_data->buffer, status, INT, bytes, INT64, ret);
973 ((player_media_stream_buffer_status_cb_ex)
974 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
975 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
980 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
982 unsigned long long offset;
984 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
985 ((player_media_stream_seek_cb)
986 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
987 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
991 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
993 unsigned long long offset;
995 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
996 ((player_media_stream_seek_cb)
997 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
998 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1002 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1008 bool ret_val = TRUE;
1010 player_msg_get4(recv_data->buffer, width, INT, height, INT, fps, INT, bit_rate, INT, ret_val);
1012 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1013 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1017 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, _player_recv_data *recv_data) = {
1018 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1019 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1020 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1021 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1022 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1023 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1024 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1025 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1026 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1027 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
1028 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1029 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
1030 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1031 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1032 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1033 #ifdef _PLAYER_FOR_PRODUCT
1034 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1035 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1037 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1038 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1039 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1040 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1041 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1042 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1043 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1044 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1045 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1046 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1048 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1051 gboolean _player_event_job_function(void *user_data)
1053 _player_cb_data *data = (_player_cb_data *)user_data;
1054 muse_player_event_e ev;
1057 LOGE("data is null");
1061 LOGD("enter ev:%d", data->int_data);
1063 g_mutex_lock(&data->event_mutex);
1064 ev = data->int_data;
1066 if (data->cb_info == NULL) {
1067 /* tried to remove before at _player_remove_idle_event */
1068 LOGW("cb_info is NULL. event %d", data->int_data);
1072 /* remove event from list */
1073 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1074 if (data->cb_info->event_queue.idle_ev_list) {
1075 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1076 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1078 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1080 if (data->cb_info->user_cb[ev])
1081 _user_callbacks[ev] (data->cb_info, data->recv_data);
1083 LOGW("user callback is unset. type : %d", ev);
1086 /* unlock and release event */
1087 g_mutex_unlock(&data->event_mutex);
1088 g_mutex_clear(&data->event_mutex);
1090 if (data->recv_data) {
1091 g_free(data->recv_data->buffer);
1092 g_free(data->recv_data);
1096 return FALSE; /* remove from the event list */
1099 static bool _player_need_sync_context(int event_id)
1101 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1102 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1103 (event_id == MUSE_PLAYER_EVENT_TYPE_PD) ||
1104 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1105 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1106 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1107 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1108 LOGD("%d callback will be issued in the mainloop.", event_id);
1115 static void *_player_event_queue_loop(void *param)
1118 LOGE("NULL parameter");
1121 callback_cb_info_s *cb_info = param;
1122 player_event_queue *ev = &cb_info->event_queue;
1123 _player_cb_data *event_data = NULL;
1125 g_mutex_lock(&ev->mutex);
1126 while (ev->running) {
1127 g_mutex_lock(&ev->qlock);
1128 if (g_queue_is_empty(ev->queue)) {
1129 g_mutex_unlock(&ev->qlock);
1130 g_cond_wait(&ev->cond, &ev->mutex);
1134 g_mutex_unlock(&ev->qlock);
1137 g_mutex_lock(&ev->qlock);
1138 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1139 g_mutex_unlock(&ev->qlock);
1141 muse_player_event_e event_type = ((_player_cb_data *)event_data)->int_data;
1143 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1144 g_mutex_lock(&cb_info->seek_cb_mutex);
1145 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1146 /* push event into queue again. */
1147 _player_event_queue_add(ev, event_data);
1148 g_mutex_unlock(&cb_info->seek_cb_mutex);
1151 g_mutex_unlock(&cb_info->seek_cb_mutex);
1154 if (_player_need_sync_context(event_data->int_data)) {
1155 if (cb_info->user_cb[event_data->int_data] &&
1156 _user_callbacks[event_data->int_data]) {
1157 g_mutex_lock(&ev->idle_ev_mutex);
1158 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1159 g_mutex_unlock(&ev->idle_ev_mutex);
1161 LOGD("add ev %d to main loop", event_data->int_data);
1163 g_idle_add_full(G_PRIORITY_DEFAULT,
1164 (GSourceFunc)_player_event_job_function,
1165 (gpointer)event_data,
1168 LOGW("there is no registered cb for ev:%d", event_data->int_data);
1169 if (event_data->recv_data) {
1170 g_free(event_data->recv_data->buffer);
1171 g_free(event_data->recv_data);
1176 _player_event_job_function(event_data);
1183 g_mutex_unlock(&ev->mutex);
1184 LOGI("Exit event loop");
1188 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1190 g_return_val_if_fail(cb_info, FALSE);
1191 player_event_queue *ev = &cb_info->event_queue;
1193 ev->queue = g_queue_new();
1194 g_return_val_if_fail(ev->queue, FALSE);
1195 g_mutex_init(&ev->qlock);
1197 g_mutex_init(&ev->mutex);
1198 g_cond_init(&ev->cond);
1201 g_mutex_init(&ev->idle_ev_mutex);
1203 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1204 g_return_val_if_fail(ev->thread, FALSE);
1205 LOGI("event queue thread %p", ev->thread);
1211 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1213 g_return_if_fail(cb_info);
1214 player_event_queue *ev = &cb_info->event_queue;
1215 _player_cb_data *event_data = NULL;
1218 g_mutex_lock(&ev->idle_ev_mutex);
1220 if (ev->idle_ev_list == NULL) {
1221 LOGD("No idle event is remained.");
1222 g_mutex_unlock(&ev->idle_ev_mutex);
1226 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1228 list = ev->idle_ev_list;
1230 event_data = list->data;
1231 list = g_list_next(list);
1234 LOGW("Fail to remove idle event. The data is NULL");
1238 if (g_mutex_trylock(&event_data->event_mutex)) {
1240 gboolean ret = FALSE;
1241 if (remove_all || (event_data->int_data == event_type)) {
1243 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1245 ret = g_idle_remove_by_data(event_data);
1247 /* will be handled at _player_event_job_function() as an exception */
1248 event_data->cb_info = NULL;
1249 LOGW("failed to remove, idle callback will be called later");
1252 /* set cb to null */
1253 set_null_user_cb(cb_info, event_data->int_data);
1254 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1256 g_mutex_unlock(&event_data->event_mutex);
1259 g_mutex_clear(&event_data->event_mutex);
1260 if (event_data->recv_data) {
1261 g_free(event_data->recv_data->buffer);
1262 g_free(event_data->recv_data);
1266 LOGD("remove idle event done");
1267 } /* else : will be handled if the cb is called. */
1269 g_mutex_unlock(&event_data->event_mutex);
1272 LOGW("event(%d) lock failed. it's being called...", event_data->int_data);
1275 /* continue: keep checking next event_data */
1279 g_list_free(ev->idle_ev_list);
1280 ev->idle_ev_list = NULL;
1283 g_mutex_unlock(&ev->idle_ev_mutex);
1289 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1291 g_return_if_fail(cb_info);
1292 player_event_queue *ev = &cb_info->event_queue;
1293 _player_cb_data *event_data;
1295 LOGI("event queue thread %p", ev->thread);
1297 g_mutex_lock(&ev->mutex);
1298 ev->running = FALSE;
1299 g_cond_broadcast(&ev->cond);
1300 g_mutex_unlock(&ev->mutex);
1302 g_thread_join(ev->thread);
1305 while (!g_queue_is_empty(ev->queue)) {
1306 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1308 g_free(event_data->recv_data->buffer);
1309 g_free(event_data->recv_data);
1313 g_queue_free(ev->queue);
1314 g_mutex_clear(&ev->qlock);
1315 g_mutex_clear(&ev->mutex);
1316 g_cond_clear(&ev->cond);
1317 g_mutex_clear(&ev->idle_ev_mutex);
1320 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1324 g_mutex_lock(&ev_queue->qlock);
1326 item = g_queue_peek_head_link(ev_queue->queue);
1328 GList *next = item->next;
1329 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1331 if (cb_data && cb_data->int_data == ev) {
1332 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1333 g_free(cb_data->recv_data->buffer);
1334 g_free(cb_data->recv_data);
1337 g_queue_delete_link(ev_queue->queue, item);
1341 g_mutex_unlock(&ev_queue->qlock);
1344 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1347 g_mutex_lock(&ev->qlock);
1348 g_queue_push_tail(ev->queue, (gpointer) data);
1349 g_mutex_unlock(&ev->qlock);
1350 g_cond_signal(&ev->cond);
1354 static bool _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1356 /* LOGD("get event %d", event); */
1358 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1359 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1360 _player_cb_data *data = NULL;
1361 data = g_new(_player_cb_data, 1);
1363 LOGE("fail to alloc mem");
1366 data->int_data = (int)event;
1367 data->cb_info = cb_info;
1368 data->recv_data = recv_data;
1369 g_mutex_init(&data->event_mutex);
1370 _player_event_queue_add(&cb_info->event_queue, data);
1376 LOGE("failed to add event to queue");
1380 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1382 ret_msg_s *msg = NULL;
1383 ret_msg_s *last = cb_info->buff.retMsgHead;
1385 msg = g_new(ret_msg_s, 1);
1388 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1391 cb_info->buff.retMsgHead = msg;
1398 LOGE("g_new failure");
1401 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1403 ret_msg_s *msg = cb_info->buff.retMsgHead;
1404 ret_msg_s *prev = NULL;
1406 if (msg->api == api) {
1408 cb_info->buff.retMsgHead = msg->next;
1410 prev->next = msg->next;
1419 static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
1421 ret_msg_s *msg = cb_info->buff.retMsgHead;
1422 ret_msg_s *prev = NULL;
1426 LOGI("Remove %s", prev->msg);
1433 static void _notify_disconnected(callback_cb_info_s * cb_info)
1435 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1436 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1439 if (_user_callbacks[event]) {
1440 _player_cb_data *data = NULL;
1441 data = g_new(_player_cb_data, 1);
1443 LOGE("fail to alloc mem");
1446 data->int_data = (int)event;
1447 data->cb_info = cb_info;
1448 data->recv_data = NULL;
1449 g_mutex_init(&data->event_mutex);
1450 _player_event_queue_add(&cb_info->event_queue, data);
1454 static void *client_cb_handler(gpointer data)
1460 callback_cb_info_s *cb_info = data;
1461 char *recvMsg = NULL;
1462 muse_core_msg_parse_err_e err;
1463 tbm_fd tfd[MUSE_NUM_FD];
1465 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(tfd));
1466 while (g_atomic_int_get(&cb_info->running)) {
1468 err = MUSE_MSG_PARSE_ERROR_NONE;
1470 len = player_recv_msg(cb_info, tfd);
1474 recvMsg = cb_info->buff.recvMsg;
1475 recvMsg[len] = '\0';
1479 while (offset < len) {
1480 api = MUSE_PLAYER_API_MAX;
1481 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1484 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1486 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1487 if (api < MUSE_PLAYER_API_MAX) {
1488 g_mutex_lock(&cb_info->player_mutex);
1489 cb_info->buff.recved++;
1490 _add_ret_msg(api, cb_info, offset, parse_len);
1491 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1492 LOGD("get tbm fd for album art.");
1493 cb_info->tfd = tfd[0];
1495 g_cond_signal(&cb_info->player_cond[api]);
1496 g_mutex_unlock(&cb_info->player_mutex);
1497 if (api == MUSE_PLAYER_API_DESTROY)
1498 g_atomic_int_set(&cb_info->running, 0);
1499 } else if (api == MUSE_PLAYER_CB_EVENT) {
1501 _player_recv_data *recv_data = NULL;
1502 g_mutex_lock(&cb_info->player_mutex);
1503 recv_data = g_new0(_player_recv_data, 1);
1504 if (recv_data != NULL) {
1505 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1506 recv_data->buffer = strndup(recvMsg+offset, parse_len);
1508 LOGE("failed to alloc recv_data.");
1509 g_mutex_unlock(&cb_info->player_mutex);
1510 muse_core_msg_object_free(jobj);
1513 g_mutex_unlock(&cb_info->player_mutex);
1514 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1515 !_user_callback_handler(cb_info, event, recv_data)) {
1516 LOGE("failed to get value or add event to the queue.");
1518 g_free(recv_data->buffer);
1522 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1523 g_mutex_lock(&cb_info->player_mutex);
1524 cb_info->buff.recved++;
1525 g_cond_signal(&cb_info->server_ack_cond);
1526 g_mutex_unlock(&cb_info->player_mutex);
1529 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1531 muse_core_msg_object_free(jobj);
1533 LOGE("Failed to get msg obj. err:%d", err);
1536 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1539 offset += parse_len;
1540 parse_len = len - offset;
1543 if (g_atomic_int_get(&cb_info->running))
1544 _notify_disconnected(cb_info);
1545 LOGD("client cb exit");
1550 static callback_cb_info_s *callback_new(gint sockfd)
1552 callback_cb_info_s *cb_info;
1556 g_return_val_if_fail(sockfd > 0, NULL);
1558 cb_info = g_new(callback_cb_info_s, 1);
1561 memset(cb_info, 0, sizeof(callback_cb_info_s));
1563 g_mutex_init(&cb_info->player_mutex);
1564 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1565 g_cond_init(&cb_info->player_cond[i]);
1566 g_cond_init(&cb_info->server_ack_cond);
1568 g_mutex_init(&cb_info->data_mutex);
1569 g_mutex_init(&cb_info->seek_cb_mutex);
1571 buff = &cb_info->buff;
1572 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1573 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1575 buff->retMsgHead = NULL;
1576 buff->part_of_msg = NULL;
1578 g_atomic_int_set(&cb_info->running, 1);
1579 cb_info->fd = sockfd;
1580 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1581 cb_info->tfd = INVALID_DEFAULT_VALUE;
1586 static void callback_destroy(callback_cb_info_s * cb_info)
1589 g_return_if_fail(cb_info);
1591 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1592 muse_client_close(cb_info->fd);
1593 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1594 muse_client_close(cb_info->data_fd);
1596 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1598 g_thread_join(cb_info->thread);
1599 cb_info->thread = NULL;
1601 LOGI("%p Callback destroyed", cb_info);
1603 g_mutex_clear(&cb_info->player_mutex);
1604 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1605 g_cond_clear(&cb_info->player_cond[i]);
1606 g_cond_clear(&cb_info->server_ack_cond);
1608 g_mutex_clear(&cb_info->data_mutex);
1609 g_mutex_clear(&cb_info->seek_cb_mutex);
1611 g_free(cb_info->buff.recvMsg);
1612 _remove_all_ret_msg(cb_info);
1613 if (cb_info->buff.part_of_msg)
1614 g_free(cb_info->buff.part_of_msg);
1618 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1623 case MUSE_PLAYER_API_PREPARE:
1624 case MUSE_PLAYER_API_PREPARE_ASYNC:
1625 case MUSE_PLAYER_API_UNPREPARE:
1626 case MUSE_PLAYER_API_START:
1627 case MUSE_PLAYER_API_STOP:
1628 case MUSE_PLAYER_API_PAUSE:
1629 timeout += SERVER_TIMEOUT(pc);
1632 /* check prepare async is done */
1633 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1634 timeout += SERVER_TIMEOUT(pc);
1637 timeout += CALLBACK_TIME_OUT;
1638 return timeout; /* ms */
1641 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1643 int ret = PLAYER_ERROR_NONE;
1644 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1645 msg_buff_s *buff = &cb_info->buff;
1646 ret_msg_s *msg = NULL;
1648 g_mutex_lock(&cb_info->player_mutex);
1650 msg = _get_ret_msg(api, cb_info);
1652 if (!buff->recved || !msg) {
1653 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1654 LOGW("api %d return msg does not received %dms", api, time_out);
1655 ret = PLAYER_ERROR_INVALID_OPERATION;
1660 msg = _get_ret_msg(api, cb_info);
1662 *ret_buf = msg->msg;
1665 if (!player_msg_get(ret, *ret_buf))
1666 ret = PLAYER_ERROR_INVALID_OPERATION;
1668 LOGE("api %d is the spurious wakeup", api);
1672 g_mutex_unlock(&cb_info->player_mutex);
1676 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1678 int ret = PLAYER_ERROR_NONE;
1679 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1680 msg_buff_s *buff = &cb_info->buff;
1682 g_mutex_lock(&cb_info->player_mutex);
1684 if (!buff->recved) {
1685 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1686 LOGW("server ack msg does not received %dms", time_out);
1688 ret = PLAYER_ERROR_INVALID_OPERATION;
1690 LOGD("Another msg is received, continue create handle");
1691 g_mutex_unlock(&cb_info->player_mutex);
1697 g_mutex_unlock(&cb_info->player_mutex);
1704 * Public Implementation
1707 int player_create(player_h * player)
1709 PLAYER_INSTANCE_CHECK(player);
1711 int ret = PLAYER_ERROR_NONE;
1712 int sock_fd = INVALID_DEFAULT_VALUE;
1715 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1716 muse_core_api_module_e module = MUSE_PLAYER;
1717 player_cli_s *pc = NULL;
1718 char *ret_buf = NULL;
1719 int retry_count = CONNECTION_RETRY;
1724 pc = g_new0(player_cli_s, 1);
1726 return PLAYER_ERROR_OUT_OF_MEMORY;
1728 while (--retry_count) {
1729 sock_fd = muse_client_new();
1730 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1731 LOGE("connection failure %d", errno);
1732 ret = PLAYER_ERROR_INVALID_OPERATION;
1734 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1738 player_msg_create_handle(api, sock_fd, INT, module, INT, pid);
1740 pc->cb_info = callback_new(sock_fd);
1742 LOGE("fail to create callback");
1743 ret = PLAYER_ERROR_INVALID_OPERATION;
1747 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1748 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1754 if (!_player_event_queue_new(pc->cb_info)) {
1755 LOGE("fail to create event queue");
1756 ret = PLAYER_ERROR_INVALID_OPERATION;
1760 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1761 if (ret == PLAYER_ERROR_NONE) {
1762 intptr_t module_addr = 0;
1763 *player = (player_h) pc;
1764 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1765 pc->cb_info->data_fd = muse_client_new_data_ch();
1766 muse_core_send_module_addr(module_addr, pc->cb_info->data_fd);
1767 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1769 ret = PLAYER_ERROR_INVALID_OPERATION;
1772 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1775 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1776 pc->cb_info->evas_info = g_new0(player_evas_info_s, 1);
1777 if (pc->cb_info->evas_info == NULL) {
1778 ret = PLAYER_ERROR_OUT_OF_MEMORY;
1781 EVAS_INFO(pc)->visible = EVAS_VISIBLE_NONE;
1783 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1784 pc->push_media_stream = FALSE;
1785 pc->support_video = FALSE;
1786 EVAS_INFO(pc)->support_video = FALSE;
1787 pc->is_audio_only = FALSE;
1789 PLAYER_DISP_DLOPEN(pc); /* update supported_video */
1795 if (pc && pc->cb_info) {
1796 if (pc->cb_info->event_queue.running)
1797 _player_event_queue_destroy(pc->cb_info);
1798 callback_destroy(pc->cb_info);
1803 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1812 int player_destroy(player_h player)
1814 PLAYER_INSTANCE_CHECK(player);
1816 int ret = PLAYER_ERROR_NONE;
1817 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1818 player_cli_s *pc = (player_cli_s *) player;
1819 char *ret_buf = NULL;
1820 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1821 int (*p_disp_destroy_evas_display)(void **) = NULL;
1825 /* clear cb and release mem */
1826 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1827 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1828 _player_release_internal_memory(pc);
1830 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1831 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
1832 if (EVAS_HANDLE(pc)) {
1833 player_unset_media_packet_video_frame_decoded_cb(player);
1834 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
1835 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
1836 LOGW("fail to unset evas client");
1837 __player_unset_retrieve_buffer_cb(player);
1838 g_free(pc->cb_info->evas_info);
1842 player_msg_send(api, pc, ret_buf, ret);
1844 if (CALLBACK_INFO(pc)) {
1845 __player_remove_tsurf_list(pc);
1846 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
1847 _player_event_queue_destroy(CALLBACK_INFO(pc));
1848 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
1850 callback_destroy(CALLBACK_INFO(pc));
1854 PLAYER_DISP_DLCLOSE(pc->dl_handle); /* update supported_video */
1861 LOGD("LEAVE 0x%X", ret);
1865 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
1867 PLAYER_INSTANCE_CHECK(player);
1868 int ret = PLAYER_ERROR_NONE;
1869 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
1870 player_cli_s *pc = (player_cli_s *) player;
1871 char *ret_buf = NULL;
1875 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
1876 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
1877 return PLAYER_ERROR_INVALID_OPERATION;
1879 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
1880 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
1882 player_msg_send(api, pc, ret_buf, ret);
1883 if (ret == PLAYER_ERROR_NONE) {
1885 player_msg_get_type(timeout, ret_buf, INT);
1887 LOGD("server timeout will be %d sec", timeout);
1888 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1890 LOGW("failed to realize, so prepare cb will be released soon");
1891 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1892 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1899 int player_prepare(player_h player)
1901 PLAYER_INSTANCE_CHECK(player);
1902 int ret = PLAYER_ERROR_NONE;
1903 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
1904 player_cli_s *pc = (player_cli_s *) player;
1905 char *ret_buf = NULL;
1909 player_msg_send(api, pc, ret_buf, ret);
1910 if (ret == PLAYER_ERROR_NONE) {
1912 player_msg_get_type(timeout, ret_buf, INT);
1914 LOGD("server timeout will be %d sec", timeout);
1915 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1922 int player_unprepare(player_h player)
1924 PLAYER_INSTANCE_CHECK(player);
1925 int ret = PLAYER_ERROR_NONE;
1926 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
1927 player_cli_s *pc = (player_cli_s *) player;
1928 char *ret_buf = NULL;
1932 if (!CALLBACK_INFO(pc))
1933 return PLAYER_ERROR_INVALID_STATE;
1935 player_msg_send(api, pc, ret_buf, ret);
1937 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1938 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1939 _player_release_internal_memory(pc);
1941 pc->cb_info->video_frame_pool_size = 0;
1942 __player_remove_tsurf_list(pc);
1943 pc->is_audio_only = FALSE;
1947 LOGD("LEAVE 0x%X", ret);
1951 /* 1. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx'
1952 * 2. remove 'file://' prefix */
1953 int _player_get_origin_internal_path(const char* uri, char* origin)
1955 gchar *file_path = NULL;
1958 if (!uri || !origin) {
1959 LOGD("invalid parameter");
1960 return PLAYER_ERROR_INVALID_PARAMETER;
1963 if (strstr(uri, "file://")) {
1964 file_path = g_filename_from_uri(uri, NULL, &err);
1966 if (!file_path || (err != NULL)) {
1967 LOGE("Invalid URI '%s', err: %s", uri,
1968 (err != NULL) ? err->message : "unknown error");
1970 if (err) g_error_free(err);
1971 if (file_path) g_free(file_path);
1973 return PLAYER_ERROR_INVALID_PARAMETER;
1975 LOGD("get file path from uri");
1978 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, origin) < 0) {
1979 /* cannot convert path. use the original one. */
1980 strncpy(origin, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
1982 /* need to use converted path. */
1983 LOGD("Converted path : %s -> %s", uri, origin);
1989 return PLAYER_ERROR_NONE;
1992 int player_set_uri(player_h player, const char *uri)
1994 PLAYER_INSTANCE_CHECK(player);
1995 PLAYER_NULL_ARG_CHECK(uri);
1996 int ret = PLAYER_ERROR_NONE;
1997 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
1998 player_cli_s *pc = (player_cli_s *) player;
1999 char *ret_buf = NULL;
2000 char path[MAX_URL_LEN] = {0, };
2004 if (_player_get_origin_internal_path(uri, path) != PLAYER_ERROR_NONE)
2005 return PLAYER_ERROR_INVALID_PARAMETER;
2007 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
2008 pc->push_media_stream = FALSE;
2014 int player_set_memory_buffer(player_h player, const void *data, int size)
2016 PLAYER_INSTANCE_CHECK(player);
2017 PLAYER_NULL_ARG_CHECK(data);
2018 int ret = PLAYER_ERROR_NONE;
2019 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2020 player_cli_s *pc = (player_cli_s *) player;
2021 char *ret_buf = NULL;
2023 tbm_bo_handle thandle;
2024 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2026 if (SERVER_TBM_BO(pc)) {
2027 LOGE("Already set the memory buffer. unprepare please");
2028 return PLAYER_ERROR_INVALID_OPERATION;
2031 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2033 LOGE("TBM get error : bo is NULL");
2034 return PLAYER_ERROR_INVALID_OPERATION;
2036 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2037 if (thandle.ptr == NULL) {
2038 LOGE("TBM get error : handle pointer is NULL");
2039 ret = PLAYER_ERROR_INVALID_OPERATION;
2042 memcpy(thandle.ptr, data, size);
2045 tfd = tbm_bo_export_fd(bo);
2047 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2048 ret = PLAYER_ERROR_INVALID_OPERATION;
2052 player_msg_send1_fd(api, pc, ret_buf, ret, INT, size, tfd);
2053 pc->push_media_stream = FALSE;
2056 if (tfd > INVALID_DEFAULT_VALUE)
2061 if (ret == PLAYER_ERROR_NONE) {
2062 intptr_t bo_addr = 0;
2063 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2064 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2071 static void _player_release_internal_memory(player_cli_s * pc)
2077 _player_deinit_memory_buffer(pc);
2080 static int _player_deinit_memory_buffer(player_cli_s * pc)
2082 PLAYER_INSTANCE_CHECK(pc);
2083 int ret = PLAYER_ERROR_NONE;
2084 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2085 intptr_t bo_addr = SERVER_TBM_BO(pc);
2090 player_msg_send1_async(api, pc, POINTER, bo_addr);
2092 SERVER_TBM_BO(pc) = 0;
2097 int player_get_state(player_h player, player_state_e * pstate)
2099 PLAYER_INSTANCE_CHECK(player);
2100 PLAYER_NULL_ARG_CHECK(pstate);
2101 int ret = PLAYER_ERROR_NONE;
2102 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
2103 player_cli_s *pc = (player_cli_s *) player;
2105 char *ret_buf = NULL;
2109 player_msg_send(api, pc, ret_buf, ret);
2111 if (ret == PLAYER_ERROR_NONE) {
2112 player_msg_get(state, ret_buf);
2120 int player_set_volume(player_h player, float left, float right)
2122 PLAYER_INSTANCE_CHECK(player);
2123 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2124 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2125 int ret = PLAYER_ERROR_NONE;
2126 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2127 player_cli_s *pc = (player_cli_s *) player;
2128 char *ret_buf = NULL;
2132 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, right, DOUBLE, left);
2137 int player_get_volume(player_h player, float *pleft, float *pright)
2139 PLAYER_INSTANCE_CHECK(player);
2140 PLAYER_NULL_ARG_CHECK(pleft && pright);
2141 int ret = PLAYER_ERROR_NONE;
2142 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2143 player_cli_s *pc = (player_cli_s *) player;
2146 char *ret_buf = NULL;
2150 player_msg_send(api, pc, ret_buf, ret);
2152 if (ret == PLAYER_ERROR_NONE) {
2153 bool ret_val = TRUE;
2154 player_msg_get2(ret_buf, left, DOUBLE, right, DOUBLE, ret_val);
2156 *pleft = (float)left;
2157 *pright = (float)right;
2159 LOGE("failed to get value from msg");
2160 ret = PLAYER_ERROR_INVALID_OPERATION;
2168 int player_set_sound_type(player_h player, sound_type_e type)
2170 PLAYER_INSTANCE_CHECK(player);
2171 int ret = PLAYER_ERROR_NONE;
2172 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_TYPE;
2173 player_cli_s *pc = (player_cli_s *) player;
2174 char *ret_buf = NULL;
2177 LOGW("DEPRECATION WARNING: player_set_sound_type() is deprecated and will be removed from next release. Use player_set_sound_stream_info() instead.");
2179 player_msg_send1(api, pc, ret_buf, ret, INT, type);
2184 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2186 PLAYER_INSTANCE_CHECK(player);
2188 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2189 player_cli_s *pc = (player_cli_s *) player;
2190 bool is_available = false;
2191 char *ret_buf = NULL;
2195 /* check if stream_info is valid */
2196 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2197 if (ret != SOUND_MANAGER_ERROR_NONE) {
2198 LOGE("failed to checking available stream info");
2199 return PLAYER_ERROR_INVALID_OPERATION;
2202 if (is_available == false) {
2203 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
2205 char *stream_type = NULL;
2206 int stream_index = 0;
2207 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2208 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2209 if (ret == SOUND_MANAGER_ERROR_NONE)
2210 player_msg_send2(api, pc, ret_buf, ret, STRING, stream_type, INT, stream_index);
2212 ret = PLAYER_ERROR_INVALID_OPERATION;
2215 LOGD("LEAVE ret: 0x%X", ret);
2222 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2224 PLAYER_INSTANCE_CHECK(player);
2225 int ret = PLAYER_ERROR_NONE;
2226 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2227 player_cli_s *pc = (player_cli_s *) player;
2228 char *ret_buf = NULL;
2232 player_msg_send1(api, pc, ret_buf, ret, INT, latency_mode);
2237 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2239 PLAYER_INSTANCE_CHECK(player);
2240 PLAYER_NULL_ARG_CHECK(platency_mode);
2241 int ret = PLAYER_ERROR_NONE;
2242 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2243 player_cli_s *pc = (player_cli_s *) player;
2244 char *ret_buf = NULL;
2245 int latency_mode = -1;
2249 player_msg_send(api, pc, ret_buf, ret);
2251 if (ret == PLAYER_ERROR_NONE) {
2252 player_msg_get(latency_mode, ret_buf);
2253 *platency_mode = latency_mode;
2261 int player_start(player_h player)
2263 PLAYER_INSTANCE_CHECK(player);
2264 int ret = PLAYER_ERROR_NONE;
2265 muse_player_api_e api = MUSE_PLAYER_API_START;
2266 player_cli_s *pc = (player_cli_s *) player;
2267 char *ret_buf = NULL;
2270 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2271 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2273 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2274 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2275 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2276 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2277 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), true);
2278 if (ret != MM_ERROR_NONE) {
2279 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2280 return PLAYER_ERROR_INVALID_OPERATION;
2282 /* avoid setting true at all times, when player is resumed */
2283 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2288 player_msg_send(api, pc, ret_buf, ret);
2294 int player_stop(player_h player)
2296 PLAYER_INSTANCE_CHECK(player);
2297 int ret = PLAYER_ERROR_NONE;
2298 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2299 player_cli_s *pc = (player_cli_s *) player;
2300 char *ret_buf = NULL;
2301 player_state_e state = PLAYER_STATE_NONE;
2302 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2303 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2307 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
2309 /* check player state */
2310 if (ret == PLAYER_ERROR_NONE) {
2311 player_msg_get(state, ret_buf);
2315 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2316 LOGE("Invalid state %d", state);
2317 return PLAYER_ERROR_INVALID_STATE;
2322 return PLAYER_ERROR_INVALID_OPERATION;
2325 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2326 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2327 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2328 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2329 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2330 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), false);
2331 if (ret != MM_ERROR_NONE) {
2332 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2333 return PLAYER_ERROR_INVALID_OPERATION;
2335 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2339 player_msg_send(api, pc, ret_buf, ret);
2340 if (ret == PLAYER_ERROR_NONE)
2341 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2347 int player_pause(player_h player)
2349 PLAYER_INSTANCE_CHECK(player);
2350 int ret = PLAYER_ERROR_NONE;
2351 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2352 player_cli_s *pc = (player_cli_s *) player;
2353 char *ret_buf = NULL;
2357 player_msg_send(api, pc, ret_buf, ret);
2362 int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data)
2364 PLAYER_INSTANCE_CHECK(player);
2365 PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2367 int ret = PLAYER_ERROR_NONE;
2368 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2369 player_cli_s *pc = (player_cli_s *) player;
2370 char *ret_buf = NULL;
2371 int pos = millisecond;
2375 LOGE("cb_info is null");
2376 return PLAYER_ERROR_INVALID_OPERATION;
2379 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2380 if ((pc->push_media_stream == FALSE) &&
2381 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2382 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2383 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2384 return PLAYER_ERROR_SEEK_FAILED;
2386 if (pc->push_media_stream == TRUE)
2387 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2389 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2390 LOGI("Event type : %d, pos : %d, accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond, accurate);
2391 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2392 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2394 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2396 player_msg_send2(api, pc, ret_buf, ret, INT, pos, INT, accurate);
2398 if (ret != PLAYER_ERROR_NONE) {
2399 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2400 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2401 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2404 if (pc->push_media_stream == TRUE)
2405 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2409 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2410 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2411 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2417 int player_get_play_position(player_h player, int *millisecond)
2419 PLAYER_INSTANCE_CHECK(player);
2420 PLAYER_NULL_ARG_CHECK(millisecond);
2422 int ret = PLAYER_ERROR_NONE;
2423 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2424 player_cli_s *pc = (player_cli_s *) player;
2426 char *ret_buf = NULL;
2430 player_msg_send(api, pc, ret_buf, ret);
2432 if (ret == PLAYER_ERROR_NONE) {
2433 player_msg_get(pos, ret_buf);
2441 int player_set_mute(player_h player, bool muted)
2443 PLAYER_INSTANCE_CHECK(player);
2444 int ret = PLAYER_ERROR_NONE;
2445 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2446 player_cli_s *pc = (player_cli_s *) player;
2447 char *ret_buf = NULL;
2448 int mute = (int)muted;
2452 player_msg_send1(api, pc, ret_buf, ret, INT, mute);
2457 int player_is_muted(player_h player, bool * muted)
2459 PLAYER_INSTANCE_CHECK(player);
2460 PLAYER_NULL_ARG_CHECK(muted);
2461 int ret = PLAYER_ERROR_NONE;
2462 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2463 player_cli_s *pc = (player_cli_s *) player;
2464 char *ret_buf = NULL;
2469 player_msg_send(api, pc, ret_buf, ret);
2470 if (ret == PLAYER_ERROR_NONE) {
2471 player_msg_get(mute, ret_buf);
2472 *muted = (bool) mute;
2479 int player_set_looping(player_h player, bool looping)
2481 PLAYER_INSTANCE_CHECK(player);
2482 int ret = PLAYER_ERROR_NONE;
2483 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2484 player_cli_s *pc = (player_cli_s *) player;
2485 char *ret_buf = NULL;
2489 player_msg_send1(api, pc, ret_buf, ret, INT, looping);
2494 int player_is_looping(player_h player, bool * plooping)
2496 PLAYER_INSTANCE_CHECK(player);
2497 PLAYER_NULL_ARG_CHECK(plooping);
2498 int ret = PLAYER_ERROR_NONE;
2499 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2500 player_cli_s *pc = (player_cli_s *) player;
2501 char *ret_buf = NULL;
2506 player_msg_send(api, pc, ret_buf, ret);
2507 if (ret == PLAYER_ERROR_NONE) {
2508 player_msg_get(looping, ret_buf);
2509 *plooping = looping;
2515 int player_get_duration(player_h player, int *pduration)
2517 PLAYER_INSTANCE_CHECK(player);
2518 PLAYER_NULL_ARG_CHECK(pduration);
2519 int ret = PLAYER_ERROR_NONE;
2520 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2521 player_cli_s *pc = (player_cli_s *) player;
2522 char *ret_buf = NULL;
2527 player_msg_send(api, pc, ret_buf, ret);
2528 if (ret == PLAYER_ERROR_NONE) {
2529 player_msg_get(duration, ret_buf);
2530 *pduration = duration;
2537 /* The player_display_type_e is different at wearable profile */
2538 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2540 int ret = PLAYER_ERROR_NONE;
2541 PLAYER_NULL_ARG_CHECK(out_type);
2544 case PLAYER_DISPLAY_TYPE_OVERLAY:
2545 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2547 case PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE:
2548 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2549 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2551 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2553 case PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS:
2554 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2555 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2557 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2559 case PLAYER_DISPLAY_TYPE_EVAS:
2560 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2562 case PLAYER_DISPLAY_TYPE_NONE:
2563 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2566 ret = PLAYER_ERROR_INVALID_PARAMETER;
2570 LOGD("display type(%d) -> (%d)", type, *out_type);
2574 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2576 PLAYER_INSTANCE_CHECK(player);
2577 int ret = PLAYER_ERROR_NONE;
2578 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2579 player_cli_s *pc = (player_cli_s *) player;
2580 char *ret_buf = NULL;
2581 wl_win_msg_type wl_win;
2582 char *wl_win_msg = (char *)&wl_win;
2583 unsigned int wl_surface_id;
2584 player_private_display_type_e conv_type;
2585 player_state_e state = PLAYER_STATE_NONE;
2586 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
2587 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2588 int (*p_disp_destroy_evas_display)(void **) = NULL;
2589 int (*p_disp_create_evas_display)(void *, void **) = NULL;
2590 int (*p_disp_set_evas_display_old_info)(void *, void *, int, int, int) = NULL;
2591 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2592 void (*p_disp_get_evas_display_geometry_info)(void *, int *, int *, int *, int *) = NULL;
2593 void (*p_disp_media_packet_video_decode_cb)(media_packet_h, void *) = NULL;
2597 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2600 wl_win.wl_window_x = 0;
2601 wl_win.wl_window_y = 0;
2602 wl_win.wl_window_width = 0;
2603 wl_win.wl_window_height = 0;
2605 LOGD("ENTER type: %d", type);
2606 if (type == PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE ||
2607 type == PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS) {
2608 LOGW("DEPRECATION WARNING: display type(%d) is deprecated and will be removed from next release. Use newly defined type value instead.", type);
2611 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
2613 /* check player state */
2614 if (ret == PLAYER_ERROR_NONE) {
2615 player_msg_get(state, ret_buf);
2619 if (state > PLAYER_STATE_IDLE) {
2620 LOGE("Invalid state %d", state);
2621 return PLAYER_ERROR_INVALID_STATE;
2626 return PLAYER_ERROR_INVALID_OPERATION;
2629 ret = _player_convert_display_type(type, &conv_type);
2630 if (ret != PLAYER_ERROR_NONE)
2633 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2635 return PLAYER_ERROR_INVALID_PARAMETER;
2637 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2639 * To support repeating play and stop, Evas_handle should not be destroyed in player_unprepare.
2640 * When the display type changes, Player need to destroy Evas_handle to set values of video output,
2641 * Otherwise, the values is not set because of checking Evas_handle.
2643 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
2644 LOGW("evas client already exists");
2645 player_unset_media_packet_video_frame_decoded_cb(player);
2646 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2647 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2648 LOGW("fail to unset evas client");
2649 __player_unset_retrieve_buffer_cb(player);
2650 /* need to set display information again to new handle */
2651 EVAS_INFO(pc)->update_needed = TRUE;
2654 /* set evas_render or wayland */
2655 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
2656 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
2657 wl_surface_id = p_disp_set_wl_display(ELM_WAYLAND_WIN, display);
2658 if (wl_surface_id > 0) {
2659 wl_win.wl_surface_id = wl_surface_id;
2660 wl_win.type = conv_type;
2661 } else return PLAYER_ERROR_INVALID_OPERATION;
2663 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2664 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS) {
2665 if (!CALLBACK_INFO(pc)) {
2666 LOGE("there is no cb info in player handle");
2667 return PLAYER_ERROR_INVALID_OPERATION;
2670 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_create_evas_display, "disp_create_evas_display");
2671 ret = p_disp_create_evas_display(display, &EVAS_HANDLE(pc));
2672 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2674 /* before evas handle is created, user could set display information */
2675 if (EVAS_INFO(pc)->update_needed) {
2676 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_old_info, "disp_set_evas_display_old_info");
2677 ret = p_disp_set_evas_display_old_info(display, EVAS_HANDLE(pc), EVAS_INFO(pc)->mode, EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2678 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2679 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2680 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2681 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), EVAS_INFO(pc)->roi_x, EVAS_INFO(pc)->roi_y, EVAS_INFO(pc)->roi_w, EVAS_INFO(pc)->roi_h);
2682 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2684 EVAS_INFO(pc)->update_needed = FALSE;
2686 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_geometry_info, "disp_get_evas_display_geometry_info");
2687 p_disp_get_evas_display_geometry_info(display, &wl_win.wl_window_x, &wl_win.wl_window_y, &wl_win.wl_window_width, &wl_win.wl_window_height);
2688 wl_win.type = conv_type;
2690 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_media_packet_video_decode_cb, "disp_media_packet_video_decode_cb");
2691 ret = player_set_media_packet_video_frame_decoded_cb(player, p_disp_media_packet_video_decode_cb, (void *)EVAS_HANDLE(pc));
2692 if (ret != PLAYER_ERROR_NONE)
2693 LOGW("fail to set decoded callback");
2694 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2695 LOGW("fail to set __retrieve_buffer_cb");
2698 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2699 LOGI("Wayland surface type is NONE");
2700 wl_win.type = conv_type;
2702 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2708 int player_set_display_mode(player_h player, player_display_mode_e mode)
2710 PLAYER_INSTANCE_CHECK(player);
2711 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2712 int ret = PLAYER_ERROR_NONE;
2713 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
2714 player_cli_s *pc = (player_cli_s *) player;
2715 char *ret_buf = NULL;
2716 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2717 int (*p_disp_set_evas_display_disp_mode)(void *, int) = NULL;
2720 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2722 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2723 if (EVAS_HANDLE(pc)) {
2724 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_disp_mode, "disp_set_evas_display_disp_mode");
2725 ret = p_disp_set_evas_display_disp_mode(EVAS_HANDLE(pc), mode);
2726 if (ret != MM_ERROR_NONE)
2727 return PLAYER_ERROR_INVALID_OPERATION;
2729 return PLAYER_ERROR_NONE;
2731 EVAS_INFO(pc)->mode = mode;
2732 EVAS_INFO(pc)->update_needed = TRUE;
2735 player_msg_send1(api, pc, ret_buf, ret, INT, mode);
2740 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
2742 PLAYER_INSTANCE_CHECK(player);
2743 PLAYER_NULL_ARG_CHECK(pmode);
2744 int ret = PLAYER_ERROR_NONE;
2745 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
2746 player_cli_s *pc = (player_cli_s *) player;
2747 char *ret_buf = NULL;
2749 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2750 int (*p_disp_get_evas_display_disp_mode)(void *, int *) = NULL;
2754 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2756 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2757 if (EVAS_HANDLE(pc)) {
2758 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_disp_mode, "disp_get_evas_display_disp_mode");
2759 ret = p_disp_get_evas_display_disp_mode(EVAS_HANDLE(pc), &mode);
2760 *pmode = (player_display_mode_e) mode;
2761 if (ret != MM_ERROR_NONE)
2762 return PLAYER_ERROR_INVALID_OPERATION;
2764 return PLAYER_ERROR_NONE;
2767 player_msg_send(api, pc, ret_buf, ret);
2768 if (ret == PLAYER_ERROR_NONE) {
2769 player_msg_get_type(mode, ret_buf, INT);
2778 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
2780 PLAYER_INSTANCE_CHECK(player);
2781 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2783 int ret = PLAYER_ERROR_NONE;
2784 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
2785 player_cli_s *pc = (player_cli_s *) player;
2786 char *ret_buf = NULL;
2787 wl_win_msg_type wl_win;
2788 char *wl_win_msg = (char *)&wl_win;
2789 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2790 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2794 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2796 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2797 if (EVAS_HANDLE(pc)) {
2798 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2799 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), x, y, width, height);
2800 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
2801 return PLAYER_ERROR_INVALID_PARAMETER;
2802 else if (ret != MM_ERROR_NONE)
2803 return PLAYER_ERROR_INVALID_OPERATION;
2805 return PLAYER_ERROR_NONE;
2807 EVAS_INFO(pc)->roi_x = x;
2808 EVAS_INFO(pc)->roi_y = y;
2809 EVAS_INFO(pc)->roi_w = width;
2810 EVAS_INFO(pc)->roi_h = height;
2811 EVAS_INFO(pc)->update_needed = TRUE;
2814 wl_win.wl_window_x = x;
2815 wl_win.wl_window_y = y;
2816 wl_win.wl_window_width = width;
2817 wl_win.wl_window_height = height;
2819 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2824 int player_set_playback_rate(player_h player, float rate)
2826 PLAYER_INSTANCE_CHECK(player);
2827 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2828 int ret = PLAYER_ERROR_NONE;
2829 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
2830 player_cli_s *pc = (player_cli_s *) player;
2831 char *ret_buf = NULL;
2835 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
2840 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
2842 PLAYER_INSTANCE_CHECK(player);
2843 int ret = PLAYER_ERROR_NONE;
2844 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
2845 player_cli_s *pc = (player_cli_s *) player;
2846 char *ret_buf = NULL;
2847 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2848 int (*p_disp_set_evas_display_rotation)(void *, int) = NULL;
2852 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2854 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2855 if (EVAS_HANDLE(pc)) {
2856 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_rotation, "disp_set_evas_display_rotation");
2857 ret = p_disp_set_evas_display_rotation(EVAS_HANDLE(pc), rotation);
2858 if (ret != MM_ERROR_NONE)
2859 return PLAYER_ERROR_INVALID_OPERATION;
2861 return PLAYER_ERROR_NONE;
2863 EVAS_INFO(pc)->rotation = rotation;
2864 EVAS_INFO(pc)->update_needed = TRUE;
2867 player_msg_send1(api, pc, ret_buf, ret, INT, rotation);
2872 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
2874 PLAYER_INSTANCE_CHECK(player);
2875 PLAYER_NULL_ARG_CHECK(protation);
2876 int ret = PLAYER_ERROR_NONE;
2877 player_cli_s *pc = (player_cli_s *) player;
2878 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
2879 char *ret_buf = NULL;
2881 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2882 int (*p_disp_get_evas_display_rotation)(void *, int *) = NULL;
2886 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2888 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2889 if (EVAS_HANDLE(pc)) {
2890 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_rotation, "disp_get_evas_display_rotation");
2891 ret = p_disp_get_evas_display_rotation(EVAS_HANDLE(pc), &rotation);
2892 *protation = (player_display_rotation_e) rotation;
2893 if (ret != MM_ERROR_NONE)
2894 return PLAYER_ERROR_INVALID_OPERATION;
2896 return PLAYER_ERROR_NONE;
2899 player_msg_send(api, pc, ret_buf, ret);
2900 if (ret == PLAYER_ERROR_NONE) {
2901 player_msg_get_type(rotation, ret_buf, INT);
2902 *protation = rotation;
2909 int player_set_display_visible(player_h player, bool visible)
2911 PLAYER_INSTANCE_CHECK(player);
2912 int ret = PLAYER_ERROR_NONE;
2913 player_cli_s *pc = (player_cli_s *) player;
2914 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
2915 char *ret_buf = NULL;
2916 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2917 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2921 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2923 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2924 if (EVAS_HANDLE(pc)) {
2925 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2926 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), visible);
2927 if (ret != MM_ERROR_NONE)
2928 return PLAYER_ERROR_INVALID_OPERATION;
2930 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
2931 return PLAYER_ERROR_NONE;
2933 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
2934 EVAS_INFO(pc)->update_needed = TRUE;
2938 player_msg_send1(api, pc, ret_buf, ret, INT, visible);
2943 int player_is_display_visible(player_h player, bool * pvisible)
2945 PLAYER_INSTANCE_CHECK(player);
2946 PLAYER_NULL_ARG_CHECK(pvisible);
2947 int ret = PLAYER_ERROR_NONE;
2948 player_cli_s *pc = (player_cli_s *) player;
2949 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
2950 char *ret_buf = NULL;
2952 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2954 int (*p_disp_get_evas_display_visible)(void *, bool *) = NULL;
2958 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2960 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2961 if (EVAS_HANDLE(pc)) {
2962 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_visible, "disp_get_evas_display_visible");
2963 ret = p_disp_get_evas_display_visible(EVAS_HANDLE(pc), &visible);
2969 if (ret != MM_ERROR_NONE)
2970 return PLAYER_ERROR_INVALID_OPERATION;
2972 return PLAYER_ERROR_NONE;
2975 player_msg_send(api, pc, ret_buf, ret);
2976 if (ret == PLAYER_ERROR_NONE) {
2977 player_msg_get_type(value, ret_buf, INT);
2989 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
2991 PLAYER_INSTANCE_CHECK(player);
2992 PLAYER_NULL_ARG_CHECK(pvalue);
2993 int ret = PLAYER_ERROR_NONE;
2994 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
2995 player_cli_s *pc = (player_cli_s *) player;
2996 char *ret_buf = NULL;
2997 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3001 player_msg_send1(api, pc, ret_buf, ret, INT, key);
3002 if (ret == PLAYER_ERROR_NONE) {
3003 player_msg_get_string(value, ret_buf);
3004 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3010 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3012 PLAYER_INSTANCE_CHECK(player);
3013 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3014 int ret = PLAYER_ERROR_NONE;
3015 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3016 player_cli_s *pc = (player_cli_s *) player;
3017 char *ret_buf = NULL;
3018 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3019 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3020 bool ret_val = TRUE;
3024 player_msg_send(api, pc, ret_buf, ret);
3025 if (ret == PLAYER_ERROR_NONE) {
3026 player_msg_get_string2(ret_buf, video_codec, audio_codec, ret_val);
3029 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3031 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3033 ret = PLAYER_ERROR_INVALID_OPERATION;
3040 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3042 PLAYER_INSTANCE_CHECK(player);
3043 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3044 int ret = PLAYER_ERROR_NONE;
3045 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3046 player_cli_s *pc = (player_cli_s *) player;
3047 char *ret_buf = NULL;
3048 int sample_rate = 0;
3054 player_msg_send(api, pc, ret_buf, ret);
3055 if (ret == PLAYER_ERROR_NONE) {
3056 bool ret_val = TRUE;
3057 player_msg_get3(ret_buf, sample_rate, INT, channel, INT, bit_rate, INT, ret_val);
3060 *psample_rate = sample_rate;
3062 *pchannel = channel;
3064 *pbit_rate = bit_rate;
3066 ret = PLAYER_ERROR_INVALID_OPERATION;
3073 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3075 PLAYER_INSTANCE_CHECK(player);
3076 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3077 int ret = PLAYER_ERROR_NONE;
3078 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3079 player_cli_s *pc = (player_cli_s *) player;
3080 char *ret_buf = NULL;
3086 player_msg_send(api, pc, ret_buf, ret);
3087 if (ret == PLAYER_ERROR_NONE) {
3088 bool ret_val = TRUE;
3089 player_msg_get2(ret_buf, fps, INT, bit_rate, INT, ret_val);
3094 *pbit_rate = bit_rate;
3096 ret = PLAYER_ERROR_INVALID_OPERATION;
3103 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3105 PLAYER_INSTANCE_CHECK(player);
3106 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3107 int ret = PLAYER_ERROR_NONE;
3108 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3109 player_cli_s *pc = (player_cli_s *) player;
3110 char *ret_buf = NULL;
3116 player_msg_send(api, pc, ret_buf, ret);
3117 if (ret == PLAYER_ERROR_NONE) {
3118 bool ret_val = TRUE;
3119 player_msg_get2(ret_buf, width, INT, height, INT, ret_val);
3124 ret = PLAYER_ERROR_INVALID_OPERATION;
3131 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3133 PLAYER_INSTANCE_CHECK(player);
3134 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3135 int ret = PLAYER_ERROR_NONE;
3136 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3137 player_cli_s *pc = (player_cli_s *) player;
3138 char *ret_buf = NULL;
3142 tbm_bo_handle thandle;
3143 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3144 int key = INVALID_DEFAULT_VALUE;
3149 player_msg_send(api, pc, ret_buf, ret);
3150 if (ret == PLAYER_ERROR_NONE) {
3151 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3152 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3154 LOGE("failed to get msg obj, err:%d", err);
3155 ret = PLAYER_ERROR_INVALID_OPERATION;
3159 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3160 LOGD("size : %d", size);
3161 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3162 LOGE("failed to get key value");
3163 ret = PLAYER_ERROR_INVALID_OPERATION;
3167 tfd = pc->cb_info->tfd;
3169 LOGE("failed to get tbm fd value");
3170 ret = PLAYER_ERROR_INVALID_OPERATION;
3174 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3176 LOGE("TBM get error : bo is NULL");
3177 ret = PLAYER_ERROR_INVALID_OPERATION;
3180 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3181 if (thandle.ptr == NULL) {
3182 LOGE("TBM get error : handle pointer is NULL");
3183 ret = PLAYER_ERROR_INVALID_OPERATION;
3186 album_art = _get_mem(pc, size);
3188 memcpy(album_art, thandle.ptr, size);
3189 *palbum_art = album_art;
3191 LOGE("g_new failure");
3192 ret = PLAYER_ERROR_INVALID_OPERATION;
3204 muse_core_msg_object_free(jobj);
3209 if (tfd > INVALID_DEFAULT_VALUE)
3212 if (CALLBACK_INFO(pc))
3213 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3219 if (key > INVALID_DEFAULT_VALUE) {
3220 LOGD("send msg to release buffer. key:%d", key);
3221 player_msg_send1_async(MUSE_PLAYER_API_RETURN_BUFFER, pc, INT, key);
3227 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3229 PLAYER_INSTANCE_CHECK(player);
3230 PLAYER_NULL_ARG_CHECK(pcount);
3231 int ret = PLAYER_ERROR_NONE;
3232 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3233 player_cli_s *pc = (player_cli_s *) player;
3234 char *ret_buf = NULL;
3239 player_msg_send(api, pc, ret_buf, ret);
3240 if (ret == PLAYER_ERROR_NONE) {
3241 player_msg_get(count, ret_buf);
3248 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3250 PLAYER_INSTANCE_CHECK(player);
3251 PLAYER_NULL_ARG_CHECK(band_levels);
3252 int ret = PLAYER_ERROR_NONE;
3253 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3254 player_cli_s *pc = (player_cli_s *) player;
3255 char *ret_buf = NULL;
3259 player_msg_send_array(api, pc, ret_buf, ret, band_levels, length, sizeof(int));
3266 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3268 PLAYER_INSTANCE_CHECK(player);
3269 int ret = PLAYER_ERROR_NONE;
3270 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3271 player_cli_s *pc = (player_cli_s *) player;
3272 char *ret_buf = NULL;
3276 player_msg_send2(api, pc, ret_buf, ret, INT, index, INT, level);
3282 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3284 PLAYER_INSTANCE_CHECK(player);
3285 PLAYER_NULL_ARG_CHECK(plevel);
3286 int ret = PLAYER_ERROR_NONE;
3287 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3288 player_cli_s *pc = (player_cli_s *) player;
3289 char *ret_buf = NULL;
3294 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3295 if (ret == PLAYER_ERROR_NONE) {
3296 player_msg_get(level, ret_buf);
3303 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3305 PLAYER_INSTANCE_CHECK(player);
3306 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3307 int ret = PLAYER_ERROR_NONE;
3308 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3309 player_cli_s *pc = (player_cli_s *) player;
3310 char *ret_buf = NULL;
3311 int min = 0, max = 0;
3315 player_msg_send(api, pc, ret_buf, ret);
3316 if (ret == PLAYER_ERROR_NONE) {
3317 bool ret_val = TRUE;
3318 player_msg_get2(ret_buf, min, INT, max, INT, ret_val);
3323 ret = PLAYER_ERROR_INVALID_OPERATION;
3330 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3332 PLAYER_INSTANCE_CHECK(player);
3333 PLAYER_NULL_ARG_CHECK(pfrequency);
3334 int ret = PLAYER_ERROR_NONE;
3335 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3336 player_cli_s *pc = (player_cli_s *) player;
3337 char *ret_buf = NULL;
3342 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3343 if (ret == PLAYER_ERROR_NONE) {
3344 player_msg_get(frequency, ret_buf);
3345 *pfrequency = frequency;
3351 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3353 PLAYER_INSTANCE_CHECK(player);
3354 PLAYER_NULL_ARG_CHECK(prange);
3355 int ret = PLAYER_ERROR_NONE;
3356 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3357 player_cli_s *pc = (player_cli_s *) player;
3358 char *ret_buf = NULL;
3363 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3364 if (ret == PLAYER_ERROR_NONE) {
3365 player_msg_get(range, ret_buf);
3372 int player_audio_effect_equalizer_clear(player_h player)
3374 PLAYER_INSTANCE_CHECK(player);
3375 int ret = PLAYER_ERROR_NONE;
3376 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3377 player_cli_s *pc = (player_cli_s *) player;
3378 char *ret_buf = NULL;
3382 player_msg_send(api, pc, ret_buf, ret);
3387 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3389 PLAYER_INSTANCE_CHECK(player);
3390 PLAYER_NULL_ARG_CHECK(pavailable);
3391 int ret = PLAYER_ERROR_NONE;
3392 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3393 player_cli_s *pc = (player_cli_s *) player;
3394 char *ret_buf = NULL;
3399 player_msg_send(api, pc, ret_buf, ret);
3400 if (ret == PLAYER_ERROR_NONE) {
3401 player_msg_get(available, ret_buf);
3402 *pavailable = available;
3408 int player_set_subtitle_path(player_h player, const char *path)
3410 PLAYER_INSTANCE_CHECK(player);
3411 int ret = PLAYER_ERROR_NONE;
3412 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3413 player_cli_s *pc = (player_cli_s *) player;
3414 char *ret_buf = NULL;
3415 char subtitle_path[MAX_URL_LEN] = {0, };
3419 if (path && _player_get_origin_internal_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3420 return PLAYER_ERROR_INVALID_PARAMETER;
3422 player_msg_send1(api, pc, ret_buf, ret, STRING, subtitle_path);
3427 int player_set_subtitle_position_offset(player_h player, int millisecond)
3429 PLAYER_INSTANCE_CHECK(player);
3430 int ret = PLAYER_ERROR_NONE;
3431 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3432 player_cli_s *pc = (player_cli_s *) player;
3433 char *ret_buf = NULL;
3437 player_msg_send1(api, pc, ret_buf, ret, INT, millisecond);
3443 int player_set_progressive_download_path(player_h player, const char *path)
3445 PLAYER_INSTANCE_CHECK(player);
3446 PLAYER_NULL_ARG_CHECK(path);
3447 int ret = PLAYER_ERROR_NONE;
3448 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
3449 player_cli_s *pc = (player_cli_s *) player;
3450 char *ret_buf = NULL;
3451 char dw_path[MAX_URL_LEN] = {0, };
3454 LOGW("DEPRECATION WARNING: player_set_progressive_download_path() is deprecated and will be removed from next release.");
3456 if (!_player_check_network_availability())
3457 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3459 if (_player_get_origin_internal_path(path, dw_path) != PLAYER_ERROR_NONE)
3460 return PLAYER_ERROR_INVALID_PARAMETER;
3462 player_msg_send1(api, pc, ret_buf, ret, STRING, dw_path);
3467 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
3469 PLAYER_INSTANCE_CHECK(player);
3470 PLAYER_NULL_ARG_CHECK(pcurrent && ptotal_size);
3471 int ret = PLAYER_ERROR_NONE;
3472 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
3473 player_cli_s *pc = (player_cli_s *) player;
3474 char *ret_buf = NULL;
3475 unsigned long current, total_size;
3478 LOGW("DEPRECATION WARNING: player_get_progressive_download_status() is deprecated and will be removed from next release.");
3480 player_msg_send(api, pc, ret_buf, ret);
3481 if (ret == PLAYER_ERROR_NONE) {
3482 bool ret_val = TRUE;
3483 player_msg_get2(ret_buf, current, POINTER, total_size, POINTER, ret_val);
3485 *pcurrent = current;
3486 *ptotal_size = total_size;
3488 ret = PLAYER_ERROR_INVALID_OPERATION;
3496 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3498 PLAYER_INSTANCE_CHECK(player);
3499 PLAYER_NULL_ARG_CHECK(callback);
3500 int ret = PLAYER_ERROR_NONE;
3501 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3502 player_cli_s *pc = (player_cli_s *) player;
3503 char *ret_buf = NULL;
3506 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3507 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3508 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3510 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3511 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3512 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3515 player_msg_send(api, pc, ret_buf, ret);
3517 if (ret != PLAYER_ERROR_NONE)
3518 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3524 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3526 PLAYER_INSTANCE_CHECK(player);
3527 PLAYER_NULL_ARG_CHECK(cookie);
3528 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3529 int ret = PLAYER_ERROR_NONE;
3530 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3531 player_cli_s *pc = (player_cli_s *) player;
3532 char *ret_buf = NULL;
3536 player_msg_send2(api, pc, ret_buf, ret, STRING, cookie, INT, size);
3541 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3543 PLAYER_INSTANCE_CHECK(player);
3544 PLAYER_NULL_ARG_CHECK(user_agent);
3545 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3546 int ret = PLAYER_ERROR_NONE;
3547 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3548 player_cli_s *pc = (player_cli_s *) player;
3549 char *ret_buf = NULL;
3553 player_msg_send2(api, pc, ret_buf, ret, STRING, user_agent, INT, size);
3558 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3560 PLAYER_INSTANCE_CHECK(player);
3561 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3562 int ret = PLAYER_ERROR_NONE;
3563 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3564 player_cli_s *pc = (player_cli_s *) player;
3565 char *ret_buf = NULL;
3566 int start = 0, current = 0;
3570 player_msg_send(api, pc, ret_buf, ret);
3571 if (ret == PLAYER_ERROR_NONE) {
3572 bool ret_val = TRUE;
3573 player_msg_get2(ret_buf, start, INT, current, INT, ret_val);
3576 *pcurrent = current;
3578 ret = PLAYER_ERROR_INVALID_OPERATION;
3586 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3588 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3591 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3592 static void __retrieve_buffer_cb(void *user_data)
3594 player_cli_s *player = (player_cli_s *)user_data;
3595 int ret = PLAYER_ERROR_NONE;
3596 bool gapless = false;
3597 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
3599 ret = player_is_gapless((player_h)user_data, &gapless);
3600 if (ret != PLAYER_ERROR_NONE) {
3601 LOGW("player_is_gapless is failed");
3605 PLAYER_DISP_DLSYM(player->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
3606 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3607 if (ret != PLAYER_ERROR_NONE)
3608 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3611 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3613 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3616 static int __player_unset_retrieve_buffer_cb(player_h player)
3618 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3622 int player_unset_completed_cb(player_h player)
3624 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3627 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3629 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3632 int player_unset_interrupted_cb(player_h player)
3634 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3637 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3639 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3642 int player_unset_error_cb(player_h player)
3644 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3647 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3649 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3652 int player_unset_buffering_cb(player_h player)
3654 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3657 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3659 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3662 int player_unset_subtitle_updated_cb(player_h player)
3664 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3667 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3669 PLAYER_INSTANCE_CHECK(player);
3670 PLAYER_NULL_ARG_CHECK(callback);
3671 int ret = PLAYER_ERROR_NONE;
3672 player_cli_s *pc = (player_cli_s *) player;
3673 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3674 char *ret_buf = NULL;
3675 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3679 LOGW("DEPRECATION WARNING: player_set_progressive_download_message_cb() is deprecated and will be removed from next release.");
3681 if (!_player_check_network_availability())
3682 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3684 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3686 if (ret == PLAYER_ERROR_NONE) {
3687 pc->cb_info->user_cb[type] = callback;
3688 pc->cb_info->user_data[type] = user_data;
3689 LOGI("Event type : %d ", type);
3696 int player_unset_progressive_download_message_cb(player_h player)
3698 PLAYER_INSTANCE_CHECK(player);
3699 int ret = PLAYER_ERROR_NONE;
3700 player_cli_s *pc = (player_cli_s *) player;
3701 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3702 char *ret_buf = NULL;
3703 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3707 LOGW("DEPRECATION WARNING: player_unset_progressive_download_message_cb() is deprecated and will be removed from next release.");
3709 set_null_user_cb_lock(pc->cb_info, type);
3711 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3718 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
3720 PLAYER_INSTANCE_CHECK(player);
3721 PLAYER_NULL_ARG_CHECK(callback);
3722 int ret = PLAYER_ERROR_NONE;
3723 player_cli_s *pc = (player_cli_s *) player;
3724 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3725 char *ret_buf = NULL;
3726 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3731 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3733 if (ret == PLAYER_ERROR_NONE) {
3734 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
3735 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
3736 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
3743 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
3745 PLAYER_INSTANCE_CHECK(player);
3746 int ret = PLAYER_ERROR_NONE;
3747 player_cli_s *pc = (player_cli_s *) player;
3748 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3749 char *ret_buf = NULL;
3750 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3755 set_null_user_cb_lock(pc->cb_info, type);
3757 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3763 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
3765 PLAYER_INSTANCE_CHECK(player);
3766 PLAYER_NULL_ARG_CHECK(callback);
3767 int ret = PLAYER_ERROR_NONE;
3768 player_cli_s *pc = (player_cli_s *) player;
3769 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3770 char *ret_buf = NULL;
3771 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3776 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3778 if (ret == PLAYER_ERROR_NONE) {
3779 pc->cb_info->user_cb[type] = callback;
3780 pc->cb_info->user_data[type] = user_data;
3781 LOGI("Event type : %d ", type);
3788 int player_unset_video_stream_changed_cb(player_h player)
3790 PLAYER_INSTANCE_CHECK(player);
3791 int ret = PLAYER_ERROR_NONE;
3792 player_cli_s *pc = (player_cli_s *) player;
3793 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3794 char *ret_buf = NULL;
3795 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3800 set_null_user_cb_lock(pc->cb_info, type);
3802 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3808 int player_set_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type, player_media_stream_buffer_status_cb callback, void *user_data)
3810 PLAYER_INSTANCE_CHECK(player);
3811 PLAYER_NULL_ARG_CHECK(callback);
3812 int ret = PLAYER_ERROR_NONE;
3813 player_cli_s *pc = (player_cli_s *) player;
3814 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3815 char *ret_buf = NULL;
3816 muse_player_event_e type;
3821 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3822 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3823 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3824 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3826 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3827 return PLAYER_ERROR_INVALID_PARAMETER;
3830 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3832 if (ret == PLAYER_ERROR_NONE) {
3833 pc->cb_info->user_cb[type] = callback;
3834 pc->cb_info->user_data[type] = user_data;
3835 LOGI("Event type : %d ", type);
3842 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
3844 PLAYER_INSTANCE_CHECK(player);
3845 int ret = PLAYER_ERROR_NONE;
3846 player_cli_s *pc = (player_cli_s *) player;
3847 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3848 char *ret_buf = NULL;
3849 muse_player_event_e type;
3854 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3855 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3856 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3857 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3859 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3860 return PLAYER_ERROR_INVALID_PARAMETER;
3863 set_null_user_cb_lock(pc->cb_info, type);
3865 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3871 int player_set_media_stream_seek_cb(player_h player, player_stream_type_e stream_type, player_media_stream_seek_cb callback, void *user_data)
3873 PLAYER_INSTANCE_CHECK(player);
3874 PLAYER_NULL_ARG_CHECK(callback);
3875 int ret = PLAYER_ERROR_NONE;
3876 player_cli_s *pc = (player_cli_s *) player;
3877 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3878 char *ret_buf = NULL;
3879 muse_player_event_e type;
3884 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3885 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3886 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3887 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3889 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3890 return PLAYER_ERROR_INVALID_PARAMETER;
3893 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3895 if (ret == PLAYER_ERROR_NONE) {
3896 pc->cb_info->user_cb[type] = callback;
3897 pc->cb_info->user_data[type] = user_data;
3898 LOGI("Event type : %d ", type);
3905 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
3907 PLAYER_INSTANCE_CHECK(player);
3908 int ret = PLAYER_ERROR_NONE;
3909 player_cli_s *pc = (player_cli_s *) player;
3910 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3911 char *ret_buf = NULL;
3912 muse_player_event_e type;
3917 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3918 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3919 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3920 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3922 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3923 return PLAYER_ERROR_INVALID_PARAMETER;
3926 set_null_user_cb_lock(pc->cb_info, type);
3928 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3934 /* TODO Implement raw data socket channel */
3935 int player_push_media_stream(player_h player, media_packet_h packet)
3937 PLAYER_INSTANCE_CHECK(player);
3938 PLAYER_NULL_ARG_CHECK(packet);
3939 int ret = PLAYER_ERROR_NONE;
3940 player_cli_s *pc = (player_cli_s *) player;
3941 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
3942 char *ret_buf = NULL;
3943 player_push_media_msg_type push_media;
3944 char *push_media_msg = (char *)&push_media;
3945 int msg_size = sizeof(player_push_media_msg_type);
3949 tbm_bo_handle thandle;
3950 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3953 media_format_h format;
3959 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
3960 media_packet_get_buffer_size(packet, &push_media.size);
3961 media_packet_get_pts(packet, &push_media.pts);
3962 media_packet_get_format(packet, &format);
3963 media_packet_get_flags(packet, &push_media.flags);
3965 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
3967 media_packet_is_video(packet, &is_video);
3968 media_packet_is_audio(packet, &is_audio);
3970 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
3972 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
3974 media_format_unref(format);
3977 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
3978 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
3980 LOGE("TBM get error : bo is NULL");
3981 return PLAYER_ERROR_INVALID_OPERATION;
3983 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
3984 if (thandle.ptr == NULL) {
3985 LOGE("TBM get error : handle pointer is NULL");
3986 ret = PLAYER_ERROR_INVALID_OPERATION;
3989 memcpy(thandle.ptr, buf, push_media.size);
3992 tfd = tbm_bo_export_fd(bo);
3994 LOGE("tbm_bo_export_fd err 0x%x", tfd);
3995 ret = PLAYER_ERROR_INVALID_OPERATION;
3999 player_msg_send_array_fd(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), tfd);
4000 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4001 buf_size = (int)push_media.size;
4002 player_msg_send_array2(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), buf, buf_size, sizeof(char));
4005 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4006 buf_size = (int)push_media.size;
4007 muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts);
4008 player_msg_send_array(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char));
4011 LOGD("ret_buf %s", ret_buf);
4015 if (tfd > INVALID_DEFAULT_VALUE)
4018 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4026 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4028 PLAYER_INSTANCE_CHECK(player);
4029 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4030 int ret = PLAYER_ERROR_NONE;
4031 player_cli_s *pc = (player_cli_s *) player;
4032 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4033 char *ret_buf = NULL;
4034 media_format_mimetype_e mimetype;
4046 media_format_ref(format);
4047 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4048 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4049 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4050 LOGE("failed to get video info from format.");
4051 return PLAYER_ERROR_INVALID_PARAMETER;
4054 player_msg_send7(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, width, INT, height, INT, avg_bps, INT, max_bps, INT, frame_rate);
4055 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4056 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4057 LOGE("failed to get audio info from format.");
4058 return PLAYER_ERROR_INVALID_PARAMETER;
4060 player_msg_send6(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, channel, INT, samplerate, INT, avg_bps, INT, bit);
4062 media_format_unref(format);
4063 pc->push_media_stream = TRUE;
4069 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4071 int ret = PLAYER_ERROR_NONE;
4072 PLAYER_INSTANCE_CHECK(player);
4073 player_cli_s *pc = (player_cli_s *) player;
4074 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4075 char *ret_buf = NULL;
4079 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT64, max_size);
4085 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4087 int ret = PLAYER_ERROR_NONE;
4088 PLAYER_INSTANCE_CHECK(player);
4089 PLAYER_NULL_ARG_CHECK(pmax_size);
4090 player_cli_s *pc = (player_cli_s *) player;
4091 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4092 char *ret_buf = NULL;
4093 unsigned long long max_size;
4097 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4098 if (ret == PLAYER_ERROR_NONE) {
4099 player_msg_get_type(max_size, ret_buf, INT64);
4100 *pmax_size = max_size;
4106 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4108 int ret = PLAYER_ERROR_NONE;
4109 PLAYER_INSTANCE_CHECK(player);
4110 player_cli_s *pc = (player_cli_s *) player;
4111 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4112 char *ret_buf = NULL;
4116 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, percent);
4122 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4124 int ret = PLAYER_ERROR_NONE;
4125 PLAYER_INSTANCE_CHECK(player);
4126 PLAYER_NULL_ARG_CHECK(ppercent);
4127 player_cli_s *pc = (player_cli_s *) player;
4128 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4129 char *ret_buf = NULL;
4134 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4135 if (ret == PLAYER_ERROR_NONE) {
4136 player_msg_get(percent, ret_buf);
4137 *ppercent = percent;
4144 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4146 PLAYER_INSTANCE_CHECK(player);
4147 PLAYER_NULL_ARG_CHECK(pcount);
4148 int ret = PLAYER_ERROR_NONE;
4149 player_cli_s *pc = (player_cli_s *) player;
4150 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4151 char *ret_buf = NULL;
4156 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4157 if (ret == PLAYER_ERROR_NONE) {
4158 player_msg_get(count, ret_buf);
4166 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4168 PLAYER_INSTANCE_CHECK(player);
4169 PLAYER_NULL_ARG_CHECK(pindex);
4170 int ret = PLAYER_ERROR_NONE;
4171 player_cli_s *pc = (player_cli_s *) player;
4172 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4173 char *ret_buf = NULL;
4178 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4179 if (ret == PLAYER_ERROR_NONE) {
4180 player_msg_get(index, ret_buf);
4188 int player_select_track(player_h player, player_stream_type_e type, int index)
4190 PLAYER_INSTANCE_CHECK(player);
4191 int ret = PLAYER_ERROR_NONE;
4192 player_cli_s *pc = (player_cli_s *) player;
4193 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4194 char *ret_buf = NULL;
4198 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
4204 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4206 PLAYER_INSTANCE_CHECK(player);
4207 PLAYER_NULL_ARG_CHECK(pcode);
4208 int ret = PLAYER_ERROR_NONE;
4209 player_cli_s *pc = (player_cli_s *) player;
4210 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4211 char *ret_buf = NULL;
4212 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4217 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
4218 if (ret == PLAYER_ERROR_NONE) {
4219 bool recv_ret = TRUE;
4220 player_msg_get1_string(ret_buf, code_len, INT, code, recv_ret);
4222 *pcode = strndup(code, code_len);
4224 ret = PLAYER_ERROR_INVALID_OPERATION;
4230 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4232 PLAYER_INSTANCE_CHECK(player);
4233 PLAYER_NULL_ARG_CHECK(callback);
4234 int ret = PLAYER_ERROR_NONE;
4235 player_cli_s *pc = (player_cli_s *) player;
4236 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4237 char *ret_buf = NULL;
4238 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4239 int idx = 0, num = 0;
4240 int bandwidth = 0, width = 0, height = 0;
4246 player_msg_send(api, pc, ret_buf, ret);
4247 if (ret == PLAYER_ERROR_NONE) {
4248 player_msg_get_type(num, ret_buf, INT);
4250 player_msg_get_string(var_info, ret_buf);
4252 LOGW("There is no stream variant info.");
4255 for (idx = 0 ; idx < num ; idx++) {
4256 bandwidth = width = height = 0;
4258 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4260 bandwidth = atoi(token);
4262 token = strtok_r(NULL, ",", &ptr);
4264 width = atoi(token);
4266 token = strtok_r(NULL, ",", &ptr);
4268 height = atoi(token);
4270 callback(bandwidth, width, height, user_data);
4273 LOGD("LEAVE 0x%X", ret);
4278 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4280 int ret = PLAYER_ERROR_NONE;
4281 PLAYER_INSTANCE_CHECK(player);
4282 player_cli_s *pc = (player_cli_s *) player;
4283 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4284 char *ret_buf = NULL;
4288 player_msg_send3(api, pc, ret_buf, ret, INT, bandwidth, INT, width, INT, height);
4291 LOGD("LEAVE 0x%X", ret);
4296 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4298 int ret = PLAYER_ERROR_NONE;
4299 PLAYER_INSTANCE_CHECK(player);
4300 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4302 player_cli_s *pc = (player_cli_s *) player;
4303 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4304 char *ret_buf = NULL;
4305 int bandwidth = -1, width = -1, height = -1;
4309 player_msg_send(api, pc, ret_buf, ret);
4310 if (ret == PLAYER_ERROR_NONE) {
4311 bool ret_val = TRUE;
4313 player_msg_get3(ret_buf, bandwidth, INT, width, INT, height, INT, ret_val);
4315 if (pbandwidth) *pbandwidth = bandwidth;
4316 if (pwidth) *pwidth = width;
4317 if (pheight) *pheight = height;
4319 ret = PLAYER_ERROR_INVALID_OPERATION;
4324 LOGD("LEAVE 0x%X", ret);
4328 int player_set_audio_only(player_h player, bool audio_only)
4330 int ret = PLAYER_ERROR_NONE;
4331 PLAYER_INSTANCE_CHECK(player);
4332 player_cli_s *pc = (player_cli_s *) player;
4333 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4334 char *ret_buf = NULL;
4335 player_state_e state = PLAYER_STATE_NONE;
4337 LOGD("ENTER audio_only: %d", audio_only);
4339 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
4341 /* check player state */
4342 if (ret == PLAYER_ERROR_NONE) {
4343 player_msg_get(state, ret_buf);
4347 if (state < PLAYER_STATE_READY) {
4348 LOGE("Invalid state %d", state);
4349 return PLAYER_ERROR_INVALID_STATE;
4354 return PLAYER_ERROR_INVALID_OPERATION;
4357 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4358 if (EVAS_HANDLE(pc)) {
4359 pc->is_audio_only = (gboolean)audio_only;
4360 return PLAYER_ERROR_NONE;
4363 player_msg_send1(api, pc, ret_buf, ret, INT, audio_only);
4366 LOGD("LEAVE 0x%X", ret);
4371 int player_is_audio_only(player_h player, bool *paudio_only)
4373 PLAYER_INSTANCE_CHECK(player);
4374 PLAYER_NULL_ARG_CHECK(paudio_only);
4375 int ret = PLAYER_ERROR_NONE;
4376 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4377 player_cli_s *pc = (player_cli_s *) player;
4378 char *ret_buf = NULL;
4382 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4383 if (EVAS_HANDLE(pc)) {
4384 *paudio_only = (bool)pc->is_audio_only;
4385 return PLAYER_ERROR_NONE;
4389 player_msg_send(api, pc, ret_buf, ret);
4390 if (ret == PLAYER_ERROR_NONE) {
4391 player_msg_get(audio_only, ret_buf);
4392 *paudio_only = (bool)audio_only;
4396 LOGD("LEAVE 0x%X", ret);
4400 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4402 int ret = PLAYER_ERROR_NONE;
4403 PLAYER_INSTANCE_CHECK(player);
4404 player_cli_s *pc = (player_cli_s *) player;
4405 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4406 char *ret_buf = NULL;
4410 player_msg_send2(api, pc, ret_buf, ret, INT, buffer_ms, INT, rebuffer_ms);
4413 LOGD("LEAVE 0x%X", ret);
4417 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4419 PLAYER_INSTANCE_CHECK(player);
4420 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4422 int ret = PLAYER_ERROR_NONE;
4423 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4424 player_cli_s *pc = (player_cli_s *) player;
4425 int buffering_time = 0, rebuffering_time = 0;
4426 char *ret_buf = NULL;
4430 player_msg_send(api, pc, ret_buf, ret);
4432 if (ret == PLAYER_ERROR_NONE) {
4433 bool ret_val = true;
4435 player_msg_get2(ret_buf, buffering_time, INT, rebuffering_time, INT, ret_val);
4437 if (buffer_ms) *buffer_ms = buffering_time;
4438 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4440 ret = PLAYER_ERROR_INVALID_OPERATION;
4446 LOGD("LEAVE 0x%X", ret);
4450 int player_360_set_enable(player_h player, bool enable)
4452 PLAYER_INSTANCE_CHECK(player);
4453 int ret = PLAYER_ERROR_NONE;
4454 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLE;
4455 player_cli_s *pc = (player_cli_s *) player;
4456 char *ret_buf = NULL;
4457 int val = (int)enable;
4459 LOGD("ENTER %d", enable);
4461 player_msg_send1(api, pc, ret_buf, ret, INT, val);
4464 LOGD("LEAVE 0x%X", ret);
4468 int player_360_is_enabled(player_h player, bool *enabled)
4470 PLAYER_INSTANCE_CHECK(player);
4471 PLAYER_NULL_ARG_CHECK(enabled);
4472 int ret = PLAYER_ERROR_NONE;
4473 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4474 player_cli_s *pc = (player_cli_s *) player;
4475 char *ret_buf = NULL;
4480 player_msg_send(api, pc, ret_buf, ret);
4481 if (ret == PLAYER_ERROR_NONE) {
4482 player_msg_get(val, ret_buf);
4487 LOGD("LEAVE 0x%X", ret);
4491 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4493 PLAYER_INSTANCE_CHECK(player);
4494 int ret = PLAYER_ERROR_NONE;
4495 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4496 player_cli_s *pc = (player_cli_s *) player;
4497 char *ret_buf = NULL;
4499 LOGD("ENTER %f %f", yaw, pitch);
4501 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, yaw, DOUBLE, pitch);
4504 LOGD("LEAVE 0x%X", ret);
4508 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4510 PLAYER_INSTANCE_CHECK(player);
4511 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4512 int ret = PLAYER_ERROR_NONE;
4513 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4514 player_cli_s *pc = (player_cli_s *) player;
4515 double yaw_val = -1;
4516 double pitch_val = -1;
4517 char *ret_buf = NULL;
4521 player_msg_send(api, pc, ret_buf, ret);
4523 if (ret == PLAYER_ERROR_NONE) {
4524 bool ret_val = TRUE;
4525 player_msg_get2(ret_buf, yaw_val, DOUBLE, pitch_val, DOUBLE, ret_val);
4527 *yaw = (float)yaw_val;
4528 *pitch = (float)pitch_val;
4530 LOGE("failed to get value from msg");
4531 ret = PLAYER_ERROR_INVALID_OPERATION;
4537 LOGD("LEAVE 0x%X", ret);
4541 int player_360_set_zoom(player_h player, float level)
4543 PLAYER_INSTANCE_CHECK(player);
4544 int ret = PLAYER_ERROR_NONE;
4545 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4546 player_cli_s *pc = (player_cli_s *) player;
4547 char *ret_buf = NULL;
4549 LOGD("ENTER %f", level);
4551 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, level);
4554 LOGD("LEAVE 0x%X", ret);
4558 int player_360_get_zoom(player_h player, float *level)
4560 PLAYER_INSTANCE_CHECK(player);
4561 PLAYER_NULL_ARG_CHECK(level);
4562 int ret = PLAYER_ERROR_NONE;
4563 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
4564 player_cli_s *pc = (player_cli_s *) player;
4566 char *ret_buf = NULL;
4570 player_msg_send(api, pc, ret_buf, ret);
4572 if (ret == PLAYER_ERROR_NONE) {
4573 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
4574 *level = (float)zoom;
4576 LOGE("failed to get value from msg");
4577 ret = PLAYER_ERROR_INVALID_OPERATION;
4583 LOGD("LEAVE 0x%X", ret);
4588 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
4590 PLAYER_INSTANCE_CHECK(player);
4591 int ret = PLAYER_ERROR_NONE;
4592 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
4593 player_cli_s *pc = (player_cli_s *) player;
4594 char *ret_buf = NULL;
4596 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
4598 player_msg_send2(api, pc, ret_buf, ret, INT, horizontal_degrees, INT, vertical_degrees);
4601 LOGD("LEAVE 0x%X", ret);
4605 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
4607 PLAYER_INSTANCE_CHECK(player);
4608 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
4609 int ret = PLAYER_ERROR_NONE;
4610 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
4611 player_cli_s *pc = (player_cli_s *) player;
4614 char *ret_buf = NULL;
4618 player_msg_send(api, pc, ret_buf, ret);
4620 if (ret == PLAYER_ERROR_NONE) {
4621 bool ret_val = TRUE;
4622 player_msg_get2(ret_buf, h_val, INT, v_val, INT, ret_val);
4624 *horizontal_degrees = h_val;
4625 *vertical_degrees = v_val;
4627 LOGE("failed to get value from msg");
4628 ret = PLAYER_ERROR_INVALID_OPERATION;
4634 LOGD("LEAVE 0x%X", ret);