2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
22 #include <tbm_bufmgr.h>
23 #include <tbm_surface.h>
24 #include <tbm_surface_internal.h>
27 #include <muse_core.h>
28 #include <muse_client.h>
29 #include <muse_player.h>
30 #include <muse_player_msg.h>
31 #include <sound_manager.h>
32 #include <sound_manager_internal.h>
33 #include <storage-internal.h>
34 #include <system_info.h>
35 #include "player_internal.h"
36 #include "player_private.h"
37 #include "player_msg.h"
39 #define INVALID_MUSE_TYPE_VALUE 0
40 #define MAX_S_PATH_LEN 32
41 #define PLAYER_FEATURE_SOUND_STREAM "http://tizen.org/feature/multimedia.player.stream_info"
42 #define PLAYER_FEATURE_OPENGL "http://tizen.org/feature/opengles.version.2_0"
43 #define PLAYER_FEATURE_SPHERICAL_VIDEO "http://tizen.org/feature/multimedia.player.spherical_video"
46 TIZEN_PROFILE_UNKNOWN = 0,
47 TIZEN_PROFILE_MOBILE = 0x1,
48 TIZEN_PROFILE_WEARABLE = 0x2,
49 TIZEN_PROFILE_TV = 0x4,
50 TIZEN_PROFILE_IVI = 0x8,
51 TIZEN_PROFILE_COMMON = 0x10,
55 tbm_fd tfd[MUSE_NUM_FD];
61 callback_cb_info_s *cb_info;
62 _player_recv_data *recv_data;
67 intptr_t remote_v_data;
71 } _media_pkt_fin_data;
73 static int _player_deinit_memory_buffer(player_cli_s * pc);
74 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data);
75 static bool _player_need_sync_context(int event_id);
76 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all);
77 #ifdef TIZEN_FEATURE_EVAS_RENDERER
78 typedef void (*player_retrieve_buffer_cb)(void *user_data);
79 static void __retrieve_buffer_cb(void *user_data);
80 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data);
81 static int __player_unset_retrieve_buffer_cb(player_h player);
83 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem);
86 * Internal Implementation
88 int _player_send_msg(muse_player_api_e api, player_cli_s *player, char* msg, tbm_fd tfd, char **retbuf)
90 int ret = PLAYER_ERROR_NONE;
92 int send_fd = INVALID_DEFAULT_VALUE;
93 int send_tfd[MUSE_NUM_FD];
94 int timeout = client_get_api_timeout(player, api);
96 memset(send_tfd, INVALID_DEFAULT_VALUE, sizeof(send_tfd));
98 if (player && CALLBACK_INFO(player)) {
99 send_fd = MSG_FD(player);
101 LOGE("can not access to cb_info");
102 return PLAYER_ERROR_INVALID_STATE;
105 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
106 LOGE("invalid socket fd %d", send_fd);
107 return PLAYER_ERROR_INVALID_OPERATION;
110 if (tfd != INVALID_DEFAULT_VALUE) {
112 send_len = muse_core_msg_send_fd(send_fd, send_tfd, msg);
114 send_len = muse_core_msg_send(send_fd, msg);
117 LOGE("sending message failed");
118 return PLAYER_ERROR_INVALID_OPERATION;
120 ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), retbuf, timeout);
126 int _player_send_msg_async(int send_fd, char* msg)
130 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
131 LOGE("invalid socket fd %d", send_fd);
132 return PLAYER_ERROR_INVALID_OPERATION;
135 send_len = muse_core_msg_send(send_fd, msg);
137 LOGE("sending message failed");
138 return PLAYER_ERROR_INVALID_OPERATION;
141 return PLAYER_ERROR_NONE;
144 static tizen_profile_t _get_tizen_profile()
147 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
149 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
152 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
153 switch (*profileName) {
156 profile = TIZEN_PROFILE_MOBILE;
160 profile = TIZEN_PROFILE_WEARABLE;
164 profile = TIZEN_PROFILE_TV;
168 profile = TIZEN_PROFILE_IVI;
170 default: // common or unknown ==> ALL ARE COMMON.
171 profile = TIZEN_PROFILE_COMMON;
178 static int _get_current_state(player_cli_s *pc, player_state_e *pstate)
180 PLAYER_INSTANCE_CHECK(pc);
181 PLAYER_NULL_ARG_CHECK(pstate);
182 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
183 int ret = PLAYER_ERROR_NONE;
184 int state = PLAYER_STATE_NONE;
185 char *ret_buf = NULL;
187 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
189 if (ret == PLAYER_ERROR_NONE) {
190 player_msg_get(state, ret_buf);
192 LOGD("current state %d", *pstate);
199 static bool _player_get_param_value(char* buf, ...)
201 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
204 int type = MUSE_TYPE_ANY;
205 char *param_name = NULL;
210 void *jobj = muse_core_msg_object_new(buf, NULL, &err);
213 LOGE("failed to get msg object. err:%d", err);
217 va_start(var_args, buf);
219 while ((type = va_arg(var_args, int)) != INVALID_MUSE_TYPE_VALUE) {
220 param_name = va_arg(var_args, char *);
223 case MUSE_TYPE_INT64:
224 case MUSE_TYPE_DOUBLE:
225 case MUSE_TYPE_STRING:
226 case MUSE_TYPE_POINTER:
227 value = va_arg(var_args, void *);
229 if (!muse_core_msg_object_get_value(param_name, jobj, type, value)) {
231 LOGE("failed to get %s value", param_name);
235 LOGE("Unexpected type");
241 muse_core_msg_object_free(jobj);
247 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
249 int ret = MEDIA_PACKET_FINALIZE;
250 muse_player_api_e api = MUSE_PLAYER_API_RETURN_VIDEO_DATA;
251 _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
253 char *snd_msg = NULL;
257 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
261 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
262 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
266 if (!fin_data->use_tsurf_pool) {
267 tbm_surface_h tsurf = NULL;
268 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
269 LOGE("media_packet_get_tbm_surface failed");
270 /* continue the remained job */
273 /* LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf); */
274 tbm_surface_destroy(tsurf);
278 /* Do not destroy tbm surface here to reuse during playback *
279 * they will be destroyed at player_unprepare() or player_destroy(). *
280 * ref: __player_remove_tsurf_list() */
282 tbm_surface_h tsurf = NULL;
284 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
285 /* LOGD("tsurf set to null %p", tsurf); */
290 if (muse_core_fd_is_valid(fin_data->fd)) {
291 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
292 LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
296 v_data = fin_data->remote_v_data;
297 snd_msg = muse_core_msg_new(api, MUSE_TYPE_POINTER, "v_data", v_data, 0);
298 snd_len = muse_core_msg_send(fin_data->fd, snd_msg);
299 muse_core_msg_free(snd_msg);
302 LOGE("[fd:%d] fail to send msg.", fin_data->fd);
304 LOGE("[fd:%d] is invalid.", fin_data->fd);
316 static bool _player_check_network_availability(void)
318 #define _FEATURE_NAME_WIFI "http://tizen.org/feature/network.wifi"
319 #define _FEATURE_NAME_TELEPHONY "http://tizen.org/feature/network.telephony"
320 #define _FEATURE_NAME_ETHERNET "http://tizen.org/feature/network.ethernet"
321 bool enabled = FALSE;
322 bool supported = FALSE;
324 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
325 LOGI("wifi status = %d", enabled);
329 LOGE("SYSTEM_INFO_ERROR");
332 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
333 LOGI("telephony status = %d", enabled);
337 LOGE("SYSTEM_INFO_ERROR");
340 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
341 LOGI("ethernet status = %d", enabled);
345 LOGE("SYSTEM_INFO_ERROR");
354 static void *_get_mem(player_cli_s * player, int size)
356 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
358 mem->data = g_new(void, size);
359 mem->next = player->head;
366 static void _del_mem(player_cli_s * player)
369 while (player->head) {
370 mem = player->head->next;
371 g_free(player->head->data);
372 g_free(player->head);
377 static int player_recv_msg(callback_cb_info_s * cb_info, tbm_fd *tfd)
380 msg_buff_s *buff = &cb_info->buff;
382 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
383 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(*tfd) * MUSE_NUM_FD);
384 recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, tfd);
386 LOGE("failed to recv msg %d", recvLen);
390 /* check the first msg */
391 if (buff->part_of_msg && buff->recvMsg[0] != '{')
393 gchar *tmp = strndup(buff->recvMsg, recvLen);
395 LOGE("failed to copy msg.");
399 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
402 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
403 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
404 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
405 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
406 if (!buff->recvMsg) {
407 LOGE("failed renew buffer.");
412 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
414 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
415 recvLen += strlen(buff->part_of_msg);
417 free(buff->part_of_msg);
418 buff->part_of_msg = NULL;
423 /* check the last msg */
424 if (buff->recvMsg[recvLen-1] != '}') {
425 char *part_pos = strrchr(buff->recvMsg, '}');
426 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
429 buff->part_of_msg = strndup(part_pos+1, part_len);
430 if (!buff->part_of_msg) {
431 LOGE("failed to alloc buffer for part of msg.");
434 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
442 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
444 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
445 cb_info->user_cb[event] = NULL;
446 cb_info->user_data[event] = NULL;
450 /* Notice : have to be called via API to avoid deadlock
451 * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
453 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
458 LOGE("cb_info is NULL, event: %d", event);
462 lock = (g_thread_self() != cb_info->event_queue.thread);
465 g_mutex_lock(&cb_info->event_queue.mutex);
467 if (_player_need_sync_context(event))
468 _player_remove_idle_event(cb_info, event, false);
470 set_null_user_cb(cb_info, event);
473 g_mutex_unlock(&cb_info->event_queue.mutex);
476 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
478 PLAYER_INSTANCE_CHECK(player);
479 PLAYER_NULL_ARG_CHECK(callback);
480 int ret = PLAYER_ERROR_NONE;
481 player_cli_s *pc = (player_cli_s *) player;
482 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
485 if (MUSE_PLAYER_EVENT_TYPE_BUFFERING == type) {
486 if (!_player_check_network_availability())
487 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
490 if (!CALLBACK_INFO(pc))
491 return PLAYER_ERROR_INVALID_OPERATION;
493 LOGI("Event type : %d ", type);
494 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
496 if (ret == PLAYER_ERROR_NONE) {
497 pc->cb_info->user_cb[type] = callback;
498 pc->cb_info->user_data[type] = user_data;
503 static int __unset_callback(muse_player_event_e type, player_h player)
505 PLAYER_INSTANCE_CHECK(player);
506 int ret = PLAYER_ERROR_NONE;
507 player_cli_s *pc = (player_cli_s *) player;
508 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
511 LOGI("Event type : %d ", type);
513 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
514 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
516 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
521 static void __prepare_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
523 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
525 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
527 set_null_user_cb(cb_info, ev);
530 static void __complete_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
532 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
533 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
536 #ifdef TIZEN_FEATURE_EVAS_RENDERER
537 static void __retrieve_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
540 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
541 ((player_retrieve_buffer_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
545 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
548 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
550 if (player_msg_get(code, recv_data->buffer))
551 ((player_interrupted_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
554 static void __error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
557 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
559 if (player_msg_get(code, recv_data->buffer)) {
560 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
561 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
562 LOGW("failed to pause, so prepare cb will be released soon");
563 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
566 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
570 static void __disconnected_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
572 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
574 ((player_error_cb) cb_info->user_cb[ev]) (PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
577 static void __buffering_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
580 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
582 if (player_msg_get(percent, recv_data->buffer))
583 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
586 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
589 char text[MUSE_URI_MAX_LENGTH] = { 0, };
590 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
593 ret = _player_get_param_value(recv_data->buffer,
594 MUSE_TYPE_INT, "duration", (void *)&duration,
595 MUSE_TYPE_STRING, "text", (void *)text,
596 INVALID_MUSE_TYPE_VALUE);
598 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
601 static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
603 unsigned char *data = NULL;
606 unsigned int size = 0;
608 tbm_bo_handle thandle;
609 int key = INVALID_DEFAULT_VALUE;
611 get_ret = _player_get_param_value(recv_data->buffer,
612 MUSE_TYPE_INT, "width", (void *)&width,
613 MUSE_TYPE_INT, "height", (void *)&height,
614 MUSE_TYPE_INT, "size", (void *)&size,
615 MUSE_TYPE_INT, "key", (void *)&key,
616 INVALID_MUSE_TYPE_VALUE);
618 if (recv_data->tfd[0] < 0) {
619 LOGE("There is no valid tbm_fd");
623 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
625 LOGE("TBM get error : bo is NULL");
628 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
629 if (thandle.ptr == NULL) {
630 LOGE("TBM get error : handle pointer is NULL");
633 data = g_new(unsigned char, size);
635 memcpy(data, thandle.ptr, size);
636 ((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]);
639 LOGE("g_new failure");
645 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
646 close(recv_data->tfd[0]);
647 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
653 if (key > INVALID_DEFAULT_VALUE) {
654 LOGD("send msg to release buffer. key:%d", key);
655 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
658 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
661 static void __seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
663 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
664 #ifdef TIZEN_FEATURE_EVAS_RENDERER
665 void *dl_handle = NULL;
666 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
668 g_mutex_lock(&cb_info->seek_cb_mutex);
669 if (cb_info->user_cb[ev] && cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_NONE) {
670 #ifdef TIZEN_FEATURE_EVAS_RENDERER
671 if (cb_info->evas_info && cb_info->evas_info->support_video) {
672 if (cb_info->evas_info->handle && cb_info->evas_info->visible != EVAS_VISIBLE_FALSE) {
673 dl_handle = dlopen(PATH_DISP_LIB, RTLD_LAZY);
675 PLAYER_DISP_DLSYM(dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
676 int ret = p_disp_set_evas_display_visible(cb_info->evas_info->handle, true);
678 if (ret != MM_ERROR_NONE)
679 LOGW("failed to set visible at evas 0x%x", ret);
681 cb_info->evas_info->visible = EVAS_VISIBLE_TRUE;
683 LOGW("not support video rendering");
688 LOGD("call seek cb");
689 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
690 set_null_user_cb(cb_info, ev);
692 LOGW("ignored. seek cb %p", cb_info->user_cb[ev]);
694 g_mutex_unlock(&cb_info->seek_cb_mutex);
697 static void __player_remove_tsurf_list(player_cli_s * pc)
701 g_mutex_lock(&pc->cb_info->data_mutex);
702 if (pc->cb_info->tsurf_list) {
703 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
705 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
706 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
708 LOGD("%p will be removed", tmp);
711 tbm_surface_destroy(tmp->tsurf);
717 g_list_free(pc->cb_info->tsurf_list);
718 pc->cb_info->tsurf_list = NULL;
720 g_mutex_unlock(&pc->cb_info->data_mutex);
724 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, int height, int width)
728 g_mutex_lock(&cb_info->data_mutex);
729 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
730 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
731 if (tmp && key && (tmp->key[0] == key[0])) {
732 LOGD("found tsurf_data of tbm_key %d", key[0]);
734 /* need to check tsuf info to support DRC */
735 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
736 (tbm_surface_get_width(tmp->tsurf) != width)) {
738 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
739 LOGW("tsurf info is changed. need to create new tsurf.");
740 tbm_surface_destroy(tmp->tsurf);
743 g_mutex_unlock(&cb_info->data_mutex);
747 g_mutex_unlock(&cb_info->data_mutex);
752 g_mutex_unlock(&cb_info->data_mutex);
756 static media_packet_rotate_method_e __convert_packet_orient_info(int orientation)
758 media_packet_rotate_method_e rotate = MEDIA_PACKET_ROTATE_IDENTITY;
760 switch (orientation) {
762 rotate = MEDIA_PACKET_ROTATE_90;
765 rotate = MEDIA_PACKET_ROTATE_180;
768 rotate = MEDIA_PACKET_ROTATE_270;
771 rotate = MEDIA_PACKET_ROTATE_IDENTITY;
778 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
780 tbm_bo bo[4] = { NULL, };
781 int key[4] = { INVALID_DEFAULT_VALUE, };
782 tbm_surface_info_s sinfo;
783 char *surface_info = (char *)&sinfo;
784 media_packet_h pkt = NULL;
785 tbm_surface_h tsurf = NULL;
786 player_tsurf_info_t *tsurf_data = NULL;
788 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
789 bool make_pkt_fmt = false;
790 int ret = MEDIA_FORMAT_ERROR_NONE;
791 _media_pkt_fin_data *fin_data = NULL;
794 int i = 0, orientation = 0;
795 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
797 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
799 !muse_core_msg_object_get_value("key[0]", jobj, MUSE_TYPE_ANY, &key[0]) ||
800 !muse_core_msg_object_get_value("key[1]", jobj, MUSE_TYPE_ANY, &key[1]) ||
801 !muse_core_msg_object_get_value("key[2]", jobj, MUSE_TYPE_ANY, &key[2]) ||
802 !muse_core_msg_object_get_value("key[3]", jobj, MUSE_TYPE_ANY, &key[3]) ||
803 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
804 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
805 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
806 !muse_core_msg_object_get_value("orientation", jobj, MUSE_TYPE_INT, &orientation) ||
807 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
809 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
811 muse_core_msg_object_free(jobj);
814 muse_core_msg_object_free(jobj);
816 LOGD("width %d, height %d", sinfo.width, sinfo.height);
819 LOGE("cb_info is null");
823 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
824 /* send msg to release v_data. */
825 LOGE("_video_decoded_cb is not set");
829 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
830 LOGE("tbm fd is invalid");
834 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
836 for (i = 0; i < MUSE_NUM_FD; i++) {
837 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
841 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
844 tsurf_data = g_new(player_tsurf_info_t, 1);
846 LOGE("failed to alloc tsurf info");
849 memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
851 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
853 LOGE("failed to create tbm surface");
857 memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
858 tsurf_data->tsurf = tsurf;
859 if (cb_info->use_tsurf_pool) {
860 g_mutex_lock(&cb_info->data_mutex);
861 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
862 LOGD("key %d is added to the pool", key[0]);
863 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
864 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
865 g_mutex_unlock(&cb_info->data_mutex);
868 if (tsurf_data->tsurf) {
869 tsurf = tsurf_data->tsurf;
871 LOGE("tsurf_data->tsurf is null (never enter here)");
876 /* check media packet format */
877 if (cb_info->pkt_fmt) {
878 int pkt_fmt_width = 0;
879 int pkt_fmt_height = 0;
880 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
882 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
883 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
884 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);
885 media_format_unref(cb_info->pkt_fmt);
886 cb_info->pkt_fmt = NULL;
892 /* create packet format */
894 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
895 ret = media_format_create(&cb_info->pkt_fmt);
896 if (ret == MEDIA_FORMAT_ERROR_NONE) {
897 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
898 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
899 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
900 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
902 LOGE("media_format_create failed");
906 fin_data = g_new0(_media_pkt_fin_data, 1);
908 LOGE("failed to alloc fin_data");
911 fin_data->remote_v_data = v_data;
912 fin_data->fd = cb_info->fd;
913 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
915 /* Keep the fd id to check validation when the pkt is destroyed. */
916 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
918 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
919 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
920 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
925 ret = media_packet_set_pts(pkt, (uint64_t) pts);
926 if (ret != MEDIA_PACKET_ERROR_NONE)
927 LOGE("media_packet_set_pts failed");
930 ret = media_packet_set_rotate_method(pkt, __convert_packet_orient_info(orientation));
931 if (ret != MEDIA_PACKET_ERROR_NONE)
932 LOGE("media_packet_set_rotate_method failed");
934 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
935 /* call media packet callback */
936 ((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]);
938 LOGE("_video_decoded_cb is not set");
939 media_packet_destroy(pkt);
942 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
943 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
944 close(recv_data->tfd[i]);
947 for (i = 0; i < bo_num; i++) {
952 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
957 media_packet_destroy(pkt);
962 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
963 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
964 close(recv_data->tfd[i]);
967 for (i = 0; i < bo_num; i++) {
971 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
973 if (cb_info && v_data)
974 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, MUSE_TYPE_POINTER, "v_data", v_data);
979 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
982 tbm_bo_handle thandle;
983 int key = INVALID_DEFAULT_VALUE;
984 player_audio_raw_data_s audio;
986 if (!player_msg_get(key, recv_data->buffer)) {
987 LOGE("failed to get key value from msg.");
991 if (recv_data->tfd[0] < 0) {
992 LOGE("failed to get tbm_fd(key:%d)", key);
996 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
998 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
1002 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
1003 if (thandle.ptr == NULL) {
1004 LOGE("TBM get error : handle pointer is NULL");
1008 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
1009 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
1011 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
1012 ((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]);
1016 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
1017 close(recv_data->tfd[0]);
1018 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1024 if (key > INVALID_DEFAULT_VALUE) {
1025 /* LOGD("send msg to release buffer. key:%d", key); */
1026 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
1030 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1034 static void __pd_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1037 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
1039 if (player_msg_get(type, recv_data->buffer))
1040 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
1043 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1047 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1051 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1055 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1057 /* player_media_stream_buffer_status_e status; */
1060 if (player_msg_get(status, recv_data->buffer)) {
1061 ((player_media_stream_buffer_status_cb)
1062 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]);
1066 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1068 /* player_media_stream_buffer_status_e status; */
1071 if (player_msg_get(status, recv_data->buffer)) {
1072 ((player_media_stream_buffer_status_cb)
1073 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
1074 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
1079 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1081 /* player_media_stream_buffer_status_e status; */
1083 unsigned long long bytes;
1086 ret = _player_get_param_value(recv_data->buffer,
1087 MUSE_TYPE_INT, "status", (void *)&status,
1088 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1089 INVALID_MUSE_TYPE_VALUE);
1091 ((player_media_stream_buffer_status_cb_ex)
1092 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
1093 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
1097 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1099 /* player_media_stream_buffer_status_e status; */
1101 unsigned long long bytes;
1104 ret = _player_get_param_value(recv_data->buffer,
1105 MUSE_TYPE_INT, "status", (void *)&status,
1106 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1107 INVALID_MUSE_TYPE_VALUE);
1109 ((player_media_stream_buffer_status_cb_ex)
1110 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
1111 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
1116 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1118 unsigned long long offset;
1120 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1121 ((player_media_stream_seek_cb)
1122 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
1123 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
1127 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1129 unsigned long long offset;
1131 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1132 ((player_media_stream_seek_cb)
1133 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
1134 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1138 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1144 bool ret_val = TRUE;
1145 ret_val = _player_get_param_value(recv_data->buffer,
1146 MUSE_TYPE_INT, "width", (void *)&width,
1147 MUSE_TYPE_INT, "height", (void *)&height,
1148 MUSE_TYPE_INT, "fps", (void *)&fps,
1149 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
1150 INVALID_MUSE_TYPE_VALUE);
1152 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1153 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1157 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, _player_recv_data *recv_data) = {
1158 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1159 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1160 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1161 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1162 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1163 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1164 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1165 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1166 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1167 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
1168 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1169 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
1170 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1171 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1172 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1173 #ifdef _PLAYER_FOR_PRODUCT
1174 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1175 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1177 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1178 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1179 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1180 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1181 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1182 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1183 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1184 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1185 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1186 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1188 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1191 gboolean _player_event_job_function(void *user_data)
1193 _player_cb_data *data = (_player_cb_data *)user_data;
1194 muse_player_event_e ev;
1197 LOGE("data is null");
1201 LOGD("enter ev:%d", data->int_data);
1203 g_mutex_lock(&data->event_mutex);
1204 ev = data->int_data;
1206 if (data->cb_info == NULL) {
1207 /* tried to remove before at _player_remove_idle_event */
1208 LOGW("cb_info is NULL. event %d", data->int_data);
1212 /* remove event from list */
1213 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1214 if (data->cb_info->event_queue.idle_ev_list) {
1215 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1216 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1218 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1220 if (data->cb_info->user_cb[ev])
1221 _user_callbacks[ev] (data->cb_info, data->recv_data);
1223 LOGW("user callback is unset. type : %d", ev);
1226 /* unlock and release event */
1227 g_mutex_unlock(&data->event_mutex);
1228 g_mutex_clear(&data->event_mutex);
1230 if (data->recv_data) {
1231 g_free(data->recv_data->buffer);
1232 g_free(data->recv_data);
1236 return FALSE; /* remove from the event list */
1239 static bool _player_need_sync_context(int event_id)
1241 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1242 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1243 (event_id == MUSE_PLAYER_EVENT_TYPE_PD) ||
1244 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1245 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1246 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1247 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1248 LOGD("%d callback will be issued in the mainloop.", event_id);
1255 static void *_player_event_queue_loop(void *param)
1258 LOGE("NULL parameter");
1261 callback_cb_info_s *cb_info = param;
1262 player_event_queue *ev = &cb_info->event_queue;
1263 _player_cb_data *event_data = NULL;
1265 g_mutex_lock(&ev->mutex);
1266 while (ev->running) {
1267 g_mutex_lock(&ev->qlock);
1268 if (g_queue_is_empty(ev->queue)) {
1269 g_mutex_unlock(&ev->qlock);
1270 g_cond_wait(&ev->cond, &ev->mutex);
1274 g_mutex_unlock(&ev->qlock);
1277 g_mutex_lock(&ev->qlock);
1278 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1279 g_mutex_unlock(&ev->qlock);
1281 muse_player_event_e event_type = ((_player_cb_data *)event_data)->int_data;
1283 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1284 g_mutex_lock(&cb_info->seek_cb_mutex);
1285 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1286 /* push event into queue again. */
1287 _player_event_queue_add(ev, event_data);
1288 g_mutex_unlock(&cb_info->seek_cb_mutex);
1291 g_mutex_unlock(&cb_info->seek_cb_mutex);
1294 if (_player_need_sync_context(event_data->int_data)) {
1295 if (cb_info->user_cb[event_data->int_data] &&
1296 _user_callbacks[event_data->int_data]) {
1297 g_mutex_lock(&ev->idle_ev_mutex);
1298 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1299 g_mutex_unlock(&ev->idle_ev_mutex);
1301 LOGD("add ev %d to main loop", event_data->int_data);
1303 g_idle_add_full(G_PRIORITY_DEFAULT,
1304 (GSourceFunc)_player_event_job_function,
1305 (gpointer)event_data,
1308 LOGW("there is no registered cb for ev:%d", event_data->int_data);
1309 if (event_data->recv_data) {
1310 g_free(event_data->recv_data->buffer);
1311 g_free(event_data->recv_data);
1316 _player_event_job_function(event_data);
1323 g_mutex_unlock(&ev->mutex);
1324 LOGI("Exit event loop");
1328 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1330 g_return_val_if_fail(cb_info, FALSE);
1331 player_event_queue *ev = &cb_info->event_queue;
1333 ev->queue = g_queue_new();
1334 g_return_val_if_fail(ev->queue, FALSE);
1335 g_mutex_init(&ev->qlock);
1337 g_mutex_init(&ev->mutex);
1338 g_cond_init(&ev->cond);
1341 g_mutex_init(&ev->idle_ev_mutex);
1343 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1344 g_return_val_if_fail(ev->thread, FALSE);
1345 LOGI("event queue thread %p", ev->thread);
1351 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1353 g_return_if_fail(cb_info);
1354 player_event_queue *ev = &cb_info->event_queue;
1355 _player_cb_data *event_data = NULL;
1358 g_mutex_lock(&ev->idle_ev_mutex);
1360 if (ev->idle_ev_list == NULL) {
1361 LOGD("No idle event is remained.");
1362 g_mutex_unlock(&ev->idle_ev_mutex);
1366 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1368 list = ev->idle_ev_list;
1370 event_data = list->data;
1371 list = g_list_next(list);
1374 LOGW("Fail to remove idle event. The data is NULL");
1378 if (g_mutex_trylock(&event_data->event_mutex)) {
1380 gboolean ret = FALSE;
1381 if (remove_all || (event_data->int_data == event_type)) {
1383 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1385 ret = g_idle_remove_by_data(event_data);
1387 /* will be handled at _player_event_job_function() as an exception */
1388 event_data->cb_info = NULL;
1389 LOGW("failed to remove, idle callback will be called later");
1392 /* set cb to null */
1393 set_null_user_cb(cb_info, event_data->int_data);
1394 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1396 g_mutex_unlock(&event_data->event_mutex);
1399 g_mutex_clear(&event_data->event_mutex);
1400 if (event_data->recv_data) {
1401 g_free(event_data->recv_data->buffer);
1402 g_free(event_data->recv_data);
1406 LOGD("remove idle event done");
1407 } /* else : will be handled if the cb is called. */
1409 g_mutex_unlock(&event_data->event_mutex);
1412 LOGW("event(%d) lock failed. it's being called...", event_data->int_data);
1415 /* continue: keep checking next event_data */
1419 g_list_free(ev->idle_ev_list);
1420 ev->idle_ev_list = NULL;
1423 g_mutex_unlock(&ev->idle_ev_mutex);
1429 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1431 g_return_if_fail(cb_info);
1432 player_event_queue *ev = &cb_info->event_queue;
1433 _player_cb_data *event_data;
1435 LOGI("event queue thread %p", ev->thread);
1437 g_mutex_lock(&ev->mutex);
1438 ev->running = FALSE;
1439 g_cond_broadcast(&ev->cond);
1440 g_mutex_unlock(&ev->mutex);
1442 g_thread_join(ev->thread);
1445 while (!g_queue_is_empty(ev->queue)) {
1446 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1448 g_free(event_data->recv_data->buffer);
1449 g_free(event_data->recv_data);
1453 g_queue_free(ev->queue);
1454 g_mutex_clear(&ev->qlock);
1455 g_mutex_clear(&ev->mutex);
1456 g_cond_clear(&ev->cond);
1457 g_mutex_clear(&ev->idle_ev_mutex);
1460 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1464 g_mutex_lock(&ev_queue->qlock);
1466 item = g_queue_peek_head_link(ev_queue->queue);
1468 GList *next = item->next;
1469 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1471 if (cb_data && cb_data->int_data == ev) {
1472 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1473 g_free(cb_data->recv_data->buffer);
1474 g_free(cb_data->recv_data);
1477 g_queue_delete_link(ev_queue->queue, item);
1481 g_mutex_unlock(&ev_queue->qlock);
1484 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1487 g_mutex_lock(&ev->qlock);
1488 g_queue_push_tail(ev->queue, (gpointer) data);
1489 g_mutex_unlock(&ev->qlock);
1490 g_cond_signal(&ev->cond);
1494 static bool _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1496 /* LOGD("get event %d", event); */
1498 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1499 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1500 _player_cb_data *data = NULL;
1501 data = g_new(_player_cb_data, 1);
1503 LOGE("fail to alloc mem");
1506 data->int_data = (int)event;
1507 data->cb_info = cb_info;
1508 data->recv_data = recv_data;
1509 g_mutex_init(&data->event_mutex);
1510 _player_event_queue_add(&cb_info->event_queue, data);
1516 LOGE("failed to add event to queue");
1520 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1522 ret_msg_s *msg = NULL;
1523 ret_msg_s *last = cb_info->buff.retMsgHead;
1525 msg = g_new(ret_msg_s, 1);
1528 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1531 cb_info->buff.retMsgHead = msg;
1538 LOGE("g_new failure");
1541 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1543 ret_msg_s *msg = cb_info->buff.retMsgHead;
1544 ret_msg_s *prev = NULL;
1546 if (msg->api == api) {
1548 cb_info->buff.retMsgHead = msg->next;
1550 prev->next = msg->next;
1559 static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
1561 ret_msg_s *msg = cb_info->buff.retMsgHead;
1562 ret_msg_s *prev = NULL;
1566 LOGI("Remove %s", prev->msg);
1573 static void _notify_disconnected(callback_cb_info_s * cb_info)
1575 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1576 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1579 if (_user_callbacks[event]) {
1580 _player_cb_data *data = NULL;
1581 data = g_new(_player_cb_data, 1);
1583 LOGE("fail to alloc mem");
1586 data->int_data = (int)event;
1587 data->cb_info = cb_info;
1588 data->recv_data = NULL;
1589 g_mutex_init(&data->event_mutex);
1590 _player_event_queue_add(&cb_info->event_queue, data);
1594 static void *client_cb_handler(gpointer data)
1600 callback_cb_info_s *cb_info = data;
1601 char *recvMsg = NULL;
1602 muse_core_msg_parse_err_e err;
1603 tbm_fd tfd[MUSE_NUM_FD];
1605 while (g_atomic_int_get(&cb_info->running)) {
1607 err = MUSE_MSG_PARSE_ERROR_NONE;
1609 len = player_recv_msg(cb_info, tfd);
1613 recvMsg = cb_info->buff.recvMsg;
1614 recvMsg[len] = '\0';
1618 while (offset < len) {
1619 api = MUSE_PLAYER_API_MAX;
1620 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1623 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1625 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1626 if (api < MUSE_PLAYER_API_MAX) {
1627 g_mutex_lock(&cb_info->player_mutex);
1628 cb_info->buff.recved++;
1629 _add_ret_msg(api, cb_info, offset, parse_len);
1630 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1631 LOGD("get tbm fd for album art.");
1632 cb_info->tfd = tfd[0];
1634 g_cond_signal(&cb_info->player_cond[api]);
1635 g_mutex_unlock(&cb_info->player_mutex);
1636 if (api == MUSE_PLAYER_API_DESTROY)
1637 g_atomic_int_set(&cb_info->running, 0);
1638 } else if (api == MUSE_PLAYER_CB_EVENT) {
1640 _player_recv_data *recv_data = NULL;
1641 g_mutex_lock(&cb_info->player_mutex);
1642 recv_data = g_new0(_player_recv_data, 1);
1643 if (recv_data != NULL) {
1644 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1645 recv_data->buffer = strndup(recvMsg+offset, parse_len);
1647 LOGE("failed to alloc recv_data.");
1648 g_mutex_unlock(&cb_info->player_mutex);
1649 muse_core_msg_object_free(jobj);
1652 g_mutex_unlock(&cb_info->player_mutex);
1653 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1654 !_user_callback_handler(cb_info, event, recv_data)) {
1655 LOGE("failed to get value or add event to the queue.");
1657 g_free(recv_data->buffer);
1661 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1662 g_mutex_lock(&cb_info->player_mutex);
1663 cb_info->buff.recved++;
1664 g_cond_signal(&cb_info->server_ack_cond);
1665 g_mutex_unlock(&cb_info->player_mutex);
1668 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1670 muse_core_msg_object_free(jobj);
1672 LOGE("Failed to get msg obj. err:%d", err);
1675 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1678 offset += parse_len;
1679 parse_len = len - offset;
1682 if (g_atomic_int_get(&cb_info->running))
1683 _notify_disconnected(cb_info);
1684 LOGD("client cb exit");
1689 static callback_cb_info_s *callback_new(gint sockfd)
1691 callback_cb_info_s *cb_info;
1695 g_return_val_if_fail(sockfd > 0, NULL);
1697 cb_info = g_new(callback_cb_info_s, 1);
1700 memset(cb_info, 0, sizeof(callback_cb_info_s));
1702 g_mutex_init(&cb_info->player_mutex);
1703 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1704 g_cond_init(&cb_info->player_cond[i]);
1705 g_cond_init(&cb_info->server_ack_cond);
1707 g_mutex_init(&cb_info->data_mutex);
1708 g_mutex_init(&cb_info->seek_cb_mutex);
1710 buff = &cb_info->buff;
1711 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1712 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1714 buff->retMsgHead = NULL;
1715 buff->part_of_msg = NULL;
1717 g_atomic_int_set(&cb_info->running, 1);
1718 cb_info->fd = sockfd;
1719 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1720 cb_info->tfd = INVALID_DEFAULT_VALUE;
1725 static void callback_destroy(callback_cb_info_s * cb_info)
1728 g_return_if_fail(cb_info);
1730 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1731 muse_client_close(cb_info->fd);
1732 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1733 muse_client_close(cb_info->data_fd);
1735 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1737 g_thread_join(cb_info->thread);
1738 cb_info->thread = NULL;
1740 LOGI("%p Callback destroyed", cb_info);
1742 g_mutex_clear(&cb_info->player_mutex);
1743 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1744 g_cond_clear(&cb_info->player_cond[i]);
1745 g_cond_clear(&cb_info->server_ack_cond);
1747 g_mutex_clear(&cb_info->data_mutex);
1748 g_mutex_clear(&cb_info->seek_cb_mutex);
1750 g_free(cb_info->buff.recvMsg);
1751 _remove_all_ret_msg(cb_info);
1752 if (cb_info->buff.part_of_msg)
1753 g_free(cb_info->buff.part_of_msg);
1757 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1762 case MUSE_PLAYER_API_PREPARE:
1763 case MUSE_PLAYER_API_PREPARE_ASYNC:
1764 case MUSE_PLAYER_API_UNPREPARE:
1765 case MUSE_PLAYER_API_START:
1766 case MUSE_PLAYER_API_STOP:
1767 case MUSE_PLAYER_API_PAUSE:
1768 timeout += SERVER_TIMEOUT(pc);
1771 /* check prepare async is done */
1772 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1773 timeout += SERVER_TIMEOUT(pc);
1776 timeout += CALLBACK_TIME_OUT;
1777 return timeout; /* ms */
1780 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1782 int ret = PLAYER_ERROR_NONE;
1783 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1784 msg_buff_s *buff = &cb_info->buff;
1785 ret_msg_s *msg = NULL;
1787 g_mutex_lock(&cb_info->player_mutex);
1789 msg = _get_ret_msg(api, cb_info);
1791 if (!buff->recved || !msg) {
1792 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1793 LOGW("api %d return msg does not received %dms", api, time_out);
1794 ret = PLAYER_ERROR_INVALID_OPERATION;
1799 msg = _get_ret_msg(api, cb_info);
1801 *ret_buf = msg->msg;
1804 if (!player_msg_get(ret, *ret_buf))
1805 ret = PLAYER_ERROR_INVALID_OPERATION;
1807 LOGE("api %d is the spurious wakeup", api);
1811 g_mutex_unlock(&cb_info->player_mutex);
1815 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1817 int ret = PLAYER_ERROR_NONE;
1818 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1819 msg_buff_s *buff = &cb_info->buff;
1821 g_mutex_lock(&cb_info->player_mutex);
1823 if (!buff->recved) {
1824 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1825 LOGW("server ack msg does not received %dms", time_out);
1827 ret = PLAYER_ERROR_INVALID_OPERATION;
1829 LOGD("Another msg is received, continue create handle");
1830 g_mutex_unlock(&cb_info->player_mutex);
1836 g_mutex_unlock(&cb_info->player_mutex);
1843 * Public Implementation
1846 int player_create(player_h * player)
1848 PLAYER_INSTANCE_CHECK(player);
1850 int ret = PLAYER_ERROR_NONE;
1851 int sock_fd = INVALID_DEFAULT_VALUE;
1854 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1855 muse_core_api_module_e module = MUSE_PLAYER;
1856 player_cli_s *pc = NULL;
1857 char *ret_buf = NULL;
1858 int retry_count = CONNECTION_RETRY;
1863 pc = g_new0(player_cli_s, 1);
1865 return PLAYER_ERROR_OUT_OF_MEMORY;
1867 while (--retry_count) {
1868 ret = PLAYER_ERROR_NONE;
1869 sock_fd = muse_client_new();
1870 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1871 LOGE("connection failure %d", errno);
1872 ret = PLAYER_ERROR_INVALID_OPERATION;
1874 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1878 PLAYER_SEND_MSG_ASYNC(api, sock_fd, ret,
1879 MUSE_TYPE_INT, "module", module,
1880 MUSE_TYPE_INT, "pid", pid);
1881 if (ret == PLAYER_ERROR_INVALID_OPERATION)
1884 pc->cb_info = callback_new(sock_fd);
1886 LOGE("fail to create callback");
1887 ret = PLAYER_ERROR_INVALID_OPERATION;
1891 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1892 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1898 if (!_player_event_queue_new(pc->cb_info)) {
1899 LOGE("fail to create event queue");
1900 ret = PLAYER_ERROR_INVALID_OPERATION;
1904 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1905 if (ret == PLAYER_ERROR_NONE) {
1906 intptr_t module_addr = 0;
1907 *player = (player_h) pc;
1908 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1909 pc->cb_info->data_fd = muse_client_new_data_ch();
1910 if (!muse_core_fd_is_valid(pc->cb_info->data_fd)) {
1911 LOGE("Failed to get data_fd");
1912 ret = PLAYER_ERROR_INVALID_OPERATION;
1916 /* share the module addr info to the data_fd */
1917 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_CREATE, pc->cb_info->data_fd, ret,
1918 MUSE_TYPE_POINTER, "module_addr", module_addr);
1919 if (ret != PLAYER_ERROR_NONE) {
1920 LOGE("Failed to send module address to the data fd");
1923 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1925 ret = PLAYER_ERROR_INVALID_OPERATION;
1928 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1932 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1933 pc->cb_info->evas_info = g_new0(player_evas_info_s, 1);
1934 if (pc->cb_info->evas_info == NULL) {
1935 ret = PLAYER_ERROR_OUT_OF_MEMORY;
1938 EVAS_INFO(pc)->visible = EVAS_VISIBLE_NONE;
1940 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1941 pc->push_media_stream = FALSE;
1942 pc->support_video = FALSE;
1943 EVAS_INFO(pc)->support_video = FALSE;
1944 pc->is_audio_only = FALSE;
1946 PLAYER_DISP_DLOPEN(pc); /* update supported_video */
1950 LOGD("LEAVE 0x%X", ret);
1954 if (pc && pc->cb_info) {
1955 if (pc->cb_info->event_queue.running)
1956 _player_event_queue_destroy(pc->cb_info);
1957 callback_destroy(pc->cb_info);
1959 } else if (sock_fd > INVALID_DEFAULT_VALUE) {
1960 muse_client_close(sock_fd);
1962 sock_fd = INVALID_DEFAULT_VALUE;
1965 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1973 LOGD("LEAVE 0x%X", ret);
1977 int player_destroy(player_h player)
1979 PLAYER_INSTANCE_CHECK(player);
1981 int ret = PLAYER_ERROR_NONE;
1982 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1983 player_cli_s *pc = (player_cli_s *) player;
1984 char *ret_buf = NULL;
1986 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1987 int (*p_disp_destroy_evas_display)(void **) = NULL;
1991 /* clear cb and release mem */
1992 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1993 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1994 _player_release_internal_memory(pc, true);
1996 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1997 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
1998 if (EVAS_HANDLE(pc)) {
1999 player_unset_media_packet_video_frame_decoded_cb(player);
2000 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2001 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2002 LOGW("fail to unset evas client");
2003 __player_unset_retrieve_buffer_cb(player);
2004 g_free(pc->cb_info->evas_info);
2009 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2011 if (CALLBACK_INFO(pc)) {
2012 __player_remove_tsurf_list(pc);
2013 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
2014 _player_event_queue_destroy(CALLBACK_INFO(pc));
2015 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
2017 callback_destroy(CALLBACK_INFO(pc));
2021 PLAYER_DISP_DLCLOSE(pc->dl_handle); /* update supported_video */
2028 LOGD("LEAVE 0x%X", ret);
2032 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
2034 PLAYER_INSTANCE_CHECK(player);
2035 int ret = PLAYER_ERROR_NONE;
2036 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
2037 player_cli_s *pc = (player_cli_s *) player;
2038 char *ret_buf = NULL;
2042 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
2043 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
2044 return PLAYER_ERROR_INVALID_OPERATION;
2046 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
2047 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
2049 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2050 if (ret == PLAYER_ERROR_NONE) {
2052 player_msg_get_type(timeout, ret_buf, INT);
2054 LOGD("server timeout will be %d sec", timeout);
2055 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2057 LOGW("failed to realize, so prepare cb will be released soon");
2058 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
2059 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2066 int player_prepare(player_h player)
2068 PLAYER_INSTANCE_CHECK(player);
2069 int ret = PLAYER_ERROR_NONE;
2070 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
2071 player_cli_s *pc = (player_cli_s *) player;
2072 char *ret_buf = NULL;
2076 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2077 if (ret == PLAYER_ERROR_NONE) {
2079 player_msg_get_type(timeout, ret_buf, INT);
2081 LOGD("server timeout will be %d sec", timeout);
2082 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2087 LOGD("LEAVE 0x%X", ret);
2091 int player_unprepare(player_h player)
2093 PLAYER_INSTANCE_CHECK(player);
2094 int ret = PLAYER_ERROR_NONE;
2095 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
2096 player_cli_s *pc = (player_cli_s *) player;
2097 char *ret_buf = NULL;
2101 if (!CALLBACK_INFO(pc))
2102 return PLAYER_ERROR_INVALID_STATE;
2104 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2106 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2107 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2108 _player_release_internal_memory(pc, false);
2110 pc->cb_info->video_frame_pool_size = 0;
2111 __player_remove_tsurf_list(pc);
2112 pc->is_audio_only = FALSE;
2116 LOGD("LEAVE 0x%X", ret);
2120 /* 1. correct the protocol prefix to lower case
2121 * 2. remove 'file://' prefix
2122 * 3. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' */
2123 int _player_get_valid_path(const char* uri, char* valid_path)
2125 gchar *file_path = NULL;
2127 gchar *colon = NULL;
2129 if (!uri || !valid_path) {
2130 LOGD("invalid parameter");
2131 return PLAYER_ERROR_INVALID_PARAMETER;
2134 if ((colon = strstr(uri, "://")) != NULL) {
2135 gchar *protocol = g_ascii_strdown(uri, colon - uri);
2139 file_path = g_strconcat(protocol, uri+strlen(protocol), NULL);
2140 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2146 if (strstr(valid_path, "file://")) { /* handle the 'file://' prefix */
2148 file_path = g_filename_from_uri(valid_path, NULL, &err);
2149 if (!file_path || (err != NULL)) {
2150 SECURE_LOGE("Invalid URI '%s', err: %s", uri,
2151 (err != NULL) ? err->message : "unknown error");
2153 if (err) g_error_free(err);
2154 if (file_path) g_free(file_path);
2156 return PLAYER_ERROR_INVALID_PARAMETER;
2158 LOGD("get file path from uri");
2160 LOGD("use the original path.");
2161 return PLAYER_ERROR_NONE;
2166 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, valid_path) < 0) {
2167 /* cannot convert path. use the original one. */
2168 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2170 /* need to use converted path. */
2171 SECURE_LOGD("Converted path : %s -> %s", uri, valid_path);
2176 return PLAYER_ERROR_NONE;
2179 int player_set_uri(player_h player, const char *uri)
2181 PLAYER_INSTANCE_CHECK(player);
2182 PLAYER_NULL_ARG_CHECK(uri);
2183 int ret = PLAYER_ERROR_NONE;
2184 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2185 player_cli_s *pc = (player_cli_s *) player;
2186 char *ret_buf = NULL;
2187 char path[MAX_URL_LEN] = {0, };
2191 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
2192 return PLAYER_ERROR_INVALID_PARAMETER;
2194 SECURE_LOGD("new path : %s", path);
2196 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", (const char*)path);
2197 pc->push_media_stream = FALSE;
2203 int player_set_memory_buffer(player_h player, const void *data, int size)
2205 PLAYER_INSTANCE_CHECK(player);
2206 PLAYER_NULL_ARG_CHECK(data);
2207 int ret = PLAYER_ERROR_NONE;
2208 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2209 player_cli_s *pc = (player_cli_s *) player;
2210 char *ret_buf = NULL;
2212 tbm_bo_handle thandle;
2213 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2215 /* before setting mem buffer, player state have to be checked. */
2216 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2218 if (SERVER_TBM_BO(pc)) {
2219 LOGW("The previous memory buffer will be cleared.");
2220 _player_deinit_memory_buffer(pc);
2223 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2225 LOGE("TBM get error : bo is NULL");
2226 return PLAYER_ERROR_INVALID_OPERATION;
2228 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2229 if (thandle.ptr == NULL) {
2230 LOGE("TBM get error : handle pointer is NULL");
2231 ret = PLAYER_ERROR_INVALID_OPERATION;
2234 memcpy(thandle.ptr, data, size);
2237 tfd = tbm_bo_export_fd(bo);
2239 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2240 ret = PLAYER_ERROR_INVALID_OPERATION;
2244 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret, MUSE_TYPE_INT, "size", size);
2245 pc->push_media_stream = FALSE;
2248 if (tfd > INVALID_DEFAULT_VALUE)
2253 if (ret == PLAYER_ERROR_NONE) {
2254 intptr_t bo_addr = 0;
2255 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2256 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2263 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem)
2270 if (deinit_server_mem)
2271 _player_deinit_memory_buffer(pc);
2274 static int _player_deinit_memory_buffer(player_cli_s * pc)
2276 PLAYER_INSTANCE_CHECK(pc);
2277 int ret = PLAYER_ERROR_NONE;
2278 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2279 intptr_t bo_addr = SERVER_TBM_BO(pc);
2281 if (!bo_addr || !CALLBACK_INFO(pc))
2284 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_POINTER, "bo_addr", bo_addr);
2285 SERVER_TBM_BO(pc) = 0;
2290 int player_get_state(player_h player, player_state_e *pstate)
2292 PLAYER_INSTANCE_CHECK(player);
2293 PLAYER_NULL_ARG_CHECK(pstate);
2294 int ret = PLAYER_ERROR_NONE;
2295 player_cli_s *pc = (player_cli_s *) player;
2299 ret = _get_current_state(pc, pstate);
2303 int player_set_volume(player_h player, float left, float right)
2305 PLAYER_INSTANCE_CHECK(player);
2306 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2307 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2308 int ret = PLAYER_ERROR_NONE;
2309 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2310 player_cli_s *pc = (player_cli_s *) player;
2311 char *ret_buf = NULL;
2315 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2316 MUSE_TYPE_DOUBLE, "right", (double)right,
2317 MUSE_TYPE_DOUBLE, "left", (double)left);
2323 int player_get_volume(player_h player, float *pleft, float *pright)
2325 PLAYER_INSTANCE_CHECK(player);
2326 PLAYER_NULL_ARG_CHECK(pleft && pright);
2327 int ret = PLAYER_ERROR_NONE;
2328 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2329 player_cli_s *pc = (player_cli_s *) player;
2332 char *ret_buf = NULL;
2336 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2338 if (ret == PLAYER_ERROR_NONE) {
2339 bool ret_val = true;
2340 ret_val = _player_get_param_value(ret_buf,
2341 MUSE_TYPE_DOUBLE, "left", (void *)&left,
2342 MUSE_TYPE_DOUBLE, "right", (void *)&right,
2343 INVALID_MUSE_TYPE_VALUE);
2345 *pleft = (float)left;
2346 *pright = (float)right;
2348 LOGE("failed to get value from msg");
2349 ret = PLAYER_ERROR_INVALID_OPERATION;
2357 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2359 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SOUND_STREAM);
2360 PLAYER_INSTANCE_CHECK(player);
2362 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2363 player_cli_s *pc = (player_cli_s *) player;
2364 bool is_available = false;
2365 char *ret_buf = NULL;
2369 /* check if stream_info is valid */
2370 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2371 if (ret != SOUND_MANAGER_ERROR_NONE) {
2372 LOGE("failed to checking available stream info");
2373 return PLAYER_ERROR_INVALID_OPERATION;
2376 if (is_available == false) {
2377 ret = PLAYER_ERROR_INVALID_PARAMETER;
2379 char *stream_type = NULL;
2380 int stream_index = 0;
2381 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2382 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2383 if (ret == SOUND_MANAGER_ERROR_NONE)
2384 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2385 MUSE_TYPE_STRING, "stream_type", (const char*)stream_type,
2386 MUSE_TYPE_INT, "stream_index", stream_index);
2388 ret = PLAYER_ERROR_INVALID_OPERATION;
2391 LOGD("LEAVE ret: 0x%X", ret);
2398 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2400 PLAYER_INSTANCE_CHECK(player);
2401 int ret = PLAYER_ERROR_NONE;
2402 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2403 player_cli_s *pc = (player_cli_s *) player;
2404 char *ret_buf = NULL;
2408 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "latency_mode", (int)latency_mode);
2413 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2415 PLAYER_INSTANCE_CHECK(player);
2416 PLAYER_NULL_ARG_CHECK(platency_mode);
2417 int ret = PLAYER_ERROR_NONE;
2418 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2419 player_cli_s *pc = (player_cli_s *) player;
2420 char *ret_buf = NULL;
2421 int latency_mode = -1;
2425 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2427 if (ret == PLAYER_ERROR_NONE) {
2428 player_msg_get(latency_mode, ret_buf);
2429 *platency_mode = latency_mode;
2437 int player_start(player_h player)
2439 PLAYER_INSTANCE_CHECK(player);
2440 int ret = PLAYER_ERROR_NONE;
2441 muse_player_api_e api = MUSE_PLAYER_API_START;
2442 player_cli_s *pc = (player_cli_s *) player;
2443 char *ret_buf = NULL;
2446 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2447 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2449 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2450 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2451 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2452 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2453 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), true);
2454 if (ret != MM_ERROR_NONE) {
2455 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2456 return PLAYER_ERROR_INVALID_OPERATION;
2458 /* avoid setting true at all times, when player is resumed */
2459 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2464 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2468 LOGD("LEAVE 0x%X", ret);
2472 int player_stop(player_h player)
2474 PLAYER_INSTANCE_CHECK(player);
2475 int ret = PLAYER_ERROR_NONE;
2476 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2477 player_cli_s *pc = (player_cli_s *) player;
2478 char *ret_buf = NULL;
2479 player_state_e state = PLAYER_STATE_NONE;
2480 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2481 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2485 /* check player state */
2486 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2487 LOGE("Failed to get state");
2488 return PLAYER_ERROR_INVALID_OPERATION;
2491 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2492 LOGE("Invalid state %d", state);
2493 return PLAYER_ERROR_INVALID_STATE;
2496 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2497 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2498 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2499 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2500 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2501 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), false);
2502 if (ret != MM_ERROR_NONE) {
2503 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2504 return PLAYER_ERROR_INVALID_OPERATION;
2506 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2510 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2511 if (ret == PLAYER_ERROR_NONE)
2512 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2516 LOGD("LEAVE 0x%X", ret);
2520 int player_pause(player_h player)
2522 PLAYER_INSTANCE_CHECK(player);
2523 int ret = PLAYER_ERROR_NONE;
2524 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2525 player_cli_s *pc = (player_cli_s *) player;
2526 char *ret_buf = NULL;
2530 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2533 LOGD("LEAVE 0x%X", ret);
2537 int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data)
2539 PLAYER_INSTANCE_CHECK(player);
2540 PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2542 int ret = PLAYER_ERROR_NONE;
2543 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2544 player_cli_s *pc = (player_cli_s *) player;
2545 char *ret_buf = NULL;
2546 int pos = millisecond;
2550 LOGE("cb_info is null");
2551 return PLAYER_ERROR_INVALID_OPERATION;
2554 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2555 if ((pc->push_media_stream == FALSE) &&
2556 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2557 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2558 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2559 return PLAYER_ERROR_SEEK_FAILED;
2561 if (pc->push_media_stream == TRUE)
2562 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2564 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2565 LOGI("Event type : %d, pos : %d, accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond, accurate);
2566 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2567 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2569 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2571 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2572 MUSE_TYPE_INT, "pos", pos,
2573 MUSE_TYPE_INT, "accurate", (int)accurate);
2575 if (ret != PLAYER_ERROR_NONE) {
2576 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2577 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2578 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2581 if (pc->push_media_stream == TRUE)
2582 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2586 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2587 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2588 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2590 LOGD("LEAVE 0x%X", ret);
2594 int player_get_play_position(player_h player, int *millisecond)
2596 PLAYER_INSTANCE_CHECK(player);
2597 PLAYER_NULL_ARG_CHECK(millisecond);
2599 int ret = PLAYER_ERROR_NONE;
2600 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2601 player_cli_s *pc = (player_cli_s *) player;
2603 char *ret_buf = NULL;
2607 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2609 if (ret == PLAYER_ERROR_NONE) {
2610 player_msg_get(pos, ret_buf);
2618 int player_set_mute(player_h player, bool muted)
2620 PLAYER_INSTANCE_CHECK(player);
2621 int ret = PLAYER_ERROR_NONE;
2622 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2623 player_cli_s *pc = (player_cli_s *) player;
2624 char *ret_buf = NULL;
2625 int mute = (int)muted;
2629 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mute", mute);
2634 int player_is_muted(player_h player, bool * muted)
2636 PLAYER_INSTANCE_CHECK(player);
2637 PLAYER_NULL_ARG_CHECK(muted);
2638 int ret = PLAYER_ERROR_NONE;
2639 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2640 player_cli_s *pc = (player_cli_s *) player;
2641 char *ret_buf = NULL;
2646 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2647 if (ret == PLAYER_ERROR_NONE) {
2648 player_msg_get(mute, ret_buf);
2649 *muted = (bool) mute;
2656 int player_set_looping(player_h player, bool looping)
2658 PLAYER_INSTANCE_CHECK(player);
2659 int ret = PLAYER_ERROR_NONE;
2660 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2661 player_cli_s *pc = (player_cli_s *) player;
2662 char *ret_buf = NULL;
2666 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "looping", (int)looping);
2671 int player_is_looping(player_h player, bool * plooping)
2673 PLAYER_INSTANCE_CHECK(player);
2674 PLAYER_NULL_ARG_CHECK(plooping);
2675 int ret = PLAYER_ERROR_NONE;
2676 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2677 player_cli_s *pc = (player_cli_s *) player;
2678 char *ret_buf = NULL;
2683 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2684 if (ret == PLAYER_ERROR_NONE) {
2685 player_msg_get(looping, ret_buf);
2686 *plooping = looping;
2692 int player_get_duration(player_h player, int *pduration)
2694 PLAYER_INSTANCE_CHECK(player);
2695 PLAYER_NULL_ARG_CHECK(pduration);
2696 int ret = PLAYER_ERROR_NONE;
2697 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2698 player_cli_s *pc = (player_cli_s *) player;
2699 char *ret_buf = NULL;
2704 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2705 if (ret == PLAYER_ERROR_NONE) {
2706 player_msg_get(duration, ret_buf);
2707 *pduration = duration;
2714 /* The player_display_type_e is different at wearable profile */
2715 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2717 int ret = PLAYER_ERROR_NONE;
2718 PLAYER_NULL_ARG_CHECK(out_type);
2721 case PLAYER_DISPLAY_TYPE_OVERLAY:
2722 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2724 case PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE:
2725 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2726 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2728 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2730 case PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS:
2731 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2732 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2734 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2736 case PLAYER_DISPLAY_TYPE_EVAS:
2737 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2739 case PLAYER_DISPLAY_TYPE_NONE:
2740 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2743 ret = PLAYER_ERROR_INVALID_PARAMETER;
2747 LOGD("display type(%d) -> (%d)", type, *out_type);
2751 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2753 PLAYER_INSTANCE_CHECK(player);
2754 int ret = PLAYER_ERROR_NONE;
2755 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2756 player_cli_s *pc = (player_cli_s *) player;
2757 char *ret_buf = NULL;
2758 wl_win_msg_type wl_win;
2759 char *wl_win_msg = (char *)&wl_win;
2760 unsigned int wl_surface_id;
2761 player_private_display_type_e conv_type;
2762 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
2763 int arr_msg_len = 0;
2764 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2765 int (*p_disp_destroy_evas_display)(void **) = NULL;
2766 int (*p_disp_create_evas_display)(void *, void **) = NULL;
2767 int (*p_disp_set_evas_display_old_info)(void *, void *, int, int, int) = NULL;
2768 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2769 void (*p_disp_get_evas_display_geometry_info)(void *, int *, int *, int *, int *) = NULL;
2770 void (*p_disp_media_packet_video_decode_cb)(media_packet_h, void *) = NULL;
2774 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2777 wl_win.wl_window_x = 0;
2778 wl_win.wl_window_y = 0;
2779 wl_win.wl_window_width = 0;
2780 wl_win.wl_window_height = 0;
2782 LOGD("ENTER type: %d", type);
2783 if (type == PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE ||
2784 type == PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS) {
2785 LOGW("DEPRECATION WARNING: display type(%d) is deprecated and will be removed from next release. Use newly defined type value instead.", type);
2788 /* before setting display, player state have to be checked. */
2789 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2791 ret = _player_convert_display_type(type, &conv_type);
2792 if (ret != PLAYER_ERROR_NONE)
2795 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2797 return PLAYER_ERROR_INVALID_PARAMETER;
2799 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2801 * To support repeating play and stop, Evas_handle should not be destroyed in player_unprepare.
2802 * When the display type changes, Player need to destroy Evas_handle to set values of video output,
2803 * Otherwise, the values is not set because of checking Evas_handle.
2805 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
2806 LOGW("evas client already exists");
2807 player_unset_media_packet_video_frame_decoded_cb(player);
2808 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2809 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2810 LOGW("fail to unset evas client");
2811 __player_unset_retrieve_buffer_cb(player);
2812 /* need to set display information again to new handle */
2813 EVAS_INFO(pc)->update_needed = TRUE;
2816 /* set evas_render or wayland */
2817 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
2818 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
2819 wl_surface_id = p_disp_set_wl_display(ELM_WAYLAND_WIN, display);
2820 if (wl_surface_id > 0) {
2821 wl_win.wl_surface_id = wl_surface_id;
2822 wl_win.type = conv_type;
2823 } else return PLAYER_ERROR_INVALID_OPERATION;
2825 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2826 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS) {
2827 if (!CALLBACK_INFO(pc)) {
2828 LOGE("there is no cb info in player handle");
2829 return PLAYER_ERROR_INVALID_OPERATION;
2832 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_create_evas_display, "disp_create_evas_display");
2833 ret = p_disp_create_evas_display(display, &EVAS_HANDLE(pc));
2834 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2836 /* before evas handle is created, user could set display information */
2837 if (EVAS_INFO(pc)->update_needed) {
2838 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_old_info, "disp_set_evas_display_old_info");
2839 ret = p_disp_set_evas_display_old_info(display, EVAS_HANDLE(pc), EVAS_INFO(pc)->mode, EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2840 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2841 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2842 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2843 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);
2844 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2846 EVAS_INFO(pc)->update_needed = FALSE;
2848 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_geometry_info, "disp_get_evas_display_geometry_info");
2849 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);
2850 wl_win.type = conv_type;
2852 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_media_packet_video_decode_cb, "disp_media_packet_video_decode_cb");
2853 ret = player_set_media_packet_video_frame_decoded_cb(player, p_disp_media_packet_video_decode_cb, (void *)EVAS_HANDLE(pc));
2854 if (ret != PLAYER_ERROR_NONE)
2855 LOGW("fail to set decoded callback");
2856 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2857 LOGW("fail to set __retrieve_buffer_cb");
2860 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2861 LOGI("Wayland surface type is NONE");
2862 wl_win.type = conv_type;
2865 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
2866 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2867 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
2873 int player_set_display_mode(player_h player, player_display_mode_e mode)
2875 PLAYER_INSTANCE_CHECK(player);
2876 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2877 int ret = PLAYER_ERROR_NONE;
2878 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
2879 player_cli_s *pc = (player_cli_s *) player;
2880 char *ret_buf = NULL;
2881 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2882 int (*p_disp_set_evas_display_disp_mode)(void *, int) = NULL;
2885 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2887 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2888 if (EVAS_HANDLE(pc)) {
2889 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_disp_mode, "disp_set_evas_display_disp_mode");
2890 ret = p_disp_set_evas_display_disp_mode(EVAS_HANDLE(pc), mode);
2891 if (ret != MM_ERROR_NONE)
2892 return PLAYER_ERROR_INVALID_OPERATION;
2894 return PLAYER_ERROR_NONE;
2896 EVAS_INFO(pc)->mode = mode;
2897 EVAS_INFO(pc)->update_needed = TRUE;
2900 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mode", (int)mode);
2905 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
2907 PLAYER_INSTANCE_CHECK(player);
2908 PLAYER_NULL_ARG_CHECK(pmode);
2909 int ret = PLAYER_ERROR_NONE;
2910 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
2911 player_cli_s *pc = (player_cli_s *) player;
2912 char *ret_buf = NULL;
2914 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2915 int (*p_disp_get_evas_display_disp_mode)(void *, int *) = NULL;
2919 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2921 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2922 if (EVAS_HANDLE(pc)) {
2923 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_disp_mode, "disp_get_evas_display_disp_mode");
2924 ret = p_disp_get_evas_display_disp_mode(EVAS_HANDLE(pc), &mode);
2925 *pmode = (player_display_mode_e) mode;
2926 if (ret != MM_ERROR_NONE)
2927 return PLAYER_ERROR_INVALID_OPERATION;
2929 return PLAYER_ERROR_NONE;
2932 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2933 if (ret == PLAYER_ERROR_NONE) {
2934 player_msg_get_type(mode, ret_buf, INT);
2943 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
2945 PLAYER_INSTANCE_CHECK(player);
2946 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2948 int ret = PLAYER_ERROR_NONE;
2949 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
2950 player_cli_s *pc = (player_cli_s *) player;
2951 char *ret_buf = NULL;
2952 wl_win_msg_type wl_win;
2953 char *wl_win_msg = (char *)&wl_win;
2954 int arr_msg_len = 0;
2955 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2956 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2960 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2962 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2963 if (EVAS_HANDLE(pc)) {
2964 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2965 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), x, y, width, height);
2966 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
2967 return PLAYER_ERROR_INVALID_PARAMETER;
2968 else if (ret != MM_ERROR_NONE)
2969 return PLAYER_ERROR_INVALID_OPERATION;
2971 return PLAYER_ERROR_NONE;
2973 EVAS_INFO(pc)->roi_x = x;
2974 EVAS_INFO(pc)->roi_y = y;
2975 EVAS_INFO(pc)->roi_w = width;
2976 EVAS_INFO(pc)->roi_h = height;
2977 EVAS_INFO(pc)->update_needed = TRUE;
2980 wl_win.wl_window_x = x;
2981 wl_win.wl_window_y = y;
2982 wl_win.wl_window_width = width;
2983 wl_win.wl_window_height = height;
2985 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
2986 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2987 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
2993 int player_set_playback_rate(player_h player, float rate)
2995 PLAYER_INSTANCE_CHECK(player);
2996 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2997 int ret = PLAYER_ERROR_NONE;
2998 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
2999 player_cli_s *pc = (player_cli_s *) player;
3000 char *ret_buf = NULL;
3004 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", (double)rate);
3007 LOGD("LEAVE 0x%X", ret);
3011 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
3013 PLAYER_INSTANCE_CHECK(player);
3014 int ret = PLAYER_ERROR_NONE;
3015 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
3016 player_cli_s *pc = (player_cli_s *) player;
3017 char *ret_buf = NULL;
3018 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3019 int (*p_disp_set_evas_display_rotation)(void *, int) = NULL;
3023 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3025 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3026 if (EVAS_HANDLE(pc)) {
3027 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_rotation, "disp_set_evas_display_rotation");
3028 ret = p_disp_set_evas_display_rotation(EVAS_HANDLE(pc), rotation);
3029 if (ret != MM_ERROR_NONE)
3030 return PLAYER_ERROR_INVALID_OPERATION;
3032 return PLAYER_ERROR_NONE;
3034 EVAS_INFO(pc)->rotation = rotation;
3035 EVAS_INFO(pc)->update_needed = TRUE;
3038 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "rotation", (int)rotation);
3043 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
3045 PLAYER_INSTANCE_CHECK(player);
3046 PLAYER_NULL_ARG_CHECK(protation);
3047 int ret = PLAYER_ERROR_NONE;
3048 player_cli_s *pc = (player_cli_s *) player;
3049 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
3050 char *ret_buf = NULL;
3052 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3053 int (*p_disp_get_evas_display_rotation)(void *, int *) = NULL;
3057 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3059 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3060 if (EVAS_HANDLE(pc)) {
3061 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_rotation, "disp_get_evas_display_rotation");
3062 ret = p_disp_get_evas_display_rotation(EVAS_HANDLE(pc), &rotation);
3063 *protation = (player_display_rotation_e) rotation;
3064 if (ret != MM_ERROR_NONE)
3065 return PLAYER_ERROR_INVALID_OPERATION;
3067 return PLAYER_ERROR_NONE;
3070 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3071 if (ret == PLAYER_ERROR_NONE) {
3072 player_msg_get_type(rotation, ret_buf, INT);
3073 *protation = rotation;
3080 int player_set_display_visible(player_h player, bool visible)
3082 PLAYER_INSTANCE_CHECK(player);
3083 int ret = PLAYER_ERROR_NONE;
3084 player_cli_s *pc = (player_cli_s *) player;
3085 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
3086 char *ret_buf = NULL;
3087 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3088 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
3092 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3094 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3095 if (EVAS_HANDLE(pc)) {
3096 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
3097 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), visible);
3098 if (ret != MM_ERROR_NONE)
3099 return PLAYER_ERROR_INVALID_OPERATION;
3101 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3102 return PLAYER_ERROR_NONE;
3104 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3105 EVAS_INFO(pc)->update_needed = TRUE;
3109 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "visible", (int)visible);
3114 int player_is_display_visible(player_h player, bool * pvisible)
3116 PLAYER_INSTANCE_CHECK(player);
3117 PLAYER_NULL_ARG_CHECK(pvisible);
3118 int ret = PLAYER_ERROR_NONE;
3119 player_cli_s *pc = (player_cli_s *) player;
3120 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
3121 char *ret_buf = NULL;
3123 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3125 int (*p_disp_get_evas_display_visible)(void *, bool *) = NULL;
3129 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3131 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3132 if (EVAS_HANDLE(pc)) {
3133 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_visible, "disp_get_evas_display_visible");
3134 ret = p_disp_get_evas_display_visible(EVAS_HANDLE(pc), &visible);
3140 if (ret != MM_ERROR_NONE)
3141 return PLAYER_ERROR_INVALID_OPERATION;
3143 return PLAYER_ERROR_NONE;
3146 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3147 if (ret == PLAYER_ERROR_NONE) {
3148 player_msg_get_type(value, ret_buf, INT);
3160 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3162 PLAYER_INSTANCE_CHECK(player);
3163 PLAYER_NULL_ARG_CHECK(pvalue);
3164 int ret = PLAYER_ERROR_NONE;
3165 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3166 player_cli_s *pc = (player_cli_s *) player;
3167 char *ret_buf = NULL;
3168 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3172 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "key", (int)key);
3173 if (ret == PLAYER_ERROR_NONE) {
3174 player_msg_get_string(value, ret_buf);
3175 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3181 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3183 PLAYER_INSTANCE_CHECK(player);
3184 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3185 int ret = PLAYER_ERROR_NONE;
3186 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3187 player_cli_s *pc = (player_cli_s *) player;
3188 char *ret_buf = NULL;
3189 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3190 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3191 bool ret_val = TRUE;
3195 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3196 if (ret == PLAYER_ERROR_NONE) {
3197 ret_val = _player_get_param_value(ret_buf,
3198 MUSE_TYPE_STRING, "video_codec", (void *)video_codec,
3199 MUSE_TYPE_STRING, "audio_codec", (void *)audio_codec,
3200 INVALID_MUSE_TYPE_VALUE);
3203 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3205 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3207 ret = PLAYER_ERROR_INVALID_OPERATION;
3214 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3216 PLAYER_INSTANCE_CHECK(player);
3217 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3218 int ret = PLAYER_ERROR_NONE;
3219 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3220 player_cli_s *pc = (player_cli_s *) player;
3221 char *ret_buf = NULL;
3222 int sample_rate = 0;
3228 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3229 if (ret == PLAYER_ERROR_NONE) {
3230 bool ret_val = true;
3231 ret_val = _player_get_param_value(ret_buf,
3232 MUSE_TYPE_INT, "sample_rate", (void *)&sample_rate,
3233 MUSE_TYPE_INT, "channel", (void *)&channel,
3234 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3235 INVALID_MUSE_TYPE_VALUE);
3238 *psample_rate = sample_rate;
3240 *pchannel = channel;
3242 *pbit_rate = bit_rate;
3244 ret = PLAYER_ERROR_INVALID_OPERATION;
3251 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3253 PLAYER_INSTANCE_CHECK(player);
3254 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3255 int ret = PLAYER_ERROR_NONE;
3256 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3257 player_cli_s *pc = (player_cli_s *) player;
3258 char *ret_buf = NULL;
3264 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3265 if (ret == PLAYER_ERROR_NONE) {
3266 bool ret_val = true;
3267 ret_val = _player_get_param_value(ret_buf,
3268 MUSE_TYPE_INT, "fps", (void *)&fps,
3269 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3270 INVALID_MUSE_TYPE_VALUE);
3275 *pbit_rate = bit_rate;
3277 ret = PLAYER_ERROR_INVALID_OPERATION;
3284 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3286 PLAYER_INSTANCE_CHECK(player);
3287 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3288 int ret = PLAYER_ERROR_NONE;
3289 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3290 player_cli_s *pc = (player_cli_s *) player;
3291 char *ret_buf = NULL;
3297 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3298 if (ret == PLAYER_ERROR_NONE) {
3299 bool ret_val = true;
3300 ret_val = _player_get_param_value(ret_buf,
3301 MUSE_TYPE_INT, "width", (void *)&width,
3302 MUSE_TYPE_INT, "height", (void *)&height,
3303 INVALID_MUSE_TYPE_VALUE);
3308 ret = PLAYER_ERROR_INVALID_OPERATION;
3315 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3317 PLAYER_INSTANCE_CHECK(player);
3318 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3319 int ret = PLAYER_ERROR_NONE;
3320 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3321 player_cli_s *pc = (player_cli_s *) player;
3322 char *ret_buf = NULL;
3326 tbm_bo_handle thandle;
3327 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3328 int key = INVALID_DEFAULT_VALUE;
3333 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3334 if (ret == PLAYER_ERROR_NONE) {
3335 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3336 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3338 LOGE("failed to get msg obj, err:%d", err);
3339 ret = PLAYER_ERROR_INVALID_OPERATION;
3343 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3344 LOGD("size : %d", size);
3345 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3346 LOGE("failed to get key value");
3347 ret = PLAYER_ERROR_INVALID_OPERATION;
3351 tfd = pc->cb_info->tfd;
3353 LOGE("failed to get tbm fd value");
3354 ret = PLAYER_ERROR_INVALID_OPERATION;
3358 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3360 LOGE("TBM get error : bo is NULL");
3361 ret = PLAYER_ERROR_INVALID_OPERATION;
3364 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3365 if (thandle.ptr == NULL) {
3366 LOGE("TBM get error : handle pointer is NULL");
3367 ret = PLAYER_ERROR_INVALID_OPERATION;
3370 album_art = _get_mem(pc, size);
3372 memcpy(album_art, thandle.ptr, size);
3373 *palbum_art = album_art;
3375 LOGE("g_new failure");
3376 ret = PLAYER_ERROR_INVALID_OPERATION;
3388 muse_core_msg_object_free(jobj);
3393 if (tfd > INVALID_DEFAULT_VALUE)
3396 if (CALLBACK_INFO(pc))
3397 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3403 if (key > INVALID_DEFAULT_VALUE && CALLBACK_INFO(pc)) {
3404 LOGD("send msg to release buffer. key:%d", key);
3405 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_RETURN_BUFFER, MSG_FD(pc), ret, MUSE_TYPE_INT, "key", key);
3411 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3413 PLAYER_INSTANCE_CHECK(player);
3414 PLAYER_NULL_ARG_CHECK(pcount);
3415 int ret = PLAYER_ERROR_NONE;
3416 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3417 player_cli_s *pc = (player_cli_s *) player;
3418 char *ret_buf = NULL;
3423 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3424 if (ret == PLAYER_ERROR_NONE) {
3425 player_msg_get(count, ret_buf);
3432 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3434 PLAYER_INSTANCE_CHECK(player);
3435 PLAYER_NULL_ARG_CHECK(band_levels);
3436 int ret = PLAYER_ERROR_NONE;
3437 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3438 player_cli_s *pc = (player_cli_s *) player;
3439 char *ret_buf = NULL;
3443 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3444 MUSE_TYPE_INT, "length", length,
3445 MUSE_TYPE_ARRAY, "band_levels", length, band_levels);
3452 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3454 PLAYER_INSTANCE_CHECK(player);
3455 int ret = PLAYER_ERROR_NONE;
3456 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3457 player_cli_s *pc = (player_cli_s *) player;
3458 char *ret_buf = NULL;
3462 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3463 MUSE_TYPE_INT, "index", index,
3464 MUSE_TYPE_INT, "level", level);
3470 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3472 PLAYER_INSTANCE_CHECK(player);
3473 PLAYER_NULL_ARG_CHECK(plevel);
3474 int ret = PLAYER_ERROR_NONE;
3475 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3476 player_cli_s *pc = (player_cli_s *) player;
3477 char *ret_buf = NULL;
3482 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3483 if (ret == PLAYER_ERROR_NONE) {
3484 player_msg_get(level, ret_buf);
3491 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3493 PLAYER_INSTANCE_CHECK(player);
3494 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3495 int ret = PLAYER_ERROR_NONE;
3496 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3497 player_cli_s *pc = (player_cli_s *) player;
3498 char *ret_buf = NULL;
3499 int min = 0, max = 0;
3503 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3504 if (ret == PLAYER_ERROR_NONE) {
3505 bool ret_val = true;
3506 ret_val = _player_get_param_value(ret_buf,
3507 MUSE_TYPE_INT, "min", (void *)&min,
3508 MUSE_TYPE_INT, "max", (void *)&max,
3509 INVALID_MUSE_TYPE_VALUE);
3514 ret = PLAYER_ERROR_INVALID_OPERATION;
3521 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3523 PLAYER_INSTANCE_CHECK(player);
3524 PLAYER_NULL_ARG_CHECK(pfrequency);
3525 int ret = PLAYER_ERROR_NONE;
3526 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3527 player_cli_s *pc = (player_cli_s *) player;
3528 char *ret_buf = NULL;
3533 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3534 if (ret == PLAYER_ERROR_NONE) {
3535 player_msg_get(frequency, ret_buf);
3536 *pfrequency = frequency;
3542 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3544 PLAYER_INSTANCE_CHECK(player);
3545 PLAYER_NULL_ARG_CHECK(prange);
3546 int ret = PLAYER_ERROR_NONE;
3547 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3548 player_cli_s *pc = (player_cli_s *) player;
3549 char *ret_buf = NULL;
3554 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3555 if (ret == PLAYER_ERROR_NONE) {
3556 player_msg_get(range, ret_buf);
3563 int player_audio_effect_equalizer_clear(player_h player)
3565 PLAYER_INSTANCE_CHECK(player);
3566 int ret = PLAYER_ERROR_NONE;
3567 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3568 player_cli_s *pc = (player_cli_s *) player;
3569 char *ret_buf = NULL;
3573 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3578 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3580 PLAYER_INSTANCE_CHECK(player);
3581 PLAYER_NULL_ARG_CHECK(pavailable);
3582 int ret = PLAYER_ERROR_NONE;
3583 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3584 player_cli_s *pc = (player_cli_s *) player;
3585 char *ret_buf = NULL;
3590 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3591 if (ret == PLAYER_ERROR_NONE) {
3592 player_msg_get(available, ret_buf);
3593 *pavailable = available;
3599 int player_set_subtitle_path(player_h player, const char *path)
3601 PLAYER_INSTANCE_CHECK(player);
3602 int ret = PLAYER_ERROR_NONE;
3603 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3604 player_cli_s *pc = (player_cli_s *) player;
3605 char *ret_buf = NULL;
3606 char subtitle_path[MAX_URL_LEN] = {0, };
3610 if (path && _player_get_valid_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3611 return PLAYER_ERROR_INVALID_PARAMETER;
3613 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "subtitle_path", (const char*)subtitle_path);
3618 int player_set_subtitle_position_offset(player_h player, int millisecond)
3620 PLAYER_INSTANCE_CHECK(player);
3621 int ret = PLAYER_ERROR_NONE;
3622 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3623 player_cli_s *pc = (player_cli_s *) player;
3624 char *ret_buf = NULL;
3628 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "millisecond", millisecond);
3634 int player_set_progressive_download_path(player_h player, const char *path)
3636 PLAYER_INSTANCE_CHECK(player);
3637 PLAYER_NULL_ARG_CHECK(path);
3638 int ret = PLAYER_ERROR_NONE;
3639 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
3640 player_cli_s *pc = (player_cli_s *) player;
3641 char *ret_buf = NULL;
3642 char dw_path[MAX_URL_LEN] = {0, };
3645 LOGW("DEPRECATION WARNING: player_set_progressive_download_path() is deprecated and will be removed from next release.");
3647 if (!_player_check_network_availability())
3648 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3650 if (_player_get_valid_path(path, dw_path) != PLAYER_ERROR_NONE)
3651 return PLAYER_ERROR_INVALID_PARAMETER;
3653 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "dw_path", (const char*)dw_path);
3658 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
3660 PLAYER_INSTANCE_CHECK(player);
3661 PLAYER_NULL_ARG_CHECK(pcurrent && ptotal_size);
3662 int ret = PLAYER_ERROR_NONE;
3663 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
3664 player_cli_s *pc = (player_cli_s *) player;
3665 char *ret_buf = NULL;
3666 unsigned long current, total_size;
3669 LOGW("DEPRECATION WARNING: player_get_progressive_download_status() is deprecated and will be removed from next release.");
3671 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3672 if (ret == PLAYER_ERROR_NONE) {
3673 bool ret_val = true;
3674 ret_val = _player_get_param_value(ret_buf,
3675 MUSE_TYPE_POINTER, "current", (void *)¤t,
3676 MUSE_TYPE_POINTER, "total_size", (void *)&total_size,
3677 INVALID_MUSE_TYPE_VALUE);
3679 *pcurrent = current;
3680 *ptotal_size = total_size;
3682 ret = PLAYER_ERROR_INVALID_OPERATION;
3690 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3692 PLAYER_INSTANCE_CHECK(player);
3693 PLAYER_NULL_ARG_CHECK(callback);
3694 int ret = PLAYER_ERROR_NONE;
3695 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3696 player_cli_s *pc = (player_cli_s *) player;
3697 char *ret_buf = NULL;
3700 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3701 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3702 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3704 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3705 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3706 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3709 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3711 if (ret != PLAYER_ERROR_NONE)
3712 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3718 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3720 PLAYER_INSTANCE_CHECK(player);
3721 PLAYER_NULL_ARG_CHECK(cookie);
3722 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3723 int ret = PLAYER_ERROR_NONE;
3724 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3725 player_cli_s *pc = (player_cli_s *) player;
3726 char *ret_buf = NULL;
3730 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3731 MUSE_TYPE_STRING, "cookie", cookie,
3732 MUSE_TYPE_INT, "size", size);
3737 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3739 PLAYER_INSTANCE_CHECK(player);
3740 PLAYER_NULL_ARG_CHECK(user_agent);
3741 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3742 int ret = PLAYER_ERROR_NONE;
3743 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3744 player_cli_s *pc = (player_cli_s *) player;
3745 char *ret_buf = NULL;
3749 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3750 MUSE_TYPE_STRING, "user_agent", user_agent,
3751 MUSE_TYPE_INT, "size", size);
3756 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3758 PLAYER_INSTANCE_CHECK(player);
3759 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3760 int ret = PLAYER_ERROR_NONE;
3761 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3762 player_cli_s *pc = (player_cli_s *) player;
3763 char *ret_buf = NULL;
3764 int start = 0, current = 0;
3768 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3769 if (ret == PLAYER_ERROR_NONE) {
3770 bool ret_val = true;
3771 ret_val = _player_get_param_value(ret_buf,
3772 MUSE_TYPE_INT, "start", (void *)&start,
3773 MUSE_TYPE_INT, "current", (void *)¤t,
3774 INVALID_MUSE_TYPE_VALUE);
3777 *pcurrent = current;
3779 ret = PLAYER_ERROR_INVALID_OPERATION;
3787 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3789 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3792 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3793 static void __retrieve_buffer_cb(void *user_data)
3795 player_cli_s *player = (player_cli_s *)user_data;
3796 int ret = PLAYER_ERROR_NONE;
3797 bool gapless = false;
3798 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
3800 ret = player_is_gapless((player_h)user_data, &gapless);
3801 if (ret != PLAYER_ERROR_NONE) {
3802 LOGW("player_is_gapless is failed");
3806 PLAYER_DISP_DLSYM(player->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
3807 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3808 if (ret != PLAYER_ERROR_NONE)
3809 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3812 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3814 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3817 static int __player_unset_retrieve_buffer_cb(player_h player)
3819 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3823 int player_unset_completed_cb(player_h player)
3825 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3828 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3830 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3833 int player_unset_interrupted_cb(player_h player)
3835 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3838 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3840 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3843 int player_unset_error_cb(player_h player)
3845 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3848 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3850 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3853 int player_unset_buffering_cb(player_h player)
3855 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3858 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3860 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3863 int player_unset_subtitle_updated_cb(player_h player)
3865 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3868 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3870 PLAYER_INSTANCE_CHECK(player);
3871 PLAYER_NULL_ARG_CHECK(callback);
3872 int ret = PLAYER_ERROR_NONE;
3873 player_cli_s *pc = (player_cli_s *) player;
3874 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3875 char *ret_buf = NULL;
3876 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3880 LOGW("DEPRECATION WARNING: player_set_progressive_download_message_cb() is deprecated and will be removed from next release.");
3882 if (!_player_check_network_availability())
3883 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3885 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3886 MUSE_TYPE_INT, "type", type,
3887 MUSE_TYPE_INT, "set", set);
3889 if (ret == PLAYER_ERROR_NONE) {
3890 pc->cb_info->user_cb[type] = callback;
3891 pc->cb_info->user_data[type] = user_data;
3892 LOGI("Event type : %d ", type);
3899 int player_unset_progressive_download_message_cb(player_h player)
3901 PLAYER_INSTANCE_CHECK(player);
3902 int ret = PLAYER_ERROR_NONE;
3903 player_cli_s *pc = (player_cli_s *) player;
3904 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3905 char *ret_buf = NULL;
3906 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3910 LOGW("DEPRECATION WARNING: player_unset_progressive_download_message_cb() is deprecated and will be removed from next release.");
3912 set_null_user_cb_lock(pc->cb_info, type);
3914 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3915 MUSE_TYPE_INT, "type", type,
3916 MUSE_TYPE_INT, "set", set);
3923 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
3925 PLAYER_INSTANCE_CHECK(player);
3926 PLAYER_NULL_ARG_CHECK(callback);
3927 int ret = PLAYER_ERROR_NONE;
3928 player_cli_s *pc = (player_cli_s *) player;
3929 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3930 char *ret_buf = NULL;
3931 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3936 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3937 MUSE_TYPE_INT, "type", type,
3938 MUSE_TYPE_INT, "set", set);
3940 if (ret == PLAYER_ERROR_NONE) {
3941 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
3942 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
3943 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
3950 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
3952 PLAYER_INSTANCE_CHECK(player);
3953 int ret = PLAYER_ERROR_NONE;
3954 player_cli_s *pc = (player_cli_s *) player;
3955 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3956 char *ret_buf = NULL;
3957 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3962 set_null_user_cb_lock(pc->cb_info, type);
3964 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3965 MUSE_TYPE_INT, "type", type,
3966 MUSE_TYPE_INT, "set", set);
3972 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
3974 PLAYER_INSTANCE_CHECK(player);
3975 PLAYER_NULL_ARG_CHECK(callback);
3976 int ret = PLAYER_ERROR_NONE;
3977 player_cli_s *pc = (player_cli_s *) player;
3978 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3979 char *ret_buf = NULL;
3980 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3985 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3986 MUSE_TYPE_INT, "type", type,
3987 MUSE_TYPE_INT, "set", set);
3989 if (ret == PLAYER_ERROR_NONE) {
3990 pc->cb_info->user_cb[type] = callback;
3991 pc->cb_info->user_data[type] = user_data;
3992 LOGI("Event type : %d ", type);
3999 int player_unset_video_stream_changed_cb(player_h player)
4001 PLAYER_INSTANCE_CHECK(player);
4002 int ret = PLAYER_ERROR_NONE;
4003 player_cli_s *pc = (player_cli_s *) player;
4004 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4005 char *ret_buf = NULL;
4006 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4011 set_null_user_cb_lock(pc->cb_info, type);
4013 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4014 MUSE_TYPE_INT, "type", type,
4015 MUSE_TYPE_INT, "set", set);
4021 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)
4023 PLAYER_INSTANCE_CHECK(player);
4024 PLAYER_NULL_ARG_CHECK(callback);
4025 int ret = PLAYER_ERROR_NONE;
4026 player_cli_s *pc = (player_cli_s *) player;
4027 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4028 char *ret_buf = NULL;
4029 muse_player_event_e type;
4034 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4035 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4036 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4037 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4039 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4040 return PLAYER_ERROR_INVALID_PARAMETER;
4043 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4044 MUSE_TYPE_INT, "type", type,
4045 MUSE_TYPE_INT, "set", set);
4047 if (ret == PLAYER_ERROR_NONE) {
4048 pc->cb_info->user_cb[type] = callback;
4049 pc->cb_info->user_data[type] = user_data;
4050 LOGI("Event type : %d ", type);
4057 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
4059 PLAYER_INSTANCE_CHECK(player);
4060 int ret = PLAYER_ERROR_NONE;
4061 player_cli_s *pc = (player_cli_s *) player;
4062 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4063 char *ret_buf = NULL;
4064 muse_player_event_e type;
4069 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4070 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4071 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4072 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4074 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4075 return PLAYER_ERROR_INVALID_PARAMETER;
4078 set_null_user_cb_lock(pc->cb_info, type);
4080 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4081 MUSE_TYPE_INT, "type", type,
4082 MUSE_TYPE_INT, "set", set);
4088 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)
4090 PLAYER_INSTANCE_CHECK(player);
4091 PLAYER_NULL_ARG_CHECK(callback);
4092 int ret = PLAYER_ERROR_NONE;
4093 player_cli_s *pc = (player_cli_s *) player;
4094 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4095 char *ret_buf = NULL;
4096 muse_player_event_e type;
4101 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4102 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4103 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4104 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4106 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4107 return PLAYER_ERROR_INVALID_PARAMETER;
4110 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4111 MUSE_TYPE_INT, "type", type,
4112 MUSE_TYPE_INT, "set", set);
4114 if (ret == PLAYER_ERROR_NONE) {
4115 pc->cb_info->user_cb[type] = callback;
4116 pc->cb_info->user_data[type] = user_data;
4117 LOGI("Event type : %d ", type);
4124 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
4126 PLAYER_INSTANCE_CHECK(player);
4127 int ret = PLAYER_ERROR_NONE;
4128 player_cli_s *pc = (player_cli_s *) player;
4129 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4130 char *ret_buf = NULL;
4131 muse_player_event_e type;
4136 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4137 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4138 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4139 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4141 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4142 return PLAYER_ERROR_INVALID_PARAMETER;
4145 set_null_user_cb_lock(pc->cb_info, type);
4147 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4148 MUSE_TYPE_INT, "type", type,
4149 MUSE_TYPE_INT, "set", set);
4155 /* TODO Implement raw data socket channel */
4156 int player_push_media_stream(player_h player, media_packet_h packet)
4158 PLAYER_INSTANCE_CHECK(player);
4159 PLAYER_NULL_ARG_CHECK(packet);
4160 int ret = PLAYER_ERROR_NONE;
4161 player_cli_s *pc = (player_cli_s *) player;
4162 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
4163 char *ret_buf = NULL;
4164 player_push_media_msg_type push_media;
4165 char *push_media_msg = (char *)&push_media;
4166 int msg_size = sizeof(player_push_media_msg_type);
4170 tbm_bo_handle thandle;
4171 tbm_fd tfd = INVALID_DEFAULT_VALUE;
4174 media_format_h format;
4178 int arr_msg_len = 0;
4182 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
4183 media_packet_get_buffer_size(packet, &push_media.size);
4184 media_packet_get_pts(packet, &push_media.pts);
4185 media_packet_get_format(packet, &format);
4186 media_packet_get_flags(packet, &push_media.flags);
4188 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
4190 media_packet_is_video(packet, &is_video);
4191 media_packet_is_audio(packet, &is_audio);
4192 media_packet_is_end_of_stream(packet, &is_eos);
4194 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
4196 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
4198 media_format_unref(format);
4201 int arr_buf_len = 0;
4203 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
4204 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
4206 LOGE("TBM get error : bo is NULL");
4207 return PLAYER_ERROR_INVALID_OPERATION;
4209 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4210 if (thandle.ptr == NULL) {
4211 LOGE("TBM get error : handle pointer is NULL");
4212 ret = PLAYER_ERROR_INVALID_OPERATION;
4215 memcpy(thandle.ptr, buf, push_media.size);
4218 tfd = tbm_bo_export_fd(bo);
4220 LOGE("tbm_bo_export_fd err 0x%x", tfd);
4221 ret = PLAYER_ERROR_INVALID_OPERATION;
4225 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4226 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret,
4227 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4229 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4230 buf_size = (int)push_media.size;
4232 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4233 arr_buf_len = (buf_size / sizeof(int) + (buf_size % sizeof(int) ? 1 : 0));
4234 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4235 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg,
4236 MUSE_TYPE_ARRAY, "buf", arr_buf_len, (int*)buf);
4240 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4241 buf_size = (int)push_media.size;
4242 if ((muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts) < 0) && (!is_eos)) {
4243 LOGE("failed to send data");
4244 return PLAYER_ERROR_INVALID_OPERATION;
4247 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4248 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4249 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg);
4252 LOGD("ret_buf %s", ret_buf);
4256 if (tfd > INVALID_DEFAULT_VALUE)
4259 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4267 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4269 PLAYER_INSTANCE_CHECK(player);
4270 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4271 int ret = PLAYER_ERROR_NONE;
4272 player_cli_s *pc = (player_cli_s *) player;
4273 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4274 char *ret_buf = NULL;
4275 media_format_mimetype_e mimetype;
4287 media_format_ref(format);
4288 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4289 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4290 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4291 LOGE("failed to get video info from format.");
4292 return PLAYER_ERROR_INVALID_PARAMETER;
4295 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4296 MUSE_TYPE_INT, "type", type,
4297 MUSE_TYPE_INT, "mimetype", mimetype,
4298 MUSE_TYPE_INT, "width", width,
4299 MUSE_TYPE_INT, "height", height,
4300 MUSE_TYPE_INT, "avg_bps", avg_bps,
4301 MUSE_TYPE_INT, "max_bps", max_bps,
4302 MUSE_TYPE_INT, "frame_rate", frame_rate);
4304 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4305 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4306 LOGE("failed to get audio info from format.");
4307 return PLAYER_ERROR_INVALID_PARAMETER;
4310 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4311 MUSE_TYPE_INT, "type", type,
4312 MUSE_TYPE_INT, "mimetype", mimetype,
4313 MUSE_TYPE_INT, "channel", channel,
4314 MUSE_TYPE_INT, "samplerate", samplerate,
4315 MUSE_TYPE_INT, "avg_bps", avg_bps,
4316 MUSE_TYPE_INT, "bit", bit);
4319 media_format_unref(format);
4320 pc->push_media_stream = TRUE;
4326 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4328 int ret = PLAYER_ERROR_NONE;
4329 PLAYER_INSTANCE_CHECK(player);
4330 player_cli_s *pc = (player_cli_s *) player;
4331 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4332 char *ret_buf = NULL;
4336 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4337 MUSE_TYPE_INT, "type", type,
4338 MUSE_TYPE_INT64, "max_size", (INT64)max_size);
4344 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4346 int ret = PLAYER_ERROR_NONE;
4347 PLAYER_INSTANCE_CHECK(player);
4348 PLAYER_NULL_ARG_CHECK(pmax_size);
4349 player_cli_s *pc = (player_cli_s *) player;
4350 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4351 char *ret_buf = NULL;
4352 unsigned long long max_size;
4356 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4357 if (ret == PLAYER_ERROR_NONE) {
4358 player_msg_get_type(max_size, ret_buf, INT64);
4359 *pmax_size = max_size;
4365 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4367 int ret = PLAYER_ERROR_NONE;
4368 PLAYER_INSTANCE_CHECK(player);
4369 player_cli_s *pc = (player_cli_s *) player;
4370 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4371 char *ret_buf = NULL;
4375 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4376 MUSE_TYPE_INT, "type", type,
4377 MUSE_TYPE_INT, "percent", (int)percent);
4383 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4385 int ret = PLAYER_ERROR_NONE;
4386 PLAYER_INSTANCE_CHECK(player);
4387 PLAYER_NULL_ARG_CHECK(ppercent);
4388 player_cli_s *pc = (player_cli_s *) player;
4389 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4390 char *ret_buf = NULL;
4395 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4396 if (ret == PLAYER_ERROR_NONE) {
4397 player_msg_get(percent, ret_buf);
4398 *ppercent = percent;
4405 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4407 PLAYER_INSTANCE_CHECK(player);
4408 PLAYER_NULL_ARG_CHECK(pcount);
4409 int ret = PLAYER_ERROR_NONE;
4410 player_cli_s *pc = (player_cli_s *) player;
4411 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4412 char *ret_buf = NULL;
4417 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4418 if (ret == PLAYER_ERROR_NONE) {
4419 player_msg_get(count, ret_buf);
4427 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4429 PLAYER_INSTANCE_CHECK(player);
4430 PLAYER_NULL_ARG_CHECK(pindex);
4431 int ret = PLAYER_ERROR_NONE;
4432 player_cli_s *pc = (player_cli_s *) player;
4433 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4434 char *ret_buf = NULL;
4439 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4440 if (ret == PLAYER_ERROR_NONE) {
4441 player_msg_get(index, ret_buf);
4449 int player_select_track(player_h player, player_stream_type_e type, int index)
4451 PLAYER_INSTANCE_CHECK(player);
4452 int ret = PLAYER_ERROR_NONE;
4453 player_cli_s *pc = (player_cli_s *) player;
4454 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4455 char *ret_buf = NULL;
4459 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4465 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4467 PLAYER_INSTANCE_CHECK(player);
4468 PLAYER_NULL_ARG_CHECK(pcode);
4469 int ret = PLAYER_ERROR_NONE;
4470 player_cli_s *pc = (player_cli_s *) player;
4471 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4472 char *ret_buf = NULL;
4473 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4478 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4479 if (ret == PLAYER_ERROR_NONE) {
4480 bool recv_ret = true;
4481 recv_ret = _player_get_param_value(ret_buf,
4482 MUSE_TYPE_INT, "code_len", (void *)&code_len,
4483 MUSE_TYPE_STRING, "code", (void *)code,
4484 INVALID_MUSE_TYPE_VALUE);
4486 *pcode = strndup(code, code_len);
4488 ret = PLAYER_ERROR_INVALID_OPERATION;
4494 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4496 PLAYER_INSTANCE_CHECK(player);
4497 PLAYER_NULL_ARG_CHECK(callback);
4498 int ret = PLAYER_ERROR_NONE;
4499 player_cli_s *pc = (player_cli_s *) player;
4500 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4501 char *ret_buf = NULL;
4502 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4503 int idx = 0, num = 0;
4504 int bandwidth = 0, width = 0, height = 0;
4510 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4511 if (ret == PLAYER_ERROR_NONE) {
4512 player_msg_get_type(num, ret_buf, INT);
4514 player_msg_get_string(var_info, ret_buf);
4516 LOGW("There is no stream variant info.");
4519 for (idx = 0 ; idx < num ; idx++) {
4520 bandwidth = width = height = 0;
4522 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4524 bandwidth = atoi(token);
4526 token = strtok_r(NULL, ",", &ptr);
4528 width = atoi(token);
4530 token = strtok_r(NULL, ",", &ptr);
4532 height = atoi(token);
4534 callback(bandwidth, width, height, user_data);
4537 LOGD("LEAVE 0x%X", ret);
4542 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4544 int ret = PLAYER_ERROR_NONE;
4545 PLAYER_INSTANCE_CHECK(player);
4546 player_cli_s *pc = (player_cli_s *) player;
4547 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4548 char *ret_buf = NULL;
4552 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4553 MUSE_TYPE_INT, "bandwidth", bandwidth,
4554 MUSE_TYPE_INT, "width", width,
4555 MUSE_TYPE_INT, "height", height);
4558 LOGD("LEAVE 0x%X", ret);
4563 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4565 int ret = PLAYER_ERROR_NONE;
4566 PLAYER_INSTANCE_CHECK(player);
4567 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4569 player_cli_s *pc = (player_cli_s *) player;
4570 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4571 char *ret_buf = NULL;
4572 int bandwidth = -1, width = -1, height = -1;
4576 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4577 if (ret == PLAYER_ERROR_NONE) {
4578 bool ret_val = true;
4579 ret_val = _player_get_param_value(ret_buf,
4580 MUSE_TYPE_INT, "bandwidth", (void *)&bandwidth,
4581 MUSE_TYPE_INT, "width", (void *)&width,
4582 MUSE_TYPE_INT, "height", (void *)&height,
4583 INVALID_MUSE_TYPE_VALUE);
4585 if (pbandwidth) *pbandwidth = bandwidth;
4586 if (pwidth) *pwidth = width;
4587 if (pheight) *pheight = height;
4589 ret = PLAYER_ERROR_INVALID_OPERATION;
4594 LOGD("LEAVE 0x%X", ret);
4598 int player_set_audio_only(player_h player, bool audio_only)
4600 int ret = PLAYER_ERROR_NONE;
4601 PLAYER_INSTANCE_CHECK(player);
4602 player_cli_s *pc = (player_cli_s *) player;
4603 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4604 char *ret_buf = NULL;
4605 player_state_e state = PLAYER_STATE_NONE;
4607 LOGD("ENTER audio_only: %d", audio_only);
4609 /* check player state */
4610 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
4611 LOGE("Failed to get state");
4612 return PLAYER_ERROR_INVALID_OPERATION;
4615 if (state < PLAYER_STATE_READY) {
4616 LOGE("Invalid state %d", state);
4617 return PLAYER_ERROR_INVALID_STATE;
4620 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4621 if (EVAS_HANDLE(pc)) {
4622 pc->is_audio_only = (gboolean)audio_only;
4623 return PLAYER_ERROR_NONE;
4626 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "audio_only", (int)audio_only);
4629 LOGD("LEAVE 0x%X", ret);
4634 int player_is_audio_only(player_h player, bool *paudio_only)
4636 PLAYER_INSTANCE_CHECK(player);
4637 PLAYER_NULL_ARG_CHECK(paudio_only);
4638 int ret = PLAYER_ERROR_NONE;
4639 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4640 player_cli_s *pc = (player_cli_s *) player;
4641 char *ret_buf = NULL;
4645 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4646 if (EVAS_HANDLE(pc)) {
4647 *paudio_only = (bool)pc->is_audio_only;
4648 return PLAYER_ERROR_NONE;
4652 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4653 if (ret == PLAYER_ERROR_NONE) {
4654 player_msg_get(audio_only, ret_buf);
4655 *paudio_only = (bool)audio_only;
4659 LOGD("LEAVE 0x%X", ret);
4663 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4665 int ret = PLAYER_ERROR_NONE;
4666 PLAYER_INSTANCE_CHECK(player);
4667 player_cli_s *pc = (player_cli_s *) player;
4668 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4669 char *ret_buf = NULL;
4673 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4674 MUSE_TYPE_INT, "buffer_ms", buffer_ms,
4675 MUSE_TYPE_INT, "rebuffer_ms", rebuffer_ms);
4678 LOGD("LEAVE 0x%X", ret);
4682 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4684 PLAYER_INSTANCE_CHECK(player);
4685 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4687 int ret = PLAYER_ERROR_NONE;
4688 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4689 player_cli_s *pc = (player_cli_s *) player;
4690 int buffering_time = 0, rebuffering_time = 0;
4691 char *ret_buf = NULL;
4695 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4697 if (ret == PLAYER_ERROR_NONE) {
4698 bool ret_val = true;
4699 ret_val = _player_get_param_value(ret_buf,
4700 MUSE_TYPE_INT, "buffering_time", (void *)&buffering_time,
4701 MUSE_TYPE_INT, "rebuffering_time", (void *)&rebuffering_time,
4702 INVALID_MUSE_TYPE_VALUE);
4704 if (buffer_ms) *buffer_ms = buffering_time;
4705 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4707 ret = PLAYER_ERROR_INVALID_OPERATION;
4713 LOGD("LEAVE 0x%X", ret);
4717 int player_360_is_content_spherical(player_h player, bool *is_spherical)
4719 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4720 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4722 PLAYER_INSTANCE_CHECK(player);
4723 PLAYER_NULL_ARG_CHECK(is_spherical);
4725 int ret = PLAYER_ERROR_NONE;
4726 muse_player_api_e api = MUSE_PLAYER_API_360_IS_CONTENT_SPHERICAL;
4727 player_cli_s *pc = (player_cli_s *) player;
4728 char *ret_buf = NULL;
4733 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4734 if (ret == PLAYER_ERROR_NONE) {
4735 player_msg_get(val, ret_buf);
4736 *is_spherical = val;
4740 LOGD("LEAVE 0x%X", ret);
4744 int player_360_set_enabled(player_h player, bool enabled)
4746 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4747 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4749 PLAYER_INSTANCE_CHECK(player);
4750 int ret = PLAYER_ERROR_NONE;
4751 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLED;
4752 player_cli_s *pc = (player_cli_s *) player;
4753 char *ret_buf = NULL;
4754 int val = (int)enabled;
4756 LOGD("ENTER %d", enabled);
4758 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
4761 LOGD("LEAVE 0x%X", ret);
4765 int player_360_is_enabled(player_h player, bool *enabled)
4767 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4768 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4770 PLAYER_INSTANCE_CHECK(player);
4771 PLAYER_NULL_ARG_CHECK(enabled);
4772 int ret = PLAYER_ERROR_NONE;
4773 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4774 player_cli_s *pc = (player_cli_s *) player;
4775 char *ret_buf = NULL;
4780 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4781 if (ret == PLAYER_ERROR_NONE) {
4782 player_msg_get(val, ret_buf);
4787 LOGD("LEAVE 0x%X", ret);
4791 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4793 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4794 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4796 PLAYER_INSTANCE_CHECK(player);
4797 int ret = PLAYER_ERROR_NONE;
4798 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4799 player_cli_s *pc = (player_cli_s *) player;
4800 char *ret_buf = NULL;
4802 LOGD("ENTER %f %f", yaw, pitch);
4804 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4805 MUSE_TYPE_DOUBLE, "yaw", (double)yaw,
4806 MUSE_TYPE_DOUBLE, "pitch", (double)pitch);
4810 LOGD("LEAVE 0x%X", ret);
4814 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4816 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4817 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4819 PLAYER_INSTANCE_CHECK(player);
4820 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4821 int ret = PLAYER_ERROR_NONE;
4822 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4823 player_cli_s *pc = (player_cli_s *) player;
4824 double yaw_val = -1;
4825 double pitch_val = -1;
4826 char *ret_buf = NULL;
4830 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4832 if (ret == PLAYER_ERROR_NONE) {
4833 bool ret_val = true;
4834 ret_val = _player_get_param_value(ret_buf,
4835 MUSE_TYPE_DOUBLE, "yaw_val", (void *)&yaw_val,
4836 MUSE_TYPE_DOUBLE, "pitch_val", (void *)&pitch_val,
4837 INVALID_MUSE_TYPE_VALUE);
4839 *yaw = (float)yaw_val;
4840 *pitch = (float)pitch_val;
4842 LOGE("failed to get value from msg");
4843 ret = PLAYER_ERROR_INVALID_OPERATION;
4849 LOGD("LEAVE 0x%X", ret);
4853 int player_360_set_zoom(player_h player, float level)
4855 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4856 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4858 PLAYER_INSTANCE_CHECK(player);
4859 int ret = PLAYER_ERROR_NONE;
4860 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4861 player_cli_s *pc = (player_cli_s *) player;
4862 char *ret_buf = NULL;
4864 LOGD("ENTER %f", level);
4866 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "level", (double)level);
4869 LOGD("LEAVE 0x%X", ret);
4873 int player_360_get_zoom(player_h player, float *level)
4875 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4876 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4878 PLAYER_INSTANCE_CHECK(player);
4879 PLAYER_NULL_ARG_CHECK(level);
4880 int ret = PLAYER_ERROR_NONE;
4881 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
4882 player_cli_s *pc = (player_cli_s *) player;
4884 char *ret_buf = NULL;
4888 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4890 if (ret == PLAYER_ERROR_NONE) {
4891 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
4892 *level = (float)zoom;
4894 LOGE("failed to get value from msg");
4895 ret = PLAYER_ERROR_INVALID_OPERATION;
4901 LOGD("LEAVE 0x%X", ret);
4906 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
4908 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4909 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4911 PLAYER_INSTANCE_CHECK(player);
4912 int ret = PLAYER_ERROR_NONE;
4913 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
4914 player_cli_s *pc = (player_cli_s *) player;
4915 char *ret_buf = NULL;
4917 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
4919 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4920 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
4921 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
4924 LOGD("LEAVE 0x%X", ret);
4928 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
4930 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4931 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4933 PLAYER_INSTANCE_CHECK(player);
4934 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
4935 int ret = PLAYER_ERROR_NONE;
4936 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
4937 player_cli_s *pc = (player_cli_s *) player;
4940 char *ret_buf = NULL;
4944 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4946 if (ret == PLAYER_ERROR_NONE) {
4947 bool ret_val = true;
4948 ret_val = _player_get_param_value(ret_buf,
4949 MUSE_TYPE_INT, "h_val", (void *)&h_val,
4950 MUSE_TYPE_INT, "v_val", (void *)&v_val,
4951 INVALID_MUSE_TYPE_VALUE);
4953 *horizontal_degrees = h_val;
4954 *vertical_degrees = v_val;
4956 LOGE("failed to get value from msg");
4957 ret = PLAYER_ERROR_INVALID_OPERATION;
4963 LOGD("LEAVE 0x%X", ret);
4967 int player_set_replaygain_enabled(player_h player, bool enabled)
4969 PLAYER_INSTANCE_CHECK(player);
4970 int ret = PLAYER_ERROR_NONE;
4971 muse_player_api_e api = MUSE_PLAYER_API_SET_REPLAYGAIN_ENABLED;
4972 player_cli_s *pc = (player_cli_s *) player;
4973 char *ret_buf = NULL;
4974 int val = (int)enabled;
4978 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
4983 int player_is_replaygain_enabled(player_h player, bool *enabled)
4985 PLAYER_INSTANCE_CHECK(player);
4986 PLAYER_NULL_ARG_CHECK(enabled);
4987 int ret = PLAYER_ERROR_NONE;
4988 muse_player_api_e api = MUSE_PLAYER_API_IS_REPLAYGAIN_ENABLED;
4989 player_cli_s *pc = (player_cli_s *) player;
4990 char *ret_buf = NULL;
4995 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4996 if (ret == PLAYER_ERROR_NONE) {
4997 player_msg_get(val, ret_buf);
4998 *enabled = (bool) val;