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_core_msg_json.h>
33 #include <muse_core_module.h>
34 #include <muse_core_ipc.h>
35 #include <muse_player.h>
36 #include <muse_player_msg.h>
37 #include <sound_manager.h>
38 #include <sound_manager_internal.h>
39 #include <tzplatform_config.h>
40 #include "player_internal.h"
41 #include "player_private.h"
42 #include "player_display.h"
43 #include "player_msg.h"
44 #ifdef TIZEN_FEATURE_EVAS_RENDERER
45 #include <mm_evas_renderer.h>
48 #define INVALID_DEFAULT_VALUE -1
53 callback_cb_info_s *cb_info;
60 } _media_pkt_fin_data;
67 * Internal Implementation
69 static int _player_deinit_memory_buffer(player_cli_s * pc);
71 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
73 int ret = MEDIA_PACKET_FINALIZE;
74 muse_player_api_e api = MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB;
75 _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
81 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
85 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
86 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
90 if (!fin_data->use_tsurf_pool) {
91 tbm_surface_h tsurf = NULL;
92 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
93 LOGE("media_packet_get_tbm_surface failed");
94 /* continue the remained job */
97 LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf);
98 tbm_surface_destroy(tsurf);
102 /* Do not destroy tbm surface here to reuse during playback *
103 * they will be destroyed at player_unprepare() or player_destroy(). *
104 * ref: __player_remove_tsurf_list() */
106 tbm_surface_h tsurf = NULL;
108 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
109 LOGD("tsurf set to null %p", tsurf);
114 packet = fin_data->remote_pkt;
115 snd_msg = muse_core_msg_json_factory_new(api, MUSE_TYPE_POINTER, "packet", packet, 0);
116 snd_len = muse_core_ipc_send_msg(fin_data->fd, snd_msg);
117 muse_core_msg_json_factory_free(snd_msg);
120 LOGE("fail to send msg.");
131 static int __player_convert_error_code(int code, char *func_name)
133 int ret = PLAYER_ERROR_INVALID_OPERATION;
134 char *msg = "PLAYER_ERROR_INVALID_OPERATION";
137 case MM_ERROR_PLAYER_AUDIO_CODEC_NOT_FOUND:
138 case MM_ERROR_PLAYER_VIDEO_CODEC_NOT_FOUND:
139 ret = PLAYER_ERROR_NONE;
140 msg = "PLAYER_ERROR_NONE";
142 case MM_ERROR_INVALID_ARGUMENT:
143 ret = PLAYER_ERROR_INVALID_PARAMETER;
144 msg = "PLAYER_ERROR_INVALID_PARAMETER";
146 case MM_ERROR_PLAYER_CODEC_NOT_FOUND:
147 case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_AUDIO:
148 case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_VIDEO:
149 case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_MEDIA_TYPE:
150 case MM_ERROR_PLAYER_NOT_SUPPORTED_FORMAT:
151 ret = PLAYER_ERROR_NOT_SUPPORTED_FILE;
152 msg = "PLAYER_ERROR_NOT_SUPPORTED_FILE";
154 case MM_ERROR_PLAYER_INVALID_STATE:
155 case MM_ERROR_PLAYER_NOT_INITIALIZED:
156 ret = PLAYER_ERROR_INVALID_STATE;
157 msg = "PLAYER_ERROR_INVALID_STATE";
159 case MM_ERROR_PLAYER_INTERNAL:
160 case MM_ERROR_PLAYER_INVALID_STREAM:
161 case MM_ERROR_PLAYER_STREAMING_FAIL:
162 case MM_ERROR_PLAYER_NO_OP:
163 ret = PLAYER_ERROR_INVALID_OPERATION;
164 msg = "PLAYER_ERROR_INVALID_OPERATION";
166 case MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS:
167 case MM_ERROR_NOT_SUPPORT_API:
168 case MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER:
169 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
170 msg = "PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE";
172 case MM_ERROR_PLAYER_NO_FREE_SPACE:
173 ret = PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE;
174 msg = "PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE";
176 case MM_ERROR_PLAYER_FILE_NOT_FOUND:
177 ret = PLAYER_ERROR_NO_SUCH_FILE;
178 msg = "PLAYER_ERROR_NO_SUCH_FILE";
180 case MM_ERROR_PLAYER_SEEK:
181 ret = PLAYER_ERROR_SEEK_FAILED;
182 msg = "PLAYER_ERROR_SEEK_FAILED";
184 case MM_ERROR_PLAYER_INVALID_URI:
185 case MM_ERROR_PLAYER_STREAMING_INVALID_URL:
186 ret = PLAYER_ERROR_INVALID_URI;
187 msg = "PLAYER_ERROR_INVALID_URI";
189 case MM_ERROR_PLAYER_STREAMING_CONNECTION_FAIL:
190 case MM_ERROR_PLAYER_STREAMING_DNS_FAIL:
191 case MM_ERROR_PLAYER_STREAMING_SERVER_DISCONNECTED:
192 case MM_ERROR_PLAYER_STREAMING_INVALID_PROTOCOL:
193 case MM_ERROR_PLAYER_STREAMING_UNEXPECTED_MSG:
194 case MM_ERROR_PLAYER_STREAMING_OUT_OF_MEMORIES:
195 case MM_ERROR_PLAYER_STREAMING_RTSP_TIMEOUT:
196 case MM_ERROR_PLAYER_STREAMING_BAD_REQUEST:
197 case MM_ERROR_PLAYER_STREAMING_NOT_AUTHORIZED:
198 case MM_ERROR_PLAYER_STREAMING_PAYMENT_REQUIRED:
199 case MM_ERROR_PLAYER_STREAMING_FORBIDDEN:
200 case MM_ERROR_PLAYER_STREAMING_CONTENT_NOT_FOUND:
201 case MM_ERROR_PLAYER_STREAMING_METHOD_NOT_ALLOWED:
202 case MM_ERROR_PLAYER_STREAMING_NOT_ACCEPTABLE:
203 case MM_ERROR_PLAYER_STREAMING_PROXY_AUTHENTICATION_REQUIRED:
204 case MM_ERROR_PLAYER_STREAMING_SERVER_TIMEOUT:
205 case MM_ERROR_PLAYER_STREAMING_GONE:
206 case MM_ERROR_PLAYER_STREAMING_LENGTH_REQUIRED:
207 case MM_ERROR_PLAYER_STREAMING_PRECONDITION_FAILED:
208 case MM_ERROR_PLAYER_STREAMING_REQUEST_ENTITY_TOO_LARGE:
209 case MM_ERROR_PLAYER_STREAMING_REQUEST_URI_TOO_LARGE:
210 case MM_ERROR_PLAYER_STREAMING_PARAMETER_NOT_UNDERSTOOD:
211 case MM_ERROR_PLAYER_STREAMING_CONFERENCE_NOT_FOUND:
212 case MM_ERROR_PLAYER_STREAMING_NOT_ENOUGH_BANDWIDTH:
213 case MM_ERROR_PLAYER_STREAMING_NO_SESSION_ID:
214 case MM_ERROR_PLAYER_STREAMING_METHOD_NOT_VALID_IN_THIS_STATE:
215 case MM_ERROR_PLAYER_STREAMING_HEADER_FIELD_NOT_VALID_FOR_SOURCE:
216 case MM_ERROR_PLAYER_STREAMING_INVALID_RANGE:
217 case MM_ERROR_PLAYER_STREAMING_PARAMETER_IS_READONLY:
218 case MM_ERROR_PLAYER_STREAMING_AGGREGATE_OP_NOT_ALLOWED:
219 case MM_ERROR_PLAYER_STREAMING_ONLY_AGGREGATE_OP_ALLOWED:
220 case MM_ERROR_PLAYER_STREAMING_BAD_TRANSPORT:
221 case MM_ERROR_PLAYER_STREAMING_DESTINATION_UNREACHABLE:
222 case MM_ERROR_PLAYER_STREAMING_INTERNAL_SERVER_ERROR:
223 case MM_ERROR_PLAYER_STREAMING_NOT_IMPLEMENTED:
224 case MM_ERROR_PLAYER_STREAMING_BAD_GATEWAY:
225 case MM_ERROR_PLAYER_STREAMING_SERVICE_UNAVAILABLE:
226 case MM_ERROR_PLAYER_STREAMING_GATEWAY_TIME_OUT:
227 case MM_ERROR_PLAYER_STREAMING_OPTION_NOT_SUPPORTED:
228 ret = PLAYER_ERROR_CONNECTION_FAILED;
229 msg = "PLAYER_ERROR_CONNECTION_FAILED";
231 case MM_ERROR_POLICY_BLOCKED:
232 case MM_ERROR_POLICY_INTERRUPTED:
233 case MM_ERROR_POLICY_INTERNAL:
234 case MM_ERROR_POLICY_DUPLICATED:
235 ret = PLAYER_ERROR_SOUND_POLICY;
236 msg = "PLAYER_ERROR_SOUND_POLICY";
238 case MM_ERROR_PLAYER_DRM_EXPIRED:
239 ret = PLAYER_ERROR_DRM_EXPIRED;
240 msg = "PLAYER_ERROR_DRM_EXPIRED";
242 case MM_ERROR_PLAYER_DRM_NOT_AUTHORIZED:
243 case MM_ERROR_PLAYER_DRM_NO_LICENSE:
244 ret = PLAYER_ERROR_DRM_NO_LICENSE;
245 msg = "PLAYER_ERROR_DRM_NO_LICENSE";
247 case MM_ERROR_PLAYER_DRM_FUTURE_USE:
248 ret = PLAYER_ERROR_DRM_FUTURE_USE;
249 msg = "PLAYER_ERROR_DRM_FUTURE_USE";
251 case MM_ERROR_PLAYER_DRM_OUTPUT_PROTECTION:
252 ret = PLAYER_ERROR_DRM_NOT_PERMITTED;
253 msg = "PLAYER_ERROR_DRM_NOT_PERMITTED";
255 case MM_ERROR_PLAYER_RESOURCE_LIMIT:
256 ret = PLAYER_ERROR_RESOURCE_LIMIT;
257 msg = "PLAYER_ERROR_RESOURCE_LIMIT";
259 case MM_ERROR_PLAYER_PERMISSION_DENIED:
260 ret = PLAYER_ERROR_PERMISSION_DENIED;
261 msg = "PLAYER_ERROR_PERMISSION_DENIED";
263 LOGE("[%s] %s(0x%08x) : core fw error(0x%x)", func_name, msg, ret, code);
267 static void *_get_mem(player_cli_s * player, int size)
269 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
271 mem->data = g_new(void, size);
272 mem->next = player->head;
279 static void _del_mem(player_cli_s * player)
282 while (player->head) {
283 mem = player->head->next;
284 g_free(player->head->data);
285 g_free(player->head);
290 static int player_recv_msg(callback_cb_info_s * cb_info)
293 msg_buff_s *buff = &cb_info->buff;
295 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
296 recvLen = muse_core_ipc_recv_fd_msg(cb_info->fd, buff->recvMsg, &cb_info->tfd);
298 /* check the first msg */
299 if (buff->part_of_msg && buff->recvMsg[0] != '{')
301 gchar *tmp = strndup(buff->recvMsg, recvLen);
303 LOGE("failed to copy msg.");
307 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
310 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
311 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
312 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
313 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
314 if (!buff->recvMsg) {
315 LOGE("failed renew buffer.");
320 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
322 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
323 recvLen += strlen(buff->part_of_msg);
325 free(buff->part_of_msg);
326 buff->part_of_msg = NULL;
331 /* check the last msg */
332 if (buff->recvMsg[recvLen-1] != '}') {
333 char *part_pos = strrchr(buff->recvMsg, '}');
334 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
337 buff->part_of_msg = strndup(part_pos+1, part_len);
338 if (!buff->part_of_msg) {
339 LOGE("failed to alloc buffer for part of msg.");
342 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
350 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
352 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
353 cb_info->user_cb[event] = NULL;
354 cb_info->user_data[event] = NULL;
358 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
360 bool lock = g_thread_self() != cb_info->event_queue.thread;
363 g_mutex_lock(&cb_info->event_queue.mutex);
365 set_null_user_cb(cb_info, event);
368 g_mutex_unlock(&cb_info->event_queue.mutex);
371 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
373 PLAYER_INSTANCE_CHECK(player);
374 PLAYER_NULL_ARG_CHECK(callback);
375 int ret = PLAYER_ERROR_NONE;
376 player_cli_s *pc = (player_cli_s *) player;
377 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
380 LOGI("Event type : %d ", type);
381 player_msg_set_callback(api, pc, ret, type, set);
383 if (ret == PLAYER_ERROR_NONE) {
384 pc->cb_info->user_cb[type] = callback;
385 pc->cb_info->user_data[type] = user_data;
390 static int __unset_callback(muse_player_event_e type, player_h player)
392 PLAYER_INSTANCE_CHECK(player);
393 int ret = PLAYER_ERROR_NONE;
394 player_cli_s *pc = (player_cli_s *) player;
395 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
398 LOGI("Event type : %d ", type);
400 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
401 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
403 player_msg_set_callback(api, pc, ret, type, set);
404 ret = PLAYER_ERROR_NONE;
409 static void __prepare_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
411 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
413 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
415 set_null_user_cb(cb_info, ev);
418 static void __complete_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
420 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
421 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
424 static char* _convert_code_to_str(int code)
427 case PLAYER_INTERRUPTED_COMPLETED: /* Deprecated since 3.0 */
428 return "PLAYER_INTERRUPTED_COMPLETED";
429 case PLAYER_INTERRUPTED_BY_MEDIA: /* Deprecated since 3.0 */
430 return "PLAYER_INTERRUPTED_BY_MEDIA";
431 case PLAYER_INTERRUPTED_BY_CALL: /* Deprecated since 3.0 */
432 return "PLAYER_INTERRUPTED_BY_CALL";
433 case PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG: /* Deprecated since 3.0 */
434 return "PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG";
435 case PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT:
436 return "PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT";
437 case PLAYER_INTERRUPTED_BY_ALARM: /* Deprecated since 3.0 */
438 return "PLAYER_INTERRUPTED_BY_ALARM";
439 case PLAYER_INTERRUPTED_BY_EMERGENCY: /* Deprecated since 3.0 */
440 return "PLAYER_INTERRUPTED_BY_EMERGENCY";
441 case PLAYER_INTERRUPTED_BY_NOTIFICATION: /* Deprecated since 3.0 */
442 return "PLAYER_INTERRUPTED_BY_NOTIFICATION";
444 LOGE("Invalid interrupted code %d (Never enter here)", code);
449 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
452 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
454 if (player_msg_get(code, recvMsg)) {
456 if (code >= PLAYER_INTERRUPTED_COMPLETED &&
457 code <= PLAYER_INTERRUPTED_BY_NOTIFICATION &&
458 code != PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT) {
459 LOGW("DEPRECATION WARNING: %s is deprecated and will be removed from next release.", _convert_code_to_str(code));
462 ((player_interrupted_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
466 static void __error_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
469 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
471 if (player_msg_get(code, recvMsg))
472 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
475 static void __buffering_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
478 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
480 if (player_msg_get(percent, recvMsg))
481 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
484 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
487 char text[MUSE_URI_MAX_LENGTH] = { 0, };
488 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
491 player_msg_get1_string(recvMsg, duration, INT, text, ret);
493 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
496 static void __capture_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
498 unsigned char *data = NULL;
501 unsigned int size = 0;
503 tbm_bo_handle thandle;
504 int key = INVALID_DEFAULT_VALUE;
507 player_msg_get4(recvMsg, width, INT, height, INT, size, INT, key, INT, ret_val);
509 if (cb_info->tfd < 0) {
510 LOGE("There is no valid tbm_fd");
514 bo = tbm_bo_import_fd(cb_info->bufmgr, cb_info->tfd);
516 LOGE("TBM get error : bo is NULL");
519 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
520 if (thandle.ptr == NULL) {
521 LOGE("TBM get error : handle pointer is NULL");
524 data = g_new(unsigned char, size);
526 memcpy(data, thandle.ptr, size);
527 ((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]);
530 LOGE("g_new failure");
536 if (cb_info->tfd > INVALID_DEFAULT_VALUE)
538 cb_info->tfd = INVALID_DEFAULT_VALUE;
544 if (key > INVALID_DEFAULT_VALUE) {
545 LOGD("send msg to release buffer. key:%d", key);
546 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
549 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
552 static void __seek_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
554 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
556 g_mutex_lock(&cb_info->seek_cb_mutex);
557 if (cb_info->user_cb[ev] && cb_info->block_seek_cb == FALSE) {
558 LOGD("call seek cb");
559 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
560 set_null_user_cb(cb_info, ev);
562 LOGW("ignored. seek cb %p, block %d", cb_info->user_cb[ev], cb_info->block_seek_cb);
564 g_mutex_unlock(&cb_info->seek_cb_mutex);
567 static void __player_remove_tsurf_list(player_cli_s * pc)
571 g_mutex_lock(&pc->cb_info->data_mutex);
572 if (pc->cb_info->tsurf_list) {
573 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
575 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
576 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
578 LOGD("%p will be removed", tmp);
581 tbm_surface_destroy(tmp->tsurf);
587 g_list_free(pc->cb_info->tsurf_list);
588 pc->cb_info->tsurf_list = NULL;
590 g_mutex_unlock(&pc->cb_info->data_mutex);
594 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, tbm_key key, tbm_surface_info_s sinfo)
598 g_mutex_lock(&cb_info->data_mutex);
599 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
600 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
601 if (tmp && (tmp->key == key)) { /* need to check fd, bo num, etc */
602 LOGD("found tsurf_data of tbm_key %d", key);
604 /* need to check tsuf info to support DRC */
605 if ((tbm_surface_get_height(tmp->tsurf) != sinfo.height) ||
606 (tbm_surface_get_width(tmp->tsurf) != sinfo.width)) {
608 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
609 LOGW("tsurf info is changed. need to create new tsurf.");
610 tbm_surface_destroy(tmp->tsurf);
613 g_mutex_unlock(&cb_info->data_mutex);
617 g_mutex_unlock(&cb_info->data_mutex);
622 g_mutex_unlock(&cb_info->data_mutex);
623 LOGD("there is no tsurf_data for tbm_key:%d", key);
627 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
629 tbm_bo bo[4] = { NULL, };
630 tbm_key key[4] = { 0, };
631 tbm_surface_info_s sinfo;
632 char *surface_info = (char *)&sinfo;
633 media_packet_h pkt = NULL;
634 tbm_surface_h tsurf = NULL;
635 player_tsurf_info_t *tsurf_data = NULL;
637 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
638 bool make_pkt_fmt = false;
639 int ret = MEDIA_FORMAT_ERROR_NONE;
640 _media_pkt_fin_data *fin_data = NULL;
644 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
646 void *jobj = muse_core_msg_json_object_new(recvMsg, NULL, &err);
648 !muse_core_msg_json_object_get_value("key[0]", jobj, &key[0], MUSE_TYPE_ANY) ||
649 !muse_core_msg_json_object_get_value("key[1]", jobj, &key[1], MUSE_TYPE_ANY) ||
650 !muse_core_msg_json_object_get_value("key[2]", jobj, &key[2], MUSE_TYPE_ANY) ||
651 !muse_core_msg_json_object_get_value("key[3]", jobj, &key[3], MUSE_TYPE_ANY) ||
652 !muse_core_msg_json_object_get_value("packet", jobj, &packet, MUSE_TYPE_POINTER) ||
653 !muse_core_msg_json_object_get_value("mimetype", jobj, &mimetype, MUSE_TYPE_ANY) ||
654 !muse_core_msg_json_object_get_value("pts", jobj, &pts, MUSE_TYPE_INT64) ||
655 !muse_core_msg_json_object_get_value("surface_info", jobj, surface_info, MUSE_TYPE_ARRAY)) {
657 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
659 muse_core_msg_json_object_free(jobj);
662 muse_core_msg_json_object_free(jobj);
664 LOGD("width %d, height %d", sinfo.width, sinfo.height);
667 LOGE("cb_info is null");
671 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
672 /* send msg to release packet. */
673 LOGE("_video_decoded_cb is not set");
674 player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
678 for (i = 0; i < 4; i++) {
681 bo[i] = tbm_bo_import(cb_info->bufmgr, key[i]);
685 tsurf_data = __player_get_tsurf_from_list(cb_info, key[0], sinfo);
687 tsurf_data = g_new(player_tsurf_info_t, 1);
689 LOGE("failed to alloc tsurf info");
693 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
695 LOGE("failed to create tbm surface");
699 tsurf_data->key = key[0];
700 tsurf_data->tsurf = tsurf;
701 if (cb_info->use_tsurf_pool) {
702 g_mutex_lock(&cb_info->data_mutex);
703 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
704 LOGD("key %d is added to the pool", key[0]);
705 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
706 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
707 g_mutex_unlock(&cb_info->data_mutex);
710 if (tsurf_data->tsurf) {
711 tsurf = tsurf_data->tsurf;
713 LOGE("tsurf_data->tsurf is null (never enter here)");
718 /* check media packet format */
719 if (cb_info->pkt_fmt) {
720 int pkt_fmt_width = 0;
721 int pkt_fmt_height = 0;
722 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
724 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
725 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
726 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);
727 media_format_unref(cb_info->pkt_fmt);
728 cb_info->pkt_fmt = NULL;
734 /* create packet format */
736 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
737 ret = media_format_create(&cb_info->pkt_fmt);
738 if (ret == MEDIA_FORMAT_ERROR_NONE) {
739 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
740 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
741 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
742 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
744 LOGE("media_format_create failed");
748 fin_data = g_new(_media_pkt_fin_data, 1);
750 LOGE("failed to alloc fin_data");
753 fin_data->remote_pkt = packet;
754 fin_data->fd = cb_info->fd;
755 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
756 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
757 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
758 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
763 ret = media_packet_set_pts(pkt, (uint64_t) pts);
764 if (ret != MEDIA_PACKET_ERROR_NONE)
765 LOGE("media_packet_set_pts failed");
767 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
768 /* call media packet callback */
769 ((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]);
771 LOGE("_video_decoded_cb is not set");
772 media_packet_destroy(pkt);
775 for (i = 0; i < bo_num; i++) {
783 media_packet_destroy(pkt);
788 for (i = 0; i < bo_num; i++) {
793 player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
797 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
800 tbm_bo_handle thandle;
801 int key = INVALID_DEFAULT_VALUE;
802 player_audio_raw_data_s audio;
804 if (!player_msg_get(key, recvMsg)) {
805 LOGE("failed to get key value from msg.");
809 if (cb_info->tfd < 0) {
810 LOGE("failed to get tbm_fd(key:%d)", key);
814 bo = tbm_bo_import_fd(cb_info->bufmgr, cb_info->tfd);
816 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", cb_info->tfd, key);
820 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
821 if (thandle.ptr == NULL) {
822 LOGE("TBM get error : handle pointer is NULL");
826 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
827 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
829 LOGD("user callback data %p, size %d", audio.data, audio.size);
830 ((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]);
834 if (cb_info->tfd > INVALID_DEFAULT_VALUE)
836 cb_info->tfd = INVALID_DEFAULT_VALUE;
842 if (key > INVALID_DEFAULT_VALUE) {
843 LOGD("send msg to release buffer. key:%d", key);
844 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
848 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
852 static void __pd_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
855 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
857 if (player_msg_get(type, recvMsg))
858 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
861 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
865 static void __supported_audio_effect_freset_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
869 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
873 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
875 /* player_media_stream_buffer_status_e status; */
878 if (player_msg_get(status, recvMsg)) {
879 ((player_media_stream_buffer_status_cb)
880 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]);
884 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
886 /* player_media_stream_buffer_status_e status; */
889 if (player_msg_get(status, recvMsg)) {
890 ((player_media_stream_buffer_status_cb)
891 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
892 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
897 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, char *recvMsg)
899 /* player_media_stream_buffer_status_e status; */
901 unsigned long long bytes;
904 player_msg_get2(recvMsg, status, INT, bytes, INT64, ret);
906 ((player_media_stream_buffer_status_cb_ex)
907 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
908 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
912 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, char *recvMsg)
914 /* player_media_stream_buffer_status_e status; */
916 unsigned long long bytes;
919 player_msg_get2(recvMsg, status, INT, bytes, INT64, ret);
921 ((player_media_stream_buffer_status_cb_ex)
922 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
923 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
928 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
930 unsigned long long offset;
932 if (player_msg_get_type(offset, recvMsg, INT64)) {
933 ((player_media_stream_seek_cb)
934 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
935 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
939 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
941 unsigned long long offset;
943 if (player_msg_get_type(offset, recvMsg, INT64)) {
944 ((player_media_stream_seek_cb)
945 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
946 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
950 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
958 player_msg_get4(recvMsg, width, INT, height, INT, fps, INT, bit_rate, INT, ret_val);
960 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
961 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
965 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, char *recvMsg) = {
966 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
967 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
968 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
969 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
970 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
971 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
972 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
973 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
974 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
975 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
976 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
977 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
978 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
979 __supported_audio_effect_freset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
980 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
981 #ifdef _PLAYER_FOR_PRODUCT
982 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
983 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
985 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
986 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
987 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
988 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
989 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
990 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
991 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
992 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
995 static void _player_event_job_function(_player_cb_data * data)
997 muse_player_event_e ev = data->int_data;
998 if (data->cb_info->user_cb[ev])
999 _user_callbacks[ev] (data->cb_info, data->buf);
1001 LOGW("user callback is unset. type : %d", ev);
1007 static void *_player_event_queue_loop(void *param)
1010 LOGE("NULL parameter");
1013 callback_cb_info_s *cb_info = param;
1014 player_event_queue *ev = &cb_info->event_queue;
1015 _player_cb_data *event_data;
1017 g_mutex_lock(&ev->mutex);
1018 while (ev->running) {
1019 g_mutex_lock(&ev->qlock);
1020 if (g_queue_is_empty(ev->queue)) {
1021 g_mutex_unlock(&ev->qlock);
1022 g_cond_wait(&ev->cond, &ev->mutex);
1026 g_mutex_unlock(&ev->qlock);
1029 g_mutex_lock(&ev->qlock);
1030 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1031 g_mutex_unlock(&ev->qlock);
1033 _player_event_job_function(event_data);
1038 g_mutex_unlock(&ev->mutex);
1039 LOGI("Exit event loop");
1043 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1045 g_return_val_if_fail(cb_info, FALSE);
1046 player_event_queue *ev = &cb_info->event_queue;
1048 ev->queue = g_queue_new();
1049 g_return_val_if_fail(ev->queue, FALSE);
1050 g_mutex_init(&ev->qlock);
1052 g_mutex_init(&ev->mutex);
1053 g_cond_init(&ev->cond);
1055 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1056 g_return_val_if_fail(ev->thread, FALSE);
1057 LOGI("event queue thread %p", ev->thread);
1063 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1065 g_return_if_fail(cb_info);
1066 player_event_queue *ev = &cb_info->event_queue;
1067 _player_cb_data *event_data;
1069 LOGI("event queue thread %p", ev->thread);
1071 g_mutex_lock(&ev->mutex);
1072 ev->running = FALSE;
1073 g_cond_broadcast(&ev->cond);
1074 g_mutex_unlock(&ev->mutex);
1076 g_thread_join(ev->thread);
1077 g_thread_unref(ev->thread);
1079 while (!g_queue_is_empty(ev->queue)) {
1080 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1082 g_free(event_data->buf);
1086 g_queue_free(ev->queue);
1087 g_mutex_clear(&ev->qlock);
1088 g_mutex_clear(&ev->mutex);
1089 g_cond_clear(&ev->cond);
1093 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1097 g_mutex_lock(&ev_queue->qlock);
1099 item = g_queue_peek_head_link(ev_queue->queue);
1101 GList *next = item->next;
1102 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1104 if (cb_data && cb_data->int_data == ev) {
1105 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1106 g_free(cb_data->buf);
1109 g_queue_delete_link(ev_queue->queue, item);
1113 g_mutex_unlock(&ev_queue->qlock);
1116 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1119 g_mutex_lock(&ev->qlock);
1120 g_queue_push_tail(ev->queue, (gpointer) data);
1121 g_mutex_unlock(&ev->qlock);
1122 g_cond_signal(&ev->cond);
1126 static void _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, char *buffer)
1128 LOGD("get event %d", event);
1130 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1131 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1132 _player_cb_data *data = NULL;
1133 data = g_new(_player_cb_data, 1);
1135 LOGE("fail to alloc mem");
1138 data->int_data = (int)event;
1139 data->cb_info = cb_info;
1141 _player_event_queue_add(&cb_info->event_queue, data);
1146 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1148 ret_msg_s *msg = NULL;
1149 ret_msg_s *last = cb_info->buff.retMsgHead;
1151 msg = g_new(ret_msg_s, 1);
1154 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1157 cb_info->buff.retMsgHead = msg;
1164 LOGE("g_new failure");
1167 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1169 ret_msg_s *msg = cb_info->buff.retMsgHead;
1170 ret_msg_s *prev = NULL;
1172 if (msg->api == api) {
1174 cb_info->buff.retMsgHead = msg->next;
1176 prev->next = msg->next;
1185 static void _notify_disconnected(callback_cb_info_s * cb_info)
1187 int code = PLAYER_ERROR_SERVICE_DISCONNECTED;
1188 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
1189 if (!cb_info || !cb_info->user_cb[ev])
1191 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
1194 static void *client_cb_handler(gpointer data)
1200 callback_cb_info_s *cb_info = data;
1201 char *recvMsg = NULL;
1202 muse_core_msg_parse_err_e err;
1204 while (g_atomic_int_get(&cb_info->running)) {
1206 err = MUSE_MSG_PARSE_ERROR_NONE;
1208 len = player_recv_msg(cb_info);
1212 recvMsg = cb_info->buff.recvMsg;
1213 recvMsg[len] = '\0';
1217 while (offset < len) {
1218 api = MUSE_PLAYER_API_MAX;
1219 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1222 void *jobj = muse_core_msg_json_object_new(recvMsg + offset, &parse_len, &err);
1224 if (muse_core_msg_json_object_get_value("api", jobj, &api, MUSE_TYPE_INT)) {
1225 if (api < MUSE_PLAYER_API_MAX) {
1226 g_mutex_lock(&cb_info->player_mutex);
1227 cb_info->buff.recved++;
1228 _add_ret_msg(api, cb_info, offset, parse_len);
1229 g_cond_signal(&cb_info->player_cond[api]);
1230 g_mutex_unlock(&cb_info->player_mutex);
1231 if (api == MUSE_PLAYER_API_DESTROY)
1232 g_atomic_int_set(&cb_info->running, 0);
1233 } else if (api == MUSE_PLAYER_CB_EVENT) {
1236 g_mutex_lock(&cb_info->player_mutex);
1237 buffer = strndup(recvMsg + offset, parse_len);
1238 g_mutex_unlock(&cb_info->player_mutex);
1239 if (muse_core_msg_json_object_get_value("event", jobj, &event, MUSE_TYPE_INT))
1240 _user_callback_handler(cb_info, event, buffer);
1241 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1242 g_mutex_lock(&cb_info->player_mutex);
1243 cb_info->buff.recved++;
1244 g_cond_signal(&cb_info->server_ack_cond);
1245 g_mutex_unlock(&cb_info->player_mutex);
1248 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1250 muse_core_msg_json_object_free(jobj);
1252 LOGE("Failed to get msg obj. err:%d", err);
1255 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1258 offset += parse_len;
1259 parse_len = len - offset;
1262 if (g_atomic_int_get(&cb_info->running))
1263 _notify_disconnected(cb_info);
1264 LOGD("client cb exit");
1269 static callback_cb_info_s *callback_new(gint sockfd)
1271 callback_cb_info_s *cb_info;
1275 g_return_val_if_fail(sockfd > 0, NULL);
1277 cb_info = g_new(callback_cb_info_s, 1);
1280 memset(cb_info, 0, sizeof(callback_cb_info_s));
1282 g_mutex_init(&cb_info->player_mutex);
1283 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1284 g_cond_init(&cb_info->player_cond[i]);
1285 g_cond_init(&cb_info->server_ack_cond);
1287 g_mutex_init(&cb_info->data_mutex);
1288 g_mutex_init(&cb_info->seek_cb_mutex);
1290 buff = &cb_info->buff;
1291 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1292 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1294 buff->retMsgHead = NULL;
1295 buff->part_of_msg = NULL;
1297 g_atomic_int_set(&cb_info->running, 1);
1298 cb_info->fd = sockfd;
1299 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1300 cb_info->tfd = INVALID_DEFAULT_VALUE;
1305 static void callback_destroy(callback_cb_info_s * cb_info)
1308 g_return_if_fail(cb_info);
1310 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1311 muse_core_connection_close(cb_info->fd);
1312 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1313 muse_core_connection_close(cb_info->data_fd);
1314 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1316 g_thread_join(cb_info->thread);
1317 g_thread_unref(cb_info->thread);
1318 cb_info->thread = NULL;
1320 LOGI("%p Callback destroyed", cb_info);
1322 g_mutex_clear(&cb_info->player_mutex);
1323 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1324 g_cond_clear(&cb_info->player_cond[i]);
1325 g_cond_clear(&cb_info->server_ack_cond);
1327 g_mutex_clear(&cb_info->data_mutex);
1328 g_mutex_clear(&cb_info->seek_cb_mutex);
1330 g_free(cb_info->buff.recvMsg);
1331 if (cb_info->buff.part_of_msg)
1332 g_free(cb_info->buff.part_of_msg);
1336 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1341 case MUSE_PLAYER_API_PREPARE:
1342 case MUSE_PLAYER_API_PREPARE_ASYNC:
1343 case MUSE_PLAYER_API_UNPREPARE:
1344 case MUSE_PLAYER_API_START:
1345 case MUSE_PLAYER_API_STOP:
1346 case MUSE_PLAYER_API_PAUSE:
1347 timeout += SERVER_TIMEOUT(pc);
1350 /* check prepare async is done */
1351 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1352 timeout += SERVER_TIMEOUT(pc);
1355 timeout += CALLBACK_TIME_OUT;
1356 return timeout; /* ms */
1359 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1361 int ret = PLAYER_ERROR_NONE;
1362 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1363 msg_buff_s *buff = &cb_info->buff;
1364 ret_msg_s *msg = NULL;
1366 g_mutex_lock(&cb_info->player_mutex);
1368 msg = _get_ret_msg(api, cb_info);
1369 if (!buff->recved || !msg) {
1370 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1371 LOGW("api %d return msg does not received %dms", api, time_out);
1372 g_mutex_unlock(&cb_info->player_mutex);
1373 return PLAYER_ERROR_INVALID_OPERATION;
1377 msg = _get_ret_msg(api, cb_info);
1379 *ret_buf = msg->msg;
1381 if (!player_msg_get(ret, *ret_buf))
1382 ret = PLAYER_ERROR_INVALID_OPERATION;
1384 LOGE("api %d return msg is not exist", api);
1385 ret = PLAYER_ERROR_INVALID_OPERATION;
1389 g_mutex_unlock(&cb_info->player_mutex);
1394 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1396 int ret = PLAYER_ERROR_NONE;
1397 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1398 msg_buff_s *buff = &cb_info->buff;
1400 g_mutex_lock(&cb_info->player_mutex);
1402 if (!buff->recved) {
1403 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1404 LOGW("server ack msg does not received %dms", time_out);
1406 ret = PLAYER_ERROR_INVALID_OPERATION;
1408 LOGD("Another msg is received, continue create handle");
1409 g_mutex_unlock(&cb_info->player_mutex);
1415 g_mutex_unlock(&cb_info->player_mutex);
1422 * Public Implementation
1425 int player_create(player_h * player)
1427 PLAYER_INSTANCE_CHECK(player);
1429 int ret = PLAYER_ERROR_NONE;
1430 int sock_fd = INVALID_DEFAULT_VALUE;
1433 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1434 muse_core_api_module_e module = MUSE_PLAYER;
1435 player_cli_s *pc = NULL;
1436 char *ret_buf = NULL;
1437 int retry_count = CONNECTION_RETRY;
1442 pc = g_new0(player_cli_s, 1);
1444 return PLAYER_ERROR_OUT_OF_MEMORY;
1446 while (--retry_count) {
1447 sock_fd = muse_core_client_new();
1448 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1449 LOGE("connection failure %d", errno);
1450 ret = PLAYER_ERROR_INVALID_OPERATION;
1452 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1456 player_msg_create_handle(api, sock_fd, INT, module, INT, pid);
1458 pc->cb_info = callback_new(sock_fd);
1460 LOGE("fail to create callback");
1461 ret = PLAYER_ERROR_INVALID_OPERATION;
1465 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1466 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1472 if (!_player_event_queue_new(pc->cb_info)) {
1473 LOGE("fail to create event queue");
1474 ret = PLAYER_ERROR_INVALID_OPERATION;
1478 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1479 if (ret == PLAYER_ERROR_NONE) {
1480 intptr_t module_addr;
1481 *player = (player_h) pc;
1482 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1483 pc->cb_info->data_fd = muse_core_client_new_data_ch();
1484 muse_core_send_module_addr(module_addr, pc->cb_info->data_fd);
1485 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1487 ret = PLAYER_ERROR_INVALID_OPERATION;
1490 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1494 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1495 pc->push_media_stream = FALSE;
1501 if (pc && pc->cb_info) {
1502 if (pc->cb_info->event_queue.running)
1503 _player_event_queue_destroy(pc->cb_info);
1504 callback_destroy(pc->cb_info);
1509 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1518 int player_destroy(player_h player)
1520 PLAYER_INSTANCE_CHECK(player);
1522 int ret = PLAYER_ERROR_NONE;
1523 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1524 player_cli_s *pc = (player_cli_s *) player;
1525 char *ret_buf = NULL;
1529 player_msg_send(api, pc, ret_buf, ret);
1530 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1531 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
1532 player_unset_media_packet_video_frame_decoded_cb(player);
1533 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
1534 LOGW("fail to unset evas client");
1538 if (CALLBACK_INFO(pc)) {
1539 __player_remove_tsurf_list(pc);
1540 _player_event_queue_destroy(CALLBACK_INFO(pc));
1541 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
1543 callback_destroy(CALLBACK_INFO(pc));
1553 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
1555 PLAYER_INSTANCE_CHECK(player);
1556 int ret = PLAYER_ERROR_NONE;
1557 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
1558 player_cli_s *pc = (player_cli_s *) player;
1559 char *ret_buf = NULL;
1563 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
1564 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
1565 return PLAYER_ERROR_INVALID_OPERATION;
1567 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
1568 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
1570 player_msg_send(api, pc, ret_buf, ret);
1571 if (ret == PLAYER_ERROR_NONE) {
1573 player_msg_get_type(timeout, ret_buf, INT);
1575 LOGD("server timeout will be %d sec", timeout);
1576 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1583 int player_prepare(player_h player)
1585 PLAYER_INSTANCE_CHECK(player);
1586 int ret = PLAYER_ERROR_NONE;
1587 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
1588 player_cli_s *pc = (player_cli_s *) player;
1589 char *ret_buf = NULL;
1593 player_msg_send(api, pc, ret_buf, ret);
1594 if (ret == PLAYER_ERROR_NONE) {
1596 player_msg_get_type(timeout, ret_buf, INT);
1598 LOGD("server timeout will be %d sec", timeout);
1599 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1606 int player_unprepare(player_h player)
1608 PLAYER_INSTANCE_CHECK(player);
1609 int ret = PLAYER_ERROR_NONE;
1610 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
1611 player_cli_s *pc = (player_cli_s *) player;
1612 char *ret_buf = NULL;
1616 if (!CALLBACK_INFO(pc))
1617 return PLAYER_ERROR_INVALID_STATE;
1618 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1619 if (EVAS_HANDLE(pc)) {
1620 player_unset_media_packet_video_frame_decoded_cb(player);
1621 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
1622 LOGW("fail to unset evas client");
1625 player_msg_send(api, pc, ret_buf, ret);
1626 if (ret == PLAYER_ERROR_NONE) {
1627 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1628 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1630 _player_deinit_memory_buffer(pc);
1633 pc->cb_info->video_frame_pool_size = 0;
1634 __player_remove_tsurf_list(pc);
1640 /* for backward compatability, to make the old path accessable */
1641 void _player_replace_old_path(const char *in_path, char *out_path)
1643 const char *old_path = "/opt/usr/media";
1645 LOGD("input file_path : %s", in_path);
1647 if (strncmp(in_path, old_path, strlen(old_path)) == 0) {
1648 snprintf(out_path, MAX_URL_LEN, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), in_path+strlen(old_path));
1650 snprintf(out_path, MAX_URL_LEN, "%s", in_path);
1653 LOGD("replaced path : %s", out_path);
1657 int player_set_uri(player_h player, const char *uri)
1659 PLAYER_INSTANCE_CHECK(player);
1660 PLAYER_NULL_ARG_CHECK(uri);
1661 int ret = PLAYER_ERROR_NONE;
1662 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
1663 player_cli_s *pc = (player_cli_s *) player;
1664 char *ret_buf = NULL;
1665 char path[MAX_URL_LEN];
1669 _player_replace_old_path(uri, path);
1671 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
1672 pc->push_media_stream = FALSE;
1678 int player_set_memory_buffer(player_h player, const void *data, int size)
1680 PLAYER_INSTANCE_CHECK(player);
1681 PLAYER_NULL_ARG_CHECK(data);
1682 int ret = PLAYER_ERROR_NONE;
1683 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
1684 player_cli_s *pc = (player_cli_s *) player;
1685 char *ret_buf = NULL;
1687 tbm_bo_handle thandle;
1688 tbm_fd tfd = INVALID_DEFAULT_VALUE;
1690 if (SERVER_TBM_BO(pc)) {
1691 LOGE("Already set the memory buffer. unprepare please");
1692 return PLAYER_ERROR_INVALID_OPERATION;
1695 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
1697 LOGE("TBM get error : bo is NULL");
1698 return PLAYER_ERROR_INVALID_OPERATION;
1700 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
1701 if (thandle.ptr == NULL) {
1702 LOGE("TBM get error : handle pointer is NULL");
1703 ret = PLAYER_ERROR_INVALID_OPERATION;
1706 memcpy(thandle.ptr, data, size);
1709 tfd = tbm_bo_export_fd(bo);
1711 LOGE("tbm_bo_export_fd err 0x%x", tfd);
1712 ret = PLAYER_ERROR_INVALID_OPERATION;
1716 player_msg_send1_fd(api, pc, ret_buf, ret, INT, size, tfd);
1717 pc->push_media_stream = FALSE;
1720 if (tfd > INVALID_DEFAULT_VALUE)
1725 if (ret == PLAYER_ERROR_NONE) {
1726 intptr_t bo_addr = 0;
1727 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
1728 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
1735 static int _player_deinit_memory_buffer(player_cli_s * pc)
1737 PLAYER_INSTANCE_CHECK(pc);
1738 int ret = PLAYER_ERROR_NONE;
1739 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
1740 intptr_t bo_addr = SERVER_TBM_BO(pc);
1745 player_msg_send1_async(api, pc, POINTER, bo_addr);
1747 SERVER_TBM_BO(pc) = 0;
1752 int player_get_state(player_h player, player_state_e * pstate)
1754 PLAYER_INSTANCE_CHECK(player);
1755 PLAYER_NULL_ARG_CHECK(pstate);
1756 int ret = PLAYER_ERROR_NONE;
1757 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
1758 player_cli_s *pc = (player_cli_s *) player;
1760 char *ret_buf = NULL;
1764 player_msg_send(api, pc, ret_buf, ret);
1766 if (ret == PLAYER_ERROR_NONE) {
1767 player_msg_get(state, ret_buf);
1775 int player_set_volume(player_h player, float left, float right)
1777 PLAYER_INSTANCE_CHECK(player);
1778 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1779 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1780 int ret = PLAYER_ERROR_NONE;
1781 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
1782 player_cli_s *pc = (player_cli_s *) player;
1783 char *ret_buf = NULL;
1787 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, right, DOUBLE, left);
1792 int player_get_volume(player_h player, float *pleft, float *pright)
1794 PLAYER_INSTANCE_CHECK(player);
1795 PLAYER_NULL_ARG_CHECK(pleft);
1796 PLAYER_NULL_ARG_CHECK(pright);
1797 int ret = PLAYER_ERROR_NONE;
1798 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
1799 player_cli_s *pc = (player_cli_s *) player;
1802 char *ret_buf = NULL;
1806 player_msg_send(api, pc, ret_buf, ret);
1808 if (ret == PLAYER_ERROR_NONE) {
1809 bool ret_val = TRUE;
1810 player_msg_get2(ret_buf, left, DOUBLE, right, DOUBLE, ret_val);
1812 *pleft = (float)left;
1813 *pright = (float)right;
1815 LOGE("failed to get value from msg");
1816 ret = PLAYER_ERROR_INVALID_OPERATION;
1824 int player_set_sound_type(player_h player, sound_type_e type)
1826 PLAYER_INSTANCE_CHECK(player);
1827 int ret = PLAYER_ERROR_NONE;
1828 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_TYPE;
1829 player_cli_s *pc = (player_cli_s *) player;
1830 char *ret_buf = NULL;
1833 LOGW("DEPRECATION WARNING: player_set_sound_type() is deprecated and will be removed from next release. Use player_set_audio_policy_info() instead.");
1835 player_msg_send1(api, pc, ret_buf, ret, INT, type);
1840 int player_set_audio_policy_info(player_h player, sound_stream_info_h stream_info)
1842 PLAYER_INSTANCE_CHECK(player);
1844 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_POLICY_INFO;
1845 player_cli_s *pc = (player_cli_s *) player;
1846 char *ret_buf = NULL;
1850 bool is_available = false;
1852 /* check if stream_info is valid */
1853 int ret = __player_convert_error_code(
1854 sound_manager_is_available_stream_information(
1855 stream_info, NATIVE_API_PLAYER, &is_available), (char *)__FUNCTION__);
1857 if (ret == PLAYER_ERROR_NONE) {
1858 if (is_available == false)
1859 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
1861 char *stream_type = NULL;
1862 int stream_index = 0;
1863 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
1864 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
1865 if (ret == SOUND_MANAGER_ERROR_NONE)
1866 player_msg_send2(api, pc, ret_buf, ret, STRING, stream_type, INT, stream_index);
1868 ret = PLAYER_ERROR_INVALID_OPERATION;
1877 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
1879 PLAYER_INSTANCE_CHECK(player);
1880 int ret = PLAYER_ERROR_NONE;
1881 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
1882 player_cli_s *pc = (player_cli_s *) player;
1883 char *ret_buf = NULL;
1887 player_msg_send1(api, pc, ret_buf, ret, INT, latency_mode);
1892 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
1894 PLAYER_INSTANCE_CHECK(player);
1895 PLAYER_NULL_ARG_CHECK(platency_mode);
1896 int ret = PLAYER_ERROR_NONE;
1897 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
1898 player_cli_s *pc = (player_cli_s *) player;
1899 char *ret_buf = NULL;
1900 int latency_mode = -1;
1904 player_msg_send(api, pc, ret_buf, ret);
1906 if (ret == PLAYER_ERROR_NONE) {
1907 player_msg_get(latency_mode, ret_buf);
1908 *platency_mode = latency_mode;
1916 int player_start(player_h player)
1918 PLAYER_INSTANCE_CHECK(player);
1919 int ret = PLAYER_ERROR_NONE;
1920 muse_player_api_e api = MUSE_PLAYER_API_START;
1921 player_cli_s *pc = (player_cli_s *) player;
1922 char *ret_buf = NULL;
1925 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1926 if (EVAS_HANDLE(pc)) {
1927 ret = mm_evas_renderer_update_param(EVAS_HANDLE(pc));
1928 if (ret != MM_ERROR_NONE) {
1929 LOGE("mm_evas_renderer_update_param err 0x%x", ret);
1930 return PLAYER_ERROR_INVALID_OPERATION;
1934 player_msg_send(api, pc, ret_buf, ret);
1940 int player_stop(player_h player)
1942 PLAYER_INSTANCE_CHECK(player);
1943 int ret = PLAYER_ERROR_NONE;
1944 muse_player_api_e api = MUSE_PLAYER_API_STOP;
1945 player_cli_s *pc = (player_cli_s *) player;
1946 char *ret_buf = NULL;
1950 player_msg_send(api, pc, ret_buf, ret);
1951 if (ret == PLAYER_ERROR_NONE)
1952 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1958 int player_pause(player_h player)
1960 PLAYER_INSTANCE_CHECK(player);
1961 int ret = PLAYER_ERROR_NONE;
1962 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
1963 player_cli_s *pc = (player_cli_s *) player;
1964 char *ret_buf = NULL;
1968 player_msg_send(api, pc, ret_buf, ret);
1973 int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data)
1975 PLAYER_INSTANCE_CHECK(player);
1976 PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1978 int ret = PLAYER_ERROR_NONE;
1979 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
1980 player_cli_s *pc = (player_cli_s *) player;
1981 char *ret_buf = NULL;
1982 int pos = millisecond;
1986 LOGE("cb_info is null");
1987 return PLAYER_ERROR_INVALID_OPERATION;
1990 if ((pc->push_media_stream == FALSE) &&
1991 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
1992 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
1993 return PLAYER_ERROR_SEEK_FAILED;
1995 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
1996 if (pc->push_media_stream == TRUE)
1997 pc->cb_info->block_seek_cb = TRUE;
1998 LOGI("Event type : %d, pos : %d ", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond);
1999 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
2000 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
2001 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2004 player_msg_send2(api, pc, ret_buf, ret, INT, pos, INT, accurate);
2006 if (ret != PLAYER_ERROR_NONE) {
2007 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
2008 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
2009 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
2012 if (pc->push_media_stream == TRUE)
2013 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
2015 pc->cb_info->block_seek_cb = FALSE;
2020 int player_get_play_position(player_h player, int *millisecond)
2022 PLAYER_INSTANCE_CHECK(player);
2023 PLAYER_NULL_ARG_CHECK(millisecond);
2025 int ret = PLAYER_ERROR_NONE;
2026 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2027 player_cli_s *pc = (player_cli_s *) player;
2029 char *ret_buf = NULL;
2033 player_msg_send(api, pc, ret_buf, ret);
2035 if (ret == PLAYER_ERROR_NONE) {
2036 player_msg_get(pos, ret_buf);
2044 int player_set_mute(player_h player, bool muted)
2046 PLAYER_INSTANCE_CHECK(player);
2047 int ret = PLAYER_ERROR_NONE;
2048 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2049 player_cli_s *pc = (player_cli_s *) player;
2050 char *ret_buf = NULL;
2051 int mute = (int)muted;
2055 player_msg_send1(api, pc, ret_buf, ret, INT, mute);
2060 int player_is_muted(player_h player, bool * muted)
2062 PLAYER_INSTANCE_CHECK(player);
2063 PLAYER_NULL_ARG_CHECK(muted);
2064 int ret = PLAYER_ERROR_NONE;
2065 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2066 player_cli_s *pc = (player_cli_s *) player;
2067 char *ret_buf = NULL;
2072 player_msg_send(api, pc, ret_buf, ret);
2073 if (ret == PLAYER_ERROR_NONE) {
2074 player_msg_get(mute, ret_buf);
2075 *muted = (bool) mute;
2082 int player_set_looping(player_h player, bool looping)
2084 PLAYER_INSTANCE_CHECK(player);
2085 int ret = PLAYER_ERROR_NONE;
2086 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2087 player_cli_s *pc = (player_cli_s *) player;
2088 char *ret_buf = NULL;
2092 player_msg_send1(api, pc, ret_buf, ret, INT, looping);
2097 int player_is_looping(player_h player, bool * plooping)
2099 PLAYER_INSTANCE_CHECK(player);
2100 PLAYER_NULL_ARG_CHECK(plooping);
2101 int ret = PLAYER_ERROR_NONE;
2102 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2103 player_cli_s *pc = (player_cli_s *) player;
2104 char *ret_buf = NULL;
2109 player_msg_send(api, pc, ret_buf, ret);
2110 if (ret == PLAYER_ERROR_NONE) {
2111 player_msg_get(looping, ret_buf);
2112 *plooping = looping;
2118 int player_get_duration(player_h player, int *pduration)
2120 PLAYER_INSTANCE_CHECK(player);
2121 PLAYER_NULL_ARG_CHECK(pduration);
2122 int ret = PLAYER_ERROR_NONE;
2123 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
2124 player_cli_s *pc = (player_cli_s *) player;
2125 char *ret_buf = NULL;
2130 player_msg_send(api, pc, ret_buf, ret);
2131 if (ret == PLAYER_ERROR_NONE) {
2132 player_msg_get(duration, ret_buf);
2133 *pduration = duration;
2140 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2142 PLAYER_INSTANCE_CHECK(player);
2143 int ret = PLAYER_ERROR_NONE;
2144 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2145 player_cli_s *pc = (player_cli_s *) player;
2146 char *ret_buf = NULL;
2147 Evas_Object *obj = NULL;
2148 const char *object_type = NULL;
2149 wl_win_msg_type wl_win;
2150 char *wl_win_msg = (char *)&wl_win;
2151 unsigned int wl_surface_id;
2152 struct wl_surface *wl_surface;
2153 struct wl_display *wl_display;
2154 Ecore_Wl_Window *wl_window = NULL;
2157 wl_win.wl_window_x = 0;
2158 wl_win.wl_window_y = 0;
2159 wl_win.wl_window_width = 0;
2160 wl_win.wl_window_height = 0;
2162 LOGD("ENTER type: %d", type);
2164 if (type != PLAYER_DISPLAY_TYPE_NONE) {
2165 obj = (Evas_Object *) display;
2167 return PLAYER_ERROR_INVALID_PARAMETER;
2169 object_type = evas_object_type_get(obj);
2171 if (type == PLAYER_DISPLAY_TYPE_OVERLAY && !strcmp(object_type, "elm_win")) {
2172 /* wayland overlay surface */
2173 LOGI("Wayland overlay surface type");
2176 e = evas_object_evas_get(obj);
2177 return_val_if_fail(e != NULL, PLAYER_ERROR_INVALID_OPERATION);
2179 if (ret != MM_ERROR_NONE) {
2180 LOGE("Fail to get window geometry");
2184 wl_window = elm_win_wl_window_get(obj);
2185 return_val_if_fail(wl_window != NULL, PLAYER_ERROR_INVALID_OPERATION);
2187 wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window);
2188 return_val_if_fail(wl_surface != NULL, PLAYER_ERROR_INVALID_OPERATION);
2190 /* get wl_display */
2191 wl_display = (struct wl_display *)ecore_wl_display_get();
2192 return_val_if_fail(wl_display != NULL, PLAYER_ERROR_INVALID_OPERATION);
2194 LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
2196 ret = _wl_client_create(&pc->wlclient);
2197 if (ret != MM_ERROR_NONE) {
2198 LOGE("Wayland client create failure");
2202 wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display);
2203 LOGD("wl_surface_id = %d", wl_surface_id);
2205 /* need to free always */
2207 g_free(pc->wlclient);
2208 pc->wlclient = NULL;
2210 return_val_if_fail(wl_surface_id > 0, PLAYER_ERROR_INVALID_OPERATION);
2211 wl_win.wl_surface_id = wl_surface_id;
2214 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2215 else if (type == PLAYER_DISPLAY_TYPE_EVAS && !strcmp(object_type, "image")) {
2216 /* evas object surface */
2217 LOGI("evas surface type");
2220 evas_object_geometry_get(obj, &wl_win.wl_window_x, &wl_win.wl_window_y,
2221 &wl_win.wl_window_width, &wl_win.wl_window_height);
2223 if (EVAS_HANDLE(pc)) {
2224 LOGW("evas client already exists");
2225 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2226 LOGW("fail to unset evas client");
2228 if (mm_evas_renderer_create(&EVAS_HANDLE(pc), obj) != MM_ERROR_NONE) {
2229 LOGW("fail to set evas client");
2230 /* FIXME : need to handle error case */
2233 if (player_set_media_packet_video_frame_decoded_cb(player, mm_evas_renderer_write, (void *)EVAS_HANDLE(pc)) != PLAYER_ERROR_NONE)
2234 LOGW("fail to set decoded callback");
2238 return PLAYER_ERROR_INVALID_PARAMETER;
2240 return PLAYER_ERROR_INVALID_PARAMETER;
2241 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2242 LOGI("Wayland surface type is NONE");
2245 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2250 int player_set_display_mode(player_h player, player_display_mode_e mode)
2252 PLAYER_INSTANCE_CHECK(player);
2253 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2254 int ret = PLAYER_ERROR_NONE;
2255 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
2256 player_cli_s *pc = (player_cli_s *) player;
2257 char *ret_buf = NULL;
2260 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2261 if (EVAS_HANDLE(pc)) {
2262 ret = mm_evas_renderer_set_geometry(EVAS_HANDLE(pc), mode);
2263 /* FIXME: need to handle error code from evas */
2264 return PLAYER_ERROR_NONE;
2267 player_msg_send1(api, pc, ret_buf, ret, INT, mode);
2272 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
2274 PLAYER_INSTANCE_CHECK(player);
2275 PLAYER_NULL_ARG_CHECK(pmode);
2276 int ret = PLAYER_ERROR_NONE;
2277 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
2278 player_cli_s *pc = (player_cli_s *) player;
2279 char *ret_buf = NULL;
2283 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2284 if (EVAS_HANDLE(pc)) {
2285 ret = mm_evas_renderer_get_geometry(EVAS_HANDLE(pc), &mode);
2286 *pmode = (player_display_mode_e) mode;
2287 /* FIXME: need to handle error code from evas */
2288 return PLAYER_ERROR_NONE;
2291 player_msg_send(api, pc, ret_buf, ret);
2292 if (ret == PLAYER_ERROR_NONE) {
2293 player_msg_get_type(mode, ret_buf, INT);
2302 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
2304 PLAYER_INSTANCE_CHECK(player);
2305 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2307 int ret = PLAYER_ERROR_NONE;
2308 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
2309 player_cli_s *pc = (player_cli_s *) player;
2310 char *ret_buf = NULL;
2311 wl_win_msg_type wl_win;
2312 char *wl_win_msg = (char *)&wl_win;
2316 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2317 if (EVAS_HANDLE(pc)) {
2318 ret = mm_evas_renderer_set_roi_area(EVAS_HANDLE(pc), x, y, width, height);
2319 /* FIXME: need to handle error code from evas */
2320 return PLAYER_ERROR_NONE;
2323 wl_win.wl_window_x = x;
2324 wl_win.wl_window_y = y;
2325 wl_win.wl_window_width = width;
2326 wl_win.wl_window_height = height;
2328 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2333 int player_set_playback_rate(player_h player, float rate)
2335 PLAYER_INSTANCE_CHECK(player);
2336 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2337 int ret = PLAYER_ERROR_NONE;
2338 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
2339 player_cli_s *pc = (player_cli_s *) player;
2340 char *ret_buf = NULL;
2344 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
2349 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
2351 PLAYER_INSTANCE_CHECK(player);
2352 int ret = PLAYER_ERROR_NONE;
2353 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
2354 player_cli_s *pc = (player_cli_s *) player;
2355 char *ret_buf = NULL;
2358 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2359 if (EVAS_HANDLE(pc)) {
2360 ret = mm_evas_renderer_set_rotation(EVAS_HANDLE(pc), rotation);
2361 /* FIXME: need to handle error code from evas */
2362 return PLAYER_ERROR_NONE;
2365 player_msg_send1(api, pc, ret_buf, ret, INT, rotation);
2370 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
2372 PLAYER_INSTANCE_CHECK(player);
2373 PLAYER_NULL_ARG_CHECK(protation);
2374 int ret = PLAYER_ERROR_NONE;
2375 player_cli_s *pc = (player_cli_s *) player;
2376 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
2377 char *ret_buf = NULL;
2381 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2382 if (EVAS_HANDLE(pc)) {
2383 ret = mm_evas_renderer_get_rotation(EVAS_HANDLE(pc), &rotation);
2384 *protation = (player_display_rotation_e) rotation;
2385 /* FIXME: need to handle error code from evas */
2386 return PLAYER_ERROR_NONE;
2389 player_msg_send(api, pc, ret_buf, ret);
2390 if (ret == PLAYER_ERROR_NONE) {
2391 player_msg_get_type(rotation, ret_buf, INT);
2392 *protation = rotation;
2399 int player_set_display_visible(player_h player, bool visible)
2401 PLAYER_INSTANCE_CHECK(player);
2402 int ret = PLAYER_ERROR_NONE;
2403 player_cli_s *pc = (player_cli_s *) player;
2404 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
2405 char *ret_buf = NULL;
2408 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2409 if (EVAS_HANDLE(pc)) {
2410 ret = mm_evas_renderer_set_visible(EVAS_HANDLE(pc), visible);
2411 /* FIXME: need to handle error code from evas */
2412 return PLAYER_ERROR_NONE;
2416 player_msg_send1(api, pc, ret_buf, ret, INT, visible);
2421 int player_is_display_visible(player_h player, bool * pvisible)
2423 PLAYER_INSTANCE_CHECK(player);
2424 PLAYER_NULL_ARG_CHECK(pvisible);
2425 int ret = PLAYER_ERROR_NONE;
2426 player_cli_s *pc = (player_cli_s *) player;
2427 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
2428 char *ret_buf = NULL;
2430 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2434 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2435 if (EVAS_HANDLE(pc)) {
2436 ret = mm_evas_renderer_get_visible(EVAS_HANDLE(pc), &visible);
2442 /* FIXME: need to handle error code from evas */
2443 return PLAYER_ERROR_NONE;
2446 player_msg_send(api, pc, ret_buf, ret);
2447 if (ret == PLAYER_ERROR_NONE) {
2448 player_msg_get_type(value, ret_buf, INT);
2460 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
2462 PLAYER_INSTANCE_CHECK(player);
2463 PLAYER_NULL_ARG_CHECK(pvalue);
2464 int ret = PLAYER_ERROR_NONE;
2465 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
2466 player_cli_s *pc = (player_cli_s *) player;
2467 char *ret_buf = NULL;
2468 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
2472 player_msg_send1(api, pc, ret_buf, ret, INT, key);
2473 if (ret == PLAYER_ERROR_NONE) {
2474 player_msg_get_string(value, ret_buf);
2475 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
2481 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
2483 PLAYER_INSTANCE_CHECK(player);
2484 PLAYER_NULL_ARG_CHECK(paudio_codec);
2485 PLAYER_NULL_ARG_CHECK(pvideo_codec);
2486 int ret = PLAYER_ERROR_NONE;
2487 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
2488 player_cli_s *pc = (player_cli_s *) player;
2489 char *ret_buf = NULL;
2490 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
2491 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
2492 bool ret_val = TRUE;
2496 player_msg_send(api, pc, ret_buf, ret);
2497 if (ret == PLAYER_ERROR_NONE) {
2498 player_msg_get_string2(ret_buf, video_codec, audio_codec, ret_val);
2500 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
2501 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
2503 ret = PLAYER_ERROR_INVALID_OPERATION;
2510 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
2512 PLAYER_INSTANCE_CHECK(player);
2513 PLAYER_NULL_ARG_CHECK(psample_rate);
2514 PLAYER_NULL_ARG_CHECK(pchannel);
2515 PLAYER_NULL_ARG_CHECK(pbit_rate);
2516 int ret = PLAYER_ERROR_NONE;
2517 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
2518 player_cli_s *pc = (player_cli_s *) player;
2519 char *ret_buf = NULL;
2520 int sample_rate = 0;
2526 player_msg_send(api, pc, ret_buf, ret);
2527 if (ret == PLAYER_ERROR_NONE) {
2528 bool ret_val = TRUE;
2529 player_msg_get3(ret_buf, sample_rate, INT, channel, INT, bit_rate, INT, ret_val);
2531 *psample_rate = sample_rate;
2532 *pchannel = channel;
2533 *pbit_rate = bit_rate;
2535 ret = PLAYER_ERROR_INVALID_OPERATION;
2542 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
2544 PLAYER_INSTANCE_CHECK(player);
2545 PLAYER_NULL_ARG_CHECK(pfps);
2546 PLAYER_NULL_ARG_CHECK(pbit_rate);
2547 int ret = PLAYER_ERROR_NONE;
2548 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
2549 player_cli_s *pc = (player_cli_s *) player;
2550 char *ret_buf = NULL;
2556 player_msg_send(api, pc, ret_buf, ret);
2557 if (ret == PLAYER_ERROR_NONE) {
2558 bool ret_val = TRUE;
2559 player_msg_get2(ret_buf, fps, INT, bit_rate, INT, ret_val);
2562 *pbit_rate = bit_rate;
2564 ret = PLAYER_ERROR_INVALID_OPERATION;
2571 int player_get_video_size(player_h player, int *pwidth, int *pheight)
2573 PLAYER_INSTANCE_CHECK(player);
2574 PLAYER_NULL_ARG_CHECK(pwidth);
2575 PLAYER_NULL_ARG_CHECK(pheight);
2576 int ret = PLAYER_ERROR_NONE;
2577 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
2578 player_cli_s *pc = (player_cli_s *) player;
2579 char *ret_buf = NULL;
2585 player_msg_send(api, pc, ret_buf, ret);
2586 if (ret == PLAYER_ERROR_NONE) {
2587 bool ret_val = TRUE;
2588 player_msg_get2(ret_buf, width, INT, height, INT, ret_val);
2593 ret = PLAYER_ERROR_INVALID_OPERATION;
2600 int player_get_album_art(player_h player, void **palbum_art, int *psize)
2602 PLAYER_INSTANCE_CHECK(player);
2603 PLAYER_NULL_ARG_CHECK(palbum_art);
2604 PLAYER_NULL_ARG_CHECK(psize);
2605 int ret = PLAYER_ERROR_NONE;
2606 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
2607 player_cli_s *pc = (player_cli_s *) player;
2608 char *ret_buf = NULL;
2612 tbm_bo_handle thandle;
2613 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2614 int key = INVALID_DEFAULT_VALUE;
2619 player_msg_send(api, pc, ret_buf, ret);
2620 if (ret == PLAYER_ERROR_NONE) {
2621 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
2622 jobj = muse_core_msg_json_object_new(ret_buf, NULL, &err);
2624 LOGE("failed to get msg obj, err:%d", err);
2625 ret = PLAYER_ERROR_INVALID_OPERATION;
2629 if (muse_core_msg_json_object_get_value("size", jobj, &size, MUSE_TYPE_INT) && (size > 0)) {
2630 LOGD("size : %d", size);
2631 if (!muse_core_msg_json_object_get_value("key", jobj, &key, MUSE_TYPE_INT)) {
2632 LOGE("failed to get key value");
2633 ret = PLAYER_ERROR_INVALID_OPERATION;
2637 tfd = pc->cb_info->tfd;
2639 LOGE("failed to get tbm fd value");
2640 ret = PLAYER_ERROR_INVALID_OPERATION;
2644 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
2646 LOGE("TBM get error : bo is NULL");
2647 ret = PLAYER_ERROR_INVALID_OPERATION;
2650 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
2651 if (thandle.ptr == NULL) {
2652 LOGE("TBM get error : handle pointer is NULL");
2653 ret = PLAYER_ERROR_INVALID_OPERATION;
2656 album_art = _get_mem(pc, size);
2658 memcpy(album_art, thandle.ptr, size);
2659 *palbum_art = album_art;
2661 LOGE("g_new failure");
2662 ret = PLAYER_ERROR_INVALID_OPERATION;
2674 muse_core_msg_json_object_free(jobj);
2679 if (tfd > INVALID_DEFAULT_VALUE)
2682 if (CALLBACK_INFO(pc))
2683 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
2689 if (key > INVALID_DEFAULT_VALUE) {
2690 LOGD("send msg to release buffer. key:%d", key);
2691 player_msg_send1_async(MUSE_PLAYER_API_RETURN_BUFFER, pc, INT, key);
2697 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
2699 PLAYER_INSTANCE_CHECK(player);
2700 PLAYER_NULL_ARG_CHECK(pcount);
2701 int ret = PLAYER_ERROR_NONE;
2702 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
2703 player_cli_s *pc = (player_cli_s *) player;
2704 char *ret_buf = NULL;
2709 player_msg_send(api, pc, ret_buf, ret);
2710 if (ret == PLAYER_ERROR_NONE) {
2711 player_msg_get(count, ret_buf);
2718 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
2720 PLAYER_INSTANCE_CHECK(player);
2721 PLAYER_NULL_ARG_CHECK(band_levels);
2722 int ret = PLAYER_ERROR_NONE;
2723 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
2724 player_cli_s *pc = (player_cli_s *) player;
2725 char *ret_buf = NULL;
2729 player_msg_send_array(api, pc, ret_buf, ret, band_levels, length, sizeof(int));
2736 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
2738 PLAYER_INSTANCE_CHECK(player);
2739 int ret = PLAYER_ERROR_NONE;
2740 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
2741 player_cli_s *pc = (player_cli_s *) player;
2742 char *ret_buf = NULL;
2746 player_msg_send2(api, pc, ret_buf, ret, INT, index, INT, level);
2752 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
2754 PLAYER_INSTANCE_CHECK(player);
2755 PLAYER_NULL_ARG_CHECK(plevel);
2756 int ret = PLAYER_ERROR_NONE;
2757 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
2758 player_cli_s *pc = (player_cli_s *) player;
2759 char *ret_buf = NULL;
2764 player_msg_send1(api, pc, ret_buf, ret, INT, index);
2765 if (ret == PLAYER_ERROR_NONE) {
2766 player_msg_get(level, ret_buf);
2773 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
2775 PLAYER_INSTANCE_CHECK(player);
2776 PLAYER_NULL_ARG_CHECK(pmin);
2777 PLAYER_NULL_ARG_CHECK(pmax);
2778 int ret = PLAYER_ERROR_NONE;
2779 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
2780 player_cli_s *pc = (player_cli_s *) player;
2781 char *ret_buf = NULL;
2782 int min = 0, max = 0;
2786 player_msg_send(api, pc, ret_buf, ret);
2787 if (ret == PLAYER_ERROR_NONE) {
2788 bool ret_val = TRUE;
2789 player_msg_get2(ret_buf, min, INT, max, INT, ret_val);
2794 ret = PLAYER_ERROR_INVALID_OPERATION;
2801 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
2803 PLAYER_INSTANCE_CHECK(player);
2804 PLAYER_NULL_ARG_CHECK(pfrequency);
2805 int ret = PLAYER_ERROR_NONE;
2806 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
2807 player_cli_s *pc = (player_cli_s *) player;
2808 char *ret_buf = NULL;
2813 player_msg_send1(api, pc, ret_buf, ret, INT, index);
2814 if (ret == PLAYER_ERROR_NONE) {
2815 player_msg_get(frequency, ret_buf);
2816 *pfrequency = frequency;
2822 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
2824 PLAYER_INSTANCE_CHECK(player);
2825 PLAYER_NULL_ARG_CHECK(prange);
2826 int ret = PLAYER_ERROR_NONE;
2827 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
2828 player_cli_s *pc = (player_cli_s *) player;
2829 char *ret_buf = NULL;
2834 player_msg_send1(api, pc, ret_buf, ret, INT, index);
2835 if (ret == PLAYER_ERROR_NONE) {
2836 player_msg_get(range, ret_buf);
2843 int player_audio_effect_equalizer_clear(player_h player)
2845 PLAYER_INSTANCE_CHECK(player);
2846 int ret = PLAYER_ERROR_NONE;
2847 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
2848 player_cli_s *pc = (player_cli_s *) player;
2849 char *ret_buf = NULL;
2853 player_msg_send(api, pc, ret_buf, ret);
2858 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
2860 PLAYER_INSTANCE_CHECK(player);
2861 PLAYER_NULL_ARG_CHECK(pavailable);
2862 int ret = PLAYER_ERROR_NONE;
2863 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
2864 player_cli_s *pc = (player_cli_s *) player;
2865 char *ret_buf = NULL;
2870 player_msg_send(api, pc, ret_buf, ret);
2871 if (ret == PLAYER_ERROR_NONE) {
2872 player_msg_get(available, ret_buf);
2873 *pavailable = available;
2879 int player_set_subtitle_path(player_h player, const char *path)
2881 PLAYER_INSTANCE_CHECK(player);
2882 int ret = PLAYER_ERROR_NONE;
2883 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
2884 player_cli_s *pc = (player_cli_s *) player;
2885 char *ret_buf = NULL;
2889 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
2894 int player_set_subtitle_position_offset(player_h player, int millisecond)
2896 PLAYER_INSTANCE_CHECK(player);
2897 int ret = PLAYER_ERROR_NONE;
2898 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
2899 player_cli_s *pc = (player_cli_s *) player;
2900 char *ret_buf = NULL;
2904 player_msg_send1(api, pc, ret_buf, ret, INT, millisecond);
2910 int player_set_progressive_download_path(player_h player, const char *path)
2912 PLAYER_INSTANCE_CHECK(player);
2913 PLAYER_NULL_ARG_CHECK(path);
2914 int ret = PLAYER_ERROR_NONE;
2915 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
2916 player_cli_s *pc = (player_cli_s *) player;
2917 char *ret_buf = NULL;
2921 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
2926 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
2928 PLAYER_INSTANCE_CHECK(player);
2929 PLAYER_NULL_ARG_CHECK(pcurrent);
2930 PLAYER_NULL_ARG_CHECK(ptotal_size);
2931 int ret = PLAYER_ERROR_NONE;
2932 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
2933 player_cli_s *pc = (player_cli_s *) player;
2934 char *ret_buf = NULL;
2935 unsigned long current, total_size;
2939 player_msg_send(api, pc, ret_buf, ret);
2940 if (ret == PLAYER_ERROR_NONE) {
2941 bool ret_val = TRUE;
2942 player_msg_get2(ret_buf, current, POINTER, total_size, POINTER, ret_val);
2944 *pcurrent = current;
2945 *ptotal_size = total_size;
2947 ret = PLAYER_ERROR_INVALID_OPERATION;
2955 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
2957 PLAYER_INSTANCE_CHECK(player);
2958 PLAYER_NULL_ARG_CHECK(callback);
2959 int ret = PLAYER_ERROR_NONE;
2960 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
2961 player_cli_s *pc = (player_cli_s *) player;
2962 char *ret_buf = NULL;
2965 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
2966 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
2967 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
2969 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
2970 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
2971 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
2974 player_msg_send(api, pc, ret_buf, ret);
2976 if (ret != PLAYER_ERROR_NONE)
2977 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
2983 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
2985 PLAYER_INSTANCE_CHECK(player);
2986 PLAYER_NULL_ARG_CHECK(cookie);
2987 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2988 int ret = PLAYER_ERROR_NONE;
2989 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
2990 player_cli_s *pc = (player_cli_s *) player;
2991 char *ret_buf = NULL;
2995 player_msg_send2(api, pc, ret_buf, ret, STRING, cookie, INT, size);
3000 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
3002 PLAYER_INSTANCE_CHECK(player);
3003 PLAYER_NULL_ARG_CHECK(user_agent);
3004 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
3005 int ret = PLAYER_ERROR_NONE;
3006 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
3007 player_cli_s *pc = (player_cli_s *) player;
3008 char *ret_buf = NULL;
3012 player_msg_send2(api, pc, ret_buf, ret, STRING, user_agent, INT, size);
3017 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
3019 PLAYER_INSTANCE_CHECK(player);
3020 PLAYER_NULL_ARG_CHECK(pstart);
3021 PLAYER_NULL_ARG_CHECK(pcurrent);
3022 int ret = PLAYER_ERROR_NONE;
3023 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3024 player_cli_s *pc = (player_cli_s *) player;
3025 char *ret_buf = NULL;
3026 int start = 0, current = 0;
3030 player_msg_send(api, pc, ret_buf, ret);
3031 if (ret == PLAYER_ERROR_NONE) {
3032 bool ret_val = TRUE;
3033 player_msg_get2(ret_buf, start, INT, current, INT, ret_val);
3036 *pcurrent = current;
3038 ret = PLAYER_ERROR_INVALID_OPERATION;
3046 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3048 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3051 int player_unset_completed_cb(player_h player)
3053 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3056 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3058 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3061 int player_unset_interrupted_cb(player_h player)
3063 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3066 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3068 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3071 int player_unset_error_cb(player_h player)
3073 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3076 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3078 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3081 int player_unset_buffering_cb(player_h player)
3083 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3086 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3088 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3091 int player_unset_subtitle_updated_cb(player_h player)
3093 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3096 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3098 PLAYER_INSTANCE_CHECK(player);
3099 PLAYER_NULL_ARG_CHECK(callback);
3100 int ret = PLAYER_ERROR_NONE;
3101 player_cli_s *pc = (player_cli_s *) player;
3102 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3103 char *ret_buf = NULL;
3104 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3109 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3111 if (ret == PLAYER_ERROR_NONE) {
3112 pc->cb_info->user_cb[type] = callback;
3113 pc->cb_info->user_data[type] = user_data;
3114 LOGI("Event type : %d ", type);
3121 int player_unset_progressive_download_message_cb(player_h player)
3123 PLAYER_INSTANCE_CHECK(player);
3124 int ret = PLAYER_ERROR_NONE;
3125 player_cli_s *pc = (player_cli_s *) player;
3126 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3127 char *ret_buf = NULL;
3128 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3133 set_null_user_cb_lock(pc->cb_info, type);
3135 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3142 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
3144 PLAYER_INSTANCE_CHECK(player);
3145 PLAYER_NULL_ARG_CHECK(callback);
3146 int ret = PLAYER_ERROR_NONE;
3147 player_cli_s *pc = (player_cli_s *) player;
3148 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3149 char *ret_buf = NULL;
3150 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3155 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3157 if (ret == PLAYER_ERROR_NONE) {
3158 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
3159 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
3160 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
3167 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
3169 PLAYER_INSTANCE_CHECK(player);
3170 int ret = PLAYER_ERROR_NONE;
3171 player_cli_s *pc = (player_cli_s *) player;
3172 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3173 char *ret_buf = NULL;
3174 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3179 set_null_user_cb_lock(pc->cb_info, type);
3181 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3187 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
3189 PLAYER_INSTANCE_CHECK(player);
3190 PLAYER_NULL_ARG_CHECK(callback);
3191 int ret = PLAYER_ERROR_NONE;
3192 player_cli_s *pc = (player_cli_s *) player;
3193 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3194 char *ret_buf = NULL;
3195 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3200 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3202 if (ret == PLAYER_ERROR_NONE) {
3203 pc->cb_info->user_cb[type] = callback;
3204 pc->cb_info->user_data[type] = user_data;
3205 LOGI("Event type : %d ", type);
3212 int player_unset_video_stream_changed_cb(player_h player)
3214 PLAYER_INSTANCE_CHECK(player);
3215 int ret = PLAYER_ERROR_NONE;
3216 player_cli_s *pc = (player_cli_s *) player;
3217 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3218 char *ret_buf = NULL;
3219 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3224 set_null_user_cb_lock(pc->cb_info, type);
3226 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3232 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)
3234 PLAYER_INSTANCE_CHECK(player);
3235 PLAYER_NULL_ARG_CHECK(callback);
3236 int ret = PLAYER_ERROR_NONE;
3237 player_cli_s *pc = (player_cli_s *) player;
3238 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3239 char *ret_buf = NULL;
3240 muse_player_event_e type;
3245 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3246 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3247 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3248 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3250 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3251 return PLAYER_ERROR_INVALID_PARAMETER;
3254 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3256 if (ret == PLAYER_ERROR_NONE) {
3257 pc->cb_info->user_cb[type] = callback;
3258 pc->cb_info->user_data[type] = user_data;
3259 LOGI("Event type : %d ", type);
3266 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
3268 PLAYER_INSTANCE_CHECK(player);
3269 int ret = PLAYER_ERROR_NONE;
3270 player_cli_s *pc = (player_cli_s *) player;
3271 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3272 char *ret_buf = NULL;
3273 muse_player_event_e type;
3278 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3279 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3280 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3281 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3283 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3284 return PLAYER_ERROR_INVALID_PARAMETER;
3287 set_null_user_cb_lock(pc->cb_info, type);
3289 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3295 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)
3297 PLAYER_INSTANCE_CHECK(player);
3298 PLAYER_NULL_ARG_CHECK(callback);
3299 int ret = PLAYER_ERROR_NONE;
3300 player_cli_s *pc = (player_cli_s *) player;
3301 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3302 char *ret_buf = NULL;
3303 muse_player_event_e type;
3308 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3309 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3310 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3311 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3313 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3314 return PLAYER_ERROR_INVALID_PARAMETER;
3317 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3319 if (ret == PLAYER_ERROR_NONE) {
3320 pc->cb_info->user_cb[type] = callback;
3321 pc->cb_info->user_data[type] = user_data;
3322 LOGI("Event type : %d ", type);
3329 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
3331 PLAYER_INSTANCE_CHECK(player);
3332 int ret = PLAYER_ERROR_NONE;
3333 player_cli_s *pc = (player_cli_s *) player;
3334 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3335 char *ret_buf = NULL;
3336 muse_player_event_e type;
3341 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3342 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3343 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3344 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3346 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3347 return PLAYER_ERROR_INVALID_PARAMETER;
3350 set_null_user_cb_lock(pc->cb_info, type);
3352 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3358 /* TODO Implement raw data socket channel */
3359 int player_push_media_stream(player_h player, media_packet_h packet)
3361 PLAYER_INSTANCE_CHECK(player);
3362 PLAYER_NULL_ARG_CHECK(packet);
3363 int ret = PLAYER_ERROR_NONE;
3364 player_cli_s *pc = (player_cli_s *) player;
3365 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
3366 char *ret_buf = NULL;
3367 player_push_media_msg_type push_media;
3368 char *push_media_msg = (char *)&push_media;
3369 int msg_size = sizeof(player_push_media_msg_type);
3373 tbm_bo_handle thandle;
3374 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3377 media_format_h format;
3383 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
3384 media_packet_get_buffer_size(packet, &push_media.size);
3385 media_packet_get_pts(packet, &push_media.pts);
3386 media_packet_get_format(packet, &format);
3387 media_packet_get_flags(packet, &push_media.flags);
3389 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
3391 media_packet_is_video(packet, &is_video);
3392 media_packet_is_audio(packet, &is_audio);
3394 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
3396 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
3398 media_format_unref(format);
3401 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
3402 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
3404 LOGE("TBM get error : bo is NULL");
3405 return PLAYER_ERROR_INVALID_OPERATION;
3407 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
3408 if (thandle.ptr == NULL) {
3409 LOGE("TBM get error : handle pointer is NULL");
3410 ret = PLAYER_ERROR_INVALID_OPERATION;
3413 memcpy(thandle.ptr, buf, push_media.size);
3416 tfd = tbm_bo_export_fd(bo);
3418 LOGE("tbm_bo_export_fd err 0x%x", tfd);
3419 ret = PLAYER_ERROR_INVALID_OPERATION;
3423 player_msg_send_array_fd(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), tfd);
3424 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
3425 buf_size = (int)push_media.size;
3426 player_msg_send_array2(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), buf, buf_size, sizeof(char));
3429 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
3430 buf_size = (int)push_media.size;
3431 muse_core_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts);
3432 player_msg_send_array(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char));
3435 LOGD("ret_buf %s", ret_buf);
3439 if (tfd > INVALID_DEFAULT_VALUE)
3442 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
3450 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
3452 PLAYER_INSTANCE_CHECK(player);
3453 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
3454 int ret = PLAYER_ERROR_NONE;
3455 player_cli_s *pc = (player_cli_s *) player;
3456 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
3457 char *ret_buf = NULL;
3458 media_format_mimetype_e mimetype;
3469 media_format_ref(format);
3470 if (type == PLAYER_STREAM_TYPE_VIDEO) {
3471 media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps);
3472 player_msg_send6(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, width, INT, height, INT, avg_bps, INT, max_bps);
3473 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
3474 media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps);
3475 player_msg_send6(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, channel, INT, samplerate, INT, avg_bps, INT, bit);
3477 media_format_unref(format);
3478 pc->push_media_stream = TRUE;
3484 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
3486 int ret = PLAYER_ERROR_NONE;
3487 PLAYER_INSTANCE_CHECK(player);
3488 player_cli_s *pc = (player_cli_s *) player;
3489 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
3490 char *ret_buf = NULL;
3494 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT64, max_size);
3500 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
3502 int ret = PLAYER_ERROR_NONE;
3503 PLAYER_INSTANCE_CHECK(player);
3504 PLAYER_NULL_ARG_CHECK(pmax_size);
3505 player_cli_s *pc = (player_cli_s *) player;
3506 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
3507 char *ret_buf = NULL;
3508 unsigned long long max_size;
3512 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3513 if (ret == PLAYER_ERROR_NONE) {
3514 player_msg_get_type(max_size, ret_buf, INT64);
3515 *pmax_size = max_size;
3521 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
3523 int ret = PLAYER_ERROR_NONE;
3524 PLAYER_INSTANCE_CHECK(player);
3525 player_cli_s *pc = (player_cli_s *) player;
3526 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
3527 char *ret_buf = NULL;
3531 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, percent);
3537 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
3539 int ret = PLAYER_ERROR_NONE;
3540 PLAYER_INSTANCE_CHECK(player);
3541 PLAYER_NULL_ARG_CHECK(ppercent);
3542 player_cli_s *pc = (player_cli_s *) player;
3543 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
3544 char *ret_buf = NULL;
3549 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3550 if (ret == PLAYER_ERROR_NONE) {
3551 player_msg_get(percent, ret_buf);
3552 *ppercent = percent;
3559 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
3561 PLAYER_INSTANCE_CHECK(player);
3562 PLAYER_NULL_ARG_CHECK(pcount);
3563 int ret = PLAYER_ERROR_NONE;
3564 player_cli_s *pc = (player_cli_s *) player;
3565 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
3566 char *ret_buf = NULL;
3571 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3572 if (ret == PLAYER_ERROR_NONE) {
3573 player_msg_get(count, ret_buf);
3581 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
3583 PLAYER_INSTANCE_CHECK(player);
3584 PLAYER_NULL_ARG_CHECK(pindex);
3585 int ret = PLAYER_ERROR_NONE;
3586 player_cli_s *pc = (player_cli_s *) player;
3587 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
3588 char *ret_buf = NULL;
3593 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3594 if (ret == PLAYER_ERROR_NONE) {
3595 player_msg_get(index, ret_buf);
3603 int player_select_track(player_h player, player_stream_type_e type, int index)
3605 PLAYER_INSTANCE_CHECK(player);
3606 int ret = PLAYER_ERROR_NONE;
3607 player_cli_s *pc = (player_cli_s *) player;
3608 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
3609 char *ret_buf = NULL;
3613 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
3619 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
3621 PLAYER_INSTANCE_CHECK(player);
3622 PLAYER_NULL_ARG_CHECK(pcode);
3623 int ret = PLAYER_ERROR_NONE;
3624 player_cli_s *pc = (player_cli_s *) player;
3625 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
3626 char *ret_buf = NULL;
3627 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
3628 const int code_len = 2;
3632 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
3633 if (ret == PLAYER_ERROR_NONE) {
3634 if (player_msg_get_string(code, ret_buf))
3635 *pcode = strndup(code, code_len);