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.
22 #include <muse_player.h>
23 #include <muse_player_msg.h>
24 #include <storage-internal.h>
25 #include "player_private.h"
26 #include "player_msg.h"
27 #include "player_internal.h"
29 int player_set_pcm_extraction_mode(player_h player, bool sync, player_audio_pcm_extraction_cb callback, void *user_data)
31 PLAYER_INSTANCE_CHECK(player);
32 PLAYER_NULL_ARG_CHECK(callback);
33 int ret = PLAYER_ERROR_NONE;
34 muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_EXTRACTION_MODE;
35 player_cli_s *pc = (player_cli_s *) player;
37 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME;
41 player_msg_send1(api, pc, ret_buf, ret, INT, sync);
43 if (ret == PLAYER_ERROR_NONE) {
44 pc->cb_info->user_cb[event] = callback;
45 pc->cb_info->user_data[event] = user_data;
46 LOGI("Event type : %d ", event);
53 int player_set_pcm_spec(player_h player, const char *format, int samplerate, int channel)
55 PLAYER_INSTANCE_CHECK(player);
56 int ret = PLAYER_ERROR_NONE;
57 muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_SPEC;
58 player_cli_s *pc = (player_cli_s *) player;
63 player_msg_send3(api, pc, ret_buf, ret, STRING, format, INT, samplerate, INT, channel);
69 int player_set_streaming_playback_rate(player_h player, float rate)
71 PLAYER_INSTANCE_CHECK(player);
72 int ret = PLAYER_ERROR_NONE;
73 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_PLAYBACK_RATE;
74 player_cli_s *pc = (player_cli_s *) player;
79 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
84 int player_set_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type, player_media_stream_buffer_status_cb_ex callback, void *user_data)
86 PLAYER_INSTANCE_CHECK(player);
87 PLAYER_NULL_ARG_CHECK(callback);
88 int ret = PLAYER_ERROR_NONE;
89 player_cli_s *pc = (player_cli_s *) player;
90 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
92 muse_player_event_e type;
97 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
98 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
99 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
100 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
102 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
103 return PLAYER_ERROR_INVALID_PARAMETER;
106 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
108 if (ret == PLAYER_ERROR_NONE) {
109 pc->cb_info->user_cb[type] = callback;
110 pc->cb_info->user_data[type] = user_data;
111 LOGI("Event type : %d ", type);
118 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
120 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
121 cb_info->user_cb[event] = NULL;
122 cb_info->user_data[event] = NULL;
126 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
128 bool lock = g_thread_self() != cb_info->event_queue.thread;
131 g_mutex_lock(&cb_info->event_queue.mutex);
133 set_null_user_cb(cb_info, event);
136 g_mutex_unlock(&cb_info->event_queue.mutex);
139 int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type)
141 PLAYER_INSTANCE_CHECK(player);
142 int ret = PLAYER_ERROR_NONE;
143 player_cli_s *pc = (player_cli_s *) player;
144 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
145 char *ret_buf = NULL;
146 muse_player_event_e type;
151 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
152 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
153 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
154 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
156 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
157 return PLAYER_ERROR_INVALID_PARAMETER;
160 set_null_user_cb_lock(pc->cb_info, type);
162 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
168 int player_set_media_stream_dynamic_resolution(player_h player, bool drc)
170 PLAYER_INSTANCE_CHECK(player);
171 int ret = PLAYER_ERROR_NONE;
172 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_DYNAMIC_RESOLUTION;
173 player_cli_s *pc = (player_cli_s *) player;
174 char *ret_buf = NULL;
178 player_msg_send1(api, pc, ret_buf, ret, INT, drc);
183 int player_set_ecore_wl_display(player_h player, player_display_type_e type, void *ecore_wl2_window, int x, int y, int width, int height)
185 PLAYER_INSTANCE_CHECK(player);
186 int ret = PLAYER_ERROR_NONE;
187 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
188 player_cli_s *pc = (player_cli_s *) player;
189 char *ret_buf = NULL;
190 wl_win_msg_type wl_win;
191 char *wl_win_msg = (char *)&wl_win;
192 unsigned int wl_surface_id;
193 player_private_display_type_e conv_type;
194 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
197 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
199 ret = _player_convert_display_type(type, &conv_type);
200 if (ret != PLAYER_ERROR_NONE)
203 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
204 LOGE("Display type(%d) is not overlay", conv_type);
205 return PLAYER_ERROR_INVALID_PARAMETER;
207 if (!ecore_wl2_window)
208 return PLAYER_ERROR_INVALID_PARAMETER;
210 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
211 wl_surface_id = p_disp_set_wl_display(ECORE_WAYLAND_WIN, ecore_wl2_window);
212 if (wl_surface_id > 0) {
213 wl_win.wl_surface_id = wl_surface_id;
214 wl_win.type = conv_type;
215 } else return PLAYER_ERROR_INVALID_OPERATION;
217 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
223 int player_set_next_uri(player_h player, const char *uri)
225 PLAYER_INSTANCE_CHECK(player);
226 PLAYER_NULL_ARG_CHECK(uri);
227 int ret = PLAYER_ERROR_NONE;
228 muse_player_api_e api = MUSE_PLAYER_API_SET_NEXT_URI;
229 player_cli_s *pc = (player_cli_s *) player;
230 char *ret_buf = NULL;
231 char path[MAX_URL_LEN] = {0, };
235 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
236 return PLAYER_ERROR_INVALID_PARAMETER;
238 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
244 int player_get_next_uri(player_h player, char **uri)
246 PLAYER_INSTANCE_CHECK(player);
247 PLAYER_NULL_ARG_CHECK(uri);
248 int ret = PLAYER_ERROR_NONE;
249 muse_player_api_e api = MUSE_PLAYER_API_GET_NEXT_URI;
250 player_cli_s *pc = (player_cli_s *) player;
251 char *ret_buf = NULL;
252 char next_uri[MUSE_MSG_MAX_LENGTH] = { 0, };
256 player_msg_send(api, pc, ret_buf, ret);
257 if (ret == PLAYER_ERROR_NONE) {
258 player_msg_get_string(next_uri, ret_buf);
260 char dest[MUSE_MSG_MAX_LENGTH] = {0,};
261 if (storage_get_compat_internal_path(next_uri, sizeof(dest), dest) < 0) {
262 /* cannot convert path. use the original one. */
263 *uri = strndup(next_uri, MUSE_MSG_MAX_LENGTH);
265 /* need to use converted path. */
266 LOGD("Converted path : %s -> %s", next_uri, dest);
267 *uri = strndup(dest, MUSE_MSG_MAX_LENGTH);
274 int player_set_gapless(player_h player, bool gapless)
276 PLAYER_INSTANCE_CHECK(player);
277 int ret = PLAYER_ERROR_NONE;
278 muse_player_api_e api = MUSE_PLAYER_API_SET_GAPLESS;
279 player_cli_s *pc = (player_cli_s *) player;
280 char *ret_buf = NULL;
284 player_msg_send1(api, pc, ret_buf, ret, INT, gapless);
289 int player_is_gapless(player_h player, bool *gapless)
291 PLAYER_INSTANCE_CHECK(player);
292 PLAYER_NULL_ARG_CHECK(gapless);
293 int ret = PLAYER_ERROR_NONE;
294 muse_player_api_e api = MUSE_PLAYER_API_IS_GAPLESS;
295 player_cli_s *pc = (player_cli_s *) player;
296 char *ret_buf = NULL;
301 player_msg_send(api, pc, ret_buf, ret);
302 if (ret == PLAYER_ERROR_NONE) {
303 player_msg_get(value, ret_buf);
310 int player_enable_tsurf_pool(player_h player, bool enable)
312 PLAYER_INSTANCE_CHECK(player);
313 int ret = PLAYER_ERROR_NONE;
314 player_cli_s *pc = (player_cli_s *) player;
316 LOGD("ENTER enable:%d", enable);
318 if (pc && pc->cb_info) {
319 pc->cb_info->use_tsurf_pool = enable;
321 LOGE("failed to enable the tbm surf pool");
322 ret = PLAYER_ERROR_INVALID_OPERATION;
328 int player_is_enabled_tsurf_pool(player_h player, bool *enabled)
330 PLAYER_INSTANCE_CHECK(player);
331 PLAYER_NULL_ARG_CHECK(enabled);
332 int ret = PLAYER_ERROR_NONE;
333 player_cli_s *pc = (player_cli_s *) player;
336 if (pc && pc->cb_info) {
337 *enabled = pc->cb_info->use_tsurf_pool;
339 LOGE("failed to get the tbm surf pool state");
340 ret = PLAYER_ERROR_INVALID_OPERATION;
346 int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
348 PLAYER_INSTANCE_CHECK(player);
349 PLAYER_NULL_ARG_CHECK(size);
351 int ret = PLAYER_ERROR_NONE;
352 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
353 player_cli_s *pc = (player_cli_s *) player;
354 char *ret_buf = NULL;
359 player_msg_send(api, pc, ret_buf, ret);
360 if (ret == PLAYER_ERROR_NONE) {
361 player_msg_get(value, ret_buf);
363 pc->cb_info->video_frame_pool_size = value;
364 LOGD("packet pool size : %d", *size);
370 int player_enable_media_packet_video_frame_decoded_cb(player_h player, bool enable)
372 PLAYER_INSTANCE_CHECK(player);
373 int ret = PLAYER_ERROR_NONE;
374 muse_player_api_e api = MUSE_PLAYER_API_ENABLE_MEDIA_PACKET_VIDEO_FRAME_DECODED_CB;
375 player_cli_s *pc = (player_cli_s *) player;
376 char *ret_buf = NULL;
380 player_msg_send1(api, pc, ret_buf, ret, INT, enable);
385 int player_set_video_codec_type(player_h player, player_video_codec_type_e codec_type)
387 PLAYER_INSTANCE_CHECK(player);
389 int ret = PLAYER_ERROR_NONE;
390 muse_player_api_e api = MUSE_PLAYER_API_SET_CODEC_TYPE;
391 player_cli_s *pc = (player_cli_s *) player;
392 char *ret_buf = NULL;
393 int stream_type = PLAYER_STREAM_TYPE_VIDEO;
395 LOGD("ENTER %d", codec_type);
397 player_msg_send2(api, pc, ret_buf, ret, INT, stream_type, INT, codec_type);
404 int player_get_video_codec_type(player_h player, player_video_codec_type_e *pcodec_type)
406 PLAYER_INSTANCE_CHECK(player);
407 PLAYER_NULL_ARG_CHECK(pcodec_type);
409 int ret = PLAYER_ERROR_NONE;
410 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_TYPE;
411 player_cli_s *pc = (player_cli_s *) player;
412 char *ret_buf = NULL;
413 int stream_type = PLAYER_STREAM_TYPE_VIDEO;
418 player_msg_send1(api, pc, ret_buf, ret, INT, stream_type);
419 if (ret == PLAYER_ERROR_NONE) {
420 player_msg_get(codec_type, ret_buf);
421 *pcodec_type = codec_type;
429 int player_set_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e codec_type)
431 PLAYER_INSTANCE_CHECK(player);
432 PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
434 int ret = PLAYER_ERROR_NONE;
435 muse_player_api_e api = MUSE_PLAYER_API_SET_CODEC_TYPE;
436 player_cli_s *pc = (player_cli_s *) player;
437 char *ret_buf = NULL;
439 LOGD("ENTER stream: %d, codec: %d", stream_type, codec_type);
441 player_msg_send2(api, pc, ret_buf, ret, INT, stream_type, INT, codec_type);
448 int player_get_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e *pcodec_type)
450 PLAYER_INSTANCE_CHECK(player);
451 PLAYER_NULL_ARG_CHECK(pcodec_type);
452 PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
454 int ret = PLAYER_ERROR_NONE;
455 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_TYPE;
456 player_cli_s *pc = (player_cli_s *) player;
457 char *ret_buf = NULL;
460 LOGD("ENTER stream_type: %d", stream_type);
462 player_msg_send1(api, pc, ret_buf, ret, INT, stream_type);
463 if (ret == PLAYER_ERROR_NONE) {
464 player_msg_get(codec_type, ret_buf);
465 *pcodec_type = codec_type;