2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
22 #include <tbm_bufmgr.h>
23 #include <tbm_surface.h>
24 #include <tbm_surface_internal.h>
26 #include <Elementary.h>
28 #include <Ecore_Wayland.h>
31 #include <muse_core.h>
32 #include <muse_client.h>
33 #include <muse_player.h>
34 #include <muse_player_msg.h>
35 #include <sound_manager.h>
36 #include <sound_manager_internal.h>
37 #include <storage-internal.h>
38 #include <system_info.h>
39 #include "player_internal.h"
40 #include "player_private.h"
41 #include "player_display.h"
42 #include "player_msg.h"
43 #ifdef TIZEN_FEATURE_EVAS_RENDERER
44 #include <mm_evas_renderer.h>
48 #define INVALID_DEFAULT_VALUE -1
49 #define MAX_S_PATH_LEN 32
51 #define PATH_EVAS_RENDERER_LIB PATH_LIBDIR"/libmmfevasrenderer.so.0"
53 #define PLAYER_VIDEO_SUPPORT_CHECK(h) \
56 _handle = dlopen(PATH_EVAS_RENDERER_LIB, RTLD_LAZY); \
58 h->support_video = TRUE; \
59 EVAS_INFO(h)->support_video = TRUE; \
62 LOGW("not support video rendering"); \
67 TIZEN_PROFILE_UNKNOWN = 0,
68 TIZEN_PROFILE_MOBILE = 0x1,
69 TIZEN_PROFILE_WEARABLE = 0x2,
70 TIZEN_PROFILE_TV = 0x4,
71 TIZEN_PROFILE_IVI = 0x8,
72 TIZEN_PROFILE_COMMON = 0x10,
74 static tizen_profile_t _get_tizen_profile()
77 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
79 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
82 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
83 switch (*profileName) {
86 profile = TIZEN_PROFILE_MOBILE;
90 profile = TIZEN_PROFILE_WEARABLE;
94 profile = TIZEN_PROFILE_TV;
98 profile = TIZEN_PROFILE_IVI;
100 default: // common or unknown ==> ALL ARE COMMON.
101 profile = TIZEN_PROFILE_COMMON;
109 tbm_fd tfd[MUSE_NUM_FD];
115 callback_cb_info_s *cb_info;
116 _player_recv_data *recv_data;
125 } _media_pkt_fin_data;
132 * Internal Implementation
134 static int _player_deinit_memory_buffer(player_cli_s * pc);
135 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data);
136 static bool _player_need_sync_context(int event_id);
137 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all);
138 #ifdef TIZEN_FEATURE_EVAS_RENDERER
139 typedef void (*player_retrieve_buffer_cb)(void *user_data);
140 static void __retrieve_buffer_cb(void *user_data);
141 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data);
142 static int __player_unset_retrieve_buffer_cb(player_h player);
144 static void _player_release_internal_memory(player_cli_s * pc);
146 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
148 int ret = MEDIA_PACKET_FINALIZE;
149 muse_player_api_e api = MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB;
150 _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
152 char *snd_msg = NULL;
156 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
160 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
161 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
165 if (!fin_data->use_tsurf_pool) {
166 tbm_surface_h tsurf = NULL;
167 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
168 LOGE("media_packet_get_tbm_surface failed");
169 /* continue the remained job */
172 /* LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf); */
173 tbm_surface_destroy(tsurf);
177 /* Do not destroy tbm surface here to reuse during playback *
178 * they will be destroyed at player_unprepare() or player_destroy(). *
179 * ref: __player_remove_tsurf_list() */
181 tbm_surface_h tsurf = NULL;
183 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
184 /* LOGD("tsurf set to null %p", tsurf); */
189 if (muse_core_fd_is_valid(fin_data->fd)) {
190 if (muse_client_check_fd_id_value(fin_data->fd, fin_data->fd_id) == FALSE) {
191 LOGE("[fd:%d,id:%d] is invalid.", fin_data->fd, fin_data->fd_id);
195 packet = fin_data->remote_pkt;
196 snd_msg = muse_core_msg_new(api, MUSE_TYPE_POINTER, "packet", packet, 0);
197 snd_len = muse_core_msg_send(fin_data->fd, snd_msg);
198 muse_core_msg_free(snd_msg);
201 LOGE("[fd:%d] fail to send msg.", fin_data->fd);
203 LOGE("[fd:%d] is invalid.", fin_data->fd);
215 static bool _player_check_network_availability(void)
217 #define _FEATURE_NAME_WIFI "http://tizen.org/feature/network.wifi"
218 #define _FEATURE_NAME_TELEPHONY "http://tizen.org/feature/network.telephony"
219 #define _FEATURE_NAME_ETHERNET "http://tizen.org/feature/network.ethernet"
220 bool enabled = FALSE;
221 bool supported = FALSE;
223 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
224 LOGI("wifi status = %d", enabled);
228 LOGE("SYSTEM_INFO_ERROR");
231 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
232 LOGI("telephony status = %d", enabled);
236 LOGE("SYSTEM_INFO_ERROR");
239 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
240 LOGI("ethernet status = %d", enabled);
244 LOGE("SYSTEM_INFO_ERROR");
253 static void *_get_mem(player_cli_s * player, int size)
255 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
257 mem->data = g_new(void, size);
258 mem->next = player->head;
265 static void _del_mem(player_cli_s * player)
268 while (player->head) {
269 mem = player->head->next;
270 g_free(player->head->data);
271 g_free(player->head);
276 static int player_recv_msg(callback_cb_info_s * cb_info, tbm_fd *tfd)
279 msg_buff_s *buff = &cb_info->buff;
281 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
282 recvLen = muse_core_msg_recv_fd(cb_info->fd, buff->recvMsg, tfd);
284 LOGE("failed to recv msg %d", recvLen);
288 /* check the first msg */
289 if (buff->part_of_msg && buff->recvMsg[0] != '{')
291 gchar *tmp = strndup(buff->recvMsg, recvLen);
293 LOGE("failed to copy msg.");
297 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
300 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
301 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
302 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
303 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
304 if (!buff->recvMsg) {
305 LOGE("failed renew buffer.");
310 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
312 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
313 recvLen += strlen(buff->part_of_msg);
315 free(buff->part_of_msg);
316 buff->part_of_msg = NULL;
321 /* check the last msg */
322 if (buff->recvMsg[recvLen-1] != '}') {
323 char *part_pos = strrchr(buff->recvMsg, '}');
324 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
327 buff->part_of_msg = strndup(part_pos+1, part_len);
328 if (!buff->part_of_msg) {
329 LOGE("failed to alloc buffer for part of msg.");
332 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
340 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
342 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
343 cb_info->user_cb[event] = NULL;
344 cb_info->user_data[event] = NULL;
348 /* Notice : have to be called via API to avoid deadlock
349 * to clear the cb setting at the cb thread, set_null_user_cb() have to be called instead.
351 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
356 LOGE("cb_info is NULL, event: %d", event);
360 lock = (g_thread_self() != cb_info->event_queue.thread);
363 g_mutex_lock(&cb_info->event_queue.mutex);
365 if (_player_need_sync_context(event))
366 _player_remove_idle_event(cb_info, event, false);
368 set_null_user_cb(cb_info, event);
371 g_mutex_unlock(&cb_info->event_queue.mutex);
374 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
376 PLAYER_INSTANCE_CHECK(player);
377 PLAYER_NULL_ARG_CHECK(callback);
378 int ret = PLAYER_ERROR_NONE;
379 player_cli_s *pc = (player_cli_s *) player;
380 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
383 if (MUSE_PLAYER_EVENT_TYPE_BUFFERING == type) {
384 if (!_player_check_network_availability())
385 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
388 LOGI("Event type : %d ", type);
389 player_msg_set_callback(api, pc, ret, type, set);
391 if (ret == PLAYER_ERROR_NONE) {
392 pc->cb_info->user_cb[type] = callback;
393 pc->cb_info->user_data[type] = user_data;
398 static int __unset_callback(muse_player_event_e type, player_h player)
400 PLAYER_INSTANCE_CHECK(player);
401 int ret = PLAYER_ERROR_NONE;
402 player_cli_s *pc = (player_cli_s *) player;
403 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
406 LOGI("Event type : %d ", type);
408 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
409 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
411 player_msg_set_callback(api, pc, ret, type, set);
412 ret = PLAYER_ERROR_NONE;
417 static void __prepare_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
419 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
421 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
423 set_null_user_cb(cb_info, ev);
426 static void __complete_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
428 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
429 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
432 #ifdef TIZEN_FEATURE_EVAS_RENDERER
433 static void __retrieve_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
436 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER;
437 ((player_retrieve_buffer_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
441 static char* _convert_code_to_str(int code)
444 case PLAYER_INTERRUPTED_COMPLETED: /* Deprecated since 3.0 */
445 return "PLAYER_INTERRUPTED_COMPLETED";
446 case PLAYER_INTERRUPTED_BY_MEDIA: /* Deprecated since 3.0 */
447 return "PLAYER_INTERRUPTED_BY_MEDIA";
448 case PLAYER_INTERRUPTED_BY_CALL: /* Deprecated since 3.0 */
449 return "PLAYER_INTERRUPTED_BY_CALL";
450 case PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG: /* Deprecated since 3.0 */
451 return "PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG";
452 case PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT:
453 return "PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT";
454 case PLAYER_INTERRUPTED_BY_ALARM: /* Deprecated since 3.0 */
455 return "PLAYER_INTERRUPTED_BY_ALARM";
456 case PLAYER_INTERRUPTED_BY_EMERGENCY: /* Deprecated since 3.0 */
457 return "PLAYER_INTERRUPTED_BY_EMERGENCY";
458 case PLAYER_INTERRUPTED_BY_NOTIFICATION: /* Deprecated since 3.0 */
459 return "PLAYER_INTERRUPTED_BY_NOTIFICATION";
461 LOGE("Invalid interrupted code %d (Never enter here)", code);
466 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
469 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
471 if (player_msg_get(code, recv_data->buffer)) {
473 if (code >= PLAYER_INTERRUPTED_COMPLETED &&
474 code <= PLAYER_INTERRUPTED_BY_NOTIFICATION &&
475 code != PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT) {
476 LOGW("DEPRECATION WARNING: %s is deprecated and will be removed from next release.", _convert_code_to_str(code));
479 ((player_interrupted_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
483 static void __error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
486 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
488 if (player_msg_get(code, recv_data->buffer)) {
489 if (code == PLAYER_ERROR_NOT_SUPPORTED_FILE) {
490 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
491 LOGW("failed to pause, so prepare cb will be released soon");
492 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
495 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
499 static void __disconnected_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
501 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
503 ((player_error_cb) cb_info->user_cb[ev]) (PLAYER_ERROR_SERVICE_DISCONNECTED, cb_info->user_data[ev]);
506 static void __buffering_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
509 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
511 if (player_msg_get(percent, recv_data->buffer))
512 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
515 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
518 char text[MUSE_URI_MAX_LENGTH] = { 0, };
519 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
522 player_msg_get1_string(recv_data->buffer, duration, INT, text, ret);
524 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
527 static void __capture_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
529 unsigned char *data = NULL;
532 unsigned int size = 0;
534 tbm_bo_handle thandle;
535 int key = INVALID_DEFAULT_VALUE;
538 player_msg_get4(recv_data->buffer, width, INT, height, INT, size, INT, key, INT, ret_val);
540 if (recv_data->tfd[0] < 0) {
541 LOGE("There is no valid tbm_fd");
545 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
547 LOGE("TBM get error : bo is NULL");
550 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
551 if (thandle.ptr == NULL) {
552 LOGE("TBM get error : handle pointer is NULL");
555 data = g_new(unsigned char, size);
557 memcpy(data, thandle.ptr, size);
558 ((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]);
561 LOGE("g_new failure");
567 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
568 close(recv_data->tfd[0]);
569 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
575 if (key > INVALID_DEFAULT_VALUE) {
576 LOGD("send msg to release buffer. key:%d", key);
577 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
580 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
583 static void __seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
585 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
587 g_mutex_lock(&cb_info->seek_cb_mutex);
588 if (cb_info->user_cb[ev] && cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_NONE) {
589 #ifdef TIZEN_FEATURE_EVAS_RENDERER
590 if (cb_info->evas_info && cb_info->evas_info->support_video) {
591 if (cb_info->evas_info->handle && cb_info->evas_info->visible != EVAS_VISIBLE_FALSE) {
592 int ret = mm_evas_renderer_set_visible(cb_info->evas_info->handle, true);
593 if (ret != MM_ERROR_NONE)
594 LOGW("failed to set visible at evas 0x%x", ret);
596 cb_info->evas_info->visible = EVAS_VISIBLE_TRUE;
600 LOGD("call seek cb");
601 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
602 set_null_user_cb(cb_info, ev);
604 LOGW("ignored. seek cb %p", cb_info->user_cb[ev]);
606 g_mutex_unlock(&cb_info->seek_cb_mutex);
609 static void __player_remove_tsurf_list(player_cli_s * pc)
613 g_mutex_lock(&pc->cb_info->data_mutex);
614 if (pc->cb_info->tsurf_list) {
615 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
617 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
618 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
620 LOGD("%p will be removed", tmp);
623 tbm_surface_destroy(tmp->tsurf);
629 g_list_free(pc->cb_info->tsurf_list);
630 pc->cb_info->tsurf_list = NULL;
632 g_mutex_unlock(&pc->cb_info->data_mutex);
636 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, int *key, int height, int width)
640 g_mutex_lock(&cb_info->data_mutex);
641 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
642 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
643 if (tmp && key && (tmp->key[0] == key[0])) {
644 LOGD("found tsurf_data of tbm_key %d", key[0]);
646 /* need to check tsuf info to support DRC */
647 if ((tbm_surface_get_height(tmp->tsurf) != height) ||
648 (tbm_surface_get_width(tmp->tsurf) != width)) {
650 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
651 LOGW("tsurf info is changed. need to create new tsurf.");
652 tbm_surface_destroy(tmp->tsurf);
655 g_mutex_unlock(&cb_info->data_mutex);
659 g_mutex_unlock(&cb_info->data_mutex);
664 g_mutex_unlock(&cb_info->data_mutex);
668 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
670 tbm_bo bo[4] = { NULL, };
671 int key[4] = { INVALID_DEFAULT_VALUE, };
672 tbm_surface_info_s sinfo;
673 char *surface_info = (char *)&sinfo;
674 media_packet_h pkt = NULL;
675 tbm_surface_h tsurf = NULL;
676 player_tsurf_info_t *tsurf_data = NULL;
678 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
679 bool make_pkt_fmt = false;
680 int ret = MEDIA_FORMAT_ERROR_NONE;
681 _media_pkt_fin_data *fin_data = NULL;
685 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
687 void *jobj = muse_core_msg_object_new(recv_data->buffer, NULL, &err);
689 !muse_core_msg_object_get_value("key[0]", jobj, MUSE_TYPE_ANY, &key[0]) ||
690 !muse_core_msg_object_get_value("key[1]", jobj, MUSE_TYPE_ANY, &key[1]) ||
691 !muse_core_msg_object_get_value("key[2]", jobj, MUSE_TYPE_ANY, &key[2]) ||
692 !muse_core_msg_object_get_value("key[3]", jobj, MUSE_TYPE_ANY, &key[3]) ||
693 !muse_core_msg_object_get_value("packet", jobj, MUSE_TYPE_POINTER, &packet) ||
694 !muse_core_msg_object_get_value("mimetype", jobj, MUSE_TYPE_ANY, &mimetype) ||
695 !muse_core_msg_object_get_value("pts", jobj, MUSE_TYPE_INT64, &pts) ||
696 !muse_core_msg_object_get_value("surface_info", jobj, MUSE_TYPE_ARRAY, surface_info)) {
698 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
700 muse_core_msg_object_free(jobj);
703 muse_core_msg_object_free(jobj);
705 LOGD("width %d, height %d", sinfo.width, sinfo.height);
708 LOGE("cb_info is null");
712 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
713 /* send msg to release packet. */
714 LOGE("_video_decoded_cb is not set");
718 if (recv_data->tfd[0] <= INVALID_DEFAULT_VALUE) {
719 LOGE("tbm fd is invalid");
723 tsurf_data = __player_get_tsurf_from_list(cb_info, key, (int)sinfo.height, (int)sinfo.width);
725 for (i = 0; i < MUSE_NUM_FD; i++) {
726 if (recv_data->tfd[i] <= INVALID_DEFAULT_VALUE)
730 bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
733 tsurf_data = g_new(player_tsurf_info_t, 1);
735 LOGE("failed to alloc tsurf info");
738 memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
740 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
742 LOGE("failed to create tbm surface");
746 memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
747 tsurf_data->tsurf = tsurf;
748 if (cb_info->use_tsurf_pool) {
749 g_mutex_lock(&cb_info->data_mutex);
750 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
751 LOGD("key %d is added to the pool", key[0]);
752 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
753 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
754 g_mutex_unlock(&cb_info->data_mutex);
757 if (tsurf_data->tsurf) {
758 tsurf = tsurf_data->tsurf;
760 LOGE("tsurf_data->tsurf is null (never enter here)");
765 /* check media packet format */
766 if (cb_info->pkt_fmt) {
767 int pkt_fmt_width = 0;
768 int pkt_fmt_height = 0;
769 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
771 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
772 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
773 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);
774 media_format_unref(cb_info->pkt_fmt);
775 cb_info->pkt_fmt = NULL;
781 /* create packet format */
783 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
784 ret = media_format_create(&cb_info->pkt_fmt);
785 if (ret == MEDIA_FORMAT_ERROR_NONE) {
786 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
787 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
788 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
789 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
791 LOGE("media_format_create failed");
795 fin_data = g_new0(_media_pkt_fin_data, 1);
797 LOGE("failed to alloc fin_data");
800 fin_data->remote_pkt = packet;
801 fin_data->fd = cb_info->fd;
802 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
804 /* Keep the fd id to check validation when the pkt is destroyed. */
805 fin_data->fd_id = muse_client_get_fd_id_value(fin_data->fd);
807 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
808 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
809 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
814 ret = media_packet_set_pts(pkt, (uint64_t) pts);
815 if (ret != MEDIA_PACKET_ERROR_NONE)
816 LOGE("media_packet_set_pts failed");
818 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
819 /* call media packet callback */
820 ((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]);
822 LOGE("_video_decoded_cb is not set");
823 media_packet_destroy(pkt);
826 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
827 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
828 close(recv_data->tfd[i]);
831 for (i = 0; i < bo_num; i++) {
836 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
841 media_packet_destroy(pkt);
846 for (i = 0; i < MUSE_NUM_FD; i++) { /* if tsruf pool is enabled, bo_num can be zero. */
847 if (recv_data->tfd[i] > INVALID_DEFAULT_VALUE)
848 close(recv_data->tfd[i]);
851 for (i = 0; i < bo_num; i++) {
855 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
857 if (cb_info && packet)
858 player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
863 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
866 tbm_bo_handle thandle;
867 int key = INVALID_DEFAULT_VALUE;
868 player_audio_raw_data_s audio;
870 if (!player_msg_get(key, recv_data->buffer)) {
871 LOGE("failed to get key value from msg.");
875 if (recv_data->tfd[0] < 0) {
876 LOGE("failed to get tbm_fd(key:%d)", key);
880 bo = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[0]);
882 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", recv_data->tfd[0], key);
886 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
887 if (thandle.ptr == NULL) {
888 LOGE("TBM get error : handle pointer is NULL");
892 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
893 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
895 /* LOGD("user callback data %p, size %d", audio.data, audio.size); */
896 ((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]);
900 if (recv_data->tfd[0] > INVALID_DEFAULT_VALUE)
901 close(recv_data->tfd[0]);
902 memset(recv_data->tfd, INVALID_DEFAULT_VALUE, sizeof(recv_data->tfd));
908 if (key > INVALID_DEFAULT_VALUE) {
909 /* LOGD("send msg to release buffer. key:%d", key); */
910 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
914 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
918 static void __pd_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
921 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
923 if (player_msg_get(type, recv_data->buffer))
924 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
927 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
931 static void __supported_audio_effect_preset_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
935 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
939 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
941 /* player_media_stream_buffer_status_e status; */
944 if (player_msg_get(status, recv_data->buffer)) {
945 ((player_media_stream_buffer_status_cb)
946 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]);
950 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
952 /* player_media_stream_buffer_status_e status; */
955 if (player_msg_get(status, recv_data->buffer)) {
956 ((player_media_stream_buffer_status_cb)
957 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
958 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
963 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
965 /* player_media_stream_buffer_status_e status; */
967 unsigned long long bytes;
970 player_msg_get2(recv_data->buffer, status, INT, bytes, INT64, ret);
972 ((player_media_stream_buffer_status_cb_ex)
973 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
974 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
978 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
980 /* player_media_stream_buffer_status_e status; */
982 unsigned long long bytes;
985 player_msg_get2(recv_data->buffer, status, INT, bytes, INT64, ret);
987 ((player_media_stream_buffer_status_cb_ex)
988 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
989 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
994 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
996 unsigned long long offset;
998 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
999 ((player_media_stream_seek_cb)
1000 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
1001 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
1005 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1007 unsigned long long offset;
1009 if (player_msg_get_type(offset, recv_data->buffer, INT64)) {
1010 ((player_media_stream_seek_cb)
1011 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
1012 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
1016 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, _player_recv_data *recv_data)
1022 bool ret_val = TRUE;
1024 player_msg_get4(recv_data->buffer, width, INT, height, INT, fps, INT, bit_rate, INT, ret_val);
1026 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
1027 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
1031 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, _player_recv_data *recv_data) = {
1032 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
1033 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
1034 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
1035 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
1036 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
1037 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
1038 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
1039 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
1040 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
1041 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
1042 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
1043 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
1044 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
1045 __supported_audio_effect_preset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
1046 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
1047 #ifdef _PLAYER_FOR_PRODUCT
1048 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
1049 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
1051 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
1052 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
1053 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
1054 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
1055 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
1056 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
1057 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
1058 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
1059 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1060 __retrieve_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER */
1062 __disconnected_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED */
1065 gboolean _player_event_job_function(void *user_data)
1067 _player_cb_data *data = (_player_cb_data *)user_data;
1068 muse_player_event_e ev;
1071 LOGE("data is null");
1075 LOGD("enter ev:%d", data->int_data);
1077 g_mutex_lock(&data->event_mutex);
1078 ev = data->int_data;
1080 if (data->cb_info == NULL) {
1081 /* tried to remove before at _player_remove_idle_event */
1082 LOGW("cb_info is NULL. event %d", data->int_data);
1086 /* remove event from list */
1087 g_mutex_lock(&data->cb_info->event_queue.idle_ev_mutex);
1088 if (data->cb_info->event_queue.idle_ev_list) {
1089 /* LOGD("remove idle event %p, %p", data, data->cb_info->event_queue.idle_ev_list); */
1090 data->cb_info->event_queue.idle_ev_list = g_list_remove(data->cb_info->event_queue.idle_ev_list, (gpointer)data);
1092 g_mutex_unlock(&data->cb_info->event_queue.idle_ev_mutex);
1094 if (data->cb_info->user_cb[ev])
1095 _user_callbacks[ev] (data->cb_info, data->recv_data);
1097 LOGW("user callback is unset. type : %d", ev);
1100 /* unlock and release event */
1101 g_mutex_unlock(&data->event_mutex);
1102 g_mutex_clear(&data->event_mutex);
1104 if (data->recv_data) {
1105 g_free(data->recv_data->buffer);
1106 g_free(data->recv_data);
1110 return FALSE; /* remove from the event list */
1113 static bool _player_need_sync_context(int event_id)
1115 if ((event_id == MUSE_PLAYER_EVENT_TYPE_INTERRUPT) ||
1116 (event_id == MUSE_PLAYER_EVENT_TYPE_BUFFERING) ||
1117 (event_id == MUSE_PLAYER_EVENT_TYPE_PD) ||
1118 (event_id == MUSE_PLAYER_EVENT_TYPE_COMPLETE) ||
1119 (event_id == MUSE_PLAYER_EVENT_TYPE_ERROR) ||
1120 (event_id == MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED) ||
1121 (event_id == MUSE_PLAYER_EVENT_TYPE_PREPARE)) {
1122 LOGD("%d callback will be issued in the mainloop.", event_id);
1129 static void *_player_event_queue_loop(void *param)
1132 LOGE("NULL parameter");
1135 callback_cb_info_s *cb_info = param;
1136 player_event_queue *ev = &cb_info->event_queue;
1137 _player_cb_data *event_data = NULL;
1139 g_mutex_lock(&ev->mutex);
1140 while (ev->running) {
1141 g_mutex_lock(&ev->qlock);
1142 if (g_queue_is_empty(ev->queue)) {
1143 g_mutex_unlock(&ev->qlock);
1144 g_cond_wait(&ev->cond, &ev->mutex);
1148 g_mutex_unlock(&ev->qlock);
1151 g_mutex_lock(&ev->qlock);
1152 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1153 g_mutex_unlock(&ev->qlock);
1155 muse_player_event_e event_type = ((_player_cb_data *)event_data)->int_data;
1157 if (event_type == MUSE_PLAYER_EVENT_TYPE_SEEK) {
1158 g_mutex_lock(&cb_info->seek_cb_mutex);
1159 if (cb_info->seek_cb_state == PLAYER_SEEK_CB_STATE_WAIT) {
1160 /* push event into queue again. */
1161 _player_event_queue_add(ev, event_data);
1162 g_mutex_unlock(&cb_info->seek_cb_mutex);
1165 g_mutex_unlock(&cb_info->seek_cb_mutex);
1168 if (_player_need_sync_context(event_data->int_data)) {
1169 if (cb_info->user_cb[event_data->int_data] &&
1170 _user_callbacks[event_data->int_data]) {
1171 g_mutex_lock(&ev->idle_ev_mutex);
1172 ev->idle_ev_list = g_list_append(ev->idle_ev_list, (gpointer)event_data);
1173 g_mutex_unlock(&ev->idle_ev_mutex);
1175 LOGD("add ev %d to main loop", event_data->int_data);
1177 g_idle_add_full(G_PRIORITY_DEFAULT,
1178 (GSourceFunc)_player_event_job_function,
1179 (gpointer)event_data,
1182 LOGW("there is no registered cb for ev:%d", event_data->int_data);
1183 if (event_data->recv_data) {
1184 g_free(event_data->recv_data->buffer);
1185 g_free(event_data->recv_data);
1190 _player_event_job_function(event_data);
1197 g_mutex_unlock(&ev->mutex);
1198 LOGI("Exit event loop");
1202 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1204 g_return_val_if_fail(cb_info, FALSE);
1205 player_event_queue *ev = &cb_info->event_queue;
1207 ev->queue = g_queue_new();
1208 g_return_val_if_fail(ev->queue, FALSE);
1209 g_mutex_init(&ev->qlock);
1211 g_mutex_init(&ev->mutex);
1212 g_cond_init(&ev->cond);
1215 g_mutex_init(&ev->idle_ev_mutex);
1217 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1218 g_return_val_if_fail(ev->thread, FALSE);
1219 LOGI("event queue thread %p", ev->thread);
1225 static void _player_remove_idle_event(callback_cb_info_s *cb_info, muse_player_event_e event_type, bool remove_all)
1227 g_return_if_fail(cb_info);
1228 player_event_queue *ev = &cb_info->event_queue;
1229 _player_cb_data *event_data = NULL;
1232 g_mutex_lock(&ev->idle_ev_mutex);
1234 if (ev->idle_ev_list == NULL) {
1235 LOGD("No idle event is remained.");
1236 g_mutex_unlock(&ev->idle_ev_mutex);
1240 LOGD("remove idle event[%d] or all[%d]", event_type, remove_all);
1242 list = ev->idle_ev_list;
1244 event_data = list->data;
1245 list = g_list_next(list);
1248 LOGW("Fail to remove idle event. The data is NULL");
1252 if (g_mutex_trylock(&event_data->event_mutex)) {
1254 gboolean ret = FALSE;
1255 if (remove_all || (event_data->int_data == event_type)) {
1257 LOGD("remove idle event [%p:%d]", event_data, event_data->int_data);
1259 ret = g_idle_remove_by_data(event_data);
1261 /* will be handled at _player_event_job_function() as an exception */
1262 event_data->cb_info = NULL;
1263 LOGW("failed to remove, idle callback will be called later");
1266 /* set cb to null */
1267 set_null_user_cb(cb_info, event_data->int_data);
1268 ev->idle_ev_list = g_list_remove(ev->idle_ev_list, (gpointer)event_data);
1270 g_mutex_unlock(&event_data->event_mutex);
1273 g_mutex_clear(&event_data->event_mutex);
1274 if (event_data->recv_data) {
1275 g_free(event_data->recv_data->buffer);
1276 g_free(event_data->recv_data);
1280 LOGD("remove idle event done");
1281 } /* else : will be handled if the cb is called. */
1283 g_mutex_unlock(&event_data->event_mutex);
1286 LOGW("event(%d) lock failed. it's being called...", event_data->int_data);
1289 /* continue: keep checking next event_data */
1293 g_list_free(ev->idle_ev_list);
1294 ev->idle_ev_list = NULL;
1297 g_mutex_unlock(&ev->idle_ev_mutex);
1303 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1305 g_return_if_fail(cb_info);
1306 player_event_queue *ev = &cb_info->event_queue;
1307 _player_cb_data *event_data;
1309 LOGI("event queue thread %p", ev->thread);
1311 g_mutex_lock(&ev->mutex);
1312 ev->running = FALSE;
1313 g_cond_broadcast(&ev->cond);
1314 g_mutex_unlock(&ev->mutex);
1316 g_thread_join(ev->thread);
1319 while (!g_queue_is_empty(ev->queue)) {
1320 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1322 g_free(event_data->recv_data->buffer);
1323 g_free(event_data->recv_data);
1327 g_queue_free(ev->queue);
1328 g_mutex_clear(&ev->qlock);
1329 g_mutex_clear(&ev->mutex);
1330 g_cond_clear(&ev->cond);
1331 g_mutex_clear(&ev->idle_ev_mutex);
1334 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1338 g_mutex_lock(&ev_queue->qlock);
1340 item = g_queue_peek_head_link(ev_queue->queue);
1342 GList *next = item->next;
1343 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1345 if (cb_data && cb_data->int_data == ev) {
1346 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1347 g_free(cb_data->recv_data->buffer);
1348 g_free(cb_data->recv_data);
1351 g_queue_delete_link(ev_queue->queue, item);
1355 g_mutex_unlock(&ev_queue->qlock);
1358 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1361 g_mutex_lock(&ev->qlock);
1362 g_queue_push_tail(ev->queue, (gpointer) data);
1363 g_mutex_unlock(&ev->qlock);
1364 g_cond_signal(&ev->cond);
1368 static bool _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, _player_recv_data *recv_data)
1370 /* LOGD("get event %d", event); */
1372 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1373 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1374 _player_cb_data *data = NULL;
1375 data = g_new(_player_cb_data, 1);
1377 LOGE("fail to alloc mem");
1380 data->int_data = (int)event;
1381 data->cb_info = cb_info;
1382 data->recv_data = recv_data;
1383 g_mutex_init(&data->event_mutex);
1384 _player_event_queue_add(&cb_info->event_queue, data);
1390 LOGE("failed to add event to queue");
1394 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1396 ret_msg_s *msg = NULL;
1397 ret_msg_s *last = cb_info->buff.retMsgHead;
1399 msg = g_new(ret_msg_s, 1);
1402 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1405 cb_info->buff.retMsgHead = msg;
1412 LOGE("g_new failure");
1415 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1417 ret_msg_s *msg = cb_info->buff.retMsgHead;
1418 ret_msg_s *prev = NULL;
1420 if (msg->api == api) {
1422 cb_info->buff.retMsgHead = msg->next;
1424 prev->next = msg->next;
1433 static void _remove_all_ret_msg(callback_cb_info_s * cb_info)
1435 ret_msg_s *msg = cb_info->buff.retMsgHead;
1436 ret_msg_s *prev = NULL;
1440 LOGI("Remove %s", prev->msg);
1447 static void _notify_disconnected(callback_cb_info_s * cb_info)
1449 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_SERVICE_DISCONNECTED;
1450 if (!cb_info || !cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
1453 if (_user_callbacks[event]) {
1454 _player_cb_data *data = NULL;
1455 data = g_new(_player_cb_data, 1);
1457 LOGE("fail to alloc mem");
1460 data->int_data = (int)event;
1461 data->cb_info = cb_info;
1462 data->recv_data = NULL;
1463 g_mutex_init(&data->event_mutex);
1464 _player_event_queue_add(&cb_info->event_queue, data);
1468 static void *client_cb_handler(gpointer data)
1474 callback_cb_info_s *cb_info = data;
1475 char *recvMsg = NULL;
1476 muse_core_msg_parse_err_e err;
1477 tbm_fd tfd[MUSE_NUM_FD];
1479 memset(tfd, INVALID_DEFAULT_VALUE, sizeof(tfd));
1480 while (g_atomic_int_get(&cb_info->running)) {
1482 err = MUSE_MSG_PARSE_ERROR_NONE;
1484 len = player_recv_msg(cb_info, tfd);
1488 recvMsg = cb_info->buff.recvMsg;
1489 recvMsg[len] = '\0';
1493 while (offset < len) {
1494 api = MUSE_PLAYER_API_MAX;
1495 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1498 void *jobj = muse_core_msg_object_new(recvMsg + offset, &parse_len, &err);
1500 if (muse_core_msg_object_get_value("api", jobj, MUSE_TYPE_INT, &api)) {
1501 if (api < MUSE_PLAYER_API_MAX) {
1502 g_mutex_lock(&cb_info->player_mutex);
1503 cb_info->buff.recved++;
1504 _add_ret_msg(api, cb_info, offset, parse_len);
1505 if (api == MUSE_PLAYER_API_GET_ALBUM_ART && tfd[0] != INVALID_DEFAULT_VALUE) {
1506 LOGD("get tbm fd for album art.");
1507 cb_info->tfd = tfd[0];
1509 g_cond_signal(&cb_info->player_cond[api]);
1510 g_mutex_unlock(&cb_info->player_mutex);
1511 if (api == MUSE_PLAYER_API_DESTROY)
1512 g_atomic_int_set(&cb_info->running, 0);
1513 } else if (api == MUSE_PLAYER_CB_EVENT) {
1515 _player_recv_data *recv_data = NULL;
1516 g_mutex_lock(&cb_info->player_mutex);
1517 recv_data = g_new0(_player_recv_data, 1);
1518 if (recv_data != NULL) {
1519 memcpy(recv_data->tfd, tfd, sizeof(recv_data->tfd));
1520 recv_data->buffer = strndup(recvMsg+offset, parse_len);
1522 LOGE("failed to alloc recv_data.");
1523 g_mutex_unlock(&cb_info->player_mutex);
1524 muse_core_msg_object_free(jobj);
1527 g_mutex_unlock(&cb_info->player_mutex);
1528 if (!muse_core_msg_object_get_value("event", jobj, MUSE_TYPE_INT, &event) ||
1529 !_user_callback_handler(cb_info, event, recv_data)) {
1530 LOGE("failed to get value or add event to the queue.");
1532 g_free(recv_data->buffer);
1536 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1537 g_mutex_lock(&cb_info->player_mutex);
1538 cb_info->buff.recved++;
1539 g_cond_signal(&cb_info->server_ack_cond);
1540 g_mutex_unlock(&cb_info->player_mutex);
1543 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1545 muse_core_msg_object_free(jobj);
1547 LOGE("Failed to get msg obj. err:%d", err);
1550 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1553 offset += parse_len;
1554 parse_len = len - offset;
1557 if (g_atomic_int_get(&cb_info->running))
1558 _notify_disconnected(cb_info);
1559 LOGD("client cb exit");
1564 static callback_cb_info_s *callback_new(gint sockfd)
1566 callback_cb_info_s *cb_info;
1570 g_return_val_if_fail(sockfd > 0, NULL);
1572 cb_info = g_new(callback_cb_info_s, 1);
1575 memset(cb_info, 0, sizeof(callback_cb_info_s));
1577 g_mutex_init(&cb_info->player_mutex);
1578 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1579 g_cond_init(&cb_info->player_cond[i]);
1580 g_cond_init(&cb_info->server_ack_cond);
1582 g_mutex_init(&cb_info->data_mutex);
1583 g_mutex_init(&cb_info->seek_cb_mutex);
1585 buff = &cb_info->buff;
1586 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1587 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1589 buff->retMsgHead = NULL;
1590 buff->part_of_msg = NULL;
1592 g_atomic_int_set(&cb_info->running, 1);
1593 cb_info->fd = sockfd;
1594 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1595 cb_info->tfd = INVALID_DEFAULT_VALUE;
1600 static void callback_destroy(callback_cb_info_s * cb_info)
1603 g_return_if_fail(cb_info);
1605 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1606 muse_client_close(cb_info->fd);
1607 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1608 muse_client_close(cb_info->data_fd);
1610 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1612 g_thread_join(cb_info->thread);
1613 cb_info->thread = NULL;
1615 LOGI("%p Callback destroyed", cb_info);
1617 g_mutex_clear(&cb_info->player_mutex);
1618 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1619 g_cond_clear(&cb_info->player_cond[i]);
1620 g_cond_clear(&cb_info->server_ack_cond);
1622 g_mutex_clear(&cb_info->data_mutex);
1623 g_mutex_clear(&cb_info->seek_cb_mutex);
1625 g_free(cb_info->buff.recvMsg);
1626 _remove_all_ret_msg(cb_info);
1627 if (cb_info->buff.part_of_msg)
1628 g_free(cb_info->buff.part_of_msg);
1632 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1637 case MUSE_PLAYER_API_PREPARE:
1638 case MUSE_PLAYER_API_PREPARE_ASYNC:
1639 case MUSE_PLAYER_API_UNPREPARE:
1640 case MUSE_PLAYER_API_START:
1641 case MUSE_PLAYER_API_STOP:
1642 case MUSE_PLAYER_API_PAUSE:
1643 timeout += SERVER_TIMEOUT(pc);
1646 /* check prepare async is done */
1647 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1648 timeout += SERVER_TIMEOUT(pc);
1651 timeout += CALLBACK_TIME_OUT;
1652 return timeout; /* ms */
1655 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1657 int ret = PLAYER_ERROR_NONE;
1658 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1659 msg_buff_s *buff = &cb_info->buff;
1660 ret_msg_s *msg = NULL;
1662 g_mutex_lock(&cb_info->player_mutex);
1664 msg = _get_ret_msg(api, cb_info);
1666 if (!buff->recved || !msg) {
1667 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1668 LOGW("api %d return msg does not received %dms", api, time_out);
1669 ret = PLAYER_ERROR_INVALID_OPERATION;
1674 msg = _get_ret_msg(api, cb_info);
1676 *ret_buf = msg->msg;
1679 if (!player_msg_get(ret, *ret_buf))
1680 ret = PLAYER_ERROR_INVALID_OPERATION;
1682 LOGE("api %d is the spurious wakeup", api);
1686 g_mutex_unlock(&cb_info->player_mutex);
1690 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1692 int ret = PLAYER_ERROR_NONE;
1693 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1694 msg_buff_s *buff = &cb_info->buff;
1696 g_mutex_lock(&cb_info->player_mutex);
1698 if (!buff->recved) {
1699 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1700 LOGW("server ack msg does not received %dms", time_out);
1702 ret = PLAYER_ERROR_INVALID_OPERATION;
1704 LOGD("Another msg is received, continue create handle");
1705 g_mutex_unlock(&cb_info->player_mutex);
1711 g_mutex_unlock(&cb_info->player_mutex);
1718 * Public Implementation
1721 int player_create(player_h * player)
1723 PLAYER_INSTANCE_CHECK(player);
1725 int ret = PLAYER_ERROR_NONE;
1726 int sock_fd = INVALID_DEFAULT_VALUE;
1729 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1730 muse_core_api_module_e module = MUSE_PLAYER;
1731 player_cli_s *pc = NULL;
1732 char *ret_buf = NULL;
1733 int retry_count = CONNECTION_RETRY;
1738 pc = g_new0(player_cli_s, 1);
1740 return PLAYER_ERROR_OUT_OF_MEMORY;
1742 while (--retry_count) {
1743 sock_fd = muse_client_new();
1744 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1745 LOGE("connection failure %d", errno);
1746 ret = PLAYER_ERROR_INVALID_OPERATION;
1748 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1752 player_msg_create_handle(api, sock_fd, INT, module, INT, pid);
1754 pc->cb_info = callback_new(sock_fd);
1756 LOGE("fail to create callback");
1757 ret = PLAYER_ERROR_INVALID_OPERATION;
1761 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1762 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1768 if (!_player_event_queue_new(pc->cb_info)) {
1769 LOGE("fail to create event queue");
1770 ret = PLAYER_ERROR_INVALID_OPERATION;
1774 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1775 if (ret == PLAYER_ERROR_NONE) {
1776 intptr_t module_addr = 0;
1777 *player = (player_h) pc;
1778 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1779 pc->cb_info->data_fd = muse_client_new_data_ch();
1780 muse_core_send_module_addr(module_addr, pc->cb_info->data_fd);
1781 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1783 ret = PLAYER_ERROR_INVALID_OPERATION;
1786 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1789 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1790 pc->cb_info->evas_info = g_new0(player_evas_info_s, 1);
1791 if (pc->cb_info->evas_info == NULL) {
1792 ret = PLAYER_ERROR_OUT_OF_MEMORY;
1795 EVAS_INFO(pc)->visible = EVAS_VISIBLE_NONE;
1797 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1798 pc->push_media_stream = FALSE;
1799 pc->support_video = FALSE;
1800 EVAS_INFO(pc)->support_video = FALSE;
1801 pc->is_audio_only = FALSE;
1803 PLAYER_VIDEO_SUPPORT_CHECK(pc); /* update supported_video */
1809 if (pc && pc->cb_info) {
1810 if (pc->cb_info->event_queue.running)
1811 _player_event_queue_destroy(pc->cb_info);
1812 callback_destroy(pc->cb_info);
1817 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1826 int player_destroy(player_h player)
1828 PLAYER_INSTANCE_CHECK(player);
1830 int ret = PLAYER_ERROR_NONE;
1831 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1832 player_cli_s *pc = (player_cli_s *) player;
1833 char *ret_buf = NULL;
1837 /* clear cb and release mem */
1838 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1839 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1840 _player_release_internal_memory(pc);
1842 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1843 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
1844 if (EVAS_HANDLE(pc)) {
1845 player_unset_media_packet_video_frame_decoded_cb(player);
1846 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
1847 LOGW("fail to unset evas client");
1848 __player_unset_retrieve_buffer_cb(player);
1849 g_free(pc->cb_info->evas_info);
1853 player_msg_send(api, pc, ret_buf, ret);
1855 if (CALLBACK_INFO(pc)) {
1856 __player_remove_tsurf_list(pc);
1857 _player_remove_idle_event(CALLBACK_INFO(pc), MUSE_PLAYER_EVENT_TYPE_NUM, true);
1858 _player_event_queue_destroy(CALLBACK_INFO(pc));
1859 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
1861 callback_destroy(CALLBACK_INFO(pc));
1869 LOGD("LEAVE 0x%X", ret);
1873 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
1875 PLAYER_INSTANCE_CHECK(player);
1876 int ret = PLAYER_ERROR_NONE;
1877 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
1878 player_cli_s *pc = (player_cli_s *) player;
1879 char *ret_buf = NULL;
1883 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
1884 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
1885 return PLAYER_ERROR_INVALID_OPERATION;
1887 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
1888 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
1890 player_msg_send(api, pc, ret_buf, ret);
1891 if (ret == PLAYER_ERROR_NONE) {
1893 player_msg_get_type(timeout, ret_buf, INT);
1895 LOGD("server timeout will be %d sec", timeout);
1896 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1898 LOGW("failed to realize, so prepare cb will be released soon");
1899 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
1900 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1908 int player_prepare(player_h player)
1910 PLAYER_INSTANCE_CHECK(player);
1911 int ret = PLAYER_ERROR_NONE;
1912 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
1913 player_cli_s *pc = (player_cli_s *) player;
1914 char *ret_buf = NULL;
1918 player_msg_send(api, pc, ret_buf, ret);
1919 if (ret == PLAYER_ERROR_NONE) {
1921 player_msg_get_type(timeout, ret_buf, INT);
1923 LOGD("server timeout will be %d sec", timeout);
1924 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1931 int player_unprepare(player_h player)
1933 PLAYER_INSTANCE_CHECK(player);
1934 int ret = PLAYER_ERROR_NONE;
1935 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
1936 player_cli_s *pc = (player_cli_s *) player;
1937 char *ret_buf = NULL;
1941 if (!CALLBACK_INFO(pc))
1942 return PLAYER_ERROR_INVALID_STATE;
1944 player_msg_send(api, pc, ret_buf, ret);
1946 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1947 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1948 _player_release_internal_memory(pc);
1950 pc->cb_info->video_frame_pool_size = 0;
1951 __player_remove_tsurf_list(pc);
1952 pc->is_audio_only = FALSE;
1956 LOGD("LEAVE 0x%X", ret);
1960 /* 1. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx'
1961 * 2. remove 'file://' prefix */
1962 int _player_get_origin_internal_path(const char* uri, char* origin)
1964 gchar *file_path = NULL;
1967 if (!uri || !origin) {
1968 LOGD("invalid parameter");
1969 return PLAYER_ERROR_INVALID_PARAMETER;
1972 if (strstr(uri, "file://")) {
1973 file_path = g_filename_from_uri(uri, NULL, &err);
1975 if (!file_path || (err != NULL)) {
1976 LOGE("Invalid URI '%s', err: %s", uri,
1977 (err != NULL) ? err->message : "unknown error");
1979 if (err) g_error_free(err);
1980 if (file_path) g_free(file_path);
1982 return PLAYER_ERROR_INVALID_PARAMETER;
1984 LOGD("get file path from uri");
1987 if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, origin) < 0) {
1988 /* cannot convert path. use the original one. */
1989 strncpy(origin, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1);
1991 /* need to use converted path. */
1992 LOGD("Converted path : %s -> %s", uri, origin);
1998 return PLAYER_ERROR_NONE;
2001 int player_set_uri(player_h player, const char *uri)
2003 PLAYER_INSTANCE_CHECK(player);
2004 PLAYER_NULL_ARG_CHECK(uri);
2005 int ret = PLAYER_ERROR_NONE;
2006 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
2007 player_cli_s *pc = (player_cli_s *) player;
2008 char *ret_buf = NULL;
2009 char path[MAX_URL_LEN] = {0, };
2013 if (_player_get_origin_internal_path(uri, path) != PLAYER_ERROR_NONE)
2014 return PLAYER_ERROR_INVALID_PARAMETER;
2016 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
2017 pc->push_media_stream = FALSE;
2023 int player_set_memory_buffer(player_h player, const void *data, int size)
2025 PLAYER_INSTANCE_CHECK(player);
2026 PLAYER_NULL_ARG_CHECK(data);
2027 int ret = PLAYER_ERROR_NONE;
2028 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
2029 player_cli_s *pc = (player_cli_s *) player;
2030 char *ret_buf = NULL;
2032 tbm_bo_handle thandle;
2033 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2035 if (SERVER_TBM_BO(pc)) {
2036 LOGE("Already set the memory buffer. unprepare please");
2037 return PLAYER_ERROR_INVALID_OPERATION;
2040 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
2042 LOGE("TBM get error : bo is NULL");
2043 return PLAYER_ERROR_INVALID_OPERATION;
2045 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
2046 if (thandle.ptr == NULL) {
2047 LOGE("TBM get error : handle pointer is NULL");
2048 ret = PLAYER_ERROR_INVALID_OPERATION;
2051 memcpy(thandle.ptr, data, size);
2054 tfd = tbm_bo_export_fd(bo);
2056 LOGE("tbm_bo_export_fd err 0x%x", tfd);
2057 ret = PLAYER_ERROR_INVALID_OPERATION;
2061 player_msg_send1_fd(api, pc, ret_buf, ret, INT, size, tfd);
2062 pc->push_media_stream = FALSE;
2065 if (tfd > INVALID_DEFAULT_VALUE)
2070 if (ret == PLAYER_ERROR_NONE) {
2071 intptr_t bo_addr = 0;
2072 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
2073 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
2080 static void _player_release_internal_memory(player_cli_s * pc)
2086 _player_deinit_memory_buffer(pc);
2089 static int _player_deinit_memory_buffer(player_cli_s * pc)
2091 PLAYER_INSTANCE_CHECK(pc);
2092 int ret = PLAYER_ERROR_NONE;
2093 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
2094 intptr_t bo_addr = SERVER_TBM_BO(pc);
2099 player_msg_send1_async(api, pc, POINTER, bo_addr);
2101 SERVER_TBM_BO(pc) = 0;
2106 int player_get_state(player_h player, player_state_e * pstate)
2108 PLAYER_INSTANCE_CHECK(player);
2109 PLAYER_NULL_ARG_CHECK(pstate);
2110 int ret = PLAYER_ERROR_NONE;
2111 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
2112 player_cli_s *pc = (player_cli_s *) player;
2114 char *ret_buf = NULL;
2118 player_msg_send(api, pc, ret_buf, ret);
2120 if (ret == PLAYER_ERROR_NONE) {
2121 player_msg_get(state, ret_buf);
2129 int player_set_volume(player_h player, float left, float right)
2131 PLAYER_INSTANCE_CHECK(player);
2132 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2133 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2134 int ret = PLAYER_ERROR_NONE;
2135 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
2136 player_cli_s *pc = (player_cli_s *) player;
2137 char *ret_buf = NULL;
2141 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, right, DOUBLE, left);
2146 int player_get_volume(player_h player, float *pleft, float *pright)
2148 PLAYER_INSTANCE_CHECK(player);
2149 PLAYER_NULL_ARG_CHECK(pleft && pright);
2150 int ret = PLAYER_ERROR_NONE;
2151 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
2152 player_cli_s *pc = (player_cli_s *) player;
2155 char *ret_buf = NULL;
2159 player_msg_send(api, pc, ret_buf, ret);
2161 if (ret == PLAYER_ERROR_NONE) {
2162 bool ret_val = TRUE;
2163 player_msg_get2(ret_buf, left, DOUBLE, right, DOUBLE, ret_val);
2165 *pleft = (float)left;
2166 *pright = (float)right;
2168 LOGE("failed to get value from msg");
2169 ret = PLAYER_ERROR_INVALID_OPERATION;
2177 int player_set_sound_type(player_h player, sound_type_e type)
2179 PLAYER_INSTANCE_CHECK(player);
2180 int ret = PLAYER_ERROR_NONE;
2181 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_TYPE;
2182 player_cli_s *pc = (player_cli_s *) player;
2183 char *ret_buf = NULL;
2186 LOGW("DEPRECATION WARNING: player_set_sound_type() is deprecated and will be removed from next release. Use player_set_sound_stream_info() instead.");
2188 player_msg_send1(api, pc, ret_buf, ret, INT, type);
2193 int player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
2195 PLAYER_INSTANCE_CHECK(player);
2197 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_STREAM_INFO;
2198 player_cli_s *pc = (player_cli_s *) player;
2199 bool is_available = false;
2200 char *ret_buf = NULL;
2204 /* check if stream_info is valid */
2205 int ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
2206 if (ret != SOUND_MANAGER_ERROR_NONE) {
2207 LOGE("failed to checking available stream info");
2208 return PLAYER_ERROR_INVALID_OPERATION;
2211 if (is_available == false) {
2212 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
2214 char *stream_type = NULL;
2215 int stream_index = 0;
2216 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2217 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2218 if (ret == SOUND_MANAGER_ERROR_NONE)
2219 player_msg_send2(api, pc, ret_buf, ret, STRING, stream_type, INT, stream_index);
2221 ret = PLAYER_ERROR_INVALID_OPERATION;
2224 LOGD("LEAVE ret: 0x%X", ret);
2231 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
2233 PLAYER_INSTANCE_CHECK(player);
2234 int ret = PLAYER_ERROR_NONE;
2235 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
2236 player_cli_s *pc = (player_cli_s *) player;
2237 char *ret_buf = NULL;
2241 player_msg_send1(api, pc, ret_buf, ret, INT, latency_mode);
2246 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
2248 PLAYER_INSTANCE_CHECK(player);
2249 PLAYER_NULL_ARG_CHECK(platency_mode);
2250 int ret = PLAYER_ERROR_NONE;
2251 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
2252 player_cli_s *pc = (player_cli_s *) player;
2253 char *ret_buf = NULL;
2254 int latency_mode = -1;
2258 player_msg_send(api, pc, ret_buf, ret);
2260 if (ret == PLAYER_ERROR_NONE) {
2261 player_msg_get(latency_mode, ret_buf);
2262 *platency_mode = latency_mode;
2270 int player_start(player_h player)
2272 PLAYER_INSTANCE_CHECK(player);
2273 int ret = PLAYER_ERROR_NONE;
2274 muse_player_api_e api = MUSE_PLAYER_API_START;
2275 player_cli_s *pc = (player_cli_s *) player;
2276 char *ret_buf = NULL;
2279 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2280 if (CALLBACK_INFO(pc) && EVAS_INFO(pc)->support_video) {
2281 if (EVAS_HANDLE(pc) && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2282 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2283 ret = mm_evas_renderer_set_visible(EVAS_HANDLE(pc), true);
2284 if (ret != MM_ERROR_NONE) {
2285 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2286 return PLAYER_ERROR_INVALID_OPERATION;
2288 /* avoid setting true at all times, when player is resumed */
2289 EVAS_INFO(pc)->visible = EVAS_VISIBLE_TRUE;
2294 player_msg_send(api, pc, ret_buf, ret);
2300 int player_stop(player_h player)
2302 PLAYER_INSTANCE_CHECK(player);
2303 int ret = PLAYER_ERROR_NONE;
2304 muse_player_api_e api = MUSE_PLAYER_API_STOP;
2305 player_cli_s *pc = (player_cli_s *) player;
2306 char *ret_buf = NULL;
2307 player_state_e state = PLAYER_STATE_NONE;
2311 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
2313 /* check player state */
2314 if (ret == PLAYER_ERROR_NONE) {
2315 player_msg_get(state, ret_buf);
2319 if ((state != PLAYER_STATE_PLAYING) && (state != PLAYER_STATE_PAUSED)) {
2320 LOGE("Invalid state %d", state);
2321 return PLAYER_ERROR_INVALID_STATE;
2326 return PLAYER_ERROR_INVALID_OPERATION;
2329 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2330 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc) &&
2331 EVAS_INFO(pc)->support_video && (EVAS_INFO(pc)->visible == EVAS_VISIBLE_NONE
2332 || EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE)) {
2333 ret = mm_evas_renderer_set_visible(EVAS_HANDLE(pc), false);
2334 if (ret != MM_ERROR_NONE) {
2335 LOGE("mm_evas_renderer_set_visible err 0x%x", ret);
2336 return PLAYER_ERROR_INVALID_OPERATION;
2338 /* do not update EVAS_INFO(pc)->visible to set visible true if start again */
2342 player_msg_send(api, pc, ret_buf, ret);
2343 if (ret == PLAYER_ERROR_NONE)
2344 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2350 int player_pause(player_h player)
2352 PLAYER_INSTANCE_CHECK(player);
2353 int ret = PLAYER_ERROR_NONE;
2354 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
2355 player_cli_s *pc = (player_cli_s *) player;
2356 char *ret_buf = NULL;
2360 player_msg_send(api, pc, ret_buf, ret);
2365 int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data)
2367 PLAYER_INSTANCE_CHECK(player);
2368 PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2370 int ret = PLAYER_ERROR_NONE;
2371 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
2372 player_cli_s *pc = (player_cli_s *) player;
2373 char *ret_buf = NULL;
2374 int pos = millisecond;
2378 LOGE("cb_info is null");
2379 return PLAYER_ERROR_INVALID_OPERATION;
2382 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2383 if ((pc->push_media_stream == FALSE) &&
2384 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
2385 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
2386 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2387 return PLAYER_ERROR_SEEK_FAILED;
2389 if (pc->push_media_stream == TRUE)
2390 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP;
2392 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT;
2393 LOGI("Event type : %d, pos : %d, accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond, accurate);
2394 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2395 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2397 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2399 player_msg_send2(api, pc, ret_buf, ret, INT, pos, INT, accurate);
2401 if (ret != PLAYER_ERROR_NONE) {
2402 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2403 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2404 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2407 if (pc->push_media_stream == TRUE)
2408 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2412 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2413 pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_NONE;
2414 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2420 int player_get_play_position(player_h player, int *millisecond)
2422 PLAYER_INSTANCE_CHECK(player);
2423 PLAYER_NULL_ARG_CHECK(millisecond);
2425 int ret = PLAYER_ERROR_NONE;
2426 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2427 player_cli_s *pc = (player_cli_s *) player;
2429 char *ret_buf = NULL;
2433 player_msg_send(api, pc, ret_buf, ret);
2435 if (ret == PLAYER_ERROR_NONE) {
2436 player_msg_get(pos, ret_buf);
2444 int player_set_mute(player_h player, bool muted)
2446 PLAYER_INSTANCE_CHECK(player);
2447 int ret = PLAYER_ERROR_NONE;
2448 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2449 player_cli_s *pc = (player_cli_s *) player;
2450 char *ret_buf = NULL;
2451 int mute = (int)muted;
2455 player_msg_send1(api, pc, ret_buf, ret, INT, mute);
2460 int player_is_muted(player_h player, bool * muted)
2462 PLAYER_INSTANCE_CHECK(player);
2463 PLAYER_NULL_ARG_CHECK(muted);
2464 int ret = PLAYER_ERROR_NONE;
2465 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2466 player_cli_s *pc = (player_cli_s *) player;
2467 char *ret_buf = NULL;
2472 player_msg_send(api, pc, ret_buf, ret);
2473 if (ret == PLAYER_ERROR_NONE) {
2474 player_msg_get(mute, ret_buf);
2475 *muted = (bool) mute;
2482 int player_set_looping(player_h player, bool looping)
2484 PLAYER_INSTANCE_CHECK(player);
2485 int ret = PLAYER_ERROR_NONE;
2486 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2487 player_cli_s *pc = (player_cli_s *) player;
2488 char *ret_buf = NULL;
2492 player_msg_send1(api, pc, ret_buf, ret, INT, looping);
2497 int player_is_looping(player_h player, bool * plooping)
2499 PLAYER_INSTANCE_CHECK(player);
2500 PLAYER_NULL_ARG_CHECK(plooping);
2501 int ret = PLAYER_ERROR_NONE;
2502 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2503 player_cli_s *pc = (player_cli_s *) player;
2504 char *ret_buf = NULL;
2509 player_msg_send(api, pc, ret_buf, ret);
2510 if (ret == PLAYER_ERROR_NONE) {
2511 player_msg_get(looping, ret_buf);
2512 *plooping = looping;
2518 int player_get_duration(player_h player, int *pduration)
2520 PLAYER_INSTANCE_CHECK(player);
2521 PLAYER_NULL_ARG_CHECK(pduration);
2522 int ret = PLAYER_ERROR_NONE;
2523 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2524 player_cli_s *pc = (player_cli_s *) player;
2525 char *ret_buf = NULL;
2530 player_msg_send(api, pc, ret_buf, ret);
2531 if (ret == PLAYER_ERROR_NONE) {
2532 player_msg_get(duration, ret_buf);
2533 *pduration = duration;
2540 /* The player_display_type_e is different at wearable profile */
2541 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type)
2543 int ret = PLAYER_ERROR_NONE;
2544 PLAYER_NULL_ARG_CHECK(out_type);
2547 case PLAYER_DISPLAY_TYPE_OVERLAY:
2548 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY;
2550 case PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE:
2551 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2552 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2554 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2556 case PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS:
2557 if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
2558 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2560 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2562 case PLAYER_DISPLAY_TYPE_EVAS:
2563 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_EVAS;
2565 case PLAYER_DISPLAY_TYPE_NONE:
2566 *out_type = PLAYER_PRIVATE_DISPLAY_TYPE_NONE;
2569 ret = PLAYER_ERROR_INVALID_PARAMETER;
2573 LOGD("display type(%d) -> (%d)", type, *out_type);
2577 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2579 PLAYER_INSTANCE_CHECK(player);
2580 int ret = PLAYER_ERROR_NONE;
2581 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2582 player_cli_s *pc = (player_cli_s *) player;
2583 char *ret_buf = NULL;
2585 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2587 Evas_Object *obj = NULL;
2588 const char *object_type = NULL;
2589 wl_win_msg_type wl_win;
2590 char *wl_win_msg = (char *)&wl_win;
2591 unsigned int wl_surface_id;
2592 struct wl_surface *wl_surface;
2593 struct wl_display *wl_display;
2594 Ecore_Wl_Window *wl_window = NULL;
2596 player_private_display_type_e conv_type;
2597 player_state_e state = PLAYER_STATE_NONE;
2600 wl_win.wl_window_x = 0;
2601 wl_win.wl_window_y = 0;
2602 wl_win.wl_window_width = 0;
2603 wl_win.wl_window_height = 0;
2605 LOGD("ENTER type: %d", type);
2606 if (type == PLAYER_DISPLAY_TYPE_OBSOLETE_EVAS_WNONE ||
2607 type == PLAYER_DISPLAY_TYPE_OBSOLETE_NONE_WEVAS) {
2608 LOGW("DEPRECATION WARNING: display type(%d) is deprecated and will be removed from next release. Use newly defined type value instead.", type);
2611 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
2613 /* check player state */
2614 if (ret == PLAYER_ERROR_NONE) {
2615 player_msg_get(state, ret_buf);
2619 if (state > PLAYER_STATE_IDLE) {
2620 LOGE("Invalid state %d", state);
2621 return PLAYER_ERROR_INVALID_STATE;
2626 return PLAYER_ERROR_INVALID_OPERATION;
2629 ret = _player_convert_display_type(type, &conv_type);
2630 if (ret != PLAYER_ERROR_NONE)
2633 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_NONE) {
2634 obj = (Evas_Object *) display;
2636 return PLAYER_ERROR_INVALID_PARAMETER;
2638 object_type = evas_object_type_get(obj);
2640 if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY && !strcmp(object_type, "elm_win")) {
2641 /* wayland overlay surface */
2642 LOGI("Wayland overlay surface type");
2643 wl_win.type = conv_type;
2645 e = evas_object_evas_get(obj);
2646 return_val_if_fail(e != NULL, PLAYER_ERROR_INVALID_OPERATION);
2648 wl_window = elm_win_wl_window_get(obj);
2649 return_val_if_fail(wl_window != NULL, PLAYER_ERROR_INVALID_OPERATION);
2651 /* Need to let wayland-server know that video is rendered in this wl_window
2652 so that wayland-server sets alpha in this wl_window */
2653 ecore_wl_window_video_has(wl_window, EINA_TRUE);
2655 wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window);
2656 return_val_if_fail(wl_surface != NULL, PLAYER_ERROR_INVALID_OPERATION);
2658 /* get wl_display */
2659 wl_display = (struct wl_display *)ecore_wl_display_get();
2660 return_val_if_fail(wl_display != NULL, PLAYER_ERROR_INVALID_OPERATION);
2662 LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
2664 ret = _wl_client_create(&pc->wlclient);
2665 if (ret != MM_ERROR_NONE) {
2666 LOGE("Wayland client create failure");
2670 wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display);
2671 LOGD("wl_surface_id = %d", wl_surface_id);
2673 /* need to free always */
2675 g_free(pc->wlclient);
2676 pc->wlclient = NULL;
2678 return_val_if_fail(wl_surface_id > 0, PLAYER_ERROR_INVALID_OPERATION);
2679 wl_win.wl_surface_id = wl_surface_id;
2682 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2683 else if (conv_type == PLAYER_PRIVATE_DISPLAY_TYPE_EVAS && !strcmp(object_type, "image")) {
2684 if (!CALLBACK_INFO(pc)) {
2685 LOGE("there is no cb info in player handle");
2686 return PLAYER_ERROR_INVALID_OPERATION;
2689 /* evas object surface */
2690 LOGI("evas surface type");
2691 wl_win.type = conv_type;
2693 evas_object_geometry_get(obj, &wl_win.wl_window_x, &wl_win.wl_window_y,
2694 &wl_win.wl_window_width, &wl_win.wl_window_height);
2696 if (EVAS_HANDLE(pc)) {
2697 LOGW("evas client already exists");
2698 player_unset_media_packet_video_frame_decoded_cb(player);
2700 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2701 LOGW("fail to unset evas client");
2702 __player_unset_retrieve_buffer_cb(player);
2704 /* need to set display information again to new handle */
2705 EVAS_INFO(pc)->update_needed = TRUE;
2708 if (mm_evas_renderer_create(&EVAS_HANDLE(pc), obj) != MM_ERROR_NONE) {
2709 LOGW("fail to set evas client");
2710 return PLAYER_ERROR_INVALID_OPERATION;
2713 /* before evas handle is created, user could set display information */
2714 if (EVAS_INFO(pc)->update_needed) {
2715 LOGW("set evas information mode %d, rotation %d, visible %d", EVAS_INFO(pc)->mode,
2716 EVAS_INFO(pc)->rotation, EVAS_INFO(pc)->visible);
2717 ret = mm_evas_renderer_set_geometry(EVAS_HANDLE(pc), EVAS_INFO(pc)->mode);
2718 ret |= mm_evas_renderer_set_rotation(EVAS_HANDLE(pc), EVAS_INFO(pc)->rotation);
2719 /* if user didn't set visible, it will be set to true in player_start */
2720 if (EVAS_INFO(pc)->visible != EVAS_VISIBLE_NONE)
2721 ret |= mm_evas_renderer_set_visible(EVAS_HANDLE(pc), (EVAS_INFO(pc)->visible == EVAS_VISIBLE_TRUE) ? true : false);
2722 if (ret != MM_ERROR_NONE) {
2723 LOGW("fail to set evas information");
2724 return PLAYER_ERROR_INVALID_OPERATION;
2727 if (EVAS_INFO(pc)->mode == PLAYER_DISPLAY_MODE_DST_ROI) {
2728 LOGW("set roi (%d, %d) %d*%d", EVAS_INFO(pc)->roi_x, EVAS_INFO(pc)->roi_y,
2729 EVAS_INFO(pc)->roi_w, EVAS_INFO(pc)->roi_h);
2730 ret = mm_evas_renderer_set_roi_area(EVAS_HANDLE(pc), EVAS_INFO(pc)->roi_x, EVAS_INFO(pc)->roi_y,
2731 EVAS_INFO(pc)->roi_w, EVAS_INFO(pc)->roi_h);
2732 if (ret != MM_ERROR_NONE)
2733 return PLAYER_ERROR_INVALID_OPERATION;
2735 EVAS_INFO(pc)->update_needed = FALSE;
2738 ret = player_set_media_packet_video_frame_decoded_cb(player, mm_evas_renderer_write, (void *)EVAS_HANDLE(pc));
2739 if (ret != PLAYER_ERROR_NONE)
2740 LOGW("fail to set decoded callback");
2741 if (__player_set_retrieve_buffer_cb(player, __retrieve_buffer_cb, pc))
2742 LOGW("fail to set __retrieve_buffer_cb");
2746 return PLAYER_ERROR_INVALID_PARAMETER;
2748 return PLAYER_ERROR_INVALID_PARAMETER;
2750 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2751 LOGI("Wayland surface type is NONE");
2752 wl_win.type = conv_type;
2754 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2759 int player_set_display_mode(player_h player, player_display_mode_e mode)
2761 PLAYER_INSTANCE_CHECK(player);
2762 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2763 int ret = PLAYER_ERROR_NONE;
2764 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
2765 player_cli_s *pc = (player_cli_s *) player;
2766 char *ret_buf = NULL;
2769 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2771 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2772 if (EVAS_HANDLE(pc)) {
2773 ret = mm_evas_renderer_set_geometry(EVAS_HANDLE(pc), mode);
2774 if (ret != MM_ERROR_NONE)
2775 return PLAYER_ERROR_INVALID_OPERATION;
2777 return PLAYER_ERROR_NONE;
2779 EVAS_INFO(pc)->mode = mode;
2780 EVAS_INFO(pc)->update_needed = TRUE;
2783 player_msg_send1(api, pc, ret_buf, ret, INT, mode);
2788 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
2790 PLAYER_INSTANCE_CHECK(player);
2791 PLAYER_NULL_ARG_CHECK(pmode);
2792 int ret = PLAYER_ERROR_NONE;
2793 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
2794 player_cli_s *pc = (player_cli_s *) player;
2795 char *ret_buf = NULL;
2799 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2801 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2802 if (EVAS_HANDLE(pc)) {
2803 ret = mm_evas_renderer_get_geometry(EVAS_HANDLE(pc), &mode);
2804 *pmode = (player_display_mode_e) mode;
2805 if (ret != MM_ERROR_NONE)
2806 return PLAYER_ERROR_INVALID_OPERATION;
2808 return PLAYER_ERROR_NONE;
2811 player_msg_send(api, pc, ret_buf, ret);
2812 if (ret == PLAYER_ERROR_NONE) {
2813 player_msg_get_type(mode, ret_buf, INT);
2822 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
2824 PLAYER_INSTANCE_CHECK(player);
2825 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2827 int ret = PLAYER_ERROR_NONE;
2828 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
2829 player_cli_s *pc = (player_cli_s *) player;
2830 char *ret_buf = NULL;
2831 wl_win_msg_type wl_win;
2832 char *wl_win_msg = (char *)&wl_win;
2835 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2837 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2838 if (EVAS_HANDLE(pc)) {
2839 ret = mm_evas_renderer_set_roi_area(EVAS_HANDLE(pc), x, y, width, height);
2840 if (ret == MM_ERROR_EVASRENDER_INVALID_ARGUMENT)
2841 return PLAYER_ERROR_INVALID_PARAMETER;
2842 else if (ret != MM_ERROR_NONE)
2843 return PLAYER_ERROR_INVALID_OPERATION;
2845 return PLAYER_ERROR_NONE;
2847 EVAS_INFO(pc)->roi_x = x;
2848 EVAS_INFO(pc)->roi_y = y;
2849 EVAS_INFO(pc)->roi_w = width;
2850 EVAS_INFO(pc)->roi_h = height;
2851 EVAS_INFO(pc)->update_needed = TRUE;
2854 wl_win.wl_window_x = x;
2855 wl_win.wl_window_y = y;
2856 wl_win.wl_window_width = width;
2857 wl_win.wl_window_height = height;
2859 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2864 int player_set_playback_rate(player_h player, float rate)
2866 PLAYER_INSTANCE_CHECK(player);
2867 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2868 int ret = PLAYER_ERROR_NONE;
2869 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
2870 player_cli_s *pc = (player_cli_s *) player;
2871 char *ret_buf = NULL;
2875 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
2880 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
2882 PLAYER_INSTANCE_CHECK(player);
2883 int ret = PLAYER_ERROR_NONE;
2884 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
2885 player_cli_s *pc = (player_cli_s *) player;
2886 char *ret_buf = NULL;
2889 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2891 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2892 if (EVAS_HANDLE(pc)) {
2893 ret = mm_evas_renderer_set_rotation(EVAS_HANDLE(pc), rotation);
2894 if (ret != MM_ERROR_NONE)
2895 return PLAYER_ERROR_INVALID_OPERATION;
2897 return PLAYER_ERROR_NONE;
2899 EVAS_INFO(pc)->rotation = rotation;
2900 EVAS_INFO(pc)->update_needed = TRUE;
2903 player_msg_send1(api, pc, ret_buf, ret, INT, rotation);
2908 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
2910 PLAYER_INSTANCE_CHECK(player);
2911 PLAYER_NULL_ARG_CHECK(protation);
2912 int ret = PLAYER_ERROR_NONE;
2913 player_cli_s *pc = (player_cli_s *) player;
2914 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
2915 char *ret_buf = NULL;
2919 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2921 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2922 if (EVAS_HANDLE(pc)) {
2923 ret = mm_evas_renderer_get_rotation(EVAS_HANDLE(pc), &rotation);
2924 *protation = (player_display_rotation_e) rotation;
2925 if (ret != MM_ERROR_NONE)
2926 return PLAYER_ERROR_INVALID_OPERATION;
2928 return PLAYER_ERROR_NONE;
2931 player_msg_send(api, pc, ret_buf, ret);
2932 if (ret == PLAYER_ERROR_NONE) {
2933 player_msg_get_type(rotation, ret_buf, INT);
2934 *protation = rotation;
2941 int player_set_display_visible(player_h player, bool visible)
2943 PLAYER_INSTANCE_CHECK(player);
2944 int ret = PLAYER_ERROR_NONE;
2945 player_cli_s *pc = (player_cli_s *) player;
2946 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
2947 char *ret_buf = NULL;
2950 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2952 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2953 if (EVAS_HANDLE(pc)) {
2954 ret = mm_evas_renderer_set_visible(EVAS_HANDLE(pc), visible);
2955 if (ret != MM_ERROR_NONE)
2956 return PLAYER_ERROR_INVALID_OPERATION;
2958 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
2959 return PLAYER_ERROR_NONE;
2961 EVAS_INFO(pc)->visible = visible ? EVAS_VISIBLE_TRUE : EVAS_VISIBLE_FALSE;
2962 EVAS_INFO(pc)->update_needed = TRUE;
2966 player_msg_send1(api, pc, ret_buf, ret, INT, visible);
2971 int player_is_display_visible(player_h player, bool * pvisible)
2973 PLAYER_INSTANCE_CHECK(player);
2974 PLAYER_NULL_ARG_CHECK(pvisible);
2975 int ret = PLAYER_ERROR_NONE;
2976 player_cli_s *pc = (player_cli_s *) player;
2977 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
2978 char *ret_buf = NULL;
2980 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2984 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
2986 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2987 if (EVAS_HANDLE(pc)) {
2988 ret = mm_evas_renderer_get_visible(EVAS_HANDLE(pc), &visible);
2994 if (ret != MM_ERROR_NONE)
2995 return PLAYER_ERROR_INVALID_OPERATION;
2997 return PLAYER_ERROR_NONE;
3000 player_msg_send(api, pc, ret_buf, ret);
3001 if (ret == PLAYER_ERROR_NONE) {
3002 player_msg_get_type(value, ret_buf, INT);
3014 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
3016 PLAYER_INSTANCE_CHECK(player);
3017 PLAYER_NULL_ARG_CHECK(pvalue);
3018 int ret = PLAYER_ERROR_NONE;
3019 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
3020 player_cli_s *pc = (player_cli_s *) player;
3021 char *ret_buf = NULL;
3022 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
3026 player_msg_send1(api, pc, ret_buf, ret, INT, key);
3027 if (ret == PLAYER_ERROR_NONE) {
3028 player_msg_get_string(value, ret_buf);
3029 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
3035 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
3037 PLAYER_INSTANCE_CHECK(player);
3038 PLAYER_NULL_ARG_CHECK(paudio_codec && pvideo_codec);
3039 int ret = PLAYER_ERROR_NONE;
3040 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
3041 player_cli_s *pc = (player_cli_s *) player;
3042 char *ret_buf = NULL;
3043 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3044 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
3045 bool ret_val = TRUE;
3049 player_msg_send(api, pc, ret_buf, ret);
3050 if (ret == PLAYER_ERROR_NONE) {
3051 player_msg_get_string2(ret_buf, video_codec, audio_codec, ret_val);
3053 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
3054 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
3056 ret = PLAYER_ERROR_INVALID_OPERATION;
3063 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
3065 PLAYER_INSTANCE_CHECK(player);
3066 PLAYER_NULL_ARG_CHECK(psample_rate && pchannel && pbit_rate);
3067 int ret = PLAYER_ERROR_NONE;
3068 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
3069 player_cli_s *pc = (player_cli_s *) player;
3070 char *ret_buf = NULL;
3071 int sample_rate = 0;
3077 player_msg_send(api, pc, ret_buf, ret);
3078 if (ret == PLAYER_ERROR_NONE) {
3079 bool ret_val = TRUE;
3080 player_msg_get3(ret_buf, sample_rate, INT, channel, INT, bit_rate, INT, ret_val);
3082 *psample_rate = sample_rate;
3083 *pchannel = channel;
3084 *pbit_rate = bit_rate;
3086 ret = PLAYER_ERROR_INVALID_OPERATION;
3093 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
3095 PLAYER_INSTANCE_CHECK(player);
3096 PLAYER_NULL_ARG_CHECK(pfps && pbit_rate);
3097 int ret = PLAYER_ERROR_NONE;
3098 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
3099 player_cli_s *pc = (player_cli_s *) player;
3100 char *ret_buf = NULL;
3106 player_msg_send(api, pc, ret_buf, ret);
3107 if (ret == PLAYER_ERROR_NONE) {
3108 bool ret_val = TRUE;
3109 player_msg_get2(ret_buf, fps, INT, bit_rate, INT, ret_val);
3112 *pbit_rate = bit_rate;
3114 ret = PLAYER_ERROR_INVALID_OPERATION;
3121 int player_get_video_size(player_h player, int *pwidth, int *pheight)
3123 PLAYER_INSTANCE_CHECK(player);
3124 PLAYER_NULL_ARG_CHECK(pwidth && pheight);
3125 int ret = PLAYER_ERROR_NONE;
3126 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
3127 player_cli_s *pc = (player_cli_s *) player;
3128 char *ret_buf = NULL;
3134 player_msg_send(api, pc, ret_buf, ret);
3135 if (ret == PLAYER_ERROR_NONE) {
3136 bool ret_val = TRUE;
3137 player_msg_get2(ret_buf, width, INT, height, INT, ret_val);
3142 ret = PLAYER_ERROR_INVALID_OPERATION;
3149 int player_get_album_art(player_h player, void **palbum_art, int *psize)
3151 PLAYER_INSTANCE_CHECK(player);
3152 PLAYER_NULL_ARG_CHECK(palbum_art && psize);
3153 int ret = PLAYER_ERROR_NONE;
3154 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
3155 player_cli_s *pc = (player_cli_s *) player;
3156 char *ret_buf = NULL;
3160 tbm_bo_handle thandle;
3161 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3162 int key = INVALID_DEFAULT_VALUE;
3167 player_msg_send(api, pc, ret_buf, ret);
3168 if (ret == PLAYER_ERROR_NONE) {
3169 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
3170 jobj = muse_core_msg_object_new(ret_buf, NULL, &err);
3172 LOGE("failed to get msg obj, err:%d", err);
3173 ret = PLAYER_ERROR_INVALID_OPERATION;
3177 if (muse_core_msg_object_get_value("size", jobj, MUSE_TYPE_INT, &size) && (size > 0)) {
3178 LOGD("size : %d", size);
3179 if (!muse_core_msg_object_get_value("key", jobj, MUSE_TYPE_INT, &key)) {
3180 LOGE("failed to get key value");
3181 ret = PLAYER_ERROR_INVALID_OPERATION;
3185 tfd = pc->cb_info->tfd;
3187 LOGE("failed to get tbm fd value");
3188 ret = PLAYER_ERROR_INVALID_OPERATION;
3192 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
3194 LOGE("TBM get error : bo is NULL");
3195 ret = PLAYER_ERROR_INVALID_OPERATION;
3198 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
3199 if (thandle.ptr == NULL) {
3200 LOGE("TBM get error : handle pointer is NULL");
3201 ret = PLAYER_ERROR_INVALID_OPERATION;
3204 album_art = _get_mem(pc, size);
3206 memcpy(album_art, thandle.ptr, size);
3207 *palbum_art = album_art;
3209 LOGE("g_new failure");
3210 ret = PLAYER_ERROR_INVALID_OPERATION;
3222 muse_core_msg_object_free(jobj);
3227 if (tfd > INVALID_DEFAULT_VALUE)
3230 if (CALLBACK_INFO(pc))
3231 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
3237 if (key > INVALID_DEFAULT_VALUE) {
3238 LOGD("send msg to release buffer. key:%d", key);
3239 player_msg_send1_async(MUSE_PLAYER_API_RETURN_BUFFER, pc, INT, key);
3245 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
3247 PLAYER_INSTANCE_CHECK(player);
3248 PLAYER_NULL_ARG_CHECK(pcount);
3249 int ret = PLAYER_ERROR_NONE;
3250 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
3251 player_cli_s *pc = (player_cli_s *) player;
3252 char *ret_buf = NULL;
3257 player_msg_send(api, pc, ret_buf, ret);
3258 if (ret == PLAYER_ERROR_NONE) {
3259 player_msg_get(count, ret_buf);
3266 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
3268 PLAYER_INSTANCE_CHECK(player);
3269 PLAYER_NULL_ARG_CHECK(band_levels);
3270 int ret = PLAYER_ERROR_NONE;
3271 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
3272 player_cli_s *pc = (player_cli_s *) player;
3273 char *ret_buf = NULL;
3277 player_msg_send_array(api, pc, ret_buf, ret, band_levels, length, sizeof(int));
3284 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
3286 PLAYER_INSTANCE_CHECK(player);
3287 int ret = PLAYER_ERROR_NONE;
3288 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
3289 player_cli_s *pc = (player_cli_s *) player;
3290 char *ret_buf = NULL;
3294 player_msg_send2(api, pc, ret_buf, ret, INT, index, INT, level);
3300 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
3302 PLAYER_INSTANCE_CHECK(player);
3303 PLAYER_NULL_ARG_CHECK(plevel);
3304 int ret = PLAYER_ERROR_NONE;
3305 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
3306 player_cli_s *pc = (player_cli_s *) player;
3307 char *ret_buf = NULL;
3312 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3313 if (ret == PLAYER_ERROR_NONE) {
3314 player_msg_get(level, ret_buf);
3321 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
3323 PLAYER_INSTANCE_CHECK(player);
3324 PLAYER_NULL_ARG_CHECK(pmin && pmax);
3325 int ret = PLAYER_ERROR_NONE;
3326 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
3327 player_cli_s *pc = (player_cli_s *) player;
3328 char *ret_buf = NULL;
3329 int min = 0, max = 0;
3333 player_msg_send(api, pc, ret_buf, ret);
3334 if (ret == PLAYER_ERROR_NONE) {
3335 bool ret_val = TRUE;
3336 player_msg_get2(ret_buf, min, INT, max, INT, ret_val);
3341 ret = PLAYER_ERROR_INVALID_OPERATION;
3348 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
3350 PLAYER_INSTANCE_CHECK(player);
3351 PLAYER_NULL_ARG_CHECK(pfrequency);
3352 int ret = PLAYER_ERROR_NONE;
3353 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
3354 player_cli_s *pc = (player_cli_s *) player;
3355 char *ret_buf = NULL;
3360 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3361 if (ret == PLAYER_ERROR_NONE) {
3362 player_msg_get(frequency, ret_buf);
3363 *pfrequency = frequency;
3369 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
3371 PLAYER_INSTANCE_CHECK(player);
3372 PLAYER_NULL_ARG_CHECK(prange);
3373 int ret = PLAYER_ERROR_NONE;
3374 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
3375 player_cli_s *pc = (player_cli_s *) player;
3376 char *ret_buf = NULL;
3381 player_msg_send1(api, pc, ret_buf, ret, INT, index);
3382 if (ret == PLAYER_ERROR_NONE) {
3383 player_msg_get(range, ret_buf);
3390 int player_audio_effect_equalizer_clear(player_h player)
3392 PLAYER_INSTANCE_CHECK(player);
3393 int ret = PLAYER_ERROR_NONE;
3394 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
3395 player_cli_s *pc = (player_cli_s *) player;
3396 char *ret_buf = NULL;
3400 player_msg_send(api, pc, ret_buf, ret);
3405 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
3407 PLAYER_INSTANCE_CHECK(player);
3408 PLAYER_NULL_ARG_CHECK(pavailable);
3409 int ret = PLAYER_ERROR_NONE;
3410 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
3411 player_cli_s *pc = (player_cli_s *) player;
3412 char *ret_buf = NULL;
3417 player_msg_send(api, pc, ret_buf, ret);
3418 if (ret == PLAYER_ERROR_NONE) {
3419 player_msg_get(available, ret_buf);
3420 *pavailable = available;
3426 int player_set_subtitle_path(player_h player, const char *path)
3428 PLAYER_INSTANCE_CHECK(player);
3429 int ret = PLAYER_ERROR_NONE;
3430 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
3431 player_cli_s *pc = (player_cli_s *) player;
3432 char *ret_buf = NULL;
3433 char subtitle_path[MAX_URL_LEN] = {0, };
3437 if (path && _player_get_origin_internal_path(path, subtitle_path) != PLAYER_ERROR_NONE)
3438 return PLAYER_ERROR_INVALID_PARAMETER;
3440 player_msg_send1(api, pc, ret_buf, ret, STRING, subtitle_path);
3445 int player_set_subtitle_position_offset(player_h player, int millisecond)
3447 PLAYER_INSTANCE_CHECK(player);
3448 int ret = PLAYER_ERROR_NONE;
3449 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
3450 player_cli_s *pc = (player_cli_s *) player;
3451 char *ret_buf = NULL;
3455 player_msg_send1(api, pc, ret_buf, ret, INT, millisecond);
3461 int player_set_progressive_download_path(player_h player, const char *path)
3463 PLAYER_INSTANCE_CHECK(player);
3464 PLAYER_NULL_ARG_CHECK(path);
3465 int ret = PLAYER_ERROR_NONE;
3466 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
3467 player_cli_s *pc = (player_cli_s *) player;
3468 char *ret_buf = NULL;
3469 char dw_path[MAX_URL_LEN] = {0, };
3472 LOGW("DEPRECATION WARNING: player_set_progressive_download_path() is deprecated and will be removed from next release.");
3474 if (!_player_check_network_availability())
3475 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3477 if (_player_get_origin_internal_path(path, dw_path) != PLAYER_ERROR_NONE)
3478 return PLAYER_ERROR_INVALID_PARAMETER;
3480 player_msg_send1(api, pc, ret_buf, ret, STRING, dw_path);
3485 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
3487 PLAYER_INSTANCE_CHECK(player);
3488 PLAYER_NULL_ARG_CHECK(pcurrent && ptotal_size);
3489 int ret = PLAYER_ERROR_NONE;
3490 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
3491 player_cli_s *pc = (player_cli_s *) player;
3492 char *ret_buf = NULL;
3493 unsigned long current, total_size;
3496 LOGW("DEPRECATION WARNING: player_get_progressive_download_status() is deprecated and will be removed from next release.");
3498 player_msg_send(api, pc, ret_buf, ret);
3499 if (ret == PLAYER_ERROR_NONE) {
3500 bool ret_val = TRUE;
3501 player_msg_get2(ret_buf, current, POINTER, total_size, POINTER, ret_val);
3503 *pcurrent = current;
3504 *ptotal_size = total_size;
3506 ret = PLAYER_ERROR_INVALID_OPERATION;
3514 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
3516 PLAYER_INSTANCE_CHECK(player);
3517 PLAYER_NULL_ARG_CHECK(callback);
3518 int ret = PLAYER_ERROR_NONE;
3519 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
3520 player_cli_s *pc = (player_cli_s *) player;
3521 char *ret_buf = NULL;
3524 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
3525 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
3526 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
3528 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3529 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
3530 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
3533 player_msg_send(api, pc, ret_buf, ret);
3535 if (ret != PLAYER_ERROR_NONE)
3536 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
3542 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
3544 PLAYER_INSTANCE_CHECK(player);
3545 PLAYER_NULL_ARG_CHECK(cookie);
3546 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3547 int ret = PLAYER_ERROR_NONE;
3548 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
3549 player_cli_s *pc = (player_cli_s *) player;
3550 char *ret_buf = NULL;
3554 player_msg_send2(api, pc, ret_buf, ret, STRING, cookie, INT, size);
3559 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3561 PLAYER_INSTANCE_CHECK(player);
3562 PLAYER_NULL_ARG_CHECK(user_agent);
3563 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3564 int ret = PLAYER_ERROR_NONE;
3565 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3566 player_cli_s *pc = (player_cli_s *) player;
3567 char *ret_buf = NULL;
3571 player_msg_send2(api, pc, ret_buf, ret, STRING, user_agent, INT, size);
3576 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3578 PLAYER_INSTANCE_CHECK(player);
3579 PLAYER_NULL_ARG_CHECK(pstart && pcurrent);
3580 int ret = PLAYER_ERROR_NONE;
3581 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3582 player_cli_s *pc = (player_cli_s *) player;
3583 char *ret_buf = NULL;
3584 int start = 0, current = 0;
3588 player_msg_send(api, pc, ret_buf, ret);
3589 if (ret == PLAYER_ERROR_NONE) {
3590 bool ret_val = TRUE;
3591 player_msg_get2(ret_buf, start, INT, current, INT, ret_val);
3594 *pcurrent = current;
3596 ret = PLAYER_ERROR_INVALID_OPERATION;
3604 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3606 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3609 #ifdef TIZEN_FEATURE_EVAS_RENDERER
3610 static void __retrieve_buffer_cb(void *user_data)
3612 player_cli_s *player = (player_cli_s *)user_data;
3613 int ret = PLAYER_ERROR_NONE;
3614 bool gapless = false;
3616 ret = player_is_gapless((player_h)user_data, &gapless);
3617 if (ret != PLAYER_ERROR_NONE) {
3618 LOGW("player_is_gapless is failed");
3622 ret = mm_evas_renderer_retrieve_all_packets(EVAS_HANDLE(player), gapless);
3623 if (ret != PLAYER_ERROR_NONE)
3624 LOGI("mm_evas_renderer_retrieve_all_packets returned error");
3627 static int __player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
3629 return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
3632 static int __player_unset_retrieve_buffer_cb(player_h player)
3634 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
3638 int player_unset_completed_cb(player_h player)
3640 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3643 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3645 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3648 int player_unset_interrupted_cb(player_h player)
3650 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3653 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3655 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3658 int player_unset_error_cb(player_h player)
3660 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3663 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3665 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3668 int player_unset_buffering_cb(player_h player)
3670 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3673 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3675 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3678 int player_unset_subtitle_updated_cb(player_h player)
3680 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3683 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3685 PLAYER_INSTANCE_CHECK(player);
3686 PLAYER_NULL_ARG_CHECK(callback);
3687 int ret = PLAYER_ERROR_NONE;
3688 player_cli_s *pc = (player_cli_s *) player;
3689 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3690 char *ret_buf = NULL;
3691 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3695 LOGW("DEPRECATION WARNING: player_set_progressive_download_message_cb() is deprecated and will be removed from next release.");
3697 if (!_player_check_network_availability())
3698 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
3700 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3702 if (ret == PLAYER_ERROR_NONE) {
3703 pc->cb_info->user_cb[type] = callback;
3704 pc->cb_info->user_data[type] = user_data;
3705 LOGI("Event type : %d ", type);
3712 int player_unset_progressive_download_message_cb(player_h player)
3714 PLAYER_INSTANCE_CHECK(player);
3715 int ret = PLAYER_ERROR_NONE;
3716 player_cli_s *pc = (player_cli_s *) player;
3717 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3718 char *ret_buf = NULL;
3719 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3723 LOGW("DEPRECATION WARNING: player_unset_progressive_download_message_cb() is deprecated and will be removed from next release.");
3725 set_null_user_cb_lock(pc->cb_info, type);
3727 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3734 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
3736 PLAYER_INSTANCE_CHECK(player);
3737 PLAYER_NULL_ARG_CHECK(callback);
3738 int ret = PLAYER_ERROR_NONE;
3739 player_cli_s *pc = (player_cli_s *) player;
3740 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3741 char *ret_buf = NULL;
3742 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3747 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3749 if (ret == PLAYER_ERROR_NONE) {
3750 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
3751 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
3752 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
3759 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
3761 PLAYER_INSTANCE_CHECK(player);
3762 int ret = PLAYER_ERROR_NONE;
3763 player_cli_s *pc = (player_cli_s *) player;
3764 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3765 char *ret_buf = NULL;
3766 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3771 set_null_user_cb_lock(pc->cb_info, type);
3773 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3779 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
3781 PLAYER_INSTANCE_CHECK(player);
3782 PLAYER_NULL_ARG_CHECK(callback);
3783 int ret = PLAYER_ERROR_NONE;
3784 player_cli_s *pc = (player_cli_s *) player;
3785 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3786 char *ret_buf = NULL;
3787 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3792 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3794 if (ret == PLAYER_ERROR_NONE) {
3795 pc->cb_info->user_cb[type] = callback;
3796 pc->cb_info->user_data[type] = user_data;
3797 LOGI("Event type : %d ", type);
3804 int player_unset_video_stream_changed_cb(player_h player)
3806 PLAYER_INSTANCE_CHECK(player);
3807 int ret = PLAYER_ERROR_NONE;
3808 player_cli_s *pc = (player_cli_s *) player;
3809 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3810 char *ret_buf = NULL;
3811 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3816 set_null_user_cb_lock(pc->cb_info, type);
3818 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3824 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)
3826 PLAYER_INSTANCE_CHECK(player);
3827 PLAYER_NULL_ARG_CHECK(callback);
3828 int ret = PLAYER_ERROR_NONE;
3829 player_cli_s *pc = (player_cli_s *) player;
3830 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3831 char *ret_buf = NULL;
3832 muse_player_event_e type;
3837 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3838 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3839 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3840 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3842 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3843 return PLAYER_ERROR_INVALID_PARAMETER;
3846 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3848 if (ret == PLAYER_ERROR_NONE) {
3849 pc->cb_info->user_cb[type] = callback;
3850 pc->cb_info->user_data[type] = user_data;
3851 LOGI("Event type : %d ", type);
3858 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
3860 PLAYER_INSTANCE_CHECK(player);
3861 int ret = PLAYER_ERROR_NONE;
3862 player_cli_s *pc = (player_cli_s *) player;
3863 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3864 char *ret_buf = NULL;
3865 muse_player_event_e type;
3870 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3871 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3872 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3873 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3875 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3876 return PLAYER_ERROR_INVALID_PARAMETER;
3879 set_null_user_cb_lock(pc->cb_info, type);
3881 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3887 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)
3889 PLAYER_INSTANCE_CHECK(player);
3890 PLAYER_NULL_ARG_CHECK(callback);
3891 int ret = PLAYER_ERROR_NONE;
3892 player_cli_s *pc = (player_cli_s *) player;
3893 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3894 char *ret_buf = NULL;
3895 muse_player_event_e type;
3900 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3901 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3902 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3903 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3905 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3906 return PLAYER_ERROR_INVALID_PARAMETER;
3909 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3911 if (ret == PLAYER_ERROR_NONE) {
3912 pc->cb_info->user_cb[type] = callback;
3913 pc->cb_info->user_data[type] = user_data;
3914 LOGI("Event type : %d ", type);
3921 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
3923 PLAYER_INSTANCE_CHECK(player);
3924 int ret = PLAYER_ERROR_NONE;
3925 player_cli_s *pc = (player_cli_s *) player;
3926 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3927 char *ret_buf = NULL;
3928 muse_player_event_e type;
3933 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3934 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3935 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3936 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3938 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3939 return PLAYER_ERROR_INVALID_PARAMETER;
3942 set_null_user_cb_lock(pc->cb_info, type);
3944 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3950 /* TODO Implement raw data socket channel */
3951 int player_push_media_stream(player_h player, media_packet_h packet)
3953 PLAYER_INSTANCE_CHECK(player);
3954 PLAYER_NULL_ARG_CHECK(packet);
3955 int ret = PLAYER_ERROR_NONE;
3956 player_cli_s *pc = (player_cli_s *) player;
3957 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
3958 char *ret_buf = NULL;
3959 player_push_media_msg_type push_media;
3960 char *push_media_msg = (char *)&push_media;
3961 int msg_size = sizeof(player_push_media_msg_type);
3965 tbm_bo_handle thandle;
3966 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3969 media_format_h format;
3975 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
3976 media_packet_get_buffer_size(packet, &push_media.size);
3977 media_packet_get_pts(packet, &push_media.pts);
3978 media_packet_get_format(packet, &format);
3979 media_packet_get_flags(packet, &push_media.flags);
3981 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
3983 media_packet_is_video(packet, &is_video);
3984 media_packet_is_audio(packet, &is_audio);
3986 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
3988 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
3990 media_format_unref(format);
3993 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
3994 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
3996 LOGE("TBM get error : bo is NULL");
3997 return PLAYER_ERROR_INVALID_OPERATION;
3999 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
4000 if (thandle.ptr == NULL) {
4001 LOGE("TBM get error : handle pointer is NULL");
4002 ret = PLAYER_ERROR_INVALID_OPERATION;
4005 memcpy(thandle.ptr, buf, push_media.size);
4008 tfd = tbm_bo_export_fd(bo);
4010 LOGE("tbm_bo_export_fd err 0x%x", tfd);
4011 ret = PLAYER_ERROR_INVALID_OPERATION;
4015 player_msg_send_array_fd(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), tfd);
4016 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
4017 buf_size = (int)push_media.size;
4018 player_msg_send_array2(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), buf, buf_size, sizeof(char));
4021 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
4022 buf_size = (int)push_media.size;
4023 muse_client_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts);
4024 player_msg_send_array(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char));
4027 LOGD("ret_buf %s", ret_buf);
4031 if (tfd > INVALID_DEFAULT_VALUE)
4034 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
4042 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
4044 PLAYER_INSTANCE_CHECK(player);
4045 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
4046 int ret = PLAYER_ERROR_NONE;
4047 player_cli_s *pc = (player_cli_s *) player;
4048 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
4049 char *ret_buf = NULL;
4050 media_format_mimetype_e mimetype;
4062 media_format_ref(format);
4063 if (type == PLAYER_STREAM_TYPE_VIDEO) {
4064 if (media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps) != MEDIA_FORMAT_ERROR_NONE ||
4065 media_format_get_video_frame_rate(format, &frame_rate) != MEDIA_FORMAT_ERROR_NONE) {
4066 LOGE("failed to get video info from format.");
4067 return PLAYER_ERROR_INVALID_PARAMETER;
4070 player_msg_send7(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, width, INT, height, INT, avg_bps, INT, max_bps, INT, frame_rate);
4071 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
4072 if (media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
4073 LOGE("failed to get audio info from format.");
4074 return PLAYER_ERROR_INVALID_PARAMETER;
4076 player_msg_send6(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, channel, INT, samplerate, INT, avg_bps, INT, bit);
4078 media_format_unref(format);
4079 pc->push_media_stream = TRUE;
4085 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
4087 int ret = PLAYER_ERROR_NONE;
4088 PLAYER_INSTANCE_CHECK(player);
4089 player_cli_s *pc = (player_cli_s *) player;
4090 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4091 char *ret_buf = NULL;
4095 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT64, max_size);
4101 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
4103 int ret = PLAYER_ERROR_NONE;
4104 PLAYER_INSTANCE_CHECK(player);
4105 PLAYER_NULL_ARG_CHECK(pmax_size);
4106 player_cli_s *pc = (player_cli_s *) player;
4107 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
4108 char *ret_buf = NULL;
4109 unsigned long long max_size;
4113 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4114 if (ret == PLAYER_ERROR_NONE) {
4115 player_msg_get_type(max_size, ret_buf, INT64);
4116 *pmax_size = max_size;
4122 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
4124 int ret = PLAYER_ERROR_NONE;
4125 PLAYER_INSTANCE_CHECK(player);
4126 player_cli_s *pc = (player_cli_s *) player;
4127 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4128 char *ret_buf = NULL;
4132 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, percent);
4138 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
4140 int ret = PLAYER_ERROR_NONE;
4141 PLAYER_INSTANCE_CHECK(player);
4142 PLAYER_NULL_ARG_CHECK(ppercent);
4143 player_cli_s *pc = (player_cli_s *) player;
4144 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
4145 char *ret_buf = NULL;
4150 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4151 if (ret == PLAYER_ERROR_NONE) {
4152 player_msg_get(percent, ret_buf);
4153 *ppercent = percent;
4160 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
4162 PLAYER_INSTANCE_CHECK(player);
4163 PLAYER_NULL_ARG_CHECK(pcount);
4164 int ret = PLAYER_ERROR_NONE;
4165 player_cli_s *pc = (player_cli_s *) player;
4166 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
4167 char *ret_buf = NULL;
4172 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4173 if (ret == PLAYER_ERROR_NONE) {
4174 player_msg_get(count, ret_buf);
4182 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
4184 PLAYER_INSTANCE_CHECK(player);
4185 PLAYER_NULL_ARG_CHECK(pindex);
4186 int ret = PLAYER_ERROR_NONE;
4187 player_cli_s *pc = (player_cli_s *) player;
4188 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
4189 char *ret_buf = NULL;
4194 player_msg_send1(api, pc, ret_buf, ret, INT, type);
4195 if (ret == PLAYER_ERROR_NONE) {
4196 player_msg_get(index, ret_buf);
4204 int player_select_track(player_h player, player_stream_type_e type, int index)
4206 PLAYER_INSTANCE_CHECK(player);
4207 int ret = PLAYER_ERROR_NONE;
4208 player_cli_s *pc = (player_cli_s *) player;
4209 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
4210 char *ret_buf = NULL;
4214 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
4220 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
4222 PLAYER_INSTANCE_CHECK(player);
4223 PLAYER_NULL_ARG_CHECK(pcode);
4224 int ret = PLAYER_ERROR_NONE;
4225 player_cli_s *pc = (player_cli_s *) player;
4226 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
4227 char *ret_buf = NULL;
4228 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
4233 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
4234 if (ret == PLAYER_ERROR_NONE) {
4235 bool recv_ret = TRUE;
4236 player_msg_get1_string(ret_buf, code_len, INT, code, recv_ret);
4238 *pcode = strndup(code, code_len);
4240 ret = PLAYER_ERROR_INVALID_OPERATION;
4246 int player_foreach_adaptive_variant(player_h player, player_adaptive_variant_cb callback, void *user_data)
4248 PLAYER_INSTANCE_CHECK(player);
4249 PLAYER_NULL_ARG_CHECK(callback);
4250 int ret = PLAYER_ERROR_NONE;
4251 player_cli_s *pc = (player_cli_s *) player;
4252 muse_player_api_e api = MUSE_PLAYER_API_GET_ADAPTIVE_VARIANT_INFO;
4253 char *ret_buf = NULL;
4254 char var_info[MUSE_MSG_MAX_LENGTH] = { 0, };
4255 int idx = 0, num = 0;
4256 int bandwidth = 0, width = 0, height = 0;
4262 player_msg_send(api, pc, ret_buf, ret);
4263 if (ret == PLAYER_ERROR_NONE) {
4264 player_msg_get_type(num, ret_buf, INT);
4266 player_msg_get_string(var_info, ret_buf);
4268 LOGW("There is no stream variant info.");
4271 for (idx = 0 ; idx < num ; idx++) {
4272 bandwidth = width = height = 0;
4274 token = strtok_r((ptr != NULL) ? (NULL) : (var_info), ",", &ptr);
4276 bandwidth = atoi(token);
4278 token = strtok_r(NULL, ",", &ptr);
4280 width = atoi(token);
4282 token = strtok_r(NULL, ",", &ptr);
4284 height = atoi(token);
4286 callback(bandwidth, width, height, user_data);
4289 LOGD("LEAVE 0x%X", ret);
4294 int player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
4296 int ret = PLAYER_ERROR_NONE;
4297 PLAYER_INSTANCE_CHECK(player);
4298 player_cli_s *pc = (player_cli_s *) player;
4299 muse_player_api_e api = MUSE_PLAYER_API_SET_MAX_ADAPTIVE_VARIANT_LIMIT;
4300 char *ret_buf = NULL;
4304 player_msg_send3(api, pc, ret_buf, ret, INT, bandwidth, INT, width, INT, height);
4307 LOGD("LEAVE 0x%X", ret);
4312 int player_get_max_adaptive_variant_limit(player_h player, int *pbandwidth, int *pwidth, int *pheight)
4314 int ret = PLAYER_ERROR_NONE;
4315 PLAYER_INSTANCE_CHECK(player);
4316 PLAYER_NULL_ARG_CHECK(pbandwidth || pwidth || pheight);
4318 player_cli_s *pc = (player_cli_s *) player;
4319 muse_player_api_e api = MUSE_PLAYER_API_GET_MAX_ADAPTIVE_VARIANT_LIMIT;
4320 char *ret_buf = NULL;
4321 int bandwidth = -1, width = -1, height = -1;
4325 player_msg_send(api, pc, ret_buf, ret);
4326 if (ret == PLAYER_ERROR_NONE) {
4327 bool ret_val = TRUE;
4329 player_msg_get3(ret_buf, bandwidth, INT, width, INT, height, INT, ret_val);
4331 if (pbandwidth) *pbandwidth = bandwidth;
4332 if (pwidth) *pwidth = width;
4333 if (pheight) *pheight = height;
4335 ret = PLAYER_ERROR_INVALID_OPERATION;
4340 LOGD("LEAVE 0x%X", ret);
4344 int player_set_audio_only(player_h player, bool audio_only)
4346 int ret = PLAYER_ERROR_NONE;
4347 PLAYER_INSTANCE_CHECK(player);
4348 player_cli_s *pc = (player_cli_s *) player;
4349 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_ONLY;
4350 char *ret_buf = NULL;
4351 player_state_e state = PLAYER_STATE_NONE;
4353 LOGD("ENTER audio_only: %d", audio_only);
4355 player_msg_send(MUSE_PLAYER_API_GET_STATE, pc, ret_buf, ret);
4357 /* check player state */
4358 if (ret == PLAYER_ERROR_NONE) {
4359 player_msg_get(state, ret_buf);
4363 if (state < PLAYER_STATE_READY) {
4364 LOGE("Invalid state %d", state);
4365 return PLAYER_ERROR_INVALID_STATE;
4370 return PLAYER_ERROR_INVALID_OPERATION;
4373 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4374 if (EVAS_HANDLE(pc)) {
4375 pc->is_audio_only = (gboolean)audio_only;
4376 return PLAYER_ERROR_NONE;
4379 player_msg_send1(api, pc, ret_buf, ret, INT, audio_only);
4382 LOGD("LEAVE 0x%X", ret);
4387 int player_is_audio_only(player_h player, bool *paudio_only)
4389 PLAYER_INSTANCE_CHECK(player);
4390 PLAYER_NULL_ARG_CHECK(paudio_only);
4391 int ret = PLAYER_ERROR_NONE;
4392 muse_player_api_e api = MUSE_PLAYER_API_IS_AUDIO_ONLY;
4393 player_cli_s *pc = (player_cli_s *) player;
4394 char *ret_buf = NULL;
4398 #ifdef TIZEN_FEATURE_EVAS_RENDERER
4399 if (EVAS_HANDLE(pc)) {
4400 *paudio_only = (bool)pc->is_audio_only;
4401 return PLAYER_ERROR_NONE;
4405 player_msg_send(api, pc, ret_buf, ret);
4406 if (ret == PLAYER_ERROR_NONE) {
4407 player_msg_get(audio_only, ret_buf);
4408 *paudio_only = (bool)audio_only;
4412 LOGD("LEAVE 0x%X", ret);
4416 int player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
4418 int ret = PLAYER_ERROR_NONE;
4419 PLAYER_INSTANCE_CHECK(player);
4420 player_cli_s *pc = (player_cli_s *) player;
4421 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_BUFFERING_TIME;
4422 char *ret_buf = NULL;
4426 player_msg_send2(api, pc, ret_buf, ret, INT, buffer_ms, INT, rebuffer_ms);
4429 LOGD("LEAVE 0x%X", ret);
4433 int player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
4435 PLAYER_INSTANCE_CHECK(player);
4436 PLAYER_NULL_ARG_CHECK(buffer_ms || rebuffer_ms);
4438 int ret = PLAYER_ERROR_NONE;
4439 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_BUFFERING_TIME;
4440 player_cli_s *pc = (player_cli_s *) player;
4441 int buffering_time = 0, rebuffering_time = 0;
4442 char *ret_buf = NULL;
4446 player_msg_send(api, pc, ret_buf, ret);
4448 if (ret == PLAYER_ERROR_NONE) {
4449 bool ret_val = true;
4451 player_msg_get2(ret_buf, buffering_time, INT, rebuffering_time, INT, ret_val);
4453 if (buffer_ms) *buffer_ms = buffering_time;
4454 if (rebuffer_ms) *rebuffer_ms = rebuffering_time;
4456 ret = PLAYER_ERROR_INVALID_OPERATION;
4462 LOGD("LEAVE 0x%X", ret);
4466 int player_360_set_enable(player_h player, bool enable)
4468 PLAYER_INSTANCE_CHECK(player);
4469 int ret = PLAYER_ERROR_NONE;
4470 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ENABLE;
4471 player_cli_s *pc = (player_cli_s *) player;
4472 char *ret_buf = NULL;
4473 int val = (int)enable;
4475 LOGD("ENTER %d", enable);
4477 player_msg_send1(api, pc, ret_buf, ret, INT, val);
4480 LOGD("LEAVE 0x%X", ret);
4484 int player_360_is_enabled(player_h player, bool *enabled)
4486 PLAYER_INSTANCE_CHECK(player);
4487 PLAYER_NULL_ARG_CHECK(enabled);
4488 int ret = PLAYER_ERROR_NONE;
4489 muse_player_api_e api = MUSE_PLAYER_API_360_IS_ENABLED;
4490 player_cli_s *pc = (player_cli_s *) player;
4491 char *ret_buf = NULL;
4496 player_msg_send(api, pc, ret_buf, ret);
4497 if (ret == PLAYER_ERROR_NONE) {
4498 player_msg_get(val, ret_buf);
4503 LOGD("LEAVE 0x%X", ret);
4507 int player_360_set_direction_of_view(player_h player, float yaw, float pitch)
4509 PLAYER_INSTANCE_CHECK(player);
4510 int ret = PLAYER_ERROR_NONE;
4511 muse_player_api_e api = MUSE_PLAYER_API_360_SET_DIRECTION_OF_VIEW;
4512 player_cli_s *pc = (player_cli_s *) player;
4513 char *ret_buf = NULL;
4515 LOGD("ENTER %f %f", yaw, pitch);
4517 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, yaw, DOUBLE, pitch);
4520 LOGD("LEAVE 0x%X", ret);
4524 int player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
4526 PLAYER_INSTANCE_CHECK(player);
4527 PLAYER_NULL_ARG_CHECK(yaw && pitch);
4528 int ret = PLAYER_ERROR_NONE;
4529 muse_player_api_e api = MUSE_PLAYER_API_360_GET_DIRECTION_OF_VIEW;
4530 player_cli_s *pc = (player_cli_s *) player;
4531 double yaw_val = -1;
4532 double pitch_val = -1;
4533 char *ret_buf = NULL;
4537 player_msg_send(api, pc, ret_buf, ret);
4539 if (ret == PLAYER_ERROR_NONE) {
4540 bool ret_val = TRUE;
4541 player_msg_get2(ret_buf, yaw_val, DOUBLE, pitch_val, DOUBLE, ret_val);
4543 *yaw = (float)yaw_val;
4544 *pitch = (float)pitch_val;
4546 LOGE("failed to get value from msg");
4547 ret = PLAYER_ERROR_INVALID_OPERATION;
4553 LOGD("LEAVE 0x%X", ret);
4557 int player_360_set_zoom(player_h player, float level)
4559 PLAYER_INSTANCE_CHECK(player);
4560 int ret = PLAYER_ERROR_NONE;
4561 muse_player_api_e api = MUSE_PLAYER_API_360_SET_ZOOM;
4562 player_cli_s *pc = (player_cli_s *) player;
4563 char *ret_buf = NULL;
4565 LOGD("ENTER %f", level);
4567 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, level);
4570 LOGD("LEAVE 0x%X", ret);
4574 int player_360_get_zoom(player_h player, float *level)
4576 PLAYER_INSTANCE_CHECK(player);
4577 PLAYER_NULL_ARG_CHECK(level);
4578 int ret = PLAYER_ERROR_NONE;
4579 muse_player_api_e api = MUSE_PLAYER_API_360_GET_ZOOM;
4580 player_cli_s *pc = (player_cli_s *) player;
4582 char *ret_buf = NULL;
4586 player_msg_send(api, pc, ret_buf, ret);
4588 if (ret == PLAYER_ERROR_NONE) {
4589 if (player_msg_get_type(zoom, ret_buf, DOUBLE)) {
4590 *level = (float)zoom;
4592 LOGE("failed to get value from msg");
4593 ret = PLAYER_ERROR_INVALID_OPERATION;
4599 LOGD("LEAVE 0x%X", ret);
4604 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
4606 PLAYER_INSTANCE_CHECK(player);
4607 int ret = PLAYER_ERROR_NONE;
4608 muse_player_api_e api = MUSE_PLAYER_API_360_SET_FIELD_OF_VIEW;
4609 player_cli_s *pc = (player_cli_s *) player;
4610 char *ret_buf = NULL;
4612 LOGD("ENTER %d %d", horizontal_degrees, vertical_degrees);
4614 player_msg_send2(api, pc, ret_buf, ret, INT, horizontal_degrees, INT, vertical_degrees);
4617 LOGD("LEAVE 0x%X", ret);
4621 int player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
4623 PLAYER_INSTANCE_CHECK(player);
4624 PLAYER_NULL_ARG_CHECK(horizontal_degrees && vertical_degrees);
4625 int ret = PLAYER_ERROR_NONE;
4626 muse_player_api_e api = MUSE_PLAYER_API_360_GET_FIELD_OF_VIEW;
4627 player_cli_s *pc = (player_cli_s *) player;
4630 char *ret_buf = NULL;
4634 player_msg_send(api, pc, ret_buf, ret);
4636 if (ret == PLAYER_ERROR_NONE) {
4637 bool ret_val = TRUE;
4638 player_msg_get2(ret_buf, h_val, INT, v_val, INT, ret_val);
4640 *horizontal_degrees = h_val;
4641 *vertical_degrees = v_val;
4643 LOGE("failed to get value from msg");
4644 ret = PLAYER_ERROR_INVALID_OPERATION;
4650 LOGD("LEAVE 0x%X", ret);