2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
24 #include <tbm_bufmgr.h>
25 #include <tbm_surface.h>
26 #include <tbm_surface_internal.h>
29 #include <muse_core.h>
30 #include <muse_client.h>
31 #include <muse_player.h>
32 #include <muse_player_msg.h>
33 #include <sound_manager.h>
34 #include <sound_manager_internal.h>
35 #include <storage-internal.h>
36 #include <system_info.h>
37 #include "player_internal.h"
38 #include "player_private.h"
39 #include "player_msg.h"
41 #define INVALID_MUSE_TYPE_VALUE 0
42 #define MAX_S_PATH_LEN 32
43 #define PLAYER_FEATURE_SOUND_STREAM "http://tizen.org/feature/multimedia.player.stream_info"
44 #define PLAYER_FEATURE_OPENGL "http://tizen.org/feature/opengles.version.2_0"
45 #define PLAYER_FEATURE_SPHERICAL_VIDEO "http://tizen.org/feature/multimedia.player.spherical_video"
48 TIZEN_PROFILE_UNKNOWN = 0,
49 TIZEN_PROFILE_MOBILE = 0x1,
50 TIZEN_PROFILE_WEARABLE = 0x2,
51 TIZEN_PROFILE_TV = 0x4,
52 TIZEN_PROFILE_IVI = 0x8,
53 TIZEN_PROFILE_COMMON = 0x10,
57 tbm_fd tfd[MUSE_NUM_FD];
63 callback_cb_info_s *cb_info;
64 _player_recv_data *recv_data;
69 intptr_t remote_v_data;
73 } _media_pkt_fin_data;
75 static int _player_deinit_memory_buffer(player_cli_s * pc);
76 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data);
77 static bool _player_need_sync_context(int event_id);
78 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all);
79 #ifdef TIZEN_FEATURE_EVAS_RENDERER
80 typedef void (*player_retrieve_buffer_cb)(void *user_data);
81 static void __retrieve_buffer_cb(void *user_data);
82 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data);
83 static int __player_unset_retrieve_buffer_cb(player_h player);
85 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem);
88 * Internal Implementation
90 int _player_send_msg(muse_player_api_e api, player_cli_s *player, char* msg, tbm_fd tfd, char **retbuf)
92 int ret = PLAYER_ERROR_NONE;
94 int send_fd = INVALID_DEFAULT_VALUE;
95 int send_tfd[MUSE_NUM_FD];
96 int timeout = client_get_api_timeout(player, api);
98 memset(send_tfd, INVALID_DEFAULT_VALUE, sizeof(send_tfd));
100 if (player && CALLBACK_INFO(player)) {
101 send_fd = MSG_FD(player);
103 LOGE("can not access to cb_info");
104 return PLAYER_ERROR_INVALID_STATE;
107 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
108 LOGE("invalid socket fd %d", send_fd);
109 return PLAYER_ERROR_INVALID_OPERATION;
112 if (tfd != INVALID_DEFAULT_VALUE) {
114 send_len = muse_core_msg_send_fd(send_fd, send_tfd, msg);
116 send_len = muse_core_msg_send(send_fd, msg);
119 LOGE("sending message failed");
120 return PLAYER_ERROR_INVALID_OPERATION;
122 ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), retbuf, timeout);
128 int _player_send_msg_async(int send_fd, char* msg)
132 if ((send_fd <= 0) || !muse_core_fd_is_valid(send_fd)) {
133 LOGE("invalid socket fd %d", send_fd);
134 return PLAYER_ERROR_INVALID_OPERATION;
137 send_len = muse_core_msg_send(send_fd, msg);
139 LOGE("sending message failed");
140 return PLAYER_ERROR_INVALID_OPERATION;
143 return PLAYER_ERROR_NONE;
146 static tizen_profile_t _get_tizen_profile()
149 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
151 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
154 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
155 switch (*profileName) {
158 profile = TIZEN_PROFILE_MOBILE;
162 profile = TIZEN_PROFILE_WEARABLE;
166 profile = TIZEN_PROFILE_TV;
170 profile = TIZEN_PROFILE_IVI;
172 default: // common or unknown ==> ALL ARE COMMON.
173 profile = TIZEN_PROFILE_COMMON;
180 static int _get_current_state(player_cli_s *pc, player_state_e *pstate)
182 PLAYER_INSTANCE_CHECK(pc);
183 PLAYER_NULL_ARG_CHECK(pstate);
184 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
185 int ret = PLAYER_ERROR_NONE;
186 int state = PLAYER_STATE_NONE;
187 char *ret_buf = NULL;
189 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
191 if (ret == PLAYER_ERROR_NONE) {
192 player_msg_get(state, ret_buf);
194 LOGD("current state %d", *pstate);
201 static bool _player_get_param_value(char* buf, ...)
203 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
206 int type = MUSE_TYPE_ANY;
207 char *param_name = NULL;
212 void *jobj = muse_core_msg_object_new(buf, NULL, &err);
215 LOGE("failed to get msg object. err:%d", err);
219 va_start(var_args, buf);
221 while ((type = va_arg(var_args, int)) != INVALID_MUSE_TYPE_VALUE) {
222 param_name = va_arg(var_args, char *);
225 case MUSE_TYPE_INT64:
226 case MUSE_TYPE_DOUBLE:
227 case MUSE_TYPE_STRING:
228 case MUSE_TYPE_POINTER:
229 value = va_arg(var_args, void *);
231 if (!muse_core_msg_object_get_value(param_name, jobj, type, value)) {
233 LOGE("failed to get %s value", param_name);
237 LOGE("Unexpected type");
243 muse_core_msg_object_free(jobj);
249 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
251 int ret = MEDIA_PACKET_FINALIZE;
252 muse_player_api_e api = MUSE_PLAYER_API_RETURN_VIDEO_DATA;
253 _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
255 char *snd_msg = NULL;
259 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
263 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
264 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
268 if (!fin_data->use_tsurf_pool) {
269 tbm_surface_h tsurf = NULL;
270 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
271 LOGE("media_packet_get_tbm_surface failed");
272 /* continue the remained job */
275 /* LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf); */
276 tbm_surface_destroy(tsurf);
280 /* Do not destroy tbm surface here to reuse during playback *
281 * they will be destroyed at player_unprepare() or player_destroy(). *
282 * ref: __player_remove_tsurf_list() */
284 tbm_surface_h tsurf = NULL;
286 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
287 /* LOGD("tsurf set to null %p", tsurf); */
292 if (muse_core_fd_is_valid(fin_data->fd)) {
293 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
294 LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
298 v_data = fin_data->remote_v_data;
299 snd_msg = muse_core_msg_new(api, MUSE_TYPE_POINTER, "v_data", v_data, 0);
300 snd_len = muse_core_msg_send(fin_data->fd, snd_msg);
301 muse_core_msg_free(snd_msg);
304 LOGE("[fd:%d] fail to send msg.", fin_data->fd);
306 LOGE("[fd:%d] is invalid.", fin_data->fd);
318 static bool _player_check_network_availability(void)
320 #define _FEATURE_NAME_WIFI "http://tizen.org/feature/network.wifi"
321 #define _FEATURE_NAME_TELEPHONY "http://tizen.org/feature/network.telephony"
322 #define _FEATURE_NAME_ETHERNET "http://tizen.org/feature/network.ethernet"
323 bool enabled = FALSE;
324 bool supported = FALSE;
326 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
327 LOGI("wifi status = %d", enabled);
331 LOGE("SYSTEM_INFO_ERROR");
334 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
335 LOGI("telephony status = %d", enabled);
339 LOGE("SYSTEM_INFO_ERROR");
342 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
343 LOGI("ethernet status = %d", enabled);
347 LOGE("SYSTEM_INFO_ERROR");
356 static void *_get_mem(player_cli_s * player, int size)
358 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
360 mem->data = g_new(void, size);
361 mem->next = player->head;
368 static void _del_mem(player_cli_s * player)
371 while (player->head) {
372 mem = player->head->next;
373 g_free(player->head->data);
374 g_free(player->head);
379 static int player_recv_msg(callback_cb_info_s * cb_info, tbm_fd *tfd)
382 msg_buff_s *buff = &cb_info->buff;
384 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
385 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(*tfd) * MUSE_NUM_FD);
386 recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, tfd);
388 LOGE("failed to recv msg %d", recvLen);
392 /* check the first msg */
393 if (buff->part_of_msg && buff->recvMsg[0] != '{')
395 gchar *tmp = strndup(buff->recvMsg, recvLen);
397 LOGE("failed to copy msg.");
401 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
404 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
405 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
406 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
407 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
408 if (!buff->recvMsg) {
409 LOGE("failed renew buffer.");
414 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
416 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
417 recvLen += strlen(buff->part_of_msg);
419 free(buff->part_of_msg);
420 buff->part_of_msg = NULL;
425 /* check the last msg */
426 if (buff->recvMsg[recvLen-1] != '}') {
427 char *part_pos = strrchr(buff->recvMsg, '}');
428 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
431 buff->part_of_msg = strndup(part_pos+1, part_len);
432 if (!buff->part_of_msg) {
433 LOGE("failed to alloc buffer for part of msg.");
436 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
444 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
446 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
447 cb_info->user_cb[event] = NULL;
448 cb_info->user_data[event] = NULL;
452 /* Notice : have to be called via API to avoid deadlock
453 * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
455 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
460 LOGE("cb_info is NULL, event: %d", event);
464 lock = (g_thread_self() != cb_info->event_queue.thread);
467 g_mutex_lock(&cb_info->event_queue.mutex);
469 if (_player_need_sync_context(event))
470 _player_remove_idle_event(cb_info, event, false);
472 set_null_user_cb(cb_info, event);
475 g_mutex_unlock(&cb_info->event_queue.mutex);
478 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
480 PLAYER_INSTANCE_CHECK(player);
481 PLAYER_NULL_ARG_CHECK(callback);
482 int ret = PLAYER_ERROR_NONE;
483 player_cli_s *pc = (player_cli_s *) player;
484 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
487 if (MUSE_PLAYER_EVENT_TYPE_BUFFERING == type) {
488 if (!_player_check_network_availability())
489 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
492 if (!CALLBACK_INFO(pc))
493 return PLAYER_ERROR_INVALID_OPERATION;
495 LOGI("Event type : %d ", type);
496 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
498 if (ret == PLAYER_ERROR_NONE) {
499 pc->cb_info->user_cb[type] = callback;
500 pc->cb_info->user_data[type] = user_data;
505 static int __unset_callback(muse_player_event_e type, player_h player)
507 PLAYER_INSTANCE_CHECK(player);
508 int ret = PLAYER_ERROR_NONE;
509 player_cli_s *pc = (player_cli_s *) player;
510 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
513 LOGI("Event type : %d ", type);
515 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
516 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
518 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
523 static void __prepare_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
525 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
527 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
529 set_null_user_cb(cb_info, ev);
532 static void __complete_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
534 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
535 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
538 #ifdef TIZEN_FEATURE_EVAS_RENDERER
539 static void __retrieve_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
542 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
543 ((player_retrieve_buffer_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
547 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
550 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
552 if (player_msg_get(code, recv_data->buffer))
553 ((player_interrupted_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
556 static void __error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
559 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
561 if (player_msg_get(code, recv_data->buffer)) {
562 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
563 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
564 LOGW("failed to pause, so prepare cb will be released soon");
565 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
568 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
572 static void __disconnected_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
574 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
576 ((player_error_cb) cb_info->user_cb[ev]) (PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
579 static void __buffering_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
582 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
584 if (player_msg_get(percent, recv_data->buffer))
585 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
588 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
591 char text[MUSE_URI_MAX_LENGTH] = { 0, };
592 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
595 ret = _player_get_param_value(recv_data->buffer,
596 MUSE_TYPE_INT, "duration", (void *)&duration,
597 MUSE_TYPE_STRING, "text", (void *)text,
598 INVALID_MUSE_TYPE_VALUE);
600 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
603 static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
605 unsigned char *data = NULL;
608 unsigned int size = 0;
610 tbm_bo_handle thandle;
611 int key = INVALID_DEFAULT_VALUE;
613 get_ret = _player_get_param_value(recv_data->buffer,
614 MUSE_TYPE_INT, "width", (void *)&width,
615 MUSE_TYPE_INT, "height", (void *)&height,
616 MUSE_TYPE_INT, "size", (void *)&size,
617 MUSE_TYPE_INT, "key", (void *)&key,
618 INVALID_MUSE_TYPE_VALUE);
620 if (recv_data->tfd[0] < 0) {
621 LOGE("There is no valid tbm_fd");
625 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
627 LOGE("TBM get error : bo is NULL");
630 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
631 if (thandle.ptr == NULL) {
632 LOGE("TBM get error : handle pointer is NULL");
635 data = g_new(unsigned char, size);
637 memcpy(data, thandle.ptr, size);
638 ((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]);
641 LOGE("g_new failure");
647 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
648 close(recv_data->tfd[0]);
649 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
655 if (key > INVALID_DEFAULT_VALUE) {
656 LOGD("send msg to release buffer. key:%d", key);
657 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
660 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
663 static void __seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
665 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
666 #ifdef TIZEN_FEATURE_EVAS_RENDERER
667 void *dl_handle = NULL;
668 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
670 g_mutex_lock(&cb_info->seek_cb_mutex);
671 if (cb_info->user_cb[ev] && cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_NONE) {
672 #ifdef TIZEN_FEATURE_EVAS_RENDERER
673 if (cb_info->evas_info && cb_info->evas_info->support_video) {
674 if (cb_info->evas_info->handle && cb_info->evas_info->visible != EVAS_VISIBLE_FALSE) {
675 dl_handle = dlopen(PATH_DISP_LIB, RTLD_LAZY);
677 PLAYER_DISP_DLSYM(dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
678 int ret = p_disp_set_evas_display_visible(cb_info->evas_info->handle, true);
680 if (ret != MM_ERROR_NONE)
681 LOGW("failed to set visible at evas 0x%x", ret);
683 cb_info->evas_info->visible = EVAS_VISIBLE_TRUE;
685 LOGW("not support video rendering");
690 LOGD("call seek cb");
691 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
692 set_null_user_cb(cb_info, ev);
694 LOGW("ignored. seek cb %p", cb_info->user_cb[ev]);
696 g_mutex_unlock(&cb_info->seek_cb_mutex);
699 static void __player_remove_tsurf_list(player_cli_s * pc)
703 g_mutex_lock(&pc->cb_info->data_mutex);
704 if (pc->cb_info->tsurf_list) {
705 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
707 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
708 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
710 LOGD("%p will be removed", tmp);
713 tbm_surface_destroy(tmp->tsurf);
719 g_list_free(pc->cb_info->tsurf_list);
720 pc->cb_info->tsurf_list = NULL;
722 g_mutex_unlock(&pc->cb_info->data_mutex);
726 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, int height, int width)
730 g_mutex_lock(&cb_info->data_mutex);
731 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
732 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
733 if (tmp && key && (tmp->key[0] == key[0])) {
734 LOGD("found tsurf_data of tbm_key %d", key[0]);
736 /* need to check tsuf info to support DRC */
737 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
738 (tbm_surface_get_width(tmp->tsurf) != width)) {
740 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
741 LOGW("tsurf info is changed. need to create new tsurf.");
742 tbm_surface_destroy(tmp->tsurf);
745 g_mutex_unlock(&cb_info->data_mutex);
749 g_mutex_unlock(&cb_info->data_mutex);
754 g_mutex_unlock(&cb_info->data_mutex);
758 static media_packet_rotate_method_e __convert_packet_orient_info(int orientation)
760 media_packet_rotate_method_e rotate = MEDIA_PACKET_ROTATE_IDENTITY;
762 switch (orientation) {
764 rotate = MEDIA_PACKET_ROTATE_90;
767 rotate = MEDIA_PACKET_ROTATE_180;
770 rotate = MEDIA_PACKET_ROTATE_270;
773 rotate = MEDIA_PACKET_ROTATE_IDENTITY;
780 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
782 tbm_bo bo[4] = { NULL, };
783 int key[4] = { INVALID_DEFAULT_VALUE, };
784 tbm_surface_info_s sinfo;
785 char *surface_info = (char *)&sinfo;
786 media_packet_h pkt = NULL;
787 tbm_surface_h tsurf = NULL;
788 player_tsurf_info_t *tsurf_data = NULL;
790 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
791 bool make_pkt_fmt = false;
792 int ret = MEDIA_FORMAT_ERROR_NONE;
793 _media_pkt_fin_data *fin_data = NULL;
796 int i = 0, orientation = 0;
797 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
799 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
801 !muse_core_msg_object_get_value("key[0]", jobj, MUSE_TYPE_ANY, &key[0]) ||
802 !muse_core_msg_object_get_value("key[1]", jobj, MUSE_TYPE_ANY, &key[1]) ||
803 !muse_core_msg_object_get_value("key[2]", jobj, MUSE_TYPE_ANY, &key[2]) ||
804 !muse_core_msg_object_get_value("key[3]", jobj, MUSE_TYPE_ANY, &key[3]) ||
805 !muse_core_msg_object_get_value("v_data", jobj, MUSE_TYPE_POINTER, &v_data) ||
806 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
807 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
808 !muse_core_msg_object_get_value("orientation", jobj, MUSE_TYPE_INT, &orientation) ||
809 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
811 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
813 muse_core_msg_object_free(jobj);
816 muse_core_msg_object_free(jobj);
818 LOGD("width %d, height %d", sinfo.width, sinfo.height);
821 LOGE("cb_info is null");
825 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
826 /* send msg to release v_data. */
827 LOGE("_video_decoded_cb is not set");
831 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
832 LOGE("tbm fd is invalid");
836 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
838 for (i = 0; i < MUSE_NUM_FD; i++) {
839 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
843 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
846 tsurf_data = g_new(player_tsurf_info_t, 1);
848 LOGE("failed to alloc tsurf info");
851 memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
853 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
855 LOGE("failed to create tbm surface");
859 memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
860 tsurf_data->tsurf = tsurf;
861 if (cb_info->use_tsurf_pool) {
862 g_mutex_lock(&cb_info->data_mutex);
863 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
864 LOGD("key %d is added to the pool", key[0]);
865 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
866 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
867 g_mutex_unlock(&cb_info->data_mutex);
870 if (tsurf_data->tsurf) {
871 tsurf = tsurf_data->tsurf;
873 LOGE("tsurf_data->tsurf is null (never enter here)");
878 /* check media packet format */
879 if (cb_info->pkt_fmt) {
880 int pkt_fmt_width = 0;
881 int pkt_fmt_height = 0;
882 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
884 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
885 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
886 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);
887 media_format_unref(cb_info->pkt_fmt);
888 cb_info->pkt_fmt = NULL;
894 /* create packet format */
896 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
897 ret = media_format_create(&cb_info->pkt_fmt);
898 if (ret == MEDIA_FORMAT_ERROR_NONE) {
899 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
900 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
901 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
902 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
904 LOGE("media_format_create failed");
908 fin_data = g_new0(_media_pkt_fin_data, 1);
910 LOGE("failed to alloc fin_data");
913 fin_data->remote_v_data = v_data;
914 fin_data->fd = cb_info->fd;
915 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
917 /* Keep the fd id to check validation when the pkt is destroyed. */
918 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
920 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
921 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
922 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
927 ret = media_packet_set_pts(pkt, (uint64_t) pts);
928 if (ret != MEDIA_PACKET_ERROR_NONE)
929 LOGE("media_packet_set_pts failed");
932 ret = media_packet_set_rotate_method(pkt, __convert_packet_orient_info(orientation));
933 if (ret != MEDIA_PACKET_ERROR_NONE)
934 LOGE("media_packet_set_rotate_method failed");
936 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
937 /* call media packet callback */
938 ((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]);
940 LOGE("_video_decoded_cb is not set");
941 media_packet_destroy(pkt);
944 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
945 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
946 close(recv_data->tfd[i]);
949 for (i = 0; i < bo_num; i++) {
954 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
959 media_packet_destroy(pkt);
964 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
965 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
966 close(recv_data->tfd[i]);
969 for (i = 0; i < bo_num; i++) {
973 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
975 if (cb_info && v_data)
976 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_VIDEO_DATA, cb_info->fd, MUSE_TYPE_POINTER, "v_data", v_data);
981 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
984 tbm_bo_handle thandle;
985 int key = INVALID_DEFAULT_VALUE;
986 player_audio_raw_data_s audio;
988 if (!player_msg_get(key, recv_data->buffer)) {
989 LOGE("failed to get key value from msg.");
993 if (recv_data->tfd[0] < 0) {
994 LOGE("failed to get tbm_fd(key:%d)", key);
998 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
1000 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
1004 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
1005 if (thandle.ptr == NULL) {
1006 LOGE("TBM get error : handle pointer is NULL");
1010 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
1011 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
1013 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
1014 ((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]);
1018 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
1019 close(recv_data->tfd[0]);
1020 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
1026 if (key > INVALID_DEFAULT_VALUE) {
1027 /* LOGD("send msg to release buffer. key:%d", key); */
1028 PLAYER_SEND_MSG_ASYNC_WITH_NO_RETURN(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, MUSE_TYPE_INT, "key", key);
1032 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1036 static void __pd_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1039 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
1041 if (player_msg_get(type, recv_data->buffer))
1042 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
1045 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1049 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1053 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1057 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1059 /* player_media_stream_buffer_status_e status; */
1062 if (player_msg_get(status, recv_data->buffer)) {
1063 ((player_media_stream_buffer_status_cb)
1064 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]);
1068 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1070 /* player_media_stream_buffer_status_e status; */
1073 if (player_msg_get(status, recv_data->buffer)) {
1074 ((player_media_stream_buffer_status_cb)
1075 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
1076 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
1081 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1083 /* player_media_stream_buffer_status_e status; */
1085 unsigned long long bytes;
1088 ret = _player_get_param_value(recv_data->buffer,
1089 MUSE_TYPE_INT, "status", (void *)&status,
1090 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1091 INVALID_MUSE_TYPE_VALUE);
1093 ((player_media_stream_buffer_status_cb_ex)
1094 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
1095 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
1099 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1101 /* player_media_stream_buffer_status_e status; */
1103 unsigned long long bytes;
1106 ret = _player_get_param_value(recv_data->buffer,
1107 MUSE_TYPE_INT, "status", (void *)&status,
1108 MUSE_TYPE_INT64, "bytes", (void *)&bytes,
1109 INVALID_MUSE_TYPE_VALUE);
1111 ((player_media_stream_buffer_status_cb_ex)
1112 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
1113 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
1118 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1120 unsigned long long offset;
1122 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1123 ((player_media_stream_seek_cb)
1124 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
1125 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
1129 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1131 unsigned long long offset;
1133 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1134 ((player_media_stream_seek_cb)
1135 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
1136 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1140 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1146 bool ret_val = TRUE;
1147 ret_val = _player_get_param_value(recv_data->buffer,
1148 MUSE_TYPE_INT, "width", (void *)&width,
1149 MUSE_TYPE_INT, "height", (void *)&height,
1150 MUSE_TYPE_INT, "fps", (void *)&fps,
1151 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
1152 INVALID_MUSE_TYPE_VALUE);
1154 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1155 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1159 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, _player_recv_data *recv_data) = {
1160 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1161 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1162 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1163 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1164 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1165 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1166 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1167 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1168 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1169 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
1170 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1171 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
1172 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1173 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1174 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1175 #ifdef _PLAYER_FOR_PRODUCT
1176 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1177 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1179 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1180 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1181 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1182 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1183 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1184 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1185 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1186 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1187 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1188 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1190 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1193 gboolean _player_event_job_function(void *user_data)
1195 _player_cb_data *data = (_player_cb_data *)user_data;
1196 muse_player_event_e ev;
1199 LOGE("data is null");
1203 LOGD("enter ev:%d", data->int_data);
1205 g_mutex_lock(&data->event_mutex);
1206 ev = data->int_data;
1208 if (data->cb_info == NULL) {
1209 /* tried to remove before at _player_remove_idle_event */
1210 LOGW("cb_info is NULL. event %d", data->int_data);
1214 /* remove event from list */
1215 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1216 if (data->cb_info->event_queue.idle_ev_list) {
1217 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1218 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1220 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1222 if (data->cb_info->user_cb[ev])
1223 _user_callbacks[ev] (data->cb_info, data->recv_data);
1225 LOGW("user callback is unset. type : %d", ev);
1228 /* unlock and release event */
1229 g_mutex_unlock(&data->event_mutex);
1230 g_mutex_clear(&data->event_mutex);
1232 if (data->recv_data) {
1233 g_free(data->recv_data->buffer);
1234 g_free(data->recv_data);
1238 return FALSE; /* remove from the event list */
1241 static bool _player_need_sync_context(int event_id)
1243 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1244 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1245 (event_id == MUSE_PLAYER_EVENT_TYPE_PD) ||
1246 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1247 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1248 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1249 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1250 LOGD("%d callback will be issued in the mainloop.", event_id);
1257 static void *_player_event_queue_loop(void *param)
1260 LOGE("NULL parameter");
1263 callback_cb_info_s *cb_info = param;
1264 player_event_queue *ev = &cb_info->event_queue;
1265 _player_cb_data *event_data = NULL;
1267 g_mutex_lock(&ev->mutex);
1268 while (ev->running) {
1269 g_mutex_lock(&ev->qlock);
1270 if (g_queue_is_empty(ev->queue)) {
1271 g_mutex_unlock(&ev->qlock);
1272 g_cond_wait(&ev->cond, &ev->mutex);
1276 g_mutex_unlock(&ev->qlock);
1279 g_mutex_lock(&ev->qlock);
1280 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1281 g_mutex_unlock(&ev->qlock);
1283 muse_player_event_e event_type = ((_player_cb_data *)event_data)->int_data;
1285 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1286 g_mutex_lock(&cb_info->seek_cb_mutex);
1287 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1288 /* push event into queue again. */
1289 _player_event_queue_add(ev, event_data);
1290 g_mutex_unlock(&cb_info->seek_cb_mutex);
1293 g_mutex_unlock(&cb_info->seek_cb_mutex);
1296 if (_player_need_sync_context(event_data->int_data)) {
1297 if (cb_info->user_cb[event_data->int_data] &&
1298 _user_callbacks[event_data->int_data]) {
1299 g_mutex_lock(&ev->idle_ev_mutex);
1300 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1301 g_mutex_unlock(&ev->idle_ev_mutex);
1303 LOGD("add ev %d to main loop", event_data->int_data);
1305 g_idle_add_full(G_PRIORITY_DEFAULT,
1306 (GSourceFunc)_player_event_job_function,
1307 (gpointer)event_data,
1310 LOGW("there is no registered cb for ev:%d", event_data->int_data);
1311 if (event_data->recv_data) {
1312 g_free(event_data->recv_data->buffer);
1313 g_free(event_data->recv_data);
1318 _player_event_job_function(event_data);
1325 g_mutex_unlock(&ev->mutex);
1326 LOGI("Exit event loop");
1330 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1332 g_return_val_if_fail(cb_info, FALSE);
1333 player_event_queue *ev = &cb_info->event_queue;
1335 ev->queue = g_queue_new();
1336 g_return_val_if_fail(ev->queue, FALSE);
1337 g_mutex_init(&ev->qlock);
1339 g_mutex_init(&ev->mutex);
1340 g_cond_init(&ev->cond);
1343 g_mutex_init(&ev->idle_ev_mutex);
1345 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1346 g_return_val_if_fail(ev->thread, FALSE);
1347 LOGI("event queue thread %p", ev->thread);
1353 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1355 g_return_if_fail(cb_info);
1356 player_event_queue *ev = &cb_info->event_queue;
1357 _player_cb_data *event_data = NULL;
1360 g_mutex_lock(&ev->idle_ev_mutex);
1362 if (ev->idle_ev_list == NULL) {
1363 LOGD("No idle event is remained.");
1364 g_mutex_unlock(&ev->idle_ev_mutex);
1368 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1370 list = ev->idle_ev_list;
1372 event_data = list->data;
1373 list = g_list_next(list);
1376 LOGW("Fail to remove idle event. The data is NULL");
1380 if (g_mutex_trylock(&event_data->event_mutex)) {
1382 gboolean ret = FALSE;
1383 if (remove_all || (event_data->int_data == event_type)) {
1385 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1387 ret = g_idle_remove_by_data(event_data);
1389 /* will be handled at _player_event_job_function() as an exception */
1390 event_data->cb_info = NULL;
1391 LOGW("failed to remove, idle callback will be called later");
1394 /* set cb to null */
1395 set_null_user_cb(cb_info, event_data->int_data);
1396 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1398 g_mutex_unlock(&event_data->event_mutex);
1401 g_mutex_clear(&event_data->event_mutex);
1402 if (event_data->recv_data) {
1403 g_free(event_data->recv_data->buffer);
1404 g_free(event_data->recv_data);
1408 LOGD("remove idle event done");
1409 } /* else : will be handled if the cb is called. */
1411 g_mutex_unlock(&event_data->event_mutex);
1414 LOGW("event(%d) lock failed. it's being called...", event_data->int_data);
1417 /* continue: keep checking next event_data */
1421 g_list_free(ev->idle_ev_list);
1422 ev->idle_ev_list = NULL;
1425 g_mutex_unlock(&ev->idle_ev_mutex);
1431 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1433 g_return_if_fail(cb_info);
1434 player_event_queue *ev = &cb_info->event_queue;
1435 _player_cb_data *event_data;
1437 LOGI("event queue thread %p", ev->thread);
1439 g_mutex_lock(&ev->mutex);
1440 ev->running = FALSE;
1441 g_cond_broadcast(&ev->cond);
1442 g_mutex_unlock(&ev->mutex);
1444 g_thread_join(ev->thread);
1447 while (!g_queue_is_empty(ev->queue)) {
1448 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1450 g_free(event_data->recv_data->buffer);
1451 g_free(event_data->recv_data);
1455 g_queue_free(ev->queue);
1456 g_mutex_clear(&ev->qlock);
1457 g_mutex_clear(&ev->mutex);
1458 g_cond_clear(&ev->cond);
1459 g_mutex_clear(&ev->idle_ev_mutex);
1462 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1466 g_mutex_lock(&ev_queue->qlock);
1468 item = g_queue_peek_head_link(ev_queue->queue);
1470 GList *next = item->next;
1471 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1473 if (cb_data && cb_data->int_data == ev) {
1474 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1475 g_free(cb_data->recv_data->buffer);
1476 g_free(cb_data->recv_data);
1479 g_queue_delete_link(ev_queue->queue, item);
1483 g_mutex_unlock(&ev_queue->qlock);
1486 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1489 g_mutex_lock(&ev->qlock);
1490 g_queue_push_tail(ev->queue, (gpointer) data);
1491 g_mutex_unlock(&ev->qlock);
1492 g_cond_signal(&ev->cond);
1496 static bool _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1498 /* LOGD("get event %d", event); */
1500 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1501 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1502 _player_cb_data *data = NULL;
1503 data = g_new(_player_cb_data, 1);
1505 LOGE("fail to alloc mem");
1508 data->int_data = (int)event;
1509 data->cb_info = cb_info;
1510 data->recv_data = recv_data;
1511 g_mutex_init(&data->event_mutex);
1512 _player_event_queue_add(&cb_info->event_queue, data);
1518 LOGE("failed to add event to queue");
1522 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1524 ret_msg_s *msg = NULL;
1525 ret_msg_s *last = cb_info->buff.retMsgHead;
1527 msg = g_new(ret_msg_s, 1);
1530 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1533 cb_info->buff.retMsgHead = msg;
1540 LOGE("g_new failure");
1543 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1545 ret_msg_s *msg = cb_info->buff.retMsgHead;
1546 ret_msg_s *prev = NULL;
1548 if (msg->api == api) {
1550 cb_info->buff.retMsgHead = msg->next;
1552 prev->next = msg->next;
1561 static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
1563 ret_msg_s *msg = cb_info->buff.retMsgHead;
1564 ret_msg_s *prev = NULL;
1568 LOGI("Remove %s", prev->msg);
1575 static void _notify_disconnected(callback_cb_info_s * cb_info)
1577 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1578 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1581 if (_user_callbacks[event]) {
1582 _player_cb_data *data = NULL;
1583 data = g_new(_player_cb_data, 1);
1585 LOGE("fail to alloc mem");
1588 data->int_data = (int)event;
1589 data->cb_info = cb_info;
1590 data->recv_data = NULL;
1591 g_mutex_init(&data->event_mutex);
1592 _player_event_queue_add(&cb_info->event_queue, data);
1596 static void *client_cb_handler(gpointer data)
1602 callback_cb_info_s *cb_info = data;
1603 char *recvMsg = NULL;
1604 muse_core_msg_parse_err_e err;
1605 tbm_fd tfd[MUSE_NUM_FD];
1607 while (g_atomic_int_get(&cb_info->running)) {
1609 err = MUSE_MSG_PARSE_ERROR_NONE;
1611 len = player_recv_msg(cb_info, tfd);
1615 recvMsg = cb_info->buff.recvMsg;
1616 recvMsg[len] = '\0';
1620 while (offset < len) {
1621 api = MUSE_PLAYER_API_MAX;
1622 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1625 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1627 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1628 if (api < MUSE_PLAYER_API_MAX) {
1629 g_mutex_lock(&cb_info->player_mutex);
1630 cb_info->buff.recved++;
1631 _add_ret_msg(api, cb_info, offset, parse_len);
1632 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1633 LOGD("get tbm fd for album art.");
1634 cb_info->tfd = tfd[0];
1636 g_cond_signal(&cb_info->player_cond[api]);
1637 g_mutex_unlock(&cb_info->player_mutex);
1638 if (api == MUSE_PLAYER_API_DESTROY)
1639 g_atomic_int_set(&cb_info->running, 0);
1640 } else if (api == MUSE_PLAYER_CB_EVENT) {
1642 _player_recv_data *recv_data = NULL;
1643 g_mutex_lock(&cb_info->player_mutex);
1644 recv_data = g_new0(_player_recv_data, 1);
1645 if (recv_data != NULL) {
1646 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1647 recv_data->buffer = strndup(recvMsg+offset, parse_len);
1649 LOGE("failed to alloc recv_data.");
1650 g_mutex_unlock(&cb_info->player_mutex);
1651 muse_core_msg_object_free(jobj);
1654 g_mutex_unlock(&cb_info->player_mutex);
1655 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1656 !_user_callback_handler(cb_info, event, recv_data)) {
1657 LOGE("failed to get value or add event to the queue.");
1659 g_free(recv_data->buffer);
1663 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1664 g_mutex_lock(&cb_info->player_mutex);
1665 cb_info->buff.recved++;
1666 g_cond_signal(&cb_info->server_ack_cond);
1667 g_mutex_unlock(&cb_info->player_mutex);
1670 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1672 muse_core_msg_object_free(jobj);
1674 LOGE("Failed to get msg obj. err:%d", err);
1677 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1680 offset += parse_len;
1681 parse_len = len - offset;
1684 if (g_atomic_int_get(&cb_info->running))
1685 _notify_disconnected(cb_info);
1686 LOGD("client cb exit");
1691 static callback_cb_info_s *callback_new(gint sockfd)
1693 callback_cb_info_s *cb_info;
1697 g_return_val_if_fail(sockfd > 0, NULL);
1699 cb_info = g_new(callback_cb_info_s, 1);
1702 memset(cb_info, 0, sizeof(callback_cb_info_s));
1704 g_mutex_init(&cb_info->player_mutex);
1705 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1706 g_cond_init(&cb_info->player_cond[i]);
1707 g_cond_init(&cb_info->server_ack_cond);
1709 g_mutex_init(&cb_info->data_mutex);
1710 g_mutex_init(&cb_info->seek_cb_mutex);
1712 buff = &cb_info->buff;
1713 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1714 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1716 buff->retMsgHead = NULL;
1717 buff->part_of_msg = NULL;
1719 g_atomic_int_set(&cb_info->running, 1);
1720 cb_info->fd = sockfd;
1721 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1722 cb_info->tfd = INVALID_DEFAULT_VALUE;
1727 static void callback_destroy(callback_cb_info_s * cb_info)
1730 g_return_if_fail(cb_info);
1732 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1733 muse_client_close(cb_info->fd);
1734 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1735 muse_client_close(cb_info->data_fd);
1737 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1739 g_thread_join(cb_info->thread);
1740 cb_info->thread = NULL;
1742 LOGI("%p Callback destroyed", cb_info);
1744 g_mutex_clear(&cb_info->player_mutex);
1745 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1746 g_cond_clear(&cb_info->player_cond[i]);
1747 g_cond_clear(&cb_info->server_ack_cond);
1749 g_mutex_clear(&cb_info->data_mutex);
1750 g_mutex_clear(&cb_info->seek_cb_mutex);
1752 g_free(cb_info->buff.recvMsg);
1753 _remove_all_ret_msg(cb_info);
1754 if (cb_info->buff.part_of_msg)
1755 g_free(cb_info->buff.part_of_msg);
1759 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1764 case MUSE_PLAYER_API_PREPARE:
1765 case MUSE_PLAYER_API_PREPARE_ASYNC:
1766 case MUSE_PLAYER_API_UNPREPARE:
1767 case MUSE_PLAYER_API_START:
1768 case MUSE_PLAYER_API_STOP:
1769 case MUSE_PLAYER_API_PAUSE:
1770 timeout += SERVER_TIMEOUT(pc);
1773 /* check prepare async is done */
1774 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1775 timeout += SERVER_TIMEOUT(pc);
1778 timeout += CALLBACK_TIME_OUT;
1779 return timeout; /* ms */
1782 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1784 int ret = PLAYER_ERROR_NONE;
1785 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1786 msg_buff_s *buff = &cb_info->buff;
1787 ret_msg_s *msg = NULL;
1789 g_mutex_lock(&cb_info->player_mutex);
1791 msg = _get_ret_msg(api, cb_info);
1793 if (!buff->recved || !msg) {
1794 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1795 LOGW("api %d return msg does not received %dms", api, time_out);
1796 ret = PLAYER_ERROR_INVALID_OPERATION;
1801 msg = _get_ret_msg(api, cb_info);
1803 *ret_buf = msg->msg;
1806 if (!player_msg_get(ret, *ret_buf))
1807 ret = PLAYER_ERROR_INVALID_OPERATION;
1809 LOGE("api %d is the spurious wakeup", api);
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 (!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;
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)->support_video) {
2000 if (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);
2006 g_free(pc->cb_info->evas_info);
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;
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;
2103 if (!CALLBACK_INFO(pc))
2104 return PLAYER_ERROR_INVALID_STATE;
2106 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2108 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2109 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
2110 _player_release_internal_memory(pc, false);
2112 pc->cb_info->video_frame_pool_size = 0;
2113 __player_remove_tsurf_list(pc);
2114 pc->is_audio_only = FALSE;
2118 LOGD("LEAVE 0x%X", ret);
2122 /* 1. correct the protocol prefix to lower case
2123 * 2. remove 'file://' prefix
2124 * 3. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' */
2125 int _player_get_valid_path(const char* uri, char* valid_path)
2127 gchar *file_path = NULL;
2129 gchar *colon = NULL;
2131 if (!uri || !valid_path) {
2132 LOGD("invalid parameter");
2133 return PLAYER_ERROR_INVALID_PARAMETER;
2136 if ((colon = strstr(uri, "://")) != NULL) {
2137 gchar *protocol = g_ascii_strdown(uri, colon - uri);
2141 file_path = g_strconcat(protocol, uri+strlen(protocol), NULL);
2142 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2148 if (strstr(valid_path, "file://")) { /* handle the 'file://' prefix */
2150 file_path = g_filename_from_uri(valid_path, NULL, &err);
2151 if (!file_path || (err != NULL)) {
2152 SECURE_LOGE("Invalid URI '%s', err: %s", uri,
2153 (err != NULL) ? err->message : "unknown error");
2155 if (err) g_error_free(err);
2156 if (file_path) g_free(file_path);
2158 return PLAYER_ERROR_INVALID_PARAMETER;
2160 LOGD("get file path from uri");
2162 LOGD("use the original path.");
2163 return PLAYER_ERROR_NONE;
2168 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, valid_path) < 0) {
2169 /* cannot convert path. use the original one. */
2170 strncpy(valid_path, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
2172 /* need to use converted path. */
2173 SECURE_LOGD("Converted path : %s -> %s", uri, valid_path);
2178 return PLAYER_ERROR_NONE;
2181 int player_set_uri(player_h player, const char *uri)
2183 PLAYER_INSTANCE_CHECK(player);
2184 PLAYER_NULL_ARG_CHECK(uri);
2185 int ret = PLAYER_ERROR_NONE;
2186 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2187 player_cli_s *pc = (player_cli_s *) player;
2188 char *ret_buf = NULL;
2189 char path[MAX_URL_LEN] = {0, };
2193 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
2194 return PLAYER_ERROR_INVALID_PARAMETER;
2196 SECURE_LOGD("new path : %s", path);
2198 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", (const char*)path);
2199 pc->push_media_stream = FALSE;
2205 int player_set_memory_buffer(player_h player, const void *data, int size)
2207 PLAYER_INSTANCE_CHECK(player);
2208 PLAYER_NULL_ARG_CHECK(data);
2209 int ret = PLAYER_ERROR_NONE;
2210 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2211 player_cli_s *pc = (player_cli_s *) player;
2212 char *ret_buf = NULL;
2214 tbm_bo_handle thandle;
2215 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2217 /* before setting mem buffer, player state have to be checked. */
2218 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2220 if (SERVER_TBM_BO(pc)) {
2221 LOGW("The previous memory buffer will be cleared.");
2222 _player_deinit_memory_buffer(pc);
2225 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2227 LOGE("TBM get error : bo is NULL");
2228 return PLAYER_ERROR_INVALID_OPERATION;
2230 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2231 if (thandle.ptr == NULL) {
2232 LOGE("TBM get error : handle pointer is NULL");
2233 ret = PLAYER_ERROR_INVALID_OPERATION;
2236 memcpy(thandle.ptr, data, size);
2239 tfd = tbm_bo_export_fd(bo);
2241 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2242 ret = PLAYER_ERROR_INVALID_OPERATION;
2246 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret, MUSE_TYPE_INT, "size", size);
2247 pc->push_media_stream = FALSE;
2250 if (tfd > INVALID_DEFAULT_VALUE)
2255 if (ret == PLAYER_ERROR_NONE) {
2256 intptr_t bo_addr = 0;
2257 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2258 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2265 static void _player_release_internal_memory(player_cli_s * pc, bool deinit_server_mem)
2272 if (deinit_server_mem)
2273 _player_deinit_memory_buffer(pc);
2276 static int _player_deinit_memory_buffer(player_cli_s * pc)
2278 PLAYER_INSTANCE_CHECK(pc);
2279 int ret = PLAYER_ERROR_NONE;
2280 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2281 intptr_t bo_addr = SERVER_TBM_BO(pc);
2283 if (!bo_addr || !CALLBACK_INFO(pc))
2286 PLAYER_SEND_MSG_ASYNC(api, MSG_FD(pc), ret, MUSE_TYPE_POINTER, "bo_addr", bo_addr);
2287 SERVER_TBM_BO(pc) = 0;
2292 int player_get_state(player_h player, player_state_e *pstate)
2294 PLAYER_INSTANCE_CHECK(player);
2295 PLAYER_NULL_ARG_CHECK(pstate);
2296 int ret = PLAYER_ERROR_NONE;
2297 player_cli_s *pc = (player_cli_s *) player;
2301 ret = _get_current_state(pc, pstate);
2305 int player_set_volume(player_h player, float left, float right)
2307 PLAYER_INSTANCE_CHECK(player);
2308 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2309 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2310 int ret = PLAYER_ERROR_NONE;
2311 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2312 player_cli_s *pc = (player_cli_s *) player;
2313 char *ret_buf = NULL;
2317 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2318 MUSE_TYPE_DOUBLE, "right", (double)right,
2319 MUSE_TYPE_DOUBLE, "left", (double)left);
2325 int player_get_volume(player_h player, float *pleft, float *pright)
2327 PLAYER_INSTANCE_CHECK(player);
2328 PLAYER_NULL_ARG_CHECK(pleft && pright);
2329 int ret = PLAYER_ERROR_NONE;
2330 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2331 player_cli_s *pc = (player_cli_s *) player;
2334 char *ret_buf = NULL;
2338 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2340 if (ret == PLAYER_ERROR_NONE) {
2341 bool ret_val = true;
2342 ret_val = _player_get_param_value(ret_buf,
2343 MUSE_TYPE_DOUBLE, "left", (void *)&left,
2344 MUSE_TYPE_DOUBLE, "right", (void *)&right,
2345 INVALID_MUSE_TYPE_VALUE);
2347 *pleft = (float)left;
2348 *pright = (float)right;
2350 LOGE("failed to get value from msg");
2351 ret = PLAYER_ERROR_INVALID_OPERATION;
2359 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2361 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SOUND_STREAM);
2362 PLAYER_INSTANCE_CHECK(player);
2364 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2365 player_cli_s *pc = (player_cli_s *) player;
2366 bool is_available = false;
2367 char *ret_buf = NULL;
2371 /* check if stream_info is valid */
2372 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2373 if (ret != SOUND_MANAGER_ERROR_NONE) {
2374 LOGE("failed to checking available stream info");
2375 return PLAYER_ERROR_INVALID_OPERATION;
2378 if (is_available == false) {
2379 ret = PLAYER_ERROR_INVALID_PARAMETER;
2381 char *stream_type = NULL;
2382 int stream_index = 0;
2383 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2384 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2385 if (ret == SOUND_MANAGER_ERROR_NONE)
2386 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2387 MUSE_TYPE_STRING, "stream_type", (const char*)stream_type,
2388 MUSE_TYPE_INT, "stream_index", stream_index);
2390 ret = PLAYER_ERROR_INVALID_OPERATION;
2393 LOGD("LEAVE ret: 0x%X", ret);
2400 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2402 PLAYER_INSTANCE_CHECK(player);
2403 int ret = PLAYER_ERROR_NONE;
2404 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2405 player_cli_s *pc = (player_cli_s *) player;
2406 char *ret_buf = NULL;
2410 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "latency_mode", (int)latency_mode);
2415 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2417 PLAYER_INSTANCE_CHECK(player);
2418 PLAYER_NULL_ARG_CHECK(platency_mode);
2419 int ret = PLAYER_ERROR_NONE;
2420 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2421 player_cli_s *pc = (player_cli_s *) player;
2422 char *ret_buf = NULL;
2423 int latency_mode = -1;
2427 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2429 if (ret == PLAYER_ERROR_NONE) {
2430 player_msg_get(latency_mode, ret_buf);
2431 *platency_mode = latency_mode;
2439 int player_start(player_h player)
2441 PLAYER_INSTANCE_CHECK(player);
2442 int ret = PLAYER_ERROR_NONE;
2443 muse_player_api_e api = MUSE_PLAYER_API_START;
2444 player_cli_s *pc = (player_cli_s *) player;
2445 char *ret_buf = NULL;
2448 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2449 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2451 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2452 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2453 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2454 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2455 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), true);
2456 if (ret != MM_ERROR_NONE) {
2457 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2458 return PLAYER_ERROR_INVALID_OPERATION;
2460 /* avoid setting true at all times, when player is resumed */
2461 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2466 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2470 LOGD("LEAVE 0x%X", ret);
2474 int player_stop(player_h player)
2476 PLAYER_INSTANCE_CHECK(player);
2477 int ret = PLAYER_ERROR_NONE;
2478 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2479 player_cli_s *pc = (player_cli_s *) player;
2480 char *ret_buf = NULL;
2481 player_state_e state = PLAYER_STATE_NONE;
2482 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2483 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
2487 /* check player state */
2488 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
2489 LOGE("Failed to get state");
2490 return PLAYER_ERROR_INVALID_OPERATION;
2493 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2494 LOGE("Invalid state %d", state);
2495 return PLAYER_ERROR_INVALID_STATE;
2498 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2499 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2500 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2501 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2502 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
2503 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), false);
2504 if (ret != MM_ERROR_NONE) {
2505 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2506 return PLAYER_ERROR_INVALID_OPERATION;
2508 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2512 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2513 if (ret == PLAYER_ERROR_NONE)
2514 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2518 LOGD("LEAVE 0x%X", ret);
2522 int player_pause(player_h player)
2524 PLAYER_INSTANCE_CHECK(player);
2525 int ret = PLAYER_ERROR_NONE;
2526 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2527 player_cli_s *pc = (player_cli_s *) player;
2528 char *ret_buf = NULL;
2532 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2535 LOGD("LEAVE 0x%X", ret);
2539 int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data)
2541 PLAYER_INSTANCE_CHECK(player);
2542 PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2544 int ret = PLAYER_ERROR_NONE;
2545 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2546 player_cli_s *pc = (player_cli_s *) player;
2547 char *ret_buf = NULL;
2548 int pos = millisecond;
2552 LOGE("cb_info is null");
2553 return PLAYER_ERROR_INVALID_OPERATION;
2556 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2557 if ((pc->push_media_stream == FALSE) &&
2558 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2559 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2560 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2561 return PLAYER_ERROR_SEEK_FAILED;
2563 if (pc->push_media_stream == TRUE)
2564 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2566 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2567 LOGI("Event type : %d, pos : %d, accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond, accurate);
2568 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2569 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2571 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2573 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2574 MUSE_TYPE_INT, "pos", pos,
2575 MUSE_TYPE_INT, "accurate", (int)accurate);
2577 if (ret != PLAYER_ERROR_NONE) {
2578 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2579 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2580 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2583 if (pc->push_media_stream == TRUE)
2584 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2588 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2589 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2590 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2592 LOGD("LEAVE 0x%X", ret);
2596 int player_get_play_position(player_h player, int *millisecond)
2598 PLAYER_INSTANCE_CHECK(player);
2599 PLAYER_NULL_ARG_CHECK(millisecond);
2601 int ret = PLAYER_ERROR_NONE;
2602 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2603 player_cli_s *pc = (player_cli_s *) player;
2605 char *ret_buf = NULL;
2609 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2611 if (ret == PLAYER_ERROR_NONE) {
2612 player_msg_get(pos, ret_buf);
2620 int player_set_mute(player_h player, bool muted)
2622 PLAYER_INSTANCE_CHECK(player);
2623 int ret = PLAYER_ERROR_NONE;
2624 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2625 player_cli_s *pc = (player_cli_s *) player;
2626 char *ret_buf = NULL;
2627 int mute = (int)muted;
2631 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mute", mute);
2636 int player_is_muted(player_h player, bool * muted)
2638 PLAYER_INSTANCE_CHECK(player);
2639 PLAYER_NULL_ARG_CHECK(muted);
2640 int ret = PLAYER_ERROR_NONE;
2641 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2642 player_cli_s *pc = (player_cli_s *) player;
2643 char *ret_buf = NULL;
2648 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2649 if (ret == PLAYER_ERROR_NONE) {
2650 player_msg_get(mute, ret_buf);
2651 *muted = (bool) mute;
2658 int player_set_looping(player_h player, bool looping)
2660 PLAYER_INSTANCE_CHECK(player);
2661 int ret = PLAYER_ERROR_NONE;
2662 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2663 player_cli_s *pc = (player_cli_s *) player;
2664 char *ret_buf = NULL;
2668 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "looping", (int)looping);
2673 int player_is_looping(player_h player, bool * plooping)
2675 PLAYER_INSTANCE_CHECK(player);
2676 PLAYER_NULL_ARG_CHECK(plooping);
2677 int ret = PLAYER_ERROR_NONE;
2678 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2679 player_cli_s *pc = (player_cli_s *) player;
2680 char *ret_buf = NULL;
2685 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2686 if (ret == PLAYER_ERROR_NONE) {
2687 player_msg_get(looping, ret_buf);
2688 *plooping = looping;
2694 int player_get_duration(player_h player, int *pduration)
2696 PLAYER_INSTANCE_CHECK(player);
2697 PLAYER_NULL_ARG_CHECK(pduration);
2698 int ret = PLAYER_ERROR_NONE;
2699 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2700 player_cli_s *pc = (player_cli_s *) player;
2701 char *ret_buf = NULL;
2706 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2707 if (ret == PLAYER_ERROR_NONE) {
2708 player_msg_get(duration, ret_buf);
2709 *pduration = duration;
2716 /* The player_display_type_e is different at wearable profile */
2717 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2719 int ret = PLAYER_ERROR_NONE;
2720 PLAYER_NULL_ARG_CHECK(out_type);
2723 case PLAYER_DISPLAY_TYPE_OVERLAY:
2724 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2726 case PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE:
2727 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2728 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2730 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2732 case PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS:
2733 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2734 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2736 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2738 case PLAYER_DISPLAY_TYPE_EVAS:
2739 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2741 case PLAYER_DISPLAY_TYPE_NONE:
2742 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2745 ret = PLAYER_ERROR_INVALID_PARAMETER;
2749 LOGD("display type(%d) -> (%d)", type, *out_type);
2753 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2755 PLAYER_INSTANCE_CHECK(player);
2756 int ret = PLAYER_ERROR_NONE;
2757 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2758 player_cli_s *pc = (player_cli_s *) player;
2759 char *ret_buf = NULL;
2760 wl_win_msg_type wl_win;
2761 char *wl_win_msg = (char *)&wl_win;
2762 unsigned int wl_surface_id;
2763 player_private_display_type_e conv_type;
2764 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
2765 int arr_msg_len = 0;
2766 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2767 int (*p_disp_destroy_evas_display)(void **) = NULL;
2768 int (*p_disp_create_evas_display)(void *, void **) = NULL;
2769 int (*p_disp_set_evas_display_old_info)(void *, void *, int, int, int) = NULL;
2770 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2771 void (*p_disp_get_evas_display_geometry_info)(void *, int *, int *, int *, int *) = NULL;
2772 void (*p_disp_media_packet_video_decode_cb)(media_packet_h, void *) = NULL;
2774 pid_t pid = getpid();
2775 pid_t tid = syscall(SYS_gettid);
2779 LOGD("Check if API is called in main thread. pid [%d], tid [%d]", pid, tid);
2781 LOGE("API isn't called in main thread");
2782 return PLAYER_ERROR_INVALID_OPERATION;
2785 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2788 wl_win.wl_window_x = 0;
2789 wl_win.wl_window_y = 0;
2790 wl_win.wl_window_width = 0;
2791 wl_win.wl_window_height = 0;
2793 LOGD("ENTER type: %d", type);
2794 if (type == PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE ||
2795 type == PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS) {
2796 LOGW("DEPRECATION WARNING: display type(%d) is deprecated and will be removed from next release. Use newly defined type value instead.", type);
2799 /* before setting display, player state have to be checked. */
2800 PLAYER_STATE_CHECK(pc, PLAYER_STATE_IDLE);
2802 ret = _player_convert_display_type(type, &conv_type);
2803 if (ret != PLAYER_ERROR_NONE)
2806 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2808 return PLAYER_ERROR_INVALID_PARAMETER;
2810 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2812 * To support repeating play and stop, Evas_handle should not be destroyed in player_unprepare.
2813 * When the display type changes, Player need to destroy Evas_handle to set values of video output,
2814 * Otherwise, the values is not set because of checking Evas_handle.
2816 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
2817 LOGW("evas client already exists");
2818 player_unset_media_packet_video_frame_decoded_cb(player);
2819 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_destroy_evas_display, "disp_destroy_evas_display");
2820 if (p_disp_destroy_evas_display(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2821 LOGW("fail to unset evas client");
2822 __player_unset_retrieve_buffer_cb(player);
2823 /* need to set display information again to new handle */
2824 EVAS_INFO(pc)->update_needed = TRUE;
2827 /* set evas_render or wayland */
2828 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
2829 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
2830 wl_surface_id = p_disp_set_wl_display(ELM_WAYLAND_WIN, display);
2831 if (wl_surface_id > 0) {
2832 wl_win.wl_surface_id = wl_surface_id;
2833 wl_win.type = conv_type;
2834 } else return PLAYER_ERROR_INVALID_OPERATION;
2836 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2837 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS) {
2838 if (!CALLBACK_INFO(pc)) {
2839 LOGE("there is no cb info in player handle");
2840 return PLAYER_ERROR_INVALID_OPERATION;
2843 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_create_evas_display, "disp_create_evas_display");
2844 ret = p_disp_create_evas_display(display, &EVAS_HANDLE(pc));
2845 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2847 /* before evas handle is created, user could set display information */
2848 if (EVAS_INFO(pc)->update_needed) {
2849 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_old_info, "disp_set_evas_display_old_info");
2850 ret = p_disp_set_evas_display_old_info(display, EVAS_HANDLE(pc), EVAS_INFO(pc)->mode, EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2851 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2852 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2853 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2854 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);
2855 if (ret != MM_ERROR_NONE) return PLAYER_ERROR_INVALID_OPERATION;
2857 EVAS_INFO(pc)->update_needed = FALSE;
2859 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_geometry_info, "disp_get_evas_display_geometry_info");
2860 p_disp_get_evas_display_geometry_info(display, &wl_win.wl_window_x, &wl_win.wl_window_y, &wl_win.wl_window_width, &wl_win.wl_window_height);
2861 wl_win.type = conv_type;
2863 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_media_packet_video_decode_cb, "disp_media_packet_video_decode_cb");
2864 ret = player_set_media_packet_video_frame_decoded_cb(player, p_disp_media_packet_video_decode_cb, (void *)EVAS_HANDLE(pc));
2865 if (ret != PLAYER_ERROR_NONE)
2866 LOGW("fail to set decoded callback");
2867 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2868 LOGW("fail to set __retrieve_buffer_cb");
2871 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2872 LOGI("Wayland surface type is NONE");
2873 wl_win.type = conv_type;
2876 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
2877 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2878 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
2884 int player_set_display_mode(player_h player, player_display_mode_e mode)
2886 PLAYER_INSTANCE_CHECK(player);
2887 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2888 int ret = PLAYER_ERROR_NONE;
2889 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
2890 player_cli_s *pc = (player_cli_s *) player;
2891 char *ret_buf = NULL;
2892 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2893 int (*p_disp_set_evas_display_disp_mode)(void *, int) = NULL;
2896 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2898 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2899 if (EVAS_HANDLE(pc)) {
2900 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_disp_mode, "disp_set_evas_display_disp_mode");
2901 ret = p_disp_set_evas_display_disp_mode(EVAS_HANDLE(pc), mode);
2902 if (ret != MM_ERROR_NONE)
2903 return PLAYER_ERROR_INVALID_OPERATION;
2905 return PLAYER_ERROR_NONE;
2907 EVAS_INFO(pc)->mode = mode;
2908 EVAS_INFO(pc)->update_needed = TRUE;
2911 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "mode", (int)mode);
2916 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
2918 PLAYER_INSTANCE_CHECK(player);
2919 PLAYER_NULL_ARG_CHECK(pmode);
2920 int ret = PLAYER_ERROR_NONE;
2921 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
2922 player_cli_s *pc = (player_cli_s *) player;
2923 char *ret_buf = NULL;
2925 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2926 int (*p_disp_get_evas_display_disp_mode)(void *, int *) = NULL;
2930 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2932 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2933 if (EVAS_HANDLE(pc)) {
2934 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_disp_mode, "disp_get_evas_display_disp_mode");
2935 ret = p_disp_get_evas_display_disp_mode(EVAS_HANDLE(pc), &mode);
2936 *pmode = (player_display_mode_e) mode;
2937 if (ret != MM_ERROR_NONE)
2938 return PLAYER_ERROR_INVALID_OPERATION;
2940 return PLAYER_ERROR_NONE;
2943 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
2944 if (ret == PLAYER_ERROR_NONE) {
2945 player_msg_get_type(mode, ret_buf, INT);
2954 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
2956 PLAYER_INSTANCE_CHECK(player);
2957 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2959 int ret = PLAYER_ERROR_NONE;
2960 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
2961 player_cli_s *pc = (player_cli_s *) player;
2962 char *ret_buf = NULL;
2963 wl_win_msg_type wl_win;
2964 char *wl_win_msg = (char *)&wl_win;
2965 int arr_msg_len = 0;
2966 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2967 int (*p_disp_set_evas_display_roi_area)(void *, int, int, int, int) = NULL;
2971 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2973 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2974 if (EVAS_HANDLE(pc)) {
2975 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_roi_area, "disp_set_evas_display_roi_area");
2976 ret = p_disp_set_evas_display_roi_area(EVAS_HANDLE(pc), x, y, width, height);
2977 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
2978 return PLAYER_ERROR_INVALID_PARAMETER;
2979 else if (ret != MM_ERROR_NONE)
2980 return PLAYER_ERROR_INVALID_OPERATION;
2982 return PLAYER_ERROR_NONE;
2984 EVAS_INFO(pc)->roi_x = x;
2985 EVAS_INFO(pc)->roi_y = y;
2986 EVAS_INFO(pc)->roi_w = width;
2987 EVAS_INFO(pc)->roi_h = height;
2988 EVAS_INFO(pc)->update_needed = TRUE;
2991 wl_win.wl_window_x = x;
2992 wl_win.wl_window_y = y;
2993 wl_win.wl_window_width = width;
2994 wl_win.wl_window_height = height;
2996 arr_msg_len = (sizeof(wl_win_msg_type)/sizeof(int) + (sizeof(wl_win_msg_type)%sizeof(int) ? 1 : 0));
2997 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
2998 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
3004 int player_set_playback_rate(player_h player, float rate)
3006 PLAYER_INSTANCE_CHECK(player);
3007 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3008 int ret = PLAYER_ERROR_NONE;
3009 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
3010 player_cli_s *pc = (player_cli_s *) player;
3011 char *ret_buf = NULL;
3015 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", (double)rate);
3018 LOGD("LEAVE 0x%X", ret);
3022 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
3024 PLAYER_INSTANCE_CHECK(player);
3025 int ret = PLAYER_ERROR_NONE;
3026 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
3027 player_cli_s *pc = (player_cli_s *) player;
3028 char *ret_buf = NULL;
3029 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3030 int (*p_disp_set_evas_display_rotation)(void *, int) = NULL;
3034 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3036 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3037 if (EVAS_HANDLE(pc)) {
3038 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_rotation, "disp_set_evas_display_rotation");
3039 ret = p_disp_set_evas_display_rotation(EVAS_HANDLE(pc), rotation);
3040 if (ret != MM_ERROR_NONE)
3041 return PLAYER_ERROR_INVALID_OPERATION;
3043 return PLAYER_ERROR_NONE;
3045 EVAS_INFO(pc)->rotation = rotation;
3046 EVAS_INFO(pc)->update_needed = TRUE;
3049 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "rotation", (int)rotation);
3054 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
3056 PLAYER_INSTANCE_CHECK(player);
3057 PLAYER_NULL_ARG_CHECK(protation);
3058 int ret = PLAYER_ERROR_NONE;
3059 player_cli_s *pc = (player_cli_s *) player;
3060 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
3061 char *ret_buf = NULL;
3063 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3064 int (*p_disp_get_evas_display_rotation)(void *, int *) = NULL;
3068 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3070 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3071 if (EVAS_HANDLE(pc)) {
3072 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_rotation, "disp_get_evas_display_rotation");
3073 ret = p_disp_get_evas_display_rotation(EVAS_HANDLE(pc), &rotation);
3074 *protation = (player_display_rotation_e) rotation;
3075 if (ret != MM_ERROR_NONE)
3076 return PLAYER_ERROR_INVALID_OPERATION;
3078 return PLAYER_ERROR_NONE;
3081 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3082 if (ret == PLAYER_ERROR_NONE) {
3083 player_msg_get_type(rotation, ret_buf, INT);
3084 *protation = rotation;
3091 int player_set_display_visible(player_h player, bool visible)
3093 PLAYER_INSTANCE_CHECK(player);
3094 int ret = PLAYER_ERROR_NONE;
3095 player_cli_s *pc = (player_cli_s *) player;
3096 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
3097 char *ret_buf = NULL;
3098 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3099 int (*p_disp_set_evas_display_visible)(void *, bool) = NULL;
3103 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3105 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3106 if (EVAS_HANDLE(pc)) {
3107 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_evas_display_visible, "disp_set_evas_display_visible");
3108 ret = p_disp_set_evas_display_visible(EVAS_HANDLE(pc), visible);
3109 if (ret != MM_ERROR_NONE)
3110 return PLAYER_ERROR_INVALID_OPERATION;
3112 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3113 return PLAYER_ERROR_NONE;
3115 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
3116 EVAS_INFO(pc)->update_needed = TRUE;
3120 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "visible", (int)visible);
3125 int player_is_display_visible(player_h player, bool * pvisible)
3127 PLAYER_INSTANCE_CHECK(player);
3128 PLAYER_NULL_ARG_CHECK(pvisible);
3129 int ret = PLAYER_ERROR_NONE;
3130 player_cli_s *pc = (player_cli_s *) player;
3131 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
3132 char *ret_buf = NULL;
3134 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3136 int (*p_disp_get_evas_display_visible)(void *, bool *) = NULL;
3140 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
3142 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3143 if (EVAS_HANDLE(pc)) {
3144 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_get_evas_display_visible, "disp_get_evas_display_visible");
3145 ret = p_disp_get_evas_display_visible(EVAS_HANDLE(pc), &visible);
3151 if (ret != MM_ERROR_NONE)
3152 return PLAYER_ERROR_INVALID_OPERATION;
3154 return PLAYER_ERROR_NONE;
3157 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3158 if (ret == PLAYER_ERROR_NONE) {
3159 player_msg_get_type(value, ret_buf, INT);
3171 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3173 PLAYER_INSTANCE_CHECK(player);
3174 PLAYER_NULL_ARG_CHECK(pvalue);
3175 int ret = PLAYER_ERROR_NONE;
3176 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3177 player_cli_s *pc = (player_cli_s *) player;
3178 char *ret_buf = NULL;
3179 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3183 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "key", (int)key);
3184 if (ret == PLAYER_ERROR_NONE) {
3185 player_msg_get_string(value, ret_buf);
3186 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3192 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3194 PLAYER_INSTANCE_CHECK(player);
3195 PLAYER_NULL_ARG_CHECK(paudio_codec || pvideo_codec);
3196 int ret = PLAYER_ERROR_NONE;
3197 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3198 player_cli_s *pc = (player_cli_s *) player;
3199 char *ret_buf = NULL;
3200 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3201 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3202 bool ret_val = TRUE;
3206 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3207 if (ret == PLAYER_ERROR_NONE) {
3208 ret_val = _player_get_param_value(ret_buf,
3209 MUSE_TYPE_STRING, "video_codec", (void *)video_codec,
3210 MUSE_TYPE_STRING, "audio_codec", (void *)audio_codec,
3211 INVALID_MUSE_TYPE_VALUE);
3214 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3216 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3218 ret = PLAYER_ERROR_INVALID_OPERATION;
3225 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3227 PLAYER_INSTANCE_CHECK(player);
3228 PLAYER_NULL_ARG_CHECK(psample_rate || pchannel || pbit_rate);
3229 int ret = PLAYER_ERROR_NONE;
3230 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3231 player_cli_s *pc = (player_cli_s *) player;
3232 char *ret_buf = NULL;
3233 int sample_rate = 0;
3239 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3240 if (ret == PLAYER_ERROR_NONE) {
3241 bool ret_val = true;
3242 ret_val = _player_get_param_value(ret_buf,
3243 MUSE_TYPE_INT, "sample_rate", (void *)&sample_rate,
3244 MUSE_TYPE_INT, "channel", (void *)&channel,
3245 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3246 INVALID_MUSE_TYPE_VALUE);
3249 *psample_rate = sample_rate;
3251 *pchannel = channel;
3253 *pbit_rate = bit_rate;
3255 ret = PLAYER_ERROR_INVALID_OPERATION;
3262 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3264 PLAYER_INSTANCE_CHECK(player);
3265 PLAYER_NULL_ARG_CHECK(pfps || pbit_rate);
3266 int ret = PLAYER_ERROR_NONE;
3267 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3268 player_cli_s *pc = (player_cli_s *) player;
3269 char *ret_buf = NULL;
3275 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3276 if (ret == PLAYER_ERROR_NONE) {
3277 bool ret_val = true;
3278 ret_val = _player_get_param_value(ret_buf,
3279 MUSE_TYPE_INT, "fps", (void *)&fps,
3280 MUSE_TYPE_INT, "bit_rate", (void *)&bit_rate,
3281 INVALID_MUSE_TYPE_VALUE);
3286 *pbit_rate = bit_rate;
3288 ret = PLAYER_ERROR_INVALID_OPERATION;
3295 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3297 PLAYER_INSTANCE_CHECK(player);
3298 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3299 int ret = PLAYER_ERROR_NONE;
3300 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3301 player_cli_s *pc = (player_cli_s *) player;
3302 char *ret_buf = NULL;
3308 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3309 if (ret == PLAYER_ERROR_NONE) {
3310 bool ret_val = true;
3311 ret_val = _player_get_param_value(ret_buf,
3312 MUSE_TYPE_INT, "width", (void *)&width,
3313 MUSE_TYPE_INT, "height", (void *)&height,
3314 INVALID_MUSE_TYPE_VALUE);
3319 ret = PLAYER_ERROR_INVALID_OPERATION;
3326 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3328 PLAYER_INSTANCE_CHECK(player);
3329 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3330 int ret = PLAYER_ERROR_NONE;
3331 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3332 player_cli_s *pc = (player_cli_s *) player;
3333 char *ret_buf = NULL;
3337 tbm_bo_handle thandle;
3338 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3339 int key = INVALID_DEFAULT_VALUE;
3344 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3345 if (ret == PLAYER_ERROR_NONE) {
3346 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3347 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3349 LOGE("failed to get msg obj, err:%d", err);
3350 ret = PLAYER_ERROR_INVALID_OPERATION;
3354 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3355 LOGD("size : %d", size);
3356 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3357 LOGE("failed to get key value");
3358 ret = PLAYER_ERROR_INVALID_OPERATION;
3362 tfd = pc->cb_info->tfd;
3364 LOGE("failed to get tbm fd value");
3365 ret = PLAYER_ERROR_INVALID_OPERATION;
3369 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3371 LOGE("TBM get error : bo is NULL");
3372 ret = PLAYER_ERROR_INVALID_OPERATION;
3375 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3376 if (thandle.ptr == NULL) {
3377 LOGE("TBM get error : handle pointer is NULL");
3378 ret = PLAYER_ERROR_INVALID_OPERATION;
3381 album_art = _get_mem(pc, size);
3383 memcpy(album_art, thandle.ptr, size);
3384 *palbum_art = album_art;
3386 LOGE("g_new failure");
3387 ret = PLAYER_ERROR_INVALID_OPERATION;
3399 muse_core_msg_object_free(jobj);
3404 if (tfd > INVALID_DEFAULT_VALUE)
3407 if (CALLBACK_INFO(pc))
3408 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3414 if (key > INVALID_DEFAULT_VALUE && CALLBACK_INFO(pc)) {
3415 LOGD("send msg to release buffer. key:%d", key);
3416 PLAYER_SEND_MSG_ASYNC(MUSE_PLAYER_API_RETURN_BUFFER, MSG_FD(pc), ret, MUSE_TYPE_INT, "key", key);
3422 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3424 PLAYER_INSTANCE_CHECK(player);
3425 PLAYER_NULL_ARG_CHECK(pcount);
3426 int ret = PLAYER_ERROR_NONE;
3427 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3428 player_cli_s *pc = (player_cli_s *) player;
3429 char *ret_buf = NULL;
3434 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3435 if (ret == PLAYER_ERROR_NONE) {
3436 player_msg_get(count, ret_buf);
3443 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3445 PLAYER_INSTANCE_CHECK(player);
3446 PLAYER_NULL_ARG_CHECK(band_levels);
3447 int ret = PLAYER_ERROR_NONE;
3448 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3449 player_cli_s *pc = (player_cli_s *) player;
3450 char *ret_buf = NULL;
3454 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3455 MUSE_TYPE_INT, "length", length,
3456 MUSE_TYPE_ARRAY, "band_levels", length, band_levels);
3463 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3465 PLAYER_INSTANCE_CHECK(player);
3466 int ret = PLAYER_ERROR_NONE;
3467 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3468 player_cli_s *pc = (player_cli_s *) player;
3469 char *ret_buf = NULL;
3473 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3474 MUSE_TYPE_INT, "index", index,
3475 MUSE_TYPE_INT, "level", level);
3481 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3483 PLAYER_INSTANCE_CHECK(player);
3484 PLAYER_NULL_ARG_CHECK(plevel);
3485 int ret = PLAYER_ERROR_NONE;
3486 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3487 player_cli_s *pc = (player_cli_s *) player;
3488 char *ret_buf = NULL;
3493 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3494 if (ret == PLAYER_ERROR_NONE) {
3495 player_msg_get(level, ret_buf);
3502 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3504 PLAYER_INSTANCE_CHECK(player);
3505 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3506 int ret = PLAYER_ERROR_NONE;
3507 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3508 player_cli_s *pc = (player_cli_s *) player;
3509 char *ret_buf = NULL;
3510 int min = 0, max = 0;
3514 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3515 if (ret == PLAYER_ERROR_NONE) {
3516 bool ret_val = true;
3517 ret_val = _player_get_param_value(ret_buf,
3518 MUSE_TYPE_INT, "min", (void *)&min,
3519 MUSE_TYPE_INT, "max", (void *)&max,
3520 INVALID_MUSE_TYPE_VALUE);
3525 ret = PLAYER_ERROR_INVALID_OPERATION;
3532 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3534 PLAYER_INSTANCE_CHECK(player);
3535 PLAYER_NULL_ARG_CHECK(pfrequency);
3536 int ret = PLAYER_ERROR_NONE;
3537 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3538 player_cli_s *pc = (player_cli_s *) player;
3539 char *ret_buf = NULL;
3544 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3545 if (ret == PLAYER_ERROR_NONE) {
3546 player_msg_get(frequency, ret_buf);
3547 *pfrequency = frequency;
3553 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3555 PLAYER_INSTANCE_CHECK(player);
3556 PLAYER_NULL_ARG_CHECK(prange);
3557 int ret = PLAYER_ERROR_NONE;
3558 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3559 player_cli_s *pc = (player_cli_s *) player;
3560 char *ret_buf = NULL;
3565 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "index", index);
3566 if (ret == PLAYER_ERROR_NONE) {
3567 player_msg_get(range, ret_buf);
3574 int player_audio_effect_equalizer_clear(player_h player)
3576 PLAYER_INSTANCE_CHECK(player);
3577 int ret = PLAYER_ERROR_NONE;
3578 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3579 player_cli_s *pc = (player_cli_s *) player;
3580 char *ret_buf = NULL;
3584 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3589 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3591 PLAYER_INSTANCE_CHECK(player);
3592 PLAYER_NULL_ARG_CHECK(pavailable);
3593 int ret = PLAYER_ERROR_NONE;
3594 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3595 player_cli_s *pc = (player_cli_s *) player;
3596 char *ret_buf = NULL;
3601 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3602 if (ret == PLAYER_ERROR_NONE) {
3603 player_msg_get(available, ret_buf);
3604 *pavailable = available;
3610 int player_set_subtitle_path(player_h player, const char *path)
3612 PLAYER_INSTANCE_CHECK(player);
3613 int ret = PLAYER_ERROR_NONE;
3614 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3615 player_cli_s *pc = (player_cli_s *) player;
3616 char *ret_buf = NULL;
3617 char subtitle_path[MAX_URL_LEN] = {0, };
3621 if (path && _player_get_valid_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3622 return PLAYER_ERROR_INVALID_PARAMETER;
3624 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "subtitle_path", (const char*)subtitle_path);
3629 int player_set_subtitle_position_offset(player_h player, int millisecond)
3631 PLAYER_INSTANCE_CHECK(player);
3632 int ret = PLAYER_ERROR_NONE;
3633 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3634 player_cli_s *pc = (player_cli_s *) player;
3635 char *ret_buf = NULL;
3639 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "millisecond", millisecond);
3645 int player_set_progressive_download_path(player_h player, const char *path)
3647 PLAYER_INSTANCE_CHECK(player);
3648 PLAYER_NULL_ARG_CHECK(path);
3649 int ret = PLAYER_ERROR_NONE;
3650 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
3651 player_cli_s *pc = (player_cli_s *) player;
3652 char *ret_buf = NULL;
3653 char dw_path[MAX_URL_LEN] = {0, };
3656 LOGW("DEPRECATION WARNING: player_set_progressive_download_path() is deprecated and will be removed from next release.");
3658 if (!_player_check_network_availability())
3659 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3661 if (_player_get_valid_path(path, dw_path) != PLAYER_ERROR_NONE)
3662 return PLAYER_ERROR_INVALID_PARAMETER;
3664 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "dw_path", (const char*)dw_path);
3669 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
3671 PLAYER_INSTANCE_CHECK(player);
3672 PLAYER_NULL_ARG_CHECK(pcurrent && ptotal_size);
3673 int ret = PLAYER_ERROR_NONE;
3674 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
3675 player_cli_s *pc = (player_cli_s *) player;
3676 char *ret_buf = NULL;
3677 unsigned long current, total_size;
3680 LOGW("DEPRECATION WARNING: player_get_progressive_download_status() is deprecated and will be removed from next release.");
3682 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3683 if (ret == PLAYER_ERROR_NONE) {
3684 bool ret_val = true;
3685 ret_val = _player_get_param_value(ret_buf,
3686 MUSE_TYPE_POINTER, "current", (void *)¤t,
3687 MUSE_TYPE_POINTER, "total_size", (void *)&total_size,
3688 INVALID_MUSE_TYPE_VALUE);
3690 *pcurrent = current;
3691 *ptotal_size = total_size;
3693 ret = PLAYER_ERROR_INVALID_OPERATION;
3701 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3703 PLAYER_INSTANCE_CHECK(player);
3704 PLAYER_NULL_ARG_CHECK(callback);
3705 int ret = PLAYER_ERROR_NONE;
3706 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3707 player_cli_s *pc = (player_cli_s *) player;
3708 char *ret_buf = NULL;
3711 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3712 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3713 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3715 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3716 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3717 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3720 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3722 if (ret != PLAYER_ERROR_NONE)
3723 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3729 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3731 PLAYER_INSTANCE_CHECK(player);
3732 PLAYER_NULL_ARG_CHECK(cookie);
3733 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3734 int ret = PLAYER_ERROR_NONE;
3735 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3736 player_cli_s *pc = (player_cli_s *) player;
3737 char *ret_buf = NULL;
3741 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3742 MUSE_TYPE_STRING, "cookie", cookie,
3743 MUSE_TYPE_INT, "size", size);
3748 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3750 PLAYER_INSTANCE_CHECK(player);
3751 PLAYER_NULL_ARG_CHECK(user_agent);
3752 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3753 int ret = PLAYER_ERROR_NONE;
3754 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3755 player_cli_s *pc = (player_cli_s *) player;
3756 char *ret_buf = NULL;
3760 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3761 MUSE_TYPE_STRING, "user_agent", user_agent,
3762 MUSE_TYPE_INT, "size", size);
3767 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3769 PLAYER_INSTANCE_CHECK(player);
3770 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3771 int ret = PLAYER_ERROR_NONE;
3772 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3773 player_cli_s *pc = (player_cli_s *) player;
3774 char *ret_buf = NULL;
3775 int start = 0, current = 0;
3779 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
3780 if (ret == PLAYER_ERROR_NONE) {
3781 bool ret_val = true;
3782 ret_val = _player_get_param_value(ret_buf,
3783 MUSE_TYPE_INT, "start", (void *)&start,
3784 MUSE_TYPE_INT, "current", (void *)¤t,
3785 INVALID_MUSE_TYPE_VALUE);
3788 *pcurrent = current;
3790 ret = PLAYER_ERROR_INVALID_OPERATION;
3798 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3800 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3803 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3804 static void __retrieve_buffer_cb(void *user_data)
3806 player_cli_s *player = (player_cli_s *)user_data;
3807 int ret = PLAYER_ERROR_NONE;
3808 bool gapless = false;
3809 int (*p_disp_evas_display_retrieve_all_packets)(void *, bool) = NULL;
3811 ret = player_is_gapless((player_h)user_data, &gapless);
3812 if (ret != PLAYER_ERROR_NONE) {
3813 LOGW("player_is_gapless is failed");
3817 PLAYER_DISP_DLSYM(player->dl_handle, p_disp_evas_display_retrieve_all_packets, "disp_evas_display_retrieve_all_packets");
3818 ret = p_disp_evas_display_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3819 if (ret != PLAYER_ERROR_NONE)
3820 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3823 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3825 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3828 static int __player_unset_retrieve_buffer_cb(player_h player)
3830 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3834 int player_unset_completed_cb(player_h player)
3836 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3839 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3841 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3844 int player_unset_interrupted_cb(player_h player)
3846 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3849 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3851 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3854 int player_unset_error_cb(player_h player)
3856 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3859 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3861 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3864 int player_unset_buffering_cb(player_h player)
3866 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3869 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3871 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3874 int player_unset_subtitle_updated_cb(player_h player)
3876 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3879 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3881 PLAYER_INSTANCE_CHECK(player);
3882 PLAYER_NULL_ARG_CHECK(callback);
3883 int ret = PLAYER_ERROR_NONE;
3884 player_cli_s *pc = (player_cli_s *) player;
3885 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3886 char *ret_buf = NULL;
3887 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3891 LOGW("DEPRECATION WARNING: player_set_progressive_download_message_cb() is deprecated and will be removed from next release.");
3893 if (!_player_check_network_availability())
3894 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3896 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3897 MUSE_TYPE_INT, "type", type,
3898 MUSE_TYPE_INT, "set", set);
3900 if (ret == PLAYER_ERROR_NONE) {
3901 pc->cb_info->user_cb[type] = callback;
3902 pc->cb_info->user_data[type] = user_data;
3903 LOGI("Event type : %d ", type);
3910 int player_unset_progressive_download_message_cb(player_h player)
3912 PLAYER_INSTANCE_CHECK(player);
3913 int ret = PLAYER_ERROR_NONE;
3914 player_cli_s *pc = (player_cli_s *) player;
3915 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3916 char *ret_buf = NULL;
3917 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3921 LOGW("DEPRECATION WARNING: player_unset_progressive_download_message_cb() is deprecated and will be removed from next release.");
3923 set_null_user_cb_lock(pc->cb_info, type);
3925 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3926 MUSE_TYPE_INT, "type", type,
3927 MUSE_TYPE_INT, "set", set);
3934 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
3936 PLAYER_INSTANCE_CHECK(player);
3937 PLAYER_NULL_ARG_CHECK(callback);
3938 int ret = PLAYER_ERROR_NONE;
3939 player_cli_s *pc = (player_cli_s *) player;
3940 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3941 char *ret_buf = NULL;
3942 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3947 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3948 MUSE_TYPE_INT, "type", type,
3949 MUSE_TYPE_INT, "set", set);
3951 if (ret == PLAYER_ERROR_NONE) {
3952 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
3953 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
3954 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
3961 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
3963 PLAYER_INSTANCE_CHECK(player);
3964 int ret = PLAYER_ERROR_NONE;
3965 player_cli_s *pc = (player_cli_s *) player;
3966 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3967 char *ret_buf = NULL;
3968 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3973 set_null_user_cb_lock(pc->cb_info, type);
3975 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3976 MUSE_TYPE_INT, "type", type,
3977 MUSE_TYPE_INT, "set", set);
3983 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
3985 PLAYER_INSTANCE_CHECK(player);
3986 PLAYER_NULL_ARG_CHECK(callback);
3987 int ret = PLAYER_ERROR_NONE;
3988 player_cli_s *pc = (player_cli_s *) player;
3989 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3990 char *ret_buf = NULL;
3991 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3996 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
3997 MUSE_TYPE_INT, "type", type,
3998 MUSE_TYPE_INT, "set", set);
4000 if (ret == PLAYER_ERROR_NONE) {
4001 pc->cb_info->user_cb[type] = callback;
4002 pc->cb_info->user_data[type] = user_data;
4003 LOGI("Event type : %d ", type);
4010 int player_unset_video_stream_changed_cb(player_h player)
4012 PLAYER_INSTANCE_CHECK(player);
4013 int ret = PLAYER_ERROR_NONE;
4014 player_cli_s *pc = (player_cli_s *) player;
4015 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4016 char *ret_buf = NULL;
4017 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
4022 set_null_user_cb_lock(pc->cb_info, type);
4024 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4025 MUSE_TYPE_INT, "type", type,
4026 MUSE_TYPE_INT, "set", set);
4032 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)
4034 PLAYER_INSTANCE_CHECK(player);
4035 PLAYER_NULL_ARG_CHECK(callback);
4036 int ret = PLAYER_ERROR_NONE;
4037 player_cli_s *pc = (player_cli_s *) player;
4038 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4039 char *ret_buf = NULL;
4040 muse_player_event_e type;
4045 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4046 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4047 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4048 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4050 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4051 return PLAYER_ERROR_INVALID_PARAMETER;
4054 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4055 MUSE_TYPE_INT, "type", type,
4056 MUSE_TYPE_INT, "set", set);
4058 if (ret == PLAYER_ERROR_NONE) {
4059 pc->cb_info->user_cb[type] = callback;
4060 pc->cb_info->user_data[type] = user_data;
4061 LOGI("Event type : %d ", type);
4068 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
4070 PLAYER_INSTANCE_CHECK(player);
4071 int ret = PLAYER_ERROR_NONE;
4072 player_cli_s *pc = (player_cli_s *) player;
4073 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4074 char *ret_buf = NULL;
4075 muse_player_event_e type;
4080 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4081 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
4082 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4083 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
4085 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4086 return PLAYER_ERROR_INVALID_PARAMETER;
4089 set_null_user_cb_lock(pc->cb_info, type);
4091 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4092 MUSE_TYPE_INT, "type", type,
4093 MUSE_TYPE_INT, "set", set);
4099 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)
4101 PLAYER_INSTANCE_CHECK(player);
4102 PLAYER_NULL_ARG_CHECK(callback);
4103 int ret = PLAYER_ERROR_NONE;
4104 player_cli_s *pc = (player_cli_s *) player;
4105 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4106 char *ret_buf = NULL;
4107 muse_player_event_e type;
4112 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4113 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4114 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4115 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4117 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4118 return PLAYER_ERROR_INVALID_PARAMETER;
4121 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4122 MUSE_TYPE_INT, "type", type,
4123 MUSE_TYPE_INT, "set", set);
4125 if (ret == PLAYER_ERROR_NONE) {
4126 pc->cb_info->user_cb[type] = callback;
4127 pc->cb_info->user_data[type] = user_data;
4128 LOGI("Event type : %d ", type);
4135 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
4137 PLAYER_INSTANCE_CHECK(player);
4138 int ret = PLAYER_ERROR_NONE;
4139 player_cli_s *pc = (player_cli_s *) player;
4140 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
4141 char *ret_buf = NULL;
4142 muse_player_event_e type;
4147 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
4148 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
4149 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
4150 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
4152 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
4153 return PLAYER_ERROR_INVALID_PARAMETER;
4156 set_null_user_cb_lock(pc->cb_info, type);
4158 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4159 MUSE_TYPE_INT, "type", type,
4160 MUSE_TYPE_INT, "set", set);
4166 /* TODO Implement raw data socket channel */
4167 int player_push_media_stream(player_h player, media_packet_h packet)
4169 PLAYER_INSTANCE_CHECK(player);
4170 PLAYER_NULL_ARG_CHECK(packet);
4171 int ret = PLAYER_ERROR_NONE;
4172 player_cli_s *pc = (player_cli_s *) player;
4173 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
4174 char *ret_buf = NULL;
4175 player_push_media_msg_type push_media;
4176 char *push_media_msg = (char *)&push_media;
4177 int msg_size = sizeof(player_push_media_msg_type);
4181 tbm_bo_handle thandle;
4182 tbm_fd tfd = INVALID_DEFAULT_VALUE;
4185 media_format_h format;
4189 int arr_msg_len = 0;
4193 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
4194 media_packet_get_buffer_size(packet, &push_media.size);
4195 media_packet_get_pts(packet, &push_media.pts);
4196 media_packet_get_format(packet, &format);
4197 media_packet_get_flags(packet, &push_media.flags);
4199 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
4201 media_packet_is_video(packet, &is_video);
4202 media_packet_is_audio(packet, &is_audio);
4203 media_packet_is_end_of_stream(packet, &is_eos);
4205 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
4207 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
4209 media_format_unref(format);
4212 int arr_buf_len = 0;
4214 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
4215 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
4217 LOGE("TBM get error : bo is NULL");
4218 return PLAYER_ERROR_INVALID_OPERATION;
4220 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4221 if (thandle.ptr == NULL) {
4222 LOGE("TBM get error : handle pointer is NULL");
4223 ret = PLAYER_ERROR_INVALID_OPERATION;
4226 memcpy(thandle.ptr, buf, push_media.size);
4229 tfd = tbm_bo_export_fd(bo);
4231 LOGE("tbm_bo_export_fd err 0x%x", tfd);
4232 ret = PLAYER_ERROR_INVALID_OPERATION;
4236 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4237 PLAYER_SEND_MSG_WITH_TFD(api, pc, tfd, ret_buf, ret,
4238 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int *)push_media_msg);
4240 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4241 buf_size = (int)push_media.size;
4243 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4244 arr_buf_len = (buf_size / sizeof(int) + (buf_size % sizeof(int) ? 1 : 0));
4245 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4246 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg,
4247 MUSE_TYPE_ARRAY, "buf", arr_buf_len, (int*)buf);
4251 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4252 buf_size = (int)push_media.size;
4253 if ((muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts) < 0) && (!is_eos)) {
4254 LOGE("failed to send data");
4255 return PLAYER_ERROR_INVALID_OPERATION;
4258 arr_msg_len = (msg_size / sizeof(int) + (msg_size % sizeof(int) ? 1 : 0));
4259 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4260 MUSE_TYPE_ARRAY, "push_media_msg", arr_msg_len, (int*)push_media_msg);
4263 LOGD("ret_buf %s", ret_buf);
4267 if (tfd > INVALID_DEFAULT_VALUE)
4270 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4278 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4280 PLAYER_INSTANCE_CHECK(player);
4281 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4282 int ret = PLAYER_ERROR_NONE;
4283 player_cli_s *pc = (player_cli_s *) player;
4284 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4285 char *ret_buf = NULL;
4286 media_format_mimetype_e mimetype;
4298 media_format_ref(format);
4299 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4300 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4301 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4302 LOGE("failed to get video info from format.");
4303 return PLAYER_ERROR_INVALID_PARAMETER;
4306 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4307 MUSE_TYPE_INT, "type", type,
4308 MUSE_TYPE_INT, "mimetype", mimetype,
4309 MUSE_TYPE_INT, "width", width,
4310 MUSE_TYPE_INT, "height", height,
4311 MUSE_TYPE_INT, "avg_bps", avg_bps,
4312 MUSE_TYPE_INT, "max_bps", max_bps,
4313 MUSE_TYPE_INT, "frame_rate", frame_rate);
4315 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4316 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4317 LOGE("failed to get audio info from format.");
4318 return PLAYER_ERROR_INVALID_PARAMETER;
4321 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4322 MUSE_TYPE_INT, "type", type,
4323 MUSE_TYPE_INT, "mimetype", mimetype,
4324 MUSE_TYPE_INT, "channel", channel,
4325 MUSE_TYPE_INT, "samplerate", samplerate,
4326 MUSE_TYPE_INT, "avg_bps", avg_bps,
4327 MUSE_TYPE_INT, "bit", bit);
4330 media_format_unref(format);
4331 pc->push_media_stream = TRUE;
4337 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4339 int ret = PLAYER_ERROR_NONE;
4340 PLAYER_INSTANCE_CHECK(player);
4341 player_cli_s *pc = (player_cli_s *) player;
4342 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4343 char *ret_buf = NULL;
4347 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4348 MUSE_TYPE_INT, "type", type,
4349 MUSE_TYPE_INT64, "max_size", (INT64)max_size);
4355 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4357 int ret = PLAYER_ERROR_NONE;
4358 PLAYER_INSTANCE_CHECK(player);
4359 PLAYER_NULL_ARG_CHECK(pmax_size);
4360 player_cli_s *pc = (player_cli_s *) player;
4361 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4362 char *ret_buf = NULL;
4363 unsigned long long max_size;
4367 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4368 if (ret == PLAYER_ERROR_NONE) {
4369 player_msg_get_type(max_size, ret_buf, INT64);
4370 *pmax_size = max_size;
4376 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4378 int ret = PLAYER_ERROR_NONE;
4379 PLAYER_INSTANCE_CHECK(player);
4380 player_cli_s *pc = (player_cli_s *) player;
4381 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4382 char *ret_buf = NULL;
4386 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4387 MUSE_TYPE_INT, "type", type,
4388 MUSE_TYPE_INT, "percent", (int)percent);
4394 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4396 int ret = PLAYER_ERROR_NONE;
4397 PLAYER_INSTANCE_CHECK(player);
4398 PLAYER_NULL_ARG_CHECK(ppercent);
4399 player_cli_s *pc = (player_cli_s *) player;
4400 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4401 char *ret_buf = NULL;
4406 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4407 if (ret == PLAYER_ERROR_NONE) {
4408 player_msg_get(percent, ret_buf);
4409 *ppercent = percent;
4416 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4418 PLAYER_INSTANCE_CHECK(player);
4419 PLAYER_NULL_ARG_CHECK(pcount);
4420 int ret = PLAYER_ERROR_NONE;
4421 player_cli_s *pc = (player_cli_s *) player;
4422 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4423 char *ret_buf = NULL;
4428 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4429 if (ret == PLAYER_ERROR_NONE) {
4430 player_msg_get(count, ret_buf);
4438 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4440 PLAYER_INSTANCE_CHECK(player);
4441 PLAYER_NULL_ARG_CHECK(pindex);
4442 int ret = PLAYER_ERROR_NONE;
4443 player_cli_s *pc = (player_cli_s *) player;
4444 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4445 char *ret_buf = NULL;
4450 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type);
4451 if (ret == PLAYER_ERROR_NONE) {
4452 player_msg_get(index, ret_buf);
4460 int player_select_track(player_h player, player_stream_type_e type, int index)
4462 PLAYER_INSTANCE_CHECK(player);
4463 int ret = PLAYER_ERROR_NONE;
4464 player_cli_s *pc = (player_cli_s *) player;
4465 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4466 char *ret_buf = NULL;
4470 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4476 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4478 PLAYER_INSTANCE_CHECK(player);
4479 PLAYER_NULL_ARG_CHECK(pcode);
4480 int ret = PLAYER_ERROR_NONE;
4481 player_cli_s *pc = (player_cli_s *) player;
4482 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4483 char *ret_buf = NULL;
4484 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4489 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "index", index);
4490 if (ret == PLAYER_ERROR_NONE) {
4491 bool recv_ret = true;
4492 recv_ret = _player_get_param_value(ret_buf,
4493 MUSE_TYPE_INT, "code_len", (void *)&code_len,
4494 MUSE_TYPE_STRING, "code", (void *)code,
4495 INVALID_MUSE_TYPE_VALUE);
4497 *pcode = strndup(code, code_len);
4499 ret = PLAYER_ERROR_INVALID_OPERATION;
4505 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4507 PLAYER_INSTANCE_CHECK(player);
4508 PLAYER_NULL_ARG_CHECK(callback);
4509 int ret = PLAYER_ERROR_NONE;
4510 player_cli_s *pc = (player_cli_s *) player;
4511 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4512 char *ret_buf = NULL;
4513 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4514 int idx = 0, num = 0;
4515 int bandwidth = 0, width = 0, height = 0;
4521 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4522 if (ret == PLAYER_ERROR_NONE) {
4523 player_msg_get_type(num, ret_buf, INT);
4525 player_msg_get_string(var_info, ret_buf);
4527 LOGW("There is no stream variant info.");
4530 for (idx = 0 ; idx < num ; idx++) {
4531 bandwidth = width = height = 0;
4533 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4535 bandwidth = atoi(token);
4537 token = strtok_r(NULL, ",", &ptr);
4539 width = atoi(token);
4541 token = strtok_r(NULL, ",", &ptr);
4543 height = atoi(token);
4545 callback(bandwidth, width, height, user_data);
4548 LOGD("LEAVE 0x%X", ret);
4553 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4555 int ret = PLAYER_ERROR_NONE;
4556 PLAYER_INSTANCE_CHECK(player);
4557 player_cli_s *pc = (player_cli_s *) player;
4558 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4559 char *ret_buf = NULL;
4563 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4564 MUSE_TYPE_INT, "bandwidth", bandwidth,
4565 MUSE_TYPE_INT, "width", width,
4566 MUSE_TYPE_INT, "height", height);
4569 LOGD("LEAVE 0x%X", ret);
4574 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4576 int ret = PLAYER_ERROR_NONE;
4577 PLAYER_INSTANCE_CHECK(player);
4578 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4580 player_cli_s *pc = (player_cli_s *) player;
4581 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4582 char *ret_buf = NULL;
4583 int bandwidth = -1, width = -1, height = -1;
4587 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4588 if (ret == PLAYER_ERROR_NONE) {
4589 bool ret_val = true;
4590 ret_val = _player_get_param_value(ret_buf,
4591 MUSE_TYPE_INT, "bandwidth", (void *)&bandwidth,
4592 MUSE_TYPE_INT, "width", (void *)&width,
4593 MUSE_TYPE_INT, "height", (void *)&height,
4594 INVALID_MUSE_TYPE_VALUE);
4596 if (pbandwidth) *pbandwidth = bandwidth;
4597 if (pwidth) *pwidth = width;
4598 if (pheight) *pheight = height;
4600 ret = PLAYER_ERROR_INVALID_OPERATION;
4605 LOGD("LEAVE 0x%X", ret);
4609 int player_set_audio_only(player_h player, bool audio_only)
4611 int ret = PLAYER_ERROR_NONE;
4612 PLAYER_INSTANCE_CHECK(player);
4613 player_cli_s *pc = (player_cli_s *) player;
4614 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4615 char *ret_buf = NULL;
4616 player_state_e state = PLAYER_STATE_NONE;
4618 LOGD("ENTER audio_only: %d", audio_only);
4620 /* check player state */
4621 if (_get_current_state(pc, &state) != PLAYER_ERROR_NONE) {
4622 LOGE("Failed to get state");
4623 return PLAYER_ERROR_INVALID_OPERATION;
4626 if (state < PLAYER_STATE_READY) {
4627 LOGE("Invalid state %d", state);
4628 return PLAYER_ERROR_INVALID_STATE;
4631 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4632 if (EVAS_HANDLE(pc)) {
4633 pc->is_audio_only = (gboolean)audio_only;
4634 return PLAYER_ERROR_NONE;
4637 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "audio_only", (int)audio_only);
4640 LOGD("LEAVE 0x%X", ret);
4645 int player_is_audio_only(player_h player, bool *paudio_only)
4647 PLAYER_INSTANCE_CHECK(player);
4648 PLAYER_NULL_ARG_CHECK(paudio_only);
4649 int ret = PLAYER_ERROR_NONE;
4650 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4651 player_cli_s *pc = (player_cli_s *) player;
4652 char *ret_buf = NULL;
4656 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4657 if (EVAS_HANDLE(pc)) {
4658 *paudio_only = (bool)pc->is_audio_only;
4659 return PLAYER_ERROR_NONE;
4663 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4664 if (ret == PLAYER_ERROR_NONE) {
4665 player_msg_get(audio_only, ret_buf);
4666 *paudio_only = (bool)audio_only;
4670 LOGD("LEAVE 0x%X", ret);
4674 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4676 int ret = PLAYER_ERROR_NONE;
4677 PLAYER_INSTANCE_CHECK(player);
4678 player_cli_s *pc = (player_cli_s *) player;
4679 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4680 char *ret_buf = NULL;
4684 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4685 MUSE_TYPE_INT, "buffer_ms", buffer_ms,
4686 MUSE_TYPE_INT, "rebuffer_ms", rebuffer_ms);
4689 LOGD("LEAVE 0x%X", ret);
4693 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4695 PLAYER_INSTANCE_CHECK(player);
4696 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4698 int ret = PLAYER_ERROR_NONE;
4699 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4700 player_cli_s *pc = (player_cli_s *) player;
4701 int buffering_time = 0, rebuffering_time = 0;
4702 char *ret_buf = NULL;
4706 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4708 if (ret == PLAYER_ERROR_NONE) {
4709 bool ret_val = true;
4710 ret_val = _player_get_param_value(ret_buf,
4711 MUSE_TYPE_INT, "buffering_time", (void *)&buffering_time,
4712 MUSE_TYPE_INT, "rebuffering_time", (void *)&rebuffering_time,
4713 INVALID_MUSE_TYPE_VALUE);
4715 if (buffer_ms) *buffer_ms = buffering_time;
4716 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4718 ret = PLAYER_ERROR_INVALID_OPERATION;
4724 LOGD("LEAVE 0x%X", ret);
4728 int player_360_is_content_spherical(player_h player, bool *is_spherical)
4730 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4731 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4733 PLAYER_INSTANCE_CHECK(player);
4734 PLAYER_NULL_ARG_CHECK(is_spherical);
4736 int ret = PLAYER_ERROR_NONE;
4737 muse_player_api_e api = MUSE_PLAYER_API_360_IS_CONTENT_SPHERICAL;
4738 player_cli_s *pc = (player_cli_s *) player;
4739 char *ret_buf = NULL;
4744 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4745 if (ret == PLAYER_ERROR_NONE) {
4746 player_msg_get(val, ret_buf);
4747 *is_spherical = val;
4751 LOGD("LEAVE 0x%X", ret);
4755 int player_360_set_enabled(player_h player, bool enabled)
4757 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4758 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4760 PLAYER_INSTANCE_CHECK(player);
4761 int ret = PLAYER_ERROR_NONE;
4762 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLED;
4763 player_cli_s *pc = (player_cli_s *) player;
4764 char *ret_buf = NULL;
4765 int val = (int)enabled;
4767 LOGD("ENTER %d", enabled);
4769 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
4772 LOGD("LEAVE 0x%X", ret);
4776 int player_360_is_enabled(player_h player, bool *enabled)
4778 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4779 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4781 PLAYER_INSTANCE_CHECK(player);
4782 PLAYER_NULL_ARG_CHECK(enabled);
4783 int ret = PLAYER_ERROR_NONE;
4784 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4785 player_cli_s *pc = (player_cli_s *) player;
4786 char *ret_buf = NULL;
4791 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4792 if (ret == PLAYER_ERROR_NONE) {
4793 player_msg_get(val, ret_buf);
4798 LOGD("LEAVE 0x%X", ret);
4802 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4804 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4805 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4807 PLAYER_INSTANCE_CHECK(player);
4808 int ret = PLAYER_ERROR_NONE;
4809 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4810 player_cli_s *pc = (player_cli_s *) player;
4811 char *ret_buf = NULL;
4813 LOGD("ENTER %f %f", yaw, pitch);
4815 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4816 MUSE_TYPE_DOUBLE, "yaw", (double)yaw,
4817 MUSE_TYPE_DOUBLE, "pitch", (double)pitch);
4821 LOGD("LEAVE 0x%X", ret);
4825 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4827 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4828 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4830 PLAYER_INSTANCE_CHECK(player);
4831 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4832 int ret = PLAYER_ERROR_NONE;
4833 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4834 player_cli_s *pc = (player_cli_s *) player;
4835 double yaw_val = -1;
4836 double pitch_val = -1;
4837 char *ret_buf = NULL;
4841 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4843 if (ret == PLAYER_ERROR_NONE) {
4844 bool ret_val = true;
4845 ret_val = _player_get_param_value(ret_buf,
4846 MUSE_TYPE_DOUBLE, "yaw_val", (void *)&yaw_val,
4847 MUSE_TYPE_DOUBLE, "pitch_val", (void *)&pitch_val,
4848 INVALID_MUSE_TYPE_VALUE);
4850 *yaw = (float)yaw_val;
4851 *pitch = (float)pitch_val;
4853 LOGE("failed to get value from msg");
4854 ret = PLAYER_ERROR_INVALID_OPERATION;
4860 LOGD("LEAVE 0x%X", ret);
4864 int player_360_set_zoom(player_h player, float level)
4866 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4867 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4869 PLAYER_INSTANCE_CHECK(player);
4870 int ret = PLAYER_ERROR_NONE;
4871 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4872 player_cli_s *pc = (player_cli_s *) player;
4873 char *ret_buf = NULL;
4875 LOGD("ENTER %f", level);
4877 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "level", (double)level);
4880 LOGD("LEAVE 0x%X", ret);
4884 int player_360_get_zoom(player_h player, float *level)
4886 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4887 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4889 PLAYER_INSTANCE_CHECK(player);
4890 PLAYER_NULL_ARG_CHECK(level);
4891 int ret = PLAYER_ERROR_NONE;
4892 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
4893 player_cli_s *pc = (player_cli_s *) player;
4895 char *ret_buf = NULL;
4899 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4901 if (ret == PLAYER_ERROR_NONE) {
4902 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
4903 *level = (float)zoom;
4905 LOGE("failed to get value from msg");
4906 ret = PLAYER_ERROR_INVALID_OPERATION;
4912 LOGD("LEAVE 0x%X", ret);
4917 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
4919 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4920 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4922 PLAYER_INSTANCE_CHECK(player);
4923 int ret = PLAYER_ERROR_NONE;
4924 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
4925 player_cli_s *pc = (player_cli_s *) player;
4926 char *ret_buf = NULL;
4928 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
4930 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
4931 MUSE_TYPE_INT, "horizontal_degrees", horizontal_degrees,
4932 MUSE_TYPE_INT, "vertical_degrees", vertical_degrees);
4935 LOGD("LEAVE 0x%X", ret);
4939 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
4941 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_OPENGL);
4942 PLAYER_FEATURE_CHECK(PLAYER_FEATURE_SPHERICAL_VIDEO);
4944 PLAYER_INSTANCE_CHECK(player);
4945 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
4946 int ret = PLAYER_ERROR_NONE;
4947 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
4948 player_cli_s *pc = (player_cli_s *) player;
4951 char *ret_buf = NULL;
4955 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
4957 if (ret == PLAYER_ERROR_NONE) {
4958 bool ret_val = true;
4959 ret_val = _player_get_param_value(ret_buf,
4960 MUSE_TYPE_INT, "h_val", (void *)&h_val,
4961 MUSE_TYPE_INT, "v_val", (void *)&v_val,
4962 INVALID_MUSE_TYPE_VALUE);
4964 *horizontal_degrees = h_val;
4965 *vertical_degrees = v_val;
4967 LOGE("failed to get value from msg");
4968 ret = PLAYER_ERROR_INVALID_OPERATION;
4974 LOGD("LEAVE 0x%X", ret);
4978 int player_set_replaygain_enabled(player_h player, bool enabled)
4980 PLAYER_INSTANCE_CHECK(player);
4981 int ret = PLAYER_ERROR_NONE;
4982 muse_player_api_e api = MUSE_PLAYER_API_SET_REPLAYGAIN_ENABLED;
4983 player_cli_s *pc = (player_cli_s *) player;
4984 char *ret_buf = NULL;
4985 int val = (int)enabled;
4989 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
4994 int player_is_replaygain_enabled(player_h player, bool *enabled)
4996 PLAYER_INSTANCE_CHECK(player);
4997 PLAYER_NULL_ARG_CHECK(enabled);
4998 int ret = PLAYER_ERROR_NONE;
4999 muse_player_api_e api = MUSE_PLAYER_API_IS_REPLAYGAIN_ENABLED;
5000 player_cli_s *pc = (player_cli_s *) player;
5001 char *ret_buf = NULL;
5006 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
5007 if (ret == PLAYER_ERROR_NONE) {
5008 player_msg_get(val, ret_buf);
5009 *enabled = (bool) val;