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 PLAYER_FEATURE_SOUND_STREAM "http://tizen.org/feature/multimedia.player.stream_info"
46 #define PLAYER_FEATURE_OPENGL "http://tizen.org/feature/opengles.version.2_0"
47 #define PLAYER_FEATURE_SPHERICAL_VIDEO "http://tizen.org/feature/multimedia.player.spherical_video"
49 #define M_PI 3.14159265358979323846
53 tbm_fd tfd[MUSE_NUM_FD];
59 callback_cb_info_s *cb_info;
60 _player_recv_data *recv_data;
65 intptr_t remote_v_data;
69 } _media_pkt_fin_data;
71 static int _player_deinit_memory_buffer(player_cli_s * pc);
72 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data);
73 static bool _player_need_sync_context(int event_id);
74 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all);
75 #ifdef TIZEN_FEATURE_EVAS_RENDERER
76 typedef void (*player_retrieve_buffer_cb)(void *user_data);
77 static void __retrieve_buffer_cb(void *user_data);
78 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data);
79 static int __player_unset_retrieve_buffer_cb(player_h player);
81 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem);
84 * Internal Implementation
86 int _player_send_msg(muse_player_api_e api, player_cli_s *player, char* msg, tbm_fd tfd, char **retbuf)
88 int ret = PLAYER_ERROR_NONE;
90 int send_fd = INVALID_DEFAULT_VALUE;
91 int send_tfd[MUSE_NUM_FD];
92 int timeout = client_get_api_timeout(player, api);
94 memset(send_tfd, INVALID_DEFAULT_VALUE, sizeof(send_tfd));
96 if (player && CALLBACK_INFO(player)) {
97 send_fd = MSG_FD(player);
99 LOGE("can not access to cb_info");
100 return PLAYER_ERROR_INVALID_STATE;
103 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
104 LOGE("invalid socket fd %d", send_fd);
105 return PLAYER_ERROR_INVALID_OPERATION;
108 if (tfd != INVALID_DEFAULT_VALUE) {
110 send_len = muse_core_msg_send_fd(send_fd, send_tfd, msg);
112 send_len = muse_core_msg_send(send_fd, msg);
115 LOGE("sending message failed");
116 return PLAYER_ERROR_INVALID_OPERATION;
118 ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), retbuf, timeout);
124 int _player_send_msg_async(int send_fd, char* msg)
128 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
129 LOGE("invalid socket fd %d", send_fd);
130 return PLAYER_ERROR_INVALID_OPERATION;
133 send_len = muse_core_msg_send(send_fd, msg);
135 LOGE("sending message failed");
136 return PLAYER_ERROR_INVALID_OPERATION;
139 return PLAYER_ERROR_NONE;
142 static int _get_current_state(player_cli_s *pc, player_state_e *pstate)
144 PLAYER_INSTANCE_CHECK(pc);
145 PLAYER_NULL_ARG_CHECK(pstate);
146 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
147 int ret = PLAYER_ERROR_NONE;
148 int state = PLAYER_STATE_NONE;
149 char *ret_buf = NULL;
151 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
153 if (ret == PLAYER_ERROR_NONE) {
154 player_msg_get(state, ret_buf);
156 LOGD("current state %d", *pstate);
163 static bool _player_get_param_value(char* buf, ...)
165 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
168 int type = MUSE_TYPE_ANY;
169 char *param_name = NULL;
174 void *jobj = muse_core_msg_object_new(buf, NULL, &err);
177 LOGE("failed to get msg object. err:%d", err);
181 va_start(var_args, buf);
183 while ((type = va_arg(var_args, int)) != INVALID_MUSE_TYPE_VALUE) {
184 param_name = va_arg(var_args, char *);
187 case MUSE_TYPE_INT64:
188 case MUSE_TYPE_DOUBLE:
189 case MUSE_TYPE_STRING:
190 case MUSE_TYPE_POINTER:
191 value = va_arg(var_args, void *);
193 if (!muse_core_msg_object_get_value(param_name, jobj, type, value)) {
195 LOGE("failed to get %s value", param_name);
199 LOGE("Unexpected type");
205 muse_core_msg_object_free(jobj);
211 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
213 int ret = MEDIA_PACKET_FINALIZE;
214 muse_player_api_e api = MUSE_PLAYER_API_RETURN_VIDEO_DATA;
215 _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
217 char *snd_msg = NULL;
221 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
225 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
226 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
230 if (!fin_data->use_tsurf_pool) {
231 tbm_surface_h tsurf = NULL;
232 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
233 LOGE("media_packet_get_tbm_surface failed");
234 /* continue the remained job */
237 /* LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf); */
238 tbm_surface_destroy(tsurf);
242 /* Do not destroy tbm surface here to reuse during playback *
243 * they will be destroyed at player_unprepare() or player_destroy(). *
244 * ref: __player_remove_tsurf_list() */
246 tbm_surface_h tsurf = NULL;
248 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
249 /* LOGD("tsurf set to null %p", tsurf); */
254 if (muse_core_fd_is_valid(fin_data->fd)) {
255 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
256 LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
260 v_data = fin_data->remote_v_data;
261 snd_msg = muse_core_msg_new(api, MUSE_TYPE_POINTER, "v_data", v_data, 0);
262 snd_len = muse_core_msg_send(fin_data->fd, snd_msg);
263 muse_core_msg_free(snd_msg);
266 LOGE("[fd:%d] fail to send msg.", fin_data->fd);
268 LOGE("[fd:%d] is invalid.", fin_data->fd);
280 static bool _player_video_roi_area_is_valid(double x_scale, double y_scale,
281 double w_scale, double h_scale)
283 if (x_scale >= 0.0 && x_scale <= 1.0 && y_scale >= 0.0 && y_scale <= 1.0
284 && w_scale > 0.0 && w_scale <= 1.0 && h_scale > 0.0 && h_scale <= 1.0)
287 LOGE("Video roi area is not valid");
291 static bool _player_check_network_availability(void)
293 #define _FEATURE_NAME_WIFI "http://tizen.org/feature/network.wifi"
294 #define _FEATURE_NAME_TELEPHONY "http://tizen.org/feature/network.telephony"
295 #define _FEATURE_NAME_ETHERNET "http://tizen.org/feature/network.ethernet"
296 bool enabled = FALSE;
297 bool supported = FALSE;
299 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
300 LOGI("wifi status = %d", enabled);
304 LOGE("SYSTEM_INFO_ERROR");
307 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
308 LOGI("telephony status = %d", enabled);
312 LOGE("SYSTEM_INFO_ERROR");
315 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
316 LOGI("ethernet status = %d", enabled);
320 LOGE("SYSTEM_INFO_ERROR");
329 static void *_get_mem(player_cli_s * player, int size)
331 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
333 mem->data = g_new(void, size);
334 mem->next = player->head;
341 static void _del_mem(player_cli_s * player)
344 while (player->head) {
345 mem = player->head->next;
346 g_free(player->head->data);
347 g_free(player->head);
352 static int player_recv_msg(callback_cb_info_s * cb_info, tbm_fd *tfd)
355 msg_buff_s *buff = &cb_info->buff;
357 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
358 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(*tfd) * MUSE_NUM_FD);
359 recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, MUSE_MSG_MAX_LENGTH, tfd);
361 LOGE("failed to recv msg %d", recvLen);
365 /* check the first msg */
366 if (buff->part_of_msg && buff->recvMsg[0] != '{')
368 gchar *tmp = strndup(buff->recvMsg, recvLen);
370 LOGE("failed to copy msg.");
374 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
377 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
378 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
379 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
380 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
381 if (!buff->recvMsg) {
382 LOGE("failed renew buffer.");
387 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
389 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
390 recvLen += strlen(buff->part_of_msg);
392 free(buff->part_of_msg);
393 buff->part_of_msg = NULL;
398 /* check the last msg */
399 if (buff->recvMsg[recvLen-1] != '}') {
400 char *part_pos = strrchr(buff->recvMsg, '}');
401 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
404 buff->part_of_msg = strndup(part_pos+1, part_len);
405 if (!buff->part_of_msg) {
406 LOGE("failed to alloc buffer for part of msg.");
409 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
417 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
419 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
420 cb_info->user_cb[event] = NULL;
421 cb_info->user_data[event] = NULL;
425 /* Notice : have to be called via API to avoid deadlock
426 * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
428 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
432 LOGD("event %d cb will be cleared", event);
435 LOGE("cb_info is NULL, event: %d", event);
439 lock = (g_thread_self() != cb_info->event_queue.thread);
442 g_mutex_lock(&cb_info->event_queue.mutex);
444 if (_player_need_sync_context(event))
445 _player_remove_idle_event(cb_info, event, false);
447 set_null_user_cb(cb_info, event);
450 g_mutex_unlock(&cb_info->event_queue.mutex);
453 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
455 PLAYER_INSTANCE_CHECK(player);
456 PLAYER_NULL_ARG_CHECK(callback);
457 int ret = PLAYER_ERROR_NONE;
458 player_cli_s *pc = (player_cli_s *) player;
459 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
462 if (MUSE_PLAYER_EVENT_TYPE_BUFFERING == type) {
463 if (!_player_check_network_availability())
464 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
467 if (!CALLBACK_INFO(pc))
468 return PLAYER_ERROR_INVALID_OPERATION;
470 LOGI("Event type : %d ", type);
471 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
473 if (ret == PLAYER_ERROR_NONE) {
474 pc->cb_info->user_cb[type] = callback;
475 pc->cb_info->user_data[type] = user_data;
480 static int __unset_callback(muse_player_event_e type, player_h player)
482 PLAYER_INSTANCE_CHECK(player);
483 int ret = PLAYER_ERROR_NONE;
484 player_cli_s *pc = (player_cli_s *) player;
485 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
488 LOGI("Event type : %d ", type);
490 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
491 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
493 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
498 static void __prepare_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
500 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
502 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
504 set_null_user_cb(cb_info, ev);
507 static void __complete_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
509 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
510 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
513 #ifdef TIZEN_FEATURE_EVAS_RENDERER
514 static void __retrieve_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
517 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
518 ((player_retrieve_buffer_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
522 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
524 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
525 ((player_interrupted_cb) cb_info->user_cb[ev]) (PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT, cb_info->user_data[ev]);
528 static void __error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
531 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
533 if (player_msg_get(code, recv_data->buffer)) {
534 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
535 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
536 LOGW("failed to pause, so prepare cb will be released soon");
537 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
540 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
544 static void __disconnected_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
546 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
548 ((player_error_cb) cb_info->user_cb[ev]) (PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
551 static void __buffering_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
554 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
556 if (player_msg_get(percent, recv_data->buffer))
557 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
560 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
563 char text[MUSE_URI_MAX_LENGTH] = { 0, };
564 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
567 ret = _player_get_param_value(recv_data->buffer,
568 MUSE_TYPE_INT, "duration", (void *)&duration,
569 MUSE_TYPE_STRING, "text", (void *)text,
570 INVALID_MUSE_TYPE_VALUE);
572 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
575 static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
577 unsigned char *data = NULL;
580 unsigned int size = 0;
582 tbm_bo_handle thandle;
583 int key = INVALID_DEFAULT_VALUE;
585 get_ret = _player_get_param_value(recv_data->buffer,
586 MUSE_TYPE_INT, "width", (void *)&width,
587 MUSE_TYPE_INT, "height", (void *)&height,
588 MUSE_TYPE_INT, "size", (void *)&size,
589 MUSE_TYPE_INT, "key", (void *)&key,
590 INVALID_MUSE_TYPE_VALUE);
592 if (recv_data->tfd[0] < 0) {
593 LOGE("There is no valid tbm_fd");
597 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
599 LOGE("TBM get error : bo is NULL");
602 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
603 if (thandle.ptr == NULL) {
604 LOGE("TBM get error : handle pointer is NULL");
607 data = g_new(unsigned char, size);
609 memcpy(data, thandle.ptr, size);
610 ((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]);
613 LOGE("g_new failure");
619 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
620 close(recv_data->tfd[0]);
621 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
627 if (key > INVALID_DEFAULT_VALUE) {
628 LOGD("send msg to release buffer. key:%d", key);
629 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
632 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
635 static void __seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
637 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
638 #ifdef TIZEN_FEATURE_EVAS_RENDERER
639 void *dl_handle = NULL;
640 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
642 g_mutex_lock(&cb_info->seek_cb_mutex);
644 switch (cb_info->seek_cb_state) {
645 case PLAYER_SEEK_CB_STATE_NONE:
647 if (!cb_info->user_cb[ev]) {
648 LOGW("invalid seek callback info, skip");
652 #ifdef TIZEN_FEATURE_EVAS_RENDERER
653 if (cb_info->evas_info && cb_info->evas_info->support_video) {
654 if (cb_info->evas_info->handle && cb_info->evas_info->visible != EVAS_VISIBLE_FALSE) {
655 dl_handle = dlopen(PATH_DISP_LIB, RTLD_LAZY);
657 PLAYER_DISP_DLSYM(dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
658 int ret = p_disp_set_evas_display_visible(cb_info->evas_info->handle, true);
660 if (ret != MM_ERROR_NONE)
661 LOGW("failed to set visible at evas 0x%x", ret);
663 cb_info->evas_info->visible = EVAS_VISIBLE_TRUE;
665 LOGW("not support video rendering");
670 LOGD("call seek cb");
671 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
672 set_null_user_cb(cb_info, ev);
676 case PLAYER_SEEK_CB_STATE_DROP:
677 case PLAYER_SEEK_CB_STATE_WAIT: /* not expected */
678 LOGW("ignored. seek cb %p, state %d", cb_info->user_cb[ev], cb_info->seek_cb_state);
681 LOGE("invalid state value");
685 g_mutex_unlock(&cb_info->seek_cb_mutex);
688 static void __player_remove_tsurf_list(player_cli_s * pc)
692 g_mutex_lock(&pc->cb_info->data_mutex);
693 if (pc->cb_info->tsurf_list) {
694 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
696 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
697 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
699 LOGD("%p will be removed", tmp);
702 tbm_surface_destroy(tmp->tsurf);
708 g_list_free(pc->cb_info->tsurf_list);
709 pc->cb_info->tsurf_list = NULL;
711 g_mutex_unlock(&pc->cb_info->data_mutex);
715 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, int height, int width)
719 g_mutex_lock(&cb_info->data_mutex);
720 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
721 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
722 if (tmp && key && (tmp->key[0] == key[0])) {
723 LOGD("found tsurf_data of tbm_key %d", key[0]);
725 /* need to check tsuf info to support DRC */
726 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
727 (tbm_surface_get_width(tmp->tsurf) != width)) {
729 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
730 LOGW("tsurf info is changed. need to create new tsurf.");
731 tbm_surface_destroy(tmp->tsurf);
734 g_mutex_unlock(&cb_info->data_mutex);
738 g_mutex_unlock(&cb_info->data_mutex);
743 g_mutex_unlock(&cb_info->data_mutex);
747 static media_packet_rotate_method_e __convert_packet_orient_info(int orientation)
749 media_packet_rotate_method_e rotate = MEDIA_PACKET_ROTATE_IDENTITY;
751 switch (orientation) {
753 rotate = MEDIA_PACKET_ROTATE_90;
756 rotate = MEDIA_PACKET_ROTATE_180;
759 rotate = MEDIA_PACKET_ROTATE_270;
762 rotate = MEDIA_PACKET_ROTATE_IDENTITY;
769 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
771 tbm_bo bo[4] = { NULL, };
772 int key[4] = { INVALID_DEFAULT_VALUE, };
773 tbm_surface_info_s sinfo;
774 char *surface_info = (char *)&sinfo;
775 media_packet_h pkt = NULL;
776 tbm_surface_h tsurf = NULL;
777 player_tsurf_info_t *tsurf_data = NULL;
779 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
780 bool make_pkt_fmt = false;
781 int ret = MEDIA_FORMAT_ERROR_NONE;
782 _media_pkt_fin_data *fin_data = NULL;
785 int i = 0, orientation = 0;
786 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
788 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
790 !muse_core_msg_object_get_value("key[0]", jobj, MUSE_TYPE_ANY, &key[0]) ||
791 !muse_core_msg_object_get_value("key[1]", jobj, MUSE_TYPE_ANY, &key[1]) ||
792 !muse_core_msg_object_get_value("key[2]", jobj, MUSE_TYPE_ANY, &key[2]) ||
793 !muse_core_msg_object_get_value("key[3]", jobj, MUSE_TYPE_ANY, &key[3]) ||
794 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
795 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
796 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
797 !muse_core_msg_object_get_value("orientation", jobj, MUSE_TYPE_INT, &orientation) ||
798 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
800 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
802 muse_core_msg_object_free(jobj);
805 muse_core_msg_object_free(jobj);
807 LOGD("width %d, height %d", sinfo.width, sinfo.height);
810 LOGE("cb_info is null");
814 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
815 /* send msg to release v_data. */
816 LOGE("_video_decoded_cb is not set");
820 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
821 LOGE("tbm fd is invalid");
825 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
827 for (i = 0; i < MUSE_NUM_FD; i++) {
828 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
832 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
835 tsurf_data = g_new(player_tsurf_info_t, 1);
837 LOGE("failed to alloc tsurf info");
840 memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
842 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
844 LOGE("failed to create tbm surface");
848 memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
849 tsurf_data->tsurf = tsurf;
850 if (cb_info->use_tsurf_pool) {
851 g_mutex_lock(&cb_info->data_mutex);
852 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
853 LOGD("key %d is added to the pool", key[0]);
854 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
855 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
856 g_mutex_unlock(&cb_info->data_mutex);
859 if (tsurf_data->tsurf) {
860 tsurf = tsurf_data->tsurf;
862 LOGE("tsurf_data->tsurf is null (never enter here)");
867 /* check media packet format */
868 if (cb_info->pkt_fmt) {
869 int pkt_fmt_width = 0;
870 int pkt_fmt_height = 0;
871 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
873 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
874 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
875 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);
876 media_format_unref(cb_info->pkt_fmt);
877 cb_info->pkt_fmt = NULL;
883 /* create packet format */
885 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
886 ret = media_format_create(&cb_info->pkt_fmt);
887 if (ret == MEDIA_FORMAT_ERROR_NONE) {
888 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
889 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
890 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
891 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
893 LOGE("media_format_create failed");
897 fin_data = g_new0(_media_pkt_fin_data, 1);
899 LOGE("failed to alloc fin_data");
902 fin_data->remote_v_data = v_data;
903 fin_data->fd = cb_info->fd;
904 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
906 /* Keep the fd id to check validation when the pkt is destroyed. */
907 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
909 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
910 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
911 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
916 ret = media_packet_set_pts(pkt, (uint64_t) pts);
917 if (ret != MEDIA_PACKET_ERROR_NONE)
918 LOGE("media_packet_set_pts failed");
921 ret = media_packet_set_rotate_method(pkt, __convert_packet_orient_info(orientation));
922 if (ret != MEDIA_PACKET_ERROR_NONE)
923 LOGE("media_packet_set_rotate_method failed");
925 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
926 /* call media packet callback */
927 ((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]);
929 LOGE("_video_decoded_cb is not set");
930 media_packet_destroy(pkt);
933 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
934 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
935 close(recv_data->tfd[i]);
938 for (i = 0; i < bo_num; i++) {
943 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
948 media_packet_destroy(pkt);
953 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
954 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
955 close(recv_data->tfd[i]);
958 for (i = 0; i < bo_num; i++) {
962 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
964 if (cb_info && v_data)
965 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, MUSE_TYPE_POINTER, "v_data", v_data);
970 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
973 tbm_bo_handle thandle;
974 int key = INVALID_DEFAULT_VALUE;
975 player_audio_raw_data_s audio;
977 if (!player_msg_get(key, recv_data->buffer)) {
978 LOGE("failed to get key value from msg.");
982 if (recv_data->tfd[0] < 0) {
983 LOGE("failed to get tbm_fd(key:%d)", key);
987 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
989 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
993 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
994 if (thandle.ptr == NULL) {
995 LOGE("TBM get error : handle pointer is NULL");
999 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
1000 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
1002 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
1003 ((player_audio_pcm_extraction_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME]) (&audio, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME]);
1007 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
1008 close(recv_data->tfd[0]);
1009 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1015 if (key > INVALID_DEFAULT_VALUE) {
1016 /* LOGD("send msg to release buffer. key:%d", key); */
1017 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
1021 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1025 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1029 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1033 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1037 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1039 /* player_media_stream_buffer_status_e status; */
1042 if (player_msg_get(status, recv_data->buffer)) {
1043 ((player_media_stream_buffer_status_cb)
1044 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]) ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS]);
1048 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1050 /* player_media_stream_buffer_status_e status; */
1053 if (player_msg_get(status, recv_data->buffer)) {
1054 ((player_media_stream_buffer_status_cb)
1055 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
1056 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
1061 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1063 /* player_media_stream_buffer_status_e status; */
1065 unsigned long long bytes;
1068 ret = _player_get_param_value(recv_data->buffer,
1069 MUSE_TYPE_INT, "status", (void *)&status,
1070 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1071 INVALID_MUSE_TYPE_VALUE);
1073 ((player_media_stream_buffer_status_cb_ex)
1074 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
1075 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
1079 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1081 /* player_media_stream_buffer_status_e status; */
1083 unsigned long long bytes;
1086 ret = _player_get_param_value(recv_data->buffer,
1087 MUSE_TYPE_INT, "status", (void *)&status,
1088 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1089 INVALID_MUSE_TYPE_VALUE);
1091 ((player_media_stream_buffer_status_cb_ex)
1092 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
1093 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
1098 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1100 unsigned long long offset;
1102 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1103 ((player_media_stream_seek_cb)
1104 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
1105 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
1109 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1111 unsigned long long offset;
1113 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1114 ((player_media_stream_seek_cb)
1115 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
1116 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1120 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1126 bool ret_val = TRUE;
1127 ret_val = _player_get_param_value(recv_data->buffer,
1128 MUSE_TYPE_INT, "width", (void *)&width,
1129 MUSE_TYPE_INT, "height", (void *)&height,
1130 MUSE_TYPE_INT, "fps", (void *)&fps,
1131 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
1132 INVALID_MUSE_TYPE_VALUE);
1134 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1135 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1139 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, _player_recv_data *recv_data) = {
1140 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1141 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1142 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1143 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1144 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1145 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1146 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1147 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1148 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1149 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
1150 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1151 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1152 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1153 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1154 #ifdef _PLAYER_FOR_PRODUCT
1155 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1156 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1158 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1159 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1160 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1161 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1162 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1163 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1164 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1165 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1166 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1167 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1169 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1172 gboolean _player_event_job_function(void *user_data)
1174 _player_cb_data *data = (_player_cb_data *)user_data;
1175 muse_player_event_e ev;
1178 LOGE("data is null");
1182 LOGD("enter ev:%d", data->int_data);
1184 g_mutex_lock(&data->event_mutex);
1185 ev = data->int_data;
1187 if (data->cb_info == NULL) {
1188 /* tried to remove before at _player_remove_idle_event */
1189 LOGW("cb_info is NULL. event %d", data->int_data);
1193 /* remove event from list */
1194 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1195 if (data->cb_info->event_queue.idle_ev_list) {
1196 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1197 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1199 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1201 if (data->cb_info->user_cb[ev])
1202 _user_callbacks[ev] (data->cb_info, data->recv_data);
1204 LOGW("user callback is unset. type : %d", ev);
1207 /* unlock and release event */
1208 g_mutex_unlock(&data->event_mutex);
1209 g_mutex_clear(&data->event_mutex);
1211 if (data->recv_data) {
1212 g_free(data->recv_data->buffer);
1213 g_free(data->recv_data);
1217 return FALSE; /* remove from the event list */
1220 static bool _player_need_sync_context(int event_id)
1222 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1223 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1224 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1225 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1226 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1227 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1228 LOGD("%d callback will be issued in the mainloop.", event_id);
1235 static void *_player_event_queue_loop(void *param)
1238 LOGE("NULL parameter");
1241 callback_cb_info_s *cb_info = param;
1242 player_event_queue *ev = &cb_info->event_queue;
1243 _player_cb_data *event_data = NULL;
1245 g_mutex_lock(&ev->mutex);
1246 while (ev->running) {
1247 g_mutex_lock(&ev->qlock);
1248 if (g_queue_is_empty(ev->queue)) {
1249 g_mutex_unlock(&ev->qlock);
1250 g_cond_wait(&ev->cond, &ev->mutex);
1254 g_mutex_unlock(&ev->qlock);
1257 g_mutex_lock(&ev->qlock);
1258 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1259 g_mutex_unlock(&ev->qlock);
1261 muse_player_event_e event_type = ((_player_cb_data *)event_data)->int_data;
1263 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1264 g_mutex_lock(&cb_info->seek_cb_mutex);
1265 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1266 /* push event into queue again. */
1267 _player_event_queue_add(ev, event_data);
1268 g_mutex_unlock(&cb_info->seek_cb_mutex);
1271 g_mutex_unlock(&cb_info->seek_cb_mutex);
1274 if (_player_need_sync_context(event_data->int_data)) {
1275 if (cb_info->user_cb[event_data->int_data] &&
1276 _user_callbacks[event_data->int_data]) {
1277 g_mutex_lock(&ev->idle_ev_mutex);
1278 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1279 g_mutex_unlock(&ev->idle_ev_mutex);
1281 LOGD("add ev %d to main loop", event_data->int_data);
1283 g_idle_add_full(G_PRIORITY_DEFAULT,
1284 (GSourceFunc)_player_event_job_function,
1285 (gpointer)event_data,
1288 LOGW("there is no registered cb for ev:%d", event_data->int_data);
1289 if (event_data->recv_data) {
1290 g_free(event_data->recv_data->buffer);
1291 g_free(event_data->recv_data);
1296 _player_event_job_function(event_data);
1303 g_mutex_unlock(&ev->mutex);
1304 LOGI("Exit event loop");
1308 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1310 g_return_val_if_fail(cb_info, FALSE);
1311 player_event_queue *ev = &cb_info->event_queue;
1313 ev->queue = g_queue_new();
1314 g_return_val_if_fail(ev->queue, FALSE);
1315 g_mutex_init(&ev->qlock);
1317 g_mutex_init(&ev->mutex);
1318 g_cond_init(&ev->cond);
1321 g_mutex_init(&ev->idle_ev_mutex);
1323 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1324 g_return_val_if_fail(ev->thread, FALSE);
1325 LOGI("event queue thread %p", ev->thread);
1331 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1333 g_return_if_fail(cb_info);
1334 player_event_queue *ev = &cb_info->event_queue;
1335 _player_cb_data *event_data = NULL;
1338 g_mutex_lock(&ev->idle_ev_mutex);
1340 if (ev->idle_ev_list == NULL) {
1341 LOGD("No idle event is remained.");
1342 g_mutex_unlock(&ev->idle_ev_mutex);
1346 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1348 list = ev->idle_ev_list;
1350 event_data = list->data;
1351 list = g_list_next(list);
1354 LOGW("Fail to remove idle event. The data is NULL");
1358 if (g_mutex_trylock(&event_data->event_mutex)) {
1360 gboolean ret = FALSE;
1361 if (remove_all || (event_data->int_data == event_type)) {
1363 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1365 ret = g_idle_remove_by_data(event_data);
1367 /* will be handled at _player_event_job_function() as an exception */
1368 event_data->cb_info = NULL;
1369 LOGW("failed to remove, idle callback will be called later");
1372 /* set cb to null */
1373 set_null_user_cb(cb_info, event_data->int_data);
1374 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1376 g_mutex_unlock(&event_data->event_mutex);
1379 g_mutex_clear(&event_data->event_mutex);
1380 if (event_data->recv_data) {
1381 g_free(event_data->recv_data->buffer);
1382 g_free(event_data->recv_data);
1386 LOGD("remove idle event done");
1387 } /* else : will be handled if the cb is called. */
1389 g_mutex_unlock(&event_data->event_mutex);
1392 LOGW("event(%d) lock failed. it's being called...", event_data->int_data);
1395 /* continue: keep checking next event_data */
1399 g_list_free(ev->idle_ev_list);
1400 ev->idle_ev_list = NULL;
1403 g_mutex_unlock(&ev->idle_ev_mutex);
1409 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1411 g_return_if_fail(cb_info);
1412 player_event_queue *ev = &cb_info->event_queue;
1413 _player_cb_data *event_data;
1415 LOGI("event queue thread %p", ev->thread);
1417 g_mutex_lock(&ev->mutex);
1418 ev->running = FALSE;
1419 g_cond_broadcast(&ev->cond);
1420 g_mutex_unlock(&ev->mutex);
1422 g_thread_join(ev->thread);
1425 while (!g_queue_is_empty(ev->queue)) {
1426 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1428 g_free(event_data->recv_data->buffer);
1429 g_free(event_data->recv_data);
1433 g_queue_free(ev->queue);
1434 g_mutex_clear(&ev->qlock);
1435 g_mutex_clear(&ev->mutex);
1436 g_cond_clear(&ev->cond);
1437 g_mutex_clear(&ev->idle_ev_mutex);
1440 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1444 g_mutex_lock(&ev_queue->qlock);
1446 item = g_queue_peek_head_link(ev_queue->queue);
1448 GList *next = item->next;
1449 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1451 if (cb_data && cb_data->int_data == ev) {
1452 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1453 g_free(cb_data->recv_data->buffer);
1454 g_free(cb_data->recv_data);
1457 g_queue_delete_link(ev_queue->queue, item);
1461 g_mutex_unlock(&ev_queue->qlock);
1464 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1467 g_mutex_lock(&ev->qlock);
1468 g_queue_push_tail(ev->queue, (gpointer) data);
1469 g_mutex_unlock(&ev->qlock);
1470 g_cond_signal(&ev->cond);
1474 static bool _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1476 /* LOGD("get event %d", event); */
1478 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1479 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1480 _player_cb_data *data = NULL;
1481 data = g_new(_player_cb_data, 1);
1483 LOGE("fail to alloc mem");
1486 data->int_data = (int)event;
1487 data->cb_info = cb_info;
1488 data->recv_data = recv_data;
1489 g_mutex_init(&data->event_mutex);
1490 _player_event_queue_add(&cb_info->event_queue, data);
1496 LOGE("failed to add event to queue");
1500 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1502 ret_msg_s *msg = NULL;
1503 ret_msg_s *last = cb_info->buff.retMsgHead;
1505 msg = g_new(ret_msg_s, 1);
1508 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1511 cb_info->buff.retMsgHead = msg;
1518 LOGE("g_new failure");
1521 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1523 ret_msg_s *msg = cb_info->buff.retMsgHead;
1524 ret_msg_s *prev = NULL;
1526 if (msg->api == api) {
1528 cb_info->buff.retMsgHead = msg->next;
1530 prev->next = msg->next;
1539 static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
1541 ret_msg_s *msg = cb_info->buff.retMsgHead;
1542 ret_msg_s *prev = NULL;
1546 LOGI("Remove %s", prev->msg);
1553 static void _notify_disconnected(callback_cb_info_s * cb_info)
1555 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1556 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1559 if (_user_callbacks[event]) {
1560 _player_cb_data *data = NULL;
1561 data = g_new(_player_cb_data, 1);
1563 LOGE("fail to alloc mem");
1566 data->int_data = (int)event;
1567 data->cb_info = cb_info;
1568 data->recv_data = NULL;
1569 g_mutex_init(&data->event_mutex);
1570 _player_event_queue_add(&cb_info->event_queue, data);
1574 static void *client_cb_handler(gpointer data)
1580 callback_cb_info_s *cb_info = data;
1581 char *recvMsg = NULL;
1582 muse_core_msg_parse_err_e err;
1583 tbm_fd tfd[MUSE_NUM_FD];
1585 while (g_atomic_int_get(&cb_info->running)) {
1587 err = MUSE_MSG_PARSE_ERROR_NONE;
1589 len = player_recv_msg(cb_info, tfd);
1593 recvMsg = cb_info->buff.recvMsg;
1594 recvMsg[len] = '\0';
1598 while (offset < len) {
1599 api = MUSE_PLAYER_API_MAX;
1600 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1603 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1605 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1606 if (api < MUSE_PLAYER_API_MAX) {
1607 g_mutex_lock(&cb_info->player_mutex);
1608 cb_info->buff.recved++;
1609 _add_ret_msg(api, cb_info, offset, parse_len);
1610 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1611 LOGD("get tbm fd for album art.");
1612 cb_info->tfd = tfd[0];
1614 g_cond_signal(&cb_info->player_cond[api]);
1615 g_mutex_unlock(&cb_info->player_mutex);
1616 if (api == MUSE_PLAYER_API_DESTROY)
1617 g_atomic_int_set(&cb_info->running, 0);
1618 } else if (api == MUSE_PLAYER_CB_EVENT) {
1620 _player_recv_data *recv_data = NULL;
1621 g_mutex_lock(&cb_info->player_mutex);
1622 recv_data = g_new0(_player_recv_data, 1);
1623 if (recv_data != NULL) {
1624 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1625 recv_data->buffer = strndup(recvMsg+offset, parse_len);
1627 LOGE("failed to alloc recv_data.");
1628 g_mutex_unlock(&cb_info->player_mutex);
1629 muse_core_msg_object_free(jobj);
1632 g_mutex_unlock(&cb_info->player_mutex);
1633 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1634 !_user_callback_handler(cb_info, event, recv_data)) {
1635 LOGE("failed to get value or add event to the queue.");
1637 g_free(recv_data->buffer);
1641 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1642 g_mutex_lock(&cb_info->player_mutex);
1643 cb_info->buff.recved++;
1644 g_cond_signal(&cb_info->server_ack_cond);
1645 g_mutex_unlock(&cb_info->player_mutex);
1648 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1650 muse_core_msg_object_free(jobj);
1652 LOGE("Failed to get msg obj. err:%d", err);
1655 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1658 offset += parse_len;
1659 parse_len = len - offset;
1662 if (g_atomic_int_get(&cb_info->running))
1663 _notify_disconnected(cb_info);
1665 g_atomic_int_set(&cb_info->running, 0);
1666 LOGD("client cb exit");
1671 static callback_cb_info_s *callback_new(gint sockfd)
1673 callback_cb_info_s *cb_info;
1677 g_return_val_if_fail(sockfd > 0, NULL);
1679 cb_info = g_new(callback_cb_info_s, 1);
1682 memset(cb_info, 0, sizeof(callback_cb_info_s));
1684 g_mutex_init(&cb_info->player_mutex);
1685 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1686 g_cond_init(&cb_info->player_cond[i]);
1687 g_cond_init(&cb_info->server_ack_cond);
1689 g_mutex_init(&cb_info->data_mutex);
1690 g_mutex_init(&cb_info->seek_cb_mutex);
1692 buff = &cb_info->buff;
1693 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1694 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1696 buff->retMsgHead = NULL;
1697 buff->part_of_msg = NULL;
1699 g_atomic_int_set(&cb_info->running, 1);
1700 cb_info->fd = sockfd;
1701 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1702 cb_info->tfd = INVALID_DEFAULT_VALUE;
1707 static void callback_destroy(callback_cb_info_s * cb_info)
1710 g_return_if_fail(cb_info);
1712 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1713 muse_client_close(cb_info->fd);
1714 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1715 muse_client_close(cb_info->data_fd);
1717 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1719 g_thread_join(cb_info->thread);
1720 cb_info->thread = NULL;
1722 LOGI("%p Callback destroyed", cb_info);
1724 for (i = 0; i < MUSE_PLAYER_API_MAX; i++) {
1725 g_mutex_lock(&cb_info->player_mutex);
1726 g_cond_signal(&cb_info->player_cond[i]);
1727 g_mutex_unlock(&cb_info->player_mutex);
1728 g_cond_clear(&cb_info->player_cond[i]);
1731 /* to make sure the return of other pending api */
1733 g_mutex_lock(&cb_info->player_mutex);
1734 g_mutex_unlock(&cb_info->player_mutex);
1735 g_mutex_clear(&cb_info->player_mutex);
1737 g_cond_clear(&cb_info->server_ack_cond);
1739 g_mutex_clear(&cb_info->data_mutex);
1740 g_mutex_clear(&cb_info->seek_cb_mutex);
1742 g_free(cb_info->buff.recvMsg);
1743 _remove_all_ret_msg(cb_info);
1744 if (cb_info->buff.part_of_msg)
1745 g_free(cb_info->buff.part_of_msg);
1749 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1754 case MUSE_PLAYER_API_PREPARE:
1755 case MUSE_PLAYER_API_PREPARE_ASYNC:
1756 case MUSE_PLAYER_API_UNPREPARE:
1757 case MUSE_PLAYER_API_START:
1758 case MUSE_PLAYER_API_STOP:
1759 case MUSE_PLAYER_API_PAUSE:
1760 timeout += SERVER_TIMEOUT(pc);
1763 /* check prepare async is done */
1764 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1765 timeout += SERVER_TIMEOUT(pc);
1768 timeout += CALLBACK_TIME_OUT;
1769 return timeout; /* ms */
1772 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1774 int ret = PLAYER_ERROR_NONE;
1775 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1776 msg_buff_s *buff = &cb_info->buff;
1777 ret_msg_s *msg = NULL;
1779 g_mutex_lock(&cb_info->player_mutex);
1781 msg = _get_ret_msg(api, cb_info);
1783 if (!buff->recved || !msg) {
1784 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1785 LOGW("api %d return msg does not received %dms", api, time_out);
1786 ret = PLAYER_ERROR_INVALID_OPERATION;
1792 msg = _get_ret_msg(api, cb_info);
1794 *ret_buf = msg->msg;
1797 if (!player_msg_get(ret, *ret_buf))
1798 ret = PLAYER_ERROR_INVALID_OPERATION;
1799 else if (ret != PLAYER_ERROR_NONE)
1800 LOGE("Get error return from server 0x%X", ret);
1804 if (!g_atomic_int_get(&cb_info->running)) {
1805 LOGE("callback thread is stopped. %d api did not get return in time", api);
1806 ret = PLAYER_ERROR_INVALID_OPERATION;
1809 LOGW("api %d is the spurious wakeup, wait again", api);
1811 } while (!msg && g_atomic_int_get(&cb_info->running));
1813 g_mutex_unlock(&cb_info->player_mutex);
1817 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1819 int ret = PLAYER_ERROR_NONE;
1820 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1821 msg_buff_s *buff = &cb_info->buff;
1823 g_mutex_lock(&cb_info->player_mutex);
1825 if (!buff->recved) {
1826 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1827 LOGW("server ack msg does not received %dms", time_out);
1829 ret = PLAYER_ERROR_INVALID_OPERATION;
1831 LOGD("Another msg is received, continue create handle");
1832 g_mutex_unlock(&cb_info->player_mutex);
1838 g_mutex_unlock(&cb_info->player_mutex);
1845 * Public Implementation
1848 int player_create(player_h * player)
1850 PLAYER_INSTANCE_CHECK(player);
1852 int ret = PLAYER_ERROR_NONE;
1853 int sock_fd = INVALID_DEFAULT_VALUE;
1856 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1857 muse_core_api_module_e module = MUSE_PLAYER;
1858 player_cli_s *pc = NULL;
1859 char *ret_buf = NULL;
1860 int retry_count = CONNECTION_RETRY;
1865 pc = g_new0(player_cli_s, 1);
1867 return PLAYER_ERROR_OUT_OF_MEMORY;
1869 while (--retry_count) {
1870 ret = PLAYER_ERROR_NONE;
1871 sock_fd = muse_client_new();
1872 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1873 LOGE("connection failure %d", errno);
1874 ret = PLAYER_ERROR_INVALID_OPERATION;
1876 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1880 PLAYER_SEND_MSG_ASYNC(api, sock_fd, ret,
1881 MUSE_TYPE_INT, "module", module,
1882 MUSE_TYPE_INT, "pid", pid);
1883 if (ret == PLAYER_ERROR_INVALID_OPERATION)
1886 pc->cb_info = callback_new(sock_fd);
1888 LOGE("fail to create callback");
1889 ret = PLAYER_ERROR_INVALID_OPERATION;
1893 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1894 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1900 if (!_player_event_queue_new(pc->cb_info)) {
1901 LOGE("fail to create event queue");
1902 ret = PLAYER_ERROR_INVALID_OPERATION;
1906 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1907 if (ret == PLAYER_ERROR_NONE) {
1908 intptr_t module_addr = 0;
1909 *player = (player_h) pc;
1910 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1911 pc->cb_info->data_fd = muse_client_new_data_ch();
1912 if ((pc->cb_info->data_fd < 0) || (!muse_core_fd_is_valid(pc->cb_info->data_fd))) {
1913 LOGE("Failed to get data_fd");
1914 ret = PLAYER_ERROR_INVALID_OPERATION;
1918 /* share the module addr info to the data_fd */
1919 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_CREATE, pc->cb_info->data_fd, ret,
1920 MUSE_TYPE_POINTER, "module_addr", module_addr);
1921 if (ret != PLAYER_ERROR_NONE) {
1922 LOGE("Failed to send module address to the data fd");
1925 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1927 ret = PLAYER_ERROR_INVALID_OPERATION;
1930 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1934 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1935 pc->cb_info->evas_info = g_new0(player_evas_info_s, 1);
1936 if (pc->cb_info->evas_info == NULL) {
1937 ret = PLAYER_ERROR_OUT_OF_MEMORY;
1940 EVAS_INFO(pc)->visible = EVAS_VISIBLE_NONE;
1942 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1943 pc->push_media_stream = FALSE;
1944 pc->support_video = FALSE;
1945 EVAS_INFO(pc)->support_video = FALSE;
1946 pc->is_audio_only = FALSE;
1948 PLAYER_DISP_DLOPEN(pc); /* update supported_video */
1952 LOGD("LEAVE 0x%X", ret);
1956 if (pc && pc->cb_info) {
1957 if (pc->cb_info->event_queue.running)
1958 _player_event_queue_destroy(pc->cb_info);
1959 callback_destroy(pc->cb_info);
1961 } else if (sock_fd > INVALID_DEFAULT_VALUE) {
1962 muse_client_close(sock_fd);
1964 sock_fd = INVALID_DEFAULT_VALUE;
1967 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1975 LOGD("LEAVE 0x%X", ret);
1979 int player_destroy(player_h player)
1981 PLAYER_INSTANCE_CHECK(player);
1983 int ret = PLAYER_ERROR_NONE;
1984 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1985 player_cli_s *pc = (player_cli_s *) player;
1986 char *ret_buf = NULL;
1988 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1989 int (*p_disp_destroy_evas_display)(void **) = NULL;
1991 LOGD("ENTER %p", pc);
1993 /* clear cb and release mem */
1994 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1995 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1996 _player_release_internal_memory(pc, true);
1998 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1999 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)) {
2000 if (EVAS_INFO(pc)->support_video && EVAS_HANDLE(pc)) {
2001 player_unset_media_packet_video_frame_decoded_cb(player);
2002 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2003 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2004 LOGW("fail to unset evas client");
2005 __player_unset_retrieve_buffer_cb(player);
2007 g_free(EVAS_INFO(pc));
2011 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2013 if (CALLBACK_INFO(pc)) {
2014 __player_remove_tsurf_list(pc);
2015 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
2016 _player_event_queue_destroy(CALLBACK_INFO(pc));
2017 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
2019 callback_destroy(CALLBACK_INFO(pc));
2023 PLAYER_DISP_DLCLOSE(pc->dl_handle); /* update supported_video */
2030 LOGD("LEAVE 0x%X", ret);
2034 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
2036 PLAYER_INSTANCE_CHECK(player);
2037 int ret = PLAYER_ERROR_NONE;
2038 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
2039 player_cli_s *pc = (player_cli_s *) player;
2040 char *ret_buf = NULL;
2044 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
2045 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
2046 return PLAYER_ERROR_INVALID_OPERATION;
2048 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
2049 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
2051 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2052 if (ret == PLAYER_ERROR_NONE) {
2054 player_msg_get_type(timeout, ret_buf, INT);
2056 LOGD("server timeout will be %d sec", timeout);
2057 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2059 LOGW("failed to realize, so prepare cb will be released soon");
2060 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
2061 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2068 int player_prepare(player_h player)
2070 PLAYER_INSTANCE_CHECK(player);
2071 int ret = PLAYER_ERROR_NONE;
2072 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
2073 player_cli_s *pc = (player_cli_s *) player;
2074 char *ret_buf = NULL;
2076 LOGD("ENTER %p", pc);
2078 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2079 if (ret == PLAYER_ERROR_NONE) {
2081 player_msg_get_type(timeout, ret_buf, INT);
2083 LOGD("server timeout will be %d sec", timeout);
2084 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
2089 LOGD("LEAVE 0x%X", ret);
2093 int player_unprepare(player_h player)
2095 PLAYER_INSTANCE_CHECK(player);
2096 int ret = PLAYER_ERROR_NONE;
2097 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
2098 player_cli_s *pc = (player_cli_s *) player;
2099 char *ret_buf = NULL;
2100 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
2101 player_state_e state = PLAYER_STATE_NONE;
2103 LOGD("ENTER %p", pc);
2105 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2106 LOGE("Failed to get state");
2107 ret = PLAYER_ERROR_INVALID_OPERATION;
2111 if (state < PLAYER_STATE_READY) {
2112 if ((!CALLBACK_INFO(pc)) || (!CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])) {
2113 LOGE("Invalid state %d", state);
2114 ret = PLAYER_ERROR_INVALID_STATE;
2119 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2120 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2122 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2123 if (EVAS_INFO(pc)->support_video && EVAS_HANDLE(pc)) {
2124 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
2125 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(pc), false);
2126 if (ret != PLAYER_ERROR_NONE)
2127 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
2131 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2133 _player_release_internal_memory(pc, false);
2134 pc->cb_info->video_frame_pool_size = 0;
2135 __player_remove_tsurf_list(pc);
2136 pc->is_audio_only = FALSE;
2141 LOGD("LEAVE 0x%X", ret);
2145 /* 1. correct the protocol prefix to lower case
2146 * 2. remove 'file://' prefix
2147 * 3. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' */
2148 int _player_get_valid_path(const char* uri, char* valid_path)
2150 gchar *file_path = NULL;
2152 gchar *colon = NULL;
2154 if (!uri || !valid_path) {
2155 LOGD("invalid parameter");
2156 return PLAYER_ERROR_INVALID_PARAMETER;
2159 if ((colon = strstr(uri, "://")) != NULL) {
2160 gchar *protocol = g_ascii_strdown(uri, colon - uri);
2164 file_path = g_strconcat(protocol, uri+strlen(protocol), NULL);
2165 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2171 if (strstr(valid_path, "file://")) { /* handle the 'file://' prefix */
2173 file_path = g_filename_from_uri(valid_path, NULL, &err);
2174 if (!file_path || (err != NULL)) {
2175 SECURE_LOGE("Invalid URI '%s', err: %s", uri,
2176 (err != NULL) ? err->message : "unknown error");
2178 if (err) g_error_free(err);
2179 if (file_path) g_free(file_path);
2181 return PLAYER_ERROR_INVALID_PARAMETER;
2183 LOGD("get file path from uri");
2185 LOGD("use the original path.");
2186 return PLAYER_ERROR_NONE;
2191 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, valid_path) < 0) {
2192 /* cannot convert path. use the original one. */
2193 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2195 /* need to use converted path. */
2196 SECURE_LOGD("Converted path : %s -> %s", uri, valid_path);
2201 return PLAYER_ERROR_NONE;
2204 int player_set_uri(player_h player, const char *uri)
2206 PLAYER_INSTANCE_CHECK(player);
2207 PLAYER_NULL_ARG_CHECK(uri);
2208 int ret = PLAYER_ERROR_NONE;
2209 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2210 player_cli_s *pc = (player_cli_s *) player;
2211 char *ret_buf = NULL;
2212 char path[MAX_URL_LEN] = {0, };
2216 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
2217 return PLAYER_ERROR_INVALID_PARAMETER;
2219 SECURE_LOGD("new path : %s", path);
2221 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", (const char*)path);
2222 pc->push_media_stream = FALSE;
2228 int player_set_memory_buffer(player_h player, const void *data, int size)
2230 PLAYER_INSTANCE_CHECK(player);
2231 PLAYER_NULL_ARG_CHECK(data);
2232 int ret = PLAYER_ERROR_NONE;
2233 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2234 player_cli_s *pc = (player_cli_s *) player;
2235 char *ret_buf = NULL;
2237 tbm_bo_handle thandle;
2238 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2242 /* before setting mem buffer, player state have to be checked. */
2243 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2245 if (SERVER_TBM_BO(pc)) {
2246 LOGW("The previous memory buffer will be cleared.");
2247 _player_deinit_memory_buffer(pc);
2250 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2252 LOGE("TBM get error : bo is NULL");
2253 return PLAYER_ERROR_INVALID_OPERATION;
2255 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2256 if (thandle.ptr == NULL) {
2257 LOGE("TBM get error : handle pointer is NULL");
2258 ret = PLAYER_ERROR_INVALID_OPERATION;
2261 memcpy(thandle.ptr, data, size);
2264 tfd = tbm_bo_export_fd(bo);
2266 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2267 ret = PLAYER_ERROR_INVALID_OPERATION;
2271 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret, MUSE_TYPE_INT, "size", size);
2272 pc->push_media_stream = FALSE;
2275 if (tfd > INVALID_DEFAULT_VALUE)
2280 if (ret == PLAYER_ERROR_NONE) {
2281 intptr_t bo_addr = 0;
2282 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2283 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2290 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem)
2297 if (deinit_server_mem)
2298 _player_deinit_memory_buffer(pc);
2301 static int _player_deinit_memory_buffer(player_cli_s * pc)
2303 PLAYER_INSTANCE_CHECK(pc);
2304 int ret = PLAYER_ERROR_NONE;
2305 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2306 intptr_t bo_addr = SERVER_TBM_BO(pc);
2308 if (!bo_addr || !CALLBACK_INFO(pc))
2311 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_POINTER, "bo_addr", bo_addr);
2312 SERVER_TBM_BO(pc) = 0;
2317 int player_get_state(player_h player, player_state_e *pstate)
2319 PLAYER_INSTANCE_CHECK(player);
2320 PLAYER_NULL_ARG_CHECK(pstate);
2321 int ret = PLAYER_ERROR_NONE;
2322 player_cli_s *pc = (player_cli_s *) player;
2326 ret = _get_current_state(pc, pstate);
2330 int player_set_volume(player_h player, float left, float right)
2332 PLAYER_INSTANCE_CHECK(player);
2333 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2334 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2335 int ret = PLAYER_ERROR_NONE;
2336 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2337 player_cli_s *pc = (player_cli_s *) player;
2338 char *ret_buf = NULL;
2342 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2343 MUSE_TYPE_DOUBLE, "right", (double)right,
2344 MUSE_TYPE_DOUBLE, "left", (double)left);
2350 int player_get_volume(player_h player, float *pleft, float *pright)
2352 PLAYER_INSTANCE_CHECK(player);
2353 PLAYER_NULL_ARG_CHECK(pleft && pright);
2354 int ret = PLAYER_ERROR_NONE;
2355 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2356 player_cli_s *pc = (player_cli_s *) player;
2359 char *ret_buf = NULL;
2363 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2365 if (ret == PLAYER_ERROR_NONE) {
2366 bool ret_val = true;
2367 ret_val = _player_get_param_value(ret_buf,
2368 MUSE_TYPE_DOUBLE, "left", (void *)&left,
2369 MUSE_TYPE_DOUBLE, "right", (void *)&right,
2370 INVALID_MUSE_TYPE_VALUE);
2372 *pleft = (float)left;
2373 *pright = (float)right;
2375 LOGE("failed to get value from msg");
2376 ret = PLAYER_ERROR_INVALID_OPERATION;
2384 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2386 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SOUND_STREAM);
2387 PLAYER_INSTANCE_CHECK(player);
2389 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2390 player_cli_s *pc = (player_cli_s *) player;
2391 bool is_available = false;
2392 char *ret_buf = NULL;
2396 /* check if stream_info is valid */
2397 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2398 if (ret != SOUND_MANAGER_ERROR_NONE) {
2399 LOGE("failed to checking available stream info");
2400 return PLAYER_ERROR_INVALID_OPERATION;
2403 if (is_available == false) {
2404 ret = PLAYER_ERROR_INVALID_PARAMETER;
2406 char *stream_type = NULL;
2407 int stream_index = 0;
2408 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2409 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2410 if (ret == SOUND_MANAGER_ERROR_NONE)
2411 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2412 MUSE_TYPE_STRING, "stream_type", (const char*)stream_type,
2413 MUSE_TYPE_INT, "stream_index", stream_index);
2415 ret = PLAYER_ERROR_INVALID_OPERATION;
2418 LOGD("LEAVE ret: 0x%X", ret);
2425 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2427 PLAYER_INSTANCE_CHECK(player);
2428 int ret = PLAYER_ERROR_NONE;
2429 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2430 player_cli_s *pc = (player_cli_s *) player;
2431 char *ret_buf = NULL;
2435 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "latency_mode", (int)latency_mode);
2440 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2442 PLAYER_INSTANCE_CHECK(player);
2443 PLAYER_NULL_ARG_CHECK(platency_mode);
2444 int ret = PLAYER_ERROR_NONE;
2445 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2446 player_cli_s *pc = (player_cli_s *) player;
2447 char *ret_buf = NULL;
2448 int latency_mode = -1;
2452 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2454 if (ret == PLAYER_ERROR_NONE) {
2455 player_msg_get(latency_mode, ret_buf);
2456 *platency_mode = latency_mode;
2464 int player_start(player_h player)
2466 PLAYER_INSTANCE_CHECK(player);
2467 int ret = PLAYER_ERROR_NONE;
2468 muse_player_api_e api = MUSE_PLAYER_API_START;
2469 player_cli_s *pc = (player_cli_s *) player;
2470 char *ret_buf = NULL;
2472 LOGD("ENTER %p", pc);
2473 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2474 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2476 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2477 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2478 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2479 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2480 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), true);
2481 if (ret != MM_ERROR_NONE) {
2482 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2483 return PLAYER_ERROR_INVALID_OPERATION;
2485 /* avoid setting true at all times, when player is resumed */
2486 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2491 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2495 LOGD("LEAVE 0x%X", ret);
2499 int player_stop(player_h player)
2501 PLAYER_INSTANCE_CHECK(player);
2502 int ret = PLAYER_ERROR_NONE;
2503 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2504 player_cli_s *pc = (player_cli_s *) player;
2505 char *ret_buf = NULL;
2506 player_state_e state = PLAYER_STATE_NONE;
2507 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2508 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2510 LOGD("ENTER %p", pc);
2512 /* check player state */
2513 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2514 LOGE("Failed to get state");
2515 return PLAYER_ERROR_INVALID_OPERATION;
2518 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2519 LOGE("Invalid state %d", state);
2520 return PLAYER_ERROR_INVALID_STATE;
2523 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2524 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2525 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2526 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2527 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2528 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), false);
2529 if (ret != MM_ERROR_NONE) {
2530 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2531 return PLAYER_ERROR_INVALID_OPERATION;
2533 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2537 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2538 if (ret == PLAYER_ERROR_NONE)
2539 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2543 LOGD("LEAVE 0x%X", ret);
2547 int player_pause(player_h player)
2549 PLAYER_INSTANCE_CHECK(player);
2550 int ret = PLAYER_ERROR_NONE;
2551 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2552 player_cli_s *pc = (player_cli_s *) player;
2553 char *ret_buf = NULL;
2555 LOGD("ENTER %p", pc);
2557 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2560 LOGD("LEAVE 0x%X", ret);
2564 static int _set_play_position(player_h player, int64_t pos, bool accurate, player_seek_completed_cb callback, void *user_data)
2566 PLAYER_INSTANCE_CHECK(player);
2567 PLAYER_CHECK_CONDITION(pos >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2569 int ret = PLAYER_ERROR_NONE;
2570 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2571 player_cli_s *pc = (player_cli_s *) player;
2572 char *ret_buf = NULL;
2574 LOGD("ENTER %p", pc);
2577 LOGE("cb_info is null");
2578 return PLAYER_ERROR_INVALID_OPERATION;
2581 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2582 if ((pc->push_media_stream == FALSE) &&
2583 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2584 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2585 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2586 return PLAYER_ERROR_SEEK_FAILED;
2588 if (pc->push_media_stream == TRUE)
2589 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2591 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2592 LOGI("Event type : %d, pos : %"PRId64", accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, pos, accurate);
2593 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2594 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2596 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2598 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2599 MUSE_TYPE_INT64, "pos", pos,
2600 MUSE_TYPE_INT, "accurate", (int)accurate);
2602 if (ret != PLAYER_ERROR_NONE) {
2603 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2604 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2605 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2608 if (pc->push_media_stream == TRUE)
2609 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2613 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2614 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2615 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2617 LOGD("LEAVE 0x%X", ret);
2622 int player_set_play_position(player_h player, int milliseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2624 PLAYER_INSTANCE_CHECK(player);
2625 PLAYER_CHECK_CONDITION(milliseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2627 int ret = PLAYER_ERROR_NONE;
2628 int64_t pos = (int64_t)(milliseconds * G_GINT64_CONSTANT(1000000));
2632 ret = _set_play_position(player, pos, accurate, callback, user_data);
2634 LOGD("LEAVE 0x%X", ret);
2638 int player_set_play_position_nsec(player_h player, int64_t nanoseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
2640 PLAYER_INSTANCE_CHECK(player);
2641 PLAYER_CHECK_CONDITION(nanoseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2643 int ret = PLAYER_ERROR_NONE;
2644 int64_t pos = nanoseconds;
2648 ret = _set_play_position(player, pos, accurate, callback, user_data);
2650 LOGD("LEAVE 0x%X", ret);
2654 static int _get_play_position(player_h player, int64_t *pos)
2656 PLAYER_INSTANCE_CHECK(player);
2657 PLAYER_NULL_ARG_CHECK(pos);
2659 int ret = PLAYER_ERROR_NONE;
2660 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2661 player_cli_s *pc = (player_cli_s *) player;
2662 char *ret_buf = NULL;
2664 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2666 if (ret == PLAYER_ERROR_NONE) {
2667 bool ret_val = true;
2668 ret_val = _player_get_param_value(ret_buf,
2669 MUSE_TYPE_INT64, "pos", (void *)pos,
2670 INVALID_MUSE_TYPE_VALUE);
2672 ret = PLAYER_ERROR_INVALID_OPERATION;
2680 int player_get_play_position(player_h player, int *milliseconds)
2682 PLAYER_INSTANCE_CHECK(player);
2683 PLAYER_NULL_ARG_CHECK(milliseconds);
2685 int ret = PLAYER_ERROR_NONE;
2688 /* LOGD("ENTER"); */
2690 ret = _get_play_position(player, &pos);
2691 if (ret == PLAYER_ERROR_NONE)
2692 *milliseconds = (int)(pos / G_GINT64_CONSTANT(1000000));
2697 int player_get_play_position_nsec(player_h player, int64_t *nanoseconds)
2699 PLAYER_INSTANCE_CHECK(player);
2700 PLAYER_NULL_ARG_CHECK(nanoseconds);
2702 int ret = PLAYER_ERROR_NONE;
2705 /* LOGD("ENTER"); */
2707 ret = _get_play_position(player, &pos);
2708 if (ret == PLAYER_ERROR_NONE)
2714 int player_set_mute(player_h player, bool muted)
2716 PLAYER_INSTANCE_CHECK(player);
2717 int ret = PLAYER_ERROR_NONE;
2718 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2719 player_cli_s *pc = (player_cli_s *) player;
2720 char *ret_buf = NULL;
2721 int mute = (int)muted;
2725 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mute", mute);
2730 int player_is_muted(player_h player, bool * muted)
2732 PLAYER_INSTANCE_CHECK(player);
2733 PLAYER_NULL_ARG_CHECK(muted);
2734 int ret = PLAYER_ERROR_NONE;
2735 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2736 player_cli_s *pc = (player_cli_s *) player;
2737 char *ret_buf = NULL;
2742 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2743 if (ret == PLAYER_ERROR_NONE) {
2744 player_msg_get(mute, ret_buf);
2745 *muted = (bool) mute;
2752 int player_set_looping(player_h player, bool looping)
2754 PLAYER_INSTANCE_CHECK(player);
2755 int ret = PLAYER_ERROR_NONE;
2756 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2757 player_cli_s *pc = (player_cli_s *) player;
2758 char *ret_buf = NULL;
2762 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "looping", (int)looping);
2767 int player_is_looping(player_h player, bool * plooping)
2769 PLAYER_INSTANCE_CHECK(player);
2770 PLAYER_NULL_ARG_CHECK(plooping);
2771 int ret = PLAYER_ERROR_NONE;
2772 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2773 player_cli_s *pc = (player_cli_s *) player;
2774 char *ret_buf = NULL;
2779 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2780 if (ret == PLAYER_ERROR_NONE) {
2781 player_msg_get(looping, ret_buf);
2782 *plooping = looping;
2788 static int _get_duration(player_h player, int64_t *duration)
2790 PLAYER_INSTANCE_CHECK(player);
2791 PLAYER_NULL_ARG_CHECK(duration);
2793 int ret = PLAYER_ERROR_NONE;
2794 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2795 player_cli_s *pc = (player_cli_s *) player;
2796 char *ret_buf = NULL;
2800 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2801 if (ret == PLAYER_ERROR_NONE) {
2802 bool ret_val = true;
2803 ret_val = _player_get_param_value(ret_buf,
2804 MUSE_TYPE_INT64, "duration", (void *)duration,
2805 INVALID_MUSE_TYPE_VALUE);
2807 ret = PLAYER_ERROR_INVALID_OPERATION;
2815 int player_get_duration(player_h player, int *milliseconds)
2817 PLAYER_INSTANCE_CHECK(player);
2818 PLAYER_NULL_ARG_CHECK(milliseconds);
2820 int ret = PLAYER_ERROR_NONE;
2821 int64_t duration = 0; /* nsec */
2825 ret = _get_duration(player, &duration);
2826 if (ret == PLAYER_ERROR_NONE) {
2827 /* convert time from ns to ms */
2828 *milliseconds = (int)(duration / G_GINT64_CONSTANT(1000000));
2831 LOGD("LEAVE 0x%X", ret);
2835 int player_get_duration_nsec(player_h player, int64_t *nanoseconds)
2837 PLAYER_INSTANCE_CHECK(player);
2838 PLAYER_NULL_ARG_CHECK(nanoseconds);
2840 int ret = PLAYER_ERROR_NONE;
2841 int64_t duration = 0; /* nsec */
2845 ret = _get_duration(player, &duration);
2846 if (ret == PLAYER_ERROR_NONE)
2847 *nanoseconds = duration;
2849 LOGD("LEAVE 0x%X", ret);
2853 /* The player_display_type_e is different at wearable profile */
2854 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2856 int ret = PLAYER_ERROR_NONE;
2857 PLAYER_NULL_ARG_CHECK(out_type);
2860 case PLAYER_DISPLAY_TYPE_OVERLAY:
2861 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2863 case PLAYER_DISPLAY_TYPE_EVAS:
2864 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2866 case PLAYER_DISPLAY_TYPE_NONE:
2867 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2870 ret = PLAYER_ERROR_INVALID_PARAMETER;
2874 LOGD("display type(%d) -> (%d)", type, *out_type);
2878 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2880 PLAYER_INSTANCE_CHECK(player);
2881 int ret = PLAYER_ERROR_NONE;
2882 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2883 player_cli_s *pc = (player_cli_s *) player;
2884 char *ret_buf = NULL;
2885 wl_win_msg_type wl_win;
2886 char *wl_win_msg = (char *)&wl_win;
2887 unsigned int wl_surface_id;
2888 player_private_display_type_e conv_type = PLAYER_DISPLAY_TYPE_NONE;
2889 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
2890 int arr_msg_len = 0;
2891 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2892 int (*p_disp_destroy_evas_display)(void **) = NULL;
2893 int (*p_disp_create_evas_display)(void *, void **) = NULL;
2894 int (*p_disp_set_evas_display_old_info)(void *, void *, int, int, int) = NULL;
2895 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2896 void (*p_disp_media_packet_video_decode_cb)(media_packet_h, void *) = NULL;
2898 pid_t pid = getpid();
2899 pid_t tid = syscall(SYS_gettid);
2903 LOGD("Check if API is called in main thread. pid [%d], tid [%d]", pid, tid);
2905 LOGE("API isn't called in main thread");
2906 return PLAYER_ERROR_INVALID_OPERATION;
2909 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2911 LOGD("ENTER type: %d", type);
2913 /* before setting display, player state have to be checked. */
2914 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2916 ret = _player_convert_display_type(type, &conv_type);
2917 if (ret != PLAYER_ERROR_NONE)
2920 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2922 return PLAYER_ERROR_INVALID_PARAMETER;
2924 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2926 * To support repeating play and stop, Evas_handle should not be destroyed in player_unprepare.
2927 * When the display type changes, Player need to destroy Evas_handle to set values of video output,
2928 * Otherwise, the values is not set because of checking Evas_handle.
2930 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
2931 LOGW("evas client already exists");
2932 player_unset_media_packet_video_frame_decoded_cb(player);
2933 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2934 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2935 LOGW("fail to unset evas client");
2936 __player_unset_retrieve_buffer_cb(player);
2937 /* need to set display information again to new handle */
2938 EVAS_INFO(pc)->update_needed = TRUE;
2941 /* set evas_render or wayland */
2942 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
2943 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
2944 wl_surface_id = p_disp_set_wl_display(ELM_WAYLAND_WIN, display);
2945 if (wl_surface_id > 0) {
2946 wl_win.surface_id = wl_surface_id;
2947 wl_win.type = conv_type;
2948 } else return PLAYER_ERROR_INVALID_OPERATION;
2950 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2951 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS) {
2952 if (!CALLBACK_INFO(pc)) {
2953 LOGE("there is no cb info in player handle");
2954 return PLAYER_ERROR_INVALID_OPERATION;
2957 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_create_evas_display, "disp_create_evas_display");
2958 ret = p_disp_create_evas_display(display, &EVAS_HANDLE(pc));
2959 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2961 /* before evas handle is created, user could set display information */
2962 if (EVAS_INFO(pc)->update_needed) {
2963 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_old_info, "disp_set_evas_display_old_info");
2964 ret = p_disp_set_evas_display_old_info(display, EVAS_HANDLE(pc), EVAS_INFO(pc)->mode, EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2965 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2966 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2967 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2968 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), EVAS_INFO(pc)->roi_x, EVAS_INFO(pc)->roi_y, EVAS_INFO(pc)->roi_w, EVAS_INFO(pc)->roi_h);
2969 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2971 EVAS_INFO(pc)->update_needed = FALSE;
2974 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_media_packet_video_decode_cb, "disp_media_packet_video_decode_cb");
2975 ret = player_set_media_packet_video_frame_decoded_cb(player, p_disp_media_packet_video_decode_cb, (void *)EVAS_HANDLE(pc));
2976 if (ret != PLAYER_ERROR_NONE)
2977 LOGW("fail to set decoded callback");
2978 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2979 LOGW("fail to set __retrieve_buffer_cb");
2982 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2983 LOGI("Wayland surface type is NONE");
2984 wl_win.type = conv_type;
2987 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
2988 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2989 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
2995 int player_set_display_mode(player_h player, player_display_mode_e mode)
2997 PLAYER_INSTANCE_CHECK(player);
2998 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2999 int ret = PLAYER_ERROR_NONE;
3000 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
3001 player_cli_s *pc = (player_cli_s *) player;
3002 char *ret_buf = NULL;
3003 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3004 int (*p_disp_set_evas_display_disp_mode)(void *, int) = NULL;
3007 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3009 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3010 if (EVAS_HANDLE(pc)) {
3011 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_disp_mode, "disp_set_evas_display_disp_mode");
3012 ret = p_disp_set_evas_display_disp_mode(EVAS_HANDLE(pc), mode);
3013 if (ret != MM_ERROR_NONE)
3014 return PLAYER_ERROR_INVALID_OPERATION;
3016 return PLAYER_ERROR_NONE;
3018 EVAS_INFO(pc)->mode = mode;
3019 EVAS_INFO(pc)->update_needed = TRUE;
3022 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mode", (int)mode);
3027 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
3029 PLAYER_INSTANCE_CHECK(player);
3030 PLAYER_NULL_ARG_CHECK(pmode);
3031 int ret = PLAYER_ERROR_NONE;
3032 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
3033 player_cli_s *pc = (player_cli_s *) player;
3034 char *ret_buf = NULL;
3036 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3037 int (*p_disp_get_evas_display_disp_mode)(void *, int *) = NULL;
3041 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3043 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3044 if (EVAS_HANDLE(pc)) {
3045 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_disp_mode, "disp_get_evas_display_disp_mode");
3046 ret = p_disp_get_evas_display_disp_mode(EVAS_HANDLE(pc), &mode);
3047 *pmode = (player_display_mode_e) mode;
3048 if (ret != MM_ERROR_NONE)
3049 return PLAYER_ERROR_INVALID_OPERATION;
3051 return PLAYER_ERROR_NONE;
3054 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3055 if (ret == PLAYER_ERROR_NONE) {
3056 player_msg_get_type(mode, ret_buf, INT);
3064 int player_set_video_roi_area(player_h player, double x_scale, double y_scale,
3065 double w_scale, double h_scale)
3067 PLAYER_INSTANCE_CHECK(player);
3068 int ret = PLAYER_ERROR_NONE;
3069 muse_player_api_e api = MUSE_PLAYER_API_SET_VIDEO_ROI_AREA;
3070 player_cli_s *pc = (player_cli_s *) player;
3071 char *ret_buf = NULL;
3074 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3075 PLAYER_CHECK_CONDITION(CALLBACK_INFO(pc) != NULL && EVAS_HANDLE(pc) == NULL,
3076 PLAYER_ERROR_INVALID_OPERATION, "Display type is EVAS, video display interface is not supported");
3078 if (!_player_video_roi_area_is_valid(x_scale, y_scale, w_scale, h_scale))
3079 return PLAYER_ERROR_INVALID_PARAMETER;
3081 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3082 MUSE_TYPE_DOUBLE, "x_scale", x_scale,
3083 MUSE_TYPE_DOUBLE, "y_scale", y_scale,
3084 MUSE_TYPE_DOUBLE, "w_scale", w_scale,
3085 MUSE_TYPE_DOUBLE, "h_scale", h_scale);
3093 int player_get_video_roi_area(player_h player, double *x_scale, double *y_scale,
3094 double *w_scale, double *h_scale)
3096 PLAYER_INSTANCE_CHECK(player);
3097 PLAYER_NULL_ARG_CHECK(x_scale && y_scale && w_scale && h_scale);
3099 int ret = PLAYER_ERROR_NONE;
3100 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_ROI_AREA;
3101 player_cli_s *pc = (player_cli_s *) player;
3102 char *ret_buf = NULL;
3103 double scale_x = 0, scale_y = 0, scale_w = 0, scale_h = 0;
3105 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3107 if (ret == PLAYER_ERROR_NONE) {
3108 if (player_msg_get_type(scale_x, ret_buf, DOUBLE))
3111 LOGE("failed to get value from msg");
3112 if (player_msg_get_type(scale_y, ret_buf, DOUBLE))
3115 LOGE("failed to get value from msg");
3116 if (player_msg_get_type(scale_w, ret_buf, DOUBLE))
3119 LOGE("failed to get value from msg");
3120 if (player_msg_get_type(scale_h, ret_buf, DOUBLE))
3123 LOGE("failed to get value from msg");
3132 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
3134 PLAYER_INSTANCE_CHECK(player);
3135 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3137 int ret = PLAYER_ERROR_NONE;
3138 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
3139 player_cli_s *pc = (player_cli_s *) player;
3140 char *ret_buf = NULL;
3141 wl_win_msg_type wl_win;
3142 char *wl_win_msg = (char *)&wl_win;
3143 int arr_msg_len = 0;
3144 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3145 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
3149 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3151 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3152 if (EVAS_HANDLE(pc)) {
3153 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
3154 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), x, y, width, height);
3155 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
3156 return PLAYER_ERROR_INVALID_PARAMETER;
3157 else if (ret != MM_ERROR_NONE)
3158 return PLAYER_ERROR_INVALID_OPERATION;
3160 return PLAYER_ERROR_NONE;
3162 EVAS_INFO(pc)->roi_x = x;
3163 EVAS_INFO(pc)->roi_y = y;
3164 EVAS_INFO(pc)->roi_w = width;
3165 EVAS_INFO(pc)->roi_h = height;
3166 EVAS_INFO(pc)->update_needed = TRUE;
3169 wl_win.win_roi_x = x;
3170 wl_win.win_roi_y = y;
3171 wl_win.win_roi_width = width;
3172 wl_win.win_roi_height = height;
3174 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
3175 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3176 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
3182 int player_set_playback_rate(player_h player, float rate)
3184 PLAYER_INSTANCE_CHECK(player);
3185 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3186 int ret = PLAYER_ERROR_NONE;
3187 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
3188 player_cli_s *pc = (player_cli_s *) player;
3189 char *ret_buf = NULL;
3193 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", (double)rate);
3196 LOGD("LEAVE 0x%X", ret);
3200 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
3202 PLAYER_INSTANCE_CHECK(player);
3203 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_ROTATION_NONE <= rotation && rotation <= PLAYER_DISPLAY_ROTATION_270, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3205 int ret = PLAYER_ERROR_NONE;
3206 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
3207 player_cli_s *pc = (player_cli_s *) player;
3208 char *ret_buf = NULL;
3209 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3210 int (*p_disp_set_evas_display_rotation)(void *, int) = NULL;
3214 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3216 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3217 if (EVAS_HANDLE(pc)) {
3218 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_rotation, "disp_set_evas_display_rotation");
3219 ret = p_disp_set_evas_display_rotation(EVAS_HANDLE(pc), rotation);
3220 if (ret != MM_ERROR_NONE)
3221 return PLAYER_ERROR_INVALID_OPERATION;
3223 return PLAYER_ERROR_NONE;
3225 EVAS_INFO(pc)->rotation = rotation;
3226 EVAS_INFO(pc)->update_needed = TRUE;
3229 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "rotation", (int)rotation);
3234 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
3236 PLAYER_INSTANCE_CHECK(player);
3237 PLAYER_NULL_ARG_CHECK(protation);
3238 int ret = PLAYER_ERROR_NONE;
3239 player_cli_s *pc = (player_cli_s *) player;
3240 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
3241 char *ret_buf = NULL;
3243 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3244 int (*p_disp_get_evas_display_rotation)(void *, int *) = NULL;
3248 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3250 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3251 if (EVAS_HANDLE(pc)) {
3252 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_rotation, "disp_get_evas_display_rotation");
3253 ret = p_disp_get_evas_display_rotation(EVAS_HANDLE(pc), &rotation);
3254 *protation = (player_display_rotation_e) rotation;
3255 if (ret != MM_ERROR_NONE)
3256 return PLAYER_ERROR_INVALID_OPERATION;
3258 return PLAYER_ERROR_NONE;
3261 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3262 if (ret == PLAYER_ERROR_NONE) {
3263 player_msg_get_type(rotation, ret_buf, INT);
3264 *protation = rotation;
3271 int player_set_display_visible(player_h player, bool visible)
3273 PLAYER_INSTANCE_CHECK(player);
3274 int ret = PLAYER_ERROR_NONE;
3275 player_cli_s *pc = (player_cli_s *) player;
3276 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
3277 char *ret_buf = NULL;
3278 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3279 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
3283 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3285 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3286 if (EVAS_HANDLE(pc)) {
3287 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
3288 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), visible);
3289 if (ret != MM_ERROR_NONE)
3290 return PLAYER_ERROR_INVALID_OPERATION;
3292 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3293 return PLAYER_ERROR_NONE;
3295 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3296 EVAS_INFO(pc)->update_needed = TRUE;
3300 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "visible", (int)visible);
3305 int player_is_display_visible(player_h player, bool * pvisible)
3307 PLAYER_INSTANCE_CHECK(player);
3308 PLAYER_NULL_ARG_CHECK(pvisible);
3309 int ret = PLAYER_ERROR_NONE;
3310 player_cli_s *pc = (player_cli_s *) player;
3311 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
3312 char *ret_buf = NULL;
3314 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3316 int (*p_disp_get_evas_display_visible)(void *, bool *) = NULL;
3320 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3322 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3323 if (EVAS_HANDLE(pc)) {
3324 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_visible, "disp_get_evas_display_visible");
3325 ret = p_disp_get_evas_display_visible(EVAS_HANDLE(pc), &visible);
3331 if (ret != MM_ERROR_NONE)
3332 return PLAYER_ERROR_INVALID_OPERATION;
3334 return PLAYER_ERROR_NONE;
3337 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3338 if (ret == PLAYER_ERROR_NONE) {
3339 player_msg_get_type(value, ret_buf, INT);
3351 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3353 PLAYER_INSTANCE_CHECK(player);
3354 PLAYER_NULL_ARG_CHECK(pvalue);
3355 int ret = PLAYER_ERROR_NONE;
3356 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3357 player_cli_s *pc = (player_cli_s *) player;
3358 char *ret_buf = NULL;
3359 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3363 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "key", (int)key);
3364 if (ret == PLAYER_ERROR_NONE) {
3365 player_msg_get_string(value, ret_buf);
3366 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3372 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3374 PLAYER_INSTANCE_CHECK(player);
3375 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3376 int ret = PLAYER_ERROR_NONE;
3377 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3378 player_cli_s *pc = (player_cli_s *) player;
3379 char *ret_buf = NULL;
3380 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3381 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3382 bool ret_val = TRUE;
3386 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3387 if (ret == PLAYER_ERROR_NONE) {
3388 ret_val = _player_get_param_value(ret_buf,
3389 MUSE_TYPE_STRING, "video_codec", (void *)video_codec,
3390 MUSE_TYPE_STRING, "audio_codec", (void *)audio_codec,
3391 INVALID_MUSE_TYPE_VALUE);
3394 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3396 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3398 ret = PLAYER_ERROR_INVALID_OPERATION;
3405 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3407 PLAYER_INSTANCE_CHECK(player);
3408 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3409 int ret = PLAYER_ERROR_NONE;
3410 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3411 player_cli_s *pc = (player_cli_s *) player;
3412 char *ret_buf = NULL;
3413 int sample_rate = 0;
3419 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3420 if (ret == PLAYER_ERROR_NONE) {
3421 bool ret_val = true;
3422 ret_val = _player_get_param_value(ret_buf,
3423 MUSE_TYPE_INT, "sample_rate", (void *)&sample_rate,
3424 MUSE_TYPE_INT, "channel", (void *)&channel,
3425 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3426 INVALID_MUSE_TYPE_VALUE);
3429 *psample_rate = sample_rate;
3431 *pchannel = channel;
3433 *pbit_rate = bit_rate;
3435 ret = PLAYER_ERROR_INVALID_OPERATION;
3442 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3444 PLAYER_INSTANCE_CHECK(player);
3445 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3446 int ret = PLAYER_ERROR_NONE;
3447 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3448 player_cli_s *pc = (player_cli_s *) player;
3449 char *ret_buf = NULL;
3455 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3456 if (ret == PLAYER_ERROR_NONE) {
3457 bool ret_val = true;
3458 ret_val = _player_get_param_value(ret_buf,
3459 MUSE_TYPE_INT, "fps", (void *)&fps,
3460 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3461 INVALID_MUSE_TYPE_VALUE);
3466 *pbit_rate = bit_rate;
3468 ret = PLAYER_ERROR_INVALID_OPERATION;
3475 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3477 PLAYER_INSTANCE_CHECK(player);
3478 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3479 int ret = PLAYER_ERROR_NONE;
3480 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3481 player_cli_s *pc = (player_cli_s *) player;
3482 char *ret_buf = NULL;
3488 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3489 if (ret == PLAYER_ERROR_NONE) {
3490 bool ret_val = true;
3491 ret_val = _player_get_param_value(ret_buf,
3492 MUSE_TYPE_INT, "width", (void *)&width,
3493 MUSE_TYPE_INT, "height", (void *)&height,
3494 INVALID_MUSE_TYPE_VALUE);
3499 ret = PLAYER_ERROR_INVALID_OPERATION;
3506 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3508 PLAYER_INSTANCE_CHECK(player);
3509 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3510 int ret = PLAYER_ERROR_NONE;
3511 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3512 player_cli_s *pc = (player_cli_s *) player;
3513 char *ret_buf = NULL;
3517 tbm_bo_handle thandle;
3518 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3519 int key = INVALID_DEFAULT_VALUE;
3524 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3525 if (ret == PLAYER_ERROR_NONE) {
3526 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3527 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3529 LOGE("failed to get msg obj, err:%d", err);
3530 ret = PLAYER_ERROR_INVALID_OPERATION;
3534 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3535 LOGD("size : %d", size);
3536 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3537 LOGE("failed to get key value");
3538 ret = PLAYER_ERROR_INVALID_OPERATION;
3542 tfd = pc->cb_info->tfd;
3544 LOGE("failed to get tbm fd value");
3545 ret = PLAYER_ERROR_INVALID_OPERATION;
3549 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3551 LOGE("TBM get error : bo is NULL");
3552 ret = PLAYER_ERROR_INVALID_OPERATION;
3555 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3556 if (thandle.ptr == NULL) {
3557 LOGE("TBM get error : handle pointer is NULL");
3558 ret = PLAYER_ERROR_INVALID_OPERATION;
3561 album_art = _get_mem(pc, size);
3563 memcpy(album_art, thandle.ptr, size);
3564 *palbum_art = album_art;
3566 LOGE("g_new failure");
3567 ret = PLAYER_ERROR_INVALID_OPERATION;
3579 muse_core_msg_object_free(jobj);
3584 if (tfd > INVALID_DEFAULT_VALUE)
3587 if (CALLBACK_INFO(pc))
3588 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3594 if (key > INVALID_DEFAULT_VALUE && CALLBACK_INFO(pc)) {
3595 LOGD("send msg to release buffer. key:%d", key);
3596 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_RETURN_BUFFER, MSG_FD(pc), ret, MUSE_TYPE_INT, "key", key);
3602 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3604 PLAYER_INSTANCE_CHECK(player);
3605 PLAYER_NULL_ARG_CHECK(pcount);
3606 int ret = PLAYER_ERROR_NONE;
3607 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3608 player_cli_s *pc = (player_cli_s *) player;
3609 char *ret_buf = NULL;
3614 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3615 if (ret == PLAYER_ERROR_NONE) {
3616 player_msg_get(count, ret_buf);
3623 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3625 PLAYER_INSTANCE_CHECK(player);
3626 PLAYER_NULL_ARG_CHECK(band_levels);
3627 int ret = PLAYER_ERROR_NONE;
3628 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3629 player_cli_s *pc = (player_cli_s *) player;
3630 char *ret_buf = NULL;
3634 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3635 MUSE_TYPE_INT, "length", length,
3636 MUSE_TYPE_ARRAY, "band_levels", length, band_levels);
3643 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3645 PLAYER_INSTANCE_CHECK(player);
3646 int ret = PLAYER_ERROR_NONE;
3647 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3648 player_cli_s *pc = (player_cli_s *) player;
3649 char *ret_buf = NULL;
3653 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3654 MUSE_TYPE_INT, "index", index,
3655 MUSE_TYPE_INT, "level", level);
3661 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3663 PLAYER_INSTANCE_CHECK(player);
3664 PLAYER_NULL_ARG_CHECK(plevel);
3665 int ret = PLAYER_ERROR_NONE;
3666 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3667 player_cli_s *pc = (player_cli_s *) player;
3668 char *ret_buf = NULL;
3673 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3674 if (ret == PLAYER_ERROR_NONE) {
3675 player_msg_get(level, ret_buf);
3682 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3684 PLAYER_INSTANCE_CHECK(player);
3685 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3686 int ret = PLAYER_ERROR_NONE;
3687 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3688 player_cli_s *pc = (player_cli_s *) player;
3689 char *ret_buf = NULL;
3690 int min = 0, max = 0;
3694 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3695 if (ret == PLAYER_ERROR_NONE) {
3696 bool ret_val = true;
3697 ret_val = _player_get_param_value(ret_buf,
3698 MUSE_TYPE_INT, "min", (void *)&min,
3699 MUSE_TYPE_INT, "max", (void *)&max,
3700 INVALID_MUSE_TYPE_VALUE);
3705 ret = PLAYER_ERROR_INVALID_OPERATION;
3712 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3714 PLAYER_INSTANCE_CHECK(player);
3715 PLAYER_NULL_ARG_CHECK(pfrequency);
3716 int ret = PLAYER_ERROR_NONE;
3717 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3718 player_cli_s *pc = (player_cli_s *) player;
3719 char *ret_buf = NULL;
3724 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3725 if (ret == PLAYER_ERROR_NONE) {
3726 player_msg_get(frequency, ret_buf);
3727 *pfrequency = frequency;
3733 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3735 PLAYER_INSTANCE_CHECK(player);
3736 PLAYER_NULL_ARG_CHECK(prange);
3737 int ret = PLAYER_ERROR_NONE;
3738 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3739 player_cli_s *pc = (player_cli_s *) player;
3740 char *ret_buf = NULL;
3745 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3746 if (ret == PLAYER_ERROR_NONE) {
3747 player_msg_get(range, ret_buf);
3754 int player_audio_effect_equalizer_clear(player_h player)
3756 PLAYER_INSTANCE_CHECK(player);
3757 int ret = PLAYER_ERROR_NONE;
3758 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3759 player_cli_s *pc = (player_cli_s *) player;
3760 char *ret_buf = NULL;
3764 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3769 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3771 PLAYER_INSTANCE_CHECK(player);
3772 PLAYER_NULL_ARG_CHECK(pavailable);
3773 int ret = PLAYER_ERROR_NONE;
3774 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3775 player_cli_s *pc = (player_cli_s *) player;
3776 char *ret_buf = NULL;
3781 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3782 if (ret == PLAYER_ERROR_NONE) {
3783 player_msg_get(available, ret_buf);
3784 *pavailable = available;
3790 int player_set_subtitle_path(player_h player, const char *path)
3792 PLAYER_INSTANCE_CHECK(player);
3793 int ret = PLAYER_ERROR_NONE;
3794 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3795 player_cli_s *pc = (player_cli_s *) player;
3796 char *ret_buf = NULL;
3797 char subtitle_path[MAX_URL_LEN] = {0, };
3801 if (path && _player_get_valid_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3802 return PLAYER_ERROR_INVALID_PARAMETER;
3804 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "subtitle_path", (const char*)subtitle_path);
3809 int player_set_subtitle_position_offset(player_h player, int milliseconds)
3811 PLAYER_INSTANCE_CHECK(player);
3812 int ret = PLAYER_ERROR_NONE;
3813 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3814 player_cli_s *pc = (player_cli_s *) player;
3815 char *ret_buf = NULL;
3819 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "milliseconds", milliseconds);
3825 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3827 PLAYER_INSTANCE_CHECK(player);
3828 PLAYER_NULL_ARG_CHECK(callback);
3829 int ret = PLAYER_ERROR_NONE;
3830 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3831 player_cli_s *pc = (player_cli_s *) player;
3832 char *ret_buf = NULL;
3835 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3836 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3837 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3839 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3840 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3841 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3844 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3846 if (ret != PLAYER_ERROR_NONE)
3847 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3853 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3855 PLAYER_INSTANCE_CHECK(player);
3856 PLAYER_NULL_ARG_CHECK(cookie);
3857 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3858 int ret = PLAYER_ERROR_NONE;
3859 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3860 player_cli_s *pc = (player_cli_s *) player;
3861 char *ret_buf = NULL;
3865 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3866 MUSE_TYPE_STRING, "cookie", cookie,
3867 MUSE_TYPE_INT, "size", size);
3872 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3874 PLAYER_INSTANCE_CHECK(player);
3875 PLAYER_NULL_ARG_CHECK(user_agent);
3876 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3877 int ret = PLAYER_ERROR_NONE;
3878 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3879 player_cli_s *pc = (player_cli_s *) player;
3880 char *ret_buf = NULL;
3884 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3885 MUSE_TYPE_STRING, "user_agent", user_agent,
3886 MUSE_TYPE_INT, "size", size);
3891 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3893 PLAYER_INSTANCE_CHECK(player);
3894 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3895 int ret = PLAYER_ERROR_NONE;
3896 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3897 player_cli_s *pc = (player_cli_s *) player;
3898 char *ret_buf = NULL;
3899 int start = 0, current = 0;
3903 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3904 if (ret == PLAYER_ERROR_NONE) {
3905 bool ret_val = true;
3906 ret_val = _player_get_param_value(ret_buf,
3907 MUSE_TYPE_INT, "start", (void *)&start,
3908 MUSE_TYPE_INT, "current", (void *)¤t,
3909 INVALID_MUSE_TYPE_VALUE);
3912 *pcurrent = current;
3914 ret = PLAYER_ERROR_INVALID_OPERATION;
3922 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3924 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3927 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3928 static void __retrieve_buffer_cb(void *user_data)
3930 player_cli_s *player = (player_cli_s *)user_data;
3931 int ret = PLAYER_ERROR_NONE;
3932 bool gapless = false;
3933 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
3935 ret = player_is_gapless((player_h)user_data, &gapless);
3936 if (ret != PLAYER_ERROR_NONE) {
3937 LOGW("player_is_gapless is failed");
3941 PLAYER_DISP_DLSYM(player->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
3942 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3943 if (ret != PLAYER_ERROR_NONE)
3944 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3947 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3949 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3952 static int __player_unset_retrieve_buffer_cb(player_h player)
3954 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3958 int player_unset_completed_cb(player_h player)
3960 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3963 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3965 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3968 int player_unset_interrupted_cb(player_h player)
3970 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3973 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3975 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3978 int player_unset_error_cb(player_h player)
3980 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3983 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3985 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3988 int player_unset_buffering_cb(player_h player)
3990 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3993 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3995 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3998 int player_unset_subtitle_updated_cb(player_h player)
4000 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
4003 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
4005 PLAYER_INSTANCE_CHECK(player);
4006 PLAYER_NULL_ARG_CHECK(callback);
4007 int ret = PLAYER_ERROR_NONE;
4008 player_cli_s *pc = (player_cli_s *) player;
4009 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4010 char *ret_buf = NULL;
4011 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
4016 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4017 MUSE_TYPE_INT, "type", type,
4018 MUSE_TYPE_INT, "set", set);
4020 if (ret == PLAYER_ERROR_NONE) {
4021 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
4022 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
4023 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
4030 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
4032 PLAYER_INSTANCE_CHECK(player);
4033 int ret = PLAYER_ERROR_NONE;
4034 player_cli_s *pc = (player_cli_s *) player;
4035 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4036 char *ret_buf = NULL;
4037 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
4042 set_null_user_cb_lock(pc->cb_info, type);
4044 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4045 MUSE_TYPE_INT, "type", type,
4046 MUSE_TYPE_INT, "set", set);
4052 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
4054 PLAYER_INSTANCE_CHECK(player);
4055 PLAYER_NULL_ARG_CHECK(callback);
4056 int ret = PLAYER_ERROR_NONE;
4057 player_cli_s *pc = (player_cli_s *) player;
4058 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4059 char *ret_buf = NULL;
4060 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4065 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4066 MUSE_TYPE_INT, "type", type,
4067 MUSE_TYPE_INT, "set", set);
4069 if (ret == PLAYER_ERROR_NONE) {
4070 pc->cb_info->user_cb[type] = callback;
4071 pc->cb_info->user_data[type] = user_data;
4072 LOGI("Event type : %d ", type);
4079 int player_unset_video_stream_changed_cb(player_h player)
4081 PLAYER_INSTANCE_CHECK(player);
4082 int ret = PLAYER_ERROR_NONE;
4083 player_cli_s *pc = (player_cli_s *) player;
4084 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4085 char *ret_buf = NULL;
4086 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4091 set_null_user_cb_lock(pc->cb_info, type);
4093 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4094 MUSE_TYPE_INT, "type", type,
4095 MUSE_TYPE_INT, "set", set);
4101 int player_set_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type, player_media_stream_buffer_status_cb callback, void *user_data)
4103 PLAYER_INSTANCE_CHECK(player);
4104 PLAYER_NULL_ARG_CHECK(callback);
4105 int ret = PLAYER_ERROR_NONE;
4106 player_cli_s *pc = (player_cli_s *) player;
4107 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4108 char *ret_buf = NULL;
4109 muse_player_event_e type;
4114 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4115 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4116 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4117 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4119 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4120 return PLAYER_ERROR_INVALID_PARAMETER;
4123 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4124 MUSE_TYPE_INT, "type", type,
4125 MUSE_TYPE_INT, "set", set);
4127 if (ret == PLAYER_ERROR_NONE) {
4128 pc->cb_info->user_cb[type] = callback;
4129 pc->cb_info->user_data[type] = user_data;
4130 LOGI("Event type : %d ", type);
4137 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
4139 PLAYER_INSTANCE_CHECK(player);
4140 int ret = PLAYER_ERROR_NONE;
4141 player_cli_s *pc = (player_cli_s *) player;
4142 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4143 char *ret_buf = NULL;
4144 muse_player_event_e type;
4149 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4150 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4151 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4152 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4154 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4155 return PLAYER_ERROR_INVALID_PARAMETER;
4158 set_null_user_cb_lock(pc->cb_info, type);
4160 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4161 MUSE_TYPE_INT, "type", type,
4162 MUSE_TYPE_INT, "set", set);
4168 int player_set_media_stream_seek_cb(player_h player, player_stream_type_e stream_type, player_media_stream_seek_cb callback, void *user_data)
4170 PLAYER_INSTANCE_CHECK(player);
4171 PLAYER_NULL_ARG_CHECK(callback);
4172 int ret = PLAYER_ERROR_NONE;
4173 player_cli_s *pc = (player_cli_s *) player;
4174 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4175 char *ret_buf = NULL;
4176 muse_player_event_e type;
4181 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4182 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4183 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4184 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4186 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4187 return PLAYER_ERROR_INVALID_PARAMETER;
4190 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4191 MUSE_TYPE_INT, "type", type,
4192 MUSE_TYPE_INT, "set", set);
4194 if (ret == PLAYER_ERROR_NONE) {
4195 pc->cb_info->user_cb[type] = callback;
4196 pc->cb_info->user_data[type] = user_data;
4197 LOGI("Event type : %d ", type);
4204 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
4206 PLAYER_INSTANCE_CHECK(player);
4207 int ret = PLAYER_ERROR_NONE;
4208 player_cli_s *pc = (player_cli_s *) player;
4209 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4210 char *ret_buf = NULL;
4211 muse_player_event_e type;
4216 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4217 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4218 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4219 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4221 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4222 return PLAYER_ERROR_INVALID_PARAMETER;
4225 set_null_user_cb_lock(pc->cb_info, type);
4227 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4228 MUSE_TYPE_INT, "type", type,
4229 MUSE_TYPE_INT, "set", set);
4235 /* TODO Implement raw data socket channel */
4236 int player_push_media_stream(player_h player, media_packet_h packet)
4238 PLAYER_INSTANCE_CHECK(player);
4239 PLAYER_NULL_ARG_CHECK(packet);
4240 int ret = PLAYER_ERROR_NONE;
4241 player_cli_s *pc = (player_cli_s *) player;
4242 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
4243 char *ret_buf = NULL;
4244 player_push_media_msg_type push_media;
4245 char *push_media_msg = (char *)&push_media;
4246 int msg_size = sizeof(player_push_media_msg_type);
4250 tbm_bo_handle thandle;
4251 tbm_fd tfd = INVALID_DEFAULT_VALUE;
4254 media_format_h format;
4258 int arr_msg_len = 0;
4262 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
4263 media_packet_get_buffer_size(packet, &push_media.size);
4264 media_packet_get_pts(packet, &push_media.pts);
4265 media_packet_get_format(packet, &format);
4266 media_packet_get_flags(packet, &push_media.flags);
4268 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
4270 media_packet_is_video(packet, &is_video);
4271 media_packet_is_audio(packet, &is_audio);
4272 media_packet_is_end_of_stream(packet, &is_eos);
4274 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
4276 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
4278 media_format_unref(format);
4281 int arr_buf_len = 0;
4283 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
4284 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
4286 LOGE("TBM get error : bo is NULL");
4287 return PLAYER_ERROR_INVALID_OPERATION;
4289 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4290 if (thandle.ptr == NULL) {
4291 LOGE("TBM get error : handle pointer is NULL");
4292 ret = PLAYER_ERROR_INVALID_OPERATION;
4295 memcpy(thandle.ptr, buf, push_media.size);
4298 tfd = tbm_bo_export_fd(bo);
4300 LOGE("tbm_bo_export_fd err 0x%x", tfd);
4301 ret = PLAYER_ERROR_INVALID_OPERATION;
4305 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4306 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret,
4307 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4309 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4310 buf_size = (int)push_media.size;
4312 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4313 arr_buf_len = (buf_size / sizeof(int) + (buf_size % sizeof(int) ? 1 : 0));
4314 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4315 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg,
4316 MUSE_TYPE_ARRAY, "buf", arr_buf_len, (int*)buf);
4320 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4321 buf_size = (int)push_media.size;
4322 if ((muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts) < 0) && (!is_eos)) {
4323 LOGE("failed to send data");
4324 return PLAYER_ERROR_INVALID_OPERATION;
4327 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4328 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4329 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg);
4332 LOGD("ret_buf %s", ret_buf);
4336 if (tfd > INVALID_DEFAULT_VALUE)
4339 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4347 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4349 PLAYER_INSTANCE_CHECK(player);
4350 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4351 int ret = PLAYER_ERROR_NONE;
4352 player_cli_s *pc = (player_cli_s *) player;
4353 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4354 char *ret_buf = NULL;
4355 media_format_mimetype_e mimetype;
4367 media_format_ref(format);
4368 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4369 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4370 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4371 LOGE("failed to get video info from format.");
4372 return PLAYER_ERROR_INVALID_PARAMETER;
4375 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4376 MUSE_TYPE_INT, "type", type,
4377 MUSE_TYPE_INT, "mimetype", mimetype,
4378 MUSE_TYPE_INT, "width", width,
4379 MUSE_TYPE_INT, "height", height,
4380 MUSE_TYPE_INT, "avg_bps", avg_bps,
4381 MUSE_TYPE_INT, "max_bps", max_bps,
4382 MUSE_TYPE_INT, "frame_rate", frame_rate);
4384 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4385 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4386 LOGE("failed to get audio info from format.");
4387 return PLAYER_ERROR_INVALID_PARAMETER;
4390 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4391 MUSE_TYPE_INT, "type", type,
4392 MUSE_TYPE_INT, "mimetype", mimetype,
4393 MUSE_TYPE_INT, "channel", channel,
4394 MUSE_TYPE_INT, "samplerate", samplerate,
4395 MUSE_TYPE_INT, "avg_bps", avg_bps,
4396 MUSE_TYPE_INT, "bit", bit);
4399 media_format_unref(format);
4400 pc->push_media_stream = TRUE;
4406 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4408 PLAYER_INSTANCE_CHECK(player);
4409 PLAYER_CHECK_CONDITION(PLAYER_STREAM_TYPE_DEFAULT <= type && type <= PLAYER_STREAM_TYPE_TEXT, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4410 PLAYER_CHECK_CONDITION(max_size > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4412 int ret = PLAYER_ERROR_NONE;
4413 player_cli_s *pc = (player_cli_s *) player;
4414 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4415 char *ret_buf = NULL;
4419 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4420 MUSE_TYPE_INT, "type", type,
4421 MUSE_TYPE_INT64, "max_size", (INT64)max_size);
4427 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4429 int ret = PLAYER_ERROR_NONE;
4430 PLAYER_INSTANCE_CHECK(player);
4431 PLAYER_NULL_ARG_CHECK(pmax_size);
4432 player_cli_s *pc = (player_cli_s *) player;
4433 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4434 char *ret_buf = NULL;
4435 unsigned long long max_size;
4439 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4440 if (ret == PLAYER_ERROR_NONE) {
4441 player_msg_get_type(max_size, ret_buf, INT64);
4442 *pmax_size = max_size;
4448 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4450 PLAYER_INSTANCE_CHECK(player);
4451 PLAYER_CHECK_CONDITION(PLAYER_STREAM_TYPE_DEFAULT <= type && type <= PLAYER_STREAM_TYPE_TEXT, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4453 int ret = PLAYER_ERROR_NONE;
4454 player_cli_s *pc = (player_cli_s *) player;
4455 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4456 char *ret_buf = NULL;
4460 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4461 MUSE_TYPE_INT, "type", type,
4462 MUSE_TYPE_INT, "percent", (int)percent);
4468 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4470 int ret = PLAYER_ERROR_NONE;
4471 PLAYER_INSTANCE_CHECK(player);
4472 PLAYER_NULL_ARG_CHECK(ppercent);
4473 player_cli_s *pc = (player_cli_s *) player;
4474 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4475 char *ret_buf = NULL;
4480 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4481 if (ret == PLAYER_ERROR_NONE) {
4482 player_msg_get(percent, ret_buf);
4483 *ppercent = percent;
4490 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4492 PLAYER_INSTANCE_CHECK(player);
4493 PLAYER_NULL_ARG_CHECK(pcount);
4494 int ret = PLAYER_ERROR_NONE;
4495 player_cli_s *pc = (player_cli_s *) player;
4496 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4497 char *ret_buf = NULL;
4502 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4503 if (ret == PLAYER_ERROR_NONE) {
4504 player_msg_get(count, ret_buf);
4512 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4514 PLAYER_INSTANCE_CHECK(player);
4515 PLAYER_NULL_ARG_CHECK(pindex);
4516 int ret = PLAYER_ERROR_NONE;
4517 player_cli_s *pc = (player_cli_s *) player;
4518 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4519 char *ret_buf = NULL;
4524 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4525 if (ret == PLAYER_ERROR_NONE) {
4526 player_msg_get(index, ret_buf);
4534 int player_select_track(player_h player, player_stream_type_e type, int index)
4536 PLAYER_INSTANCE_CHECK(player);
4537 int ret = PLAYER_ERROR_NONE;
4538 player_cli_s *pc = (player_cli_s *) player;
4539 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4540 char *ret_buf = NULL;
4544 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4550 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4552 PLAYER_INSTANCE_CHECK(player);
4553 PLAYER_NULL_ARG_CHECK(pcode);
4554 int ret = PLAYER_ERROR_NONE;
4555 player_cli_s *pc = (player_cli_s *) player;
4556 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4557 char *ret_buf = NULL;
4558 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4563 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4564 if (ret == PLAYER_ERROR_NONE) {
4565 bool recv_ret = true;
4566 recv_ret = _player_get_param_value(ret_buf,
4567 MUSE_TYPE_INT, "code_len", (void *)&code_len,
4568 MUSE_TYPE_STRING, "code", (void *)code,
4569 INVALID_MUSE_TYPE_VALUE);
4571 *pcode = strndup(code, code_len);
4573 ret = PLAYER_ERROR_INVALID_OPERATION;
4579 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4581 PLAYER_INSTANCE_CHECK(player);
4582 PLAYER_NULL_ARG_CHECK(callback);
4583 int ret = PLAYER_ERROR_NONE;
4584 player_cli_s *pc = (player_cli_s *) player;
4585 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4586 char *ret_buf = NULL;
4587 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4588 int idx = 0, num = 0;
4589 int bandwidth = 0, width = 0, height = 0;
4595 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4596 if (ret == PLAYER_ERROR_NONE) {
4597 player_msg_get_type(num, ret_buf, INT);
4599 player_msg_get_string(var_info, ret_buf);
4601 LOGW("There is no stream variant info.");
4604 for (idx = 0 ; idx < num ; idx++) {
4605 bandwidth = width = height = 0;
4607 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4609 bandwidth = atoi(token);
4611 token = strtok_r(NULL, ",", &ptr);
4613 width = atoi(token);
4615 token = strtok_r(NULL, ",", &ptr);
4617 height = atoi(token);
4619 callback(bandwidth, width, height, user_data);
4622 LOGD("LEAVE 0x%X", ret);
4627 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4629 int ret = PLAYER_ERROR_NONE;
4630 PLAYER_INSTANCE_CHECK(player);
4631 PLAYER_CHECK_CONDITION(bandwidth >= -1 && width >= -1 && height >= -1,
4632 PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4633 player_cli_s *pc = (player_cli_s *) player;
4634 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4635 char *ret_buf = NULL;
4639 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4640 MUSE_TYPE_INT, "bandwidth", bandwidth,
4641 MUSE_TYPE_INT, "width", width,
4642 MUSE_TYPE_INT, "height", height);
4645 LOGD("LEAVE 0x%X", ret);
4650 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4652 int ret = PLAYER_ERROR_NONE;
4653 PLAYER_INSTANCE_CHECK(player);
4654 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4656 player_cli_s *pc = (player_cli_s *) player;
4657 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4658 char *ret_buf = NULL;
4659 int bandwidth = -1, width = -1, height = -1;
4663 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4664 if (ret == PLAYER_ERROR_NONE) {
4665 bool ret_val = true;
4666 ret_val = _player_get_param_value(ret_buf,
4667 MUSE_TYPE_INT, "bandwidth", (void *)&bandwidth,
4668 MUSE_TYPE_INT, "width", (void *)&width,
4669 MUSE_TYPE_INT, "height", (void *)&height,
4670 INVALID_MUSE_TYPE_VALUE);
4672 if (pbandwidth) *pbandwidth = bandwidth;
4673 if (pwidth) *pwidth = width;
4674 if (pheight) *pheight = height;
4676 ret = PLAYER_ERROR_INVALID_OPERATION;
4681 LOGD("LEAVE 0x%X", ret);
4685 int player_set_audio_only(player_h player, bool audio_only)
4687 int ret = PLAYER_ERROR_NONE;
4688 PLAYER_INSTANCE_CHECK(player);
4689 player_cli_s *pc = (player_cli_s *) player;
4690 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4691 char *ret_buf = NULL;
4692 player_state_e state = PLAYER_STATE_NONE;
4694 LOGD("ENTER audio_only: %d", audio_only);
4696 /* check player state */
4697 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
4698 LOGE("Failed to get state");
4699 return PLAYER_ERROR_INVALID_OPERATION;
4702 if (state < PLAYER_STATE_READY) {
4703 LOGE("Invalid state %d", state);
4704 return PLAYER_ERROR_INVALID_STATE;
4707 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4708 if (EVAS_HANDLE(pc)) {
4709 pc->is_audio_only = (gboolean)audio_only;
4710 return PLAYER_ERROR_NONE;
4713 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "audio_only", (int)audio_only);
4716 LOGD("LEAVE 0x%X", ret);
4721 int player_is_audio_only(player_h player, bool *paudio_only)
4723 PLAYER_INSTANCE_CHECK(player);
4724 PLAYER_NULL_ARG_CHECK(paudio_only);
4725 int ret = PLAYER_ERROR_NONE;
4726 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4727 player_cli_s *pc = (player_cli_s *) player;
4728 char *ret_buf = NULL;
4732 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4733 if (EVAS_HANDLE(pc)) {
4734 *paudio_only = (bool)pc->is_audio_only;
4735 return PLAYER_ERROR_NONE;
4739 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4740 if (ret == PLAYER_ERROR_NONE) {
4741 player_msg_get(audio_only, ret_buf);
4742 *paudio_only = (bool)audio_only;
4746 LOGD("LEAVE 0x%X", ret);
4750 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4752 int ret = PLAYER_ERROR_NONE;
4753 PLAYER_INSTANCE_CHECK(player);
4754 PLAYER_CHECK_CONDITION(buffer_ms >= 0 && rebuffer_ms >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4756 player_cli_s *pc = (player_cli_s *) player;
4757 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4758 char *ret_buf = NULL;
4762 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4763 MUSE_TYPE_INT, "buffer_ms", buffer_ms,
4764 MUSE_TYPE_INT, "rebuffer_ms", rebuffer_ms);
4767 LOGD("LEAVE 0x%X", ret);
4771 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4773 PLAYER_INSTANCE_CHECK(player);
4774 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4776 int ret = PLAYER_ERROR_NONE;
4777 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4778 player_cli_s *pc = (player_cli_s *) player;
4779 int buffering_time = 0, rebuffering_time = 0;
4780 char *ret_buf = NULL;
4784 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4786 if (ret == PLAYER_ERROR_NONE) {
4787 bool ret_val = true;
4788 ret_val = _player_get_param_value(ret_buf,
4789 MUSE_TYPE_INT, "buffering_time", (void *)&buffering_time,
4790 MUSE_TYPE_INT, "rebuffering_time", (void *)&rebuffering_time,
4791 INVALID_MUSE_TYPE_VALUE);
4793 if (buffer_ms) *buffer_ms = buffering_time;
4794 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4796 ret = PLAYER_ERROR_INVALID_OPERATION;
4802 LOGD("LEAVE 0x%X", ret);
4806 int player_360_is_content_spherical(player_h player, bool *is_spherical)
4808 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4809 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4811 PLAYER_INSTANCE_CHECK(player);
4812 PLAYER_NULL_ARG_CHECK(is_spherical);
4814 int ret = PLAYER_ERROR_NONE;
4815 muse_player_api_e api = MUSE_PLAYER_API_360_IS_CONTENT_SPHERICAL;
4816 player_cli_s *pc = (player_cli_s *) player;
4817 char *ret_buf = NULL;
4822 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4823 if (ret == PLAYER_ERROR_NONE) {
4824 player_msg_get(val, ret_buf);
4825 *is_spherical = val;
4829 LOGD("LEAVE 0x%X", ret);
4833 int player_360_set_enabled(player_h player, bool enabled)
4835 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4836 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4838 PLAYER_INSTANCE_CHECK(player);
4839 int ret = PLAYER_ERROR_NONE;
4840 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLED;
4841 player_cli_s *pc = (player_cli_s *) player;
4842 char *ret_buf = NULL;
4843 int val = (int)enabled;
4845 LOGD("ENTER %d", enabled);
4847 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
4850 LOGD("LEAVE 0x%X", ret);
4854 int player_360_is_enabled(player_h player, bool *enabled)
4856 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4857 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4859 PLAYER_INSTANCE_CHECK(player);
4860 PLAYER_NULL_ARG_CHECK(enabled);
4861 int ret = PLAYER_ERROR_NONE;
4862 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4863 player_cli_s *pc = (player_cli_s *) player;
4864 char *ret_buf = NULL;
4869 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4870 if (ret == PLAYER_ERROR_NONE) {
4871 player_msg_get(val, ret_buf);
4876 LOGD("LEAVE 0x%X", ret);
4880 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4882 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4883 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4885 PLAYER_INSTANCE_CHECK(player);
4886 PLAYER_CHECK_CONDITION(yaw >= (float)-M_PI && yaw <= (float)M_PI, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4887 PLAYER_CHECK_CONDITION(pitch >= (float)-M_PI/2 && pitch <= (float)M_PI/2, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4889 int ret = PLAYER_ERROR_NONE;
4890 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4891 player_cli_s *pc = (player_cli_s *) player;
4892 char *ret_buf = NULL;
4894 LOGD("ENTER %f %f", yaw, pitch);
4896 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4897 MUSE_TYPE_DOUBLE, "yaw", (double)yaw,
4898 MUSE_TYPE_DOUBLE, "pitch", (double)pitch);
4902 LOGD("LEAVE 0x%X", ret);
4906 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4908 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4909 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4911 PLAYER_INSTANCE_CHECK(player);
4912 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4913 int ret = PLAYER_ERROR_NONE;
4914 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4915 player_cli_s *pc = (player_cli_s *) player;
4916 double yaw_val = -1;
4917 double pitch_val = -1;
4918 char *ret_buf = NULL;
4922 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4924 if (ret == PLAYER_ERROR_NONE) {
4925 bool ret_val = true;
4926 ret_val = _player_get_param_value(ret_buf,
4927 MUSE_TYPE_DOUBLE, "yaw_val", (void *)&yaw_val,
4928 MUSE_TYPE_DOUBLE, "pitch_val", (void *)&pitch_val,
4929 INVALID_MUSE_TYPE_VALUE);
4931 *yaw = (float)yaw_val;
4932 *pitch = (float)pitch_val;
4934 LOGE("failed to get value from msg");
4935 ret = PLAYER_ERROR_INVALID_OPERATION;
4941 LOGD("LEAVE 0x%X", ret);
4945 int player_360_set_zoom(player_h player, float level)
4947 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4948 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4950 PLAYER_INSTANCE_CHECK(player);
4951 PLAYER_CHECK_CONDITION(level >= 1.0 && level <= 10.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
4953 int ret = PLAYER_ERROR_NONE;
4954 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4955 player_cli_s *pc = (player_cli_s *) player;
4956 char *ret_buf = NULL;
4958 LOGD("ENTER %f", level);
4960 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "level", (double)level);
4963 LOGD("LEAVE 0x%X", ret);
4967 int player_360_get_zoom(player_h player, float *level)
4969 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4970 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4972 PLAYER_INSTANCE_CHECK(player);
4973 PLAYER_NULL_ARG_CHECK(level);
4974 int ret = PLAYER_ERROR_NONE;
4975 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
4976 player_cli_s *pc = (player_cli_s *) player;
4978 char *ret_buf = NULL;
4982 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4984 if (ret == PLAYER_ERROR_NONE) {
4985 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
4986 *level = (float)zoom;
4988 LOGE("failed to get value from msg");
4989 ret = PLAYER_ERROR_INVALID_OPERATION;
4995 LOGD("LEAVE 0x%X", ret);
5000 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
5002 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5003 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5005 PLAYER_INSTANCE_CHECK(player);
5006 PLAYER_CHECK_CONDITION(horizontal_degrees >= 1 && horizontal_degrees <= 360, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
5007 PLAYER_CHECK_CONDITION(vertical_degrees >= 1 && vertical_degrees <= 180, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
5009 int ret = PLAYER_ERROR_NONE;
5010 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
5011 player_cli_s *pc = (player_cli_s *) player;
5012 char *ret_buf = NULL;
5014 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
5016 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5017 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5018 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5021 LOGD("LEAVE 0x%X", ret);
5025 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
5027 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5028 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5030 PLAYER_INSTANCE_CHECK(player);
5031 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
5032 int ret = PLAYER_ERROR_NONE;
5033 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
5034 player_cli_s *pc = (player_cli_s *) player;
5037 char *ret_buf = NULL;
5041 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5043 if (ret == PLAYER_ERROR_NONE) {
5044 bool ret_val = true;
5045 ret_val = _player_get_param_value(ret_buf,
5046 MUSE_TYPE_INT, "h_val", (void *)&h_val,
5047 MUSE_TYPE_INT, "v_val", (void *)&v_val,
5048 INVALID_MUSE_TYPE_VALUE);
5050 *horizontal_degrees = h_val;
5051 *vertical_degrees = v_val;
5053 LOGE("failed to get value from msg");
5054 ret = PLAYER_ERROR_INVALID_OPERATION;
5060 LOGD("LEAVE 0x%X", ret);
5064 int player_360_set_zoom_with_field_of_view(player_h player, float level, int horizontal_degrees, int vertical_degrees)
5066 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
5067 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
5069 PLAYER_INSTANCE_CHECK(player);
5070 PLAYER_CHECK_CONDITION(horizontal_degrees >= 1 && horizontal_degrees <= 360, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
5071 PLAYER_CHECK_CONDITION(vertical_degrees >= 1 && vertical_degrees <= 180, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
5072 PLAYER_CHECK_CONDITION(level >= 1.0 && level <= 10.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
5074 int ret = PLAYER_ERROR_NONE;
5075 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM_WITH_FIELD_OF_VIEW;
5076 player_cli_s *pc = (player_cli_s *) player;
5077 char *ret_buf = NULL;
5079 LOGD("ENTER %f %d %d", level, horizontal_degrees, vertical_degrees);
5081 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
5082 MUSE_TYPE_DOUBLE, "level", (double)level,
5083 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
5084 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
5087 LOGD("LEAVE 0x%X", ret);
5091 int player_set_replaygain_enabled(player_h player, bool enabled)
5093 PLAYER_INSTANCE_CHECK(player);
5094 int ret = PLAYER_ERROR_NONE;
5095 muse_player_api_e api = MUSE_PLAYER_API_SET_REPLAYGAIN_ENABLED;
5096 player_cli_s *pc = (player_cli_s *) player;
5097 char *ret_buf = NULL;
5098 int val = (int)enabled;
5102 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
5107 int player_is_replaygain_enabled(player_h player, bool *enabled)
5109 PLAYER_INSTANCE_CHECK(player);
5110 PLAYER_NULL_ARG_CHECK(enabled);
5111 int ret = PLAYER_ERROR_NONE;
5112 muse_player_api_e api = MUSE_PLAYER_API_IS_REPLAYGAIN_ENABLED;
5113 player_cli_s *pc = (player_cli_s *) player;
5114 char *ret_buf = NULL;
5119 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5120 if (ret == PLAYER_ERROR_NONE) {
5121 player_msg_get(val, ret_buf);
5122 *enabled = (bool) val;