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 "player_internal.h"
40 #include "player_private.h"
41 #include "player_display.h"
42 #include "player_msg.h"
43 #ifdef TIZEN_FEATURE_EVAS_RENDERER
44 #include <mm_evas_renderer.h>
47 #define INVALID_DEFAULT_VALUE -1
52 callback_cb_info_s *cb_info;
59 } _media_pkt_fin_data;
66 * Internal Implementation
68 static int _player_deinit_memory_buffer(player_cli_s * pc);
70 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
72 int ret = MEDIA_PACKET_FINALIZE;
73 muse_player_api_e api = MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB;
74 _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
80 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
84 if (!fin_data || fin_data->fd <= INVALID_DEFAULT_VALUE) {
85 LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
89 if (!fin_data->use_tsurf_pool) {
90 tbm_surface_h tsurf = NULL;
91 if (media_packet_get_tbm_surface(pkt, &tsurf) != MEDIA_PACKET_ERROR_NONE) {
92 LOGE("media_packet_get_tbm_surface failed");
93 /* continue the remained job */
96 LOGD("_player_media_packet_finalize tsurf destroy %p", tsurf);
97 tbm_surface_destroy(tsurf);
101 /* Do not destroy tbm surface here to reuse during playback *
102 * they will be destroyed at player_unprepare() or player_destroy(). *
103 * ref: __player_remove_tsurf_list() */
105 tbm_surface_h tsurf = NULL;
107 if (media_packet_get_tbm_surface(pkt, &tsurf) == MEDIA_PACKET_ERROR_NONE) {
108 LOGD("tsurf set to null %p", tsurf);
113 packet = fin_data->remote_pkt;
114 snd_msg = muse_core_msg_json_factory_new(api, MUSE_TYPE_POINTER, "packet", packet, 0);
115 snd_len = muse_core_ipc_send_msg(fin_data->fd, snd_msg);
116 muse_core_msg_json_factory_free(snd_msg);
119 LOGE("fail to send msg.");
130 static int __player_convert_error_code(int code, char *func_name)
132 int ret = PLAYER_ERROR_INVALID_OPERATION;
133 char *msg = "PLAYER_ERROR_INVALID_OPERATION";
136 case MM_ERROR_PLAYER_AUDIO_CODEC_NOT_FOUND:
137 case MM_ERROR_PLAYER_VIDEO_CODEC_NOT_FOUND:
138 ret = PLAYER_ERROR_NONE;
139 msg = "PLAYER_ERROR_NONE";
141 case MM_ERROR_INVALID_ARGUMENT:
142 ret = PLAYER_ERROR_INVALID_PARAMETER;
143 msg = "PLAYER_ERROR_INVALID_PARAMETER";
145 case MM_ERROR_PLAYER_CODEC_NOT_FOUND:
146 case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_AUDIO:
147 case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_VIDEO:
148 case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_MEDIA_TYPE:
149 case MM_ERROR_PLAYER_NOT_SUPPORTED_FORMAT:
150 ret = PLAYER_ERROR_NOT_SUPPORTED_FILE;
151 msg = "PLAYER_ERROR_NOT_SUPPORTED_FILE";
153 case MM_ERROR_PLAYER_INVALID_STATE:
154 case MM_ERROR_PLAYER_NOT_INITIALIZED:
155 ret = PLAYER_ERROR_INVALID_STATE;
156 msg = "PLAYER_ERROR_INVALID_STATE";
158 case MM_ERROR_PLAYER_INTERNAL:
159 case MM_ERROR_PLAYER_INVALID_STREAM:
160 case MM_ERROR_PLAYER_STREAMING_FAIL:
161 case MM_ERROR_PLAYER_NO_OP:
162 ret = PLAYER_ERROR_INVALID_OPERATION;
163 msg = "PLAYER_ERROR_INVALID_OPERATION";
165 case MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS:
166 case MM_ERROR_NOT_SUPPORT_API:
167 case MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER:
168 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
169 msg = "PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE";
171 case MM_ERROR_PLAYER_NO_FREE_SPACE:
172 ret = PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE;
173 msg = "PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE";
175 case MM_ERROR_PLAYER_FILE_NOT_FOUND:
176 ret = PLAYER_ERROR_NO_SUCH_FILE;
177 msg = "PLAYER_ERROR_NO_SUCH_FILE";
179 case MM_ERROR_PLAYER_SEEK:
180 ret = PLAYER_ERROR_SEEK_FAILED;
181 msg = "PLAYER_ERROR_SEEK_FAILED";
183 case MM_ERROR_PLAYER_INVALID_URI:
184 case MM_ERROR_PLAYER_STREAMING_INVALID_URL:
185 ret = PLAYER_ERROR_INVALID_URI;
186 msg = "PLAYER_ERROR_INVALID_URI";
188 case MM_ERROR_PLAYER_STREAMING_CONNECTION_FAIL:
189 case MM_ERROR_PLAYER_STREAMING_DNS_FAIL:
190 case MM_ERROR_PLAYER_STREAMING_SERVER_DISCONNECTED:
191 case MM_ERROR_PLAYER_STREAMING_INVALID_PROTOCOL:
192 case MM_ERROR_PLAYER_STREAMING_UNEXPECTED_MSG:
193 case MM_ERROR_PLAYER_STREAMING_OUT_OF_MEMORIES:
194 case MM_ERROR_PLAYER_STREAMING_RTSP_TIMEOUT:
195 case MM_ERROR_PLAYER_STREAMING_BAD_REQUEST:
196 case MM_ERROR_PLAYER_STREAMING_NOT_AUTHORIZED:
197 case MM_ERROR_PLAYER_STREAMING_PAYMENT_REQUIRED:
198 case MM_ERROR_PLAYER_STREAMING_FORBIDDEN:
199 case MM_ERROR_PLAYER_STREAMING_CONTENT_NOT_FOUND:
200 case MM_ERROR_PLAYER_STREAMING_METHOD_NOT_ALLOWED:
201 case MM_ERROR_PLAYER_STREAMING_NOT_ACCEPTABLE:
202 case MM_ERROR_PLAYER_STREAMING_PROXY_AUTHENTICATION_REQUIRED:
203 case MM_ERROR_PLAYER_STREAMING_SERVER_TIMEOUT:
204 case MM_ERROR_PLAYER_STREAMING_GONE:
205 case MM_ERROR_PLAYER_STREAMING_LENGTH_REQUIRED:
206 case MM_ERROR_PLAYER_STREAMING_PRECONDITION_FAILED:
207 case MM_ERROR_PLAYER_STREAMING_REQUEST_ENTITY_TOO_LARGE:
208 case MM_ERROR_PLAYER_STREAMING_REQUEST_URI_TOO_LARGE:
209 case MM_ERROR_PLAYER_STREAMING_PARAMETER_NOT_UNDERSTOOD:
210 case MM_ERROR_PLAYER_STREAMING_CONFERENCE_NOT_FOUND:
211 case MM_ERROR_PLAYER_STREAMING_NOT_ENOUGH_BANDWIDTH:
212 case MM_ERROR_PLAYER_STREAMING_NO_SESSION_ID:
213 case MM_ERROR_PLAYER_STREAMING_METHOD_NOT_VALID_IN_THIS_STATE:
214 case MM_ERROR_PLAYER_STREAMING_HEADER_FIELD_NOT_VALID_FOR_SOURCE:
215 case MM_ERROR_PLAYER_STREAMING_INVALID_RANGE:
216 case MM_ERROR_PLAYER_STREAMING_PARAMETER_IS_READONLY:
217 case MM_ERROR_PLAYER_STREAMING_AGGREGATE_OP_NOT_ALLOWED:
218 case MM_ERROR_PLAYER_STREAMING_ONLY_AGGREGATE_OP_ALLOWED:
219 case MM_ERROR_PLAYER_STREAMING_BAD_TRANSPORT:
220 case MM_ERROR_PLAYER_STREAMING_DESTINATION_UNREACHABLE:
221 case MM_ERROR_PLAYER_STREAMING_INTERNAL_SERVER_ERROR:
222 case MM_ERROR_PLAYER_STREAMING_NOT_IMPLEMENTED:
223 case MM_ERROR_PLAYER_STREAMING_BAD_GATEWAY:
224 case MM_ERROR_PLAYER_STREAMING_SERVICE_UNAVAILABLE:
225 case MM_ERROR_PLAYER_STREAMING_GATEWAY_TIME_OUT:
226 case MM_ERROR_PLAYER_STREAMING_OPTION_NOT_SUPPORTED:
227 ret = PLAYER_ERROR_CONNECTION_FAILED;
228 msg = "PLAYER_ERROR_CONNECTION_FAILED";
230 case MM_ERROR_POLICY_BLOCKED:
231 case MM_ERROR_POLICY_INTERRUPTED:
232 case MM_ERROR_POLICY_INTERNAL:
233 case MM_ERROR_POLICY_DUPLICATED:
234 ret = PLAYER_ERROR_SOUND_POLICY;
235 msg = "PLAYER_ERROR_SOUND_POLICY";
237 case MM_ERROR_PLAYER_DRM_EXPIRED:
238 ret = PLAYER_ERROR_DRM_EXPIRED;
239 msg = "PLAYER_ERROR_DRM_EXPIRED";
241 case MM_ERROR_PLAYER_DRM_NOT_AUTHORIZED:
242 case MM_ERROR_PLAYER_DRM_NO_LICENSE:
243 ret = PLAYER_ERROR_DRM_NO_LICENSE;
244 msg = "PLAYER_ERROR_DRM_NO_LICENSE";
246 case MM_ERROR_PLAYER_DRM_FUTURE_USE:
247 ret = PLAYER_ERROR_DRM_FUTURE_USE;
248 msg = "PLAYER_ERROR_DRM_FUTURE_USE";
250 case MM_ERROR_PLAYER_DRM_OUTPUT_PROTECTION:
251 ret = PLAYER_ERROR_DRM_NOT_PERMITTED;
252 msg = "PLAYER_ERROR_DRM_NOT_PERMITTED";
254 case MM_ERROR_PLAYER_RESOURCE_LIMIT:
255 ret = PLAYER_ERROR_RESOURCE_LIMIT;
256 msg = "PLAYER_ERROR_RESOURCE_LIMIT";
258 case MM_ERROR_PLAYER_PERMISSION_DENIED:
259 ret = PLAYER_ERROR_PERMISSION_DENIED;
260 msg = "PLAYER_ERROR_PERMISSION_DENIED";
262 LOGE("[%s] %s(0x%08x) : core fw error(0x%x)", func_name, msg, ret, code);
266 static void *_get_mem(player_cli_s * player, int size)
268 player_data_s *mem = g_new(player_data_s, sizeof(player_data_s));
270 mem->data = g_new(void, size);
271 mem->next = player->head;
278 static void _del_mem(player_cli_s * player)
281 while (player->head) {
282 mem = player->head->next;
283 g_free(player->head->data);
284 g_free(player->head);
289 static int player_recv_msg(callback_cb_info_s * cb_info)
292 msg_buff_s *buff = &cb_info->buff;
294 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
295 recvLen = muse_core_ipc_recv_fd_msg(cb_info->fd, buff->recvMsg, &cb_info->tfd);
297 /* check the first msg */
298 if (buff->part_of_msg && buff->recvMsg[0] != '{')
300 gchar *tmp = strndup(buff->recvMsg, recvLen);
302 LOGE("failed to copy msg.");
306 LOGD("get remained part of msg %d + %d, %d", recvLen, strlen(buff->part_of_msg), buff->bufLen);
309 if (recvLen+strlen(buff->part_of_msg) >= buff->bufLen) {
310 LOGD("realloc Buffer %d -> %d", buff->bufLen, recvLen+strlen(buff->part_of_msg)+1);
311 buff->bufLen = recvLen+strlen(buff->part_of_msg)+1;
312 buff->recvMsg = g_renew(char, buff->recvMsg, buff->bufLen);
313 if (!buff->recvMsg) {
314 LOGE("failed renew buffer.");
319 memset(buff->recvMsg, 0x00, sizeof(char)*buff->bufLen);
321 snprintf(buff->recvMsg, buff->bufLen, "%s%s", buff->part_of_msg, tmp);
322 recvLen += strlen(buff->part_of_msg);
324 free(buff->part_of_msg);
325 buff->part_of_msg = NULL;
330 /* check the last msg */
331 if (buff->recvMsg[recvLen-1] != '}') {
332 char *part_pos = strrchr(buff->recvMsg, '}');
333 int part_len = ((part_pos) ? (strlen(part_pos+1)) : (0));
336 buff->part_of_msg = strndup(part_pos+1, part_len);
337 if (!buff->part_of_msg) {
338 LOGE("failed to alloc buffer for part of msg.");
341 LOGD("get part of msg: %d, %s", strlen(buff->part_of_msg), buff->part_of_msg);
349 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
351 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
352 cb_info->user_cb[event] = NULL;
353 cb_info->user_data[event] = NULL;
357 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
359 bool lock = g_thread_self() != cb_info->event_queue.thread;
362 g_mutex_lock(&cb_info->event_queue.mutex);
364 set_null_user_cb(cb_info, event);
367 g_mutex_unlock(&cb_info->event_queue.mutex);
370 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
372 PLAYER_INSTANCE_CHECK(player);
373 PLAYER_NULL_ARG_CHECK(callback);
374 int ret = PLAYER_ERROR_NONE;
375 player_cli_s *pc = (player_cli_s *) player;
376 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
379 LOGI("Event type : %d ", type);
380 player_msg_set_callback(api, pc, ret, type, set);
382 if (ret == PLAYER_ERROR_NONE) {
383 pc->cb_info->user_cb[type] = callback;
384 pc->cb_info->user_data[type] = user_data;
389 static int __unset_callback(muse_player_event_e type, player_h player)
391 PLAYER_INSTANCE_CHECK(player);
392 int ret = PLAYER_ERROR_NONE;
393 player_cli_s *pc = (player_cli_s *) player;
394 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
397 LOGI("Event type : %d ", type);
399 PLAYER_NULL_ARG_CHECK(CALLBACK_INFO(pc));
400 set_null_user_cb_lock(CALLBACK_INFO(pc), type);
402 player_msg_set_callback(api, pc, ret, type, set);
403 ret = PLAYER_ERROR_NONE;
408 static void __prepare_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
410 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PREPARE;
412 ((player_prepared_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
414 set_null_user_cb(cb_info, ev);
417 static void __complete_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
419 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_COMPLETE;
420 ((player_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
423 static char* _convert_code_to_str(int code)
426 case PLAYER_INTERRUPTED_COMPLETED: /* Deprecated since 3.0 */
427 return "PLAYER_INTERRUPTED_COMPLETED";
428 case PLAYER_INTERRUPTED_BY_MEDIA: /* Deprecated since 3.0 */
429 return "PLAYER_INTERRUPTED_BY_MEDIA";
430 case PLAYER_INTERRUPTED_BY_CALL: /* Deprecated since 3.0 */
431 return "PLAYER_INTERRUPTED_BY_CALL";
432 case PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG: /* Deprecated since 3.0 */
433 return "PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG";
434 case PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT:
435 return "PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT";
436 case PLAYER_INTERRUPTED_BY_ALARM: /* Deprecated since 3.0 */
437 return "PLAYER_INTERRUPTED_BY_ALARM";
438 case PLAYER_INTERRUPTED_BY_EMERGENCY: /* Deprecated since 3.0 */
439 return "PLAYER_INTERRUPTED_BY_EMERGENCY";
440 case PLAYER_INTERRUPTED_BY_NOTIFICATION: /* Deprecated since 3.0 */
441 return "PLAYER_INTERRUPTED_BY_NOTIFICATION";
443 LOGE("Invalid interrupted code %d (Never enter here)", code);
448 static void __interrupt_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
451 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_INTERRUPT;
453 if (player_msg_get(code, recvMsg)) {
455 if (code >= PLAYER_INTERRUPTED_COMPLETED &&
456 code <= PLAYER_INTERRUPTED_BY_NOTIFICATION &&
457 code != PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT) {
458 LOGW("DEPRECATION WARNING: %s is deprecated and will be removed from next release.", _convert_code_to_str(code));
461 ((player_interrupted_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
465 static void __error_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
468 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
470 if (player_msg_get(code, recvMsg))
471 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
474 static void __buffering_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
477 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_BUFFERING;
479 if (player_msg_get(percent, recvMsg))
480 ((player_buffering_cb) cb_info->user_cb[ev]) (percent, cb_info->user_data[ev]);
483 static void __subtitle_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
486 char text[MUSE_URI_MAX_LENGTH] = { 0, };
487 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SUBTITLE;
490 player_msg_get1_string(recvMsg, duration, INT, text, ret);
492 ((player_subtitle_updated_cb) cb_info->user_cb[ev]) (duration, text, cb_info->user_data[ev]);
495 static void __capture_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
497 unsigned char *data = NULL;
500 unsigned int size = 0;
502 tbm_bo_handle thandle;
503 int key = INVALID_DEFAULT_VALUE;
506 player_msg_get4(recvMsg, width, INT, height, INT, size, INT, key, INT, ret_val);
508 if (cb_info->tfd < 0) {
509 LOGE("There is no valid tbm_fd");
513 bo = tbm_bo_import_fd(cb_info->bufmgr, cb_info->tfd);
515 LOGE("TBM get error : bo is NULL");
518 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
519 if (thandle.ptr == NULL) {
520 LOGE("TBM get error : handle pointer is NULL");
523 data = g_new(unsigned char, size);
525 memcpy(data, thandle.ptr, size);
526 ((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]);
529 LOGE("g_new failure");
535 if (cb_info->tfd > INVALID_DEFAULT_VALUE)
537 cb_info->tfd = INVALID_DEFAULT_VALUE;
543 if (key > INVALID_DEFAULT_VALUE) {
544 LOGD("send msg to release buffer. key:%d", key);
545 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
548 set_null_user_cb(cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
551 static void __seek_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
553 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_SEEK;
555 g_mutex_lock(&cb_info->seek_cb_mutex);
556 if (cb_info->user_cb[ev] && cb_info->block_seek_cb == FALSE) {
557 LOGD("call seek cb");
558 ((player_seek_completed_cb) cb_info->user_cb[ev]) (cb_info->user_data[ev]);
559 set_null_user_cb(cb_info, ev);
561 LOGW("ignored. seek cb %p, block %d", cb_info->user_cb[ev], cb_info->block_seek_cb);
563 g_mutex_unlock(&cb_info->seek_cb_mutex);
566 static void __player_remove_tsurf_list(player_cli_s * pc)
570 g_mutex_lock(&pc->cb_info->data_mutex);
571 if (pc->cb_info->tsurf_list) {
572 LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
574 for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
575 player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
577 LOGD("%p will be removed", tmp);
580 tbm_surface_destroy(tmp->tsurf);
586 g_list_free(pc->cb_info->tsurf_list);
587 pc->cb_info->tsurf_list = NULL;
589 g_mutex_unlock(&pc->cb_info->data_mutex);
593 static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, tbm_key key, tbm_surface_info_s sinfo)
597 g_mutex_lock(&cb_info->data_mutex);
598 for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
599 player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
600 if (tmp && (tmp->key == key)) { /* need to check fd, bo num, etc */
601 LOGD("found tsurf_data of tbm_key %d", key);
603 /* need to check tsuf info to support DRC */
604 if ((tbm_surface_get_height(tmp->tsurf) != sinfo.height) ||
605 (tbm_surface_get_width(tmp->tsurf) != sinfo.width)) {
607 cb_info->tsurf_list = g_list_remove(cb_info->tsurf_list, tmp);
608 LOGW("tsurf info is changed. need to create new tsurf.");
609 tbm_surface_destroy(tmp->tsurf);
612 g_mutex_unlock(&cb_info->data_mutex);
616 g_mutex_unlock(&cb_info->data_mutex);
621 g_mutex_unlock(&cb_info->data_mutex);
622 LOGD("there is no tsurf_data for tbm_key:%d", key);
626 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
628 tbm_bo bo[4] = { NULL, };
629 tbm_key key[4] = { 0, };
630 tbm_surface_info_s sinfo;
631 char *surface_info = (char *)&sinfo;
632 media_packet_h pkt = NULL;
633 tbm_surface_h tsurf = NULL;
634 player_tsurf_info_t *tsurf_data = NULL;
636 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
637 bool make_pkt_fmt = false;
638 int ret = MEDIA_FORMAT_ERROR_NONE;
639 _media_pkt_fin_data *fin_data = NULL;
643 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
645 void *jobj = muse_core_msg_json_object_new(recvMsg, NULL, &err);
647 !muse_core_msg_json_object_get_value("key[0]", jobj, &key[0], MUSE_TYPE_ANY) ||
648 !muse_core_msg_json_object_get_value("key[1]", jobj, &key[1], MUSE_TYPE_ANY) ||
649 !muse_core_msg_json_object_get_value("key[2]", jobj, &key[2], MUSE_TYPE_ANY) ||
650 !muse_core_msg_json_object_get_value("key[3]", jobj, &key[3], MUSE_TYPE_ANY) ||
651 !muse_core_msg_json_object_get_value("packet", jobj, &packet, MUSE_TYPE_POINTER) ||
652 !muse_core_msg_json_object_get_value("mimetype", jobj, &mimetype, MUSE_TYPE_ANY) ||
653 !muse_core_msg_json_object_get_value("pts", jobj, &pts, MUSE_TYPE_INT64) ||
654 !muse_core_msg_json_object_get_value("surface_info", jobj, surface_info, MUSE_TYPE_ARRAY)) {
656 LOGE("failed to get value from msg. jobj:%p, err:%d", jobj, err);
658 muse_core_msg_json_object_free(jobj);
661 muse_core_msg_json_object_free(jobj);
663 LOGD("width %d, height %d", sinfo.width, sinfo.height);
666 LOGE("cb_info is null");
670 if (!cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
671 /* send msg to release packet. */
672 LOGE("_video_decoded_cb is not set");
673 player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
677 for (i = 0; i < 4; i++) {
680 bo[i] = tbm_bo_import(cb_info->bufmgr, key[i]);
684 tsurf_data = __player_get_tsurf_from_list(cb_info, key[0], sinfo);
686 tsurf_data = g_new(player_tsurf_info_t, 1);
688 LOGE("failed to alloc tsurf info");
692 tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
694 LOGE("failed to create tbm surface");
698 tsurf_data->key = key[0];
699 tsurf_data->tsurf = tsurf;
700 if (cb_info->use_tsurf_pool) {
701 g_mutex_lock(&cb_info->data_mutex);
702 cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
703 LOGD("key %d is added to the pool", key[0]);
704 if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list))
705 LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
706 g_mutex_unlock(&cb_info->data_mutex);
709 if (tsurf_data->tsurf) {
710 tsurf = tsurf_data->tsurf;
712 LOGE("tsurf_data->tsurf is null (never enter here)");
717 /* check media packet format */
718 if (cb_info->pkt_fmt) {
719 int pkt_fmt_width = 0;
720 int pkt_fmt_height = 0;
721 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
723 media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
724 if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
725 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);
726 media_format_unref(cb_info->pkt_fmt);
727 cb_info->pkt_fmt = NULL;
733 /* create packet format */
735 LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
736 ret = media_format_create(&cb_info->pkt_fmt);
737 if (ret == MEDIA_FORMAT_ERROR_NONE) {
738 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
739 ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
740 ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
741 LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
743 LOGE("media_format_create failed");
747 fin_data = g_new(_media_pkt_fin_data, 1);
749 LOGE("failed to alloc fin_data");
752 fin_data->remote_pkt = packet;
753 fin_data->fd = cb_info->fd;
754 fin_data->use_tsurf_pool = cb_info->use_tsurf_pool;
755 ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
756 if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
757 LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
762 ret = media_packet_set_pts(pkt, (uint64_t) pts);
763 if (ret != MEDIA_PACKET_ERROR_NONE)
764 LOGE("media_packet_set_pts failed");
766 if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
767 /* call media packet callback */
768 ((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]);
770 LOGE("_video_decoded_cb is not set");
771 media_packet_destroy(pkt);
774 for (i = 0; i < bo_num; i++) {
782 media_packet_destroy(pkt);
787 for (i = 0; i < bo_num; i++) {
792 player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
796 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
799 tbm_bo_handle thandle;
800 int key = INVALID_DEFAULT_VALUE;
801 player_audio_raw_data_s audio;
803 if (!player_msg_get(key, recvMsg)) {
804 LOGE("failed to get key value from msg.");
808 if (cb_info->tfd < 0) {
809 LOGE("failed to get tbm_fd(key:%d)", key);
813 bo = tbm_bo_import_fd(cb_info->bufmgr, cb_info->tfd);
815 LOGE("TBM get error : bo is NULL, tbm_fd:%d(key:%d)", cb_info->tfd, key);
819 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
820 if (thandle.ptr == NULL) {
821 LOGE("TBM get error : handle pointer is NULL");
825 memcpy(&audio, thandle.ptr, sizeof(player_audio_raw_data_s));
826 audio.data = thandle.ptr + sizeof(player_audio_raw_data_s);
828 LOGD("user callback data %p, size %d", audio.data, audio.size);
829 ((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]);
833 if (cb_info->tfd > INVALID_DEFAULT_VALUE)
835 cb_info->tfd = INVALID_DEFAULT_VALUE;
841 if (key > INVALID_DEFAULT_VALUE) {
842 LOGD("send msg to release buffer. key:%d", key);
843 player_msg_send1_no_return(MUSE_PLAYER_API_RETURN_BUFFER, cb_info->fd, INT, key);
847 static void __video_frame_render_error_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
851 static void __pd_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
854 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_PD;
856 if (player_msg_get(type, recvMsg))
857 ((player_pd_message_cb) cb_info->user_cb[ev]) (type, cb_info->user_data[ev]);
860 static void __supported_audio_effect_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
864 static void __supported_audio_effect_freset_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
868 static void __missed_plugin_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
872 static void __media_stream_video_buffer_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
874 /* player_media_stream_buffer_status_e status; */
877 if (player_msg_get(status, recvMsg)) {
878 ((player_media_stream_buffer_status_cb)
879 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]);
883 static void __media_stream_audio_buffer_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
885 /* player_media_stream_buffer_status_e status; */
888 if (player_msg_get(status, recvMsg)) {
889 ((player_media_stream_buffer_status_cb)
890 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS])
891 ((player_media_stream_buffer_status_e) status, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS]);
896 static void __media_stream_video_buffer_cb_handler_ex(callback_cb_info_s * cb_info, char *recvMsg)
898 /* player_media_stream_buffer_status_e status; */
900 unsigned long long bytes;
903 player_msg_get2(recvMsg, status, INT, bytes, INT64, ret);
905 ((player_media_stream_buffer_status_cb_ex)
906 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO])
907 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO]);
911 static void __media_stream_audio_buffer_cb_handler_ex(callback_cb_info_s * cb_info, char *recvMsg)
913 /* player_media_stream_buffer_status_e status; */
915 unsigned long long bytes;
918 player_msg_get2(recvMsg, status, INT, bytes, INT64, ret);
920 ((player_media_stream_buffer_status_cb_ex)
921 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO])
922 ((player_media_stream_buffer_status_e) status, bytes, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO]);
927 static void __media_stream_video_seek_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
929 unsigned long long offset;
931 if (player_msg_get_type(offset, recvMsg, INT64)) {
932 ((player_media_stream_seek_cb)
933 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK])
934 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK]);
938 static void __media_stream_audio_seek_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
940 unsigned long long offset;
942 if (player_msg_get_type(offset, recvMsg, INT64)) {
943 ((player_media_stream_seek_cb)
944 cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK])
945 (offset, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK]);
949 static void __video_stream_changed_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
957 player_msg_get4(recvMsg, width, INT, height, INT, fps, INT, bit_rate, INT, ret_val);
959 ((player_video_stream_changed_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
960 (width, height, fps, bit_rate, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED]);
964 static void (*_user_callbacks[MUSE_PLAYER_EVENT_TYPE_NUM]) (callback_cb_info_s * cb_info, char *recvMsg) = {
965 __prepare_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
966 __complete_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
967 __interrupt_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_INTERRUPT */
968 __error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_ERROR */
969 __buffering_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_BUFFERING */
970 __subtitle_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUBTITLE */
971 __capture_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_CAPTURE */
972 __seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SEEK */
973 __media_packet_video_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME */
974 __audio_frame_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME */
975 __video_frame_render_error_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR */
976 __pd_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_PD */
977 __supported_audio_effect_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT */
978 __supported_audio_effect_freset_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_SUPPORTED_AUDIO_EFFECT_PRESET */
979 __missed_plugin_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MISSED_PLUGIN */
980 #ifdef _PLAYER_FOR_PRODUCT
981 NULL, /* MUSE_PLAYER_EVENT_TYPE_IMAGE_BUFFER */
982 NULL, /* MUSE_PLAYER_EVENT_TYPE_SELECTED_SUBTITLE_LANGUAGE */
984 __media_stream_video_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS */
985 __media_stream_audio_buffer_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS */
986 __media_stream_video_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO */
987 __media_stream_audio_buffer_cb_handler_ex, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO */
988 __media_stream_video_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK */
989 __media_stream_audio_seek_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK */
990 NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED */
991 __video_stream_changed_cb_handler, /* MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED */
994 static void _player_event_job_function(_player_cb_data * data)
996 muse_player_event_e ev = data->int_data;
997 if (data->cb_info->user_cb[ev])
998 _user_callbacks[ev] (data->cb_info, data->buf);
1000 LOGW("user callback is unset. type : %d", ev);
1006 static void *_player_event_queue_loop(void *param)
1009 LOGE("NULL parameter");
1012 callback_cb_info_s *cb_info = param;
1013 player_event_queue *ev = &cb_info->event_queue;
1014 _player_cb_data *event_data;
1016 g_mutex_lock(&ev->mutex);
1017 while (ev->running) {
1018 g_mutex_lock(&ev->qlock);
1019 if (g_queue_is_empty(ev->queue)) {
1020 g_mutex_unlock(&ev->qlock);
1021 g_cond_wait(&ev->cond, &ev->mutex);
1025 g_mutex_unlock(&ev->qlock);
1028 g_mutex_lock(&ev->qlock);
1029 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1030 g_mutex_unlock(&ev->qlock);
1032 _player_event_job_function(event_data);
1037 g_mutex_unlock(&ev->mutex);
1038 LOGI("Exit event loop");
1042 static gboolean _player_event_queue_new(callback_cb_info_s * cb_info)
1044 g_return_val_if_fail(cb_info, FALSE);
1045 player_event_queue *ev = &cb_info->event_queue;
1047 ev->queue = g_queue_new();
1048 g_return_val_if_fail(ev->queue, FALSE);
1049 g_mutex_init(&ev->qlock);
1051 g_mutex_init(&ev->mutex);
1052 g_cond_init(&ev->cond);
1054 ev->thread = g_thread_new("cb_event_thread", _player_event_queue_loop, (gpointer) cb_info);
1055 g_return_val_if_fail(ev->thread, FALSE);
1056 LOGI("event queue thread %p", ev->thread);
1062 static void _player_event_queue_destroy(callback_cb_info_s * cb_info)
1064 g_return_if_fail(cb_info);
1065 player_event_queue *ev = &cb_info->event_queue;
1066 _player_cb_data *event_data;
1068 LOGI("event queue thread %p", ev->thread);
1070 g_mutex_lock(&ev->mutex);
1071 ev->running = FALSE;
1072 g_cond_broadcast(&ev->cond);
1073 g_mutex_unlock(&ev->mutex);
1075 g_thread_join(ev->thread);
1076 g_thread_unref(ev->thread);
1078 while (!g_queue_is_empty(ev->queue)) {
1079 event_data = (_player_cb_data *) g_queue_pop_head(ev->queue);
1081 g_free(event_data->buf);
1085 g_queue_free(ev->queue);
1086 g_mutex_clear(&ev->qlock);
1087 g_mutex_clear(&ev->mutex);
1088 g_cond_clear(&ev->cond);
1092 static void _player_event_queue_remove(player_event_queue * ev_queue, int ev)
1096 g_mutex_lock(&ev_queue->qlock);
1098 item = g_queue_peek_head_link(ev_queue->queue);
1100 GList *next = item->next;
1101 _player_cb_data *cb_data = (_player_cb_data *)item->data;
1103 if (cb_data && cb_data->int_data == ev) {
1104 LOGD("removing '%p (ev:%d)' from event queue", cb_data, cb_data->int_data);
1105 g_free(cb_data->buf);
1108 g_queue_delete_link(ev_queue->queue, item);
1112 g_mutex_unlock(&ev_queue->qlock);
1115 static void _player_event_queue_add(player_event_queue * ev, _player_cb_data * data)
1118 g_mutex_lock(&ev->qlock);
1119 g_queue_push_tail(ev->queue, (gpointer) data);
1120 g_mutex_unlock(&ev->qlock);
1121 g_cond_signal(&ev->cond);
1125 static void _user_callback_handler(callback_cb_info_s * cb_info, muse_player_event_e event, char *buffer)
1127 LOGD("get event %d", event);
1129 if (event < MUSE_PLAYER_EVENT_TYPE_NUM) {
1130 if (cb_info->user_cb[event] && _user_callbacks[event]) {
1131 _player_cb_data *data = NULL;
1132 data = g_new(_player_cb_data, 1);
1134 LOGE("fail to alloc mem");
1137 data->int_data = (int)event;
1138 data->cb_info = cb_info;
1140 _player_event_queue_add(&cb_info->event_queue, data);
1145 static void _add_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info, int offset, int parse_len)
1147 ret_msg_s *msg = NULL;
1148 ret_msg_s *last = cb_info->buff.retMsgHead;
1150 msg = g_new(ret_msg_s, 1);
1153 msg->msg = strndup(cb_info->buff.recvMsg + offset, parse_len);
1156 cb_info->buff.retMsgHead = msg;
1163 LOGE("g_new failure");
1166 static ret_msg_s *_get_ret_msg(muse_player_api_e api, callback_cb_info_s * cb_info)
1168 ret_msg_s *msg = cb_info->buff.retMsgHead;
1169 ret_msg_s *prev = NULL;
1171 if (msg->api == api) {
1173 cb_info->buff.retMsgHead = msg->next;
1175 prev->next = msg->next;
1184 static void _notify_disconnected(callback_cb_info_s * cb_info)
1186 int code = PLAYER_ERROR_SERVICE_DISCONNECTED;
1187 muse_player_event_e ev = MUSE_PLAYER_EVENT_TYPE_ERROR;
1188 if (!cb_info || !cb_info->user_cb[ev])
1190 ((player_error_cb) cb_info->user_cb[ev]) (code, cb_info->user_data[ev]);
1193 static void *client_cb_handler(gpointer data)
1199 callback_cb_info_s *cb_info = data;
1200 char *recvMsg = NULL;
1201 muse_core_msg_parse_err_e err;
1203 while (g_atomic_int_get(&cb_info->running)) {
1205 err = MUSE_MSG_PARSE_ERROR_NONE;
1207 len = player_recv_msg(cb_info);
1211 recvMsg = cb_info->buff.recvMsg;
1212 recvMsg[len] = '\0';
1216 while (offset < len) {
1217 api = MUSE_PLAYER_API_MAX;
1218 // LOGD(">>>>>> [%d/%d] %p, %s", offset, len, recvMsg + offset, recvMsg + offset);
1221 void *jobj = muse_core_msg_json_object_new(recvMsg + offset, &parse_len, &err);
1223 if (muse_core_msg_json_object_get_value("api", jobj, &api, MUSE_TYPE_INT)) {
1224 if (api < MUSE_PLAYER_API_MAX) {
1225 g_mutex_lock(&cb_info->player_mutex);
1226 cb_info->buff.recved++;
1227 _add_ret_msg(api, cb_info, offset, parse_len);
1228 g_cond_signal(&cb_info->player_cond[api]);
1229 g_mutex_unlock(&cb_info->player_mutex);
1230 if (api == MUSE_PLAYER_API_DESTROY)
1231 g_atomic_int_set(&cb_info->running, 0);
1232 } else if (api == MUSE_PLAYER_CB_EVENT) {
1235 g_mutex_lock(&cb_info->player_mutex);
1236 buffer = strndup(recvMsg + offset, parse_len);
1237 g_mutex_unlock(&cb_info->player_mutex);
1238 if (muse_core_msg_json_object_get_value("event", jobj, &event, MUSE_TYPE_INT))
1239 _user_callback_handler(cb_info, event, buffer);
1240 } else if (api == MUSE_PLAYER_CB_CREATE_ACK) {
1241 g_mutex_lock(&cb_info->player_mutex);
1242 cb_info->buff.recved++;
1243 g_cond_signal(&cb_info->server_ack_cond);
1244 g_mutex_unlock(&cb_info->player_mutex);
1247 LOGE("Failed to get value. offset:%d/%d, [msg][ %s ]", offset, len, (recvMsg+offset));
1249 muse_core_msg_json_object_free(jobj);
1251 LOGE("Failed to get msg obj. err:%d", err);
1254 if (parse_len == 0 || err != MUSE_MSG_PARSE_ERROR_NONE)
1257 offset += parse_len;
1258 parse_len = len - offset;
1261 if (g_atomic_int_get(&cb_info->running))
1262 _notify_disconnected(cb_info);
1263 LOGD("client cb exit");
1268 static callback_cb_info_s *callback_new(gint sockfd)
1270 callback_cb_info_s *cb_info;
1274 g_return_val_if_fail(sockfd > 0, NULL);
1276 cb_info = g_new(callback_cb_info_s, 1);
1279 memset(cb_info, 0, sizeof(callback_cb_info_s));
1281 g_mutex_init(&cb_info->player_mutex);
1282 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1283 g_cond_init(&cb_info->player_cond[i]);
1284 g_cond_init(&cb_info->server_ack_cond);
1286 g_mutex_init(&cb_info->data_mutex);
1287 g_mutex_init(&cb_info->seek_cb_mutex);
1289 buff = &cb_info->buff;
1290 buff->recvMsg = g_new(char, MUSE_MSG_MAX_LENGTH + 1);
1291 buff->bufLen = MUSE_MSG_MAX_LENGTH + 1;
1293 buff->retMsgHead = NULL;
1294 buff->part_of_msg = NULL;
1296 g_atomic_int_set(&cb_info->running, 1);
1297 cb_info->fd = sockfd;
1298 cb_info->thread = g_thread_new("callback_thread", client_cb_handler, (gpointer) cb_info);
1299 cb_info->tfd = INVALID_DEFAULT_VALUE;
1304 static void callback_destroy(callback_cb_info_s * cb_info)
1307 g_return_if_fail(cb_info);
1309 if (cb_info->fd > INVALID_DEFAULT_VALUE)
1310 muse_core_connection_close(cb_info->fd);
1311 if (cb_info->data_fd > INVALID_DEFAULT_VALUE)
1312 muse_core_connection_close(cb_info->data_fd);
1313 cb_info->fd = cb_info->data_fd = INVALID_DEFAULT_VALUE;
1315 g_thread_join(cb_info->thread);
1316 g_thread_unref(cb_info->thread);
1317 cb_info->thread = NULL;
1319 LOGI("%p Callback destroyed", cb_info);
1321 g_mutex_clear(&cb_info->player_mutex);
1322 for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
1323 g_cond_clear(&cb_info->player_cond[i]);
1324 g_cond_clear(&cb_info->server_ack_cond);
1326 g_mutex_clear(&cb_info->data_mutex);
1327 g_mutex_clear(&cb_info->seek_cb_mutex);
1329 g_free(cb_info->buff.recvMsg);
1330 if (cb_info->buff.part_of_msg)
1331 g_free(cb_info->buff.part_of_msg);
1335 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api)
1340 case MUSE_PLAYER_API_PREPARE:
1341 case MUSE_PLAYER_API_PREPARE_ASYNC:
1342 case MUSE_PLAYER_API_UNPREPARE:
1343 case MUSE_PLAYER_API_START:
1344 case MUSE_PLAYER_API_STOP:
1345 case MUSE_PLAYER_API_PAUSE:
1346 timeout += SERVER_TIMEOUT(pc);
1349 /* check prepare async is done */
1350 if (pc && CALLBACK_INFO(pc) && CALLBACK_INFO(pc)->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])
1351 timeout += SERVER_TIMEOUT(pc);
1354 timeout += CALLBACK_TIME_OUT;
1355 return timeout; /* ms */
1358 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out)
1360 int ret = PLAYER_ERROR_NONE;
1361 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1362 msg_buff_s *buff = &cb_info->buff;
1363 ret_msg_s *msg = NULL;
1365 g_mutex_lock(&cb_info->player_mutex);
1367 msg = _get_ret_msg(api, cb_info);
1368 if (!buff->recved || !msg) {
1369 if (!g_cond_wait_until(&cb_info->player_cond[api], &cb_info->player_mutex, end_time)) {
1370 LOGW("api %d return msg does not received %dms", api, time_out);
1371 g_mutex_unlock(&cb_info->player_mutex);
1372 return PLAYER_ERROR_INVALID_OPERATION;
1376 msg = _get_ret_msg(api, cb_info);
1378 *ret_buf = msg->msg;
1380 if (!player_msg_get(ret, *ret_buf))
1381 ret = PLAYER_ERROR_INVALID_OPERATION;
1383 LOGE("api %d return msg is not exist", api);
1384 ret = PLAYER_ERROR_INVALID_OPERATION;
1388 g_mutex_unlock(&cb_info->player_mutex);
1393 int client_wait_for_server_ack(muse_player_api_e api, callback_cb_info_s * cb_info, int time_out)
1395 int ret = PLAYER_ERROR_NONE;
1396 gint64 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_MILLISECOND;
1397 msg_buff_s *buff = &cb_info->buff;
1399 g_mutex_lock(&cb_info->player_mutex);
1401 if (!buff->recved) {
1402 if (!g_cond_wait_until(&cb_info->server_ack_cond, &cb_info->player_mutex, end_time)) {
1403 LOGW("server ack msg does not received %dms", time_out);
1405 ret = PLAYER_ERROR_INVALID_OPERATION;
1407 LOGD("Another msg is received, continue create handle");
1408 g_mutex_unlock(&cb_info->player_mutex);
1414 g_mutex_unlock(&cb_info->player_mutex);
1421 * Public Implementation
1424 int player_create(player_h * player)
1426 PLAYER_INSTANCE_CHECK(player);
1428 int ret = PLAYER_ERROR_NONE;
1429 int sock_fd = INVALID_DEFAULT_VALUE;
1432 muse_player_api_e api = MUSE_PLAYER_API_CREATE;
1433 muse_core_api_module_e module = MUSE_PLAYER;
1434 player_cli_s *pc = NULL;
1435 char *ret_buf = NULL;
1436 int retry_count = CONNECTION_RETRY;
1441 pc = g_new0(player_cli_s, 1);
1443 return PLAYER_ERROR_OUT_OF_MEMORY;
1445 while (--retry_count) {
1446 sock_fd = muse_core_client_new();
1447 if (sock_fd <= INVALID_DEFAULT_VALUE) {
1448 LOGE("connection failure %d", errno);
1449 ret = PLAYER_ERROR_INVALID_OPERATION;
1451 usleep(CONNECTION_TIME_OUT * G_TIME_SPAN_MILLISECOND);
1455 player_msg_create_handle(api, sock_fd, INT, module, INT, pid);
1457 pc->cb_info = callback_new(sock_fd);
1459 LOGE("fail to create callback");
1460 ret = PLAYER_ERROR_INVALID_OPERATION;
1464 ret = client_wait_for_server_ack(api, pc->cb_info, CREATE_CB_TIME_OUT);
1465 if (ret == PLAYER_ERROR_INVALID_OPERATION) {
1471 if (!_player_event_queue_new(pc->cb_info)) {
1472 LOGE("fail to create event queue");
1473 ret = PLAYER_ERROR_INVALID_OPERATION;
1477 ret = client_wait_for_cb_return(api, pc->cb_info, &ret_buf, CALLBACK_TIME_OUT * 2);
1478 if (ret == PLAYER_ERROR_NONE) {
1479 intptr_t module_addr;
1480 *player = (player_h) pc;
1481 if (player_msg_get_type(module_addr, ret_buf, POINTER)) {
1482 pc->cb_info->data_fd = muse_core_client_new_data_ch();
1483 muse_core_send_module_addr(module_addr, pc->cb_info->data_fd);
1484 LOGD("Data channel fd %d, muse module addr %p", pc->cb_info->data_fd, module_addr);
1486 ret = PLAYER_ERROR_INVALID_OPERATION;
1489 SERVER_TIMEOUT(pc) = MAX_SERVER_TIME_OUT; /* will be update after prepare phase. */
1493 pc->cb_info->bufmgr = tbm_bufmgr_init(-1);
1494 pc->push_media_stream = FALSE;
1500 if (pc && pc->cb_info) {
1501 if (pc->cb_info->event_queue.running)
1502 _player_event_queue_destroy(pc->cb_info);
1503 callback_destroy(pc->cb_info);
1508 LOGE("ret value : %d, retry #%d", ret, CONNECTION_RETRY - retry_count);
1517 int player_destroy(player_h player)
1519 PLAYER_INSTANCE_CHECK(player);
1521 int ret = PLAYER_ERROR_NONE;
1522 muse_player_api_e api = MUSE_PLAYER_API_DESTROY;
1523 player_cli_s *pc = (player_cli_s *) player;
1524 char *ret_buf = NULL;
1528 player_msg_send(api, pc, ret_buf, ret);
1529 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1530 if (CALLBACK_INFO(pc) && EVAS_HANDLE(pc)) {
1531 player_unset_media_packet_video_frame_decoded_cb(player);
1532 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
1533 LOGW("fail to unset evas client");
1537 if (CALLBACK_INFO(pc)) {
1538 __player_remove_tsurf_list(pc);
1539 _player_event_queue_destroy(CALLBACK_INFO(pc));
1540 tbm_bufmgr_deinit(TBM_BUFMGR(pc));
1542 callback_destroy(CALLBACK_INFO(pc));
1552 int player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
1554 PLAYER_INSTANCE_CHECK(player);
1555 int ret = PLAYER_ERROR_NONE;
1556 muse_player_api_e api = MUSE_PLAYER_API_PREPARE_ASYNC;
1557 player_cli_s *pc = (player_cli_s *) player;
1558 char *ret_buf = NULL;
1562 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
1563 LOGE("PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing...", PLAYER_ERROR_INVALID_OPERATION);
1564 return PLAYER_ERROR_INVALID_OPERATION;
1566 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
1567 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
1569 player_msg_send(api, pc, ret_buf, ret);
1570 if (ret == PLAYER_ERROR_NONE) {
1572 player_msg_get_type(timeout, ret_buf, INT);
1574 LOGD("server timeout will be %d sec", timeout);
1575 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1582 int player_prepare(player_h player)
1584 PLAYER_INSTANCE_CHECK(player);
1585 int ret = PLAYER_ERROR_NONE;
1586 muse_player_api_e api = MUSE_PLAYER_API_PREPARE;
1587 player_cli_s *pc = (player_cli_s *) player;
1588 char *ret_buf = NULL;
1592 player_msg_send(api, pc, ret_buf, ret);
1593 if (ret == PLAYER_ERROR_NONE) {
1595 player_msg_get_type(timeout, ret_buf, INT);
1597 LOGD("server timeout will be %d sec", timeout);
1598 SERVER_TIMEOUT(pc) = timeout * G_TIME_SPAN_MILLISECOND;
1605 int player_unprepare(player_h player)
1607 PLAYER_INSTANCE_CHECK(player);
1608 int ret = PLAYER_ERROR_NONE;
1609 muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
1610 player_cli_s *pc = (player_cli_s *) player;
1611 char *ret_buf = NULL;
1615 if (!CALLBACK_INFO(pc))
1616 return PLAYER_ERROR_INVALID_STATE;
1617 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1618 if (EVAS_HANDLE(pc)) {
1619 player_unset_media_packet_video_frame_decoded_cb(player);
1620 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
1621 LOGW("fail to unset evas client");
1624 player_msg_send(api, pc, ret_buf, ret);
1625 if (ret == PLAYER_ERROR_NONE) {
1626 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1627 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_PREPARE);
1629 _player_deinit_memory_buffer(pc);
1632 pc->cb_info->video_frame_pool_size = 0;
1633 __player_remove_tsurf_list(pc);
1639 int player_set_uri(player_h player, const char *uri)
1641 PLAYER_INSTANCE_CHECK(player);
1642 PLAYER_NULL_ARG_CHECK(uri);
1643 int ret = PLAYER_ERROR_NONE;
1644 muse_player_api_e api = MUSE_PLAYER_API_SET_URI;
1645 player_cli_s *pc = (player_cli_s *) player;
1646 char *ret_buf = NULL;
1650 player_msg_send1(api, pc, ret_buf, ret, STRING, uri);
1651 pc->push_media_stream = FALSE;
1657 int player_set_memory_buffer(player_h player, const void *data, int size)
1659 PLAYER_INSTANCE_CHECK(player);
1660 PLAYER_NULL_ARG_CHECK(data);
1661 int ret = PLAYER_ERROR_NONE;
1662 muse_player_api_e api = MUSE_PLAYER_API_SET_MEMORY_BUFFER;
1663 player_cli_s *pc = (player_cli_s *) player;
1664 char *ret_buf = NULL;
1666 tbm_bo_handle thandle;
1667 tbm_fd tfd = INVALID_DEFAULT_VALUE;
1669 if (SERVER_TBM_BO(pc)) {
1670 LOGE("Already set the memory buffer. unprepare please");
1671 return PLAYER_ERROR_INVALID_OPERATION;
1674 bo = tbm_bo_alloc(pc->cb_info->bufmgr, size, TBM_BO_DEFAULT);
1676 LOGE("TBM get error : bo is NULL");
1677 return PLAYER_ERROR_INVALID_OPERATION;
1679 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
1680 if (thandle.ptr == NULL) {
1681 LOGE("TBM get error : handle pointer is NULL");
1682 ret = PLAYER_ERROR_INVALID_OPERATION;
1685 memcpy(thandle.ptr, data, size);
1688 tfd = tbm_bo_export_fd(bo);
1690 LOGE("tbm_bo_export_fd err 0x%x", tfd);
1691 ret = PLAYER_ERROR_INVALID_OPERATION;
1695 player_msg_send1_fd(api, pc, ret_buf, ret, INT, size, tfd);
1696 pc->push_media_stream = FALSE;
1699 if (tfd > INVALID_DEFAULT_VALUE)
1704 if (ret == PLAYER_ERROR_NONE) {
1705 intptr_t bo_addr = 0;
1706 if (player_msg_get_type(bo_addr, ret_buf, POINTER))
1707 SERVER_TBM_BO(pc) = (intptr_t) bo_addr;
1714 static int _player_deinit_memory_buffer(player_cli_s * pc)
1716 PLAYER_INSTANCE_CHECK(pc);
1717 int ret = PLAYER_ERROR_NONE;
1718 muse_player_api_e api = MUSE_PLAYER_API_DEINIT_MEMORY_BUFFER;
1719 intptr_t bo_addr = SERVER_TBM_BO(pc);
1724 player_msg_send1_async(api, pc, POINTER, bo_addr);
1726 SERVER_TBM_BO(pc) = 0;
1731 int player_get_state(player_h player, player_state_e * pstate)
1733 PLAYER_INSTANCE_CHECK(player);
1734 PLAYER_NULL_ARG_CHECK(pstate);
1735 int ret = PLAYER_ERROR_NONE;
1736 muse_player_api_e api = MUSE_PLAYER_API_GET_STATE;
1737 player_cli_s *pc = (player_cli_s *) player;
1739 char *ret_buf = NULL;
1743 player_msg_send(api, pc, ret_buf, ret);
1745 if (ret == PLAYER_ERROR_NONE) {
1746 player_msg_get(state, ret_buf);
1754 int player_set_volume(player_h player, float left, float right)
1756 PLAYER_INSTANCE_CHECK(player);
1757 PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1758 PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1759 int ret = PLAYER_ERROR_NONE;
1760 muse_player_api_e api = MUSE_PLAYER_API_SET_VOLUME;
1761 player_cli_s *pc = (player_cli_s *) player;
1762 char *ret_buf = NULL;
1766 player_msg_send2(api, pc, ret_buf, ret, DOUBLE, right, DOUBLE, left);
1771 int player_get_volume(player_h player, float *pleft, float *pright)
1773 PLAYER_INSTANCE_CHECK(player);
1774 PLAYER_NULL_ARG_CHECK(pleft);
1775 PLAYER_NULL_ARG_CHECK(pright);
1776 int ret = PLAYER_ERROR_NONE;
1777 muse_player_api_e api = MUSE_PLAYER_API_GET_VOLUME;
1778 player_cli_s *pc = (player_cli_s *) player;
1781 char *ret_buf = NULL;
1785 player_msg_send(api, pc, ret_buf, ret);
1787 if (ret == PLAYER_ERROR_NONE) {
1788 bool ret_val = TRUE;
1789 player_msg_get2(ret_buf, left, DOUBLE, right, DOUBLE, ret_val);
1791 *pleft = (float)left;
1792 *pright = (float)right;
1794 LOGE("failed to get value from msg");
1795 ret = PLAYER_ERROR_INVALID_OPERATION;
1803 int player_set_sound_type(player_h player, sound_type_e type)
1805 PLAYER_INSTANCE_CHECK(player);
1806 int ret = PLAYER_ERROR_NONE;
1807 muse_player_api_e api = MUSE_PLAYER_API_SET_SOUND_TYPE;
1808 player_cli_s *pc = (player_cli_s *) player;
1809 char *ret_buf = NULL;
1812 LOGW("DEPRECATION WARNING: player_set_sound_type() is deprecated and will be removed from next release. Use player_set_audio_policy_info() instead.");
1814 player_msg_send1(api, pc, ret_buf, ret, INT, type);
1819 int player_set_audio_policy_info(player_h player, sound_stream_info_h stream_info)
1821 PLAYER_INSTANCE_CHECK(player);
1823 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_POLICY_INFO;
1824 player_cli_s *pc = (player_cli_s *) player;
1825 char *ret_buf = NULL;
1829 bool is_available = false;
1831 /* check if stream_info is valid */
1832 int ret = __player_convert_error_code(
1833 sound_manager_is_available_stream_information(
1834 stream_info, NATIVE_API_PLAYER, &is_available), (char *)__FUNCTION__);
1836 if (ret == PLAYER_ERROR_NONE) {
1837 if (is_available == false)
1838 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
1840 char *stream_type = NULL;
1841 int stream_index = 0;
1842 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
1843 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
1844 if (ret == SOUND_MANAGER_ERROR_NONE)
1845 player_msg_send2(api, pc, ret_buf, ret, STRING, stream_type, INT, stream_index);
1847 ret = PLAYER_ERROR_INVALID_OPERATION;
1856 int player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
1858 PLAYER_INSTANCE_CHECK(player);
1859 int ret = PLAYER_ERROR_NONE;
1860 muse_player_api_e api = MUSE_PLAYER_API_SET_AUDIO_LATENCY_MODE;
1861 player_cli_s *pc = (player_cli_s *) player;
1862 char *ret_buf = NULL;
1866 player_msg_send1(api, pc, ret_buf, ret, INT, latency_mode);
1871 int player_get_audio_latency_mode(player_h player, audio_latency_mode_e * platency_mode)
1873 PLAYER_INSTANCE_CHECK(player);
1874 PLAYER_NULL_ARG_CHECK(platency_mode);
1875 int ret = PLAYER_ERROR_NONE;
1876 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_LATENCY_MODE;
1877 player_cli_s *pc = (player_cli_s *) player;
1878 char *ret_buf = NULL;
1879 int latency_mode = -1;
1883 player_msg_send(api, pc, ret_buf, ret);
1885 if (ret == PLAYER_ERROR_NONE) {
1886 player_msg_get(latency_mode, ret_buf);
1887 *platency_mode = latency_mode;
1895 int player_start(player_h player)
1897 PLAYER_INSTANCE_CHECK(player);
1898 int ret = PLAYER_ERROR_NONE;
1899 muse_player_api_e api = MUSE_PLAYER_API_START;
1900 player_cli_s *pc = (player_cli_s *) player;
1901 char *ret_buf = NULL;
1904 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1905 if (EVAS_HANDLE(pc)) {
1906 ret = mm_evas_renderer_update_param(EVAS_HANDLE(pc));
1907 if (ret != MM_ERROR_NONE) {
1908 LOGE("mm_evas_renderer_update_param err 0x%x", ret);
1909 return PLAYER_ERROR_INVALID_OPERATION;
1913 player_msg_send(api, pc, ret_buf, ret);
1919 int player_stop(player_h player)
1921 PLAYER_INSTANCE_CHECK(player);
1922 int ret = PLAYER_ERROR_NONE;
1923 muse_player_api_e api = MUSE_PLAYER_API_STOP;
1924 player_cli_s *pc = (player_cli_s *) player;
1925 char *ret_buf = NULL;
1929 player_msg_send(api, pc, ret_buf, ret);
1930 if (ret == PLAYER_ERROR_NONE)
1931 set_null_user_cb_lock(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1937 int player_pause(player_h player)
1939 PLAYER_INSTANCE_CHECK(player);
1940 int ret = PLAYER_ERROR_NONE;
1941 muse_player_api_e api = MUSE_PLAYER_API_PAUSE;
1942 player_cli_s *pc = (player_cli_s *) player;
1943 char *ret_buf = NULL;
1947 player_msg_send(api, pc, ret_buf, ret);
1952 int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data)
1954 PLAYER_INSTANCE_CHECK(player);
1955 PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1957 int ret = PLAYER_ERROR_NONE;
1958 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION;
1959 player_cli_s *pc = (player_cli_s *) player;
1960 char *ret_buf = NULL;
1961 int pos = millisecond;
1965 LOGE("cb_info is null");
1966 return PLAYER_ERROR_INVALID_OPERATION;
1969 if ((pc->push_media_stream == FALSE) &&
1970 (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])) {
1971 LOGE("PLAYER_ERROR_SEEK_FAILED (0x%08x) : seeking...", PLAYER_ERROR_SEEK_FAILED);
1972 return PLAYER_ERROR_SEEK_FAILED;
1974 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
1975 if (pc->push_media_stream == TRUE)
1976 pc->cb_info->block_seek_cb = TRUE;
1977 LOGI("Event type : %d, pos : %d ", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond);
1978 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
1979 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
1980 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
1983 player_msg_send2(api, pc, ret_buf, ret, INT, pos, INT, accurate);
1985 if (ret != PLAYER_ERROR_NONE) {
1986 g_mutex_lock(&pc->cb_info->seek_cb_mutex);
1987 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_SEEK);
1988 g_mutex_unlock(&pc->cb_info->seek_cb_mutex);
1991 if (pc->push_media_stream == TRUE)
1992 _player_event_queue_remove(&pc->cb_info->event_queue, MUSE_PLAYER_EVENT_TYPE_SEEK);
1994 pc->cb_info->block_seek_cb = FALSE;
1999 int player_get_play_position(player_h player, int *millisecond)
2001 PLAYER_INSTANCE_CHECK(player);
2002 PLAYER_NULL_ARG_CHECK(millisecond);
2004 int ret = PLAYER_ERROR_NONE;
2005 muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION;
2006 player_cli_s *pc = (player_cli_s *) player;
2008 char *ret_buf = NULL;
2012 player_msg_send(api, pc, ret_buf, ret);
2014 if (ret == PLAYER_ERROR_NONE) {
2015 player_msg_get(pos, ret_buf);
2023 int player_set_mute(player_h player, bool muted)
2025 PLAYER_INSTANCE_CHECK(player);
2026 int ret = PLAYER_ERROR_NONE;
2027 muse_player_api_e api = MUSE_PLAYER_API_SET_MUTE;
2028 player_cli_s *pc = (player_cli_s *) player;
2029 char *ret_buf = NULL;
2030 int mute = (int)muted;
2034 player_msg_send1(api, pc, ret_buf, ret, INT, mute);
2039 int player_is_muted(player_h player, bool * muted)
2041 PLAYER_INSTANCE_CHECK(player);
2042 PLAYER_NULL_ARG_CHECK(muted);
2043 int ret = PLAYER_ERROR_NONE;
2044 muse_player_api_e api = MUSE_PLAYER_API_IS_MUTED;
2045 player_cli_s *pc = (player_cli_s *) player;
2046 char *ret_buf = NULL;
2051 player_msg_send(api, pc, ret_buf, ret);
2052 if (ret == PLAYER_ERROR_NONE) {
2053 player_msg_get(mute, ret_buf);
2054 *muted = (bool) mute;
2061 int player_set_looping(player_h player, bool looping)
2063 PLAYER_INSTANCE_CHECK(player);
2064 int ret = PLAYER_ERROR_NONE;
2065 muse_player_api_e api = MUSE_PLAYER_API_SET_LOOPING;
2066 player_cli_s *pc = (player_cli_s *) player;
2067 char *ret_buf = NULL;
2071 player_msg_send1(api, pc, ret_buf, ret, INT, looping);
2076 int player_is_looping(player_h player, bool * plooping)
2078 PLAYER_INSTANCE_CHECK(player);
2079 PLAYER_NULL_ARG_CHECK(plooping);
2080 int ret = PLAYER_ERROR_NONE;
2081 muse_player_api_e api = MUSE_PLAYER_API_IS_LOOPING;
2082 player_cli_s *pc = (player_cli_s *) player;
2083 char *ret_buf = NULL;
2088 player_msg_send(api, pc, ret_buf, ret);
2089 if (ret == PLAYER_ERROR_NONE) {
2090 player_msg_get(looping, ret_buf);
2091 *plooping = looping;
2097 int player_get_duration(player_h player, int *pduration)
2099 PLAYER_INSTANCE_CHECK(player);
2100 PLAYER_NULL_ARG_CHECK(pduration);
2101 int ret = PLAYER_ERROR_NONE;
2102 muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION;
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(duration, ret_buf);
2112 *pduration = duration;
2119 int player_set_display(player_h player, player_display_type_e type, player_display_h display)
2121 PLAYER_INSTANCE_CHECK(player);
2122 int ret = PLAYER_ERROR_NONE;
2123 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
2124 player_cli_s *pc = (player_cli_s *) player;
2125 char *ret_buf = NULL;
2126 Evas_Object *obj = NULL;
2127 const char *object_type = NULL;
2128 wl_win_msg_type wl_win;
2129 char *wl_win_msg = (char *)&wl_win;
2130 unsigned int wl_surface_id;
2131 struct wl_surface *wl_surface;
2132 struct wl_display *wl_display;
2133 Ecore_Wl_Window *wl_window = NULL;
2136 wl_win.wl_window_x = 0;
2137 wl_win.wl_window_y = 0;
2138 wl_win.wl_window_width = 0;
2139 wl_win.wl_window_height = 0;
2141 LOGD("ENTER type: %d", type);
2143 if (type != PLAYER_DISPLAY_TYPE_NONE) {
2144 obj = (Evas_Object *) display;
2146 return PLAYER_ERROR_INVALID_PARAMETER;
2148 object_type = evas_object_type_get(obj);
2150 if (type == PLAYER_DISPLAY_TYPE_OVERLAY && !strcmp(object_type, "elm_win")) {
2151 /* wayland overlay surface */
2152 LOGI("Wayland overlay surface type");
2155 e = evas_object_evas_get(obj);
2156 return_val_if_fail(e != NULL, PLAYER_ERROR_INVALID_OPERATION);
2158 if (ret != MM_ERROR_NONE) {
2159 LOGE("Fail to get window geometry");
2163 wl_window = elm_win_wl_window_get(obj);
2164 return_val_if_fail(wl_window != NULL, PLAYER_ERROR_INVALID_OPERATION);
2166 wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window);
2167 return_val_if_fail(wl_surface != NULL, PLAYER_ERROR_INVALID_OPERATION);
2169 /* get wl_display */
2170 wl_display = (struct wl_display *)ecore_wl_display_get();
2171 return_val_if_fail(wl_display != NULL, PLAYER_ERROR_INVALID_OPERATION);
2173 LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
2175 ret = _wl_client_create(&pc->wlclient);
2176 if (ret != MM_ERROR_NONE) {
2177 LOGE("Wayland client create failure");
2181 wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display);
2182 LOGD("wl_surface_id = %d", wl_surface_id);
2184 /* need to free always */
2186 g_free(pc->wlclient);
2187 pc->wlclient = NULL;
2189 return_val_if_fail(wl_surface_id > 0, PLAYER_ERROR_INVALID_OPERATION);
2190 wl_win.wl_surface_id = wl_surface_id;
2193 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2194 else if (type == PLAYER_DISPLAY_TYPE_EVAS && !strcmp(object_type, "image")) {
2195 /* evas object surface */
2196 LOGI("evas surface type");
2199 evas_object_geometry_get(obj, &wl_win.wl_window_x, &wl_win.wl_window_y,
2200 &wl_win.wl_window_width, &wl_win.wl_window_height);
2202 if (EVAS_HANDLE(pc)) {
2203 LOGW("evas client already exists");
2204 if (mm_evas_renderer_destroy(&EVAS_HANDLE(pc)) != MM_ERROR_NONE)
2205 LOGW("fail to unset evas client");
2207 if (mm_evas_renderer_create(&EVAS_HANDLE(pc), obj) != MM_ERROR_NONE) {
2208 LOGW("fail to set evas client");
2209 /* FIXME : need to handle error case */
2212 if (player_set_media_packet_video_frame_decoded_cb(player, mm_evas_renderer_write, (void *)EVAS_HANDLE(pc)) != PLAYER_ERROR_NONE)
2213 LOGW("fail to set decoded callback");
2217 return PLAYER_ERROR_INVALID_PARAMETER;
2219 return PLAYER_ERROR_INVALID_PARAMETER;
2220 } else { /* PLAYER_DISPLAY_TYPE_NONE */
2221 LOGI("Wayland surface type is NONE");
2224 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2229 int player_set_display_mode(player_h player, player_display_mode_e mode)
2231 PLAYER_INSTANCE_CHECK(player);
2232 PLAYER_CHECK_CONDITION(PLAYER_DISPLAY_MODE_LETTER_BOX <= mode && mode < PLAYER_DISPLAY_MODE_NUM, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2233 int ret = PLAYER_ERROR_NONE;
2234 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_MODE;
2235 player_cli_s *pc = (player_cli_s *) player;
2236 char *ret_buf = NULL;
2239 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2240 if (EVAS_HANDLE(pc)) {
2241 ret = mm_evas_renderer_set_geometry(EVAS_HANDLE(pc), mode);
2242 /* FIXME: need to handle error code from evas */
2243 return PLAYER_ERROR_NONE;
2246 player_msg_send1(api, pc, ret_buf, ret, INT, mode);
2251 int player_get_display_mode(player_h player, player_display_mode_e * pmode)
2253 PLAYER_INSTANCE_CHECK(player);
2254 PLAYER_NULL_ARG_CHECK(pmode);
2255 int ret = PLAYER_ERROR_NONE;
2256 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_MODE;
2257 player_cli_s *pc = (player_cli_s *) player;
2258 char *ret_buf = NULL;
2262 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2263 if (EVAS_HANDLE(pc)) {
2264 ret = mm_evas_renderer_get_geometry(EVAS_HANDLE(pc), &mode);
2265 *pmode = (player_display_mode_e) mode;
2266 /* FIXME: need to handle error code from evas */
2267 return PLAYER_ERROR_NONE;
2270 player_msg_send(api, pc, ret_buf, ret);
2271 if (ret == PLAYER_ERROR_NONE) {
2272 player_msg_get_type(mode, ret_buf, INT);
2281 int player_set_display_roi_area(player_h player, int x, int y, int width, int height)
2283 PLAYER_INSTANCE_CHECK(player);
2284 PLAYER_CHECK_CONDITION(width > 0 && height > 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2286 int ret = PLAYER_ERROR_NONE;
2287 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROI_AREA;
2288 player_cli_s *pc = (player_cli_s *) player;
2289 char *ret_buf = NULL;
2290 wl_win_msg_type wl_win;
2291 char *wl_win_msg = (char *)&wl_win;
2295 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2296 if (EVAS_HANDLE(pc)) {
2297 ret = mm_evas_renderer_set_roi_area(EVAS_HANDLE(pc), x, y, width, height);
2298 /* FIXME: need to handle error code from evas */
2299 return PLAYER_ERROR_NONE;
2302 wl_win.wl_window_x = x;
2303 wl_win.wl_window_y = y;
2304 wl_win.wl_window_width = width;
2305 wl_win.wl_window_height = height;
2307 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
2312 int player_set_playback_rate(player_h player, float rate)
2314 PLAYER_INSTANCE_CHECK(player);
2315 PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2316 int ret = PLAYER_ERROR_NONE;
2317 muse_player_api_e api = MUSE_PLAYER_API_SET_PLAYBACK_RATE;
2318 player_cli_s *pc = (player_cli_s *) player;
2319 char *ret_buf = NULL;
2323 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
2328 int player_set_display_rotation(player_h player, player_display_rotation_e rotation)
2330 PLAYER_INSTANCE_CHECK(player);
2331 int ret = PLAYER_ERROR_NONE;
2332 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_ROTATION;
2333 player_cli_s *pc = (player_cli_s *) player;
2334 char *ret_buf = NULL;
2337 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2338 if (EVAS_HANDLE(pc)) {
2339 ret = mm_evas_renderer_set_rotation(EVAS_HANDLE(pc), rotation);
2340 /* FIXME: need to handle error code from evas */
2341 return PLAYER_ERROR_NONE;
2344 player_msg_send1(api, pc, ret_buf, ret, INT, rotation);
2349 int player_get_display_rotation(player_h player, player_display_rotation_e * protation)
2351 PLAYER_INSTANCE_CHECK(player);
2352 PLAYER_NULL_ARG_CHECK(protation);
2353 int ret = PLAYER_ERROR_NONE;
2354 player_cli_s *pc = (player_cli_s *) player;
2355 muse_player_api_e api = MUSE_PLAYER_API_GET_DISPLAY_ROTATION;
2356 char *ret_buf = NULL;
2360 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2361 if (EVAS_HANDLE(pc)) {
2362 ret = mm_evas_renderer_get_rotation(EVAS_HANDLE(pc), &rotation);
2363 *protation = (player_display_rotation_e) rotation;
2364 /* FIXME: need to handle error code from evas */
2365 return PLAYER_ERROR_NONE;
2368 player_msg_send(api, pc, ret_buf, ret);
2369 if (ret == PLAYER_ERROR_NONE) {
2370 player_msg_get_type(rotation, ret_buf, INT);
2371 *protation = rotation;
2378 int player_set_display_visible(player_h player, bool visible)
2380 PLAYER_INSTANCE_CHECK(player);
2381 int ret = PLAYER_ERROR_NONE;
2382 player_cli_s *pc = (player_cli_s *) player;
2383 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY_VISIBLE;
2384 char *ret_buf = NULL;
2387 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2388 if (EVAS_HANDLE(pc)) {
2389 ret = mm_evas_renderer_set_visible(EVAS_HANDLE(pc), visible);
2390 /* FIXME: need to handle error code from evas */
2391 return PLAYER_ERROR_NONE;
2394 player_msg_send1(api, pc, ret_buf, ret, INT, visible);
2399 int player_is_display_visible(player_h player, bool * pvisible)
2401 PLAYER_INSTANCE_CHECK(player);
2402 PLAYER_NULL_ARG_CHECK(pvisible);
2403 int ret = PLAYER_ERROR_NONE;
2404 player_cli_s *pc = (player_cli_s *) player;
2405 muse_player_api_e api = MUSE_PLAYER_API_IS_DISPLAY_VISIBLE;
2406 char *ret_buf = NULL;
2408 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2412 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2413 if (EVAS_HANDLE(pc)) {
2414 ret = mm_evas_renderer_get_visible(EVAS_HANDLE(pc), &visible);
2420 /* FIXME: need to handle error code from evas */
2421 return PLAYER_ERROR_NONE;
2424 player_msg_send(api, pc, ret_buf, ret);
2425 if (ret == PLAYER_ERROR_NONE) {
2426 player_msg_get_type(value, ret_buf, INT);
2438 int player_get_content_info(player_h player, player_content_info_e key, char **pvalue)
2440 PLAYER_INSTANCE_CHECK(player);
2441 PLAYER_NULL_ARG_CHECK(pvalue);
2442 int ret = PLAYER_ERROR_NONE;
2443 muse_player_api_e api = MUSE_PLAYER_API_GET_CONTENT_INFO;
2444 player_cli_s *pc = (player_cli_s *) player;
2445 char *ret_buf = NULL;
2446 char value[MUSE_MSG_MAX_LENGTH] = { 0, };
2450 player_msg_send1(api, pc, ret_buf, ret, INT, key);
2451 if (ret == PLAYER_ERROR_NONE) {
2452 player_msg_get_string(value, ret_buf);
2453 *pvalue = strndup(value, MUSE_MSG_MAX_LENGTH);
2459 int player_get_codec_info(player_h player, char **paudio_codec, char **pvideo_codec)
2461 PLAYER_INSTANCE_CHECK(player);
2462 PLAYER_NULL_ARG_CHECK(paudio_codec);
2463 PLAYER_NULL_ARG_CHECK(pvideo_codec);
2464 int ret = PLAYER_ERROR_NONE;
2465 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_INFO;
2466 player_cli_s *pc = (player_cli_s *) player;
2467 char *ret_buf = NULL;
2468 char video_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
2469 char audio_codec[MUSE_MSG_MAX_LENGTH] = { 0, };
2470 bool ret_val = TRUE;
2474 player_msg_send(api, pc, ret_buf, ret);
2475 if (ret == PLAYER_ERROR_NONE) {
2476 player_msg_get_string2(ret_buf, video_codec, audio_codec, ret_val);
2478 *pvideo_codec = strndup(video_codec, MUSE_MSG_MAX_LENGTH);
2479 *paudio_codec = strndup(audio_codec, MUSE_MSG_MAX_LENGTH);
2481 ret = PLAYER_ERROR_INVALID_OPERATION;
2488 int player_get_audio_stream_info(player_h player, int *psample_rate, int *pchannel, int *pbit_rate)
2490 PLAYER_INSTANCE_CHECK(player);
2491 PLAYER_NULL_ARG_CHECK(psample_rate);
2492 PLAYER_NULL_ARG_CHECK(pchannel);
2493 PLAYER_NULL_ARG_CHECK(pbit_rate);
2494 int ret = PLAYER_ERROR_NONE;
2495 muse_player_api_e api = MUSE_PLAYER_API_GET_AUDIO_STREAM_INFO;
2496 player_cli_s *pc = (player_cli_s *) player;
2497 char *ret_buf = NULL;
2498 int sample_rate = 0;
2504 player_msg_send(api, pc, ret_buf, ret);
2505 if (ret == PLAYER_ERROR_NONE) {
2506 bool ret_val = TRUE;
2507 player_msg_get3(ret_buf, sample_rate, INT, channel, INT, bit_rate, INT, ret_val);
2509 *psample_rate = sample_rate;
2510 *pchannel = channel;
2511 *pbit_rate = bit_rate;
2513 ret = PLAYER_ERROR_INVALID_OPERATION;
2520 int player_get_video_stream_info(player_h player, int *pfps, int *pbit_rate)
2522 PLAYER_INSTANCE_CHECK(player);
2523 PLAYER_NULL_ARG_CHECK(pfps);
2524 PLAYER_NULL_ARG_CHECK(pbit_rate);
2525 int ret = PLAYER_ERROR_NONE;
2526 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_STREAM_INFO;
2527 player_cli_s *pc = (player_cli_s *) player;
2528 char *ret_buf = NULL;
2534 player_msg_send(api, pc, ret_buf, ret);
2535 if (ret == PLAYER_ERROR_NONE) {
2536 bool ret_val = TRUE;
2537 player_msg_get2(ret_buf, fps, INT, bit_rate, INT, ret_val);
2540 *pbit_rate = bit_rate;
2542 ret = PLAYER_ERROR_INVALID_OPERATION;
2549 int player_get_video_size(player_h player, int *pwidth, int *pheight)
2551 PLAYER_INSTANCE_CHECK(player);
2552 PLAYER_NULL_ARG_CHECK(pwidth);
2553 PLAYER_NULL_ARG_CHECK(pheight);
2554 int ret = PLAYER_ERROR_NONE;
2555 muse_player_api_e api = MUSE_PLAYER_API_GET_VIDEO_SIZE;
2556 player_cli_s *pc = (player_cli_s *) player;
2557 char *ret_buf = NULL;
2563 player_msg_send(api, pc, ret_buf, ret);
2564 if (ret == PLAYER_ERROR_NONE) {
2565 bool ret_val = TRUE;
2566 player_msg_get2(ret_buf, width, INT, height, INT, ret_val);
2571 ret = PLAYER_ERROR_INVALID_OPERATION;
2578 int player_get_album_art(player_h player, void **palbum_art, int *psize)
2580 PLAYER_INSTANCE_CHECK(player);
2581 PLAYER_NULL_ARG_CHECK(palbum_art);
2582 PLAYER_NULL_ARG_CHECK(psize);
2583 int ret = PLAYER_ERROR_NONE;
2584 muse_player_api_e api = MUSE_PLAYER_API_GET_ALBUM_ART;
2585 player_cli_s *pc = (player_cli_s *) player;
2586 char *ret_buf = NULL;
2590 tbm_bo_handle thandle;
2591 tbm_fd tfd = INVALID_DEFAULT_VALUE;
2592 int key = INVALID_DEFAULT_VALUE;
2597 player_msg_send(api, pc, ret_buf, ret);
2598 if (ret == PLAYER_ERROR_NONE) {
2599 muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
2600 jobj = muse_core_msg_json_object_new(ret_buf, NULL, &err);
2602 LOGE("failed to get msg obj, err:%d", err);
2603 ret = PLAYER_ERROR_INVALID_OPERATION;
2607 if (muse_core_msg_json_object_get_value("size", jobj, &size, MUSE_TYPE_INT) && (size > 0)) {
2608 LOGD("size : %d", size);
2609 if (!muse_core_msg_json_object_get_value("key", jobj, &key, MUSE_TYPE_INT)) {
2610 LOGE("failed to get key value");
2611 ret = PLAYER_ERROR_INVALID_OPERATION;
2615 tfd = pc->cb_info->tfd;
2617 LOGE("failed to get tbm fd value");
2618 ret = PLAYER_ERROR_INVALID_OPERATION;
2622 bo = tbm_bo_import_fd(pc->cb_info->bufmgr, tfd);
2624 LOGE("TBM get error : bo is NULL");
2625 ret = PLAYER_ERROR_INVALID_OPERATION;
2628 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE | TBM_OPTION_READ);
2629 if (thandle.ptr == NULL) {
2630 LOGE("TBM get error : handle pointer is NULL");
2631 ret = PLAYER_ERROR_INVALID_OPERATION;
2634 album_art = _get_mem(pc, size);
2636 memcpy(album_art, thandle.ptr, size);
2637 *palbum_art = album_art;
2639 LOGE("g_new failure");
2640 ret = PLAYER_ERROR_INVALID_OPERATION;
2652 muse_core_msg_json_object_free(jobj);
2657 if (tfd > INVALID_DEFAULT_VALUE)
2659 pc->cb_info->tfd = INVALID_DEFAULT_VALUE;
2665 if (key > INVALID_DEFAULT_VALUE) {
2666 LOGD("send msg to release buffer. key:%d", key);
2667 player_msg_send1_async(MUSE_PLAYER_API_RETURN_BUFFER, pc, INT, key);
2673 int player_audio_effect_get_equalizer_bands_count(player_h player, int *pcount)
2675 PLAYER_INSTANCE_CHECK(player);
2676 PLAYER_NULL_ARG_CHECK(pcount);
2677 int ret = PLAYER_ERROR_NONE;
2678 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BANDS_COUNT;
2679 player_cli_s *pc = (player_cli_s *) player;
2680 char *ret_buf = NULL;
2685 player_msg_send(api, pc, ret_buf, ret);
2686 if (ret == PLAYER_ERROR_NONE) {
2687 player_msg_get(count, ret_buf);
2694 int player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
2696 PLAYER_INSTANCE_CHECK(player);
2697 PLAYER_NULL_ARG_CHECK(band_levels);
2698 int ret = PLAYER_ERROR_NONE;
2699 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_ALL_BANDS;
2700 player_cli_s *pc = (player_cli_s *) player;
2701 char *ret_buf = NULL;
2705 player_msg_send_array(api, pc, ret_buf, ret, band_levels, length, sizeof(int));
2712 int player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
2714 PLAYER_INSTANCE_CHECK(player);
2715 int ret = PLAYER_ERROR_NONE;
2716 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_SET_EQUALIZER_BAND_LEVEL;
2717 player_cli_s *pc = (player_cli_s *) player;
2718 char *ret_buf = NULL;
2722 player_msg_send2(api, pc, ret_buf, ret, INT, index, INT, level);
2728 int player_audio_effect_get_equalizer_band_level(player_h player, int index, int *plevel)
2730 PLAYER_INSTANCE_CHECK(player);
2731 PLAYER_NULL_ARG_CHECK(plevel);
2732 int ret = PLAYER_ERROR_NONE;
2733 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_LEVEL;
2734 player_cli_s *pc = (player_cli_s *) player;
2735 char *ret_buf = NULL;
2740 player_msg_send1(api, pc, ret_buf, ret, INT, index);
2741 if (ret == PLAYER_ERROR_NONE) {
2742 player_msg_get(level, ret_buf);
2749 int player_audio_effect_get_equalizer_level_range(player_h player, int *pmin, int *pmax)
2751 PLAYER_INSTANCE_CHECK(player);
2752 PLAYER_NULL_ARG_CHECK(pmin);
2753 PLAYER_NULL_ARG_CHECK(pmax);
2754 int ret = PLAYER_ERROR_NONE;
2755 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_LEVEL_RANGE;
2756 player_cli_s *pc = (player_cli_s *) player;
2757 char *ret_buf = NULL;
2758 int min = 0, max = 0;
2762 player_msg_send(api, pc, ret_buf, ret);
2763 if (ret == PLAYER_ERROR_NONE) {
2764 bool ret_val = TRUE;
2765 player_msg_get2(ret_buf, min, INT, max, INT, ret_val);
2770 ret = PLAYER_ERROR_INVALID_OPERATION;
2777 int player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *pfrequency)
2779 PLAYER_INSTANCE_CHECK(player);
2780 PLAYER_NULL_ARG_CHECK(pfrequency);
2781 int ret = PLAYER_ERROR_NONE;
2782 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY;
2783 player_cli_s *pc = (player_cli_s *) player;
2784 char *ret_buf = NULL;
2789 player_msg_send1(api, pc, ret_buf, ret, INT, index);
2790 if (ret == PLAYER_ERROR_NONE) {
2791 player_msg_get(frequency, ret_buf);
2792 *pfrequency = frequency;
2798 int player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *prange)
2800 PLAYER_INSTANCE_CHECK(player);
2801 PLAYER_NULL_ARG_CHECK(prange);
2802 int ret = PLAYER_ERROR_NONE;
2803 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_GET_EQUALIZER_BAND_FREQUENCY_RANGE;
2804 player_cli_s *pc = (player_cli_s *) player;
2805 char *ret_buf = NULL;
2810 player_msg_send1(api, pc, ret_buf, ret, INT, index);
2811 if (ret == PLAYER_ERROR_NONE) {
2812 player_msg_get(range, ret_buf);
2819 int player_audio_effect_equalizer_clear(player_h player)
2821 PLAYER_INSTANCE_CHECK(player);
2822 int ret = PLAYER_ERROR_NONE;
2823 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_CLEAR;
2824 player_cli_s *pc = (player_cli_s *) player;
2825 char *ret_buf = NULL;
2829 player_msg_send(api, pc, ret_buf, ret);
2834 int player_audio_effect_equalizer_is_available(player_h player, bool * pavailable)
2836 PLAYER_INSTANCE_CHECK(player);
2837 PLAYER_NULL_ARG_CHECK(pavailable);
2838 int ret = PLAYER_ERROR_NONE;
2839 muse_player_api_e api = MUSE_PLAYER_API_AUDIO_EFFECT_EQUALIZER_IS_AVAILABLE;
2840 player_cli_s *pc = (player_cli_s *) player;
2841 char *ret_buf = NULL;
2846 player_msg_send(api, pc, ret_buf, ret);
2847 if (ret == PLAYER_ERROR_NONE) {
2848 player_msg_get(available, ret_buf);
2849 *pavailable = available;
2855 int player_set_subtitle_path(player_h player, const char *path)
2857 PLAYER_INSTANCE_CHECK(player);
2858 int ret = PLAYER_ERROR_NONE;
2859 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_PATH;
2860 player_cli_s *pc = (player_cli_s *) player;
2861 char *ret_buf = NULL;
2865 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
2870 int player_set_subtitle_position_offset(player_h player, int millisecond)
2872 PLAYER_INSTANCE_CHECK(player);
2873 int ret = PLAYER_ERROR_NONE;
2874 muse_player_api_e api = MUSE_PLAYER_API_SET_SUBTITLE_POSITION_OFFSET;
2875 player_cli_s *pc = (player_cli_s *) player;
2876 char *ret_buf = NULL;
2880 player_msg_send1(api, pc, ret_buf, ret, INT, millisecond);
2886 int player_set_progressive_download_path(player_h player, const char *path)
2888 PLAYER_INSTANCE_CHECK(player);
2889 PLAYER_NULL_ARG_CHECK(path);
2890 int ret = PLAYER_ERROR_NONE;
2891 muse_player_api_e api = MUSE_PLAYER_API_SET_PROGRESSIVE_DOWNLOAD_PATH;
2892 player_cli_s *pc = (player_cli_s *) player;
2893 char *ret_buf = NULL;
2897 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
2902 int player_get_progressive_download_status(player_h player, unsigned long *pcurrent, unsigned long *ptotal_size)
2904 PLAYER_INSTANCE_CHECK(player);
2905 PLAYER_NULL_ARG_CHECK(pcurrent);
2906 PLAYER_NULL_ARG_CHECK(ptotal_size);
2907 int ret = PLAYER_ERROR_NONE;
2908 muse_player_api_e api = MUSE_PLAYER_API_GET_PROGRESSIVE_DOWNLOAD_STATUS;
2909 player_cli_s *pc = (player_cli_s *) player;
2910 char *ret_buf = NULL;
2911 unsigned long current, total_size;
2915 player_msg_send(api, pc, ret_buf, ret);
2916 if (ret == PLAYER_ERROR_NONE) {
2917 bool ret_val = TRUE;
2918 player_msg_get2(ret_buf, current, POINTER, total_size, POINTER, ret_val);
2920 *pcurrent = current;
2921 *ptotal_size = total_size;
2923 ret = PLAYER_ERROR_INVALID_OPERATION;
2931 int player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
2933 PLAYER_INSTANCE_CHECK(player);
2934 PLAYER_NULL_ARG_CHECK(callback);
2935 int ret = PLAYER_ERROR_NONE;
2936 muse_player_api_e api = MUSE_PLAYER_API_CAPTURE_VIDEO;
2937 player_cli_s *pc = (player_cli_s *) player;
2938 char *ret_buf = NULL;
2941 if (pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
2942 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing...", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
2943 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
2945 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_CAPTURE);
2946 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
2947 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
2950 player_msg_send(api, pc, ret_buf, ret);
2952 if (ret != PLAYER_ERROR_NONE)
2953 set_null_user_cb(pc->cb_info, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
2959 int player_set_streaming_cookie(player_h player, const char *cookie, int size)
2961 PLAYER_INSTANCE_CHECK(player);
2962 PLAYER_NULL_ARG_CHECK(cookie);
2963 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2964 int ret = PLAYER_ERROR_NONE;
2965 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_COOKIE;
2966 player_cli_s *pc = (player_cli_s *) player;
2967 char *ret_buf = NULL;
2971 player_msg_send2(api, pc, ret_buf, ret, STRING, cookie, INT, size);
2976 int player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
2978 PLAYER_INSTANCE_CHECK(player);
2979 PLAYER_NULL_ARG_CHECK(user_agent);
2980 PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2981 int ret = PLAYER_ERROR_NONE;
2982 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_USER_AGENT;
2983 player_cli_s *pc = (player_cli_s *) player;
2984 char *ret_buf = NULL;
2988 player_msg_send2(api, pc, ret_buf, ret, STRING, user_agent, INT, size);
2993 int player_get_streaming_download_progress(player_h player, int *pstart, int *pcurrent)
2995 PLAYER_INSTANCE_CHECK(player);
2996 PLAYER_NULL_ARG_CHECK(pstart);
2997 PLAYER_NULL_ARG_CHECK(pcurrent);
2998 int ret = PLAYER_ERROR_NONE;
2999 muse_player_api_e api = MUSE_PLAYER_API_GET_STREAMING_DOWNLOAD_PROGRESS;
3000 player_cli_s *pc = (player_cli_s *) player;
3001 char *ret_buf = NULL;
3002 int start = 0, current = 0;
3006 player_msg_send(api, pc, ret_buf, ret);
3007 if (ret == PLAYER_ERROR_NONE) {
3008 bool ret_val = TRUE;
3009 player_msg_get2(ret_buf, start, INT, current, INT, ret_val);
3012 *pcurrent = current;
3014 ret = PLAYER_ERROR_INVALID_OPERATION;
3022 int player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
3024 return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
3027 int player_unset_completed_cb(player_h player)
3029 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
3032 int player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
3034 return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
3037 int player_unset_interrupted_cb(player_h player)
3039 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
3042 int player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
3044 return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
3047 int player_unset_error_cb(player_h player)
3049 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
3052 int player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
3054 return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
3057 int player_unset_buffering_cb(player_h player)
3059 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
3062 int player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
3064 return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
3067 int player_unset_subtitle_updated_cb(player_h player)
3069 return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
3072 int player_set_progressive_download_message_cb(player_h player, player_pd_message_cb callback, void *user_data)
3074 PLAYER_INSTANCE_CHECK(player);
3075 PLAYER_NULL_ARG_CHECK(callback);
3076 int ret = PLAYER_ERROR_NONE;
3077 player_cli_s *pc = (player_cli_s *) player;
3078 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3079 char *ret_buf = NULL;
3080 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PD;
3085 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3087 if (ret == PLAYER_ERROR_NONE) {
3088 pc->cb_info->user_cb[type] = callback;
3089 pc->cb_info->user_data[type] = user_data;
3090 LOGI("Event type : %d ", type);
3097 int player_unset_progressive_download_message_cb(player_h player)
3099 PLAYER_INSTANCE_CHECK(player);
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 set_null_user_cb_lock(pc->cb_info, type);
3111 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3118 int player_set_media_packet_video_frame_decoded_cb(player_h player, player_media_packet_video_decoded_cb callback, void *user_data)
3120 PLAYER_INSTANCE_CHECK(player);
3121 PLAYER_NULL_ARG_CHECK(callback);
3122 int ret = PLAYER_ERROR_NONE;
3123 player_cli_s *pc = (player_cli_s *) player;
3124 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3125 char *ret_buf = NULL;
3126 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME;
3131 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3133 if (ret == PLAYER_ERROR_NONE) {
3134 pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
3135 pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
3136 LOGI("Event type : %d ", MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
3143 int player_unset_media_packet_video_frame_decoded_cb(player_h player)
3145 PLAYER_INSTANCE_CHECK(player);
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 set_null_user_cb_lock(pc->cb_info, type);
3157 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3163 int player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
3165 PLAYER_INSTANCE_CHECK(player);
3166 PLAYER_NULL_ARG_CHECK(callback);
3167 int ret = PLAYER_ERROR_NONE;
3168 player_cli_s *pc = (player_cli_s *) player;
3169 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3170 char *ret_buf = NULL;
3171 muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
3176 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3178 if (ret == PLAYER_ERROR_NONE) {
3179 pc->cb_info->user_cb[type] = callback;
3180 pc->cb_info->user_data[type] = user_data;
3181 LOGI("Event type : %d ", type);
3188 int player_unset_video_stream_changed_cb(player_h player)
3190 PLAYER_INSTANCE_CHECK(player);
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 set_null_user_cb_lock(pc->cb_info, type);
3202 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3208 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)
3210 PLAYER_INSTANCE_CHECK(player);
3211 PLAYER_NULL_ARG_CHECK(callback);
3212 int ret = PLAYER_ERROR_NONE;
3213 player_cli_s *pc = (player_cli_s *) player;
3214 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3215 char *ret_buf = NULL;
3216 muse_player_event_e type;
3221 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3222 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3223 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3224 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3226 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3227 return PLAYER_ERROR_INVALID_PARAMETER;
3230 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3232 if (ret == PLAYER_ERROR_NONE) {
3233 pc->cb_info->user_cb[type] = callback;
3234 pc->cb_info->user_data[type] = user_data;
3235 LOGI("Event type : %d ", type);
3242 int player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e stream_type)
3244 PLAYER_INSTANCE_CHECK(player);
3245 int ret = PLAYER_ERROR_NONE;
3246 player_cli_s *pc = (player_cli_s *) player;
3247 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3248 char *ret_buf = NULL;
3249 muse_player_event_e type;
3254 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3255 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
3256 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3257 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
3259 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3260 return PLAYER_ERROR_INVALID_PARAMETER;
3263 set_null_user_cb_lock(pc->cb_info, type);
3265 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3271 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)
3273 PLAYER_INSTANCE_CHECK(player);
3274 PLAYER_NULL_ARG_CHECK(callback);
3275 int ret = PLAYER_ERROR_NONE;
3276 player_cli_s *pc = (player_cli_s *) player;
3277 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3278 char *ret_buf = NULL;
3279 muse_player_event_e type;
3284 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3285 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3286 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3287 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3289 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3290 return PLAYER_ERROR_INVALID_PARAMETER;
3293 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3295 if (ret == PLAYER_ERROR_NONE) {
3296 pc->cb_info->user_cb[type] = callback;
3297 pc->cb_info->user_data[type] = user_data;
3298 LOGI("Event type : %d ", type);
3305 int player_unset_media_stream_seek_cb(player_h player, player_stream_type_e stream_type)
3307 PLAYER_INSTANCE_CHECK(player);
3308 int ret = PLAYER_ERROR_NONE;
3309 player_cli_s *pc = (player_cli_s *) player;
3310 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
3311 char *ret_buf = NULL;
3312 muse_player_event_e type;
3317 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
3318 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
3319 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
3320 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
3322 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
3323 return PLAYER_ERROR_INVALID_PARAMETER;
3326 set_null_user_cb_lock(pc->cb_info, type);
3328 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
3334 /* TODO Implement raw data socket channel */
3335 int player_push_media_stream(player_h player, media_packet_h packet)
3337 PLAYER_INSTANCE_CHECK(player);
3338 PLAYER_NULL_ARG_CHECK(packet);
3339 int ret = PLAYER_ERROR_NONE;
3340 player_cli_s *pc = (player_cli_s *) player;
3341 muse_player_api_e api = MUSE_PLAYER_API_PUSH_MEDIA_STREAM;
3342 char *ret_buf = NULL;
3343 player_push_media_msg_type push_media;
3344 char *push_media_msg = (char *)&push_media;
3345 int msg_size = sizeof(player_push_media_msg_type);
3349 tbm_bo_handle thandle;
3350 tbm_fd tfd = INVALID_DEFAULT_VALUE;
3353 media_format_h format;
3359 media_packet_get_buffer_data_ptr(packet, (void **)&buf);
3360 media_packet_get_buffer_size(packet, &push_media.size);
3361 media_packet_get_pts(packet, &push_media.pts);
3362 media_packet_get_format(packet, &format);
3363 media_packet_get_flags(packet, &push_media.flags);
3365 push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW;
3367 media_packet_is_video(packet, &is_video);
3368 media_packet_is_audio(packet, &is_audio);
3370 media_format_get_video_info(format, &push_media.mimetype, &push_media.width, &push_media.height, NULL, NULL);
3372 media_format_get_audio_info(format, &push_media.mimetype, NULL, NULL, NULL, NULL);
3374 media_format_unref(format);
3377 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM) {
3378 bo = tbm_bo_alloc(pc->cb_info->bufmgr, push_media.size, TBM_BO_DEFAULT);
3380 LOGE("TBM get error : bo is NULL");
3381 return PLAYER_ERROR_INVALID_OPERATION;
3383 thandle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
3384 if (thandle.ptr == NULL) {
3385 LOGE("TBM get error : handle pointer is NULL");
3386 ret = PLAYER_ERROR_INVALID_OPERATION;
3389 memcpy(thandle.ptr, buf, push_media.size);
3392 tfd = tbm_bo_export_fd(bo);
3394 LOGE("tbm_bo_export_fd err 0x%x", tfd);
3395 ret = PLAYER_ERROR_INVALID_OPERATION;
3399 player_msg_send_array_fd(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), tfd);
3400 } else if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_MSG) {
3401 buf_size = (int)push_media.size;
3402 player_msg_send_array2(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char), buf, buf_size, sizeof(char));
3405 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_RAW) {
3406 buf_size = (int)push_media.size;
3407 muse_core_ipc_push_data(pc->cb_info->data_fd, buf, buf_size, push_media.pts);
3408 player_msg_send_array(api, pc, ret_buf, ret, push_media_msg, msg_size, sizeof(char));
3411 LOGD("ret_buf %s", ret_buf);
3415 if (tfd > INVALID_DEFAULT_VALUE)
3418 if (push_media.buf_type == PUSH_MEDIA_BUF_TYPE_TBM)
3426 int player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
3428 PLAYER_INSTANCE_CHECK(player);
3429 g_return_val_if_fail(format, PLAYER_ERROR_INVALID_OPERATION);
3430 int ret = PLAYER_ERROR_NONE;
3431 player_cli_s *pc = (player_cli_s *) player;
3432 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_INFO;
3433 char *ret_buf = NULL;
3434 media_format_mimetype_e mimetype;
3445 media_format_ref(format);
3446 if (type == PLAYER_STREAM_TYPE_VIDEO) {
3447 media_format_get_video_info(format, &mimetype, &width, &height, &avg_bps, &max_bps);
3448 player_msg_send6(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, width, INT, height, INT, avg_bps, INT, max_bps);
3449 } else if (type == PLAYER_STREAM_TYPE_AUDIO) {
3450 media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &avg_bps);
3451 player_msg_send6(api, pc, ret_buf, ret, INT, type, INT, mimetype, INT, channel, INT, samplerate, INT, avg_bps, INT, bit);
3453 media_format_unref(format);
3454 pc->push_media_stream = TRUE;
3460 int player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
3462 int ret = PLAYER_ERROR_NONE;
3463 PLAYER_INSTANCE_CHECK(player);
3464 player_cli_s *pc = (player_cli_s *) player;
3465 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MAX_SIZE;
3466 char *ret_buf = NULL;
3470 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT64, max_size);
3476 int player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *pmax_size)
3478 int ret = PLAYER_ERROR_NONE;
3479 PLAYER_INSTANCE_CHECK(player);
3480 PLAYER_NULL_ARG_CHECK(pmax_size);
3481 player_cli_s *pc = (player_cli_s *) player;
3482 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MAX_SIZE;
3483 char *ret_buf = NULL;
3484 unsigned long long max_size;
3488 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3489 if (ret == PLAYER_ERROR_NONE) {
3490 player_msg_get_type(max_size, ret_buf, INT64);
3491 *pmax_size = max_size;
3497 int player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
3499 int ret = PLAYER_ERROR_NONE;
3500 PLAYER_INSTANCE_CHECK(player);
3501 player_cli_s *pc = (player_cli_s *) player;
3502 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
3503 char *ret_buf = NULL;
3507 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, percent);
3513 int player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *ppercent)
3515 int ret = PLAYER_ERROR_NONE;
3516 PLAYER_INSTANCE_CHECK(player);
3517 PLAYER_NULL_ARG_CHECK(ppercent);
3518 player_cli_s *pc = (player_cli_s *) player;
3519 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_STREAM_BUFFER_MIN_THRESHOLD;
3520 char *ret_buf = NULL;
3525 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3526 if (ret == PLAYER_ERROR_NONE) {
3527 player_msg_get(percent, ret_buf);
3528 *ppercent = percent;
3535 int player_get_track_count(player_h player, player_stream_type_e type, int *pcount)
3537 PLAYER_INSTANCE_CHECK(player);
3538 PLAYER_NULL_ARG_CHECK(pcount);
3539 int ret = PLAYER_ERROR_NONE;
3540 player_cli_s *pc = (player_cli_s *) player;
3541 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_COUNT;
3542 char *ret_buf = NULL;
3547 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3548 if (ret == PLAYER_ERROR_NONE) {
3549 player_msg_get(count, ret_buf);
3557 int player_get_current_track(player_h player, player_stream_type_e type, int *pindex)
3559 PLAYER_INSTANCE_CHECK(player);
3560 PLAYER_NULL_ARG_CHECK(pindex);
3561 int ret = PLAYER_ERROR_NONE;
3562 player_cli_s *pc = (player_cli_s *) player;
3563 muse_player_api_e api = MUSE_PLAYER_API_GET_CURRENT_TRACK;
3564 char *ret_buf = NULL;
3569 player_msg_send1(api, pc, ret_buf, ret, INT, type);
3570 if (ret == PLAYER_ERROR_NONE) {
3571 player_msg_get(index, ret_buf);
3579 int player_select_track(player_h player, player_stream_type_e type, int index)
3581 PLAYER_INSTANCE_CHECK(player);
3582 int ret = PLAYER_ERROR_NONE;
3583 player_cli_s *pc = (player_cli_s *) player;
3584 muse_player_api_e api = MUSE_PLAYER_API_SELECT_TRACK;
3585 char *ret_buf = NULL;
3589 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
3595 int player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **pcode)
3597 PLAYER_INSTANCE_CHECK(player);
3598 PLAYER_NULL_ARG_CHECK(pcode);
3599 int ret = PLAYER_ERROR_NONE;
3600 player_cli_s *pc = (player_cli_s *) player;
3601 muse_player_api_e api = MUSE_PLAYER_API_GET_TRACK_LANGUAGE_CODE;
3602 char *ret_buf = NULL;
3603 char code[MUSE_MSG_MAX_LENGTH] = { 0, };
3604 const int code_len = 2;
3608 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, index);
3609 if (ret == PLAYER_ERROR_NONE) {
3610 if (player_msg_get_string(code, ret_buf))
3611 *pcode = strndup(code, code_len);