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 <muse_core.h>
21 #include <muse_core_msg_json.h>
22 #include <muse_core_ipc.h>
26 #include <Ecore_Evas.h>
27 #include <Ecore_Wayland.h>
28 #include <muse_player.h>
29 #include <muse_player_msg.h>
30 #include <storage-internal.h>
31 #include "player_private.h"
32 #include "player_msg.h"
33 #include "player_internal.h"
34 #include "player_display.h"
36 int player_set_pcm_extraction_mode(player_h player, bool sync, player_audio_pcm_extraction_cb callback, void *user_data)
38 PLAYER_INSTANCE_CHECK(player);
39 PLAYER_NULL_ARG_CHECK(callback);
40 int ret = PLAYER_ERROR_NONE;
41 muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_EXTRACTION_MODE;
42 player_cli_s *pc = (player_cli_s *) player;
44 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME;
48 player_msg_send1(api, pc, ret_buf, ret, INT, sync);
50 if (ret == PLAYER_ERROR_NONE) {
51 pc->cb_info->user_cb[event] = callback;
52 pc->cb_info->user_data[event] = user_data;
53 LOGI("Event type : %d ", event);
60 int player_set_pcm_spec(player_h player, const char *format, int samplerate, int channel)
62 PLAYER_INSTANCE_CHECK(player);
63 int ret = PLAYER_ERROR_NONE;
64 muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_SPEC;
65 player_cli_s *pc = (player_cli_s *) player;
70 player_msg_send3(api, pc, ret_buf, ret, STRING, format, INT, samplerate, INT, channel);
76 int player_set_streaming_playback_rate(player_h player, float rate)
78 PLAYER_INSTANCE_CHECK(player);
79 int ret = PLAYER_ERROR_NONE;
80 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_PLAYBACK_RATE;
81 player_cli_s *pc = (player_cli_s *) player;
86 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
91 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)
93 PLAYER_INSTANCE_CHECK(player);
94 PLAYER_NULL_ARG_CHECK(callback);
95 int ret = PLAYER_ERROR_NONE;
96 player_cli_s *pc = (player_cli_s *) player;
97 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
99 muse_player_event_e type;
104 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
105 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
106 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
107 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
109 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
110 return PLAYER_ERROR_INVALID_PARAMETER;
113 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
115 if (ret == PLAYER_ERROR_NONE) {
116 pc->cb_info->user_cb[type] = callback;
117 pc->cb_info->user_data[type] = user_data;
118 LOGI("Event type : %d ", type);
125 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
127 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
128 cb_info->user_cb[event] = NULL;
129 cb_info->user_data[event] = NULL;
133 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
135 bool lock = g_thread_self() != cb_info->event_queue.thread;
138 g_mutex_lock(&cb_info->event_queue.mutex);
140 set_null_user_cb(cb_info, event);
143 g_mutex_unlock(&cb_info->event_queue.mutex);
146 int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type)
148 PLAYER_INSTANCE_CHECK(player);
149 int ret = PLAYER_ERROR_NONE;
150 player_cli_s *pc = (player_cli_s *) player;
151 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
152 char *ret_buf = NULL;
153 muse_player_event_e type;
158 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
159 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
160 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
161 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
163 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
164 return PLAYER_ERROR_INVALID_PARAMETER;
167 set_null_user_cb_lock(pc->cb_info, type);
169 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
175 int player_set_media_stream_dynamic_resolution(player_h player, bool drc)
177 PLAYER_INSTANCE_CHECK(player);
178 int ret = PLAYER_ERROR_NONE;
179 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_DYNAMIC_RESOLUTION;
180 player_cli_s *pc = (player_cli_s *) player;
181 char *ret_buf = NULL;
185 player_msg_send1(api, pc, ret_buf, ret, INT, drc);
190 int player_set_ecore_wl_display(player_h player, player_display_type_e type, Ecore_Wl_Window *ecore_wl_window, int x, int y, int width, int height)
192 PLAYER_INSTANCE_CHECK(player);
193 int ret = PLAYER_ERROR_NONE;
194 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
195 player_cli_s *pc = (player_cli_s *) player;
196 char *ret_buf = NULL;
197 wl_win_msg_type wl_win;
198 char *wl_win_msg = (char *)&wl_win;
199 unsigned int wl_surface_id;
200 struct wl_surface *wl_surface;
201 struct wl_display *wl_display;
202 Ecore_Wl_Window *wl_window = NULL;
203 player_private_display_type_e conv_type;
206 ret = _player_convert_display_type(type, &conv_type);
207 if (ret != PLAYER_ERROR_NONE)
210 if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
211 LOGE("Display type(%d) is not overlay", conv_type);
212 return PLAYER_ERROR_INVALID_PARAMETER;
214 if (!ecore_wl_window)
215 return PLAYER_ERROR_INVALID_PARAMETER;
217 LOGI("Wayland overlay surface type");
218 LOGD("Ecore Wayland Window handle(%p), size (%d, %d, %d, %d)", ecore_wl_window, x, y, width, height);
219 wl_window = ecore_wl_window;
222 wl_win.type = conv_type;
223 wl_win.wl_window_x = x;
224 wl_win.wl_window_y = y;
225 wl_win.wl_window_width = width;
226 wl_win.wl_window_height = height;
228 wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window);
230 wl_display = (struct wl_display *)ecore_wl_display_get();
233 ret = _wl_client_create(&pc->wlclient);
234 if (ret != MM_ERROR_NONE) {
235 LOGE("Wayland client create failure");
240 if (wl_surface && wl_display) {
241 LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
242 wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display);
243 LOGD("wl_surface_id = %d", wl_surface_id);
244 wl_win.wl_surface_id = wl_surface_id;
245 LOGD("wl_win.wl_surface_id = %d", wl_win.wl_surface_id);
247 LOGE("Fail to get wl_surface or wl_display");
248 return PLAYER_ERROR_INVALID_OPERATION;
252 g_free(pc->wlclient);
256 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
263 int player_set_next_uri(player_h player, const char *uri)
265 PLAYER_INSTANCE_CHECK(player);
266 PLAYER_NULL_ARG_CHECK(uri);
267 int ret = PLAYER_ERROR_NONE;
268 muse_player_api_e api = MUSE_PLAYER_API_SET_NEXT_URI;
269 player_cli_s *pc = (player_cli_s *) player;
270 char *ret_buf = NULL;
271 char path[MAX_URL_LEN] = {0, };
275 if (_player_get_origin_internal_path(uri, path) != PLAYER_ERROR_NONE)
276 return PLAYER_ERROR_INVALID_PARAMETER;
278 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
284 int player_get_next_uri(player_h player, char **uri)
286 PLAYER_INSTANCE_CHECK(player);
287 PLAYER_NULL_ARG_CHECK(uri);
288 int ret = PLAYER_ERROR_NONE;
289 muse_player_api_e api = MUSE_PLAYER_API_GET_NEXT_URI;
290 player_cli_s *pc = (player_cli_s *) player;
291 char *ret_buf = NULL;
292 char next_uri[MUSE_MSG_MAX_LENGTH] = { 0, };
296 player_msg_send(api, pc, ret_buf, ret);
297 if (ret == PLAYER_ERROR_NONE) {
298 player_msg_get_string(next_uri, ret_buf);
300 char dest[MUSE_MSG_MAX_LENGTH] = {0,};
301 if (storage_get_compat_internal_path(next_uri, sizeof(dest), dest) < 0) {
302 /* cannot convert path. use the original one. */
303 *uri = strndup(next_uri, MUSE_MSG_MAX_LENGTH);
305 /* need to use converted path. */
306 LOGD("Converted path : %s -> %s", next_uri, dest);
307 *uri = strndup(dest, MUSE_MSG_MAX_LENGTH);
314 int player_set_gapless(player_h player, bool gapless)
316 PLAYER_INSTANCE_CHECK(player);
317 int ret = PLAYER_ERROR_NONE;
318 muse_player_api_e api = MUSE_PLAYER_API_SET_GAPLESS;
319 player_cli_s *pc = (player_cli_s *) player;
320 char *ret_buf = NULL;
324 player_msg_send1(api, pc, ret_buf, ret, INT, gapless);
329 int player_is_gapless(player_h player, bool *gapless)
331 PLAYER_INSTANCE_CHECK(player);
332 PLAYER_NULL_ARG_CHECK(gapless);
333 int ret = PLAYER_ERROR_NONE;
334 muse_player_api_e api = MUSE_PLAYER_API_IS_GAPLESS;
335 player_cli_s *pc = (player_cli_s *) player;
336 char *ret_buf = NULL;
341 player_msg_send(api, pc, ret_buf, ret);
342 if (ret == PLAYER_ERROR_NONE) {
343 player_msg_get(value, ret_buf);
350 int player_enable_tsurf_pool(player_h player, bool enable)
352 PLAYER_INSTANCE_CHECK(player);
353 int ret = PLAYER_ERROR_NONE;
354 player_cli_s *pc = (player_cli_s *) player;
356 LOGD("ENTER enable:%d", enable);
358 if (pc && pc->cb_info) {
359 pc->cb_info->use_tsurf_pool = enable;
361 LOGE("failed to enable the tbm surf pool");
362 ret = PLAYER_ERROR_INVALID_OPERATION;
368 int player_is_enabled_tsurf_pool(player_h player, bool *enabled)
370 PLAYER_INSTANCE_CHECK(player);
371 PLAYER_NULL_ARG_CHECK(enabled);
372 int ret = PLAYER_ERROR_NONE;
373 player_cli_s *pc = (player_cli_s *) player;
376 if (pc && pc->cb_info) {
377 *enabled = pc->cb_info->use_tsurf_pool;
379 LOGE("failed to get the tbm surf pool state");
380 ret = PLAYER_ERROR_INVALID_OPERATION;
386 int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
388 PLAYER_INSTANCE_CHECK(player);
389 PLAYER_NULL_ARG_CHECK(size);
391 int ret = PLAYER_ERROR_NONE;
392 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
393 player_cli_s *pc = (player_cli_s *) player;
394 char *ret_buf = NULL;
399 player_msg_send(api, pc, ret_buf, ret);
400 if (ret == PLAYER_ERROR_NONE) {
401 player_msg_get(value, ret_buf);
403 pc->cb_info->video_frame_pool_size = value;
404 LOGD("packet pool size : %d", *size);
410 int player_enable_media_packet_video_frame_decoded_cb(player_h player, bool enable)
412 PLAYER_INSTANCE_CHECK(player);
413 int ret = PLAYER_ERROR_NONE;
414 muse_player_api_e api = MUSE_PLAYER_API_ENABLE_MEDIA_PACKET_VIDEO_FRAME_DECODED_CB;
415 player_cli_s *pc = (player_cli_s *) player;
416 char *ret_buf = NULL;
420 player_msg_send1(api, pc, ret_buf, ret, INT, enable);