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;
2104 if (!CALLBACK_INFO(pc))
2105 return PLAYER_ERROR_INVALID_STATE;
2107 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2109 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2110 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2111 _player_release_internal_memory(pc, false);
2113 pc->cb_info->video_frame_pool_size = 0;
2114 __player_remove_tsurf_list(pc);
2115 pc->is_audio_only = FALSE;
2119 LOGD("LEAVE 0x%X", ret);
2123 /* 1. correct the protocol prefix to lower case
2124 * 2. remove 'file://' prefix
2125 * 3. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' */
2126 int _player_get_valid_path(const char* uri, char* valid_path)
2128 gchar *file_path = NULL;
2130 gchar *colon = NULL;
2132 if (!uri || !valid_path) {
2133 LOGD("invalid parameter");
2134 return PLAYER_ERROR_INVALID_PARAMETER;
2137 if ((colon = strstr(uri, "://")) != NULL) {
2138 gchar *protocol = g_ascii_strdown(uri, colon - uri);
2142 file_path = g_strconcat(protocol, uri+strlen(protocol), NULL);
2143 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2149 if (strstr(valid_path, "file://")) { /* handle the 'file://' prefix */
2151 file_path = g_filename_from_uri(valid_path, NULL, &err);
2152 if (!file_path || (err != NULL)) {
2153 SECURE_LOGE("Invalid URI '%s', err: %s", uri,
2154 (err != NULL) ? err->message : "unknown error");
2156 if (err) g_error_free(err);
2157 if (file_path) g_free(file_path);
2159 return PLAYER_ERROR_INVALID_PARAMETER;
2161 LOGD("get file path from uri");
2163 LOGD("use the original path.");
2164 return PLAYER_ERROR_NONE;
2169 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, valid_path) < 0) {
2170 /* cannot convert path. use the original one. */
2171 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2173 /* need to use converted path. */
2174 SECURE_LOGD("Converted path : %s -> %s", uri, valid_path);
2179 return PLAYER_ERROR_NONE;
2182 int player_set_uri(player_h player, const char *uri)
2184 PLAYER_INSTANCE_CHECK(player);
2185 PLAYER_NULL_ARG_CHECK(uri);
2186 int ret = PLAYER_ERROR_NONE;
2187 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2188 player_cli_s *pc = (player_cli_s *) player;
2189 char *ret_buf = NULL;
2190 char path[MAX_URL_LEN] = {0, };
2194 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
2195 return PLAYER_ERROR_INVALID_PARAMETER;
2197 SECURE_LOGD("new path : %s", path);
2199 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", (const char*)path);
2200 pc->push_media_stream = FALSE;
2206 int player_set_memory_buffer(player_h player, const void *data, int size)
2208 PLAYER_INSTANCE_CHECK(player);
2209 PLAYER_NULL_ARG_CHECK(data);
2210 int ret = PLAYER_ERROR_NONE;
2211 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2212 player_cli_s *pc = (player_cli_s *) player;
2213 char *ret_buf = NULL;
2215 tbm_bo_handle thandle;
2216 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2218 /* before setting mem buffer, player state have to be checked. */
2219 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2221 if (SERVER_TBM_BO(pc)) {
2222 LOGW("The previous memory buffer will be cleared.");
2223 _player_deinit_memory_buffer(pc);
2226 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2228 LOGE("TBM get error : bo is NULL");
2229 return PLAYER_ERROR_INVALID_OPERATION;
2231 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2232 if (thandle.ptr == NULL) {
2233 LOGE("TBM get error : handle pointer is NULL");
2234 ret = PLAYER_ERROR_INVALID_OPERATION;
2237 memcpy(thandle.ptr, data, size);
2240 tfd = tbm_bo_export_fd(bo);
2242 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2243 ret = PLAYER_ERROR_INVALID_OPERATION;
2247 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret, MUSE_TYPE_INT, "size", size);
2248 pc->push_media_stream = FALSE;
2251 if (tfd > INVALID_DEFAULT_VALUE)
2256 if (ret == PLAYER_ERROR_NONE) {
2257 intptr_t bo_addr = 0;
2258 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2259 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2266 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem)
2273 if (deinit_server_mem)
2274 _player_deinit_memory_buffer(pc);
2277 static int _player_deinit_memory_buffer(player_cli_s * pc)
2279 PLAYER_INSTANCE_CHECK(pc);
2280 int ret = PLAYER_ERROR_NONE;
2281 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2282 intptr_t bo_addr = SERVER_TBM_BO(pc);
2284 if (!bo_addr || !CALLBACK_INFO(pc))
2287 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_POINTER, "bo_addr", bo_addr);
2288 SERVER_TBM_BO(pc) = 0;
2293 int player_get_state(player_h player, player_state_e *pstate)
2295 PLAYER_INSTANCE_CHECK(player);
2296 PLAYER_NULL_ARG_CHECK(pstate);
2297 int ret = PLAYER_ERROR_NONE;
2298 player_cli_s *pc = (player_cli_s *) player;
2302 ret = _get_current_state(pc, pstate);
2306 int player_set_volume(player_h player, float left, float right)
2308 PLAYER_INSTANCE_CHECK(player);
2309 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2310 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2311 int ret = PLAYER_ERROR_NONE;
2312 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2313 player_cli_s *pc = (player_cli_s *) player;
2314 char *ret_buf = NULL;
2318 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2319 MUSE_TYPE_DOUBLE, "right", (double)right,
2320 MUSE_TYPE_DOUBLE, "left", (double)left);
2326 int player_get_volume(player_h player, float *pleft, float *pright)
2328 PLAYER_INSTANCE_CHECK(player);
2329 PLAYER_NULL_ARG_CHECK(pleft && pright);
2330 int ret = PLAYER_ERROR_NONE;
2331 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2332 player_cli_s *pc = (player_cli_s *) player;
2335 char *ret_buf = NULL;
2339 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2341 if (ret == PLAYER_ERROR_NONE) {
2342 bool ret_val = true;
2343 ret_val = _player_get_param_value(ret_buf,
2344 MUSE_TYPE_DOUBLE, "left", (void *)&left,
2345 MUSE_TYPE_DOUBLE, "right", (void *)&right,
2346 INVALID_MUSE_TYPE_VALUE);
2348 *pleft = (float)left;
2349 *pright = (float)right;
2351 LOGE("failed to get value from msg");
2352 ret = PLAYER_ERROR_INVALID_OPERATION;
2360 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2362 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SOUND_STREAM);
2363 PLAYER_INSTANCE_CHECK(player);
2365 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2366 player_cli_s *pc = (player_cli_s *) player;
2367 bool is_available = false;
2368 char *ret_buf = NULL;
2372 /* check if stream_info is valid */
2373 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2374 if (ret != SOUND_MANAGER_ERROR_NONE) {
2375 LOGE("failed to checking available stream info");
2376 return PLAYER_ERROR_INVALID_OPERATION;
2379 if (is_available == false) {
2380 ret = PLAYER_ERROR_INVALID_PARAMETER;
2382 char *stream_type = NULL;
2383 int stream_index = 0;
2384 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2385 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2386 if (ret == SOUND_MANAGER_ERROR_NONE)
2387 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2388 MUSE_TYPE_STRING, "stream_type", (const char*)stream_type,
2389 MUSE_TYPE_INT, "stream_index", stream_index);
2391 ret = PLAYER_ERROR_INVALID_OPERATION;
2394 LOGD("LEAVE ret: 0x%X", ret);
2401 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2403 PLAYER_INSTANCE_CHECK(player);
2404 int ret = PLAYER_ERROR_NONE;
2405 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2406 player_cli_s *pc = (player_cli_s *) player;
2407 char *ret_buf = NULL;
2411 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "latency_mode", (int)latency_mode);
2416 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2418 PLAYER_INSTANCE_CHECK(player);
2419 PLAYER_NULL_ARG_CHECK(platency_mode);
2420 int ret = PLAYER_ERROR_NONE;
2421 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2422 player_cli_s *pc = (player_cli_s *) player;
2423 char *ret_buf = NULL;
2424 int latency_mode = -1;
2428 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2430 if (ret == PLAYER_ERROR_NONE) {
2431 player_msg_get(latency_mode, ret_buf);
2432 *platency_mode = latency_mode;
2440 int player_start(player_h player)
2442 PLAYER_INSTANCE_CHECK(player);
2443 int ret = PLAYER_ERROR_NONE;
2444 muse_player_api_e api = MUSE_PLAYER_API_START;
2445 player_cli_s *pc = (player_cli_s *) player;
2446 char *ret_buf = NULL;
2449 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2450 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2452 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2453 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2454 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2455 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2456 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), true);
2457 if (ret != MM_ERROR_NONE) {
2458 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2459 return PLAYER_ERROR_INVALID_OPERATION;
2461 /* avoid setting true at all times, when player is resumed */
2462 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2467 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2471 LOGD("LEAVE 0x%X", ret);
2475 int player_stop(player_h player)
2477 PLAYER_INSTANCE_CHECK(player);
2478 int ret = PLAYER_ERROR_NONE;
2479 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2480 player_cli_s *pc = (player_cli_s *) player;
2481 char *ret_buf = NULL;
2482 player_state_e state = PLAYER_STATE_NONE;
2483 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2484 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2488 /* check player state */
2489 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2490 LOGE("Failed to get state");
2491 return PLAYER_ERROR_INVALID_OPERATION;
2494 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2495 LOGE("Invalid state %d", state);
2496 return PLAYER_ERROR_INVALID_STATE;
2499 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2500 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2501 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2502 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2503 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2504 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), false);
2505 if (ret != MM_ERROR_NONE) {
2506 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2507 return PLAYER_ERROR_INVALID_OPERATION;
2509 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2513 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2514 if (ret == PLAYER_ERROR_NONE)
2515 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2519 LOGD("LEAVE 0x%X", ret);
2523 int player_pause(player_h player)
2525 PLAYER_INSTANCE_CHECK(player);
2526 int ret = PLAYER_ERROR_NONE;
2527 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2528 player_cli_s *pc = (player_cli_s *) player;
2529 char *ret_buf = NULL;
2533 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2536 LOGD("LEAVE 0x%X", ret);
2540 static int _set_play_position(player_h player, int64_t pos, bool accurate, player_seek_completed_cb callback, void *user_data)
2542 PLAYER_INSTANCE_CHECK(player);
2543 PLAYER_CHECK_CONDITION(pos >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2545 int ret = PLAYER_ERROR_NONE;
2546 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2547 player_cli_s *pc = (player_cli_s *) player;
2548 char *ret_buf = NULL;
2553 LOGE("cb_info is null");
2554 return PLAYER_ERROR_INVALID_OPERATION;
2557 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2558 if ((pc->push_media_stream == FALSE) &&
2559 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2560 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2561 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2562 return PLAYER_ERROR_SEEK_FAILED;
2564 if (pc->push_media_stream == TRUE)
2565 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2567 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2568 LOGI("Event type : %d, pos : %"PRId64", accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, pos, accurate);
2569 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2570 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2572 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2574 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2575 MUSE_TYPE_INT64, "pos", pos,
2576 MUSE_TYPE_INT, "accurate", (int)accurate);
2578 if (ret != PLAYER_ERROR_NONE) {
2579 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2580 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2581 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2584 if (pc->push_media_stream == TRUE)
2585 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2589 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2590 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2591 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2593 LOGD("LEAVE 0x%X", ret);
2598 int player_set_play_position(player_h player, int milliseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2600 PLAYER_INSTANCE_CHECK(player);
2601 PLAYER_CHECK_CONDITION(milliseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2603 int ret = PLAYER_ERROR_NONE;
2604 int64_t pos = (int64_t)(milliseconds * G_GINT64_CONSTANT(1000000));
2608 ret = _set_play_position(player, pos, accurate, callback, user_data);
2610 LOGD("LEAVE 0x%X", ret);
2614 int player_set_play_position_nsec(player_h player, int64_t nanoseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2616 PLAYER_INSTANCE_CHECK(player);
2617 PLAYER_CHECK_CONDITION(nanoseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2619 int ret = PLAYER_ERROR_NONE;
2620 int64_t pos = nanoseconds;
2624 ret = _set_play_position(player, pos, accurate, callback, user_data);
2626 LOGD("LEAVE 0x%X", ret);
2630 static int _get_play_position(player_h player, int64_t *pos)
2632 PLAYER_INSTANCE_CHECK(player);
2633 PLAYER_NULL_ARG_CHECK(pos);
2635 int ret = PLAYER_ERROR_NONE;
2636 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2637 player_cli_s *pc = (player_cli_s *) player;
2638 char *ret_buf = NULL;
2640 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2642 if (ret == PLAYER_ERROR_NONE) {
2643 bool ret_val = true;
2644 ret_val = _player_get_param_value(ret_buf,
2645 MUSE_TYPE_INT64, "pos", (void *)pos,
2646 INVALID_MUSE_TYPE_VALUE);
2648 ret = PLAYER_ERROR_INVALID_OPERATION;
2657 int player_get_play_position(player_h player, int *milliseconds)
2659 PLAYER_INSTANCE_CHECK(player);
2660 PLAYER_NULL_ARG_CHECK(milliseconds);
2662 int ret = PLAYER_ERROR_NONE;
2665 /* LOGD("ENTER"); */
2667 ret = _get_play_position(player, &pos);
2668 if (ret == PLAYER_ERROR_NONE) {
2669 *milliseconds = (int)(pos / G_GINT64_CONSTANT(1000000));
2675 int player_get_play_position_nsec(player_h player, int64_t *nanoseconds)
2677 PLAYER_INSTANCE_CHECK(player);
2678 PLAYER_NULL_ARG_CHECK(nanoseconds);
2680 int ret = PLAYER_ERROR_NONE;
2683 /* LOGD("ENTER"); */
2685 ret = _get_play_position(player, &pos);
2686 if (ret == PLAYER_ERROR_NONE) {
2693 int player_set_mute(player_h player, bool muted)
2695 PLAYER_INSTANCE_CHECK(player);
2696 int ret = PLAYER_ERROR_NONE;
2697 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2698 player_cli_s *pc = (player_cli_s *) player;
2699 char *ret_buf = NULL;
2700 int mute = (int)muted;
2704 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mute", mute);
2709 int player_is_muted(player_h player, bool * muted)
2711 PLAYER_INSTANCE_CHECK(player);
2712 PLAYER_NULL_ARG_CHECK(muted);
2713 int ret = PLAYER_ERROR_NONE;
2714 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2715 player_cli_s *pc = (player_cli_s *) player;
2716 char *ret_buf = NULL;
2721 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2722 if (ret == PLAYER_ERROR_NONE) {
2723 player_msg_get(mute, ret_buf);
2724 *muted = (bool) mute;
2731 int player_set_looping(player_h player, bool looping)
2733 PLAYER_INSTANCE_CHECK(player);
2734 int ret = PLAYER_ERROR_NONE;
2735 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2736 player_cli_s *pc = (player_cli_s *) player;
2737 char *ret_buf = NULL;
2741 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "looping", (int)looping);
2746 int player_is_looping(player_h player, bool * plooping)
2748 PLAYER_INSTANCE_CHECK(player);
2749 PLAYER_NULL_ARG_CHECK(plooping);
2750 int ret = PLAYER_ERROR_NONE;
2751 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2752 player_cli_s *pc = (player_cli_s *) player;
2753 char *ret_buf = NULL;
2758 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2759 if (ret == PLAYER_ERROR_NONE) {
2760 player_msg_get(looping, ret_buf);
2761 *plooping = looping;
2767 static int _get_duration(player_h player, int64_t *duration)
2769 PLAYER_INSTANCE_CHECK(player);
2770 PLAYER_NULL_ARG_CHECK(duration);
2772 int ret = PLAYER_ERROR_NONE;
2773 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2774 player_cli_s *pc = (player_cli_s *) player;
2775 char *ret_buf = NULL;
2779 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2780 if (ret == PLAYER_ERROR_NONE) {
2781 bool ret_val = true;
2782 ret_val = _player_get_param_value(ret_buf,
2783 MUSE_TYPE_INT64, "duration", (void *)duration,
2784 INVALID_MUSE_TYPE_VALUE);
2786 ret = PLAYER_ERROR_INVALID_OPERATION;
2795 int player_get_duration(player_h player, int *milliseconds)
2797 PLAYER_INSTANCE_CHECK(player);
2798 PLAYER_NULL_ARG_CHECK(milliseconds);
2800 int ret = PLAYER_ERROR_NONE;
2801 int64_t duration = 0; /* nsec */
2805 ret = _get_duration(player, &duration);
2806 if (ret == PLAYER_ERROR_NONE) {
2807 /* convert time from ns to ms */
2808 *milliseconds = (int)(duration / G_GINT64_CONSTANT(1000000));
2811 LOGD("LEAVE 0x%X", ret);
2815 int player_get_duration_nsec(player_h player, int64_t *nanoseconds)
2817 PLAYER_INSTANCE_CHECK(player);
2818 PLAYER_NULL_ARG_CHECK(nanoseconds);
2820 int ret = PLAYER_ERROR_NONE;
2821 int64_t duration = 0; /* nsec */
2825 ret = _get_duration(player, &duration);
2826 if (ret == PLAYER_ERROR_NONE) {
2827 *nanoseconds = duration;
2830 LOGD("LEAVE 0x%X", ret);
2834 /* The player_display_type_e is different at wearable profile */
2835 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2837 int ret = PLAYER_ERROR_NONE;
2838 PLAYER_NULL_ARG_CHECK(out_type);
2841 case PLAYER_DISPLAY_TYPE_OVERLAY:
2842 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2844 case PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE:
2845 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2846 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2848 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2850 case PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS:
2851 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2852 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2854 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2856 case PLAYER_DISPLAY_TYPE_EVAS:
2857 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2859 case PLAYER_DISPLAY_TYPE_NONE:
2860 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2863 ret = PLAYER_ERROR_INVALID_PARAMETER;
2867 LOGD("display type(%d) -> (%d)", type, *out_type);
2871 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2873 PLAYER_INSTANCE_CHECK(player);
2874 int ret = PLAYER_ERROR_NONE;
2875 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2876 player_cli_s *pc = (player_cli_s *) player;
2877 char *ret_buf = NULL;
2878 wl_win_msg_type wl_win;
2879 char *wl_win_msg = (char *)&wl_win;
2880 unsigned int wl_surface_id;
2881 player_private_display_type_e conv_type;
2882 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
2883 int arr_msg_len = 0;
2884 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2885 int (*p_disp_destroy_evas_display)(void **) = NULL;
2886 int (*p_disp_create_evas_display)(void *, void **) = NULL;
2887 int (*p_disp_set_evas_display_old_info)(void *, void *, int, int, int) = NULL;
2888 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2889 void (*p_disp_get_evas_display_geometry_info)(void *, int *, int *, int *, int *) = NULL;
2890 void (*p_disp_media_packet_video_decode_cb)(media_packet_h, void *) = NULL;
2892 pid_t pid = getpid();
2893 pid_t tid = syscall(SYS_gettid);
2897 LOGD("Check if API is called in main thread. pid [%d], tid [%d]", pid, tid);
2899 LOGE("API isn't called in main thread");
2900 return PLAYER_ERROR_INVALID_OPERATION;
2903 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2906 wl_win.wl_window_x = 0;
2907 wl_win.wl_window_y = 0;
2908 wl_win.wl_window_width = 0;
2909 wl_win.wl_window_height = 0;
2911 LOGD("ENTER type: %d", type);
2912 if (type == PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE ||
2913 type == PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS) {
2914 LOGW("DEPRECATION WARNING: display type(%d) is deprecated and will be removed from next release. Use newly defined type value instead.", type);
2917 /* before setting display, player state have to be checked. */
2918 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2920 ret = _player_convert_display_type(type, &conv_type);
2921 if (ret != PLAYER_ERROR_NONE)
2924 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2926 return PLAYER_ERROR_INVALID_PARAMETER;
2928 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2930 * To support repeating play and stop, Evas_handle should not be destroyed in player_unprepare.
2931 * When the display type changes, Player need to destroy Evas_handle to set values of video output,
2932 * Otherwise, the values is not set because of checking Evas_handle.
2934 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
2935 LOGW("evas client already exists");
2936 player_unset_media_packet_video_frame_decoded_cb(player);
2937 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2938 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2939 LOGW("fail to unset evas client");
2940 __player_unset_retrieve_buffer_cb(player);
2941 /* need to set display information again to new handle */
2942 EVAS_INFO(pc)->update_needed = TRUE;
2945 /* set evas_render or wayland */
2946 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
2947 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
2948 wl_surface_id = p_disp_set_wl_display(ELM_WAYLAND_WIN, display);
2949 if (wl_surface_id > 0) {
2950 wl_win.wl_surface_id = wl_surface_id;
2951 wl_win.type = conv_type;
2952 } else return PLAYER_ERROR_INVALID_OPERATION;
2954 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2955 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS) {
2956 if (!CALLBACK_INFO(pc)) {
2957 LOGE("there is no cb info in player handle");
2958 return PLAYER_ERROR_INVALID_OPERATION;
2961 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_create_evas_display, "disp_create_evas_display");
2962 ret = p_disp_create_evas_display(display, &EVAS_HANDLE(pc));
2963 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2965 /* before evas handle is created, user could set display information */
2966 if (EVAS_INFO(pc)->update_needed) {
2967 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_old_info, "disp_set_evas_display_old_info");
2968 ret = p_disp_set_evas_display_old_info(display, EVAS_HANDLE(pc), EVAS_INFO(pc)->mode, EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2969 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2970 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2971 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2972 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);
2973 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2975 EVAS_INFO(pc)->update_needed = FALSE;
2977 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_geometry_info, "disp_get_evas_display_geometry_info");
2978 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);
2979 wl_win.type = conv_type;
2981 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_media_packet_video_decode_cb, "disp_media_packet_video_decode_cb");
2982 ret = player_set_media_packet_video_frame_decoded_cb(player, p_disp_media_packet_video_decode_cb, (void *)EVAS_HANDLE(pc));
2983 if (ret != PLAYER_ERROR_NONE)
2984 LOGW("fail to set decoded callback");
2985 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2986 LOGW("fail to set __retrieve_buffer_cb");
2989 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2990 LOGI("Wayland surface type is NONE");
2991 wl_win.type = conv_type;
2994 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
2995 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2996 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
3002 int player_set_display_mode(player_h player, player_display_mode_e mode)
3004 PLAYER_INSTANCE_CHECK(player);
3005 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3006 int ret = PLAYER_ERROR_NONE;
3007 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
3008 player_cli_s *pc = (player_cli_s *) player;
3009 char *ret_buf = NULL;
3010 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3011 int (*p_disp_set_evas_display_disp_mode)(void *, int) = NULL;
3014 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3016 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3017 if (EVAS_HANDLE(pc)) {
3018 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_disp_mode, "disp_set_evas_display_disp_mode");
3019 ret = p_disp_set_evas_display_disp_mode(EVAS_HANDLE(pc), mode);
3020 if (ret != MM_ERROR_NONE)
3021 return PLAYER_ERROR_INVALID_OPERATION;
3023 return PLAYER_ERROR_NONE;
3025 EVAS_INFO(pc)->mode = mode;
3026 EVAS_INFO(pc)->update_needed = TRUE;
3029 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mode", (int)mode);
3034 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
3036 PLAYER_INSTANCE_CHECK(player);
3037 PLAYER_NULL_ARG_CHECK(pmode);
3038 int ret = PLAYER_ERROR_NONE;
3039 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
3040 player_cli_s *pc = (player_cli_s *) player;
3041 char *ret_buf = NULL;
3043 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3044 int (*p_disp_get_evas_display_disp_mode)(void *, int *) = NULL;
3048 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3050 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3051 if (EVAS_HANDLE(pc)) {
3052 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_disp_mode, "disp_get_evas_display_disp_mode");
3053 ret = p_disp_get_evas_display_disp_mode(EVAS_HANDLE(pc), &mode);
3054 *pmode = (player_display_mode_e) mode;
3055 if (ret != MM_ERROR_NONE)
3056 return PLAYER_ERROR_INVALID_OPERATION;
3058 return PLAYER_ERROR_NONE;
3061 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3062 if (ret == PLAYER_ERROR_NONE) {
3063 player_msg_get_type(mode, ret_buf, INT);
3072 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
3074 PLAYER_INSTANCE_CHECK(player);
3075 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3077 int ret = PLAYER_ERROR_NONE;
3078 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
3079 player_cli_s *pc = (player_cli_s *) player;
3080 char *ret_buf = NULL;
3081 wl_win_msg_type wl_win;
3082 char *wl_win_msg = (char *)&wl_win;
3083 int arr_msg_len = 0;
3084 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3085 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
3089 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3091 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3092 if (EVAS_HANDLE(pc)) {
3093 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
3094 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), x, y, width, height);
3095 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
3096 return PLAYER_ERROR_INVALID_PARAMETER;
3097 else if (ret != MM_ERROR_NONE)
3098 return PLAYER_ERROR_INVALID_OPERATION;
3100 return PLAYER_ERROR_NONE;
3102 EVAS_INFO(pc)->roi_x = x;
3103 EVAS_INFO(pc)->roi_y = y;
3104 EVAS_INFO(pc)->roi_w = width;
3105 EVAS_INFO(pc)->roi_h = height;
3106 EVAS_INFO(pc)->update_needed = TRUE;
3109 wl_win.wl_window_x = x;
3110 wl_win.wl_window_y = y;
3111 wl_win.wl_window_width = width;
3112 wl_win.wl_window_height = height;
3114 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
3115 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3116 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
3122 int player_set_playback_rate(player_h player, float rate)
3124 PLAYER_INSTANCE_CHECK(player);
3125 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3126 int ret = PLAYER_ERROR_NONE;
3127 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
3128 player_cli_s *pc = (player_cli_s *) player;
3129 char *ret_buf = NULL;
3133 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", (double)rate);
3136 LOGD("LEAVE 0x%X", ret);
3140 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
3142 PLAYER_INSTANCE_CHECK(player);
3143 int ret = PLAYER_ERROR_NONE;
3144 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
3145 player_cli_s *pc = (player_cli_s *) player;
3146 char *ret_buf = NULL;
3147 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3148 int (*p_disp_set_evas_display_rotation)(void *, int) = NULL;
3152 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3154 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3155 if (EVAS_HANDLE(pc)) {
3156 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_rotation, "disp_set_evas_display_rotation");
3157 ret = p_disp_set_evas_display_rotation(EVAS_HANDLE(pc), rotation);
3158 if (ret != MM_ERROR_NONE)
3159 return PLAYER_ERROR_INVALID_OPERATION;
3161 return PLAYER_ERROR_NONE;
3163 EVAS_INFO(pc)->rotation = rotation;
3164 EVAS_INFO(pc)->update_needed = TRUE;
3167 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "rotation", (int)rotation);
3172 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
3174 PLAYER_INSTANCE_CHECK(player);
3175 PLAYER_NULL_ARG_CHECK(protation);
3176 int ret = PLAYER_ERROR_NONE;
3177 player_cli_s *pc = (player_cli_s *) player;
3178 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
3179 char *ret_buf = NULL;
3181 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3182 int (*p_disp_get_evas_display_rotation)(void *, int *) = NULL;
3186 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3188 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3189 if (EVAS_HANDLE(pc)) {
3190 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_rotation, "disp_get_evas_display_rotation");
3191 ret = p_disp_get_evas_display_rotation(EVAS_HANDLE(pc), &rotation);
3192 *protation = (player_display_rotation_e) rotation;
3193 if (ret != MM_ERROR_NONE)
3194 return PLAYER_ERROR_INVALID_OPERATION;
3196 return PLAYER_ERROR_NONE;
3199 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3200 if (ret == PLAYER_ERROR_NONE) {
3201 player_msg_get_type(rotation, ret_buf, INT);
3202 *protation = rotation;
3209 int player_set_display_visible(player_h player, bool visible)
3211 PLAYER_INSTANCE_CHECK(player);
3212 int ret = PLAYER_ERROR_NONE;
3213 player_cli_s *pc = (player_cli_s *) player;
3214 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
3215 char *ret_buf = NULL;
3216 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3217 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
3221 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3223 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3224 if (EVAS_HANDLE(pc)) {
3225 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
3226 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), visible);
3227 if (ret != MM_ERROR_NONE)
3228 return PLAYER_ERROR_INVALID_OPERATION;
3230 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3231 return PLAYER_ERROR_NONE;
3233 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3234 EVAS_INFO(pc)->update_needed = TRUE;
3238 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "visible", (int)visible);
3243 int player_is_display_visible(player_h player, bool * pvisible)
3245 PLAYER_INSTANCE_CHECK(player);
3246 PLAYER_NULL_ARG_CHECK(pvisible);
3247 int ret = PLAYER_ERROR_NONE;
3248 player_cli_s *pc = (player_cli_s *) player;
3249 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
3250 char *ret_buf = NULL;
3252 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3254 int (*p_disp_get_evas_display_visible)(void *, bool *) = NULL;
3258 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3260 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3261 if (EVAS_HANDLE(pc)) {
3262 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_visible, "disp_get_evas_display_visible");
3263 ret = p_disp_get_evas_display_visible(EVAS_HANDLE(pc), &visible);
3269 if (ret != MM_ERROR_NONE)
3270 return PLAYER_ERROR_INVALID_OPERATION;
3272 return PLAYER_ERROR_NONE;
3275 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3276 if (ret == PLAYER_ERROR_NONE) {
3277 player_msg_get_type(value, ret_buf, INT);
3289 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3291 PLAYER_INSTANCE_CHECK(player);
3292 PLAYER_NULL_ARG_CHECK(pvalue);
3293 int ret = PLAYER_ERROR_NONE;
3294 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3295 player_cli_s *pc = (player_cli_s *) player;
3296 char *ret_buf = NULL;
3297 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3301 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "key", (int)key);
3302 if (ret == PLAYER_ERROR_NONE) {
3303 player_msg_get_string(value, ret_buf);
3304 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3310 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3312 PLAYER_INSTANCE_CHECK(player);
3313 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3314 int ret = PLAYER_ERROR_NONE;
3315 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3316 player_cli_s *pc = (player_cli_s *) player;
3317 char *ret_buf = NULL;
3318 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3319 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3320 bool ret_val = TRUE;
3324 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3325 if (ret == PLAYER_ERROR_NONE) {
3326 ret_val = _player_get_param_value(ret_buf,
3327 MUSE_TYPE_STRING, "video_codec", (void *)video_codec,
3328 MUSE_TYPE_STRING, "audio_codec", (void *)audio_codec,
3329 INVALID_MUSE_TYPE_VALUE);
3332 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3334 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3336 ret = PLAYER_ERROR_INVALID_OPERATION;
3343 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3345 PLAYER_INSTANCE_CHECK(player);
3346 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3347 int ret = PLAYER_ERROR_NONE;
3348 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3349 player_cli_s *pc = (player_cli_s *) player;
3350 char *ret_buf = NULL;
3351 int sample_rate = 0;
3357 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3358 if (ret == PLAYER_ERROR_NONE) {
3359 bool ret_val = true;
3360 ret_val = _player_get_param_value(ret_buf,
3361 MUSE_TYPE_INT, "sample_rate", (void *)&sample_rate,
3362 MUSE_TYPE_INT, "channel", (void *)&channel,
3363 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3364 INVALID_MUSE_TYPE_VALUE);
3367 *psample_rate = sample_rate;
3369 *pchannel = channel;
3371 *pbit_rate = bit_rate;
3373 ret = PLAYER_ERROR_INVALID_OPERATION;
3380 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3382 PLAYER_INSTANCE_CHECK(player);
3383 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3384 int ret = PLAYER_ERROR_NONE;
3385 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3386 player_cli_s *pc = (player_cli_s *) player;
3387 char *ret_buf = NULL;
3393 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3394 if (ret == PLAYER_ERROR_NONE) {
3395 bool ret_val = true;
3396 ret_val = _player_get_param_value(ret_buf,
3397 MUSE_TYPE_INT, "fps", (void *)&fps,
3398 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3399 INVALID_MUSE_TYPE_VALUE);
3404 *pbit_rate = bit_rate;
3406 ret = PLAYER_ERROR_INVALID_OPERATION;
3413 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3415 PLAYER_INSTANCE_CHECK(player);
3416 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3417 int ret = PLAYER_ERROR_NONE;
3418 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3419 player_cli_s *pc = (player_cli_s *) player;
3420 char *ret_buf = NULL;
3426 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3427 if (ret == PLAYER_ERROR_NONE) {
3428 bool ret_val = true;
3429 ret_val = _player_get_param_value(ret_buf,
3430 MUSE_TYPE_INT, "width", (void *)&width,
3431 MUSE_TYPE_INT, "height", (void *)&height,
3432 INVALID_MUSE_TYPE_VALUE);
3437 ret = PLAYER_ERROR_INVALID_OPERATION;
3444 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3446 PLAYER_INSTANCE_CHECK(player);
3447 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3448 int ret = PLAYER_ERROR_NONE;
3449 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3450 player_cli_s *pc = (player_cli_s *) player;
3451 char *ret_buf = NULL;
3455 tbm_bo_handle thandle;
3456 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3457 int key = INVALID_DEFAULT_VALUE;
3462 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3463 if (ret == PLAYER_ERROR_NONE) {
3464 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3465 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3467 LOGE("failed to get msg obj, err:%d", err);
3468 ret = PLAYER_ERROR_INVALID_OPERATION;
3472 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3473 LOGD("size : %d", size);
3474 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3475 LOGE("failed to get key value");
3476 ret = PLAYER_ERROR_INVALID_OPERATION;
3480 tfd = pc->cb_info->tfd;
3482 LOGE("failed to get tbm fd value");
3483 ret = PLAYER_ERROR_INVALID_OPERATION;
3487 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3489 LOGE("TBM get error : bo is NULL");
3490 ret = PLAYER_ERROR_INVALID_OPERATION;
3493 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3494 if (thandle.ptr == NULL) {
3495 LOGE("TBM get error : handle pointer is NULL");
3496 ret = PLAYER_ERROR_INVALID_OPERATION;
3499 album_art = _get_mem(pc, size);
3501 memcpy(album_art, thandle.ptr, size);
3502 *palbum_art = album_art;
3504 LOGE("g_new failure");
3505 ret = PLAYER_ERROR_INVALID_OPERATION;
3517 muse_core_msg_object_free(jobj);
3522 if (tfd > INVALID_DEFAULT_VALUE)
3525 if (CALLBACK_INFO(pc))
3526 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3532 if (key > INVALID_DEFAULT_VALUE && CALLBACK_INFO(pc)) {
3533 LOGD("send msg to release buffer. key:%d", key);
3534 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_RETURN_BUFFER, MSG_FD(pc), ret, MUSE_TYPE_INT, "key", key);
3540 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3542 PLAYER_INSTANCE_CHECK(player);
3543 PLAYER_NULL_ARG_CHECK(pcount);
3544 int ret = PLAYER_ERROR_NONE;
3545 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3546 player_cli_s *pc = (player_cli_s *) player;
3547 char *ret_buf = NULL;
3552 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3553 if (ret == PLAYER_ERROR_NONE) {
3554 player_msg_get(count, ret_buf);
3561 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3563 PLAYER_INSTANCE_CHECK(player);
3564 PLAYER_NULL_ARG_CHECK(band_levels);
3565 int ret = PLAYER_ERROR_NONE;
3566 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3567 player_cli_s *pc = (player_cli_s *) player;
3568 char *ret_buf = NULL;
3572 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3573 MUSE_TYPE_INT, "length", length,
3574 MUSE_TYPE_ARRAY, "band_levels", length, band_levels);
3581 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3583 PLAYER_INSTANCE_CHECK(player);
3584 int ret = PLAYER_ERROR_NONE;
3585 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3586 player_cli_s *pc = (player_cli_s *) player;
3587 char *ret_buf = NULL;
3591 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3592 MUSE_TYPE_INT, "index", index,
3593 MUSE_TYPE_INT, "level", level);
3599 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3601 PLAYER_INSTANCE_CHECK(player);
3602 PLAYER_NULL_ARG_CHECK(plevel);
3603 int ret = PLAYER_ERROR_NONE;
3604 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3605 player_cli_s *pc = (player_cli_s *) player;
3606 char *ret_buf = NULL;
3611 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3612 if (ret == PLAYER_ERROR_NONE) {
3613 player_msg_get(level, ret_buf);
3620 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3622 PLAYER_INSTANCE_CHECK(player);
3623 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3624 int ret = PLAYER_ERROR_NONE;
3625 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3626 player_cli_s *pc = (player_cli_s *) player;
3627 char *ret_buf = NULL;
3628 int min = 0, max = 0;
3632 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3633 if (ret == PLAYER_ERROR_NONE) {
3634 bool ret_val = true;
3635 ret_val = _player_get_param_value(ret_buf,
3636 MUSE_TYPE_INT, "min", (void *)&min,
3637 MUSE_TYPE_INT, "max", (void *)&max,
3638 INVALID_MUSE_TYPE_VALUE);
3643 ret = PLAYER_ERROR_INVALID_OPERATION;
3650 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3652 PLAYER_INSTANCE_CHECK(player);
3653 PLAYER_NULL_ARG_CHECK(pfrequency);
3654 int ret = PLAYER_ERROR_NONE;
3655 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3656 player_cli_s *pc = (player_cli_s *) player;
3657 char *ret_buf = NULL;
3662 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3663 if (ret == PLAYER_ERROR_NONE) {
3664 player_msg_get(frequency, ret_buf);
3665 *pfrequency = frequency;
3671 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3673 PLAYER_INSTANCE_CHECK(player);
3674 PLAYER_NULL_ARG_CHECK(prange);
3675 int ret = PLAYER_ERROR_NONE;
3676 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3677 player_cli_s *pc = (player_cli_s *) player;
3678 char *ret_buf = NULL;
3683 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3684 if (ret == PLAYER_ERROR_NONE) {
3685 player_msg_get(range, ret_buf);
3692 int player_audio_effect_equalizer_clear(player_h player)
3694 PLAYER_INSTANCE_CHECK(player);
3695 int ret = PLAYER_ERROR_NONE;
3696 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3697 player_cli_s *pc = (player_cli_s *) player;
3698 char *ret_buf = NULL;
3702 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3707 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3709 PLAYER_INSTANCE_CHECK(player);
3710 PLAYER_NULL_ARG_CHECK(pavailable);
3711 int ret = PLAYER_ERROR_NONE;
3712 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3713 player_cli_s *pc = (player_cli_s *) player;
3714 char *ret_buf = NULL;
3719 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3720 if (ret == PLAYER_ERROR_NONE) {
3721 player_msg_get(available, ret_buf);
3722 *pavailable = available;
3728 int player_set_subtitle_path(player_h player, const char *path)
3730 PLAYER_INSTANCE_CHECK(player);
3731 int ret = PLAYER_ERROR_NONE;
3732 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3733 player_cli_s *pc = (player_cli_s *) player;
3734 char *ret_buf = NULL;
3735 char subtitle_path[MAX_URL_LEN] = {0, };
3739 if (path && _player_get_valid_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3740 return PLAYER_ERROR_INVALID_PARAMETER;
3742 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "subtitle_path", (const char*)subtitle_path);
3747 int player_set_subtitle_position_offset(player_h player, int milliseconds)
3749 PLAYER_INSTANCE_CHECK(player);
3750 int ret = PLAYER_ERROR_NONE;
3751 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3752 player_cli_s *pc = (player_cli_s *) player;
3753 char *ret_buf = NULL;
3757 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "milliseconds", milliseconds);
3763 int player_set_progressive_download_path(player_h player, const char *path)
3765 PLAYER_INSTANCE_CHECK(player);
3766 PLAYER_NULL_ARG_CHECK(path);
3767 int ret = PLAYER_ERROR_NONE;
3768 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
3769 player_cli_s *pc = (player_cli_s *) player;
3770 char *ret_buf = NULL;
3771 char dw_path[MAX_URL_LEN] = {0, };
3774 LOGW("DEPRECATION WARNING: player_set_progressive_download_path() is deprecated and will be removed from next release.");
3776 if (!_player_check_network_availability())
3777 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3779 if (_player_get_valid_path(path, dw_path) != PLAYER_ERROR_NONE)
3780 return PLAYER_ERROR_INVALID_PARAMETER;
3782 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "dw_path", (const char*)dw_path);
3787 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
3789 PLAYER_INSTANCE_CHECK(player);
3790 PLAYER_NULL_ARG_CHECK(pcurrent && ptotal_size);
3791 int ret = PLAYER_ERROR_NONE;
3792 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
3793 player_cli_s *pc = (player_cli_s *) player;
3794 char *ret_buf = NULL;
3795 unsigned long current, total_size;
3798 LOGW("DEPRECATION WARNING: player_get_progressive_download_status() is deprecated and will be removed from next release.");
3800 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3801 if (ret == PLAYER_ERROR_NONE) {
3802 bool ret_val = true;
3803 ret_val = _player_get_param_value(ret_buf,
3804 MUSE_TYPE_POINTER, "current", (void *)¤t,
3805 MUSE_TYPE_POINTER, "total_size", (void *)&total_size,
3806 INVALID_MUSE_TYPE_VALUE);
3808 *pcurrent = current;
3809 *ptotal_size = total_size;
3811 ret = PLAYER_ERROR_INVALID_OPERATION;
3819 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3821 PLAYER_INSTANCE_CHECK(player);
3822 PLAYER_NULL_ARG_CHECK(callback);
3823 int ret = PLAYER_ERROR_NONE;
3824 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3825 player_cli_s *pc = (player_cli_s *) player;
3826 char *ret_buf = NULL;
3829 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3830 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3831 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3833 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3834 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3835 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3838 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3840 if (ret != PLAYER_ERROR_NONE)
3841 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3847 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3849 PLAYER_INSTANCE_CHECK(player);
3850 PLAYER_NULL_ARG_CHECK(cookie);
3851 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3852 int ret = PLAYER_ERROR_NONE;
3853 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3854 player_cli_s *pc = (player_cli_s *) player;
3855 char *ret_buf = NULL;
3859 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3860 MUSE_TYPE_STRING, "cookie", cookie,
3861 MUSE_TYPE_INT, "size", size);
3866 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3868 PLAYER_INSTANCE_CHECK(player);
3869 PLAYER_NULL_ARG_CHECK(user_agent);
3870 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3871 int ret = PLAYER_ERROR_NONE;
3872 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3873 player_cli_s *pc = (player_cli_s *) player;
3874 char *ret_buf = NULL;
3878 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3879 MUSE_TYPE_STRING, "user_agent", user_agent,
3880 MUSE_TYPE_INT, "size", size);
3885 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3887 PLAYER_INSTANCE_CHECK(player);
3888 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3889 int ret = PLAYER_ERROR_NONE;
3890 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3891 player_cli_s *pc = (player_cli_s *) player;
3892 char *ret_buf = NULL;
3893 int start = 0, current = 0;
3897 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3898 if (ret == PLAYER_ERROR_NONE) {
3899 bool ret_val = true;
3900 ret_val = _player_get_param_value(ret_buf,
3901 MUSE_TYPE_INT, "start", (void *)&start,
3902 MUSE_TYPE_INT, "current", (void *)¤t,
3903 INVALID_MUSE_TYPE_VALUE);
3906 *pcurrent = current;
3908 ret = PLAYER_ERROR_INVALID_OPERATION;
3916 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3918 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3921 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3922 static void __retrieve_buffer_cb(void *user_data)
3924 player_cli_s *player = (player_cli_s *)user_data;
3925 int ret = PLAYER_ERROR_NONE;
3926 bool gapless = false;
3927 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
3929 ret = player_is_gapless((player_h)user_data, &gapless);
3930 if (ret != PLAYER_ERROR_NONE) {
3931 LOGW("player_is_gapless is failed");
3935 PLAYER_DISP_DLSYM(player->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
3936 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3937 if (ret != PLAYER_ERROR_NONE)
3938 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3941 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3943 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3946 static int __player_unset_retrieve_buffer_cb(player_h player)
3948 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3952 int player_unset_completed_cb(player_h player)
3954 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3957 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3959 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3962 int player_unset_interrupted_cb(player_h player)
3964 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3967 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3969 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3972 int player_unset_error_cb(player_h player)
3974 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3977 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3979 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3982 int player_unset_buffering_cb(player_h player)
3984 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3987 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3989 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3992 int player_unset_subtitle_updated_cb(player_h player)
3994 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3997 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3999 PLAYER_INSTANCE_CHECK(player);
4000 PLAYER_NULL_ARG_CHECK(callback);
4001 int ret = PLAYER_ERROR_NONE;
4002 player_cli_s *pc = (player_cli_s *) player;
4003 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4004 char *ret_buf = NULL;
4005 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
4009 LOGW("DEPRECATION WARNING: player_set_progressive_download_message_cb() is deprecated and will be removed from next release.");
4011 if (!_player_check_network_availability())
4012 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
4014 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4015 MUSE_TYPE_INT, "type", type,
4016 MUSE_TYPE_INT, "set", set);
4018 if (ret == PLAYER_ERROR_NONE) {
4019 pc->cb_info->user_cb[type] = callback;
4020 pc->cb_info->user_data[type] = user_data;
4021 LOGI("Event type : %d ", type);
4028 int player_unset_progressive_download_message_cb(player_h player)
4030 PLAYER_INSTANCE_CHECK(player);
4031 int ret = PLAYER_ERROR_NONE;
4032 player_cli_s *pc = (player_cli_s *) player;
4033 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4034 char *ret_buf = NULL;
4035 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
4039 LOGW("DEPRECATION WARNING: player_unset_progressive_download_message_cb() is deprecated and will be removed from next release.");
4041 set_null_user_cb_lock(pc->cb_info, type);
4043 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4044 MUSE_TYPE_INT, "type", type,
4045 MUSE_TYPE_INT, "set", set);
4052 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
4054 PLAYER_INSTANCE_CHECK(player);
4055 PLAYER_NULL_ARG_CHECK(callback);
4056 int ret = PLAYER_ERROR_NONE;
4057 player_cli_s *pc = (player_cli_s *) player;
4058 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4059 char *ret_buf = NULL;
4060 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
4065 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4066 MUSE_TYPE_INT, "type", type,
4067 MUSE_TYPE_INT, "set", set);
4069 if (ret == PLAYER_ERROR_NONE) {
4070 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
4071 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
4072 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
4079 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
4081 PLAYER_INSTANCE_CHECK(player);
4082 int ret = PLAYER_ERROR_NONE;
4083 player_cli_s *pc = (player_cli_s *) player;
4084 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4085 char *ret_buf = NULL;
4086 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
4091 set_null_user_cb_lock(pc->cb_info, type);
4093 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4094 MUSE_TYPE_INT, "type", type,
4095 MUSE_TYPE_INT, "set", set);
4101 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
4103 PLAYER_INSTANCE_CHECK(player);
4104 PLAYER_NULL_ARG_CHECK(callback);
4105 int ret = PLAYER_ERROR_NONE;
4106 player_cli_s *pc = (player_cli_s *) player;
4107 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4108 char *ret_buf = NULL;
4109 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4114 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4115 MUSE_TYPE_INT, "type", type,
4116 MUSE_TYPE_INT, "set", set);
4118 if (ret == PLAYER_ERROR_NONE) {
4119 pc->cb_info->user_cb[type] = callback;
4120 pc->cb_info->user_data[type] = user_data;
4121 LOGI("Event type : %d ", type);
4128 int player_unset_video_stream_changed_cb(player_h player)
4130 PLAYER_INSTANCE_CHECK(player);
4131 int ret = PLAYER_ERROR_NONE;
4132 player_cli_s *pc = (player_cli_s *) player;
4133 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4134 char *ret_buf = NULL;
4135 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4140 set_null_user_cb_lock(pc->cb_info, type);
4142 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4143 MUSE_TYPE_INT, "type", type,
4144 MUSE_TYPE_INT, "set", set);
4150 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)
4152 PLAYER_INSTANCE_CHECK(player);
4153 PLAYER_NULL_ARG_CHECK(callback);
4154 int ret = PLAYER_ERROR_NONE;
4155 player_cli_s *pc = (player_cli_s *) player;
4156 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4157 char *ret_buf = NULL;
4158 muse_player_event_e type;
4163 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4164 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4165 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4166 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4168 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4169 return PLAYER_ERROR_INVALID_PARAMETER;
4172 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4173 MUSE_TYPE_INT, "type", type,
4174 MUSE_TYPE_INT, "set", set);
4176 if (ret == PLAYER_ERROR_NONE) {
4177 pc->cb_info->user_cb[type] = callback;
4178 pc->cb_info->user_data[type] = user_data;
4179 LOGI("Event type : %d ", type);
4186 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
4188 PLAYER_INSTANCE_CHECK(player);
4189 int ret = PLAYER_ERROR_NONE;
4190 player_cli_s *pc = (player_cli_s *) player;
4191 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4192 char *ret_buf = NULL;
4193 muse_player_event_e type;
4198 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4199 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4200 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4201 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4203 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4204 return PLAYER_ERROR_INVALID_PARAMETER;
4207 set_null_user_cb_lock(pc->cb_info, type);
4209 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4210 MUSE_TYPE_INT, "type", type,
4211 MUSE_TYPE_INT, "set", set);
4217 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)
4219 PLAYER_INSTANCE_CHECK(player);
4220 PLAYER_NULL_ARG_CHECK(callback);
4221 int ret = PLAYER_ERROR_NONE;
4222 player_cli_s *pc = (player_cli_s *) player;
4223 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4224 char *ret_buf = NULL;
4225 muse_player_event_e type;
4230 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4231 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4232 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4233 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4235 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4236 return PLAYER_ERROR_INVALID_PARAMETER;
4239 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4240 MUSE_TYPE_INT, "type", type,
4241 MUSE_TYPE_INT, "set", set);
4243 if (ret == PLAYER_ERROR_NONE) {
4244 pc->cb_info->user_cb[type] = callback;
4245 pc->cb_info->user_data[type] = user_data;
4246 LOGI("Event type : %d ", type);
4253 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
4255 PLAYER_INSTANCE_CHECK(player);
4256 int ret = PLAYER_ERROR_NONE;
4257 player_cli_s *pc = (player_cli_s *) player;
4258 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4259 char *ret_buf = NULL;
4260 muse_player_event_e type;
4265 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4266 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4267 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4268 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4270 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4271 return PLAYER_ERROR_INVALID_PARAMETER;
4274 set_null_user_cb_lock(pc->cb_info, type);
4276 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4277 MUSE_TYPE_INT, "type", type,
4278 MUSE_TYPE_INT, "set", set);
4284 /* TODO Implement raw data socket channel */
4285 int player_push_media_stream(player_h player, media_packet_h packet)
4287 PLAYER_INSTANCE_CHECK(player);
4288 PLAYER_NULL_ARG_CHECK(packet);
4289 int ret = PLAYER_ERROR_NONE;
4290 player_cli_s *pc = (player_cli_s *) player;
4291 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
4292 char *ret_buf = NULL;
4293 player_push_media_msg_type push_media;
4294 char *push_media_msg = (char *)&push_media;
4295 int msg_size = sizeof(player_push_media_msg_type);
4299 tbm_bo_handle thandle;
4300 tbm_fd tfd = INVALID_DEFAULT_VALUE;
4303 media_format_h format;
4307 int arr_msg_len = 0;
4311 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
4312 media_packet_get_buffer_size(packet, &push_media.size);
4313 media_packet_get_pts(packet, &push_media.pts);
4314 media_packet_get_format(packet, &format);
4315 media_packet_get_flags(packet, &push_media.flags);
4317 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
4319 media_packet_is_video(packet, &is_video);
4320 media_packet_is_audio(packet, &is_audio);
4321 media_packet_is_end_of_stream(packet, &is_eos);
4323 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
4325 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
4327 media_format_unref(format);
4330 int arr_buf_len = 0;
4332 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
4333 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
4335 LOGE("TBM get error : bo is NULL");
4336 return PLAYER_ERROR_INVALID_OPERATION;
4338 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4339 if (thandle.ptr == NULL) {
4340 LOGE("TBM get error : handle pointer is NULL");
4341 ret = PLAYER_ERROR_INVALID_OPERATION;
4344 memcpy(thandle.ptr, buf, push_media.size);
4347 tfd = tbm_bo_export_fd(bo);
4349 LOGE("tbm_bo_export_fd err 0x%x", tfd);
4350 ret = PLAYER_ERROR_INVALID_OPERATION;
4354 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4355 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret,
4356 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4358 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4359 buf_size = (int)push_media.size;
4361 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4362 arr_buf_len = (buf_size / sizeof(int) + (buf_size % sizeof(int) ? 1 : 0));
4363 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4364 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg,
4365 MUSE_TYPE_ARRAY, "buf", arr_buf_len, (int*)buf);
4369 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4370 buf_size = (int)push_media.size;
4371 if ((muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts) < 0) && (!is_eos)) {
4372 LOGE("failed to send data");
4373 return PLAYER_ERROR_INVALID_OPERATION;
4376 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4377 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4378 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg);
4381 LOGD("ret_buf %s", ret_buf);
4385 if (tfd > INVALID_DEFAULT_VALUE)
4388 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4396 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4398 PLAYER_INSTANCE_CHECK(player);
4399 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4400 int ret = PLAYER_ERROR_NONE;
4401 player_cli_s *pc = (player_cli_s *) player;
4402 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4403 char *ret_buf = NULL;
4404 media_format_mimetype_e mimetype;
4416 media_format_ref(format);
4417 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4418 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4419 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4420 LOGE("failed to get video info from format.");
4421 return PLAYER_ERROR_INVALID_PARAMETER;
4424 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4425 MUSE_TYPE_INT, "type", type,
4426 MUSE_TYPE_INT, "mimetype", mimetype,
4427 MUSE_TYPE_INT, "width", width,
4428 MUSE_TYPE_INT, "height", height,
4429 MUSE_TYPE_INT, "avg_bps", avg_bps,
4430 MUSE_TYPE_INT, "max_bps", max_bps,
4431 MUSE_TYPE_INT, "frame_rate", frame_rate);
4433 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4434 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4435 LOGE("failed to get audio info from format.");
4436 return PLAYER_ERROR_INVALID_PARAMETER;
4439 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4440 MUSE_TYPE_INT, "type", type,
4441 MUSE_TYPE_INT, "mimetype", mimetype,
4442 MUSE_TYPE_INT, "channel", channel,
4443 MUSE_TYPE_INT, "samplerate", samplerate,
4444 MUSE_TYPE_INT, "avg_bps", avg_bps,
4445 MUSE_TYPE_INT, "bit", bit);
4448 media_format_unref(format);
4449 pc->push_media_stream = TRUE;
4455 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4457 int ret = PLAYER_ERROR_NONE;
4458 PLAYER_INSTANCE_CHECK(player);
4459 player_cli_s *pc = (player_cli_s *) player;
4460 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4461 char *ret_buf = NULL;
4465 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4466 MUSE_TYPE_INT, "type", type,
4467 MUSE_TYPE_INT64, "max_size", (INT64)max_size);
4473 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4475 int ret = PLAYER_ERROR_NONE;
4476 PLAYER_INSTANCE_CHECK(player);
4477 PLAYER_NULL_ARG_CHECK(pmax_size);
4478 player_cli_s *pc = (player_cli_s *) player;
4479 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4480 char *ret_buf = NULL;
4481 unsigned long long max_size;
4485 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4486 if (ret == PLAYER_ERROR_NONE) {
4487 player_msg_get_type(max_size, ret_buf, INT64);
4488 *pmax_size = max_size;
4494 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4496 int ret = PLAYER_ERROR_NONE;
4497 PLAYER_INSTANCE_CHECK(player);
4498 player_cli_s *pc = (player_cli_s *) player;
4499 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4500 char *ret_buf = NULL;
4504 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4505 MUSE_TYPE_INT, "type", type,
4506 MUSE_TYPE_INT, "percent", (int)percent);
4512 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4514 int ret = PLAYER_ERROR_NONE;
4515 PLAYER_INSTANCE_CHECK(player);
4516 PLAYER_NULL_ARG_CHECK(ppercent);
4517 player_cli_s *pc = (player_cli_s *) player;
4518 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4519 char *ret_buf = NULL;
4524 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4525 if (ret == PLAYER_ERROR_NONE) {
4526 player_msg_get(percent, ret_buf);
4527 *ppercent = percent;
4534 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4536 PLAYER_INSTANCE_CHECK(player);
4537 PLAYER_NULL_ARG_CHECK(pcount);
4538 int ret = PLAYER_ERROR_NONE;
4539 player_cli_s *pc = (player_cli_s *) player;
4540 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4541 char *ret_buf = NULL;
4546 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4547 if (ret == PLAYER_ERROR_NONE) {
4548 player_msg_get(count, ret_buf);
4556 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4558 PLAYER_INSTANCE_CHECK(player);
4559 PLAYER_NULL_ARG_CHECK(pindex);
4560 int ret = PLAYER_ERROR_NONE;
4561 player_cli_s *pc = (player_cli_s *) player;
4562 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4563 char *ret_buf = NULL;
4568 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4569 if (ret == PLAYER_ERROR_NONE) {
4570 player_msg_get(index, ret_buf);
4578 int player_select_track(player_h player, player_stream_type_e type, int index)
4580 PLAYER_INSTANCE_CHECK(player);
4581 int ret = PLAYER_ERROR_NONE;
4582 player_cli_s *pc = (player_cli_s *) player;
4583 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4584 char *ret_buf = NULL;
4588 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4594 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4596 PLAYER_INSTANCE_CHECK(player);
4597 PLAYER_NULL_ARG_CHECK(pcode);
4598 int ret = PLAYER_ERROR_NONE;
4599 player_cli_s *pc = (player_cli_s *) player;
4600 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4601 char *ret_buf = NULL;
4602 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4607 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4608 if (ret == PLAYER_ERROR_NONE) {
4609 bool recv_ret = true;
4610 recv_ret = _player_get_param_value(ret_buf,
4611 MUSE_TYPE_INT, "code_len", (void *)&code_len,
4612 MUSE_TYPE_STRING, "code", (void *)code,
4613 INVALID_MUSE_TYPE_VALUE);
4615 *pcode = strndup(code, code_len);
4617 ret = PLAYER_ERROR_INVALID_OPERATION;
4623 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4625 PLAYER_INSTANCE_CHECK(player);
4626 PLAYER_NULL_ARG_CHECK(callback);
4627 int ret = PLAYER_ERROR_NONE;
4628 player_cli_s *pc = (player_cli_s *) player;
4629 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4630 char *ret_buf = NULL;
4631 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4632 int idx = 0, num = 0;
4633 int bandwidth = 0, width = 0, height = 0;
4639 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4640 if (ret == PLAYER_ERROR_NONE) {
4641 player_msg_get_type(num, ret_buf, INT);
4643 player_msg_get_string(var_info, ret_buf);
4645 LOGW("There is no stream variant info.");
4648 for (idx = 0 ; idx < num ; idx++) {
4649 bandwidth = width = height = 0;
4651 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4653 bandwidth = atoi(token);
4655 token = strtok_r(NULL, ",", &ptr);
4657 width = atoi(token);
4659 token = strtok_r(NULL, ",", &ptr);
4661 height = atoi(token);
4663 callback(bandwidth, width, height, user_data);
4666 LOGD("LEAVE 0x%X", ret);
4671 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4673 int ret = PLAYER_ERROR_NONE;
4674 PLAYER_INSTANCE_CHECK(player);
4675 PLAYER_CHECK_CONDITION(bandwidth >= -1 && width >= -1 && height >= -1,
4676 PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4677 player_cli_s *pc = (player_cli_s *) player;
4678 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4679 char *ret_buf = NULL;
4683 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4684 MUSE_TYPE_INT, "bandwidth", bandwidth,
4685 MUSE_TYPE_INT, "width", width,
4686 MUSE_TYPE_INT, "height", height);
4689 LOGD("LEAVE 0x%X", ret);
4694 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4696 int ret = PLAYER_ERROR_NONE;
4697 PLAYER_INSTANCE_CHECK(player);
4698 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4700 player_cli_s *pc = (player_cli_s *) player;
4701 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4702 char *ret_buf = NULL;
4703 int bandwidth = -1, width = -1, height = -1;
4707 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4708 if (ret == PLAYER_ERROR_NONE) {
4709 bool ret_val = true;
4710 ret_val = _player_get_param_value(ret_buf,
4711 MUSE_TYPE_INT, "bandwidth", (void *)&bandwidth,
4712 MUSE_TYPE_INT, "width", (void *)&width,
4713 MUSE_TYPE_INT, "height", (void *)&height,
4714 INVALID_MUSE_TYPE_VALUE);
4716 if (pbandwidth) *pbandwidth = bandwidth;
4717 if (pwidth) *pwidth = width;
4718 if (pheight) *pheight = height;
4720 ret = PLAYER_ERROR_INVALID_OPERATION;
4725 LOGD("LEAVE 0x%X", ret);
4729 int player_set_audio_only(player_h player, bool audio_only)
4731 int ret = PLAYER_ERROR_NONE;
4732 PLAYER_INSTANCE_CHECK(player);
4733 player_cli_s *pc = (player_cli_s *) player;
4734 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4735 char *ret_buf = NULL;
4736 player_state_e state = PLAYER_STATE_NONE;
4738 LOGD("ENTER audio_only: %d", audio_only);
4740 /* check player state */
4741 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
4742 LOGE("Failed to get state");
4743 return PLAYER_ERROR_INVALID_OPERATION;
4746 if (state < PLAYER_STATE_READY) {
4747 LOGE("Invalid state %d", state);
4748 return PLAYER_ERROR_INVALID_STATE;
4751 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4752 if (EVAS_HANDLE(pc)) {
4753 pc->is_audio_only = (gboolean)audio_only;
4754 return PLAYER_ERROR_NONE;
4757 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "audio_only", (int)audio_only);
4760 LOGD("LEAVE 0x%X", ret);
4765 int player_is_audio_only(player_h player, bool *paudio_only)
4767 PLAYER_INSTANCE_CHECK(player);
4768 PLAYER_NULL_ARG_CHECK(paudio_only);
4769 int ret = PLAYER_ERROR_NONE;
4770 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4771 player_cli_s *pc = (player_cli_s *) player;
4772 char *ret_buf = NULL;
4776 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4777 if (EVAS_HANDLE(pc)) {
4778 *paudio_only = (bool)pc->is_audio_only;
4779 return PLAYER_ERROR_NONE;
4783 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4784 if (ret == PLAYER_ERROR_NONE) {
4785 player_msg_get(audio_only, ret_buf);
4786 *paudio_only = (bool)audio_only;
4790 LOGD("LEAVE 0x%X", ret);
4794 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4796 int ret = PLAYER_ERROR_NONE;
4797 PLAYER_INSTANCE_CHECK(player);
4798 PLAYER_CHECK_CONDITION(buffer_ms >= 0 && rebuffer_ms >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4800 player_cli_s *pc = (player_cli_s *) player;
4801 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4802 char *ret_buf = NULL;
4806 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4807 MUSE_TYPE_INT, "buffer_ms", buffer_ms,
4808 MUSE_TYPE_INT, "rebuffer_ms", rebuffer_ms);
4811 LOGD("LEAVE 0x%X", ret);
4815 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4817 PLAYER_INSTANCE_CHECK(player);
4818 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4820 int ret = PLAYER_ERROR_NONE;
4821 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4822 player_cli_s *pc = (player_cli_s *) player;
4823 int buffering_time = 0, rebuffering_time = 0;
4824 char *ret_buf = NULL;
4828 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4830 if (ret == PLAYER_ERROR_NONE) {
4831 bool ret_val = true;
4832 ret_val = _player_get_param_value(ret_buf,
4833 MUSE_TYPE_INT, "buffering_time", (void *)&buffering_time,
4834 MUSE_TYPE_INT, "rebuffering_time", (void *)&rebuffering_time,
4835 INVALID_MUSE_TYPE_VALUE);
4837 if (buffer_ms) *buffer_ms = buffering_time;
4838 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4840 ret = PLAYER_ERROR_INVALID_OPERATION;
4846 LOGD("LEAVE 0x%X", ret);
4850 int player_360_is_content_spherical(player_h player, bool *is_spherical)
4852 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4853 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4855 PLAYER_INSTANCE_CHECK(player);
4856 PLAYER_NULL_ARG_CHECK(is_spherical);
4858 int ret = PLAYER_ERROR_NONE;
4859 muse_player_api_e api = MUSE_PLAYER_API_360_IS_CONTENT_SPHERICAL;
4860 player_cli_s *pc = (player_cli_s *) player;
4861 char *ret_buf = NULL;
4866 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4867 if (ret == PLAYER_ERROR_NONE) {
4868 player_msg_get(val, ret_buf);
4869 *is_spherical = val;
4873 LOGD("LEAVE 0x%X", ret);
4877 int player_360_set_enabled(player_h player, bool enabled)
4879 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4880 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4882 PLAYER_INSTANCE_CHECK(player);
4883 int ret = PLAYER_ERROR_NONE;
4884 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLED;
4885 player_cli_s *pc = (player_cli_s *) player;
4886 char *ret_buf = NULL;
4887 int val = (int)enabled;
4889 LOGD("ENTER %d", enabled);
4891 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
4894 LOGD("LEAVE 0x%X", ret);
4898 int player_360_is_enabled(player_h player, bool *enabled)
4900 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4901 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4903 PLAYER_INSTANCE_CHECK(player);
4904 PLAYER_NULL_ARG_CHECK(enabled);
4905 int ret = PLAYER_ERROR_NONE;
4906 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4907 player_cli_s *pc = (player_cli_s *) player;
4908 char *ret_buf = NULL;
4913 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4914 if (ret == PLAYER_ERROR_NONE) {
4915 player_msg_get(val, ret_buf);
4920 LOGD("LEAVE 0x%X", ret);
4924 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4926 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4927 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4929 PLAYER_INSTANCE_CHECK(player);
4930 int ret = PLAYER_ERROR_NONE;
4931 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4932 player_cli_s *pc = (player_cli_s *) player;
4933 char *ret_buf = NULL;
4935 LOGD("ENTER %f %f", yaw, pitch);
4937 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4938 MUSE_TYPE_DOUBLE, "yaw", (double)yaw,
4939 MUSE_TYPE_DOUBLE, "pitch", (double)pitch);
4943 LOGD("LEAVE 0x%X", ret);
4947 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4949 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4950 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4952 PLAYER_INSTANCE_CHECK(player);
4953 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4954 int ret = PLAYER_ERROR_NONE;
4955 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4956 player_cli_s *pc = (player_cli_s *) player;
4957 double yaw_val = -1;
4958 double pitch_val = -1;
4959 char *ret_buf = NULL;
4963 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4965 if (ret == PLAYER_ERROR_NONE) {
4966 bool ret_val = true;
4967 ret_val = _player_get_param_value(ret_buf,
4968 MUSE_TYPE_DOUBLE, "yaw_val", (void *)&yaw_val,
4969 MUSE_TYPE_DOUBLE, "pitch_val", (void *)&pitch_val,
4970 INVALID_MUSE_TYPE_VALUE);
4972 *yaw = (float)yaw_val;
4973 *pitch = (float)pitch_val;
4975 LOGE("failed to get value from msg");
4976 ret = PLAYER_ERROR_INVALID_OPERATION;
4982 LOGD("LEAVE 0x%X", ret);
4986 int player_360_set_zoom(player_h player, float level)
4988 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4989 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4991 PLAYER_INSTANCE_CHECK(player);
4992 int ret = PLAYER_ERROR_NONE;
4993 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4994 player_cli_s *pc = (player_cli_s *) player;
4995 char *ret_buf = NULL;
4997 LOGD("ENTER %f", level);
4999 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "level", (double)level);
5002 LOGD("LEAVE 0x%X", ret);
5006 int player_360_get_zoom(player_h player, float *level)
5008 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5009 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5011 PLAYER_INSTANCE_CHECK(player);
5012 PLAYER_NULL_ARG_CHECK(level);
5013 int ret = PLAYER_ERROR_NONE;
5014 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
5015 player_cli_s *pc = (player_cli_s *) player;
5017 char *ret_buf = NULL;
5021 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5023 if (ret == PLAYER_ERROR_NONE) {
5024 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
5025 *level = (float)zoom;
5027 LOGE("failed to get value from msg");
5028 ret = PLAYER_ERROR_INVALID_OPERATION;
5034 LOGD("LEAVE 0x%X", ret);
5039 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
5041 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5042 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5044 PLAYER_INSTANCE_CHECK(player);
5045 int ret = PLAYER_ERROR_NONE;
5046 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
5047 player_cli_s *pc = (player_cli_s *) player;
5048 char *ret_buf = NULL;
5050 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
5052 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5053 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5054 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5057 LOGD("LEAVE 0x%X", ret);
5061 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
5063 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5064 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5066 PLAYER_INSTANCE_CHECK(player);
5067 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
5068 int ret = PLAYER_ERROR_NONE;
5069 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
5070 player_cli_s *pc = (player_cli_s *) player;
5073 char *ret_buf = NULL;
5077 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5079 if (ret == PLAYER_ERROR_NONE) {
5080 bool ret_val = true;
5081 ret_val = _player_get_param_value(ret_buf,
5082 MUSE_TYPE_INT, "h_val", (void *)&h_val,
5083 MUSE_TYPE_INT, "v_val", (void *)&v_val,
5084 INVALID_MUSE_TYPE_VALUE);
5086 *horizontal_degrees = h_val;
5087 *vertical_degrees = v_val;
5089 LOGE("failed to get value from msg");
5090 ret = PLAYER_ERROR_INVALID_OPERATION;
5096 LOGD("LEAVE 0x%X", ret);
5100 int player_set_replaygain_enabled(player_h player, bool enabled)
5102 PLAYER_INSTANCE_CHECK(player);
5103 int ret = PLAYER_ERROR_NONE;
5104 muse_player_api_e api = MUSE_PLAYER_API_SET_REPLAYGAIN_ENABLED;
5105 player_cli_s *pc = (player_cli_s *) player;
5106 char *ret_buf = NULL;
5107 int val = (int)enabled;
5111 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5116 int player_is_replaygain_enabled(player_h player, bool *enabled)
5118 PLAYER_INSTANCE_CHECK(player);
5119 PLAYER_NULL_ARG_CHECK(enabled);
5120 int ret = PLAYER_ERROR_NONE;
5121 muse_player_api_e api = MUSE_PLAYER_API_IS_REPLAYGAIN_ENABLED;
5122 player_cli_s *pc = (player_cli_s *) player;
5123 char *ret_buf = NULL;
5128 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5129 if (ret == PLAYER_ERROR_NONE) {
5130 player_msg_get(val, ret_buf);
5131 *enabled = (bool) val;