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.
21 #include <sys/types.h>
26 #include <tbm_bufmgr.h>
27 #include <tbm_surface.h>
28 #include <tbm_surface_internal.h>
31 #include <muse_core.h>
32 #include <muse_client.h>
33 #include <muse_player.h>
34 #include <muse_player_msg.h>
35 #include <sound_manager.h>
36 #include <sound_manager_internal.h>
37 #include <storage-internal.h>
38 #include <system_info.h>
39 #include "player_internal.h"
40 #include "player_private.h"
41 #include "player_msg.h"
43 #define INVALID_MUSE_TYPE_VALUE 0
44 #define MAX_S_PATH_LEN 32
45 #define MODULE_NAME "player"
46 #define PLAYER_FEATURE_SOUND_STREAM "http://tizen.org/feature/multimedia.player.stream_info"
47 #define PLAYER_FEATURE_OPENGL "http://tizen.org/feature/opengles.version.2_0"
48 #define PLAYER_FEATURE_SPHERICAL_VIDEO "http://tizen.org/feature/multimedia.player.spherical_video"
49 #define PLAYER_FEATURE_AUDIO_OFFLOAD "http://tizen.org/feature/multimedia.player.audio_offload"
51 #define M_PI 3.14159265358979323846
55 tbm_fd tfd[MUSE_NUM_FD];
61 callback_cb_info_s *cb_info;
62 _player_recv_data *recv_data;
66 intptr_t remote_v_data;
70 } _media_pkt_video_fin_data;
77 } _media_pkt_audio_fin_data;
79 static int _player_deinit_memory_buffer(player_cli_s *pc);
80 static void _player_event_queue_add(player_event_queue *ev, _player_cb_data *data);
81 static bool _player_need_sync_context(int event_id);
82 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all);
83 typedef void (*player_retrieve_buffer_cb)(void *user_data);
84 static void __retrieve_buffer_cb(void *user_data);
85 static void __player_media_packet_video_decoded_cb(media_packet_h packet, void *user_data);
86 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data);
87 static int __player_unset_retrieve_buffer_cb(player_h player);
88 static void _player_release_internal_memory(player_cli_s *pc, bool deinit_server_mem);
91 * Internal Implementation
93 int _player_send_msg(muse_player_api_e api, player_cli_s *player, char *msg, tbm_fd tfd, char **retbuf)
95 int ret = PLAYER_ERROR_NONE;
97 int send_fd = INVALID_DEFAULT_VALUE;
98 int send_tfd[MUSE_NUM_FD];
99 int timeout = client_get_api_timeout(player, api);
101 memset(send_tfd, INVALID_DEFAULT_VALUE, sizeof(send_tfd));
103 if (player && CALLBACK_INFO(player)) {
104 send_fd = MSG_FD(player);
106 LOGE("can not access to cb_info");
107 return PLAYER_ERROR_INVALID_STATE;
110 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
111 LOGE("invalid socket fd %d", send_fd);
112 return PLAYER_ERROR_INVALID_OPERATION;
115 if (tfd != INVALID_DEFAULT_VALUE) {
117 send_len = muse_core_msg_send_fd(send_fd, send_tfd, msg);
119 send_len = muse_core_msg_send(send_fd, msg);
122 LOGE("sending message failed");
123 return PLAYER_ERROR_INVALID_OPERATION;
125 ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), retbuf, timeout);
131 int _player_send_msg_async(int send_fd, char *msg)
135 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
136 LOGE("invalid socket fd %d", send_fd);
137 return PLAYER_ERROR_INVALID_OPERATION;
140 send_len = muse_core_msg_send(send_fd, msg);
142 LOGE("sending message failed");
143 return PLAYER_ERROR_INVALID_OPERATION;
146 return PLAYER_ERROR_NONE;
149 static int _get_current_state(player_cli_s *pc, player_state_e *pstate)
151 PLAYER_INSTANCE_CHECK(pc);
152 PLAYER_NULL_ARG_CHECK(pstate);
153 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
154 int ret = PLAYER_ERROR_NONE;
155 int state = PLAYER_STATE_NONE;
156 char *ret_buf = NULL;
158 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
160 if (ret == PLAYER_ERROR_NONE) {
161 player_msg_get(state, ret_buf);
163 LOGD("current state %d", *pstate);
170 static bool _player_get_param_value(char *buf, ...)
172 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
175 int type = MUSE_TYPE_ANY;
176 char *param_name = NULL;
179 void *jobj = muse_core_msg_object_new(buf, NULL, &err);
182 LOGE("failed to get msg object. err:%d", err);
186 va_start(var_args, buf);
188 while ((type = va_arg(var_args, int)) != INVALID_MUSE_TYPE_VALUE) {
189 param_name = va_arg(var_args, char *);
192 case MUSE_TYPE_INT64:
193 case MUSE_TYPE_DOUBLE:
194 case MUSE_TYPE_STRING:
195 case MUSE_TYPE_POINTER:
196 value = va_arg(var_args, void *);
198 if (!muse_core_msg_object_get_value(param_name, jobj, type, value)) {
200 LOGE("failed to get %s value", param_name);
204 LOGE("Unexpected type");
210 muse_core_msg_object_free(jobj);
216 int _player_video_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
218 int ret = MEDIA_PACKET_FINALIZE;
219 muse_player_api_e api = MUSE_PLAYER_API_RETURN_VIDEO_DATA;
220 _media_pkt_video_fin_data *fin_data = (_media_pkt_video_fin_data *)user_data;
222 char *snd_msg = NULL;
226 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
230 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
231 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
235 if (!fin_data->use_tsurf_pool) {
236 tbm_surface_h tsurf = NULL;
237 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
238 LOGE("media_packet_get_tbm_surface failed");
239 /* continue the remained job */
242 /* LOGD("tsurf destroy %p", tsurf); */
243 tbm_surface_destroy(tsurf);
247 /* Do not destroy tbm surface here to reuse during playback *
248 * they will be destroyed at player_unprepare() or player_destroy(). *
249 * ref: __player_remove_tsurf_list() */
251 tbm_surface_h tsurf = NULL;
253 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
254 /* LOGD("tsurf set to null %p", tsurf); */
259 if (muse_core_fd_is_valid(fin_data->fd)) {
260 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
261 LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
265 v_data = fin_data->remote_v_data;
266 snd_msg = muse_core_msg_new(api, MUSE_TYPE_POINTER, "v_data", v_data, 0);
267 snd_len = muse_core_msg_send(fin_data->fd, snd_msg);
268 muse_core_msg_free(snd_msg);
271 LOGE("[fd:%d] fail to send msg.", fin_data->fd);
273 LOGE("[fd:%d] is invalid.", fin_data->fd);
285 int _player_audio_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
287 int ret = MEDIA_PACKET_FINALIZE;
288 muse_player_api_e api = MUSE_PLAYER_API_RETURN_BUFFER;
289 _media_pkt_audio_fin_data *fin_data = (_media_pkt_audio_fin_data *)user_data;
292 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
297 LOGE("invalid fin_data");
302 /* LOGD("release memory - %p", fin_data->bo); */
303 tbm_bo_unref(fin_data->bo);
306 if (fin_data->fd > INVALID_DEFAULT_VALUE && muse_core_fd_is_valid(fin_data->fd)) {
307 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
308 LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
312 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(api, fin_data->fd, MUSE_TYPE_INT, "key", fin_data->key);
314 LOGE("[fd:%d] is invalid.", fin_data->fd);
326 static bool _player_video_roi_area_is_valid(double x_scale, double y_scale,
327 double w_scale, double h_scale)
329 if (x_scale >= 0.0 && x_scale <= 1.0 && y_scale >= 0.0 && y_scale <= 1.0
330 && w_scale > 0.0 && w_scale <= 1.0 && h_scale > 0.0 && h_scale <= 1.0)
333 LOGE("Video roi area is not valid");
337 static bool _player_check_network_availability(void)
339 #define _FEATURE_NAME_WIFI "http://tizen.org/feature/network.wifi"
340 #define _FEATURE_NAME_TELEPHONY "http://tizen.org/feature/network.telephony"
341 #define _FEATURE_NAME_ETHERNET "http://tizen.org/feature/network.ethernet"
342 bool enabled = FALSE;
343 bool supported = FALSE;
345 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
346 LOGI("wifi status = %d", enabled);
350 LOGE("SYSTEM_INFO_ERROR");
353 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
354 LOGI("telephony status = %d", enabled);
358 LOGE("SYSTEM_INFO_ERROR");
361 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
362 LOGI("ethernet status = %d", enabled);
366 LOGE("SYSTEM_INFO_ERROR");
375 static void *_get_mem(player_cli_s *player, int size)
377 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
379 mem->data = g_new(void, size);
380 mem->next = player->head;
387 static void _del_mem(player_cli_s *player)
390 while (player->head) {
391 mem = player->head->next;
392 g_free(player->head->data);
393 g_free(player->head);
398 static int player_recv_msg(callback_cb_info_s *cb_info, tbm_fd *tfd)
401 msg_buff_s *buff = &cb_info->buff;
403 memset(buff->recvMsg, 0x00, sizeof(char) * buff->bufLen);
404 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(*tfd) * MUSE_NUM_FD);
405 recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, MUSE_MSG_MAX_LENGTH, tfd);
407 LOGE("failed to recv msg %d", recvLen);
411 /* check the first msg */
412 if (buff->part_of_msg && buff->recvMsg[0] != '{')
414 gchar *tmp = g_strndup(buff->recvMsg, recvLen);
416 LOGE("failed to copy msg.");
420 LOGD("get remained part of msg %d + %zu, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
423 if (recvLen + strlen(buff->part_of_msg) >= buff->bufLen) {
424 LOGD("realloc Buffer %d -> %d", buff->bufLen, (int)(recvLen + strlen(buff->part_of_msg) + 1));
425 buff->bufLen = recvLen + strlen(buff->part_of_msg) + 1;
426 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
427 if (!buff->recvMsg) {
428 LOGE("failed renew buffer.");
432 memset(buff->recvMsg, 0x00, sizeof(char) * buff->bufLen);
434 g_snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
435 recvLen += strlen(buff->part_of_msg);
437 g_free(buff->part_of_msg);
438 buff->part_of_msg = NULL;
443 /* check the last msg */
444 if (buff->recvMsg[recvLen - 1] != '}') {
445 char *part_pos = strrchr(buff->recvMsg, '}');
446 int part_len = ((part_pos) ? (strlen(part_pos + 1)) : (0));
449 buff->part_of_msg = g_strndup(part_pos + 1, part_len);
450 if (!buff->part_of_msg) {
451 LOGE("failed to alloc buffer for part of msg.");
454 LOGD("get part of msg: %zu, %s", strlen(buff->part_of_msg), buff->part_of_msg);
462 static void set_null_user_cb(callback_cb_info_s *cb_info, muse_player_event_e event)
464 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
465 cb_info->user_cb[event] = NULL;
466 cb_info->user_data[event] = NULL;
470 /* Notice : have to be called via API to avoid deadlock
471 * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
473 static void set_null_user_cb_lock(callback_cb_info_s *cb_info, muse_player_event_e event)
477 LOGD("event %d cb will be cleared", event);
480 LOGE("cb_info is NULL, event: %d", event);
484 lock = (g_thread_self() != cb_info->event_queue.thread);
487 g_mutex_lock(&cb_info->event_queue.mutex);
489 if (_player_need_sync_context(event))
490 _player_remove_idle_event(cb_info, event, false);
492 set_null_user_cb(cb_info, event);
495 g_mutex_unlock(&cb_info->event_queue.mutex);
498 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
500 int ret = PLAYER_ERROR_NONE;
501 player_cli_s *pc = (player_cli_s *)player;
502 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
503 char *ret_buf = NULL;
506 PLAYER_INSTANCE_CHECK(player);
507 PLAYER_NULL_ARG_CHECK(callback);
509 if (type == MUSE_PLAYER_EVENT_TYPE_BUFFERING) {
510 if (!_player_check_network_availability())
511 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
512 pc->cb_info->drop_buffering_message = FALSE;
515 if (!CALLBACK_INFO(pc))
516 return PLAYER_ERROR_INVALID_OPERATION;
518 LOGI("Event type : %d ", type);
519 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
520 MUSE_TYPE_INT, "type", type,
521 MUSE_TYPE_INT, "set", set);
523 if (ret == PLAYER_ERROR_NONE) {
524 pc->cb_info->user_cb[type] = callback;
525 pc->cb_info->user_data[type] = user_data;
532 static int __unset_callback(muse_player_event_e type, player_h player)
534 int ret = PLAYER_ERROR_NONE;
535 player_cli_s *pc = (player_cli_s *)player;
536 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
537 char *ret_buf = NULL;
540 PLAYER_INSTANCE_CHECK(player);
542 LOGI("Event type : %d ", type);
544 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
546 if ((type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) ||
547 (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME)) {
548 /* check state condition */
549 player_state_e state = PLAYER_STATE_NONE;
551 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
552 LOGE("Failed to get current state");
553 return PLAYER_ERROR_INVALID_OPERATION;
556 if (state > PLAYER_STATE_READY) {
557 LOGE("Invalid state %d", state);
558 return PLAYER_ERROR_INVALID_STATE;
562 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
564 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
565 MUSE_TYPE_INT, "type", type,
566 MUSE_TYPE_INT, "set", set);
572 static void __prepare_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
574 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
576 ((player_prepared_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
578 set_null_user_cb(cb_info, ev);
581 static void __complete_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
583 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
584 ((player_completed_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
587 static void __player_media_packet_video_decoded_cb(media_packet_h packet, void *user_data)
589 if (!packet || !user_data) {
590 LOGE("invalid param [packet:%p, user_data:%p]", packet, user_data);
594 LOGD("render packet %p", packet);
596 mm_display_interface_evas_render(DP_INTERFACE((player_cli_s *)user_data), packet);
599 static void __retrieve_buffer_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
602 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
603 ((player_retrieve_buffer_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
606 static void __interrupt_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
608 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
609 ((player_interrupted_cb)cb_info->user_cb[ev])(PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT, cb_info->user_data[ev]);
612 static void __error_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
615 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
617 if (player_msg_get(code, recv_data->buffer)) {
618 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
619 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
620 LOGW("failed to pause, so prepare cb will be released soon");
621 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
624 ((player_error_cb)cb_info->user_cb[ev])(code, cb_info->user_data[ev]);
628 static void __disconnected_error_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
630 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
632 ((player_error_cb)cb_info->user_cb[ev])(PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
635 static void __buffering_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
638 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
640 if (player_msg_get(percent, recv_data->buffer)) {
641 g_mutex_lock(&cb_info->buffering_cb_mutex);
642 if (cb_info->drop_buffering_message) {
643 LOGD("Drop buffering callback");
644 g_mutex_unlock(&cb_info->buffering_cb_mutex);
647 g_mutex_unlock(&cb_info->buffering_cb_mutex);
648 ((player_buffering_cb)cb_info->user_cb[ev])(percent, cb_info->user_data[ev]);
653 static void __subtitle_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
656 char text[MUSE_URI_MAX_LENGTH] = { 0, };
657 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
660 ret = _player_get_param_value(recv_data->buffer,
661 MUSE_TYPE_INT, "duration", (void *)&duration,
662 MUSE_TYPE_STRING, "text", (void *)text,
663 INVALID_MUSE_TYPE_VALUE);
665 ((player_subtitle_updated_cb)cb_info->user_cb[ev])(duration, text, cb_info->user_data[ev]);
668 static void __capture_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
670 unsigned char *data = NULL;
673 unsigned int size = 0;
675 tbm_bo_handle thandle;
676 int key = INVALID_DEFAULT_VALUE;
678 get_ret = _player_get_param_value(recv_data->buffer,
679 MUSE_TYPE_INT, "width", (void *)&width,
680 MUSE_TYPE_INT, "height", (void *)&height,
681 MUSE_TYPE_INT, "size", (void *)&size,
682 MUSE_TYPE_INT, "key", (void *)&key,
683 INVALID_MUSE_TYPE_VALUE);
685 if (recv_data->tfd[0] < 0) {
686 LOGE("There is no valid tbm_fd");
690 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
692 LOGE("TBM get error : bo is NULL");
695 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
696 if (thandle.ptr == NULL) {
697 LOGE("TBM get error : handle pointer is NULL");
700 data = g_new(unsigned char, size);
702 memcpy(data, thandle.ptr, size);
703 ((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]);
706 LOGE("g_new failure");
713 PLAYER_CLOSE_FD(recv_data->tfd[0]);
715 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
721 if (key > INVALID_DEFAULT_VALUE) {
722 LOGD("send msg to release buffer. key:%d", key);
723 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
726 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
729 static void __seek_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
731 int ret = MM_ERROR_NONE;
732 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
733 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
735 g_mutex_lock(&cb_info->seek_cb_mutex);
737 switch (cb_info->seek_cb_state) {
738 case PLAYER_SEEK_CB_STATE_NONE:
740 if (!cb_info->user_cb[ev]) {
741 LOGW("invalid seek callback info, skip");
745 ret = mm_display_interface_get_type(cb_info->dp_info.interface, &display_type);
746 if (ret == MM_ERROR_NONE && display_type == MM_DISPLAY_TYPE_EVAS &&
747 cb_info->dp_info.visible != PLAYER_VISIBLE_INFO_FALSE) {
748 LOGW("set display visible true for EVAS");
749 if (mm_display_interface_evas_set_visible(cb_info->dp_info.interface, true) != MM_ERROR_NONE)
750 LOGE("mm_display_interface_evas_set_visible failed");
752 LOGW("get display type ret 0x%x, type %d", ret, display_type);
755 LOGD("call seek cb");
756 ((player_seek_completed_cb)cb_info->user_cb[ev])(cb_info->user_data[ev]);
757 set_null_user_cb(cb_info, ev);
761 case PLAYER_SEEK_CB_STATE_DROP:
762 case PLAYER_SEEK_CB_STATE_WAIT: /* not expected */
763 LOGW("ignored. seek cb %p, state %d", cb_info->user_cb[ev], cb_info->seek_cb_state);
766 LOGE("invalid state value");
770 g_mutex_unlock(&cb_info->seek_cb_mutex);
773 static void __player_remove_tsurf_list(player_cli_s *pc)
777 g_mutex_lock(&pc->cb_info->data_mutex);
778 if (pc->cb_info->tsurf_list) {
779 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
781 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
782 player_tsurf_info_s *tmp = (player_tsurf_info_s *)l->data;
784 LOGD("%p will be removed", tmp);
787 tbm_surface_destroy(tmp->tsurf);
793 g_list_free(pc->cb_info->tsurf_list);
794 pc->cb_info->tsurf_list = NULL;
796 g_mutex_unlock(&pc->cb_info->data_mutex);
800 static player_tsurf_info_s *__player_get_tsurf_from_list(callback_cb_info_s *cb_info, intptr_t key, int height, int width)
804 g_mutex_lock(&cb_info->data_mutex);
805 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
806 player_tsurf_info_s *tmp = (player_tsurf_info_s *)l->data;
807 if (tmp && key && (tmp->key == key)) {
808 LOGD("found tsurf_data of tbm_key %" PRIdPTR, key);
810 /* need to check tsuf info to support DRC */
811 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
812 (tbm_surface_get_width(tmp->tsurf) != width)) {
814 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
815 LOGW("tsurf info is changed. need to create new tsurf.");
816 tbm_surface_destroy(tmp->tsurf);
819 g_mutex_unlock(&cb_info->data_mutex);
823 g_mutex_unlock(&cb_info->data_mutex);
828 g_mutex_unlock(&cb_info->data_mutex);
832 static media_packet_rotate_method_e __convert_packet_orient_info(int orientation)
834 media_packet_rotate_method_e rotate = MEDIA_PACKET_ROTATE_IDENTITY;
836 switch (orientation) {
838 rotate = MEDIA_PACKET_ROTATE_90;
841 rotate = MEDIA_PACKET_ROTATE_180;
844 rotate = MEDIA_PACKET_ROTATE_270;
847 rotate = MEDIA_PACKET_ROTATE_IDENTITY;
854 static void __media_packet_video_frame_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
856 tbm_bo bo[4] = { NULL, };
857 tbm_surface_info_s sinfo;
858 char *surface_info = (char *)&sinfo;
859 media_packet_h pkt = NULL;
860 tbm_surface_h tsurf = NULL;
861 player_tsurf_info_s *tsurf_data = NULL;
863 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
864 bool make_pkt_fmt = false;
865 int ret = MEDIA_FORMAT_ERROR_NONE;
866 _media_pkt_video_fin_data *fin_data = NULL;
870 int i = 0, orientation = 0;
871 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
873 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
875 !muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_POINTER, &key) ||
876 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
877 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
878 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
879 !muse_core_msg_object_get_value("orientation", jobj, MUSE_TYPE_INT, &orientation) ||
880 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
882 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
884 muse_core_msg_object_free(jobj);
887 muse_core_msg_object_free(jobj);
889 LOGD("width %d, height %d", sinfo.width, sinfo.height);
892 LOGE("cb_info is null");
896 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
897 /* send msg to release v_data. */
898 LOGE("_video_decoded_cb is not set");
902 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
903 LOGE("tbm fd is invalid");
907 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
909 for (i = 0; i < MUSE_NUM_FD; i++) {
910 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
914 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
917 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
919 LOGE("failed to create tbm surface");
923 if (cb_info->use_tsurf_pool) {
924 tsurf_data = g_try_new(player_tsurf_info_s, 1);
926 LOGE("failed to alloc tsurf info");
929 tsurf_data->key = key;
930 tsurf_data->tsurf = tsurf;
932 g_mutex_lock(&cb_info->data_mutex);
933 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
934 LOGD("key %" PRIdPTR " is added to the pool", key);
935 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
936 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
937 g_mutex_unlock(&cb_info->data_mutex);
940 if (tsurf_data->tsurf) {
941 tsurf = tsurf_data->tsurf;
943 LOGE("tsurf_data->tsurf is null (never enter here)");
948 /* check media packet format */
949 if (cb_info->pkt_fmt) {
950 int pkt_fmt_width = 0;
951 int pkt_fmt_height = 0;
952 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
954 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
955 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
956 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);
957 media_format_unref(cb_info->pkt_fmt);
958 cb_info->pkt_fmt = NULL;
964 /* create packet format */
966 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
967 ret = media_format_create(&cb_info->pkt_fmt);
968 if (ret == MEDIA_FORMAT_ERROR_NONE) {
969 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
970 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
971 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
972 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
974 LOGE("media_format_create failed");
978 fin_data = g_try_new0(_media_pkt_video_fin_data, 1);
980 LOGE("failed to alloc fin_data");
983 fin_data->remote_v_data = v_data;
984 fin_data->fd = cb_info->fd;
985 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
987 /* Keep the fd id to check validation when the pkt is destroyed. */
988 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
990 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb)_player_video_media_packet_finalize, (void *)fin_data, &pkt);
991 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
992 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
997 ret = media_packet_set_pts(pkt, (uint64_t)pts);
998 if (ret != MEDIA_PACKET_ERROR_NONE)
999 LOGE("media_packet_set_pts failed");
1002 ret = media_packet_set_rotate_method(pkt, __convert_packet_orient_info(orientation));
1003 if (ret != MEDIA_PACKET_ERROR_NONE)
1004 LOGE("media_packet_set_rotate_method failed");
1006 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
1007 /* call media packet callback */
1008 ((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]);
1010 LOGE("_video_decoded_cb is not set");
1011 media_packet_destroy(pkt);
1014 /* if tsruf pool is enabled, bo_num can be zero. */
1015 for (i = 0; i < MUSE_NUM_FD; i++)
1016 PLAYER_CLOSE_FD(recv_data->tfd[i]);
1018 for (i = 0; i < bo_num; i++) {
1020 tbm_bo_unref(bo[i]);
1023 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1028 media_packet_destroy(pkt);
1029 else if (!tsurf_data && tsurf)
1030 tbm_surface_destroy(tsurf);
1035 /* if tsruf pool is enabled, bo_num can be zero. */
1036 for (i = 0; i < MUSE_NUM_FD; i++)
1037 PLAYER_CLOSE_FD(recv_data->tfd[i]);
1039 for (i = 0; i < bo_num; i++) {
1041 tbm_bo_unref(bo[i]);
1043 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1045 if (cb_info && v_data)
1046 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, MUSE_TYPE_POINTER, "v_data", v_data);
1051 static void __media_packet_audio_frame_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1053 int ret = MEDIA_FORMAT_ERROR_NONE;
1055 tbm_bo_handle thandle;
1056 int key = INVALID_DEFAULT_VALUE;
1057 player_audio_decoded_data_info_t audio;
1058 media_packet_h pkt = NULL;
1059 media_format_h fmt = NULL;
1060 _media_pkt_audio_fin_data *fin_data = NULL;
1062 if (!player_msg_get(key, recv_data->buffer)) {
1063 LOGE("failed to get key value from msg.");
1067 if (recv_data->tfd[0] < 0) {
1068 LOGE("failed to get tbm_fd(key:%d)", key);
1072 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
1074 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
1078 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
1079 if (thandle.ptr == NULL) {
1080 LOGE("TBM get error : handle pointer is NULL");
1084 memcpy(&audio, thandle.ptr, sizeof(player_audio_decoded_data_info_t));
1085 audio.data = thandle.ptr + sizeof(player_audio_decoded_data_info_t);
1088 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
1089 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME]) {
1090 ret = media_format_create(&fmt);
1091 if (ret != MEDIA_FORMAT_ERROR_NONE || !fmt) {
1092 LOGE("failed to create media format 0x%X %p", ret, fmt);
1096 ret = media_format_set_audio_mime(fmt, audio.pcm_format);
1097 ret |= media_format_set_audio_samplerate(fmt, audio.rate);
1098 ret |= media_format_set_audio_channel(fmt, audio.channel);
1099 ret |= media_format_set_audio_channel_mask(fmt, audio.channel_mask);
1100 if (ret != MEDIA_FORMAT_ERROR_NONE) {
1101 LOGE("failed to set audio format 0x%X", ret);
1105 fin_data = g_new0(_media_pkt_audio_fin_data, 1);
1107 LOGE("failed to alloc fin_data");
1111 fin_data->key = key;
1112 fin_data->fd = cb_info->fd;
1115 /* Keep the fd id to check validation when the pkt is destroyed. */
1116 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
1118 ret = media_packet_create_from_external_memory(fmt, audio.data, audio.size,
1119 (media_packet_finalize_cb)_player_audio_media_packet_finalize, (void *)fin_data, &pkt);
1120 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
1121 LOGE("failed to create media packet 0x%X %p", ret, pkt);
1123 media_packet_destroy(pkt); /* fin_data will be free in finalize function. */
1129 media_format_unref(fmt);
1132 ((player_media_packet_audio_decoded_cb)cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME])
1133 (pkt, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME]);
1135 LOGE("there is no registered cb");
1140 PLAYER_CLOSE_FD(recv_data->tfd[0]);
1142 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1145 media_format_unref(fmt);
1148 if ((cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] == NULL) &&
1149 (key > INVALID_DEFAULT_VALUE)) {
1151 if (bo) tbm_bo_unref(bo);
1153 /* LOGD("send msg to release buffer. key:%d", key); */
1154 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
1160 static void __video_frame_render_error_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1164 static void __supported_audio_effect_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1168 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1172 static void __missed_plugin_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1176 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1178 /* player_media_stream_buffer_status_e status; */
1181 if (player_msg_get(status, recv_data->buffer)) {
1182 ((player_media_stream_buffer_status_cb)
1183 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS])
1184 ((player_media_stream_buffer_status_e)status,
1185 cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]);
1189 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1191 /* player_media_stream_buffer_status_e status; */
1194 if (player_msg_get(status, recv_data->buffer)) {
1195 ((player_media_stream_buffer_status_cb)
1196 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
1197 ((player_media_stream_buffer_status_e) status,
1198 cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
1203 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1205 /* player_media_stream_buffer_status_e status; */
1207 unsigned long long bytes;
1210 ret = _player_get_param_value(recv_data->buffer,
1211 MUSE_TYPE_INT, "status", (void *)&status,
1212 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1213 INVALID_MUSE_TYPE_VALUE);
1215 ((player_media_stream_buffer_status_cb_ex)
1216 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
1217 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
1221 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1223 /* player_media_stream_buffer_status_e status; */
1225 unsigned long long bytes;
1228 ret = _player_get_param_value(recv_data->buffer,
1229 MUSE_TYPE_INT, "status", (void *)&status,
1230 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1231 INVALID_MUSE_TYPE_VALUE);
1233 ((player_media_stream_buffer_status_cb_ex)
1234 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
1235 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
1240 static void __media_stream_video_seek_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1242 unsigned long long offset;
1244 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1245 ((player_media_stream_seek_cb)
1246 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
1247 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
1251 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1253 unsigned long long offset;
1255 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1256 ((player_media_stream_seek_cb)
1257 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
1258 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1262 static void __video_stream_changed_cb_handler(callback_cb_info_s *cb_info, _player_recv_data *recv_data)
1268 bool ret_val = TRUE;
1269 ret_val = _player_get_param_value(recv_data->buffer,
1270 MUSE_TYPE_INT, "width", (void *)&width,
1271 MUSE_TYPE_INT, "height", (void *)&height,
1272 MUSE_TYPE_INT, "fps", (void *)&fps,
1273 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
1274 INVALID_MUSE_TYPE_VALUE);
1276 ((player_video_stream_changed_cb)cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1277 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1281 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM])(callback_cb_info_s *cb_info, _player_recv_data *recv_data) = {
1282 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1283 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1284 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1285 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1286 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1287 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1288 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1289 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1290 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1291 __media_packet_audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME */
1292 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1293 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1294 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1295 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1296 #ifdef _PLAYER_FOR_PRODUCT
1297 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1298 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1300 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1301 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1302 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1303 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1304 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1305 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1306 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1307 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1308 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1309 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1312 gboolean _player_event_job_function(void *user_data)
1314 _player_cb_data *data = (_player_cb_data *)user_data;
1315 muse_player_event_e ev;
1317 if (!data || !data->cb_info) {
1318 LOGE("invalid user data");
1322 ev = data->int_data;
1323 if ((ev != MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) &&
1324 (ev != MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME))
1325 LOGD("enter ev:%d(%p)", ev, data);
1327 /* remove event from list */
1328 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1329 if (data->cb_info->event_queue.idle_ev_list) {
1330 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1331 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1333 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1335 if ((data->cb_info->user_cb[ev] || ev == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) &&
1336 (_user_callbacks[ev]))
1337 _user_callbacks[ev](data->cb_info, data->recv_data);
1339 LOGW("user callback is unset. type : %d", ev);
1341 return FALSE; /* remove from the event list */
1344 static bool _player_need_sync_context(int event_id)
1346 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1347 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1348 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1349 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1350 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1351 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1352 LOGD("%d callback will be issued in the mainloop.", event_id);
1359 static void _destroy_event_data(gpointer user_data)
1361 _player_cb_data *data = (_player_cb_data *)user_data;
1364 LOGW("data is null");
1368 LOGD("remove event data %p (%d)", data, data->int_data);
1369 if (data->recv_data) {
1370 g_free(data->recv_data->buffer);
1371 data->recv_data->buffer = NULL;
1372 g_free(data->recv_data);
1373 data->recv_data = NULL;
1379 static void *_player_event_queue_loop(void *param)
1382 LOGE("NULL parameter");
1385 callback_cb_info_s *cb_info = param;
1386 player_event_queue *ev = &cb_info->event_queue;
1387 _player_cb_data *event_data = NULL;
1389 g_mutex_lock(&ev->mutex);
1390 while (ev->running) {
1391 g_mutex_lock(&ev->qlock);
1392 if (g_queue_is_empty(ev->queue)) {
1393 g_mutex_unlock(&ev->qlock);
1394 g_cond_wait(&ev->cond, &ev->mutex);
1398 g_mutex_unlock(&ev->qlock);
1401 g_mutex_lock(&ev->qlock);
1402 event_data = (_player_cb_data *)g_queue_pop_head(ev->queue);
1403 g_mutex_unlock(&ev->qlock);
1408 muse_player_event_e event_type = event_data->int_data;
1410 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1411 g_mutex_lock(&cb_info->seek_cb_mutex);
1412 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1413 /* push event into queue again. */
1414 _player_event_queue_add(ev, event_data);
1415 g_mutex_unlock(&cb_info->seek_cb_mutex);
1418 g_mutex_unlock(&cb_info->seek_cb_mutex);
1419 } else if (event_type == MUSE_PLAYER_EVENT_TYPE_BUFFERING) {
1420 g_mutex_lock(&cb_info->buffering_cb_mutex);
1421 if (cb_info->drop_buffering_message) {
1422 LOGD("Drop buffering event");
1423 g_mutex_unlock(&cb_info->buffering_cb_mutex);
1425 _destroy_event_data(event_data);
1428 g_mutex_unlock(&cb_info->buffering_cb_mutex);
1431 if (_player_need_sync_context(event_type)) {
1432 if ((cb_info->user_cb[event_type] || (event_type == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED)) &&
1433 _user_callbacks[event_type]) {
1434 g_mutex_lock(&ev->idle_ev_mutex);
1435 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1436 g_mutex_unlock(&ev->idle_ev_mutex);
1438 LOGD("add ev %d to main loop", event_type);
1440 g_idle_add_full(G_PRIORITY_DEFAULT,
1441 (GSourceFunc)_player_event_job_function,
1442 (gpointer)event_data,
1443 (GDestroyNotify)_destroy_event_data);
1445 LOGW("there is no registered cb for ev:%d", event_type);
1446 _destroy_event_data(event_data);
1449 _player_event_job_function(event_data);
1450 _destroy_event_data(event_data);
1454 g_mutex_unlock(&ev->mutex);
1455 LOGI("Exit event loop");
1459 static gboolean _player_event_queue_new(callback_cb_info_s *cb_info)
1461 g_return_val_if_fail(cb_info, FALSE);
1462 player_event_queue *ev = &cb_info->event_queue;
1464 ev->queue = g_queue_new();
1465 g_return_val_if_fail(ev->queue, FALSE);
1466 g_mutex_init(&ev->qlock);
1468 g_mutex_init(&ev->mutex);
1469 g_cond_init(&ev->cond);
1472 g_mutex_init(&ev->idle_ev_mutex);
1474 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer)cb_info);
1475 g_return_val_if_fail(ev->thread, FALSE);
1476 LOGI("event queue thread %p", ev->thread);
1482 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1484 g_return_if_fail(cb_info);
1485 player_event_queue *ev = &cb_info->event_queue;
1486 _player_cb_data *event_data = NULL;
1489 g_mutex_lock(&ev->idle_ev_mutex);
1491 if (ev->idle_ev_list == NULL) {
1492 LOGD("No idle event is remained.");
1493 g_mutex_unlock(&ev->idle_ev_mutex);
1497 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1499 list = ev->idle_ev_list;
1501 event_data = list->data;
1502 list = g_list_next(list);
1505 LOGW("Fail to remove idle event. The data is NULL");
1509 if ((event_data->int_data != event_type) && !remove_all)
1512 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1514 /* set cb to null */
1516 set_null_user_cb(cb_info, event_data->int_data);
1518 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1520 if (!g_idle_remove_by_data(event_data))
1521 LOGW("failed to find source with %p", event_data);
1525 g_list_free(ev->idle_ev_list);
1526 ev->idle_ev_list = NULL;
1529 g_mutex_unlock(&ev->idle_ev_mutex);
1535 static void _player_event_queue_destroy(callback_cb_info_s *cb_info)
1537 g_return_if_fail(cb_info);
1538 player_event_queue *ev = &cb_info->event_queue;
1539 _player_cb_data *event_data;
1541 LOGI("event queue thread %p", ev->thread);
1543 g_mutex_lock(&ev->mutex);
1544 ev->running = FALSE;
1545 g_cond_broadcast(&ev->cond);
1546 g_mutex_unlock(&ev->mutex);
1548 g_thread_join(ev->thread);
1551 while (!g_queue_is_empty(ev->queue)) {
1552 event_data = (_player_cb_data *)g_queue_pop_head(ev->queue);
1554 g_free(event_data->recv_data->buffer);
1555 g_free(event_data->recv_data);
1559 g_queue_free(ev->queue);
1560 g_mutex_clear(&ev->qlock);
1561 g_mutex_clear(&ev->mutex);
1562 g_cond_clear(&ev->cond);
1563 g_mutex_clear(&ev->idle_ev_mutex);
1566 static void _player_event_queue_remove(player_event_queue *ev_queue, int ev)
1570 g_mutex_lock(&ev_queue->qlock);
1572 item = g_queue_peek_head_link(ev_queue->queue);
1574 GList *next = item->next;
1575 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1577 if (cb_data && cb_data->int_data == ev) {
1578 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1579 g_free(cb_data->recv_data->buffer);
1580 g_free(cb_data->recv_data);
1583 g_queue_delete_link(ev_queue->queue, item);
1587 g_mutex_unlock(&ev_queue->qlock);
1590 static void _player_event_queue_add(player_event_queue *ev, _player_cb_data *data)
1593 g_mutex_lock(&ev->qlock);
1594 g_queue_push_tail(ev->queue, (gpointer)data);
1595 g_mutex_unlock(&ev->qlock);
1596 g_cond_signal(&ev->cond);
1600 static bool _user_callback_handler(callback_cb_info_s *cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1602 /* LOGD("get event %d", event); */
1604 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1605 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1606 _player_cb_data *data = NULL;
1607 data = g_new(_player_cb_data, 1);
1609 LOGE("fail to alloc mem");
1612 data->int_data = (int)event;
1613 data->cb_info = cb_info;
1614 data->recv_data = recv_data;
1615 _player_event_queue_add(&cb_info->event_queue, data);
1621 LOGE("failed to add event to queue %d", event);
1625 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s *cb_info, int offset, int parse_len)
1627 ret_msg_s *msg = NULL;
1628 ret_msg_s *last = cb_info->buff.retMsgHead;
1630 msg = g_new(ret_msg_s, 1);
1633 msg->msg = g_strndup(cb_info->buff.recvMsg + offset, parse_len);
1636 cb_info->buff.retMsgHead = msg;
1643 LOGE("g_new failure");
1646 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s *cb_info)
1648 ret_msg_s *msg = cb_info->buff.retMsgHead;
1649 ret_msg_s *prev = NULL;
1651 if (msg->api == api) {
1653 cb_info->buff.retMsgHead = msg->next;
1655 prev->next = msg->next;
1664 static void _remove_all_ret_msg(callback_cb_info_s *cb_info)
1666 ret_msg_s *msg = cb_info->buff.retMsgHead;
1667 ret_msg_s *prev = NULL;
1671 LOGI("Remove %s", prev->msg);
1678 static void _notify_disconnected(callback_cb_info_s *cb_info)
1680 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1681 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1684 if (_user_callbacks[event]) {
1685 _player_cb_data *data = NULL;
1686 data = g_new(_player_cb_data, 1);
1688 LOGE("fail to alloc mem");
1691 data->int_data = (int)event;
1692 data->cb_info = cb_info;
1693 data->recv_data = NULL;
1694 _player_event_queue_add(&cb_info->event_queue, data);
1698 static void *client_cb_handler(gpointer data)
1704 callback_cb_info_s *cb_info = data;
1705 char *recvMsg = NULL;
1706 muse_core_msg_parse_err_e err;
1707 tbm_fd tfd[MUSE_NUM_FD];
1709 while (g_atomic_int_get(&cb_info->running)) {
1711 err = MUSE_MSG_PARSE_ERROR_NONE;
1713 len = player_recv_msg(cb_info, tfd);
1717 recvMsg = cb_info->buff.recvMsg;
1718 recvMsg[len] = '\0';
1722 while (offset < len) {
1723 api = MUSE_PLAYER_API_MAX;
1724 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1725 // usleep(10 * 1000);
1727 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1729 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1730 if (api < MUSE_PLAYER_API_MAX) {
1731 g_mutex_lock(&cb_info->player_mutex);
1732 cb_info->buff.recved++;
1733 _add_ret_msg(api, cb_info, offset, parse_len);
1734 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1735 LOGD("get tbm fd for album art.");
1736 cb_info->tfd = tfd[0];
1738 g_cond_signal(&cb_info->player_cond[api]);
1739 g_mutex_unlock(&cb_info->player_mutex);
1740 if (api == MUSE_PLAYER_API_DESTROY)
1741 g_atomic_int_set(&cb_info->running, 0);
1742 } else if (api == MUSE_PLAYER_CB_EVENT) {
1744 _player_recv_data *recv_data = NULL;
1745 g_mutex_lock(&cb_info->player_mutex);
1746 recv_data = g_new0(_player_recv_data, 1);
1747 if (recv_data != NULL) {
1748 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1749 recv_data->buffer = g_strndup(recvMsg + offset, parse_len);
1751 LOGE("failed to alloc recv_data.");
1752 g_mutex_unlock(&cb_info->player_mutex);
1753 muse_core_msg_object_free(jobj);
1756 g_mutex_unlock(&cb_info->player_mutex);
1757 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1758 !_user_callback_handler(cb_info, event, recv_data)) {
1759 LOGE("failed to get value or add event to the queue.");
1761 g_free(recv_data->buffer);
1765 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1766 g_mutex_lock(&cb_info->player_mutex);
1767 cb_info->buff.recved++;
1768 g_cond_signal(&cb_info->server_ack_cond);
1769 g_mutex_unlock(&cb_info->player_mutex);
1772 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg + offset));
1774 muse_core_msg_object_free(jobj);
1776 LOGE("Failed to get msg obj. err:%d", err);
1779 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1782 offset += parse_len;
1783 parse_len = len - offset;
1786 if (g_atomic_int_get(&cb_info->running))
1787 _notify_disconnected(cb_info);
1789 g_atomic_int_set(&cb_info->running, 0);
1790 LOGD("client cb exit");
1795 static callback_cb_info_s *callback_new(gint sockfd)
1797 callback_cb_info_s *cb_info;
1801 g_return_val_if_fail(sockfd > 0, NULL);
1803 cb_info = g_new(callback_cb_info_s, 1);
1806 memset(cb_info, 0, sizeof(callback_cb_info_s));
1808 g_mutex_init(&cb_info->player_mutex);
1809 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1810 g_cond_init(&cb_info->player_cond[i]);
1811 g_cond_init(&cb_info->server_ack_cond);
1813 g_mutex_init(&cb_info->data_mutex);
1814 g_mutex_init(&cb_info->seek_cb_mutex);
1815 g_mutex_init(&cb_info->buffering_cb_mutex);
1816 cb_info->drop_buffering_message = FALSE;
1818 buff = &cb_info->buff;
1819 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1820 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1822 buff->retMsgHead = NULL;
1823 buff->part_of_msg = NULL;
1825 g_atomic_int_set(&cb_info->running, 1);
1826 cb_info->fd = sockfd;
1827 cb_info->tfd = INVALID_DEFAULT_VALUE;
1828 cb_info->data_fd = INVALID_DEFAULT_VALUE;
1829 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1834 static void callback_destroy(callback_cb_info_s *cb_info)
1837 g_return_if_fail(cb_info);
1839 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1840 muse_client_close(cb_info->fd);
1841 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1842 muse_client_close(cb_info->data_fd);
1844 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1846 g_thread_join(cb_info->thread);
1847 cb_info->thread = NULL;
1849 LOGI("%p Callback destroyed", cb_info);
1851 for (i = 0; i < MUSE_PLAYER_API_MAX; i++) {
1852 g_mutex_lock(&cb_info->player_mutex);
1853 g_cond_signal(&cb_info->player_cond[i]);
1854 g_mutex_unlock(&cb_info->player_mutex);
1855 g_cond_clear(&cb_info->player_cond[i]);
1858 /* to make sure the return of other pending api */
1860 g_mutex_lock(&cb_info->player_mutex);
1861 g_mutex_unlock(&cb_info->player_mutex);
1862 g_mutex_clear(&cb_info->player_mutex);
1864 g_cond_clear(&cb_info->server_ack_cond);
1866 g_mutex_clear(&cb_info->data_mutex);
1867 g_mutex_clear(&cb_info->seek_cb_mutex);
1868 g_mutex_clear(&cb_info->buffering_cb_mutex);
1870 g_free(cb_info->buff.recvMsg);
1871 _remove_all_ret_msg(cb_info);
1872 g_free(cb_info->buff.part_of_msg);
1877 int client_get_api_timeout(player_cli_s *pc, muse_player_api_e api)
1882 case MUSE_PLAYER_API_PREPARE:
1883 case MUSE_PLAYER_API_PREPARE_ASYNC:
1884 case MUSE_PLAYER_API_UNPREPARE:
1885 case MUSE_PLAYER_API_START:
1886 case MUSE_PLAYER_API_STOP:
1887 case MUSE_PLAYER_API_PAUSE:
1888 timeout += SERVER_TIMEOUT(pc);
1891 /* check prepare async is done */
1892 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1893 timeout += SERVER_TIMEOUT(pc);
1896 timeout += CALLBACK_TIME_OUT;
1897 return timeout; /* ms */
1900 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s *cb_info, char **ret_buf, int time_out)
1902 int ret = PLAYER_ERROR_NONE;
1903 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1904 msg_buff_s *buff = &cb_info->buff;
1905 ret_msg_s *msg = NULL;
1907 g_mutex_lock(&cb_info->player_mutex);
1909 msg = _get_ret_msg(api, cb_info);
1911 if (!buff->recved || !msg) {
1912 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1913 LOGW("api %d return msg does not received %dms", api, time_out);
1914 ret = PLAYER_ERROR_INVALID_OPERATION;
1920 msg = _get_ret_msg(api, cb_info);
1922 *ret_buf = msg->msg;
1925 if (!player_msg_get(ret, *ret_buf))
1926 ret = PLAYER_ERROR_INVALID_OPERATION;
1927 else if (ret != PLAYER_ERROR_NONE)
1928 LOGE("Get error return from server 0x%X", ret);
1932 if (!g_atomic_int_get(&cb_info->running)) {
1933 LOGE("callback thread is stopped. %d api did not get return in time", api);
1934 ret = PLAYER_ERROR_INVALID_OPERATION;
1937 LOGW("api %d is the spurious wakeup, wait again", api);
1939 } while (!msg && g_atomic_int_get(&cb_info->running));
1941 g_mutex_unlock(&cb_info->player_mutex);
1945 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s *cb_info, int time_out)
1947 int ret = PLAYER_ERROR_NONE;
1948 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1949 msg_buff_s *buff = &cb_info->buff;
1951 g_mutex_lock(&cb_info->player_mutex);
1953 if (!buff->recved) {
1954 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1955 LOGW("server ack msg does not received %dms", time_out);
1957 ret = PLAYER_ERROR_INVALID_OPERATION;
1959 LOGD("Another msg is received, continue create handle");
1960 g_mutex_unlock(&cb_info->player_mutex);
1966 g_mutex_unlock(&cb_info->player_mutex);
1973 * Public Implementation
1976 int player_create(player_h *player)
1978 int ret = PLAYER_ERROR_NONE;
1979 int sock_fd = INVALID_DEFAULT_VALUE;
1982 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1983 int module_index = INVALID_DEFAULT_VALUE;
1984 player_cli_s *pc = NULL;
1985 gchar *ret_buf = NULL;
1986 int retry_count = CONNECTION_RETRY;
1988 PLAYER_INSTANCE_CHECK(player);
1992 pc = g_new0(player_cli_s, 1);
1994 return PLAYER_ERROR_OUT_OF_MEMORY;
1996 while (retry_count--) {
1997 ret = PLAYER_ERROR_NONE;
1998 sock_fd = muse_client_new();
1999 if (sock_fd <= INVALID_DEFAULT_VALUE) {
2000 LOGE("connection failure %d", errno);
2001 ret = PLAYER_ERROR_INVALID_OPERATION;
2002 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
2006 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2007 LOGE("muse client get module index failed");
2008 ret = PLAYER_ERROR_INVALID_OPERATION;
2012 PLAYER_SEND_MSG_ASYNC(api, sock_fd, ret,
2013 MUSE_TYPE_INT, "module", module_index,
2014 MUSE_TYPE_INT, "pid", pid);
2015 if (ret == PLAYER_ERROR_INVALID_OPERATION)
2018 pc->cb_info = callback_new(sock_fd);
2020 LOGE("fail to create callback");
2021 ret = PLAYER_ERROR_INVALID_OPERATION;
2025 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
2026 if (ret == PLAYER_ERROR_INVALID_OPERATION)
2029 if (!_player_event_queue_new(pc->cb_info)) {
2030 LOGE("fail to create event queue");
2031 ret = PLAYER_ERROR_INVALID_OPERATION;
2035 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
2036 if (ret == PLAYER_ERROR_NONE) {
2037 intptr_t module_addr = 0;
2038 *player = (player_h)pc;
2039 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
2040 pc->cb_info->data_fd = muse_client_new_data_ch();
2041 if ((pc->cb_info->data_fd < 0) || (!muse_core_fd_is_valid(pc->cb_info->data_fd))) {
2042 LOGE("Failed to get data_fd");
2043 ret = PLAYER_ERROR_INVALID_OPERATION;
2047 /* share the module addr info to the data_fd */
2048 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_CREATE, pc->cb_info->data_fd, ret,
2049 MUSE_TYPE_POINTER, "module_addr", module_addr);
2050 if (ret != PLAYER_ERROR_NONE) {
2051 LOGE("Failed to send module address to the data fd");
2054 LOGD("Data channel fd %d, muse module addr %"PRIxPTR, pc->cb_info->data_fd, module_addr);
2056 ret = PLAYER_ERROR_INVALID_OPERATION;
2059 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
2064 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
2065 pc->push_media_stream = FALSE;
2067 /* get display interface handle */
2068 if (mm_display_interface_init(&DP_INTERFACE(pc)) != MM_ERROR_NONE)
2069 LOGW("display interface init failed");
2073 LOGD("LEAVE 0x%X", ret);
2079 if (pc && pc->cb_info) {
2080 if (pc->cb_info->event_queue.running)
2081 _player_event_queue_destroy(pc->cb_info);
2082 callback_destroy(pc->cb_info);
2084 } else if (sock_fd > INVALID_DEFAULT_VALUE) {
2085 muse_client_close(sock_fd);
2087 sock_fd = INVALID_DEFAULT_VALUE;
2091 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
2097 LOGD("LEAVE 0x%X", ret);
2101 int player_destroy(player_h player)
2103 int ret = PLAYER_ERROR_NONE;
2104 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
2105 player_cli_s *pc = (player_cli_s *)player;
2106 char *ret_buf = NULL;
2107 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2109 PLAYER_INSTANCE_CHECK(player);
2111 LOGD("ENTER %p", pc);
2113 /* clear cb and release mem */
2114 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2115 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2116 _player_release_internal_memory(pc, true);
2118 if (DP_INTERFACE(pc)) {
2119 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2121 if (display_type == MM_DISPLAY_TYPE_EVAS) {
2122 player_unset_media_packet_video_frame_decoded_cb(player);
2123 __player_unset_retrieve_buffer_cb(player);
2126 mm_display_interface_deinit(DP_INTERFACE(pc));
2127 DP_INTERFACE(pc) = NULL;
2130 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2132 if (CALLBACK_INFO(pc)) {
2133 __player_remove_tsurf_list(pc);
2134 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
2135 _player_event_queue_destroy(CALLBACK_INFO(pc));
2136 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
2138 callback_destroy(CALLBACK_INFO(pc));
2146 LOGD("LEAVE 0x%X", ret);
2150 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
2152 int ret = PLAYER_ERROR_NONE;
2153 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
2154 player_cli_s *pc = (player_cli_s *)player;
2155 char *ret_buf = NULL;
2157 PLAYER_INSTANCE_CHECK(player);
2159 LOGD("ENTER %p %p", pc, callback);
2161 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
2162 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
2163 return PLAYER_ERROR_INVALID_OPERATION;
2165 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
2166 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
2168 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2169 if (ret == PLAYER_ERROR_NONE) {
2171 player_msg_get_type(timeout, ret_buf, INT);
2173 LOGD("server timeout will be %d sec", timeout);
2174 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2176 LOGW("failed to realize, so prepare cb will be released soon");
2177 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
2178 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2185 int player_prepare(player_h player)
2187 int ret = PLAYER_ERROR_NONE;
2188 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
2189 player_cli_s *pc = (player_cli_s *)player;
2190 char *ret_buf = NULL;
2192 PLAYER_INSTANCE_CHECK(player);
2194 LOGD("ENTER %p", pc);
2196 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2197 if (ret == PLAYER_ERROR_NONE) {
2199 player_msg_get_type(timeout, ret_buf, INT);
2201 LOGD("server timeout will be %d sec", timeout);
2202 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2207 LOGD("LEAVE 0x%X", ret);
2211 int player_unprepare(player_h player)
2213 int ret = PLAYER_ERROR_NONE;
2214 int mm_ret = MM_ERROR_NONE;
2215 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
2216 player_cli_s *pc = (player_cli_s *)player;
2217 char *ret_buf = NULL;
2218 player_state_e state = PLAYER_STATE_NONE;
2219 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2221 PLAYER_INSTANCE_CHECK(player);
2223 LOGD("ENTER %p", pc);
2225 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2226 LOGE("Failed to get state");
2227 ret = PLAYER_ERROR_INVALID_OPERATION;
2231 if (state < PLAYER_STATE_READY) {
2232 if ((!CALLBACK_INFO(pc)) || (!CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])) {
2233 LOGE("Invalid state %d", state);
2234 ret = PLAYER_ERROR_INVALID_STATE;
2239 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2240 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2242 if (!DP_INTERFACE(pc))
2243 goto _PLAYER_UNPREPARE;
2246 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2248 if (display_type != MM_DISPLAY_TYPE_EVAS)
2249 goto _PLAYER_UNPREPARE;
2251 if (CALLBACK_INFO(pc)->dp_info.visible != PLAYER_VISIBLE_INFO_FALSE) {
2252 mm_ret = mm_display_interface_evas_set_visible(DP_INTERFACE(pc), false);
2253 if (mm_ret != MM_ERROR_NONE) {
2254 LOGE("mm_display_interface_evas_set_visible failed 0x%x", mm_ret);
2255 return PLAYER_ERROR_INVALID_OPERATION;
2259 mm_ret = mm_display_interface_evas_flush(DP_INTERFACE(pc), false);
2260 if (mm_ret != MM_ERROR_NONE) {
2261 LOGE("mm_display_interface_evas_flush failed 0x%x", mm_ret);
2262 return PLAYER_ERROR_INVALID_OPERATION;
2266 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2268 _player_release_internal_memory(pc, false);
2269 pc->cb_info->video_frame_pool_size = 0;
2270 __player_remove_tsurf_list(pc);
2275 LOGD("LEAVE 0x%X", ret);
2279 /* 1. correct the protocol prefix to lower case
2280 * 2. remove 'file://' prefix
2281 * 3. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' */
2282 int _player_get_valid_path(const char *uri, char *valid_path)
2284 gchar *file_path = NULL;
2286 gchar *colon = NULL;
2288 if (!uri || !valid_path) {
2289 LOGD("invalid parameter");
2290 return PLAYER_ERROR_INVALID_PARAMETER;
2293 if ((colon = strstr(uri, "://")) != NULL) {
2294 gchar *protocol = g_ascii_strdown(uri, colon - uri);
2298 file_path = g_strconcat(protocol, uri + strlen(protocol), NULL);
2299 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN - 1);
2305 if (strstr(valid_path, "file://")) { /* handle the 'file://' prefix */
2307 file_path = g_filename_from_uri(valid_path, NULL, &err);
2308 if (!file_path || (err != NULL)) {
2309 SECURE_LOGE("Invalid URI '%s', err: %s", uri,
2310 (err != NULL) ? err->message : "unknown error");
2315 return PLAYER_ERROR_INVALID_PARAMETER;
2317 LOGD("get file path from uri");
2319 LOGD("use the original path.");
2320 return PLAYER_ERROR_NONE;
2325 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, valid_path) < 0) {
2326 /* cannot convert path. use the original one. */
2327 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN - 1);
2329 /* need to use converted path. */
2330 SECURE_LOGD("Converted path : %s -> %s", uri, valid_path);
2335 return PLAYER_ERROR_NONE;
2338 int player_set_uri(player_h player, const char *uri)
2340 int ret = PLAYER_ERROR_NONE;
2341 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2342 player_cli_s *pc = (player_cli_s *)player;
2343 char *ret_buf = NULL;
2344 char path[MAX_URL_LEN] = {0, };
2346 PLAYER_INSTANCE_CHECK(player);
2347 PLAYER_NULL_ARG_CHECK(uri);
2351 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
2352 return PLAYER_ERROR_INVALID_PARAMETER;
2354 SECURE_LOGD("new path : %s", path);
2356 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", (const char *)path);
2357 pc->push_media_stream = FALSE;
2363 int player_set_memory_buffer(player_h player, const void *data, int size)
2365 int ret = PLAYER_ERROR_NONE;
2366 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2367 player_cli_s *pc = (player_cli_s *)player;
2368 char *ret_buf = NULL;
2370 tbm_bo_handle thandle;
2371 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2373 PLAYER_INSTANCE_CHECK(player);
2374 PLAYER_NULL_ARG_CHECK(data);
2378 /* before setting mem buffer, player state have to be checked. */
2379 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2381 if (SERVER_TBM_BO(pc)) {
2382 LOGW("The previous memory buffer will be cleared.");
2383 _player_deinit_memory_buffer(pc);
2386 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2388 LOGE("TBM get error : bo is NULL");
2389 return PLAYER_ERROR_INVALID_OPERATION;
2391 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2392 if (thandle.ptr == NULL) {
2393 LOGE("TBM get error : handle pointer is NULL");
2394 ret = PLAYER_ERROR_INVALID_OPERATION;
2397 memcpy(thandle.ptr, data, size);
2400 tfd = tbm_bo_export_fd(bo);
2402 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2403 ret = PLAYER_ERROR_INVALID_OPERATION;
2407 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret, MUSE_TYPE_INT, "size", size);
2408 pc->push_media_stream = FALSE;
2411 PLAYER_CLOSE_FD(tfd);
2415 if (ret == PLAYER_ERROR_NONE) {
2416 intptr_t bo_addr = 0;
2417 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2418 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2425 static void _player_release_internal_memory(player_cli_s *pc, bool deinit_server_mem)
2432 if (deinit_server_mem)
2433 _player_deinit_memory_buffer(pc);
2436 static int _player_deinit_memory_buffer(player_cli_s *pc)
2438 PLAYER_INSTANCE_CHECK(pc);
2439 int ret = PLAYER_ERROR_NONE;
2440 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2441 intptr_t bo_addr = SERVER_TBM_BO(pc);
2443 if (!bo_addr || !CALLBACK_INFO(pc))
2446 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_POINTER, "bo_addr", bo_addr);
2447 SERVER_TBM_BO(pc) = 0;
2452 int player_get_state(player_h player, player_state_e *pstate)
2454 int ret = PLAYER_ERROR_NONE;
2455 player_cli_s *pc = (player_cli_s *)player;
2457 PLAYER_INSTANCE_CHECK(player);
2458 PLAYER_NULL_ARG_CHECK(pstate);
2462 ret = _get_current_state(pc, pstate);
2466 int player_set_volume(player_h player, float left, float right)
2468 int ret = PLAYER_ERROR_NONE;
2469 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2470 player_cli_s *pc = (player_cli_s *)player;
2471 char *ret_buf = NULL;
2473 PLAYER_INSTANCE_CHECK(player);
2474 PLAYER_RANGE_ARG_CHECK(left, 0, 1.0);
2475 PLAYER_RANGE_ARG_CHECK(right, 0, 1.0);
2477 /* not support to set different value into each channel */
2478 PLAYER_CHECK_CONDITION(left == right, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2480 LOGD("ENTER %f", left);
2482 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2483 MUSE_TYPE_DOUBLE, "volume", (double)left);
2489 int player_get_volume(player_h player, float *left, float *right)
2491 int ret = PLAYER_ERROR_NONE;
2492 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2493 player_cli_s *pc = (player_cli_s *)player;
2494 double volume = 0.0;
2495 char *ret_buf = NULL;
2497 PLAYER_INSTANCE_CHECK(player);
2498 PLAYER_NULL_ARG_CHECK(left && right);
2502 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2504 if (ret == PLAYER_ERROR_NONE) {
2505 bool ret_val = true;
2506 ret_val = _player_get_param_value(ret_buf,
2507 MUSE_TYPE_DOUBLE, "volume", (void *)&volume,
2508 INVALID_MUSE_TYPE_VALUE);
2510 *left = (float)volume;
2511 *right = (float)volume;
2513 LOGE("failed to get value from msg");
2514 ret = PLAYER_ERROR_INVALID_OPERATION;
2522 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2524 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2525 player_cli_s *pc = (player_cli_s *)player;
2526 bool is_available = false;
2527 char *ret_buf = NULL;
2529 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SOUND_STREAM);
2530 PLAYER_INSTANCE_CHECK(player);
2531 PLAYER_NULL_ARG_CHECK(stream_info);
2535 /* check if stream_info is valid */
2536 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2537 if (ret != SOUND_MANAGER_ERROR_NONE) {
2538 LOGE("failed to checking available stream info");
2539 return PLAYER_ERROR_INVALID_OPERATION;
2542 if (is_available == false) {
2543 ret = PLAYER_ERROR_INVALID_PARAMETER;
2545 char *stream_type = NULL;
2546 int stream_index = 0;
2547 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2548 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2549 if (ret == SOUND_MANAGER_ERROR_NONE)
2550 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2551 MUSE_TYPE_STRING, "stream_type", (const char *)stream_type,
2552 MUSE_TYPE_INT, "stream_index", stream_index);
2554 ret = PLAYER_ERROR_INVALID_OPERATION;
2557 LOGD("LEAVE ret: 0x%X", ret);
2564 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2566 int ret = PLAYER_ERROR_NONE;
2567 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2568 player_cli_s *pc = (player_cli_s *)player;
2569 char *ret_buf = NULL;
2571 PLAYER_INSTANCE_CHECK(player);
2572 PLAYER_RANGE_ARG_CHECK(latency_mode, AUDIO_LATENCY_MODE_LOW, AUDIO_LATENCY_MODE_HIGH);
2576 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "latency_mode", (int)latency_mode);
2581 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e *platency_mode)
2583 int ret = PLAYER_ERROR_NONE;
2584 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2585 player_cli_s *pc = (player_cli_s *)player;
2586 char *ret_buf = NULL;
2587 int latency_mode = -1;
2589 PLAYER_INSTANCE_CHECK(player);
2590 PLAYER_NULL_ARG_CHECK(platency_mode);
2594 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2596 if (ret == PLAYER_ERROR_NONE) {
2597 player_msg_get(latency_mode, ret_buf);
2598 *platency_mode = latency_mode;
2606 int player_start(player_h player)
2608 int ret = PLAYER_ERROR_NONE;
2609 muse_player_api_e api = MUSE_PLAYER_API_START;
2610 player_cli_s *pc = (player_cli_s *)player;
2611 char *ret_buf = NULL;
2612 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2614 PLAYER_INSTANCE_CHECK(player);
2616 LOGD("ENTER %p", pc);
2618 if (!DP_INTERFACE(pc))
2621 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2623 if (display_type != MM_DISPLAY_TYPE_EVAS ||
2624 CALLBACK_INFO(pc)->dp_info.visible == PLAYER_VISIBLE_INFO_FALSE)
2627 /* set proper visible to evas renderer */
2628 if (mm_display_interface_evas_set_visible(DP_INTERFACE(pc), true) != MM_ERROR_NONE) {
2629 LOGE("mm_display_interface_evas_set_visible failed");
2630 return PLAYER_ERROR_INVALID_OPERATION;
2633 /* avoid setting true at all times, when player is resumed */
2634 CALLBACK_INFO(pc)->dp_info.visible = PLAYER_VISIBLE_INFO_TRUE;
2637 g_mutex_lock(&pc->cb_info->buffering_cb_mutex);
2638 pc->cb_info->drop_buffering_message = TRUE;
2639 g_mutex_unlock(&pc->cb_info->buffering_cb_mutex);
2641 _player_remove_idle_event(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_BUFFERING, false);
2643 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2645 g_mutex_lock(&pc->cb_info->buffering_cb_mutex);
2646 pc->cb_info->drop_buffering_message = FALSE;
2647 g_mutex_unlock(&pc->cb_info->buffering_cb_mutex);
2651 LOGD("LEAVE 0x%X", ret);
2655 int player_stop(player_h player)
2657 int ret = PLAYER_ERROR_NONE;
2658 int mm_ret = MM_ERROR_NONE;
2659 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2660 player_cli_s *pc = (player_cli_s *)player;
2661 char *ret_buf = NULL;
2662 player_state_e state = PLAYER_STATE_NONE;
2663 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
2665 PLAYER_INSTANCE_CHECK(player);
2667 LOGD("ENTER %p", pc);
2669 /* check player state */
2670 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2671 LOGE("Failed to get state");
2672 return PLAYER_ERROR_INVALID_OPERATION;
2675 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2676 LOGE("Invalid state %d", state);
2677 return PLAYER_ERROR_INVALID_STATE;
2680 if (!DP_INTERFACE(pc))
2683 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
2685 if (display_type != MM_DISPLAY_TYPE_EVAS ||
2686 CALLBACK_INFO(pc)->dp_info.visible == PLAYER_VISIBLE_INFO_FALSE)
2689 mm_ret = mm_display_interface_evas_set_visible(DP_INTERFACE(pc), false);
2690 if (mm_ret != MM_ERROR_NONE) {
2691 LOGE("mm_display_interface_evas_set_visible failed 0x%x", mm_ret);
2692 return PLAYER_ERROR_INVALID_OPERATION;
2696 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2697 if (ret == PLAYER_ERROR_NONE)
2698 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2702 LOGD("LEAVE 0x%X", ret);
2706 int player_pause(player_h player)
2708 int ret = PLAYER_ERROR_NONE;
2709 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2710 player_cli_s *pc = (player_cli_s *)player;
2711 char *ret_buf = NULL;
2713 PLAYER_INSTANCE_CHECK(player);
2715 LOGD("ENTER %p", pc);
2717 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2720 LOGD("LEAVE 0x%X", ret);
2724 static int _set_play_position(player_h player, int64_t pos, bool accurate, player_seek_completed_cb callback, void *user_data)
2726 int ret = PLAYER_ERROR_NONE;
2727 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2728 player_cli_s *pc = (player_cli_s *)player;
2729 char *ret_buf = NULL;
2731 PLAYER_INSTANCE_CHECK(player);
2732 PLAYER_CHECK_CONDITION(pos >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2734 LOGD("ENTER %p", pc);
2737 LOGE("cb_info is null");
2738 return PLAYER_ERROR_INVALID_OPERATION;
2741 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2742 if ((pc->push_media_stream == FALSE) &&
2743 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2744 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2745 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2746 return PLAYER_ERROR_SEEK_FAILED;
2748 if (pc->push_media_stream == TRUE)
2749 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2751 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2752 LOGI("Event type : %d, pos : %"PRId64", accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, pos, accurate);
2753 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2754 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2756 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2758 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2759 MUSE_TYPE_INT64, "pos", pos,
2760 MUSE_TYPE_INT, "accurate", (int)accurate);
2762 if (ret != PLAYER_ERROR_NONE) {
2763 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2764 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2765 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2768 if (pc->push_media_stream == TRUE)
2769 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2773 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2774 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2775 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2777 LOGD("LEAVE 0x%X", ret);
2782 int player_set_play_position(player_h player, int milliseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2784 int ret = PLAYER_ERROR_NONE;
2785 int64_t pos = (int64_t)(milliseconds * G_GINT64_CONSTANT(1000000));
2787 PLAYER_INSTANCE_CHECK(player);
2788 PLAYER_CHECK_CONDITION(milliseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2792 ret = _set_play_position(player, pos, accurate, callback, user_data);
2794 LOGD("LEAVE 0x%X", ret);
2798 int player_set_play_position_nsec(player_h player, int64_t nanoseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2800 int ret = PLAYER_ERROR_NONE;
2801 int64_t pos = nanoseconds;
2803 PLAYER_INSTANCE_CHECK(player);
2804 PLAYER_CHECK_CONDITION(nanoseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2808 ret = _set_play_position(player, pos, accurate, callback, user_data);
2810 LOGD("LEAVE 0x%X", ret);
2814 static int _get_play_position(player_h player, int64_t *pos)
2816 int ret = PLAYER_ERROR_NONE;
2817 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2818 player_cli_s *pc = (player_cli_s *)player;
2819 char *ret_buf = NULL;
2821 PLAYER_INSTANCE_CHECK(player);
2822 PLAYER_NULL_ARG_CHECK(pos);
2824 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2826 if (ret == PLAYER_ERROR_NONE) {
2827 bool ret_val = true;
2828 ret_val = _player_get_param_value(ret_buf,
2829 MUSE_TYPE_INT64, "pos", (void *)pos,
2830 INVALID_MUSE_TYPE_VALUE);
2832 ret = PLAYER_ERROR_INVALID_OPERATION;
2840 int player_get_play_position(player_h player, int *milliseconds)
2842 int ret = PLAYER_ERROR_NONE;
2845 PLAYER_INSTANCE_CHECK(player);
2846 PLAYER_NULL_ARG_CHECK(milliseconds);
2848 /* LOGD("ENTER"); */
2850 ret = _get_play_position(player, &pos);
2851 if (ret == PLAYER_ERROR_NONE)
2852 *milliseconds = (int)(pos / G_GINT64_CONSTANT(1000000));
2857 int player_get_play_position_nsec(player_h player, int64_t *nanoseconds)
2859 int ret = PLAYER_ERROR_NONE;
2862 PLAYER_INSTANCE_CHECK(player);
2863 PLAYER_NULL_ARG_CHECK(nanoseconds);
2865 /* LOGD("ENTER"); */
2867 ret = _get_play_position(player, &pos);
2868 if (ret == PLAYER_ERROR_NONE)
2874 int player_set_mute(player_h player, bool muted)
2876 int ret = PLAYER_ERROR_NONE;
2877 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2878 player_cli_s *pc = (player_cli_s *)player;
2879 char *ret_buf = NULL;
2880 int mute = (int)muted;
2882 PLAYER_INSTANCE_CHECK(player);
2886 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mute", mute);
2891 int player_is_muted(player_h player, bool *muted)
2893 int ret = PLAYER_ERROR_NONE;
2894 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2895 player_cli_s *pc = (player_cli_s *)player;
2896 char *ret_buf = NULL;
2899 PLAYER_INSTANCE_CHECK(player);
2900 PLAYER_NULL_ARG_CHECK(muted);
2904 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2905 if (ret == PLAYER_ERROR_NONE) {
2906 player_msg_get(mute, ret_buf);
2907 *muted = (bool)mute;
2914 int player_set_looping(player_h player, bool looping)
2916 int ret = PLAYER_ERROR_NONE;
2917 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2918 player_cli_s *pc = (player_cli_s *)player;
2919 char *ret_buf = NULL;
2921 PLAYER_INSTANCE_CHECK(player);
2925 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "looping", (int)looping);
2930 int player_is_looping(player_h player, bool *plooping)
2932 int ret = PLAYER_ERROR_NONE;
2933 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2934 player_cli_s *pc = (player_cli_s *)player;
2935 char *ret_buf = NULL;
2938 PLAYER_INSTANCE_CHECK(player);
2939 PLAYER_NULL_ARG_CHECK(plooping);
2943 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2944 if (ret == PLAYER_ERROR_NONE) {
2945 player_msg_get(looping, ret_buf);
2946 *plooping = looping;
2952 static int _get_duration(player_h player, int64_t *duration)
2954 int ret = PLAYER_ERROR_NONE;
2955 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2956 player_cli_s *pc = (player_cli_s *)player;
2957 char *ret_buf = NULL;
2959 PLAYER_INSTANCE_CHECK(player);
2960 PLAYER_NULL_ARG_CHECK(duration);
2964 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2965 if (ret == PLAYER_ERROR_NONE) {
2966 bool ret_val = true;
2967 ret_val = _player_get_param_value(ret_buf,
2968 MUSE_TYPE_INT64, "duration", (void *)duration,
2969 INVALID_MUSE_TYPE_VALUE);
2971 ret = PLAYER_ERROR_INVALID_OPERATION;
2979 int player_get_duration(player_h player, int *milliseconds)
2981 int ret = PLAYER_ERROR_NONE;
2982 int64_t duration = 0; /* nsec */
2984 PLAYER_INSTANCE_CHECK(player);
2985 PLAYER_NULL_ARG_CHECK(milliseconds);
2989 ret = _get_duration(player, &duration);
2990 if (ret == PLAYER_ERROR_NONE) {
2991 /* convert time from ns to ms */
2992 *milliseconds = (int)(duration / G_GINT64_CONSTANT(1000000));
2995 LOGD("LEAVE 0x%X", ret);
2999 int player_get_duration_nsec(player_h player, int64_t *nanoseconds)
3001 int ret = PLAYER_ERROR_NONE;
3002 int64_t duration = 0; /* nsec */
3004 PLAYER_INSTANCE_CHECK(player);
3005 PLAYER_NULL_ARG_CHECK(nanoseconds);
3009 ret = _get_duration(player, &duration);
3010 if (ret == PLAYER_ERROR_NONE)
3011 *nanoseconds = duration;
3013 LOGD("LEAVE 0x%X", ret);
3017 /* The player_display_type_e is different at wearable profile */
3018 int _player_convert_display_type(player_display_type_e type, mm_display_type_e *out_type)
3020 int ret = PLAYER_ERROR_NONE;
3022 PLAYER_NULL_ARG_CHECK(out_type);
3025 case PLAYER_DISPLAY_TYPE_OVERLAY:
3026 *out_type = MM_DISPLAY_TYPE_OVERLAY;
3028 case PLAYER_DISPLAY_TYPE_OVERLAY_SYNC_UI:
3029 *out_type = MM_DISPLAY_TYPE_OVERLAY_SYNC_UI;
3031 case PLAYER_DISPLAY_TYPE_EVAS:
3032 *out_type = MM_DISPLAY_TYPE_EVAS;
3034 case PLAYER_DISPLAY_TYPE_NONE:
3035 *out_type = MM_DISPLAY_TYPE_NONE;
3038 ret = PLAYER_ERROR_INVALID_PARAMETER;
3042 LOGD("display type(%d) -> (%d)", type, *out_type);
3047 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
3049 int ret = PLAYER_ERROR_NONE;
3050 int mm_ret = MM_ERROR_NONE;
3051 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
3052 player_cli_s *pc = (player_cli_s *)player;
3053 char *ret_buf = NULL;
3054 wl_win_msg_type wl_win;
3055 char *wl_win_msg = (char *)&wl_win;
3056 mm_display_type_e conv_type = MM_DISPLAY_TYPE_NONE;
3057 int arr_msg_len = 0;
3058 pid_t pid = getpid();
3059 pid_t tid = syscall(SYS_gettid);
3061 PLAYER_INSTANCE_CHECK(player);
3063 if (type != PLAYER_DISPLAY_TYPE_NONE) {
3064 LOGD("Check if API is called in main thread. pid [%d], tid [%d]", pid, tid);
3066 LOGE("API isn't called in main thread");
3067 return PLAYER_ERROR_INVALID_OPERATION;
3071 /* check display interface handle */
3072 if (!DP_INTERFACE(pc)) {
3073 LOGE("display interface not supported");
3074 return PLAYER_ERROR_INVALID_OPERATION;
3077 LOGD("ENTER type: %d", type);
3079 /* before setting display, player state have to be checked. */
3080 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
3082 ret = _player_convert_display_type(type, &conv_type);
3083 if (ret != PLAYER_ERROR_NONE)
3086 if (conv_type != MM_DISPLAY_TYPE_NONE) {
3088 LOGE("type[%d] NULL handle for display", type);
3089 return PLAYER_ERROR_INVALID_PARAMETER;
3092 mm_ret = mm_display_interface_set_display(DP_INTERFACE(pc), conv_type, display, &wl_win.surface_id);
3093 if (mm_ret != MM_ERROR_NONE) {
3094 LOGE("[INVALID_OPERATION] set display failed[0x%x]", mm_ret);
3095 return PLAYER_ERROR_INVALID_OPERATION;
3098 if (conv_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3099 g_strlcpy(wl_win.exported_shell_handle, (char *)display, MAX_EXPORTED_SHELL_HANDLE_LEN);
3100 } else if (conv_type == MM_DISPLAY_TYPE_EVAS) {
3101 /* before evas handle is created, user could set display information */
3102 player_display_mode_e mode = PLAYER_DISPLAY_MODE_LETTER_BOX;
3103 player_display_rotation_e rotation = PLAYER_DISPLAY_ROTATION_NONE;
3104 bool visible = false;
3106 ret = player_get_display_mode(player, &mode);
3107 ret |= player_get_display_rotation(player, &rotation);
3108 ret |= player_is_display_visible(player, &visible);
3110 if (ret != PLAYER_ERROR_NONE) {
3111 LOGE("get current display settings");
3112 return PLAYER_ERROR_INVALID_OPERATION;
3115 LOGD("current setting : mode %d, rotation %d, visible %d, roi %d,%d,%dx%d",
3116 mode, rotation, visible,
3117 CALLBACK_INFO(pc)->dp_info.roi_x,
3118 CALLBACK_INFO(pc)->dp_info.roi_y,
3119 CALLBACK_INFO(pc)->dp_info.roi_w,
3120 CALLBACK_INFO(pc)->dp_info.roi_h);
3122 mm_ret = mm_display_interface_evas_set_mode(DP_INTERFACE(pc), mode);
3123 mm_ret |= mm_display_interface_evas_set_rotation(DP_INTERFACE(pc), rotation);
3124 mm_ret |= mm_display_interface_evas_set_visible(DP_INTERFACE(pc), visible);
3125 if (mode == PLAYER_DISPLAY_MODE_DST_ROI) {
3126 mm_ret |= mm_display_interface_evas_set_roi_area(DP_INTERFACE(pc),
3127 CALLBACK_INFO(pc)->dp_info.roi_x, CALLBACK_INFO(pc)->dp_info.roi_y,
3128 CALLBACK_INFO(pc)->dp_info.roi_w, CALLBACK_INFO(pc)->dp_info.roi_h);
3131 if (mm_ret != MM_ERROR_NONE) {
3132 LOGE("set mm_display_interface failed");
3133 return PLAYER_ERROR_INVALID_OPERATION;
3136 if (player_set_media_packet_video_frame_decoded_cb(player,
3137 __player_media_packet_video_decoded_cb, player) != MM_ERROR_NONE) {
3138 LOGE("fail to set decoded callback");
3139 return PLAYER_ERROR_INVALID_OPERATION;
3142 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
3143 LOGW("fail to set __retrieve_buffer_cb");
3147 wl_win.type = conv_type;
3149 arr_msg_len = (sizeof(wl_win_msg_type) / sizeof(int) + (sizeof(wl_win_msg_type) % sizeof(int) ? 1 : 0));
3150 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3151 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int *)wl_win_msg);
3158 int player_set_display_mode(player_h player, player_display_mode_e mode)
3160 int ret = PLAYER_ERROR_NONE;
3161 int mm_ret = MM_ERROR_NONE;
3162 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
3163 player_cli_s *pc = (player_cli_s *)player;
3164 char *ret_buf = NULL;
3165 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3167 PLAYER_INSTANCE_CHECK(player);
3168 PLAYER_RANGE_ARG_CHECK(mode, PLAYER_DISPLAY_MODE_LETTER_BOX, PLAYER_DISPLAY_MODE_DST_ROI);
3172 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3174 if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3175 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3176 return PLAYER_ERROR_NOT_AVAILABLE;
3179 if (display_type == MM_DISPLAY_TYPE_EVAS) {
3180 mm_ret = mm_display_interface_evas_set_mode(DP_INTERFACE(pc), mode);
3181 if (mm_ret != MM_ERROR_NONE) {
3182 LOGE("mm_display_interface_evas_set_mode failed 0x%x", mm_ret);
3183 return PLAYER_ERROR_INVALID_OPERATION;
3187 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mode", (int)mode);
3194 int player_get_display_mode(player_h player, player_display_mode_e *pmode)
3196 int ret = PLAYER_ERROR_NONE;
3197 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
3198 player_cli_s *pc = (player_cli_s *)player;
3199 char *ret_buf = NULL;
3201 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3203 PLAYER_INSTANCE_CHECK(player);
3204 PLAYER_NULL_ARG_CHECK(pmode);
3208 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3210 if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3211 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3212 return PLAYER_ERROR_NOT_AVAILABLE;
3215 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3217 if (ret == PLAYER_ERROR_NONE) {
3218 player_msg_get_type(mode, ret_buf, INT);
3227 int player_set_video_roi_area(player_h player, double x_scale, double y_scale,
3228 double w_scale, double h_scale)
3230 int ret = PLAYER_ERROR_NONE;
3231 muse_player_api_e api = MUSE_PLAYER_API_SET_VIDEO_ROI_AREA;
3232 player_cli_s *pc = (player_cli_s *)player;
3233 char *ret_buf = NULL;
3234 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3236 PLAYER_INSTANCE_CHECK(player);
3240 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3242 if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3243 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3244 return PLAYER_ERROR_NOT_AVAILABLE;
3247 if (display_type == MM_DISPLAY_TYPE_EVAS) {
3248 LOGE("Display type is EVAS, video display interface is not supported");
3249 return PLAYER_ERROR_INVALID_OPERATION;
3252 if (!_player_video_roi_area_is_valid(x_scale, y_scale, w_scale, h_scale))
3253 return PLAYER_ERROR_INVALID_PARAMETER;
3255 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3256 MUSE_TYPE_DOUBLE, "x_scale", x_scale,
3257 MUSE_TYPE_DOUBLE, "y_scale", y_scale,
3258 MUSE_TYPE_DOUBLE, "w_scale", w_scale,
3259 MUSE_TYPE_DOUBLE, "h_scale", h_scale);
3267 int player_get_video_roi_area(player_h player, double *x_scale, double *y_scale,
3268 double *w_scale, double *h_scale)
3270 int ret = PLAYER_ERROR_NONE;
3271 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_ROI_AREA;
3272 player_cli_s *pc = (player_cli_s *)player;
3273 char *ret_buf = NULL;
3274 double scale_x = 0, scale_y = 0, scale_w = 0, scale_h = 0;
3275 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3277 PLAYER_INSTANCE_CHECK(player);
3278 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3280 if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3281 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3282 return PLAYER_ERROR_NOT_AVAILABLE;
3285 PLAYER_NULL_ARG_CHECK(x_scale && y_scale && w_scale && h_scale);
3287 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3289 if (ret == PLAYER_ERROR_NONE) {
3290 if (player_msg_get_type(scale_x, ret_buf, DOUBLE))
3293 LOGE("failed to get value from msg");
3294 if (player_msg_get_type(scale_y, ret_buf, DOUBLE))
3297 LOGE("failed to get value from msg");
3298 if (player_msg_get_type(scale_w, ret_buf, DOUBLE))
3301 LOGE("failed to get value from msg");
3302 if (player_msg_get_type(scale_h, ret_buf, DOUBLE))
3305 LOGE("failed to get value from msg");
3314 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
3316 int ret = PLAYER_ERROR_NONE;
3317 int mm_ret = MM_ERROR_NONE;
3318 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
3319 player_cli_s *pc = (player_cli_s *)player;
3320 char *ret_buf = NULL;
3321 wl_win_msg_type wl_win;
3322 char *wl_win_msg = (char *)&wl_win;
3323 int arr_msg_len = 0;
3324 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3326 PLAYER_INSTANCE_CHECK(player);
3327 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3331 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3333 if (display_type == MM_DISPLAY_TYPE_EVAS) {
3334 mm_ret = mm_display_interface_evas_set_roi_area(DP_INTERFACE(pc), x, y, width, height);
3335 if (mm_ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
3336 return PLAYER_ERROR_INVALID_PARAMETER;
3337 else if (mm_ret != MM_ERROR_NONE)
3338 return PLAYER_ERROR_INVALID_OPERATION;
3341 wl_win.win_roi_x = x;
3342 wl_win.win_roi_y = y;
3343 wl_win.win_roi_width = width;
3344 wl_win.win_roi_height = height;
3346 arr_msg_len = (sizeof(wl_win_msg_type) / sizeof(int) + (sizeof(wl_win_msg_type) % sizeof(int) ? 1 : 0));
3347 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3348 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int *)wl_win_msg);
3350 if (ret == PLAYER_ERROR_NONE) {
3351 CALLBACK_INFO(pc)->dp_info.roi_x = x;
3352 CALLBACK_INFO(pc)->dp_info.roi_y = y;
3353 CALLBACK_INFO(pc)->dp_info.roi_w = width;
3354 CALLBACK_INFO(pc)->dp_info.roi_h = height;
3362 int player_set_playback_rate(player_h player, float rate)
3364 int ret = PLAYER_ERROR_NONE;
3365 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
3366 player_cli_s *pc = (player_cli_s *)player;
3367 char *ret_buf = NULL;
3369 PLAYER_INSTANCE_CHECK(player);
3370 PLAYER_RANGE_ARG_CHECK(rate, -5.0, 5.0);
3374 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", (double)rate);
3377 LOGD("LEAVE 0x%X", ret);
3381 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
3383 int ret = PLAYER_ERROR_NONE;
3384 int mm_ret = MM_ERROR_NONE;
3385 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
3386 player_cli_s *pc = (player_cli_s *)player;
3387 char *ret_buf = NULL;
3388 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3390 PLAYER_INSTANCE_CHECK(player);
3391 PLAYER_RANGE_ARG_CHECK(rotation, PLAYER_DISPLAY_ROTATION_NONE, PLAYER_DISPLAY_ROTATION_270);
3395 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3397 if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3398 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3399 return PLAYER_ERROR_NOT_AVAILABLE;
3402 if (display_type == MM_DISPLAY_TYPE_EVAS) {
3403 mm_ret = mm_display_interface_evas_set_rotation(DP_INTERFACE(pc), rotation);
3404 if (mm_ret != MM_ERROR_NONE) {
3405 LOGE("mm_display_interface_evas_set_rotation failed 0x%x", mm_ret);
3406 return PLAYER_ERROR_INVALID_OPERATION;
3410 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "rotation", (int)rotation);
3417 int player_get_display_rotation(player_h player, player_display_rotation_e *protation)
3419 int ret = PLAYER_ERROR_NONE;
3420 player_cli_s *pc = (player_cli_s *)player;
3421 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
3422 char *ret_buf = NULL;
3424 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3426 PLAYER_INSTANCE_CHECK(player);
3427 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3429 if (display_type == MM_DISPLAY_TYPE_OVERLAY_SYNC_UI) {
3430 LOGE("Function is not available in MM_DISPLAY_TYPE_OVERLAY_SYNC_UI type");
3431 return PLAYER_ERROR_NOT_AVAILABLE;
3434 PLAYER_NULL_ARG_CHECK(protation);
3438 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3440 if (ret == PLAYER_ERROR_NONE) {
3441 player_msg_get_type(rotation, ret_buf, INT);
3442 *protation = rotation;
3450 int player_set_display_visible(player_h player, bool visible)
3452 int ret = PLAYER_ERROR_NONE;
3453 int mm_ret = MM_ERROR_NONE;
3454 player_cli_s *pc = (player_cli_s *)player;
3455 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
3456 char *ret_buf = NULL;
3457 mm_display_type_e display_type = MM_DISPLAY_TYPE_NONE;
3459 PLAYER_INSTANCE_CHECK(player);
3463 PLAYER_GET_DISPLAY_TYPE(pc, display_type);
3465 if (display_type == MM_DISPLAY_TYPE_EVAS) {
3466 mm_ret = mm_display_interface_evas_set_visible(DP_INTERFACE(pc), visible);
3467 if (mm_ret != MM_ERROR_NONE) {
3468 LOGE("mm_display_interface_evas_set_visible failed 0x%x", mm_ret);
3469 return PLAYER_ERROR_INVALID_OPERATION;
3473 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "visible", (int)visible);
3477 if (ret == PLAYER_ERROR_NONE)
3478 CALLBACK_INFO(pc)->dp_info.visible = visible ? PLAYER_VISIBLE_INFO_TRUE : PLAYER_VISIBLE_INFO_FALSE;
3483 int player_is_display_visible(player_h player, bool *pvisible)
3485 int ret = PLAYER_ERROR_NONE;
3486 player_cli_s *pc = (player_cli_s *)player;
3487 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
3488 char *ret_buf = NULL;
3491 PLAYER_INSTANCE_CHECK(player);
3492 PLAYER_NULL_ARG_CHECK(pvisible);
3496 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3498 if (ret == PLAYER_ERROR_NONE) {
3499 player_msg_get_type(value, ret_buf, INT);
3512 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3514 int ret = PLAYER_ERROR_NONE;
3515 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3516 player_cli_s *pc = (player_cli_s *)player;
3517 char *ret_buf = NULL;
3518 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3520 PLAYER_INSTANCE_CHECK(player);
3521 PLAYER_NULL_ARG_CHECK(pvalue);
3525 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "key", (int)key);
3526 if (ret == PLAYER_ERROR_NONE) {
3527 player_msg_get_string(value, ret_buf);
3528 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3534 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3536 int ret = PLAYER_ERROR_NONE;
3537 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3538 player_cli_s *pc = (player_cli_s *)player;
3539 char *ret_buf = NULL;
3540 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3541 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3542 bool ret_val = TRUE;
3544 PLAYER_INSTANCE_CHECK(player);
3545 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3549 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3550 if (ret == PLAYER_ERROR_NONE) {
3551 ret_val = _player_get_param_value(ret_buf,
3552 MUSE_TYPE_STRING, "video_codec", (void *)video_codec,
3553 MUSE_TYPE_STRING, "audio_codec", (void *)audio_codec,
3554 INVALID_MUSE_TYPE_VALUE);
3557 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3559 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3561 ret = PLAYER_ERROR_INVALID_OPERATION;
3568 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3570 int ret = PLAYER_ERROR_NONE;
3571 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3572 player_cli_s *pc = (player_cli_s *)player;
3573 char *ret_buf = NULL;
3574 int sample_rate = 0;
3578 PLAYER_INSTANCE_CHECK(player);
3579 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3583 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3584 if (ret == PLAYER_ERROR_NONE) {
3585 bool ret_val = true;
3586 ret_val = _player_get_param_value(ret_buf,
3587 MUSE_TYPE_INT, "sample_rate", (void *)&sample_rate,
3588 MUSE_TYPE_INT, "channel", (void *)&channel,
3589 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3590 INVALID_MUSE_TYPE_VALUE);
3593 *psample_rate = sample_rate;
3595 *pchannel = channel;
3597 *pbit_rate = bit_rate;
3599 ret = PLAYER_ERROR_INVALID_OPERATION;
3606 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3608 int ret = PLAYER_ERROR_NONE;
3609 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3610 player_cli_s *pc = (player_cli_s *)player;
3611 char *ret_buf = NULL;
3615 PLAYER_INSTANCE_CHECK(player);
3616 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3620 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3621 if (ret == PLAYER_ERROR_NONE) {
3622 bool ret_val = true;
3623 ret_val = _player_get_param_value(ret_buf,
3624 MUSE_TYPE_INT, "fps", (void *)&fps,
3625 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3626 INVALID_MUSE_TYPE_VALUE);
3631 *pbit_rate = bit_rate;
3633 ret = PLAYER_ERROR_INVALID_OPERATION;
3640 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3642 int ret = PLAYER_ERROR_NONE;
3643 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3644 player_cli_s *pc = (player_cli_s *)player;
3645 char *ret_buf = NULL;
3649 PLAYER_INSTANCE_CHECK(player);
3650 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3654 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3655 if (ret == PLAYER_ERROR_NONE) {
3656 bool ret_val = true;
3657 ret_val = _player_get_param_value(ret_buf,
3658 MUSE_TYPE_INT, "width", (void *)&width,
3659 MUSE_TYPE_INT, "height", (void *)&height,
3660 INVALID_MUSE_TYPE_VALUE);
3665 ret = PLAYER_ERROR_INVALID_OPERATION;
3672 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3674 int ret = PLAYER_ERROR_NONE;
3675 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3676 player_cli_s *pc = (player_cli_s *)player;
3677 char *ret_buf = NULL;
3681 tbm_bo_handle thandle;
3682 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3683 int key = INVALID_DEFAULT_VALUE;
3686 PLAYER_INSTANCE_CHECK(player);
3687 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3691 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3692 if (ret == PLAYER_ERROR_NONE) {
3693 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3694 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3696 LOGE("failed to get msg obj, err:%d", err);
3697 ret = PLAYER_ERROR_INVALID_OPERATION;
3701 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3702 LOGD("size : %d", size);
3703 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3704 LOGE("failed to get key value");
3705 ret = PLAYER_ERROR_INVALID_OPERATION;
3709 tfd = pc->cb_info->tfd;
3711 LOGE("failed to get tbm fd value");
3712 ret = PLAYER_ERROR_INVALID_OPERATION;
3716 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3718 LOGE("TBM get error : bo is NULL");
3719 ret = PLAYER_ERROR_INVALID_OPERATION;
3722 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3723 if (thandle.ptr == NULL) {
3724 LOGE("TBM get error : handle pointer is NULL");
3725 ret = PLAYER_ERROR_INVALID_OPERATION;
3728 album_art = _get_mem(pc, size);
3730 memcpy(album_art, thandle.ptr, size);
3731 *palbum_art = album_art;
3733 LOGE("g_new failure");
3734 ret = PLAYER_ERROR_INVALID_OPERATION;
3746 muse_core_msg_object_free(jobj);
3750 PLAYER_CLOSE_FD(tfd);
3752 if (CALLBACK_INFO(pc))
3753 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3759 if (key > INVALID_DEFAULT_VALUE && CALLBACK_INFO(pc)) {
3760 LOGD("send msg to release buffer. key:%d", key);
3761 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_RETURN_BUFFER, MSG_FD(pc), ret, MUSE_TYPE_INT, "key", key);
3767 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3769 int ret = PLAYER_ERROR_NONE;
3770 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3771 player_cli_s *pc = (player_cli_s *)player;
3772 char *ret_buf = NULL;
3775 PLAYER_INSTANCE_CHECK(player);
3776 PLAYER_NULL_ARG_CHECK(pcount);
3780 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3781 if (ret == PLAYER_ERROR_NONE) {
3782 player_msg_get(count, ret_buf);
3789 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3791 int ret = PLAYER_ERROR_NONE;
3792 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3793 player_cli_s *pc = (player_cli_s *)player;
3794 char *ret_buf = NULL;
3796 PLAYER_INSTANCE_CHECK(player);
3797 PLAYER_NULL_ARG_CHECK(band_levels);
3801 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3802 MUSE_TYPE_INT, "length", length,
3803 MUSE_TYPE_ARRAY, "band_levels", length, band_levels);
3810 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3812 int ret = PLAYER_ERROR_NONE;
3813 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3814 player_cli_s *pc = (player_cli_s *)player;
3815 char *ret_buf = NULL;
3817 PLAYER_INSTANCE_CHECK(player);
3821 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3822 MUSE_TYPE_INT, "index", index,
3823 MUSE_TYPE_INT, "level", level);
3829 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3831 int ret = PLAYER_ERROR_NONE;
3832 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3833 player_cli_s *pc = (player_cli_s *)player;
3834 char *ret_buf = NULL;
3837 PLAYER_INSTANCE_CHECK(player);
3838 PLAYER_NULL_ARG_CHECK(plevel);
3842 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3843 if (ret == PLAYER_ERROR_NONE) {
3844 player_msg_get(level, ret_buf);
3851 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3853 int ret = PLAYER_ERROR_NONE;
3854 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3855 player_cli_s *pc = (player_cli_s *)player;
3856 char *ret_buf = NULL;
3857 int min = 0, max = 0;
3859 PLAYER_INSTANCE_CHECK(player);
3860 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3864 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3865 if (ret == PLAYER_ERROR_NONE) {
3866 bool ret_val = true;
3867 ret_val = _player_get_param_value(ret_buf,
3868 MUSE_TYPE_INT, "min", (void *)&min,
3869 MUSE_TYPE_INT, "max", (void *)&max,
3870 INVALID_MUSE_TYPE_VALUE);
3875 ret = PLAYER_ERROR_INVALID_OPERATION;
3882 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3884 int ret = PLAYER_ERROR_NONE;
3885 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3886 player_cli_s *pc = (player_cli_s *)player;
3887 char *ret_buf = NULL;
3890 PLAYER_INSTANCE_CHECK(player);
3891 PLAYER_NULL_ARG_CHECK(pfrequency);
3895 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3896 if (ret == PLAYER_ERROR_NONE) {
3897 player_msg_get(frequency, ret_buf);
3898 *pfrequency = frequency;
3904 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3906 int ret = PLAYER_ERROR_NONE;
3907 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3908 player_cli_s *pc = (player_cli_s *)player;
3909 char *ret_buf = NULL;
3912 PLAYER_INSTANCE_CHECK(player);
3913 PLAYER_NULL_ARG_CHECK(prange);
3917 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3918 if (ret == PLAYER_ERROR_NONE) {
3919 player_msg_get(range, ret_buf);
3926 int player_audio_effect_equalizer_clear(player_h player)
3928 int ret = PLAYER_ERROR_NONE;
3929 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3930 player_cli_s *pc = (player_cli_s *)player;
3931 char *ret_buf = NULL;
3933 PLAYER_INSTANCE_CHECK(player);
3937 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3942 int player_audio_effect_equalizer_is_available(player_h player, bool *pavailable)
3944 int ret = PLAYER_ERROR_NONE;
3945 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3946 player_cli_s *pc = (player_cli_s *)player;
3947 char *ret_buf = NULL;
3950 PLAYER_INSTANCE_CHECK(player);
3951 PLAYER_NULL_ARG_CHECK(pavailable);
3955 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3956 if (ret == PLAYER_ERROR_NONE) {
3957 player_msg_get(available, ret_buf);
3958 *pavailable = available;
3964 int player_set_subtitle_path(player_h player, const char *path)
3966 int ret = PLAYER_ERROR_NONE;
3967 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3968 player_cli_s *pc = (player_cli_s *)player;
3969 char *ret_buf = NULL;
3970 char subtitle_path[MAX_URL_LEN] = {0, };
3972 PLAYER_INSTANCE_CHECK(player);
3976 if (path && _player_get_valid_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3977 return PLAYER_ERROR_INVALID_PARAMETER;
3979 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "subtitle_path", (const char *)subtitle_path);
3984 int player_set_subtitle_position_offset(player_h player, int milliseconds)
3986 int ret = PLAYER_ERROR_NONE;
3987 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3988 player_cli_s *pc = (player_cli_s *)player;
3989 char *ret_buf = NULL;
3991 PLAYER_INSTANCE_CHECK(player);
3995 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "milliseconds", milliseconds);
4001 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
4003 int ret = PLAYER_ERROR_NONE;
4004 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
4005 player_cli_s *pc = (player_cli_s *)player;
4006 char *ret_buf = NULL;
4008 PLAYER_INSTANCE_CHECK(player);
4009 PLAYER_NULL_ARG_CHECK(callback);
4012 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
4013 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
4014 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
4016 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
4017 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
4018 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
4021 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4023 if (ret != PLAYER_ERROR_NONE)
4024 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
4030 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
4032 int ret = PLAYER_ERROR_NONE;
4033 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
4034 player_cli_s *pc = (player_cli_s *)player;
4035 char *ret_buf = NULL;
4037 PLAYER_INSTANCE_CHECK(player);
4038 PLAYER_NULL_ARG_CHECK(cookie);
4039 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4043 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4044 MUSE_TYPE_STRING, "cookie", cookie,
4045 MUSE_TYPE_INT, "size", size);
4050 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
4052 int ret = PLAYER_ERROR_NONE;
4053 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
4054 player_cli_s *pc = (player_cli_s *)player;
4055 char *ret_buf = NULL;
4057 PLAYER_INSTANCE_CHECK(player);
4058 PLAYER_NULL_ARG_CHECK(user_agent);
4059 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4063 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4064 MUSE_TYPE_STRING, "user_agent", user_agent,
4065 MUSE_TYPE_INT, "size", size);
4070 int player_get_streaming_download_progress(player_h player, int *start, int *end)
4072 int ret = PLAYER_ERROR_NONE;
4073 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
4074 player_cli_s *pc = (player_cli_s *)player;
4075 char *ret_buf = NULL;
4076 int start_pos = 0, end_pos = 0;
4078 PLAYER_INSTANCE_CHECK(player);
4079 PLAYER_NULL_ARG_CHECK(start && end);
4083 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4084 if (ret == PLAYER_ERROR_NONE) {
4085 bool ret_val = true;
4086 ret_val = _player_get_param_value(ret_buf,
4087 MUSE_TYPE_INT, "start_pos", (void *)&start_pos,
4088 MUSE_TYPE_INT, "end_pos", (void *)&end_pos,
4089 INVALID_MUSE_TYPE_VALUE);
4094 ret = PLAYER_ERROR_INVALID_OPERATION;
4101 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
4103 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
4106 static void __retrieve_buffer_cb(void *user_data)
4108 player_cli_s *player = (player_cli_s *)user_data;
4109 int ret = PLAYER_ERROR_NONE;
4110 bool gapless = false;
4112 ret = player_is_gapless((player_h)player, &gapless);
4113 if (ret != PLAYER_ERROR_NONE) {
4114 LOGW("player_is_gapless is failed");
4118 ret = mm_display_interface_evas_flush(DP_INTERFACE(player), gapless);
4120 LOGW("flush all packet : 0x%x [gapless %d]", ret, gapless);
4123 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
4125 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
4128 static int __player_unset_retrieve_buffer_cb(player_h player)
4130 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
4133 int player_unset_completed_cb(player_h player)
4135 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
4138 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
4140 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
4143 int player_unset_interrupted_cb(player_h player)
4145 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
4148 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
4150 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
4153 int player_unset_error_cb(player_h player)
4155 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
4158 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
4160 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
4163 int player_unset_buffering_cb(player_h player)
4165 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
4168 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
4170 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
4173 int player_unset_subtitle_updated_cb(player_h player)
4175 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
4178 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
4180 return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME, player, callback, user_data);
4183 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
4185 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME, player);
4188 int player_set_media_packet_audio_frame_decoded_cb(player_h player, media_format_h format,
4189 player_audio_extract_option_e opt, player_media_packet_audio_decoded_cb callback, void *user_data)
4191 int ret = PLAYER_ERROR_NONE;
4192 player_cli_s *pc = (player_cli_s *)player;
4193 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_PACKET_AUDIO_FRAME_DECODED_CB;
4194 char *ret_buf = NULL;
4195 media_format_mimetype_e mimetype = MEDIA_FORMAT_MAX;
4199 PLAYER_INSTANCE_CHECK(player);
4200 PLAYER_NULL_ARG_CHECK(callback);
4201 PLAYER_RANGE_ARG_CHECK(opt, PLAYER_AUDIO_EXTRACT_DEFAULT, PLAYER_AUDIO_EXTRACT_NO_SYNC_AND_DEINTERLEAVE);
4206 media_format_ref(format);
4207 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE) {
4208 LOGE("failed to get audio info from media format.");
4209 media_format_unref(format);
4210 return PLAYER_ERROR_INVALID_PARAMETER;
4212 media_format_unref(format);
4214 if (mimetype < MEDIA_FORMAT_PCM || mimetype > MEDIA_FORMAT_PCM_U32BE) {
4215 LOGW("Not supported audio format type : 0x%X", mimetype);
4216 return PLAYER_ERROR_INVALID_PARAMETER;
4220 LOGD("pcm spec : 0x%X, %d, %d", mimetype, channel, samplerate);
4222 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4223 MUSE_TYPE_INT, "opt", opt,
4224 MUSE_TYPE_INT, "mimetype", mimetype,
4225 MUSE_TYPE_INT, "channel", channel,
4226 MUSE_TYPE_INT, "samplerate", samplerate);
4228 if (ret == PLAYER_ERROR_NONE) {
4229 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] = callback;
4230 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] = user_data;
4231 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME);
4238 int player_unset_media_packet_audio_frame_decoded_cb(player_h player)
4240 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME, player);
4243 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
4245 return __set_callback(MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, player, callback, user_data);
4248 int player_unset_video_stream_changed_cb(player_h player)
4250 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, player);
4253 int player_set_media_stream_buffer_status_cb(player_h player,
4254 player_stream_type_e stream_type, player_media_stream_buffer_status_cb callback, void *user_data)
4256 muse_player_event_e type;
4258 PLAYER_INSTANCE_CHECK(player);
4259 PLAYER_NULL_ARG_CHECK(callback);
4263 if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4264 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4265 } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4266 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4268 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4269 return PLAYER_ERROR_INVALID_PARAMETER;
4272 return __set_callback(type, player, callback, user_data);
4275 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
4277 muse_player_event_e type;
4279 PLAYER_INSTANCE_CHECK(player);
4283 if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4284 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4285 } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4286 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4288 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4289 return PLAYER_ERROR_INVALID_PARAMETER;
4292 return __unset_callback(type, player);
4295 int player_set_media_stream_seek_cb(player_h player,
4296 player_stream_type_e stream_type, player_media_stream_seek_cb callback, void *user_data)
4298 muse_player_event_e type;
4300 PLAYER_INSTANCE_CHECK(player);
4301 PLAYER_NULL_ARG_CHECK(callback);
4305 if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4306 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4307 } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4308 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4310 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4311 return PLAYER_ERROR_INVALID_PARAMETER;
4314 return __set_callback(type, player, callback, user_data);
4317 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
4319 muse_player_event_e type;
4321 PLAYER_INSTANCE_CHECK(player);
4325 if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
4326 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4327 } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
4328 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4330 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4331 return PLAYER_ERROR_INVALID_PARAMETER;
4334 return __unset_callback(type, player);
4337 /* TODO Implement raw data socket channel */
4338 int player_push_media_stream(player_h player, media_packet_h packet)
4340 int ret = PLAYER_ERROR_NONE;
4341 int packet_ret = MEDIA_PACKET_ERROR_NONE;
4342 player_cli_s *pc = (player_cli_s *)player;
4343 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
4344 char *ret_buf = NULL;
4345 player_push_media_msg_type push_media;
4346 char *push_media_msg = (char *)&push_media;
4347 int msg_size = sizeof(player_push_media_msg_type);
4351 tbm_bo_handle thandle;
4352 tbm_fd tfd = INVALID_DEFAULT_VALUE;
4355 media_format_h format;
4359 int arr_msg_len = 0;
4360 char *codec_data = NULL;
4361 unsigned int codec_data_size = 0;
4363 PLAYER_INSTANCE_CHECK(player);
4364 PLAYER_NULL_ARG_CHECK(packet);
4368 if (media_packet_get_buffer_data_ptr(packet, (void **)&buf) != MEDIA_PACKET_ERROR_NONE) {
4369 LOGE("failed to get buffer data ptr");
4370 return PLAYER_ERROR_INVALID_OPERATION;
4373 if (media_packet_get_buffer_size(packet, &push_media.size) != MEDIA_PACKET_ERROR_NONE) {
4374 LOGE("failed to get buffer size");
4375 return PLAYER_ERROR_INVALID_OPERATION;
4378 if (media_packet_get_pts(packet, &push_media.pts) != MEDIA_PACKET_ERROR_NONE) {
4379 LOGE("failed to get buffer pts");
4380 return PLAYER_ERROR_INVALID_OPERATION;
4383 if (media_packet_get_format(packet, &format) != MEDIA_PACKET_ERROR_NONE) { /* format ref count is increased */
4384 LOGE("failed to get media format");
4385 return PLAYER_ERROR_INVALID_OPERATION;
4388 packet_ret = media_packet_get_flags(packet, &push_media.flags);
4389 packet_ret |= media_packet_is_video(packet, &is_video);
4390 packet_ret |= media_packet_is_audio(packet, &is_audio);
4391 packet_ret |= media_packet_is_end_of_stream(packet, &is_eos);
4393 packet_ret |= media_format_get_video_info(format, &push_media.mimetype,
4394 &push_media.width, &push_media.height, NULL, NULL);
4396 packet_ret |= media_format_get_audio_info(format, &push_media.mimetype,
4397 &push_media.channels, &push_media.samplerate, NULL, NULL);
4399 media_format_unref(format);
4401 if (packet_ret != MEDIA_PACKET_ERROR_NONE) {
4402 LOGE("failed to get media packet info");
4403 return PLAYER_ERROR_INVALID_OPERATION;
4406 if (media_packet_get_codec_data(packet, (void **)&codec_data, &codec_data_size) == MEDIA_PACKET_ERROR_NONE) {
4407 if (codec_data_size > 0 && codec_data_size <= sizeof(push_media.codec_data))
4408 memcpy(push_media.codec_data, codec_data, codec_data_size);
4411 push_media.codec_data_size = codec_data_size;
4412 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
4415 int arr_buf_len = 0;
4417 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
4418 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
4420 LOGE("TBM get error : bo is NULL");
4421 return PLAYER_ERROR_INVALID_OPERATION;
4423 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4424 if (thandle.ptr == NULL) {
4425 LOGE("TBM get error : handle pointer is NULL");
4426 ret = PLAYER_ERROR_INVALID_OPERATION;
4429 memcpy(thandle.ptr, buf, push_media.size);
4432 tfd = tbm_bo_export_fd(bo);
4434 LOGE("tbm_bo_export_fd err 0x%x", tfd);
4435 ret = PLAYER_ERROR_INVALID_OPERATION;
4439 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4440 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret,
4441 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4443 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4444 buf_size = (int)push_media.size;
4446 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4447 arr_buf_len = (buf_size / sizeof(int) + (buf_size % sizeof(int) ? 1 : 0));
4448 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4449 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg,
4450 MUSE_TYPE_ARRAY, "buf", arr_buf_len, (int *)buf);
4454 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4455 buf_size = (int)push_media.size;
4456 if ((muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts) < 0) && (!is_eos)) {
4457 LOGE("failed to send data");
4458 return PLAYER_ERROR_INVALID_OPERATION;
4461 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4462 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4463 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4466 LOGD("ret_buf %s", ret_buf);
4471 PLAYER_CLOSE_FD(tfd);
4473 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4481 int player_foreach_media_stream_supported_format(player_h player, player_supported_media_format_cb callback, void *user_data)
4483 int ret = PLAYER_ERROR_NONE;
4484 player_cli_s *pc = (player_cli_s *)player;
4485 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_SUPPORTED_FORMAT;
4486 char *ret_buf = NULL;
4487 int format_info[MAX_SUPPORTED_MEDIA_FORMAT] = {0,};
4488 int len = 0, idx = 0;
4490 PLAYER_INSTANCE_CHECK(player);
4491 PLAYER_NULL_ARG_CHECK(callback);
4495 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4497 player_msg_get_type(len, ret_buf, INT);
4498 player_msg_get_array(format_info, ret_buf);
4500 LOGD("num of format %d", len);
4501 for (idx = 0 ; idx < len ; idx++) {
4502 if (!callback(format_info[idx], user_data)) {
4503 LOGW("stop foreach callback");
4508 LOGD("LEAVE 0x%X", ret);
4513 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4515 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4516 int ret = PLAYER_ERROR_NONE;
4517 player_cli_s *pc = (player_cli_s *)player;
4518 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4519 char *ret_buf = NULL;
4520 media_format_mimetype_e mimetype;
4530 PLAYER_INSTANCE_CHECK(player);
4534 media_format_ref(format);
4535 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4536 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4537 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4538 LOGE("failed to get video info from format.");
4539 return PLAYER_ERROR_INVALID_PARAMETER;
4542 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4543 MUSE_TYPE_INT, "type", type,
4544 MUSE_TYPE_INT, "mimetype", mimetype,
4545 MUSE_TYPE_INT, "width", width,
4546 MUSE_TYPE_INT, "height", height,
4547 MUSE_TYPE_INT, "avg_bps", avg_bps,
4548 MUSE_TYPE_INT, "max_bps", max_bps,
4549 MUSE_TYPE_INT, "frame_rate", frame_rate);
4551 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4552 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4553 LOGE("failed to get audio info from format.");
4554 return PLAYER_ERROR_INVALID_PARAMETER;
4557 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4558 MUSE_TYPE_INT, "type", type,
4559 MUSE_TYPE_INT, "mimetype", mimetype,
4560 MUSE_TYPE_INT, "channel", channel,
4561 MUSE_TYPE_INT, "samplerate", samplerate,
4562 MUSE_TYPE_INT, "avg_bps", avg_bps,
4563 MUSE_TYPE_INT, "bit", bit);
4566 media_format_unref(format);
4567 pc->push_media_stream = TRUE;
4573 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4575 int ret = PLAYER_ERROR_NONE;
4576 player_cli_s *pc = (player_cli_s *)player;
4577 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4578 char *ret_buf = NULL;
4580 PLAYER_INSTANCE_CHECK(player);
4581 PLAYER_RANGE_ARG_CHECK(type, PLAYER_STREAM_TYPE_AUDIO, PLAYER_STREAM_TYPE_VIDEO);
4582 PLAYER_CHECK_CONDITION(max_size > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4586 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4587 MUSE_TYPE_INT, "type", type,
4588 MUSE_TYPE_INT64, "max_size", (INT64)max_size);
4594 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4596 int ret = PLAYER_ERROR_NONE;
4597 player_cli_s *pc = (player_cli_s *)player;
4598 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4599 char *ret_buf = NULL;
4600 unsigned long long max_size;
4602 PLAYER_INSTANCE_CHECK(player);
4603 PLAYER_NULL_ARG_CHECK(pmax_size);
4604 PLAYER_RANGE_ARG_CHECK(type, PLAYER_STREAM_TYPE_AUDIO, PLAYER_STREAM_TYPE_VIDEO);
4608 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4609 if (ret == PLAYER_ERROR_NONE) {
4610 player_msg_get_type(max_size, ret_buf, INT64);
4611 *pmax_size = max_size;
4617 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4619 int ret = PLAYER_ERROR_NONE;
4620 player_cli_s *pc = (player_cli_s *)player;
4621 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4622 char *ret_buf = NULL;
4624 PLAYER_INSTANCE_CHECK(player);
4625 PLAYER_RANGE_ARG_CHECK(type, PLAYER_STREAM_TYPE_DEFAULT, PLAYER_STREAM_TYPE_TEXT);
4629 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4630 MUSE_TYPE_INT, "type", type,
4631 MUSE_TYPE_INT, "percent", (int)percent);
4637 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4639 int ret = PLAYER_ERROR_NONE;
4640 player_cli_s *pc = (player_cli_s *)player;
4641 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4642 char *ret_buf = NULL;
4643 unsigned int percent;
4645 PLAYER_INSTANCE_CHECK(player);
4646 PLAYER_NULL_ARG_CHECK(ppercent);
4650 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4651 if (ret == PLAYER_ERROR_NONE) {
4652 player_msg_get(percent, ret_buf);
4653 *ppercent = percent;
4660 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4662 int ret = PLAYER_ERROR_NONE;
4663 player_cli_s *pc = (player_cli_s *)player;
4664 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4665 char *ret_buf = NULL;
4668 PLAYER_INSTANCE_CHECK(player);
4669 PLAYER_NULL_ARG_CHECK(pcount);
4673 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4674 if (ret == PLAYER_ERROR_NONE) {
4675 player_msg_get(count, ret_buf);
4683 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4685 int ret = PLAYER_ERROR_NONE;
4686 player_cli_s *pc = (player_cli_s *)player;
4687 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4688 char *ret_buf = NULL;
4691 PLAYER_INSTANCE_CHECK(player);
4692 PLAYER_NULL_ARG_CHECK(pindex);
4696 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4697 if (ret == PLAYER_ERROR_NONE) {
4698 player_msg_get(index, ret_buf);
4706 int player_select_track(player_h player, player_stream_type_e type, int index)
4708 int ret = PLAYER_ERROR_NONE;
4709 player_cli_s *pc = (player_cli_s *)player;
4710 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4711 char *ret_buf = NULL;
4713 PLAYER_INSTANCE_CHECK(player);
4717 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4723 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4725 int ret = PLAYER_ERROR_NONE;
4726 player_cli_s *pc = (player_cli_s *)player;
4727 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4728 char *ret_buf = NULL;
4729 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4732 PLAYER_INSTANCE_CHECK(player);
4733 PLAYER_NULL_ARG_CHECK(pcode);
4737 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4738 if (ret == PLAYER_ERROR_NONE) {
4739 bool recv_ret = true;
4740 recv_ret = _player_get_param_value(ret_buf,
4741 MUSE_TYPE_INT, "code_len", (void *)&code_len,
4742 MUSE_TYPE_STRING, "code", (void *)code,
4743 INVALID_MUSE_TYPE_VALUE);
4745 *pcode = strndup(code, code_len);
4747 ret = PLAYER_ERROR_INVALID_OPERATION;
4753 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4755 int ret = PLAYER_ERROR_NONE;
4756 player_cli_s *pc = (player_cli_s *)player;
4757 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4758 char *ret_buf = NULL;
4759 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4760 int idx = 0, num = 0;
4761 int bandwidth = 0, width = 0, height = 0;
4765 PLAYER_INSTANCE_CHECK(player);
4766 PLAYER_NULL_ARG_CHECK(callback);
4770 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4771 if (ret == PLAYER_ERROR_NONE) {
4772 player_msg_get_type(num, ret_buf, INT);
4774 player_msg_get_string(var_info, ret_buf);
4776 LOGW("There is no stream variant info.");
4779 for (idx = 0 ; idx < num ; idx++) {
4780 bandwidth = width = height = 0;
4782 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4784 bandwidth = atoi(token);
4786 token = strtok_r(NULL, ",", &ptr);
4788 width = atoi(token);
4790 token = strtok_r(NULL, ",", &ptr);
4792 height = atoi(token);
4794 callback(bandwidth, width, height, user_data);
4797 LOGD("LEAVE 0x%X", ret);
4802 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4804 int ret = PLAYER_ERROR_NONE;
4805 player_cli_s *pc = (player_cli_s *)player;
4806 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4807 char *ret_buf = NULL;
4809 PLAYER_INSTANCE_CHECK(player);
4810 PLAYER_CHECK_CONDITION(bandwidth >= -1 && width >= -1 && height >= -1,
4811 PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4815 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4816 MUSE_TYPE_INT, "bandwidth", bandwidth,
4817 MUSE_TYPE_INT, "width", width,
4818 MUSE_TYPE_INT, "height", height);
4821 LOGD("LEAVE 0x%X", ret);
4826 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4828 int ret = PLAYER_ERROR_NONE;
4829 player_cli_s *pc = (player_cli_s *)player;
4830 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4831 char *ret_buf = NULL;
4832 int bandwidth = -1, width = -1, height = -1;
4834 PLAYER_INSTANCE_CHECK(player);
4835 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4839 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4840 if (ret == PLAYER_ERROR_NONE) {
4841 bool ret_val = true;
4842 ret_val = _player_get_param_value(ret_buf,
4843 MUSE_TYPE_INT, "bandwidth", (void *)&bandwidth,
4844 MUSE_TYPE_INT, "width", (void *)&width,
4845 MUSE_TYPE_INT, "height", (void *)&height,
4846 INVALID_MUSE_TYPE_VALUE);
4848 if (pbandwidth) *pbandwidth = bandwidth;
4849 if (pwidth) *pwidth = width;
4850 if (pheight) *pheight = height;
4852 ret = PLAYER_ERROR_INVALID_OPERATION;
4857 LOGD("LEAVE 0x%X", ret);
4861 int player_set_audio_only(player_h player, bool audio_only)
4863 int ret = PLAYER_ERROR_NONE;
4864 player_cli_s *pc = (player_cli_s *)player;
4865 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4866 char *ret_buf = NULL;
4867 player_state_e state = PLAYER_STATE_NONE;
4869 PLAYER_INSTANCE_CHECK(player);
4871 LOGD("ENTER audio_only: %d", audio_only);
4873 /* check player state */
4874 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
4875 LOGE("Failed to get state");
4876 return PLAYER_ERROR_INVALID_OPERATION;
4879 if (state < PLAYER_STATE_READY) {
4880 LOGE("Invalid state %d", state);
4881 return PLAYER_ERROR_INVALID_STATE;
4884 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "audio_only", (int)audio_only);
4888 LOGD("LEAVE 0x%X", ret);
4893 int player_is_audio_only(player_h player, bool *paudio_only)
4895 int ret = PLAYER_ERROR_NONE;
4896 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4897 player_cli_s *pc = (player_cli_s *)player;
4898 char *ret_buf = NULL;
4901 PLAYER_INSTANCE_CHECK(player);
4902 PLAYER_NULL_ARG_CHECK(paudio_only);
4906 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4908 if (ret == PLAYER_ERROR_NONE) {
4909 player_msg_get(audio_only, ret_buf);
4910 *paudio_only = (bool)audio_only;
4915 LOGD("LEAVE 0x%X", ret);
4920 int player_set_streaming_buffering_time(player_h player, int prebuffer_ms, int rebuffer_ms)
4922 #define MIN_BUFFER_TIME -1
4923 int ret = PLAYER_ERROR_NONE;
4924 player_cli_s *pc = (player_cli_s *)player;
4925 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4926 char *ret_buf = NULL;
4928 PLAYER_INSTANCE_CHECK(player);
4929 PLAYER_CHECK_CONDITION(prebuffer_ms >= MIN_BUFFER_TIME && rebuffer_ms >= MIN_BUFFER_TIME,
4930 PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4934 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4935 MUSE_TYPE_INT, "prebuffer_ms", prebuffer_ms,
4936 MUSE_TYPE_INT, "rebuffer_ms", rebuffer_ms);
4939 LOGD("LEAVE 0x%X", ret);
4943 int player_get_streaming_buffering_time(player_h player, int *prebuffer_ms, int *rebuffer_ms)
4945 int ret = PLAYER_ERROR_NONE;
4946 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4947 player_cli_s *pc = (player_cli_s *)player;
4948 int prebuffering_time = 0, rebuffering_time = 0;
4949 char *ret_buf = NULL;
4951 PLAYER_INSTANCE_CHECK(player);
4952 PLAYER_NULL_ARG_CHECK(prebuffer_ms || rebuffer_ms);
4956 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4958 if (ret == PLAYER_ERROR_NONE) {
4959 bool ret_val = true;
4960 ret_val = _player_get_param_value(ret_buf,
4961 MUSE_TYPE_INT, "prebuffer_ms", (void *)&prebuffering_time,
4962 MUSE_TYPE_INT, "rebuffer_ms", (void *)&rebuffering_time,
4963 INVALID_MUSE_TYPE_VALUE);
4965 if (prebuffer_ms) *prebuffer_ms = prebuffering_time;
4966 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4968 ret = PLAYER_ERROR_INVALID_OPERATION;
4974 LOGD("LEAVE 0x%X", ret);
4978 int player_360_is_content_spherical(player_h player, bool *is_spherical)
4980 int ret = PLAYER_ERROR_NONE;
4981 muse_player_api_e api = MUSE_PLAYER_API_360_IS_CONTENT_SPHERICAL;
4982 player_cli_s *pc = (player_cli_s *)player;
4983 char *ret_buf = NULL;
4986 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4987 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4988 PLAYER_INSTANCE_CHECK(player);
4989 PLAYER_NULL_ARG_CHECK(is_spherical);
4993 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4994 if (ret == PLAYER_ERROR_NONE) {
4995 player_msg_get(val, ret_buf);
4996 *is_spherical = val;
5000 LOGD("LEAVE 0x%X", ret);
5004 int player_360_set_enabled(player_h player, bool enabled)
5006 int ret = PLAYER_ERROR_NONE;
5007 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLED;
5008 player_cli_s *pc = (player_cli_s *)player;
5009 char *ret_buf = NULL;
5010 int val = (int)enabled;
5012 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5013 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5014 PLAYER_INSTANCE_CHECK(player);
5016 LOGD("ENTER %d", enabled);
5018 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5021 LOGD("LEAVE 0x%X", ret);
5025 int player_360_is_enabled(player_h player, bool *enabled)
5027 int ret = PLAYER_ERROR_NONE;
5028 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
5029 player_cli_s *pc = (player_cli_s *)player;
5030 char *ret_buf = NULL;
5033 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5034 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5035 PLAYER_INSTANCE_CHECK(player);
5036 PLAYER_NULL_ARG_CHECK(enabled);
5040 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5041 if (ret == PLAYER_ERROR_NONE) {
5042 player_msg_get(val, ret_buf);
5047 LOGD("LEAVE 0x%X", ret);
5051 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
5053 int ret = PLAYER_ERROR_NONE;
5054 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
5055 player_cli_s *pc = (player_cli_s *)player;
5056 char *ret_buf = NULL;
5058 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5059 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5060 PLAYER_INSTANCE_CHECK(player);
5061 PLAYER_RANGE_ARG_CHECK(yaw, (float)-M_PI, (float)M_PI);
5062 PLAYER_RANGE_ARG_CHECK(pitch, ((float)-M_PI / 2), ((float)M_PI / 2));
5064 LOGD("ENTER %f %f", yaw, pitch);
5066 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5067 MUSE_TYPE_DOUBLE, "yaw", (double)yaw,
5068 MUSE_TYPE_DOUBLE, "pitch", (double)pitch);
5072 LOGD("LEAVE 0x%X", ret);
5076 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
5078 int ret = PLAYER_ERROR_NONE;
5079 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
5080 player_cli_s *pc = (player_cli_s *)player;
5081 double yaw_val = -1;
5082 double pitch_val = -1;
5083 char *ret_buf = NULL;
5085 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5086 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5087 PLAYER_INSTANCE_CHECK(player);
5088 PLAYER_NULL_ARG_CHECK(yaw && pitch);
5092 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5094 if (ret == PLAYER_ERROR_NONE) {
5095 bool ret_val = true;
5096 ret_val = _player_get_param_value(ret_buf,
5097 MUSE_TYPE_DOUBLE, "yaw_val", (void *)&yaw_val,
5098 MUSE_TYPE_DOUBLE, "pitch_val", (void *)&pitch_val,
5099 INVALID_MUSE_TYPE_VALUE);
5101 *yaw = (float)yaw_val;
5102 *pitch = (float)pitch_val;
5104 LOGE("failed to get value from msg");
5105 ret = PLAYER_ERROR_INVALID_OPERATION;
5111 LOGD("LEAVE 0x%X", ret);
5115 int player_360_set_zoom(player_h player, float level)
5117 int ret = PLAYER_ERROR_NONE;
5118 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
5119 player_cli_s *pc = (player_cli_s *)player;
5120 char *ret_buf = NULL;
5122 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5123 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5124 PLAYER_INSTANCE_CHECK(player);
5125 PLAYER_RANGE_ARG_CHECK(level, 1.0, 10.0);
5127 LOGD("ENTER %f", level);
5129 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "level", (double)level);
5132 LOGD("LEAVE 0x%X", ret);
5136 int player_360_get_zoom(player_h player, float *level)
5138 int ret = PLAYER_ERROR_NONE;
5139 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
5140 player_cli_s *pc = (player_cli_s *)player;
5142 char *ret_buf = NULL;
5144 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5145 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5146 PLAYER_INSTANCE_CHECK(player);
5147 PLAYER_NULL_ARG_CHECK(level);
5151 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5153 if (ret == PLAYER_ERROR_NONE) {
5154 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
5155 *level = (float)zoom;
5157 LOGE("failed to get value from msg");
5158 ret = PLAYER_ERROR_INVALID_OPERATION;
5164 LOGD("LEAVE 0x%X", ret);
5168 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
5170 int ret = PLAYER_ERROR_NONE;
5171 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
5172 player_cli_s *pc = (player_cli_s *)player;
5173 char *ret_buf = NULL;
5175 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5176 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5177 PLAYER_INSTANCE_CHECK(player);
5178 PLAYER_RANGE_ARG_CHECK(horizontal_degrees, 1, 360);
5179 PLAYER_RANGE_ARG_CHECK(vertical_degrees, 1, 180);
5181 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
5183 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5184 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5185 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5188 LOGD("LEAVE 0x%X", ret);
5192 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
5194 int ret = PLAYER_ERROR_NONE;
5195 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
5196 player_cli_s *pc = (player_cli_s *)player;
5199 char *ret_buf = NULL;
5201 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5202 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5203 PLAYER_INSTANCE_CHECK(player);
5204 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
5208 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5210 if (ret == PLAYER_ERROR_NONE) {
5211 bool ret_val = true;
5212 ret_val = _player_get_param_value(ret_buf,
5213 MUSE_TYPE_INT, "h_val", (void *)&h_val,
5214 MUSE_TYPE_INT, "v_val", (void *)&v_val,
5215 INVALID_MUSE_TYPE_VALUE);
5217 *horizontal_degrees = h_val;
5218 *vertical_degrees = v_val;
5220 LOGE("failed to get value from msg");
5221 ret = PLAYER_ERROR_INVALID_OPERATION;
5227 LOGD("LEAVE 0x%X", ret);
5231 int player_360_set_zoom_with_field_of_view(player_h player, float level, int horizontal_degrees, int vertical_degrees)
5233 int ret = PLAYER_ERROR_NONE;
5234 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM_WITH_FIELD_OF_VIEW;
5235 player_cli_s *pc = (player_cli_s *)player;
5236 char *ret_buf = NULL;
5238 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5239 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5240 PLAYER_INSTANCE_CHECK(player);
5241 PLAYER_RANGE_ARG_CHECK(horizontal_degrees, 1, 360);
5242 PLAYER_RANGE_ARG_CHECK(vertical_degrees, 1, 180);
5243 PLAYER_RANGE_ARG_CHECK(level, 1.0, 10.0);
5245 LOGD("ENTER %f %d %d", level, horizontal_degrees, vertical_degrees);
5247 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5248 MUSE_TYPE_DOUBLE, "level", (double)level,
5249 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5250 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5253 LOGD("LEAVE 0x%X", ret);
5257 int player_set_replaygain_enabled(player_h player, bool enabled)
5259 int ret = PLAYER_ERROR_NONE;
5260 muse_player_api_e api = MUSE_PLAYER_API_SET_REPLAYGAIN_ENABLED;
5261 player_cli_s *pc = (player_cli_s *)player;
5262 char *ret_buf = NULL;
5263 int val = (int)enabled;
5265 PLAYER_INSTANCE_CHECK(player);
5269 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5274 int player_is_replaygain_enabled(player_h player, bool *enabled)
5276 int ret = PLAYER_ERROR_NONE;
5277 muse_player_api_e api = MUSE_PLAYER_API_IS_REPLAYGAIN_ENABLED;
5278 player_cli_s *pc = (player_cli_s *)player;
5279 char *ret_buf = NULL;
5282 PLAYER_INSTANCE_CHECK(player);
5283 PLAYER_NULL_ARG_CHECK(enabled);
5287 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5288 if (ret == PLAYER_ERROR_NONE) {
5289 player_msg_get(val, ret_buf);
5290 *enabled = (bool)val;
5297 int player_audio_pitch_set_enabled(player_h player, bool enabled)
5299 int ret = PLAYER_ERROR_NONE;
5300 muse_player_api_e api = MUSE_PLAYER_API_PITCH_SET_ENABLED;
5301 player_cli_s *pc = (player_cli_s *)player;
5302 char *ret_buf = NULL;
5303 int val = (int)enabled;
5305 PLAYER_INSTANCE_CHECK(player);
5309 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5314 int player_audio_pitch_is_enabled(player_h player, bool *enabled)
5316 int ret = PLAYER_ERROR_NONE;
5317 muse_player_api_e api = MUSE_PLAYER_API_PITCH_IS_ENABLED;
5318 player_cli_s *pc = (player_cli_s *)player;
5319 char *ret_buf = NULL;
5322 PLAYER_INSTANCE_CHECK(player);
5323 PLAYER_NULL_ARG_CHECK(enabled);
5327 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5328 if (ret == PLAYER_ERROR_NONE) {
5329 player_msg_get(val, ret_buf);
5330 *enabled = (bool)val;
5337 int player_audio_pitch_set_value(player_h player, float value)
5339 int ret = PLAYER_ERROR_NONE;
5340 muse_player_api_e api = MUSE_PLAYER_API_PITCH_SET_VALUE;
5341 player_cli_s *pc = (player_cli_s *)player;
5342 char *ret_buf = NULL;
5344 PLAYER_INSTANCE_CHECK(player);
5345 PLAYER_RANGE_ARG_CHECK(value, 0.5, 2.0);
5347 LOGD("ENTER %1.3f", value);
5349 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "pitch", (double)value);
5352 LOGD("LEAVE 0x%X", ret);
5356 int player_audio_pitch_get_value(player_h player, float *value)
5358 int ret = PLAYER_ERROR_NONE;
5359 muse_player_api_e api = MUSE_PLAYER_API_PITCH_GET_VALUE;
5360 player_cli_s *pc = (player_cli_s *)player;
5362 char *ret_buf = NULL;
5364 PLAYER_INSTANCE_CHECK(player);
5365 PLAYER_NULL_ARG_CHECK(value);
5369 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5371 if (ret == PLAYER_ERROR_NONE) {
5372 if (player_msg_get_type(pitch, ret_buf, DOUBLE)) {
5373 *value = (float)pitch;
5375 LOGE("failed to get pitch value");
5376 ret = PLAYER_ERROR_INVALID_OPERATION;
5382 LOGD("LEAVE 0x%X", ret);
5386 int player_audio_offload_foreach_supported_format(player_h player, player_supported_media_format_cb callback, void *user_data)
5388 int ret = PLAYER_ERROR_NONE;
5389 player_cli_s *pc = (player_cli_s *)player;
5390 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_GET_SUPPORTED_FORMAT;
5391 char *ret_buf = NULL;
5392 int format_info[MAX_SUPPORTED_MEDIA_FORMAT] = {0,};
5393 int len = 0, idx = 0;
5395 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5396 PLAYER_INSTANCE_CHECK(player);
5397 PLAYER_NULL_ARG_CHECK(callback);
5401 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5403 player_msg_get_type(len, ret_buf, INT);
5404 player_msg_get_array(format_info, ret_buf);
5406 LOGD("num of format %d", len);
5407 for (idx = 0 ; idx < len ; idx++) {
5408 if (!callback(format_info[idx], user_data)) {
5409 LOGW("stop foreach callback");
5414 LOGD("LEAVE 0x%X", ret);
5419 int player_audio_offload_set_enabled(player_h player, bool enabled)
5421 int ret = PLAYER_ERROR_NONE;
5422 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_SET_ENABLED;
5423 player_cli_s *pc = (player_cli_s *)player;
5424 char *ret_buf = NULL;
5425 int val = (int)enabled;
5427 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5428 PLAYER_INSTANCE_CHECK(player);
5432 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5437 int player_audio_offload_is_enabled(player_h player, bool *enabled)
5439 int ret = PLAYER_ERROR_NONE;
5440 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_IS_ENABLED;
5441 player_cli_s *pc = (player_cli_s *)player;
5442 char *ret_buf = NULL;
5445 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5446 PLAYER_INSTANCE_CHECK(player);
5447 PLAYER_NULL_ARG_CHECK(enabled);
5451 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5452 if (ret == PLAYER_ERROR_NONE) {
5453 player_msg_get(val, ret_buf);
5454 *enabled = (bool)val;
5461 int player_audio_offload_is_activated(player_h player, bool *activated)
5463 int ret = PLAYER_ERROR_NONE;
5464 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_OFFLOAD_IS_ACTIVATED;
5465 player_cli_s *pc = (player_cli_s *)player;
5466 char *ret_buf = NULL;
5469 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_AUDIO_OFFLOAD);
5470 PLAYER_INSTANCE_CHECK(player);
5471 PLAYER_NULL_ARG_CHECK(activated);
5475 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5476 if (ret == PLAYER_ERROR_NONE) {
5477 player_msg_get(val, ret_buf);
5478 *activated = (bool)val;
5485 int player_set_audio_codec_type(player_h player, player_codec_type_e codec_type)
5487 PLAYER_INSTANCE_CHECK(player);
5488 PLAYER_RANGE_ARG_CHECK(codec_type, PLAYER_CODEC_TYPE_HW, PLAYER_CODEC_TYPE_SW);
5490 int ret = PLAYER_ERROR_NONE;
5491 muse_player_api_e api = MUSE_PLAYER_API_SET_CODEC_TYPE;
5492 player_cli_s *pc = (player_cli_s *)player;
5493 char *ret_buf = NULL;
5495 LOGD("ENTER codec: %d", codec_type);
5497 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5498 MUSE_TYPE_INT, "stream_type", PLAYER_STREAM_TYPE_AUDIO,
5499 MUSE_TYPE_INT, "codec_type", codec_type);
5507 int player_get_audio_codec_type(player_h player, player_codec_type_e *codec_type)
5509 PLAYER_INSTANCE_CHECK(player);
5510 PLAYER_NULL_ARG_CHECK(codec_type);
5512 int ret = PLAYER_ERROR_NONE;
5513 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_TYPE;
5514 player_cli_s *pc = (player_cli_s *)player;
5515 char *ret_buf = NULL;
5520 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5521 MUSE_TYPE_INT, "stream_type", PLAYER_STREAM_TYPE_AUDIO);
5522 if (ret == PLAYER_ERROR_NONE) {
5523 player_msg_get(type, ret_buf);
5528 LOGD("LEAVE codec: %d", *codec_type);