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>
25 #include <tbm_bufmgr.h>
26 #include <tbm_surface.h>
27 #include <tbm_surface_internal.h>
30 #include <muse_core.h>
31 #include <muse_client.h>
32 #include <muse_player.h>
33 #include <muse_player_msg.h>
34 #include <sound_manager.h>
35 #include <sound_manager_internal.h>
36 #include <storage-internal.h>
37 #include <system_info.h>
38 #include "player_internal.h"
39 #include "player_private.h"
40 #include "player_msg.h"
42 #define INVALID_MUSE_TYPE_VALUE 0
43 #define MAX_S_PATH_LEN 32
44 #define PLAYER_FEATURE_SOUND_STREAM "http://tizen.org/feature/multimedia.player.stream_info"
45 #define PLAYER_FEATURE_OPENGL "http://tizen.org/feature/opengles.version.2_0"
46 #define PLAYER_FEATURE_SPHERICAL_VIDEO "http://tizen.org/feature/multimedia.player.spherical_video"
49 TIZEN_PROFILE_UNKNOWN = 0,
50 TIZEN_PROFILE_MOBILE = 0x1,
51 TIZEN_PROFILE_WEARABLE = 0x2,
52 TIZEN_PROFILE_TV = 0x4,
53 TIZEN_PROFILE_IVI = 0x8,
54 TIZEN_PROFILE_COMMON = 0x10,
58 tbm_fd tfd[MUSE_NUM_FD];
64 callback_cb_info_s *cb_info;
65 _player_recv_data *recv_data;
70 intptr_t remote_v_data;
74 } _media_pkt_fin_data;
76 static int _player_deinit_memory_buffer(player_cli_s * pc);
77 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data);
78 static bool _player_need_sync_context(int event_id);
79 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all);
80 #ifdef TIZEN_FEATURE_EVAS_RENDERER
81 typedef void (*player_retrieve_buffer_cb)(void *user_data);
82 static void __retrieve_buffer_cb(void *user_data);
83 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data);
84 static int __player_unset_retrieve_buffer_cb(player_h player);
86 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem);
89 * Internal Implementation
91 int _player_send_msg(muse_player_api_e api, player_cli_s *player, char* msg, tbm_fd tfd, char **retbuf)
93 int ret = PLAYER_ERROR_NONE;
95 int send_fd = INVALID_DEFAULT_VALUE;
96 int send_tfd[MUSE_NUM_FD];
97 int timeout = client_get_api_timeout(player, api);
99 memset(send_tfd, INVALID_DEFAULT_VALUE, sizeof(send_tfd));
101 if (player && CALLBACK_INFO(player)) {
102 send_fd = MSG_FD(player);
104 LOGE("can not access to cb_info");
105 return PLAYER_ERROR_INVALID_STATE;
108 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
109 LOGE("invalid socket fd %d", send_fd);
110 return PLAYER_ERROR_INVALID_OPERATION;
113 if (tfd != INVALID_DEFAULT_VALUE) {
115 send_len = muse_core_msg_send_fd(send_fd, send_tfd, msg);
117 send_len = muse_core_msg_send(send_fd, msg);
120 LOGE("sending message failed");
121 return PLAYER_ERROR_INVALID_OPERATION;
123 ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), retbuf, timeout);
129 int _player_send_msg_async(int send_fd, char* msg)
133 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
134 LOGE("invalid socket fd %d", send_fd);
135 return PLAYER_ERROR_INVALID_OPERATION;
138 send_len = muse_core_msg_send(send_fd, msg);
140 LOGE("sending message failed");
141 return PLAYER_ERROR_INVALID_OPERATION;
144 return PLAYER_ERROR_NONE;
147 static tizen_profile_t _get_tizen_profile()
150 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
152 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
155 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
156 switch (*profileName) {
159 profile = TIZEN_PROFILE_MOBILE;
163 profile = TIZEN_PROFILE_WEARABLE;
167 profile = TIZEN_PROFILE_TV;
171 profile = TIZEN_PROFILE_IVI;
173 default: // common or unknown ==> ALL ARE COMMON.
174 profile = TIZEN_PROFILE_COMMON;
181 static int _get_current_state(player_cli_s *pc, player_state_e *pstate)
183 PLAYER_INSTANCE_CHECK(pc);
184 PLAYER_NULL_ARG_CHECK(pstate);
185 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
186 int ret = PLAYER_ERROR_NONE;
187 int state = PLAYER_STATE_NONE;
188 char *ret_buf = NULL;
190 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
192 if (ret == PLAYER_ERROR_NONE) {
193 player_msg_get(state, ret_buf);
195 LOGD("current state %d", *pstate);
202 static bool _player_get_param_value(char* buf, ...)
204 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
207 int type = MUSE_TYPE_ANY;
208 char *param_name = NULL;
213 void *jobj = muse_core_msg_object_new(buf, NULL, &err);
216 LOGE("failed to get msg object. err:%d", err);
220 va_start(var_args, buf);
222 while ((type = va_arg(var_args, int)) != INVALID_MUSE_TYPE_VALUE) {
223 param_name = va_arg(var_args, char *);
226 case MUSE_TYPE_INT64:
227 case MUSE_TYPE_DOUBLE:
228 case MUSE_TYPE_STRING:
229 case MUSE_TYPE_POINTER:
230 value = va_arg(var_args, void *);
232 if (!muse_core_msg_object_get_value(param_name, jobj, type, value)) {
234 LOGE("failed to get %s value", param_name);
238 LOGE("Unexpected type");
244 muse_core_msg_object_free(jobj);
250 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
252 int ret = MEDIA_PACKET_FINALIZE;
253 muse_player_api_e api = MUSE_PLAYER_API_RETURN_VIDEO_DATA;
254 _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
256 char *snd_msg = NULL;
260 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
264 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
265 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
269 if (!fin_data->use_tsurf_pool) {
270 tbm_surface_h tsurf = NULL;
271 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
272 LOGE("media_packet_get_tbm_surface failed");
273 /* continue the remained job */
276 /* LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf); */
277 tbm_surface_destroy(tsurf);
281 /* Do not destroy tbm surface here to reuse during playback *
282 * they will be destroyed at player_unprepare() or player_destroy(). *
283 * ref: __player_remove_tsurf_list() */
285 tbm_surface_h tsurf = NULL;
287 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
288 /* LOGD("tsurf set to null %p", tsurf); */
293 if (muse_core_fd_is_valid(fin_data->fd)) {
294 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
295 LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
299 v_data = fin_data->remote_v_data;
300 snd_msg = muse_core_msg_new(api, MUSE_TYPE_POINTER, "v_data", v_data, 0);
301 snd_len = muse_core_msg_send(fin_data->fd, snd_msg);
302 muse_core_msg_free(snd_msg);
305 LOGE("[fd:%d] fail to send msg.", fin_data->fd);
307 LOGE("[fd:%d] is invalid.", fin_data->fd);
319 static bool _player_check_network_availability(void)
321 #define _FEATURE_NAME_WIFI "http://tizen.org/feature/network.wifi"
322 #define _FEATURE_NAME_TELEPHONY "http://tizen.org/feature/network.telephony"
323 #define _FEATURE_NAME_ETHERNET "http://tizen.org/feature/network.ethernet"
324 bool enabled = FALSE;
325 bool supported = FALSE;
327 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
328 LOGI("wifi status = %d", enabled);
332 LOGE("SYSTEM_INFO_ERROR");
335 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
336 LOGI("telephony status = %d", enabled);
340 LOGE("SYSTEM_INFO_ERROR");
343 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
344 LOGI("ethernet status = %d", enabled);
348 LOGE("SYSTEM_INFO_ERROR");
357 static void *_get_mem(player_cli_s * player, int size)
359 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
361 mem->data = g_new(void, size);
362 mem->next = player->head;
369 static void _del_mem(player_cli_s * player)
372 while (player->head) {
373 mem = player->head->next;
374 g_free(player->head->data);
375 g_free(player->head);
380 static int player_recv_msg(callback_cb_info_s * cb_info, tbm_fd *tfd)
383 msg_buff_s *buff = &cb_info->buff;
385 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
386 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(*tfd) * MUSE_NUM_FD);
387 recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, tfd);
389 LOGE("failed to recv msg %d", recvLen);
393 /* check the first msg */
394 if (buff->part_of_msg && buff->recvMsg[0] != '{')
396 gchar *tmp = strndup(buff->recvMsg, recvLen);
398 LOGE("failed to copy msg.");
402 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
405 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
406 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
407 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
408 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
409 if (!buff->recvMsg) {
410 LOGE("failed renew buffer.");
415 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
417 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
418 recvLen += strlen(buff->part_of_msg);
420 free(buff->part_of_msg);
421 buff->part_of_msg = NULL;
426 /* check the last msg */
427 if (buff->recvMsg[recvLen-1] != '}') {
428 char *part_pos = strrchr(buff->recvMsg, '}');
429 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
432 buff->part_of_msg = strndup(part_pos+1, part_len);
433 if (!buff->part_of_msg) {
434 LOGE("failed to alloc buffer for part of msg.");
437 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
445 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
447 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
448 cb_info->user_cb[event] = NULL;
449 cb_info->user_data[event] = NULL;
453 /* Notice : have to be called via API to avoid deadlock
454 * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
456 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
461 LOGE("cb_info is NULL, event: %d", event);
465 lock = (g_thread_self() != cb_info->event_queue.thread);
468 g_mutex_lock(&cb_info->event_queue.mutex);
470 if (_player_need_sync_context(event))
471 _player_remove_idle_event(cb_info, event, false);
473 set_null_user_cb(cb_info, event);
476 g_mutex_unlock(&cb_info->event_queue.mutex);
479 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
481 PLAYER_INSTANCE_CHECK(player);
482 PLAYER_NULL_ARG_CHECK(callback);
483 int ret = PLAYER_ERROR_NONE;
484 player_cli_s *pc = (player_cli_s *) player;
485 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
488 if (MUSE_PLAYER_EVENT_TYPE_BUFFERING == type) {
489 if (!_player_check_network_availability())
490 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
493 if (!CALLBACK_INFO(pc))
494 return PLAYER_ERROR_INVALID_OPERATION;
496 LOGI("Event type : %d ", type);
497 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
499 if (ret == PLAYER_ERROR_NONE) {
500 pc->cb_info->user_cb[type] = callback;
501 pc->cb_info->user_data[type] = user_data;
506 static int __unset_callback(muse_player_event_e type, player_h player)
508 PLAYER_INSTANCE_CHECK(player);
509 int ret = PLAYER_ERROR_NONE;
510 player_cli_s *pc = (player_cli_s *) player;
511 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
514 LOGI("Event type : %d ", type);
516 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
517 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
519 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
524 static void __prepare_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
526 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
528 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
530 set_null_user_cb(cb_info, ev);
533 static void __complete_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
535 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
536 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
539 #ifdef TIZEN_FEATURE_EVAS_RENDERER
540 static void __retrieve_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
543 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
544 ((player_retrieve_buffer_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
548 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
551 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
553 if (player_msg_get(code, recv_data->buffer))
554 ((player_interrupted_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
557 static void __error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
560 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
562 if (player_msg_get(code, recv_data->buffer)) {
563 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
564 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
565 LOGW("failed to pause, so prepare cb will be released soon");
566 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
569 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
573 static void __disconnected_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
575 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
577 ((player_error_cb) cb_info->user_cb[ev]) (PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
580 static void __buffering_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
583 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
585 if (player_msg_get(percent, recv_data->buffer))
586 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
589 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
592 char text[MUSE_URI_MAX_LENGTH] = { 0, };
593 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
596 ret = _player_get_param_value(recv_data->buffer,
597 MUSE_TYPE_INT, "duration", (void *)&duration,
598 MUSE_TYPE_STRING, "text", (void *)text,
599 INVALID_MUSE_TYPE_VALUE);
601 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
604 static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
606 unsigned char *data = NULL;
609 unsigned int size = 0;
611 tbm_bo_handle thandle;
612 int key = INVALID_DEFAULT_VALUE;
614 get_ret = _player_get_param_value(recv_data->buffer,
615 MUSE_TYPE_INT, "width", (void *)&width,
616 MUSE_TYPE_INT, "height", (void *)&height,
617 MUSE_TYPE_INT, "size", (void *)&size,
618 MUSE_TYPE_INT, "key", (void *)&key,
619 INVALID_MUSE_TYPE_VALUE);
621 if (recv_data->tfd[0] < 0) {
622 LOGE("There is no valid tbm_fd");
626 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
628 LOGE("TBM get error : bo is NULL");
631 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
632 if (thandle.ptr == NULL) {
633 LOGE("TBM get error : handle pointer is NULL");
636 data = g_new(unsigned char, size);
638 memcpy(data, thandle.ptr, size);
639 ((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]);
642 LOGE("g_new failure");
648 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
649 close(recv_data->tfd[0]);
650 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
656 if (key > INVALID_DEFAULT_VALUE) {
657 LOGD("send msg to release buffer. key:%d", key);
658 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
661 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
664 static void __seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
666 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
667 #ifdef TIZEN_FEATURE_EVAS_RENDERER
668 void *dl_handle = NULL;
669 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
671 g_mutex_lock(&cb_info->seek_cb_mutex);
672 if (cb_info->user_cb[ev] && cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_NONE) {
673 #ifdef TIZEN_FEATURE_EVAS_RENDERER
674 if (cb_info->evas_info && cb_info->evas_info->support_video) {
675 if (cb_info->evas_info->handle && cb_info->evas_info->visible != EVAS_VISIBLE_FALSE) {
676 dl_handle = dlopen(PATH_DISP_LIB, RTLD_LAZY);
678 PLAYER_DISP_DLSYM(dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
679 int ret = p_disp_set_evas_display_visible(cb_info->evas_info->handle, true);
681 if (ret != MM_ERROR_NONE)
682 LOGW("failed to set visible at evas 0x%x", ret);
684 cb_info->evas_info->visible = EVAS_VISIBLE_TRUE;
686 LOGW("not support video rendering");
691 LOGD("call seek cb");
692 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
693 set_null_user_cb(cb_info, ev);
695 LOGW("ignored. seek cb %p", cb_info->user_cb[ev]);
697 g_mutex_unlock(&cb_info->seek_cb_mutex);
700 static void __player_remove_tsurf_list(player_cli_s * pc)
704 g_mutex_lock(&pc->cb_info->data_mutex);
705 if (pc->cb_info->tsurf_list) {
706 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
708 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
709 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
711 LOGD("%p will be removed", tmp);
714 tbm_surface_destroy(tmp->tsurf);
720 g_list_free(pc->cb_info->tsurf_list);
721 pc->cb_info->tsurf_list = NULL;
723 g_mutex_unlock(&pc->cb_info->data_mutex);
727 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, int height, int width)
731 g_mutex_lock(&cb_info->data_mutex);
732 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
733 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
734 if (tmp && key && (tmp->key[0] == key[0])) {
735 LOGD("found tsurf_data of tbm_key %d", key[0]);
737 /* need to check tsuf info to support DRC */
738 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
739 (tbm_surface_get_width(tmp->tsurf) != width)) {
741 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
742 LOGW("tsurf info is changed. need to create new tsurf.");
743 tbm_surface_destroy(tmp->tsurf);
746 g_mutex_unlock(&cb_info->data_mutex);
750 g_mutex_unlock(&cb_info->data_mutex);
755 g_mutex_unlock(&cb_info->data_mutex);
759 static media_packet_rotate_method_e __convert_packet_orient_info(int orientation)
761 media_packet_rotate_method_e rotate = MEDIA_PACKET_ROTATE_IDENTITY;
763 switch (orientation) {
765 rotate = MEDIA_PACKET_ROTATE_90;
768 rotate = MEDIA_PACKET_ROTATE_180;
771 rotate = MEDIA_PACKET_ROTATE_270;
774 rotate = MEDIA_PACKET_ROTATE_IDENTITY;
781 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
783 tbm_bo bo[4] = { NULL, };
784 int key[4] = { INVALID_DEFAULT_VALUE, };
785 tbm_surface_info_s sinfo;
786 char *surface_info = (char *)&sinfo;
787 media_packet_h pkt = NULL;
788 tbm_surface_h tsurf = NULL;
789 player_tsurf_info_t *tsurf_data = NULL;
791 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
792 bool make_pkt_fmt = false;
793 int ret = MEDIA_FORMAT_ERROR_NONE;
794 _media_pkt_fin_data *fin_data = NULL;
797 int i = 0, orientation = 0;
798 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
800 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
802 !muse_core_msg_object_get_value("key[0]", jobj, MUSE_TYPE_ANY, &key[0]) ||
803 !muse_core_msg_object_get_value("key[1]", jobj, MUSE_TYPE_ANY, &key[1]) ||
804 !muse_core_msg_object_get_value("key[2]", jobj, MUSE_TYPE_ANY, &key[2]) ||
805 !muse_core_msg_object_get_value("key[3]", jobj, MUSE_TYPE_ANY, &key[3]) ||
806 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
807 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
808 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
809 !muse_core_msg_object_get_value("orientation", jobj, MUSE_TYPE_INT, &orientation) ||
810 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
812 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
814 muse_core_msg_object_free(jobj);
817 muse_core_msg_object_free(jobj);
819 LOGD("width %d, height %d", sinfo.width, sinfo.height);
822 LOGE("cb_info is null");
826 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
827 /* send msg to release v_data. */
828 LOGE("_video_decoded_cb is not set");
832 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
833 LOGE("tbm fd is invalid");
837 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
839 for (i = 0; i < MUSE_NUM_FD; i++) {
840 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
844 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
847 tsurf_data = g_new(player_tsurf_info_t, 1);
849 LOGE("failed to alloc tsurf info");
852 memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
854 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
856 LOGE("failed to create tbm surface");
860 memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
861 tsurf_data->tsurf = tsurf;
862 if (cb_info->use_tsurf_pool) {
863 g_mutex_lock(&cb_info->data_mutex);
864 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
865 LOGD("key %d is added to the pool", key[0]);
866 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
867 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
868 g_mutex_unlock(&cb_info->data_mutex);
871 if (tsurf_data->tsurf) {
872 tsurf = tsurf_data->tsurf;
874 LOGE("tsurf_data->tsurf is null (never enter here)");
879 /* check media packet format */
880 if (cb_info->pkt_fmt) {
881 int pkt_fmt_width = 0;
882 int pkt_fmt_height = 0;
883 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
885 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
886 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
887 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);
888 media_format_unref(cb_info->pkt_fmt);
889 cb_info->pkt_fmt = NULL;
895 /* create packet format */
897 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
898 ret = media_format_create(&cb_info->pkt_fmt);
899 if (ret == MEDIA_FORMAT_ERROR_NONE) {
900 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
901 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
902 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
903 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
905 LOGE("media_format_create failed");
909 fin_data = g_new0(_media_pkt_fin_data, 1);
911 LOGE("failed to alloc fin_data");
914 fin_data->remote_v_data = v_data;
915 fin_data->fd = cb_info->fd;
916 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
918 /* Keep the fd id to check validation when the pkt is destroyed. */
919 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
921 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
922 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
923 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
928 ret = media_packet_set_pts(pkt, (uint64_t) pts);
929 if (ret != MEDIA_PACKET_ERROR_NONE)
930 LOGE("media_packet_set_pts failed");
933 ret = media_packet_set_rotate_method(pkt, __convert_packet_orient_info(orientation));
934 if (ret != MEDIA_PACKET_ERROR_NONE)
935 LOGE("media_packet_set_rotate_method failed");
937 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
938 /* call media packet callback */
939 ((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]);
941 LOGE("_video_decoded_cb is not set");
942 media_packet_destroy(pkt);
945 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
946 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
947 close(recv_data->tfd[i]);
950 for (i = 0; i < bo_num; i++) {
955 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
960 media_packet_destroy(pkt);
965 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
966 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
967 close(recv_data->tfd[i]);
970 for (i = 0; i < bo_num; i++) {
974 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
976 if (cb_info && v_data)
977 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, MUSE_TYPE_POINTER, "v_data", v_data);
982 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
985 tbm_bo_handle thandle;
986 int key = INVALID_DEFAULT_VALUE;
987 player_audio_raw_data_s audio;
989 if (!player_msg_get(key, recv_data->buffer)) {
990 LOGE("failed to get key value from msg.");
994 if (recv_data->tfd[0] < 0) {
995 LOGE("failed to get tbm_fd(key:%d)", key);
999 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
1001 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
1005 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
1006 if (thandle.ptr == NULL) {
1007 LOGE("TBM get error : handle pointer is NULL");
1011 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
1012 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
1014 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
1015 ((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]);
1019 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
1020 close(recv_data->tfd[0]);
1021 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1027 if (key > INVALID_DEFAULT_VALUE) {
1028 /* LOGD("send msg to release buffer. key:%d", key); */
1029 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
1033 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1037 static void __pd_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1040 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
1042 if (player_msg_get(type, recv_data->buffer))
1043 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
1046 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1050 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1054 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1058 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1060 /* player_media_stream_buffer_status_e status; */
1063 if (player_msg_get(status, recv_data->buffer)) {
1064 ((player_media_stream_buffer_status_cb)
1065 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]);
1069 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1071 /* player_media_stream_buffer_status_e status; */
1074 if (player_msg_get(status, recv_data->buffer)) {
1075 ((player_media_stream_buffer_status_cb)
1076 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
1077 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
1082 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1084 /* player_media_stream_buffer_status_e status; */
1086 unsigned long long bytes;
1089 ret = _player_get_param_value(recv_data->buffer,
1090 MUSE_TYPE_INT, "status", (void *)&status,
1091 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1092 INVALID_MUSE_TYPE_VALUE);
1094 ((player_media_stream_buffer_status_cb_ex)
1095 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
1096 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
1100 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1102 /* player_media_stream_buffer_status_e status; */
1104 unsigned long long bytes;
1107 ret = _player_get_param_value(recv_data->buffer,
1108 MUSE_TYPE_INT, "status", (void *)&status,
1109 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1110 INVALID_MUSE_TYPE_VALUE);
1112 ((player_media_stream_buffer_status_cb_ex)
1113 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
1114 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
1119 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1121 unsigned long long offset;
1123 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1124 ((player_media_stream_seek_cb)
1125 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
1126 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
1130 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1132 unsigned long long offset;
1134 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1135 ((player_media_stream_seek_cb)
1136 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
1137 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1141 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1147 bool ret_val = TRUE;
1148 ret_val = _player_get_param_value(recv_data->buffer,
1149 MUSE_TYPE_INT, "width", (void *)&width,
1150 MUSE_TYPE_INT, "height", (void *)&height,
1151 MUSE_TYPE_INT, "fps", (void *)&fps,
1152 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
1153 INVALID_MUSE_TYPE_VALUE);
1155 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1156 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1160 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, _player_recv_data *recv_data) = {
1161 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1162 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1163 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1164 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1165 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1166 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1167 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1168 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1169 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1170 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
1171 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1172 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
1173 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1174 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1175 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1176 #ifdef _PLAYER_FOR_PRODUCT
1177 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1178 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1180 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1181 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1182 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1183 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1184 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1185 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1186 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1187 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1188 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1189 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1191 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1194 gboolean _player_event_job_function(void *user_data)
1196 _player_cb_data *data = (_player_cb_data *)user_data;
1197 muse_player_event_e ev;
1200 LOGE("data is null");
1204 LOGD("enter ev:%d", data->int_data);
1206 g_mutex_lock(&data->event_mutex);
1207 ev = data->int_data;
1209 if (data->cb_info == NULL) {
1210 /* tried to remove before at _player_remove_idle_event */
1211 LOGW("cb_info is NULL. event %d", data->int_data);
1215 /* remove event from list */
1216 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1217 if (data->cb_info->event_queue.idle_ev_list) {
1218 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1219 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1221 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1223 if (data->cb_info->user_cb[ev])
1224 _user_callbacks[ev] (data->cb_info, data->recv_data);
1226 LOGW("user callback is unset. type : %d", ev);
1229 /* unlock and release event */
1230 g_mutex_unlock(&data->event_mutex);
1231 g_mutex_clear(&data->event_mutex);
1233 if (data->recv_data) {
1234 g_free(data->recv_data->buffer);
1235 g_free(data->recv_data);
1239 return FALSE; /* remove from the event list */
1242 static bool _player_need_sync_context(int event_id)
1244 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1245 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1246 (event_id == MUSE_PLAYER_EVENT_TYPE_PD) ||
1247 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1248 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1249 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1250 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1251 LOGD("%d callback will be issued in the mainloop.", event_id);
1258 static void *_player_event_queue_loop(void *param)
1261 LOGE("NULL parameter");
1264 callback_cb_info_s *cb_info = param;
1265 player_event_queue *ev = &cb_info->event_queue;
1266 _player_cb_data *event_data = NULL;
1268 g_mutex_lock(&ev->mutex);
1269 while (ev->running) {
1270 g_mutex_lock(&ev->qlock);
1271 if (g_queue_is_empty(ev->queue)) {
1272 g_mutex_unlock(&ev->qlock);
1273 g_cond_wait(&ev->cond, &ev->mutex);
1277 g_mutex_unlock(&ev->qlock);
1280 g_mutex_lock(&ev->qlock);
1281 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1282 g_mutex_unlock(&ev->qlock);
1284 muse_player_event_e event_type = ((_player_cb_data *)event_data)->int_data;
1286 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1287 g_mutex_lock(&cb_info->seek_cb_mutex);
1288 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1289 /* push event into queue again. */
1290 _player_event_queue_add(ev, event_data);
1291 g_mutex_unlock(&cb_info->seek_cb_mutex);
1294 g_mutex_unlock(&cb_info->seek_cb_mutex);
1297 if (_player_need_sync_context(event_data->int_data)) {
1298 if (cb_info->user_cb[event_data->int_data] &&
1299 _user_callbacks[event_data->int_data]) {
1300 g_mutex_lock(&ev->idle_ev_mutex);
1301 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1302 g_mutex_unlock(&ev->idle_ev_mutex);
1304 LOGD("add ev %d to main loop", event_data->int_data);
1306 g_idle_add_full(G_PRIORITY_DEFAULT,
1307 (GSourceFunc)_player_event_job_function,
1308 (gpointer)event_data,
1311 LOGW("there is no registered cb for ev:%d", event_data->int_data);
1312 if (event_data->recv_data) {
1313 g_free(event_data->recv_data->buffer);
1314 g_free(event_data->recv_data);
1319 _player_event_job_function(event_data);
1326 g_mutex_unlock(&ev->mutex);
1327 LOGI("Exit event loop");
1331 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1333 g_return_val_if_fail(cb_info, FALSE);
1334 player_event_queue *ev = &cb_info->event_queue;
1336 ev->queue = g_queue_new();
1337 g_return_val_if_fail(ev->queue, FALSE);
1338 g_mutex_init(&ev->qlock);
1340 g_mutex_init(&ev->mutex);
1341 g_cond_init(&ev->cond);
1344 g_mutex_init(&ev->idle_ev_mutex);
1346 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1347 g_return_val_if_fail(ev->thread, FALSE);
1348 LOGI("event queue thread %p", ev->thread);
1354 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1356 g_return_if_fail(cb_info);
1357 player_event_queue *ev = &cb_info->event_queue;
1358 _player_cb_data *event_data = NULL;
1361 g_mutex_lock(&ev->idle_ev_mutex);
1363 if (ev->idle_ev_list == NULL) {
1364 LOGD("No idle event is remained.");
1365 g_mutex_unlock(&ev->idle_ev_mutex);
1369 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1371 list = ev->idle_ev_list;
1373 event_data = list->data;
1374 list = g_list_next(list);
1377 LOGW("Fail to remove idle event. The data is NULL");
1381 if (g_mutex_trylock(&event_data->event_mutex)) {
1383 gboolean ret = FALSE;
1384 if (remove_all || (event_data->int_data == event_type)) {
1386 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1388 ret = g_idle_remove_by_data(event_data);
1390 /* will be handled at _player_event_job_function() as an exception */
1391 event_data->cb_info = NULL;
1392 LOGW("failed to remove, idle callback will be called later");
1395 /* set cb to null */
1396 set_null_user_cb(cb_info, event_data->int_data);
1397 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1399 g_mutex_unlock(&event_data->event_mutex);
1402 g_mutex_clear(&event_data->event_mutex);
1403 if (event_data->recv_data) {
1404 g_free(event_data->recv_data->buffer);
1405 g_free(event_data->recv_data);
1409 LOGD("remove idle event done");
1410 } /* else : will be handled if the cb is called. */
1412 g_mutex_unlock(&event_data->event_mutex);
1415 LOGW("event(%d) lock failed. it's being called...", event_data->int_data);
1418 /* continue: keep checking next event_data */
1422 g_list_free(ev->idle_ev_list);
1423 ev->idle_ev_list = NULL;
1426 g_mutex_unlock(&ev->idle_ev_mutex);
1432 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1434 g_return_if_fail(cb_info);
1435 player_event_queue *ev = &cb_info->event_queue;
1436 _player_cb_data *event_data;
1438 LOGI("event queue thread %p", ev->thread);
1440 g_mutex_lock(&ev->mutex);
1441 ev->running = FALSE;
1442 g_cond_broadcast(&ev->cond);
1443 g_mutex_unlock(&ev->mutex);
1445 g_thread_join(ev->thread);
1448 while (!g_queue_is_empty(ev->queue)) {
1449 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1451 g_free(event_data->recv_data->buffer);
1452 g_free(event_data->recv_data);
1456 g_queue_free(ev->queue);
1457 g_mutex_clear(&ev->qlock);
1458 g_mutex_clear(&ev->mutex);
1459 g_cond_clear(&ev->cond);
1460 g_mutex_clear(&ev->idle_ev_mutex);
1463 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1467 g_mutex_lock(&ev_queue->qlock);
1469 item = g_queue_peek_head_link(ev_queue->queue);
1471 GList *next = item->next;
1472 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1474 if (cb_data && cb_data->int_data == ev) {
1475 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1476 g_free(cb_data->recv_data->buffer);
1477 g_free(cb_data->recv_data);
1480 g_queue_delete_link(ev_queue->queue, item);
1484 g_mutex_unlock(&ev_queue->qlock);
1487 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1490 g_mutex_lock(&ev->qlock);
1491 g_queue_push_tail(ev->queue, (gpointer) data);
1492 g_mutex_unlock(&ev->qlock);
1493 g_cond_signal(&ev->cond);
1497 static bool _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1499 /* LOGD("get event %d", event); */
1501 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1502 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1503 _player_cb_data *data = NULL;
1504 data = g_new(_player_cb_data, 1);
1506 LOGE("fail to alloc mem");
1509 data->int_data = (int)event;
1510 data->cb_info = cb_info;
1511 data->recv_data = recv_data;
1512 g_mutex_init(&data->event_mutex);
1513 _player_event_queue_add(&cb_info->event_queue, data);
1519 LOGE("failed to add event to queue");
1523 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1525 ret_msg_s *msg = NULL;
1526 ret_msg_s *last = cb_info->buff.retMsgHead;
1528 msg = g_new(ret_msg_s, 1);
1531 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1534 cb_info->buff.retMsgHead = msg;
1541 LOGE("g_new failure");
1544 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1546 ret_msg_s *msg = cb_info->buff.retMsgHead;
1547 ret_msg_s *prev = NULL;
1549 if (msg->api == api) {
1551 cb_info->buff.retMsgHead = msg->next;
1553 prev->next = msg->next;
1562 static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
1564 ret_msg_s *msg = cb_info->buff.retMsgHead;
1565 ret_msg_s *prev = NULL;
1569 LOGI("Remove %s", prev->msg);
1576 static void _notify_disconnected(callback_cb_info_s * cb_info)
1578 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1579 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1582 if (_user_callbacks[event]) {
1583 _player_cb_data *data = NULL;
1584 data = g_new(_player_cb_data, 1);
1586 LOGE("fail to alloc mem");
1589 data->int_data = (int)event;
1590 data->cb_info = cb_info;
1591 data->recv_data = NULL;
1592 g_mutex_init(&data->event_mutex);
1593 _player_event_queue_add(&cb_info->event_queue, data);
1597 static void *client_cb_handler(gpointer data)
1603 callback_cb_info_s *cb_info = data;
1604 char *recvMsg = NULL;
1605 muse_core_msg_parse_err_e err;
1606 tbm_fd tfd[MUSE_NUM_FD];
1608 while (g_atomic_int_get(&cb_info->running)) {
1610 err = MUSE_MSG_PARSE_ERROR_NONE;
1612 len = player_recv_msg(cb_info, tfd);
1616 recvMsg = cb_info->buff.recvMsg;
1617 recvMsg[len] = '\0';
1621 while (offset < len) {
1622 api = MUSE_PLAYER_API_MAX;
1623 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1626 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1628 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1629 if (api < MUSE_PLAYER_API_MAX) {
1630 g_mutex_lock(&cb_info->player_mutex);
1631 cb_info->buff.recved++;
1632 _add_ret_msg(api, cb_info, offset, parse_len);
1633 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1634 LOGD("get tbm fd for album art.");
1635 cb_info->tfd = tfd[0];
1637 g_cond_signal(&cb_info->player_cond[api]);
1638 g_mutex_unlock(&cb_info->player_mutex);
1639 if (api == MUSE_PLAYER_API_DESTROY)
1640 g_atomic_int_set(&cb_info->running, 0);
1641 } else if (api == MUSE_PLAYER_CB_EVENT) {
1643 _player_recv_data *recv_data = NULL;
1644 g_mutex_lock(&cb_info->player_mutex);
1645 recv_data = g_new0(_player_recv_data, 1);
1646 if (recv_data != NULL) {
1647 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1648 recv_data->buffer = strndup(recvMsg+offset, parse_len);
1650 LOGE("failed to alloc recv_data.");
1651 g_mutex_unlock(&cb_info->player_mutex);
1652 muse_core_msg_object_free(jobj);
1655 g_mutex_unlock(&cb_info->player_mutex);
1656 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1657 !_user_callback_handler(cb_info, event, recv_data)) {
1658 LOGE("failed to get value or add event to the queue.");
1660 g_free(recv_data->buffer);
1664 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1665 g_mutex_lock(&cb_info->player_mutex);
1666 cb_info->buff.recved++;
1667 g_cond_signal(&cb_info->server_ack_cond);
1668 g_mutex_unlock(&cb_info->player_mutex);
1671 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1673 muse_core_msg_object_free(jobj);
1675 LOGE("Failed to get msg obj. err:%d", err);
1678 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1681 offset += parse_len;
1682 parse_len = len - offset;
1685 if (g_atomic_int_get(&cb_info->running))
1686 _notify_disconnected(cb_info);
1687 LOGD("client cb exit");
1692 static callback_cb_info_s *callback_new(gint sockfd)
1694 callback_cb_info_s *cb_info;
1698 g_return_val_if_fail(sockfd > 0, NULL);
1700 cb_info = g_new(callback_cb_info_s, 1);
1703 memset(cb_info, 0, sizeof(callback_cb_info_s));
1705 g_mutex_init(&cb_info->player_mutex);
1706 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1707 g_cond_init(&cb_info->player_cond[i]);
1708 g_cond_init(&cb_info->server_ack_cond);
1710 g_mutex_init(&cb_info->data_mutex);
1711 g_mutex_init(&cb_info->seek_cb_mutex);
1713 buff = &cb_info->buff;
1714 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1715 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1717 buff->retMsgHead = NULL;
1718 buff->part_of_msg = NULL;
1720 g_atomic_int_set(&cb_info->running, 1);
1721 cb_info->fd = sockfd;
1722 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1723 cb_info->tfd = INVALID_DEFAULT_VALUE;
1728 static void callback_destroy(callback_cb_info_s * cb_info)
1731 g_return_if_fail(cb_info);
1733 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1734 muse_client_close(cb_info->fd);
1735 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1736 muse_client_close(cb_info->data_fd);
1738 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1740 g_thread_join(cb_info->thread);
1741 cb_info->thread = NULL;
1743 LOGI("%p Callback destroyed", cb_info);
1745 g_mutex_clear(&cb_info->player_mutex);
1746 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1747 g_cond_clear(&cb_info->player_cond[i]);
1748 g_cond_clear(&cb_info->server_ack_cond);
1750 g_mutex_clear(&cb_info->data_mutex);
1751 g_mutex_clear(&cb_info->seek_cb_mutex);
1753 g_free(cb_info->buff.recvMsg);
1754 _remove_all_ret_msg(cb_info);
1755 if (cb_info->buff.part_of_msg)
1756 g_free(cb_info->buff.part_of_msg);
1760 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1765 case MUSE_PLAYER_API_PREPARE:
1766 case MUSE_PLAYER_API_PREPARE_ASYNC:
1767 case MUSE_PLAYER_API_UNPREPARE:
1768 case MUSE_PLAYER_API_START:
1769 case MUSE_PLAYER_API_STOP:
1770 case MUSE_PLAYER_API_PAUSE:
1771 timeout += SERVER_TIMEOUT(pc);
1774 /* check prepare async is done */
1775 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1776 timeout += SERVER_TIMEOUT(pc);
1779 timeout += CALLBACK_TIME_OUT;
1780 return timeout; /* ms */
1783 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1785 int ret = PLAYER_ERROR_NONE;
1786 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1787 msg_buff_s *buff = &cb_info->buff;
1788 ret_msg_s *msg = NULL;
1790 g_mutex_lock(&cb_info->player_mutex);
1792 msg = _get_ret_msg(api, cb_info);
1794 if (!buff->recved || !msg) {
1795 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1796 LOGW("api %d return msg does not received %dms", api, time_out);
1797 ret = PLAYER_ERROR_INVALID_OPERATION;
1802 msg = _get_ret_msg(api, cb_info);
1804 *ret_buf = msg->msg;
1807 if (!player_msg_get(ret, *ret_buf))
1808 ret = PLAYER_ERROR_INVALID_OPERATION;
1810 LOGE("api %d is the spurious wakeup", api);
1814 g_mutex_unlock(&cb_info->player_mutex);
1818 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1820 int ret = PLAYER_ERROR_NONE;
1821 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1822 msg_buff_s *buff = &cb_info->buff;
1824 g_mutex_lock(&cb_info->player_mutex);
1826 if (!buff->recved) {
1827 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1828 LOGW("server ack msg does not received %dms", time_out);
1830 ret = PLAYER_ERROR_INVALID_OPERATION;
1832 LOGD("Another msg is received, continue create handle");
1833 g_mutex_unlock(&cb_info->player_mutex);
1839 g_mutex_unlock(&cb_info->player_mutex);
1846 * Public Implementation
1849 int player_create(player_h * player)
1851 PLAYER_INSTANCE_CHECK(player);
1853 int ret = PLAYER_ERROR_NONE;
1854 int sock_fd = INVALID_DEFAULT_VALUE;
1857 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1858 muse_core_api_module_e module = MUSE_PLAYER;
1859 player_cli_s *pc = NULL;
1860 char *ret_buf = NULL;
1861 int retry_count = CONNECTION_RETRY;
1866 pc = g_new0(player_cli_s, 1);
1868 return PLAYER_ERROR_OUT_OF_MEMORY;
1870 while (--retry_count) {
1871 ret = PLAYER_ERROR_NONE;
1872 sock_fd = muse_client_new();
1873 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1874 LOGE("connection failure %d", errno);
1875 ret = PLAYER_ERROR_INVALID_OPERATION;
1877 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1881 PLAYER_SEND_MSG_ASYNC(api, sock_fd, ret,
1882 MUSE_TYPE_INT, "module", module,
1883 MUSE_TYPE_INT, "pid", pid);
1884 if (ret == PLAYER_ERROR_INVALID_OPERATION)
1887 pc->cb_info = callback_new(sock_fd);
1889 LOGE("fail to create callback");
1890 ret = PLAYER_ERROR_INVALID_OPERATION;
1894 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1895 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1901 if (!_player_event_queue_new(pc->cb_info)) {
1902 LOGE("fail to create event queue");
1903 ret = PLAYER_ERROR_INVALID_OPERATION;
1907 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1908 if (ret == PLAYER_ERROR_NONE) {
1909 intptr_t module_addr = 0;
1910 *player = (player_h) pc;
1911 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1912 pc->cb_info->data_fd = muse_client_new_data_ch();
1913 if (!muse_core_fd_is_valid(pc->cb_info->data_fd)) {
1914 LOGE("Failed to get data_fd");
1915 ret = PLAYER_ERROR_INVALID_OPERATION;
1919 /* share the module addr info to the data_fd */
1920 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_CREATE, pc->cb_info->data_fd, ret,
1921 MUSE_TYPE_POINTER, "module_addr", module_addr);
1922 if (ret != PLAYER_ERROR_NONE) {
1923 LOGE("Failed to send module address to the data fd");
1926 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1928 ret = PLAYER_ERROR_INVALID_OPERATION;
1931 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1935 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1936 pc->cb_info->evas_info = g_new0(player_evas_info_s, 1);
1937 if (pc->cb_info->evas_info == NULL) {
1938 ret = PLAYER_ERROR_OUT_OF_MEMORY;
1941 EVAS_INFO(pc)->visible = EVAS_VISIBLE_NONE;
1943 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1944 pc->push_media_stream = FALSE;
1945 pc->support_video = FALSE;
1946 EVAS_INFO(pc)->support_video = FALSE;
1947 pc->is_audio_only = FALSE;
1949 PLAYER_DISP_DLOPEN(pc); /* update supported_video */
1953 LOGD("LEAVE 0x%X", ret);
1957 if (pc && pc->cb_info) {
1958 if (pc->cb_info->event_queue.running)
1959 _player_event_queue_destroy(pc->cb_info);
1960 callback_destroy(pc->cb_info);
1962 } else if (sock_fd > INVALID_DEFAULT_VALUE) {
1963 muse_client_close(sock_fd);
1965 sock_fd = INVALID_DEFAULT_VALUE;
1968 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1976 LOGD("LEAVE 0x%X", ret);
1980 int player_destroy(player_h player)
1982 PLAYER_INSTANCE_CHECK(player);
1984 int ret = PLAYER_ERROR_NONE;
1985 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1986 player_cli_s *pc = (player_cli_s *) player;
1987 char *ret_buf = NULL;
1989 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1990 int (*p_disp_destroy_evas_display)(void **) = NULL;
1994 /* clear cb and release mem */
1995 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1996 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1997 _player_release_internal_memory(pc, true);
1999 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2000 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2001 if (EVAS_HANDLE(pc)) {
2002 player_unset_media_packet_video_frame_decoded_cb(player);
2003 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2004 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2005 LOGW("fail to unset evas client");
2006 __player_unset_retrieve_buffer_cb(player);
2007 g_free(pc->cb_info->evas_info);
2012 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2014 if (CALLBACK_INFO(pc)) {
2015 __player_remove_tsurf_list(pc);
2016 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
2017 _player_event_queue_destroy(CALLBACK_INFO(pc));
2018 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
2020 callback_destroy(CALLBACK_INFO(pc));
2024 PLAYER_DISP_DLCLOSE(pc->dl_handle); /* update supported_video */
2031 LOGD("LEAVE 0x%X", ret);
2035 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
2037 PLAYER_INSTANCE_CHECK(player);
2038 int ret = PLAYER_ERROR_NONE;
2039 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
2040 player_cli_s *pc = (player_cli_s *) player;
2041 char *ret_buf = NULL;
2045 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
2046 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
2047 return PLAYER_ERROR_INVALID_OPERATION;
2049 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
2050 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
2052 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2053 if (ret == PLAYER_ERROR_NONE) {
2055 player_msg_get_type(timeout, ret_buf, INT);
2057 LOGD("server timeout will be %d sec", timeout);
2058 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2060 LOGW("failed to realize, so prepare cb will be released soon");
2061 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
2062 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2069 int player_prepare(player_h player)
2071 PLAYER_INSTANCE_CHECK(player);
2072 int ret = PLAYER_ERROR_NONE;
2073 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
2074 player_cli_s *pc = (player_cli_s *) player;
2075 char *ret_buf = NULL;
2079 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2080 if (ret == PLAYER_ERROR_NONE) {
2082 player_msg_get_type(timeout, ret_buf, INT);
2084 LOGD("server timeout will be %d sec", timeout);
2085 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2090 LOGD("LEAVE 0x%X", ret);
2094 int player_unprepare(player_h player)
2096 PLAYER_INSTANCE_CHECK(player);
2097 int ret = PLAYER_ERROR_NONE;
2098 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
2099 player_cli_s *pc = (player_cli_s *) player;
2100 char *ret_buf = NULL;
2101 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
2105 if (!CALLBACK_INFO(pc))
2106 return PLAYER_ERROR_INVALID_STATE;
2108 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2109 if (EVAS_INFO(pc)->support_video && EVAS_HANDLE(pc)) {
2110 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
2111 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(pc), false);
2112 if (ret != PLAYER_ERROR_NONE)
2113 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
2117 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2119 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2120 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2121 _player_release_internal_memory(pc, false);
2123 pc->cb_info->video_frame_pool_size = 0;
2124 __player_remove_tsurf_list(pc);
2125 pc->is_audio_only = FALSE;
2129 LOGD("LEAVE 0x%X", ret);
2133 /* 1. correct the protocol prefix to lower case
2134 * 2. remove 'file://' prefix
2135 * 3. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' */
2136 int _player_get_valid_path(const char* uri, char* valid_path)
2138 gchar *file_path = NULL;
2140 gchar *colon = NULL;
2142 if (!uri || !valid_path) {
2143 LOGD("invalid parameter");
2144 return PLAYER_ERROR_INVALID_PARAMETER;
2147 if ((colon = strstr(uri, "://")) != NULL) {
2148 gchar *protocol = g_ascii_strdown(uri, colon - uri);
2152 file_path = g_strconcat(protocol, uri+strlen(protocol), NULL);
2153 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2159 if (strstr(valid_path, "file://")) { /* handle the 'file://' prefix */
2161 file_path = g_filename_from_uri(valid_path, NULL, &err);
2162 if (!file_path || (err != NULL)) {
2163 SECURE_LOGE("Invalid URI '%s', err: %s", uri,
2164 (err != NULL) ? err->message : "unknown error");
2166 if (err) g_error_free(err);
2167 if (file_path) g_free(file_path);
2169 return PLAYER_ERROR_INVALID_PARAMETER;
2171 LOGD("get file path from uri");
2173 LOGD("use the original path.");
2174 return PLAYER_ERROR_NONE;
2179 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, valid_path) < 0) {
2180 /* cannot convert path. use the original one. */
2181 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2183 /* need to use converted path. */
2184 SECURE_LOGD("Converted path : %s -> %s", uri, valid_path);
2189 return PLAYER_ERROR_NONE;
2192 int player_set_uri(player_h player, const char *uri)
2194 PLAYER_INSTANCE_CHECK(player);
2195 PLAYER_NULL_ARG_CHECK(uri);
2196 int ret = PLAYER_ERROR_NONE;
2197 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2198 player_cli_s *pc = (player_cli_s *) player;
2199 char *ret_buf = NULL;
2200 char path[MAX_URL_LEN] = {0, };
2204 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
2205 return PLAYER_ERROR_INVALID_PARAMETER;
2207 SECURE_LOGD("new path : %s", path);
2209 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", (const char*)path);
2210 pc->push_media_stream = FALSE;
2216 int player_set_memory_buffer(player_h player, const void *data, int size)
2218 PLAYER_INSTANCE_CHECK(player);
2219 PLAYER_NULL_ARG_CHECK(data);
2220 int ret = PLAYER_ERROR_NONE;
2221 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2222 player_cli_s *pc = (player_cli_s *) player;
2223 char *ret_buf = NULL;
2225 tbm_bo_handle thandle;
2226 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2228 /* before setting mem buffer, player state have to be checked. */
2229 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2231 if (SERVER_TBM_BO(pc)) {
2232 LOGW("The previous memory buffer will be cleared.");
2233 _player_deinit_memory_buffer(pc);
2236 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2238 LOGE("TBM get error : bo is NULL");
2239 return PLAYER_ERROR_INVALID_OPERATION;
2241 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2242 if (thandle.ptr == NULL) {
2243 LOGE("TBM get error : handle pointer is NULL");
2244 ret = PLAYER_ERROR_INVALID_OPERATION;
2247 memcpy(thandle.ptr, data, size);
2250 tfd = tbm_bo_export_fd(bo);
2252 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2253 ret = PLAYER_ERROR_INVALID_OPERATION;
2257 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret, MUSE_TYPE_INT, "size", size);
2258 pc->push_media_stream = FALSE;
2261 if (tfd > INVALID_DEFAULT_VALUE)
2266 if (ret == PLAYER_ERROR_NONE) {
2267 intptr_t bo_addr = 0;
2268 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2269 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2276 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem)
2283 if (deinit_server_mem)
2284 _player_deinit_memory_buffer(pc);
2287 static int _player_deinit_memory_buffer(player_cli_s * pc)
2289 PLAYER_INSTANCE_CHECK(pc);
2290 int ret = PLAYER_ERROR_NONE;
2291 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2292 intptr_t bo_addr = SERVER_TBM_BO(pc);
2294 if (!bo_addr || !CALLBACK_INFO(pc))
2297 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_POINTER, "bo_addr", bo_addr);
2298 SERVER_TBM_BO(pc) = 0;
2303 int player_get_state(player_h player, player_state_e *pstate)
2305 PLAYER_INSTANCE_CHECK(player);
2306 PLAYER_NULL_ARG_CHECK(pstate);
2307 int ret = PLAYER_ERROR_NONE;
2308 player_cli_s *pc = (player_cli_s *) player;
2312 ret = _get_current_state(pc, pstate);
2316 int player_set_volume(player_h player, float left, float right)
2318 PLAYER_INSTANCE_CHECK(player);
2319 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2320 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2321 int ret = PLAYER_ERROR_NONE;
2322 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2323 player_cli_s *pc = (player_cli_s *) player;
2324 char *ret_buf = NULL;
2328 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2329 MUSE_TYPE_DOUBLE, "right", (double)right,
2330 MUSE_TYPE_DOUBLE, "left", (double)left);
2336 int player_get_volume(player_h player, float *pleft, float *pright)
2338 PLAYER_INSTANCE_CHECK(player);
2339 PLAYER_NULL_ARG_CHECK(pleft && pright);
2340 int ret = PLAYER_ERROR_NONE;
2341 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2342 player_cli_s *pc = (player_cli_s *) player;
2345 char *ret_buf = NULL;
2349 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2351 if (ret == PLAYER_ERROR_NONE) {
2352 bool ret_val = true;
2353 ret_val = _player_get_param_value(ret_buf,
2354 MUSE_TYPE_DOUBLE, "left", (void *)&left,
2355 MUSE_TYPE_DOUBLE, "right", (void *)&right,
2356 INVALID_MUSE_TYPE_VALUE);
2358 *pleft = (float)left;
2359 *pright = (float)right;
2361 LOGE("failed to get value from msg");
2362 ret = PLAYER_ERROR_INVALID_OPERATION;
2370 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2372 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SOUND_STREAM);
2373 PLAYER_INSTANCE_CHECK(player);
2375 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2376 player_cli_s *pc = (player_cli_s *) player;
2377 bool is_available = false;
2378 char *ret_buf = NULL;
2382 /* check if stream_info is valid */
2383 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2384 if (ret != SOUND_MANAGER_ERROR_NONE) {
2385 LOGE("failed to checking available stream info");
2386 return PLAYER_ERROR_INVALID_OPERATION;
2389 if (is_available == false) {
2390 ret = PLAYER_ERROR_INVALID_PARAMETER;
2392 char *stream_type = NULL;
2393 int stream_index = 0;
2394 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2395 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2396 if (ret == SOUND_MANAGER_ERROR_NONE)
2397 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2398 MUSE_TYPE_STRING, "stream_type", (const char*)stream_type,
2399 MUSE_TYPE_INT, "stream_index", stream_index);
2401 ret = PLAYER_ERROR_INVALID_OPERATION;
2404 LOGD("LEAVE ret: 0x%X", ret);
2411 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2413 PLAYER_INSTANCE_CHECK(player);
2414 int ret = PLAYER_ERROR_NONE;
2415 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2416 player_cli_s *pc = (player_cli_s *) player;
2417 char *ret_buf = NULL;
2421 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "latency_mode", (int)latency_mode);
2426 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2428 PLAYER_INSTANCE_CHECK(player);
2429 PLAYER_NULL_ARG_CHECK(platency_mode);
2430 int ret = PLAYER_ERROR_NONE;
2431 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2432 player_cli_s *pc = (player_cli_s *) player;
2433 char *ret_buf = NULL;
2434 int latency_mode = -1;
2438 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2440 if (ret == PLAYER_ERROR_NONE) {
2441 player_msg_get(latency_mode, ret_buf);
2442 *platency_mode = latency_mode;
2450 int player_start(player_h player)
2452 PLAYER_INSTANCE_CHECK(player);
2453 int ret = PLAYER_ERROR_NONE;
2454 muse_player_api_e api = MUSE_PLAYER_API_START;
2455 player_cli_s *pc = (player_cli_s *) player;
2456 char *ret_buf = NULL;
2459 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2460 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2462 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2463 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2464 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2465 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2466 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), true);
2467 if (ret != MM_ERROR_NONE) {
2468 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2469 return PLAYER_ERROR_INVALID_OPERATION;
2471 /* avoid setting true at all times, when player is resumed */
2472 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2477 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2481 LOGD("LEAVE 0x%X", ret);
2485 int player_stop(player_h player)
2487 PLAYER_INSTANCE_CHECK(player);
2488 int ret = PLAYER_ERROR_NONE;
2489 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2490 player_cli_s *pc = (player_cli_s *) player;
2491 char *ret_buf = NULL;
2492 player_state_e state = PLAYER_STATE_NONE;
2493 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2494 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2498 /* check player state */
2499 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2500 LOGE("Failed to get state");
2501 return PLAYER_ERROR_INVALID_OPERATION;
2504 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2505 LOGE("Invalid state %d", state);
2506 return PLAYER_ERROR_INVALID_STATE;
2509 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2510 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2511 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2512 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2513 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2514 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), false);
2515 if (ret != MM_ERROR_NONE) {
2516 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2517 return PLAYER_ERROR_INVALID_OPERATION;
2519 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2523 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2524 if (ret == PLAYER_ERROR_NONE)
2525 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2529 LOGD("LEAVE 0x%X", ret);
2533 int player_pause(player_h player)
2535 PLAYER_INSTANCE_CHECK(player);
2536 int ret = PLAYER_ERROR_NONE;
2537 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2538 player_cli_s *pc = (player_cli_s *) player;
2539 char *ret_buf = NULL;
2543 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2546 LOGD("LEAVE 0x%X", ret);
2550 static int _set_play_position(player_h player, int64_t pos, bool accurate, player_seek_completed_cb callback, void *user_data)
2552 PLAYER_INSTANCE_CHECK(player);
2553 PLAYER_CHECK_CONDITION(pos >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2555 int ret = PLAYER_ERROR_NONE;
2556 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2557 player_cli_s *pc = (player_cli_s *) player;
2558 char *ret_buf = NULL;
2563 LOGE("cb_info is null");
2564 return PLAYER_ERROR_INVALID_OPERATION;
2567 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2568 if ((pc->push_media_stream == FALSE) &&
2569 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2570 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2571 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2572 return PLAYER_ERROR_SEEK_FAILED;
2574 if (pc->push_media_stream == TRUE)
2575 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2577 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2578 LOGI("Event type : %d, pos : %"PRId64", accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, pos, accurate);
2579 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2580 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2582 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2584 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2585 MUSE_TYPE_INT64, "pos", pos,
2586 MUSE_TYPE_INT, "accurate", (int)accurate);
2588 if (ret != PLAYER_ERROR_NONE) {
2589 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2590 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2591 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2594 if (pc->push_media_stream == TRUE)
2595 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2599 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2600 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2601 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2603 LOGD("LEAVE 0x%X", ret);
2608 int player_set_play_position(player_h player, int milliseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2610 PLAYER_INSTANCE_CHECK(player);
2611 PLAYER_CHECK_CONDITION(milliseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2613 int ret = PLAYER_ERROR_NONE;
2614 int64_t pos = (int64_t)(milliseconds * G_GINT64_CONSTANT(1000000));
2618 ret = _set_play_position(player, pos, accurate, callback, user_data);
2620 LOGD("LEAVE 0x%X", ret);
2624 int player_set_play_position_nsec(player_h player, int64_t nanoseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2626 PLAYER_INSTANCE_CHECK(player);
2627 PLAYER_CHECK_CONDITION(nanoseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2629 int ret = PLAYER_ERROR_NONE;
2630 int64_t pos = nanoseconds;
2634 ret = _set_play_position(player, pos, accurate, callback, user_data);
2636 LOGD("LEAVE 0x%X", ret);
2640 static int _get_play_position(player_h player, int64_t *pos)
2642 PLAYER_INSTANCE_CHECK(player);
2643 PLAYER_NULL_ARG_CHECK(pos);
2645 int ret = PLAYER_ERROR_NONE;
2646 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2647 player_cli_s *pc = (player_cli_s *) player;
2648 char *ret_buf = NULL;
2650 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2652 if (ret == PLAYER_ERROR_NONE) {
2653 bool ret_val = true;
2654 ret_val = _player_get_param_value(ret_buf,
2655 MUSE_TYPE_INT64, "pos", (void *)pos,
2656 INVALID_MUSE_TYPE_VALUE);
2658 ret = PLAYER_ERROR_INVALID_OPERATION;
2666 int player_get_play_position(player_h player, int *milliseconds)
2668 PLAYER_INSTANCE_CHECK(player);
2669 PLAYER_NULL_ARG_CHECK(milliseconds);
2671 int ret = PLAYER_ERROR_NONE;
2674 /* LOGD("ENTER"); */
2676 ret = _get_play_position(player, &pos);
2677 if (ret == PLAYER_ERROR_NONE)
2678 *milliseconds = (int)(pos / G_GINT64_CONSTANT(1000000));
2683 int player_get_play_position_nsec(player_h player, int64_t *nanoseconds)
2685 PLAYER_INSTANCE_CHECK(player);
2686 PLAYER_NULL_ARG_CHECK(nanoseconds);
2688 int ret = PLAYER_ERROR_NONE;
2691 /* LOGD("ENTER"); */
2693 ret = _get_play_position(player, &pos);
2694 if (ret == PLAYER_ERROR_NONE)
2700 int player_set_mute(player_h player, bool muted)
2702 PLAYER_INSTANCE_CHECK(player);
2703 int ret = PLAYER_ERROR_NONE;
2704 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2705 player_cli_s *pc = (player_cli_s *) player;
2706 char *ret_buf = NULL;
2707 int mute = (int)muted;
2711 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mute", mute);
2716 int player_is_muted(player_h player, bool * muted)
2718 PLAYER_INSTANCE_CHECK(player);
2719 PLAYER_NULL_ARG_CHECK(muted);
2720 int ret = PLAYER_ERROR_NONE;
2721 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2722 player_cli_s *pc = (player_cli_s *) player;
2723 char *ret_buf = NULL;
2728 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2729 if (ret == PLAYER_ERROR_NONE) {
2730 player_msg_get(mute, ret_buf);
2731 *muted = (bool) mute;
2738 int player_set_looping(player_h player, bool looping)
2740 PLAYER_INSTANCE_CHECK(player);
2741 int ret = PLAYER_ERROR_NONE;
2742 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2743 player_cli_s *pc = (player_cli_s *) player;
2744 char *ret_buf = NULL;
2748 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "looping", (int)looping);
2753 int player_is_looping(player_h player, bool * plooping)
2755 PLAYER_INSTANCE_CHECK(player);
2756 PLAYER_NULL_ARG_CHECK(plooping);
2757 int ret = PLAYER_ERROR_NONE;
2758 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2759 player_cli_s *pc = (player_cli_s *) player;
2760 char *ret_buf = NULL;
2765 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2766 if (ret == PLAYER_ERROR_NONE) {
2767 player_msg_get(looping, ret_buf);
2768 *plooping = looping;
2774 static int _get_duration(player_h player, int64_t *duration)
2776 PLAYER_INSTANCE_CHECK(player);
2777 PLAYER_NULL_ARG_CHECK(duration);
2779 int ret = PLAYER_ERROR_NONE;
2780 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2781 player_cli_s *pc = (player_cli_s *) player;
2782 char *ret_buf = NULL;
2786 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2787 if (ret == PLAYER_ERROR_NONE) {
2788 bool ret_val = true;
2789 ret_val = _player_get_param_value(ret_buf,
2790 MUSE_TYPE_INT64, "duration", (void *)duration,
2791 INVALID_MUSE_TYPE_VALUE);
2793 ret = PLAYER_ERROR_INVALID_OPERATION;
2801 int player_get_duration(player_h player, int *milliseconds)
2803 PLAYER_INSTANCE_CHECK(player);
2804 PLAYER_NULL_ARG_CHECK(milliseconds);
2806 int ret = PLAYER_ERROR_NONE;
2807 int64_t duration = 0; /* nsec */
2811 ret = _get_duration(player, &duration);
2812 if (ret == PLAYER_ERROR_NONE) {
2813 /* convert time from ns to ms */
2814 *milliseconds = (int)(duration / G_GINT64_CONSTANT(1000000));
2817 LOGD("LEAVE 0x%X", ret);
2821 int player_get_duration_nsec(player_h player, int64_t *nanoseconds)
2823 PLAYER_INSTANCE_CHECK(player);
2824 PLAYER_NULL_ARG_CHECK(nanoseconds);
2826 int ret = PLAYER_ERROR_NONE;
2827 int64_t duration = 0; /* nsec */
2831 ret = _get_duration(player, &duration);
2832 if (ret == PLAYER_ERROR_NONE)
2833 *nanoseconds = duration;
2835 LOGD("LEAVE 0x%X", ret);
2839 /* The player_display_type_e is different at wearable profile */
2840 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2842 int ret = PLAYER_ERROR_NONE;
2843 PLAYER_NULL_ARG_CHECK(out_type);
2846 case PLAYER_DISPLAY_TYPE_OVERLAY:
2847 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2849 case PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE:
2850 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2851 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2853 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2855 case PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS:
2856 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2857 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2859 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2861 case PLAYER_DISPLAY_TYPE_EVAS:
2862 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2864 case PLAYER_DISPLAY_TYPE_NONE:
2865 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2868 ret = PLAYER_ERROR_INVALID_PARAMETER;
2872 LOGD("display type(%d) -> (%d)", type, *out_type);
2876 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2878 PLAYER_INSTANCE_CHECK(player);
2879 int ret = PLAYER_ERROR_NONE;
2880 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2881 player_cli_s *pc = (player_cli_s *) player;
2882 char *ret_buf = NULL;
2883 wl_win_msg_type wl_win;
2884 char *wl_win_msg = (char *)&wl_win;
2885 unsigned int wl_surface_id;
2886 player_private_display_type_e conv_type;
2887 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
2888 int arr_msg_len = 0;
2889 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2890 int (*p_disp_destroy_evas_display)(void **) = NULL;
2891 int (*p_disp_create_evas_display)(void *, void **) = NULL;
2892 int (*p_disp_set_evas_display_old_info)(void *, void *, int, int, int) = NULL;
2893 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2894 void (*p_disp_get_evas_display_geometry_info)(void *, int *, int *, int *, int *) = NULL;
2895 void (*p_disp_media_packet_video_decode_cb)(media_packet_h, void *) = NULL;
2897 pid_t pid = getpid();
2898 pid_t tid = syscall(SYS_gettid);
2902 LOGD("Check if API is called in main thread. pid [%d], tid [%d]", pid, tid);
2904 LOGE("API isn't called in main thread");
2905 return PLAYER_ERROR_INVALID_OPERATION;
2908 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2911 wl_win.wl_window_x = 0;
2912 wl_win.wl_window_y = 0;
2913 wl_win.wl_window_width = 0;
2914 wl_win.wl_window_height = 0;
2916 LOGD("ENTER type: %d", type);
2917 if (type == PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE ||
2918 type == PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS) {
2919 LOGW("DEPRECATION WARNING: display type(%d) is deprecated and will be removed from next release. Use newly defined type value instead.", type);
2922 /* before setting display, player state have to be checked. */
2923 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2925 ret = _player_convert_display_type(type, &conv_type);
2926 if (ret != PLAYER_ERROR_NONE)
2929 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2931 return PLAYER_ERROR_INVALID_PARAMETER;
2933 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2935 * To support repeating play and stop, Evas_handle should not be destroyed in player_unprepare.
2936 * When the display type changes, Player need to destroy Evas_handle to set values of video output,
2937 * Otherwise, the values is not set because of checking Evas_handle.
2939 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
2940 LOGW("evas client already exists");
2941 player_unset_media_packet_video_frame_decoded_cb(player);
2942 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2943 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2944 LOGW("fail to unset evas client");
2945 __player_unset_retrieve_buffer_cb(player);
2946 /* need to set display information again to new handle */
2947 EVAS_INFO(pc)->update_needed = TRUE;
2950 /* set evas_render or wayland */
2951 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
2952 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
2953 wl_surface_id = p_disp_set_wl_display(ELM_WAYLAND_WIN, display);
2954 if (wl_surface_id > 0) {
2955 wl_win.wl_surface_id = wl_surface_id;
2956 wl_win.type = conv_type;
2957 } else return PLAYER_ERROR_INVALID_OPERATION;
2959 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2960 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS) {
2961 if (!CALLBACK_INFO(pc)) {
2962 LOGE("there is no cb info in player handle");
2963 return PLAYER_ERROR_INVALID_OPERATION;
2966 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_create_evas_display, "disp_create_evas_display");
2967 ret = p_disp_create_evas_display(display, &EVAS_HANDLE(pc));
2968 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2970 /* before evas handle is created, user could set display information */
2971 if (EVAS_INFO(pc)->update_needed) {
2972 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_old_info, "disp_set_evas_display_old_info");
2973 ret = p_disp_set_evas_display_old_info(display, EVAS_HANDLE(pc), EVAS_INFO(pc)->mode, EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2974 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2975 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2976 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2977 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);
2978 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2980 EVAS_INFO(pc)->update_needed = FALSE;
2982 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_geometry_info, "disp_get_evas_display_geometry_info");
2983 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);
2984 wl_win.type = conv_type;
2986 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_media_packet_video_decode_cb, "disp_media_packet_video_decode_cb");
2987 ret = player_set_media_packet_video_frame_decoded_cb(player, p_disp_media_packet_video_decode_cb, (void *)EVAS_HANDLE(pc));
2988 if (ret != PLAYER_ERROR_NONE)
2989 LOGW("fail to set decoded callback");
2990 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2991 LOGW("fail to set __retrieve_buffer_cb");
2994 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2995 LOGI("Wayland surface type is NONE");
2996 wl_win.type = conv_type;
2999 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
3000 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3001 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
3007 int player_set_display_mode(player_h player, player_display_mode_e mode)
3009 PLAYER_INSTANCE_CHECK(player);
3010 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3011 int ret = PLAYER_ERROR_NONE;
3012 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
3013 player_cli_s *pc = (player_cli_s *) player;
3014 char *ret_buf = NULL;
3015 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3016 int (*p_disp_set_evas_display_disp_mode)(void *, int) = NULL;
3019 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3021 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3022 if (EVAS_HANDLE(pc)) {
3023 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_disp_mode, "disp_set_evas_display_disp_mode");
3024 ret = p_disp_set_evas_display_disp_mode(EVAS_HANDLE(pc), mode);
3025 if (ret != MM_ERROR_NONE)
3026 return PLAYER_ERROR_INVALID_OPERATION;
3028 return PLAYER_ERROR_NONE;
3030 EVAS_INFO(pc)->mode = mode;
3031 EVAS_INFO(pc)->update_needed = TRUE;
3034 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mode", (int)mode);
3039 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
3041 PLAYER_INSTANCE_CHECK(player);
3042 PLAYER_NULL_ARG_CHECK(pmode);
3043 int ret = PLAYER_ERROR_NONE;
3044 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
3045 player_cli_s *pc = (player_cli_s *) player;
3046 char *ret_buf = NULL;
3048 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3049 int (*p_disp_get_evas_display_disp_mode)(void *, int *) = NULL;
3053 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3055 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3056 if (EVAS_HANDLE(pc)) {
3057 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_disp_mode, "disp_get_evas_display_disp_mode");
3058 ret = p_disp_get_evas_display_disp_mode(EVAS_HANDLE(pc), &mode);
3059 *pmode = (player_display_mode_e) mode;
3060 if (ret != MM_ERROR_NONE)
3061 return PLAYER_ERROR_INVALID_OPERATION;
3063 return PLAYER_ERROR_NONE;
3066 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3067 if (ret == PLAYER_ERROR_NONE) {
3068 player_msg_get_type(mode, ret_buf, INT);
3077 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
3079 PLAYER_INSTANCE_CHECK(player);
3080 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3082 int ret = PLAYER_ERROR_NONE;
3083 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
3084 player_cli_s *pc = (player_cli_s *) player;
3085 char *ret_buf = NULL;
3086 wl_win_msg_type wl_win;
3087 char *wl_win_msg = (char *)&wl_win;
3088 int arr_msg_len = 0;
3089 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3090 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
3094 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3096 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3097 if (EVAS_HANDLE(pc)) {
3098 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
3099 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), x, y, width, height);
3100 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
3101 return PLAYER_ERROR_INVALID_PARAMETER;
3102 else if (ret != MM_ERROR_NONE)
3103 return PLAYER_ERROR_INVALID_OPERATION;
3105 return PLAYER_ERROR_NONE;
3107 EVAS_INFO(pc)->roi_x = x;
3108 EVAS_INFO(pc)->roi_y = y;
3109 EVAS_INFO(pc)->roi_w = width;
3110 EVAS_INFO(pc)->roi_h = height;
3111 EVAS_INFO(pc)->update_needed = TRUE;
3114 wl_win.wl_window_x = x;
3115 wl_win.wl_window_y = y;
3116 wl_win.wl_window_width = width;
3117 wl_win.wl_window_height = height;
3119 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
3120 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3121 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
3127 int player_set_playback_rate(player_h player, float rate)
3129 PLAYER_INSTANCE_CHECK(player);
3130 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3131 int ret = PLAYER_ERROR_NONE;
3132 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
3133 player_cli_s *pc = (player_cli_s *) player;
3134 char *ret_buf = NULL;
3138 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", (double)rate);
3141 LOGD("LEAVE 0x%X", ret);
3145 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
3147 PLAYER_INSTANCE_CHECK(player);
3148 int ret = PLAYER_ERROR_NONE;
3149 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
3150 player_cli_s *pc = (player_cli_s *) player;
3151 char *ret_buf = NULL;
3152 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3153 int (*p_disp_set_evas_display_rotation)(void *, int) = NULL;
3157 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3159 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3160 if (EVAS_HANDLE(pc)) {
3161 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_rotation, "disp_set_evas_display_rotation");
3162 ret = p_disp_set_evas_display_rotation(EVAS_HANDLE(pc), rotation);
3163 if (ret != MM_ERROR_NONE)
3164 return PLAYER_ERROR_INVALID_OPERATION;
3166 return PLAYER_ERROR_NONE;
3168 EVAS_INFO(pc)->rotation = rotation;
3169 EVAS_INFO(pc)->update_needed = TRUE;
3172 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "rotation", (int)rotation);
3177 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
3179 PLAYER_INSTANCE_CHECK(player);
3180 PLAYER_NULL_ARG_CHECK(protation);
3181 int ret = PLAYER_ERROR_NONE;
3182 player_cli_s *pc = (player_cli_s *) player;
3183 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
3184 char *ret_buf = NULL;
3186 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3187 int (*p_disp_get_evas_display_rotation)(void *, int *) = NULL;
3191 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3193 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3194 if (EVAS_HANDLE(pc)) {
3195 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_rotation, "disp_get_evas_display_rotation");
3196 ret = p_disp_get_evas_display_rotation(EVAS_HANDLE(pc), &rotation);
3197 *protation = (player_display_rotation_e) rotation;
3198 if (ret != MM_ERROR_NONE)
3199 return PLAYER_ERROR_INVALID_OPERATION;
3201 return PLAYER_ERROR_NONE;
3204 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3205 if (ret == PLAYER_ERROR_NONE) {
3206 player_msg_get_type(rotation, ret_buf, INT);
3207 *protation = rotation;
3214 int player_set_display_visible(player_h player, bool visible)
3216 PLAYER_INSTANCE_CHECK(player);
3217 int ret = PLAYER_ERROR_NONE;
3218 player_cli_s *pc = (player_cli_s *) player;
3219 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
3220 char *ret_buf = NULL;
3221 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3222 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
3226 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3228 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3229 if (EVAS_HANDLE(pc)) {
3230 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
3231 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), visible);
3232 if (ret != MM_ERROR_NONE)
3233 return PLAYER_ERROR_INVALID_OPERATION;
3235 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3236 return PLAYER_ERROR_NONE;
3238 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3239 EVAS_INFO(pc)->update_needed = TRUE;
3243 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "visible", (int)visible);
3248 int player_is_display_visible(player_h player, bool * pvisible)
3250 PLAYER_INSTANCE_CHECK(player);
3251 PLAYER_NULL_ARG_CHECK(pvisible);
3252 int ret = PLAYER_ERROR_NONE;
3253 player_cli_s *pc = (player_cli_s *) player;
3254 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
3255 char *ret_buf = NULL;
3257 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3259 int (*p_disp_get_evas_display_visible)(void *, bool *) = NULL;
3263 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3265 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3266 if (EVAS_HANDLE(pc)) {
3267 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_visible, "disp_get_evas_display_visible");
3268 ret = p_disp_get_evas_display_visible(EVAS_HANDLE(pc), &visible);
3274 if (ret != MM_ERROR_NONE)
3275 return PLAYER_ERROR_INVALID_OPERATION;
3277 return PLAYER_ERROR_NONE;
3280 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3281 if (ret == PLAYER_ERROR_NONE) {
3282 player_msg_get_type(value, ret_buf, INT);
3294 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3296 PLAYER_INSTANCE_CHECK(player);
3297 PLAYER_NULL_ARG_CHECK(pvalue);
3298 int ret = PLAYER_ERROR_NONE;
3299 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3300 player_cli_s *pc = (player_cli_s *) player;
3301 char *ret_buf = NULL;
3302 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3306 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "key", (int)key);
3307 if (ret == PLAYER_ERROR_NONE) {
3308 player_msg_get_string(value, ret_buf);
3309 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3315 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3317 PLAYER_INSTANCE_CHECK(player);
3318 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3319 int ret = PLAYER_ERROR_NONE;
3320 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3321 player_cli_s *pc = (player_cli_s *) player;
3322 char *ret_buf = NULL;
3323 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3324 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3325 bool ret_val = TRUE;
3329 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3330 if (ret == PLAYER_ERROR_NONE) {
3331 ret_val = _player_get_param_value(ret_buf,
3332 MUSE_TYPE_STRING, "video_codec", (void *)video_codec,
3333 MUSE_TYPE_STRING, "audio_codec", (void *)audio_codec,
3334 INVALID_MUSE_TYPE_VALUE);
3337 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3339 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3341 ret = PLAYER_ERROR_INVALID_OPERATION;
3348 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3350 PLAYER_INSTANCE_CHECK(player);
3351 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3352 int ret = PLAYER_ERROR_NONE;
3353 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3354 player_cli_s *pc = (player_cli_s *) player;
3355 char *ret_buf = NULL;
3356 int sample_rate = 0;
3362 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3363 if (ret == PLAYER_ERROR_NONE) {
3364 bool ret_val = true;
3365 ret_val = _player_get_param_value(ret_buf,
3366 MUSE_TYPE_INT, "sample_rate", (void *)&sample_rate,
3367 MUSE_TYPE_INT, "channel", (void *)&channel,
3368 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3369 INVALID_MUSE_TYPE_VALUE);
3372 *psample_rate = sample_rate;
3374 *pchannel = channel;
3376 *pbit_rate = bit_rate;
3378 ret = PLAYER_ERROR_INVALID_OPERATION;
3385 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3387 PLAYER_INSTANCE_CHECK(player);
3388 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3389 int ret = PLAYER_ERROR_NONE;
3390 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3391 player_cli_s *pc = (player_cli_s *) player;
3392 char *ret_buf = NULL;
3398 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3399 if (ret == PLAYER_ERROR_NONE) {
3400 bool ret_val = true;
3401 ret_val = _player_get_param_value(ret_buf,
3402 MUSE_TYPE_INT, "fps", (void *)&fps,
3403 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3404 INVALID_MUSE_TYPE_VALUE);
3409 *pbit_rate = bit_rate;
3411 ret = PLAYER_ERROR_INVALID_OPERATION;
3418 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3420 PLAYER_INSTANCE_CHECK(player);
3421 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3422 int ret = PLAYER_ERROR_NONE;
3423 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3424 player_cli_s *pc = (player_cli_s *) player;
3425 char *ret_buf = NULL;
3431 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3432 if (ret == PLAYER_ERROR_NONE) {
3433 bool ret_val = true;
3434 ret_val = _player_get_param_value(ret_buf,
3435 MUSE_TYPE_INT, "width", (void *)&width,
3436 MUSE_TYPE_INT, "height", (void *)&height,
3437 INVALID_MUSE_TYPE_VALUE);
3442 ret = PLAYER_ERROR_INVALID_OPERATION;
3449 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3451 PLAYER_INSTANCE_CHECK(player);
3452 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3453 int ret = PLAYER_ERROR_NONE;
3454 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3455 player_cli_s *pc = (player_cli_s *) player;
3456 char *ret_buf = NULL;
3460 tbm_bo_handle thandle;
3461 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3462 int key = INVALID_DEFAULT_VALUE;
3467 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3468 if (ret == PLAYER_ERROR_NONE) {
3469 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3470 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3472 LOGE("failed to get msg obj, err:%d", err);
3473 ret = PLAYER_ERROR_INVALID_OPERATION;
3477 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3478 LOGD("size : %d", size);
3479 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3480 LOGE("failed to get key value");
3481 ret = PLAYER_ERROR_INVALID_OPERATION;
3485 tfd = pc->cb_info->tfd;
3487 LOGE("failed to get tbm fd value");
3488 ret = PLAYER_ERROR_INVALID_OPERATION;
3492 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3494 LOGE("TBM get error : bo is NULL");
3495 ret = PLAYER_ERROR_INVALID_OPERATION;
3498 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3499 if (thandle.ptr == NULL) {
3500 LOGE("TBM get error : handle pointer is NULL");
3501 ret = PLAYER_ERROR_INVALID_OPERATION;
3504 album_art = _get_mem(pc, size);
3506 memcpy(album_art, thandle.ptr, size);
3507 *palbum_art = album_art;
3509 LOGE("g_new failure");
3510 ret = PLAYER_ERROR_INVALID_OPERATION;
3522 muse_core_msg_object_free(jobj);
3527 if (tfd > INVALID_DEFAULT_VALUE)
3530 if (CALLBACK_INFO(pc))
3531 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3537 if (key > INVALID_DEFAULT_VALUE && CALLBACK_INFO(pc)) {
3538 LOGD("send msg to release buffer. key:%d", key);
3539 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_RETURN_BUFFER, MSG_FD(pc), ret, MUSE_TYPE_INT, "key", key);
3545 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3547 PLAYER_INSTANCE_CHECK(player);
3548 PLAYER_NULL_ARG_CHECK(pcount);
3549 int ret = PLAYER_ERROR_NONE;
3550 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3551 player_cli_s *pc = (player_cli_s *) player;
3552 char *ret_buf = NULL;
3557 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3558 if (ret == PLAYER_ERROR_NONE) {
3559 player_msg_get(count, ret_buf);
3566 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3568 PLAYER_INSTANCE_CHECK(player);
3569 PLAYER_NULL_ARG_CHECK(band_levels);
3570 int ret = PLAYER_ERROR_NONE;
3571 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3572 player_cli_s *pc = (player_cli_s *) player;
3573 char *ret_buf = NULL;
3577 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3578 MUSE_TYPE_INT, "length", length,
3579 MUSE_TYPE_ARRAY, "band_levels", length, band_levels);
3586 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3588 PLAYER_INSTANCE_CHECK(player);
3589 int ret = PLAYER_ERROR_NONE;
3590 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3591 player_cli_s *pc = (player_cli_s *) player;
3592 char *ret_buf = NULL;
3596 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3597 MUSE_TYPE_INT, "index", index,
3598 MUSE_TYPE_INT, "level", level);
3604 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3606 PLAYER_INSTANCE_CHECK(player);
3607 PLAYER_NULL_ARG_CHECK(plevel);
3608 int ret = PLAYER_ERROR_NONE;
3609 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3610 player_cli_s *pc = (player_cli_s *) player;
3611 char *ret_buf = NULL;
3616 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3617 if (ret == PLAYER_ERROR_NONE) {
3618 player_msg_get(level, ret_buf);
3625 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3627 PLAYER_INSTANCE_CHECK(player);
3628 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3629 int ret = PLAYER_ERROR_NONE;
3630 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3631 player_cli_s *pc = (player_cli_s *) player;
3632 char *ret_buf = NULL;
3633 int min = 0, max = 0;
3637 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3638 if (ret == PLAYER_ERROR_NONE) {
3639 bool ret_val = true;
3640 ret_val = _player_get_param_value(ret_buf,
3641 MUSE_TYPE_INT, "min", (void *)&min,
3642 MUSE_TYPE_INT, "max", (void *)&max,
3643 INVALID_MUSE_TYPE_VALUE);
3648 ret = PLAYER_ERROR_INVALID_OPERATION;
3655 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3657 PLAYER_INSTANCE_CHECK(player);
3658 PLAYER_NULL_ARG_CHECK(pfrequency);
3659 int ret = PLAYER_ERROR_NONE;
3660 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3661 player_cli_s *pc = (player_cli_s *) player;
3662 char *ret_buf = NULL;
3667 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3668 if (ret == PLAYER_ERROR_NONE) {
3669 player_msg_get(frequency, ret_buf);
3670 *pfrequency = frequency;
3676 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3678 PLAYER_INSTANCE_CHECK(player);
3679 PLAYER_NULL_ARG_CHECK(prange);
3680 int ret = PLAYER_ERROR_NONE;
3681 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3682 player_cli_s *pc = (player_cli_s *) player;
3683 char *ret_buf = NULL;
3688 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3689 if (ret == PLAYER_ERROR_NONE) {
3690 player_msg_get(range, ret_buf);
3697 int player_audio_effect_equalizer_clear(player_h player)
3699 PLAYER_INSTANCE_CHECK(player);
3700 int ret = PLAYER_ERROR_NONE;
3701 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3702 player_cli_s *pc = (player_cli_s *) player;
3703 char *ret_buf = NULL;
3707 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3712 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3714 PLAYER_INSTANCE_CHECK(player);
3715 PLAYER_NULL_ARG_CHECK(pavailable);
3716 int ret = PLAYER_ERROR_NONE;
3717 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3718 player_cli_s *pc = (player_cli_s *) player;
3719 char *ret_buf = NULL;
3724 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3725 if (ret == PLAYER_ERROR_NONE) {
3726 player_msg_get(available, ret_buf);
3727 *pavailable = available;
3733 int player_set_subtitle_path(player_h player, const char *path)
3735 PLAYER_INSTANCE_CHECK(player);
3736 int ret = PLAYER_ERROR_NONE;
3737 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3738 player_cli_s *pc = (player_cli_s *) player;
3739 char *ret_buf = NULL;
3740 char subtitle_path[MAX_URL_LEN] = {0, };
3744 if (path && _player_get_valid_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3745 return PLAYER_ERROR_INVALID_PARAMETER;
3747 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "subtitle_path", (const char*)subtitle_path);
3752 int player_set_subtitle_position_offset(player_h player, int milliseconds)
3754 PLAYER_INSTANCE_CHECK(player);
3755 int ret = PLAYER_ERROR_NONE;
3756 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3757 player_cli_s *pc = (player_cli_s *) player;
3758 char *ret_buf = NULL;
3762 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "milliseconds", milliseconds);
3768 int player_set_progressive_download_path(player_h player, const char *path)
3770 PLAYER_INSTANCE_CHECK(player);
3771 PLAYER_NULL_ARG_CHECK(path);
3772 int ret = PLAYER_ERROR_NONE;
3773 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
3774 player_cli_s *pc = (player_cli_s *) player;
3775 char *ret_buf = NULL;
3776 char dw_path[MAX_URL_LEN] = {0, };
3779 LOGW("DEPRECATION WARNING: player_set_progressive_download_path() is deprecated and will be removed from next release.");
3781 if (!_player_check_network_availability())
3782 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3784 if (_player_get_valid_path(path, dw_path) != PLAYER_ERROR_NONE)
3785 return PLAYER_ERROR_INVALID_PARAMETER;
3787 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "dw_path", (const char*)dw_path);
3792 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
3794 PLAYER_INSTANCE_CHECK(player);
3795 PLAYER_NULL_ARG_CHECK(pcurrent && ptotal_size);
3796 int ret = PLAYER_ERROR_NONE;
3797 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
3798 player_cli_s *pc = (player_cli_s *) player;
3799 char *ret_buf = NULL;
3800 unsigned long current, total_size;
3803 LOGW("DEPRECATION WARNING: player_get_progressive_download_status() is deprecated and will be removed from next release.");
3805 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3806 if (ret == PLAYER_ERROR_NONE) {
3807 bool ret_val = true;
3808 ret_val = _player_get_param_value(ret_buf,
3809 MUSE_TYPE_POINTER, "current", (void *)¤t,
3810 MUSE_TYPE_POINTER, "total_size", (void *)&total_size,
3811 INVALID_MUSE_TYPE_VALUE);
3813 *pcurrent = current;
3814 *ptotal_size = total_size;
3816 ret = PLAYER_ERROR_INVALID_OPERATION;
3824 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3826 PLAYER_INSTANCE_CHECK(player);
3827 PLAYER_NULL_ARG_CHECK(callback);
3828 int ret = PLAYER_ERROR_NONE;
3829 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3830 player_cli_s *pc = (player_cli_s *) player;
3831 char *ret_buf = NULL;
3834 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3835 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3836 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3838 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3839 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3840 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3843 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3845 if (ret != PLAYER_ERROR_NONE)
3846 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3852 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3854 PLAYER_INSTANCE_CHECK(player);
3855 PLAYER_NULL_ARG_CHECK(cookie);
3856 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3857 int ret = PLAYER_ERROR_NONE;
3858 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3859 player_cli_s *pc = (player_cli_s *) player;
3860 char *ret_buf = NULL;
3864 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3865 MUSE_TYPE_STRING, "cookie", cookie,
3866 MUSE_TYPE_INT, "size", size);
3871 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3873 PLAYER_INSTANCE_CHECK(player);
3874 PLAYER_NULL_ARG_CHECK(user_agent);
3875 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3876 int ret = PLAYER_ERROR_NONE;
3877 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3878 player_cli_s *pc = (player_cli_s *) player;
3879 char *ret_buf = NULL;
3883 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3884 MUSE_TYPE_STRING, "user_agent", user_agent,
3885 MUSE_TYPE_INT, "size", size);
3890 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3892 PLAYER_INSTANCE_CHECK(player);
3893 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3894 int ret = PLAYER_ERROR_NONE;
3895 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3896 player_cli_s *pc = (player_cli_s *) player;
3897 char *ret_buf = NULL;
3898 int start = 0, current = 0;
3902 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3903 if (ret == PLAYER_ERROR_NONE) {
3904 bool ret_val = true;
3905 ret_val = _player_get_param_value(ret_buf,
3906 MUSE_TYPE_INT, "start", (void *)&start,
3907 MUSE_TYPE_INT, "current", (void *)¤t,
3908 INVALID_MUSE_TYPE_VALUE);
3911 *pcurrent = current;
3913 ret = PLAYER_ERROR_INVALID_OPERATION;
3921 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3923 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3926 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3927 static void __retrieve_buffer_cb(void *user_data)
3929 player_cli_s *player = (player_cli_s *)user_data;
3930 int ret = PLAYER_ERROR_NONE;
3931 bool gapless = false;
3932 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
3934 ret = player_is_gapless((player_h)user_data, &gapless);
3935 if (ret != PLAYER_ERROR_NONE) {
3936 LOGW("player_is_gapless is failed");
3940 PLAYER_DISP_DLSYM(player->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
3941 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3942 if (ret != PLAYER_ERROR_NONE)
3943 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3946 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3948 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3951 static int __player_unset_retrieve_buffer_cb(player_h player)
3953 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3957 int player_unset_completed_cb(player_h player)
3959 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3962 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3964 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3967 int player_unset_interrupted_cb(player_h player)
3969 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3972 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3974 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3977 int player_unset_error_cb(player_h player)
3979 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3982 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3984 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3987 int player_unset_buffering_cb(player_h player)
3989 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3992 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3994 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3997 int player_unset_subtitle_updated_cb(player_h player)
3999 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
4002 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
4004 PLAYER_INSTANCE_CHECK(player);
4005 PLAYER_NULL_ARG_CHECK(callback);
4006 int ret = PLAYER_ERROR_NONE;
4007 player_cli_s *pc = (player_cli_s *) player;
4008 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4009 char *ret_buf = NULL;
4010 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
4014 LOGW("DEPRECATION WARNING: player_set_progressive_download_message_cb() is deprecated and will be removed from next release.");
4016 if (!_player_check_network_availability())
4017 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
4019 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4020 MUSE_TYPE_INT, "type", type,
4021 MUSE_TYPE_INT, "set", set);
4023 if (ret == PLAYER_ERROR_NONE) {
4024 pc->cb_info->user_cb[type] = callback;
4025 pc->cb_info->user_data[type] = user_data;
4026 LOGI("Event type : %d ", type);
4033 int player_unset_progressive_download_message_cb(player_h player)
4035 PLAYER_INSTANCE_CHECK(player);
4036 int ret = PLAYER_ERROR_NONE;
4037 player_cli_s *pc = (player_cli_s *) player;
4038 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4039 char *ret_buf = NULL;
4040 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
4044 LOGW("DEPRECATION WARNING: player_unset_progressive_download_message_cb() is deprecated and will be removed from next release.");
4046 set_null_user_cb_lock(pc->cb_info, type);
4048 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4049 MUSE_TYPE_INT, "type", type,
4050 MUSE_TYPE_INT, "set", set);
4057 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
4059 PLAYER_INSTANCE_CHECK(player);
4060 PLAYER_NULL_ARG_CHECK(callback);
4061 int ret = PLAYER_ERROR_NONE;
4062 player_cli_s *pc = (player_cli_s *) player;
4063 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4064 char *ret_buf = NULL;
4065 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
4070 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4071 MUSE_TYPE_INT, "type", type,
4072 MUSE_TYPE_INT, "set", set);
4074 if (ret == PLAYER_ERROR_NONE) {
4075 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
4076 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
4077 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
4084 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
4086 PLAYER_INSTANCE_CHECK(player);
4087 int ret = PLAYER_ERROR_NONE;
4088 player_cli_s *pc = (player_cli_s *) player;
4089 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4090 char *ret_buf = NULL;
4091 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
4096 set_null_user_cb_lock(pc->cb_info, type);
4098 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4099 MUSE_TYPE_INT, "type", type,
4100 MUSE_TYPE_INT, "set", set);
4106 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
4108 PLAYER_INSTANCE_CHECK(player);
4109 PLAYER_NULL_ARG_CHECK(callback);
4110 int ret = PLAYER_ERROR_NONE;
4111 player_cli_s *pc = (player_cli_s *) player;
4112 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4113 char *ret_buf = NULL;
4114 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4119 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4120 MUSE_TYPE_INT, "type", type,
4121 MUSE_TYPE_INT, "set", set);
4123 if (ret == PLAYER_ERROR_NONE) {
4124 pc->cb_info->user_cb[type] = callback;
4125 pc->cb_info->user_data[type] = user_data;
4126 LOGI("Event type : %d ", type);
4133 int player_unset_video_stream_changed_cb(player_h player)
4135 PLAYER_INSTANCE_CHECK(player);
4136 int ret = PLAYER_ERROR_NONE;
4137 player_cli_s *pc = (player_cli_s *) player;
4138 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4139 char *ret_buf = NULL;
4140 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4145 set_null_user_cb_lock(pc->cb_info, type);
4147 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4148 MUSE_TYPE_INT, "type", type,
4149 MUSE_TYPE_INT, "set", set);
4155 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)
4157 PLAYER_INSTANCE_CHECK(player);
4158 PLAYER_NULL_ARG_CHECK(callback);
4159 int ret = PLAYER_ERROR_NONE;
4160 player_cli_s *pc = (player_cli_s *) player;
4161 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4162 char *ret_buf = NULL;
4163 muse_player_event_e type;
4168 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4169 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4170 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4171 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4173 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4174 return PLAYER_ERROR_INVALID_PARAMETER;
4177 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4178 MUSE_TYPE_INT, "type", type,
4179 MUSE_TYPE_INT, "set", set);
4181 if (ret == PLAYER_ERROR_NONE) {
4182 pc->cb_info->user_cb[type] = callback;
4183 pc->cb_info->user_data[type] = user_data;
4184 LOGI("Event type : %d ", type);
4191 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
4193 PLAYER_INSTANCE_CHECK(player);
4194 int ret = PLAYER_ERROR_NONE;
4195 player_cli_s *pc = (player_cli_s *) player;
4196 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4197 char *ret_buf = NULL;
4198 muse_player_event_e type;
4203 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4204 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4205 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4206 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4208 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4209 return PLAYER_ERROR_INVALID_PARAMETER;
4212 set_null_user_cb_lock(pc->cb_info, type);
4214 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4215 MUSE_TYPE_INT, "type", type,
4216 MUSE_TYPE_INT, "set", set);
4222 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)
4224 PLAYER_INSTANCE_CHECK(player);
4225 PLAYER_NULL_ARG_CHECK(callback);
4226 int ret = PLAYER_ERROR_NONE;
4227 player_cli_s *pc = (player_cli_s *) player;
4228 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4229 char *ret_buf = NULL;
4230 muse_player_event_e type;
4235 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4236 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4237 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4238 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4240 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4241 return PLAYER_ERROR_INVALID_PARAMETER;
4244 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4245 MUSE_TYPE_INT, "type", type,
4246 MUSE_TYPE_INT, "set", set);
4248 if (ret == PLAYER_ERROR_NONE) {
4249 pc->cb_info->user_cb[type] = callback;
4250 pc->cb_info->user_data[type] = user_data;
4251 LOGI("Event type : %d ", type);
4258 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
4260 PLAYER_INSTANCE_CHECK(player);
4261 int ret = PLAYER_ERROR_NONE;
4262 player_cli_s *pc = (player_cli_s *) player;
4263 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4264 char *ret_buf = NULL;
4265 muse_player_event_e type;
4270 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4271 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4272 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4273 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4275 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4276 return PLAYER_ERROR_INVALID_PARAMETER;
4279 set_null_user_cb_lock(pc->cb_info, type);
4281 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4282 MUSE_TYPE_INT, "type", type,
4283 MUSE_TYPE_INT, "set", set);
4289 /* TODO Implement raw data socket channel */
4290 int player_push_media_stream(player_h player, media_packet_h packet)
4292 PLAYER_INSTANCE_CHECK(player);
4293 PLAYER_NULL_ARG_CHECK(packet);
4294 int ret = PLAYER_ERROR_NONE;
4295 player_cli_s *pc = (player_cli_s *) player;
4296 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
4297 char *ret_buf = NULL;
4298 player_push_media_msg_type push_media;
4299 char *push_media_msg = (char *)&push_media;
4300 int msg_size = sizeof(player_push_media_msg_type);
4304 tbm_bo_handle thandle;
4305 tbm_fd tfd = INVALID_DEFAULT_VALUE;
4308 media_format_h format;
4312 int arr_msg_len = 0;
4316 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
4317 media_packet_get_buffer_size(packet, &push_media.size);
4318 media_packet_get_pts(packet, &push_media.pts);
4319 media_packet_get_format(packet, &format);
4320 media_packet_get_flags(packet, &push_media.flags);
4322 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
4324 media_packet_is_video(packet, &is_video);
4325 media_packet_is_audio(packet, &is_audio);
4326 media_packet_is_end_of_stream(packet, &is_eos);
4328 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
4330 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
4332 media_format_unref(format);
4335 int arr_buf_len = 0;
4337 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
4338 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
4340 LOGE("TBM get error : bo is NULL");
4341 return PLAYER_ERROR_INVALID_OPERATION;
4343 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4344 if (thandle.ptr == NULL) {
4345 LOGE("TBM get error : handle pointer is NULL");
4346 ret = PLAYER_ERROR_INVALID_OPERATION;
4349 memcpy(thandle.ptr, buf, push_media.size);
4352 tfd = tbm_bo_export_fd(bo);
4354 LOGE("tbm_bo_export_fd err 0x%x", tfd);
4355 ret = PLAYER_ERROR_INVALID_OPERATION;
4359 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4360 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret,
4361 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4363 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4364 buf_size = (int)push_media.size;
4366 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4367 arr_buf_len = (buf_size / sizeof(int) + (buf_size % sizeof(int) ? 1 : 0));
4368 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4369 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg,
4370 MUSE_TYPE_ARRAY, "buf", arr_buf_len, (int*)buf);
4374 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4375 buf_size = (int)push_media.size;
4376 if ((muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts) < 0) && (!is_eos)) {
4377 LOGE("failed to send data");
4378 return PLAYER_ERROR_INVALID_OPERATION;
4381 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4382 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4383 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg);
4386 LOGD("ret_buf %s", ret_buf);
4390 if (tfd > INVALID_DEFAULT_VALUE)
4393 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4401 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4403 PLAYER_INSTANCE_CHECK(player);
4404 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4405 int ret = PLAYER_ERROR_NONE;
4406 player_cli_s *pc = (player_cli_s *) player;
4407 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4408 char *ret_buf = NULL;
4409 media_format_mimetype_e mimetype;
4421 media_format_ref(format);
4422 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4423 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4424 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4425 LOGE("failed to get video info from format.");
4426 return PLAYER_ERROR_INVALID_PARAMETER;
4429 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4430 MUSE_TYPE_INT, "type", type,
4431 MUSE_TYPE_INT, "mimetype", mimetype,
4432 MUSE_TYPE_INT, "width", width,
4433 MUSE_TYPE_INT, "height", height,
4434 MUSE_TYPE_INT, "avg_bps", avg_bps,
4435 MUSE_TYPE_INT, "max_bps", max_bps,
4436 MUSE_TYPE_INT, "frame_rate", frame_rate);
4438 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4439 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4440 LOGE("failed to get audio info from format.");
4441 return PLAYER_ERROR_INVALID_PARAMETER;
4444 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4445 MUSE_TYPE_INT, "type", type,
4446 MUSE_TYPE_INT, "mimetype", mimetype,
4447 MUSE_TYPE_INT, "channel", channel,
4448 MUSE_TYPE_INT, "samplerate", samplerate,
4449 MUSE_TYPE_INT, "avg_bps", avg_bps,
4450 MUSE_TYPE_INT, "bit", bit);
4453 media_format_unref(format);
4454 pc->push_media_stream = TRUE;
4460 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4462 int ret = PLAYER_ERROR_NONE;
4463 PLAYER_INSTANCE_CHECK(player);
4464 player_cli_s *pc = (player_cli_s *) player;
4465 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4466 char *ret_buf = NULL;
4470 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4471 MUSE_TYPE_INT, "type", type,
4472 MUSE_TYPE_INT64, "max_size", (INT64)max_size);
4478 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4480 int ret = PLAYER_ERROR_NONE;
4481 PLAYER_INSTANCE_CHECK(player);
4482 PLAYER_NULL_ARG_CHECK(pmax_size);
4483 player_cli_s *pc = (player_cli_s *) player;
4484 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4485 char *ret_buf = NULL;
4486 unsigned long long max_size;
4490 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4491 if (ret == PLAYER_ERROR_NONE) {
4492 player_msg_get_type(max_size, ret_buf, INT64);
4493 *pmax_size = max_size;
4499 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4501 int ret = PLAYER_ERROR_NONE;
4502 PLAYER_INSTANCE_CHECK(player);
4503 player_cli_s *pc = (player_cli_s *) player;
4504 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4505 char *ret_buf = NULL;
4509 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4510 MUSE_TYPE_INT, "type", type,
4511 MUSE_TYPE_INT, "percent", (int)percent);
4517 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4519 int ret = PLAYER_ERROR_NONE;
4520 PLAYER_INSTANCE_CHECK(player);
4521 PLAYER_NULL_ARG_CHECK(ppercent);
4522 player_cli_s *pc = (player_cli_s *) player;
4523 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4524 char *ret_buf = NULL;
4529 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4530 if (ret == PLAYER_ERROR_NONE) {
4531 player_msg_get(percent, ret_buf);
4532 *ppercent = percent;
4539 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4541 PLAYER_INSTANCE_CHECK(player);
4542 PLAYER_NULL_ARG_CHECK(pcount);
4543 int ret = PLAYER_ERROR_NONE;
4544 player_cli_s *pc = (player_cli_s *) player;
4545 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4546 char *ret_buf = NULL;
4551 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4552 if (ret == PLAYER_ERROR_NONE) {
4553 player_msg_get(count, ret_buf);
4561 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4563 PLAYER_INSTANCE_CHECK(player);
4564 PLAYER_NULL_ARG_CHECK(pindex);
4565 int ret = PLAYER_ERROR_NONE;
4566 player_cli_s *pc = (player_cli_s *) player;
4567 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4568 char *ret_buf = NULL;
4573 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4574 if (ret == PLAYER_ERROR_NONE) {
4575 player_msg_get(index, ret_buf);
4583 int player_select_track(player_h player, player_stream_type_e type, int index)
4585 PLAYER_INSTANCE_CHECK(player);
4586 int ret = PLAYER_ERROR_NONE;
4587 player_cli_s *pc = (player_cli_s *) player;
4588 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4589 char *ret_buf = NULL;
4593 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4599 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4601 PLAYER_INSTANCE_CHECK(player);
4602 PLAYER_NULL_ARG_CHECK(pcode);
4603 int ret = PLAYER_ERROR_NONE;
4604 player_cli_s *pc = (player_cli_s *) player;
4605 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4606 char *ret_buf = NULL;
4607 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4612 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4613 if (ret == PLAYER_ERROR_NONE) {
4614 bool recv_ret = true;
4615 recv_ret = _player_get_param_value(ret_buf,
4616 MUSE_TYPE_INT, "code_len", (void *)&code_len,
4617 MUSE_TYPE_STRING, "code", (void *)code,
4618 INVALID_MUSE_TYPE_VALUE);
4620 *pcode = strndup(code, code_len);
4622 ret = PLAYER_ERROR_INVALID_OPERATION;
4628 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4630 PLAYER_INSTANCE_CHECK(player);
4631 PLAYER_NULL_ARG_CHECK(callback);
4632 int ret = PLAYER_ERROR_NONE;
4633 player_cli_s *pc = (player_cli_s *) player;
4634 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4635 char *ret_buf = NULL;
4636 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4637 int idx = 0, num = 0;
4638 int bandwidth = 0, width = 0, height = 0;
4644 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4645 if (ret == PLAYER_ERROR_NONE) {
4646 player_msg_get_type(num, ret_buf, INT);
4648 player_msg_get_string(var_info, ret_buf);
4650 LOGW("There is no stream variant info.");
4653 for (idx = 0 ; idx < num ; idx++) {
4654 bandwidth = width = height = 0;
4656 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4658 bandwidth = atoi(token);
4660 token = strtok_r(NULL, ",", &ptr);
4662 width = atoi(token);
4664 token = strtok_r(NULL, ",", &ptr);
4666 height = atoi(token);
4668 callback(bandwidth, width, height, user_data);
4671 LOGD("LEAVE 0x%X", ret);
4676 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4678 int ret = PLAYER_ERROR_NONE;
4679 PLAYER_INSTANCE_CHECK(player);
4680 PLAYER_CHECK_CONDITION(bandwidth >= -1 && width >= -1 && height >= -1,
4681 PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4682 player_cli_s *pc = (player_cli_s *) player;
4683 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4684 char *ret_buf = NULL;
4688 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4689 MUSE_TYPE_INT, "bandwidth", bandwidth,
4690 MUSE_TYPE_INT, "width", width,
4691 MUSE_TYPE_INT, "height", height);
4694 LOGD("LEAVE 0x%X", ret);
4699 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4701 int ret = PLAYER_ERROR_NONE;
4702 PLAYER_INSTANCE_CHECK(player);
4703 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4705 player_cli_s *pc = (player_cli_s *) player;
4706 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4707 char *ret_buf = NULL;
4708 int bandwidth = -1, width = -1, height = -1;
4712 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4713 if (ret == PLAYER_ERROR_NONE) {
4714 bool ret_val = true;
4715 ret_val = _player_get_param_value(ret_buf,
4716 MUSE_TYPE_INT, "bandwidth", (void *)&bandwidth,
4717 MUSE_TYPE_INT, "width", (void *)&width,
4718 MUSE_TYPE_INT, "height", (void *)&height,
4719 INVALID_MUSE_TYPE_VALUE);
4721 if (pbandwidth) *pbandwidth = bandwidth;
4722 if (pwidth) *pwidth = width;
4723 if (pheight) *pheight = height;
4725 ret = PLAYER_ERROR_INVALID_OPERATION;
4730 LOGD("LEAVE 0x%X", ret);
4734 int player_set_audio_only(player_h player, bool audio_only)
4736 int ret = PLAYER_ERROR_NONE;
4737 PLAYER_INSTANCE_CHECK(player);
4738 player_cli_s *pc = (player_cli_s *) player;
4739 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4740 char *ret_buf = NULL;
4741 player_state_e state = PLAYER_STATE_NONE;
4743 LOGD("ENTER audio_only: %d", audio_only);
4745 /* check player state */
4746 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
4747 LOGE("Failed to get state");
4748 return PLAYER_ERROR_INVALID_OPERATION;
4751 if (state < PLAYER_STATE_READY) {
4752 LOGE("Invalid state %d", state);
4753 return PLAYER_ERROR_INVALID_STATE;
4756 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4757 if (EVAS_HANDLE(pc)) {
4758 pc->is_audio_only = (gboolean)audio_only;
4759 return PLAYER_ERROR_NONE;
4762 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "audio_only", (int)audio_only);
4765 LOGD("LEAVE 0x%X", ret);
4770 int player_is_audio_only(player_h player, bool *paudio_only)
4772 PLAYER_INSTANCE_CHECK(player);
4773 PLAYER_NULL_ARG_CHECK(paudio_only);
4774 int ret = PLAYER_ERROR_NONE;
4775 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4776 player_cli_s *pc = (player_cli_s *) player;
4777 char *ret_buf = NULL;
4781 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4782 if (EVAS_HANDLE(pc)) {
4783 *paudio_only = (bool)pc->is_audio_only;
4784 return PLAYER_ERROR_NONE;
4788 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4789 if (ret == PLAYER_ERROR_NONE) {
4790 player_msg_get(audio_only, ret_buf);
4791 *paudio_only = (bool)audio_only;
4795 LOGD("LEAVE 0x%X", ret);
4799 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4801 int ret = PLAYER_ERROR_NONE;
4802 PLAYER_INSTANCE_CHECK(player);
4803 PLAYER_CHECK_CONDITION(buffer_ms >= 0 && rebuffer_ms >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4805 player_cli_s *pc = (player_cli_s *) player;
4806 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4807 char *ret_buf = NULL;
4811 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4812 MUSE_TYPE_INT, "buffer_ms", buffer_ms,
4813 MUSE_TYPE_INT, "rebuffer_ms", rebuffer_ms);
4816 LOGD("LEAVE 0x%X", ret);
4820 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4822 PLAYER_INSTANCE_CHECK(player);
4823 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4825 int ret = PLAYER_ERROR_NONE;
4826 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4827 player_cli_s *pc = (player_cli_s *) player;
4828 int buffering_time = 0, rebuffering_time = 0;
4829 char *ret_buf = NULL;
4833 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4835 if (ret == PLAYER_ERROR_NONE) {
4836 bool ret_val = true;
4837 ret_val = _player_get_param_value(ret_buf,
4838 MUSE_TYPE_INT, "buffering_time", (void *)&buffering_time,
4839 MUSE_TYPE_INT, "rebuffering_time", (void *)&rebuffering_time,
4840 INVALID_MUSE_TYPE_VALUE);
4842 if (buffer_ms) *buffer_ms = buffering_time;
4843 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4845 ret = PLAYER_ERROR_INVALID_OPERATION;
4851 LOGD("LEAVE 0x%X", ret);
4855 int player_360_is_content_spherical(player_h player, bool *is_spherical)
4857 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4858 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4860 PLAYER_INSTANCE_CHECK(player);
4861 PLAYER_NULL_ARG_CHECK(is_spherical);
4863 int ret = PLAYER_ERROR_NONE;
4864 muse_player_api_e api = MUSE_PLAYER_API_360_IS_CONTENT_SPHERICAL;
4865 player_cli_s *pc = (player_cli_s *) player;
4866 char *ret_buf = NULL;
4871 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4872 if (ret == PLAYER_ERROR_NONE) {
4873 player_msg_get(val, ret_buf);
4874 *is_spherical = val;
4878 LOGD("LEAVE 0x%X", ret);
4882 int player_360_set_enabled(player_h player, bool enabled)
4884 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4885 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4887 PLAYER_INSTANCE_CHECK(player);
4888 int ret = PLAYER_ERROR_NONE;
4889 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLED;
4890 player_cli_s *pc = (player_cli_s *) player;
4891 char *ret_buf = NULL;
4892 int val = (int)enabled;
4894 LOGD("ENTER %d", enabled);
4896 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
4899 LOGD("LEAVE 0x%X", ret);
4903 int player_360_is_enabled(player_h player, bool *enabled)
4905 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4906 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4908 PLAYER_INSTANCE_CHECK(player);
4909 PLAYER_NULL_ARG_CHECK(enabled);
4910 int ret = PLAYER_ERROR_NONE;
4911 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4912 player_cli_s *pc = (player_cli_s *) player;
4913 char *ret_buf = NULL;
4918 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4919 if (ret == PLAYER_ERROR_NONE) {
4920 player_msg_get(val, ret_buf);
4925 LOGD("LEAVE 0x%X", ret);
4929 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4931 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4932 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4934 PLAYER_INSTANCE_CHECK(player);
4935 int ret = PLAYER_ERROR_NONE;
4936 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4937 player_cli_s *pc = (player_cli_s *) player;
4938 char *ret_buf = NULL;
4940 LOGD("ENTER %f %f", yaw, pitch);
4942 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4943 MUSE_TYPE_DOUBLE, "yaw", (double)yaw,
4944 MUSE_TYPE_DOUBLE, "pitch", (double)pitch);
4948 LOGD("LEAVE 0x%X", ret);
4952 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4954 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4955 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4957 PLAYER_INSTANCE_CHECK(player);
4958 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4959 int ret = PLAYER_ERROR_NONE;
4960 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4961 player_cli_s *pc = (player_cli_s *) player;
4962 double yaw_val = -1;
4963 double pitch_val = -1;
4964 char *ret_buf = NULL;
4968 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4970 if (ret == PLAYER_ERROR_NONE) {
4971 bool ret_val = true;
4972 ret_val = _player_get_param_value(ret_buf,
4973 MUSE_TYPE_DOUBLE, "yaw_val", (void *)&yaw_val,
4974 MUSE_TYPE_DOUBLE, "pitch_val", (void *)&pitch_val,
4975 INVALID_MUSE_TYPE_VALUE);
4977 *yaw = (float)yaw_val;
4978 *pitch = (float)pitch_val;
4980 LOGE("failed to get value from msg");
4981 ret = PLAYER_ERROR_INVALID_OPERATION;
4987 LOGD("LEAVE 0x%X", ret);
4991 int player_360_set_zoom(player_h player, float level)
4993 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4994 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4996 PLAYER_INSTANCE_CHECK(player);
4997 int ret = PLAYER_ERROR_NONE;
4998 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4999 player_cli_s *pc = (player_cli_s *) player;
5000 char *ret_buf = NULL;
5002 LOGD("ENTER %f", level);
5004 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "level", (double)level);
5007 LOGD("LEAVE 0x%X", ret);
5011 int player_360_get_zoom(player_h player, float *level)
5013 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5014 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5016 PLAYER_INSTANCE_CHECK(player);
5017 PLAYER_NULL_ARG_CHECK(level);
5018 int ret = PLAYER_ERROR_NONE;
5019 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
5020 player_cli_s *pc = (player_cli_s *) player;
5022 char *ret_buf = NULL;
5026 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5028 if (ret == PLAYER_ERROR_NONE) {
5029 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
5030 *level = (float)zoom;
5032 LOGE("failed to get value from msg");
5033 ret = PLAYER_ERROR_INVALID_OPERATION;
5039 LOGD("LEAVE 0x%X", ret);
5044 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
5046 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5047 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5049 PLAYER_INSTANCE_CHECK(player);
5050 int ret = PLAYER_ERROR_NONE;
5051 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
5052 player_cli_s *pc = (player_cli_s *) player;
5053 char *ret_buf = NULL;
5055 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
5057 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5058 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5059 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5062 LOGD("LEAVE 0x%X", ret);
5066 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
5068 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5069 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5071 PLAYER_INSTANCE_CHECK(player);
5072 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
5073 int ret = PLAYER_ERROR_NONE;
5074 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
5075 player_cli_s *pc = (player_cli_s *) player;
5078 char *ret_buf = NULL;
5082 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5084 if (ret == PLAYER_ERROR_NONE) {
5085 bool ret_val = true;
5086 ret_val = _player_get_param_value(ret_buf,
5087 MUSE_TYPE_INT, "h_val", (void *)&h_val,
5088 MUSE_TYPE_INT, "v_val", (void *)&v_val,
5089 INVALID_MUSE_TYPE_VALUE);
5091 *horizontal_degrees = h_val;
5092 *vertical_degrees = v_val;
5094 LOGE("failed to get value from msg");
5095 ret = PLAYER_ERROR_INVALID_OPERATION;
5101 LOGD("LEAVE 0x%X", ret);
5105 int player_360_set_zoom_with_field_of_view(player_h player, float level, int horizontal_degrees, int vertical_degrees)
5107 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5108 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5110 PLAYER_INSTANCE_CHECK(player);
5111 int ret = PLAYER_ERROR_NONE;
5112 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM_WITH_FIELD_OF_VIEW;
5113 player_cli_s *pc = (player_cli_s *) player;
5114 char *ret_buf = NULL;
5116 LOGD("ENTER %f %d %d", level, horizontal_degrees, vertical_degrees);
5118 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5119 MUSE_TYPE_DOUBLE, "level", (double)level,
5120 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5121 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5124 LOGD("LEAVE 0x%X", ret);
5128 int player_set_replaygain_enabled(player_h player, bool enabled)
5130 PLAYER_INSTANCE_CHECK(player);
5131 int ret = PLAYER_ERROR_NONE;
5132 muse_player_api_e api = MUSE_PLAYER_API_SET_REPLAYGAIN_ENABLED;
5133 player_cli_s *pc = (player_cli_s *) player;
5134 char *ret_buf = NULL;
5135 int val = (int)enabled;
5139 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5144 int player_is_replaygain_enabled(player_h player, bool *enabled)
5146 PLAYER_INSTANCE_CHECK(player);
5147 PLAYER_NULL_ARG_CHECK(enabled);
5148 int ret = PLAYER_ERROR_NONE;
5149 muse_player_api_e api = MUSE_PLAYER_API_IS_REPLAYGAIN_ENABLED;
5150 player_cli_s *pc = (player_cli_s *) player;
5151 char *ret_buf = NULL;
5156 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5157 if (ret == PLAYER_ERROR_NONE) {
5158 player_msg_get(val, ret_buf);
5159 *enabled = (bool) val;