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_streaming_playback_rate(player_h player, float rate)
31 PLAYER_INSTANCE_CHECK(player);
32 int ret = PLAYER_ERROR_NONE;
33 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_PLAYBACK_RATE;
34 player_cli_s *pc = (player_cli_s *)player;
39 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", rate);
44 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)
46 PLAYER_INSTANCE_CHECK(player);
47 PLAYER_NULL_ARG_CHECK(callback);
48 int ret = PLAYER_ERROR_NONE;
49 player_cli_s *pc = (player_cli_s *)player;
50 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
52 muse_player_event_e type;
57 if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
58 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
59 } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
60 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
62 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
63 return PLAYER_ERROR_INVALID_PARAMETER;
66 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
68 if (ret == PLAYER_ERROR_NONE) {
69 pc->cb_info->user_cb[type] = callback;
70 pc->cb_info->user_data[type] = user_data;
71 LOGI("Event type : %d ", type);
78 static void set_null_user_cb(callback_cb_info_s *cb_info, muse_player_event_e event)
80 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
81 cb_info->user_cb[event] = NULL;
82 cb_info->user_data[event] = NULL;
86 static void set_null_user_cb_lock(callback_cb_info_s *cb_info, muse_player_event_e event)
88 bool lock = g_thread_self() != cb_info->event_queue.thread;
91 g_mutex_lock(&cb_info->event_queue.mutex);
93 set_null_user_cb(cb_info, event);
96 g_mutex_unlock(&cb_info->event_queue.mutex);
99 int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type)
101 PLAYER_INSTANCE_CHECK(player);
102 int ret = PLAYER_ERROR_NONE;
103 player_cli_s *pc = (player_cli_s *)player;
104 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
105 char *ret_buf = NULL;
106 muse_player_event_e type;
111 if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
112 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
113 } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
114 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
116 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
117 return PLAYER_ERROR_INVALID_PARAMETER;
120 set_null_user_cb_lock(pc->cb_info, type);
122 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
128 int player_set_media_stream_dynamic_resolution(player_h player, bool drc)
130 PLAYER_INSTANCE_CHECK(player);
131 int ret = PLAYER_ERROR_NONE;
132 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_DYNAMIC_RESOLUTION;
133 player_cli_s *pc = (player_cli_s *)player;
134 char *ret_buf = NULL;
138 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "drc", drc);
143 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)
145 PLAYER_INSTANCE_CHECK(player);
146 int ret = PLAYER_ERROR_NONE;
147 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
148 player_cli_s *pc = (player_cli_s *)player;
149 char *ret_buf = NULL;
150 wl_win_msg_type wl_win;
151 char *wl_win_msg = (char *)&wl_win;
152 unsigned int wl_surface_id;
153 player_private_display_type_e conv_type;
154 unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
158 PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
160 ret = _player_convert_display_type(type, &conv_type);
161 if (ret != PLAYER_ERROR_NONE)
164 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
165 LOGE("Display type(%d) is not overlay", conv_type);
166 return PLAYER_ERROR_INVALID_PARAMETER;
168 if (!ecore_wl2_window)
169 return PLAYER_ERROR_INVALID_PARAMETER;
171 PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
172 wl_surface_id = p_disp_set_wl_display(ECORE_WAYLAND_WIN, ecore_wl2_window);
173 if (wl_surface_id > 0) {
174 wl_win.surface_id = wl_surface_id;
175 wl_win.type = conv_type;
177 return PLAYER_ERROR_INVALID_OPERATION;
180 arr_msg_len = (sizeof(wl_win_msg_type) / sizeof(int) + (sizeof(wl_win_msg_type) % sizeof(int) ? 1 : 0));
181 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
182 MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int *)wl_win_msg);
188 int player_set_next_uri(player_h player, const char *uri)
190 PLAYER_INSTANCE_CHECK(player);
191 PLAYER_NULL_ARG_CHECK(uri);
192 int ret = PLAYER_ERROR_NONE;
193 muse_player_api_e api = MUSE_PLAYER_API_SET_NEXT_URI;
194 player_cli_s *pc = (player_cli_s *)player;
195 char *ret_buf = NULL;
196 char path[MAX_URL_LEN] = {0, };
200 if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
201 return PLAYER_ERROR_INVALID_PARAMETER;
203 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", path);
209 int player_get_next_uri(player_h player, char **uri)
211 PLAYER_INSTANCE_CHECK(player);
212 PLAYER_NULL_ARG_CHECK(uri);
213 int ret = PLAYER_ERROR_NONE;
214 muse_player_api_e api = MUSE_PLAYER_API_GET_NEXT_URI;
215 player_cli_s *pc = (player_cli_s *)player;
216 char *ret_buf = NULL;
217 char next_uri[MUSE_MSG_MAX_LENGTH] = { 0, };
221 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
222 if (ret == PLAYER_ERROR_NONE) {
223 player_msg_get_string(next_uri, ret_buf);
225 char dest[MUSE_MSG_MAX_LENGTH] = {0,};
226 if (storage_get_compat_internal_path(next_uri, sizeof(dest), dest) < 0) {
227 /* cannot convert path. use the original one. */
228 *uri = strndup(next_uri, MUSE_MSG_MAX_LENGTH);
230 /* need to use converted path. */
231 LOGD("Converted path : %s -> %s", next_uri, dest);
232 *uri = strndup(dest, MUSE_MSG_MAX_LENGTH);
239 int player_set_gapless(player_h player, bool gapless)
241 PLAYER_INSTANCE_CHECK(player);
242 int ret = PLAYER_ERROR_NONE;
243 muse_player_api_e api = MUSE_PLAYER_API_SET_GAPLESS;
244 player_cli_s *pc = (player_cli_s *)player;
245 char *ret_buf = NULL;
249 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "gapless", gapless);
254 int player_is_gapless(player_h player, bool *gapless)
256 PLAYER_INSTANCE_CHECK(player);
257 PLAYER_NULL_ARG_CHECK(gapless);
258 int ret = PLAYER_ERROR_NONE;
259 muse_player_api_e api = MUSE_PLAYER_API_IS_GAPLESS;
260 player_cli_s *pc = (player_cli_s *)player;
261 char *ret_buf = NULL;
266 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
267 if (ret == PLAYER_ERROR_NONE) {
268 player_msg_get(value, ret_buf);
275 int player_enable_tsurf_pool(player_h player, bool enable)
277 PLAYER_INSTANCE_CHECK(player);
278 int ret = PLAYER_ERROR_NONE;
279 player_cli_s *pc = (player_cli_s *)player;
281 LOGD("ENTER enable:%d", enable);
283 if (pc && pc->cb_info) {
284 pc->cb_info->use_tsurf_pool = enable;
286 LOGE("failed to enable the tbm surf pool");
287 ret = PLAYER_ERROR_INVALID_OPERATION;
293 int player_is_enabled_tsurf_pool(player_h player, bool *enabled)
295 PLAYER_INSTANCE_CHECK(player);
296 PLAYER_NULL_ARG_CHECK(enabled);
297 int ret = PLAYER_ERROR_NONE;
298 player_cli_s *pc = (player_cli_s *)player;
301 if (pc && pc->cb_info) {
302 *enabled = pc->cb_info->use_tsurf_pool;
304 LOGE("failed to get the tbm surf pool state");
305 ret = PLAYER_ERROR_INVALID_OPERATION;
311 int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
313 PLAYER_INSTANCE_CHECK(player);
314 PLAYER_NULL_ARG_CHECK(size);
316 int ret = PLAYER_ERROR_NONE;
317 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
318 player_cli_s *pc = (player_cli_s *)player;
319 char *ret_buf = NULL;
324 PLAYER_SEND_MSG(api, pc, ret_buf, ret);
325 if (ret == PLAYER_ERROR_NONE) {
326 player_msg_get(value, ret_buf);
328 pc->cb_info->video_frame_pool_size = value;
329 LOGD("packet pool size : %d", *size);
335 int player_enable_media_packet_video_frame_decoded_cb(player_h player, bool enable)
337 PLAYER_INSTANCE_CHECK(player);
338 int ret = PLAYER_ERROR_NONE;
339 muse_player_api_e api = MUSE_PLAYER_API_ENABLE_MEDIA_PACKET_VIDEO_FRAME_DECODED_CB;
340 player_cli_s *pc = (player_cli_s *)player;
341 char *ret_buf = NULL;
343 LOGD("ENTER %d", enable);
345 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "enable", enable);
350 int player_set_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e codec_type)
352 PLAYER_INSTANCE_CHECK(player);
353 PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
355 int ret = PLAYER_ERROR_NONE;
356 muse_player_api_e api = MUSE_PLAYER_API_SET_CODEC_TYPE;
357 player_cli_s *pc = (player_cli_s *)player;
358 char *ret_buf = NULL;
360 LOGD("ENTER stream: %d, codec: %d", stream_type, codec_type);
362 PLAYER_SEND_MSG(api, pc, ret_buf, ret,
363 MUSE_TYPE_INT, "stream_type", stream_type,
364 MUSE_TYPE_INT, "codec_type", codec_type);
371 int player_get_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e *pcodec_type)
373 PLAYER_INSTANCE_CHECK(player);
374 PLAYER_NULL_ARG_CHECK(pcodec_type);
375 PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
377 int ret = PLAYER_ERROR_NONE;
378 muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_TYPE;
379 player_cli_s *pc = (player_cli_s *)player;
380 char *ret_buf = NULL;
383 LOGD("ENTER stream_type: %d", stream_type);
385 PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "stream_type", stream_type);
386 if (ret == PLAYER_ERROR_NONE) {
387 player_msg_get(codec_type, ret_buf);
388 *pcodec_type = codec_type;