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_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "sync", 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_SEND_MSG(api, pc, ret_buf, ret,
64 MUSE_TYPE_STRING, "format", format,
65 MUSE_TYPE_INT, "samplerate", samplerate,
66 MUSE_TYPE_INT, "channel", channel);
72 int player_set_streaming_playback_rate(player_h player, float rate)
74 PLAYER_INSTANCE_CHECK(player);
75 int ret = PLAYER_ERROR_NONE;
76 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_PLAYBACK_RATE;
77 player_cli_s *pc = (player_cli_s *) player;
82 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", rate);
87 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)
89 PLAYER_INSTANCE_CHECK(player);
90 PLAYER_NULL_ARG_CHECK(callback);
91 int ret = PLAYER_ERROR_NONE;
92 player_cli_s *pc = (player_cli_s *) player;
93 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
95 muse_player_event_e type;
100 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
101 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
102 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
103 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
105 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
106 return PLAYER_ERROR_INVALID_PARAMETER;
109 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
111 if (ret == PLAYER_ERROR_NONE) {
112 pc->cb_info->user_cb[type] = callback;
113 pc->cb_info->user_data[type] = user_data;
114 LOGI("Event type : %d ", type);
121 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
123 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
124 cb_info->user_cb[event] = NULL;
125 cb_info->user_data[event] = NULL;
129 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
131 bool lock = g_thread_self() != cb_info->event_queue.thread;
134 g_mutex_lock(&cb_info->event_queue.mutex);
136 set_null_user_cb(cb_info, event);
139 g_mutex_unlock(&cb_info->event_queue.mutex);
142 int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type)
144 PLAYER_INSTANCE_CHECK(player);
145 int ret = PLAYER_ERROR_NONE;
146 player_cli_s *pc = (player_cli_s *) player;
147 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
148 char *ret_buf = NULL;
149 muse_player_event_e type;
154 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
155 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
156 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
157 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
159 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
160 return PLAYER_ERROR_INVALID_PARAMETER;
163 set_null_user_cb_lock(pc->cb_info, type);
165 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
171 int player_set_media_stream_dynamic_resolution(player_h player, bool drc)
173 PLAYER_INSTANCE_CHECK(player);
174 int ret = PLAYER_ERROR_NONE;
175 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_DYNAMIC_RESOLUTION;
176 player_cli_s *pc = (player_cli_s *) player;
177 char *ret_buf = NULL;
181 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "drc", drc);
186 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)
188 PLAYER_INSTANCE_CHECK(player);
189 int ret = PLAYER_ERROR_NONE;
190 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
191 player_cli_s *pc = (player_cli_s *) player;
192 char *ret_buf = NULL;
193 wl_win_msg_type wl_win;
194 char *wl_win_msg = (char *)&wl_win;
195 unsigned int wl_surface_id;
196 player_private_display_type_e conv_type;
197 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
201 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
203 ret = _player_convert_display_type(type, &conv_type);
204 if (ret != PLAYER_ERROR_NONE)
207 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
208 LOGE("Display type(%d) is not overlay", conv_type);
209 return PLAYER_ERROR_INVALID_PARAMETER;
211 if (!ecore_wl2_window)
212 return PLAYER_ERROR_INVALID_PARAMETER;
214 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
215 wl_surface_id = p_disp_set_wl_display(ECORE_WAYLAND_WIN, ecore_wl2_window);
216 if (wl_surface_id > 0) {
217 wl_win.surface_id = wl_surface_id;
218 wl_win.type = conv_type;
219 } else return PLAYER_ERROR_INVALID_OPERATION;
221 arr_msg_len = (sizeof(wl_win_msg_type) / sizeof(int) + (sizeof(wl_win_msg_type) % sizeof(int) ? 1 : 0));
222 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
223 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int*)wl_win_msg);
229 int player_set_next_uri(player_h player, const char *uri)
231 PLAYER_INSTANCE_CHECK(player);
232 PLAYER_NULL_ARG_CHECK(uri);
233 int ret = PLAYER_ERROR_NONE;
234 muse_player_api_e api = MUSE_PLAYER_API_SET_NEXT_URI;
235 player_cli_s *pc = (player_cli_s *) player;
236 char *ret_buf = NULL;
237 char path[MAX_URL_LEN] = {0, };
241 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
242 return PLAYER_ERROR_INVALID_PARAMETER;
244 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", path);
250 int player_get_next_uri(player_h player, char **uri)
252 PLAYER_INSTANCE_CHECK(player);
253 PLAYER_NULL_ARG_CHECK(uri);
254 int ret = PLAYER_ERROR_NONE;
255 muse_player_api_e api = MUSE_PLAYER_API_GET_NEXT_URI;
256 player_cli_s *pc = (player_cli_s *) player;
257 char *ret_buf = NULL;
258 char next_uri[MUSE_MSG_MAX_LENGTH] = { 0, };
262 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
263 if (ret == PLAYER_ERROR_NONE) {
264 player_msg_get_string(next_uri, ret_buf);
266 char dest[MUSE_MSG_MAX_LENGTH] = {0,};
267 if (storage_get_compat_internal_path(next_uri, sizeof(dest), dest) < 0) {
268 /* cannot convert path. use the original one. */
269 *uri = strndup(next_uri, MUSE_MSG_MAX_LENGTH);
271 /* need to use converted path. */
272 LOGD("Converted path : %s -> %s", next_uri, dest);
273 *uri = strndup(dest, MUSE_MSG_MAX_LENGTH);
280 int player_set_gapless(player_h player, bool gapless)
282 PLAYER_INSTANCE_CHECK(player);
283 int ret = PLAYER_ERROR_NONE;
284 muse_player_api_e api = MUSE_PLAYER_API_SET_GAPLESS;
285 player_cli_s *pc = (player_cli_s *) player;
286 char *ret_buf = NULL;
290 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "gapless", gapless);
295 int player_is_gapless(player_h player, bool *gapless)
297 PLAYER_INSTANCE_CHECK(player);
298 PLAYER_NULL_ARG_CHECK(gapless);
299 int ret = PLAYER_ERROR_NONE;
300 muse_player_api_e api = MUSE_PLAYER_API_IS_GAPLESS;
301 player_cli_s *pc = (player_cli_s *) player;
302 char *ret_buf = NULL;
307 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
308 if (ret == PLAYER_ERROR_NONE) {
309 player_msg_get(value, ret_buf);
316 int player_enable_tsurf_pool(player_h player, bool enable)
318 PLAYER_INSTANCE_CHECK(player);
319 int ret = PLAYER_ERROR_NONE;
320 player_cli_s *pc = (player_cli_s *) player;
322 LOGD("ENTER enable:%d", enable);
324 if (pc && pc->cb_info) {
325 pc->cb_info->use_tsurf_pool = enable;
327 LOGE("failed to enable the tbm surf pool");
328 ret = PLAYER_ERROR_INVALID_OPERATION;
334 int player_is_enabled_tsurf_pool(player_h player, bool *enabled)
336 PLAYER_INSTANCE_CHECK(player);
337 PLAYER_NULL_ARG_CHECK(enabled);
338 int ret = PLAYER_ERROR_NONE;
339 player_cli_s *pc = (player_cli_s *) player;
342 if (pc && pc->cb_info) {
343 *enabled = pc->cb_info->use_tsurf_pool;
345 LOGE("failed to get the tbm surf pool state");
346 ret = PLAYER_ERROR_INVALID_OPERATION;
352 int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
354 PLAYER_INSTANCE_CHECK(player);
355 PLAYER_NULL_ARG_CHECK(size);
357 int ret = PLAYER_ERROR_NONE;
358 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
359 player_cli_s *pc = (player_cli_s *) player;
360 char *ret_buf = NULL;
365 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
366 if (ret == PLAYER_ERROR_NONE) {
367 player_msg_get(value, ret_buf);
369 pc->cb_info->video_frame_pool_size = value;
370 LOGD("packet pool size : %d", *size);
376 int player_enable_media_packet_video_frame_decoded_cb(player_h player, bool enable)
378 PLAYER_INSTANCE_CHECK(player);
379 int ret = PLAYER_ERROR_NONE;
380 muse_player_api_e api = MUSE_PLAYER_API_ENABLE_MEDIA_PACKET_VIDEO_FRAME_DECODED_CB;
381 player_cli_s *pc = (player_cli_s *) player;
382 char *ret_buf = NULL;
384 LOGD("ENTER %d", enable);
386 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "enable", enable);
391 int player_set_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e codec_type)
393 PLAYER_INSTANCE_CHECK(player);
394 PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
396 int ret = PLAYER_ERROR_NONE;
397 muse_player_api_e api = MUSE_PLAYER_API_SET_CODEC_TYPE;
398 player_cli_s *pc = (player_cli_s *) player;
399 char *ret_buf = NULL;
401 LOGD("ENTER stream: %d, codec: %d", stream_type, codec_type);
403 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
404 MUSE_TYPE_INT, "stream_type", stream_type,
405 MUSE_TYPE_INT, "codec_type", codec_type);
412 int player_get_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e *pcodec_type)
414 PLAYER_INSTANCE_CHECK(player);
415 PLAYER_NULL_ARG_CHECK(pcodec_type);
416 PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
418 int ret = PLAYER_ERROR_NONE;
419 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_TYPE;
420 player_cli_s *pc = (player_cli_s *) player;
421 char *ret_buf = NULL;
424 LOGD("ENTER stream_type: %d", stream_type);
426 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "stream_type", stream_type);
427 if (ret == PLAYER_ERROR_NONE) {
428 player_msg_get(codec_type, ret_buf);
429 *pcodec_type = codec_type;