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>
28 #include <Ecore_Wayland.h>
30 #include <muse_player.h>
31 #include <muse_player_msg.h>
32 #include "player_private.h"
33 #include "player_internal.h"
35 int player_set_pcm_extraction_mode(player_h player, bool sync, player_audio_pcm_extraction_cb callback, void *user_data)
37 PLAYER_INSTANCE_CHECK(player);
38 PLAYER_NULL_ARG_CHECK(callback);
39 int ret = PLAYER_ERROR_NONE;
40 muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_EXTRACTION_MODE;
41 player_cli_s *pc = (player_cli_s *) player;
43 muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME;
47 player_msg_send1(api, pc, ret_buf, ret, INT, sync);
49 if (ret == PLAYER_ERROR_NONE) {
50 pc->cb_info->user_cb[event] = callback;
51 pc->cb_info->user_data[event] = user_data;
52 LOGI("Event type : %d ", event);
59 int player_set_pcm_spec(player_h player, const char *format, int samplerate, int channel)
61 PLAYER_INSTANCE_CHECK(player);
62 int ret = PLAYER_ERROR_NONE;
63 muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_SPEC;
64 player_cli_s *pc = (player_cli_s *) player;
69 player_msg_send3(api, pc, ret_buf, ret, STRING, format, INT, samplerate, INT, channel);
75 int player_set_streaming_playback_rate(player_h player, float rate)
77 PLAYER_INSTANCE_CHECK(player);
78 int ret = PLAYER_ERROR_NONE;
79 muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_PLAYBACK_RATE;
80 player_cli_s *pc = (player_cli_s *) player;
85 player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
90 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)
92 PLAYER_INSTANCE_CHECK(player);
93 PLAYER_NULL_ARG_CHECK(callback);
94 int ret = PLAYER_ERROR_NONE;
95 player_cli_s *pc = (player_cli_s *) player;
96 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
98 muse_player_event_e type;
103 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
104 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
105 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
106 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
108 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
109 return PLAYER_ERROR_INVALID_PARAMETER;
112 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
114 if (ret == PLAYER_ERROR_NONE) {
115 pc->cb_info->user_cb[type] = callback;
116 pc->cb_info->user_data[type] = user_data;
117 LOGI("Event type : %d ", type);
124 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
126 if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
127 cb_info->user_cb[event] = NULL;
128 cb_info->user_data[event] = NULL;
132 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
134 bool lock = g_thread_self() != cb_info->event_queue.thread;
137 g_mutex_lock(&cb_info->event_queue.mutex);
139 set_null_user_cb(cb_info, event);
142 g_mutex_unlock(&cb_info->event_queue.mutex);
145 int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type)
147 PLAYER_INSTANCE_CHECK(player);
148 int ret = PLAYER_ERROR_NONE;
149 player_cli_s *pc = (player_cli_s *) player;
150 muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
151 char *ret_buf = NULL;
152 muse_player_event_e type;
157 if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
158 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
159 else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
160 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
162 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
163 return PLAYER_ERROR_INVALID_PARAMETER;
166 set_null_user_cb_lock(pc->cb_info, type);
168 player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
174 static void __evas_resize_cb(void *data, Evas * e, Evas_Object * eo, void *event_info)
176 player_cli_s *pc = (player_cli_s *) data;
177 wl_win_msg_type wl_win;
178 char *wl_win_msg = (char *)&wl_win;
179 char *ret_buf = NULL;
181 Ecore_Evas *ecore_evas;
182 muse_player_api_e api = MUSE_PLAYER_API_RESIZE_VIDEO_RENDER_RECT;
183 int ret = PLAYER_ERROR_NONE;
184 LOGD("ret =%d", ret);
186 evas_object_geometry_get(eo, &wl_win.wl_window_x, &wl_win.wl_window_y, &wl_win.wl_window_width, &wl_win.wl_window_height);
187 ecore_evas = ecore_evas_ecore_evas_get(e);
188 rotation = ecore_evas_rotation_get(ecore_evas);
189 LOGD("rotation(%d)", rotation);
190 LOGD("get window rectangle: x(%d) y(%d) width(%d) height(%d)",
191 wl_win.wl_window_x, wl_win.wl_window_y, wl_win.wl_window_width, wl_win.wl_window_height);
192 if (rotation == 270 || rotation == 90) {
193 LOGD("swap w and h");
195 temp = wl_win.wl_window_width;
196 wl_win.wl_window_width = wl_win.wl_window_height;
197 wl_win.wl_window_height = temp;
199 LOGD("get window rectangle: x(%d) y(%d) width(%d) height(%d)",
200 wl_win.wl_window_x, wl_win.wl_window_y, wl_win.wl_window_width, wl_win.wl_window_height);
201 wl_win.type = 0; /*init but not use */
202 wl_win.wl_surface_id = 0; /*init but not use */
204 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
211 static void __evas_del_cb(void *data, Evas * e, Evas_Object * eo, void *event_info)
214 player_cli_s *pc = (player_cli_s *) data;
216 evas_object_event_callback_del(eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb);
217 evas_object_event_callback_del(eo, EVAS_CALLBACK_DEL, __evas_del_cb);
219 LOGD("evas callback del %p", eo);
220 pc->have_evas_callback = FALSE;
225 int player_set_evas_object_cb(player_h player, Evas_Object * eo)
228 PLAYER_INSTANCE_CHECK(player);
229 return_val_if_fail(eo != NULL, MM_ERROR_INVALID_ARGUMENT);
231 player_cli_s *pc = (player_cli_s *) player;
233 if (pc->have_evas_callback && pc->eo == eo) {
234 LOGW("evas object had callback already %p", pc->eo);
235 return MM_ERROR_UNKNOWN;
238 evas_object_event_callback_add(eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb, player);
239 evas_object_event_callback_add(eo, EVAS_CALLBACK_DEL, __evas_del_cb, player);
240 LOGD("evas callback add %p", pc->eo);
241 pc->have_evas_callback = TRUE;
243 return MM_ERROR_NONE;
246 int player_unset_evas_object_cb(player_h player)
248 PLAYER_INSTANCE_CHECK(player);
249 player_cli_s *pc = (player_cli_s *) player;
250 return_val_if_fail(pc->eo != NULL, MM_ERROR_INVALID_ARGUMENT);
252 evas_object_event_callback_del(pc->eo, EVAS_CALLBACK_RESIZE, __evas_resize_cb);
253 evas_object_event_callback_del(pc->eo, EVAS_CALLBACK_DEL, __evas_del_cb);
254 LOGD("evas callback del %p", pc->eo);
256 pc->have_evas_callback = FALSE;
258 return MM_ERROR_NONE;
262 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)
264 PLAYER_INSTANCE_CHECK(player);
265 int ret = PLAYER_ERROR_NONE;
266 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
267 player_cli_s *pc = (player_cli_s *) player;
268 char *ret_buf = NULL;
269 wl_win_msg_type wl_win;
270 char *wl_win_msg = (char *)&wl_win;
271 unsigned int wl_surface_id;
272 struct wl_surface *wl_surface;
273 struct wl_display *wl_display;
274 Ecore_Wl_Window *wl_window = NULL;
277 if (type !=PLAYER_DISPLAY_TYPE_OVERLAY) {
278 LOGE("Display type(%d) is not overlay", type);
279 return PLAYER_ERROR_INVALID_PARAMETER;
281 if (!ecore_wl_window)
282 return PLAYER_ERROR_INVALID_PARAMETER;
284 LOGI("Wayland overlay surface type");
285 LOGD("Ecore Wayland Window handle(%p), size (%d, %d, %d, %d)", ecore_wl_window, x, y, width, height);
286 wl_window = ecore_wl_window;
290 wl_win.wl_window_x = x;
291 wl_win.wl_window_y = y;
292 wl_win.wl_window_width = width;
293 wl_win.wl_window_height = height;
295 wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window);
297 wl_display = (struct wl_display *)ecore_wl_display_get();
300 ret = _wlclient_create(&pc->wlclient);
301 if (ret != MM_ERROR_NONE) {
302 LOGE("Wayland client create failure");
307 if (wl_surface && wl_display) {
308 LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
309 wl_surface_id = _wlclient_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display);
310 LOGD("wl_surface_id = %d", wl_surface_id);
311 wl_win.wl_surface_id = wl_surface_id;
312 LOGD("wl_win.wl_surface_id = %d", wl_win.wl_surface_id);
314 LOGE("Fail to get wl_surface or wl_display");
315 return PLAYER_ERROR_INVALID_OPERATION;
319 g_free(pc->wlclient);
323 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));