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 "player_private.h"
31 #include "player_msg.h"
32 #include "player_internal.h"
33 #include "player_display.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 int player_set_media_stream_dynamic_resolution(player_h player, bool drc)
176 PLAYER_INSTANCE_CHECK(player);
177 int ret = PLAYER_ERROR_NONE;
178 muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_DYNAMIC_RESOLUTION;
179 player_cli_s *pc = (player_cli_s *) player;
180 char *ret_buf = NULL;
184 player_msg_send1(api, pc, ret_buf, ret, INT, drc);
189 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)
191 PLAYER_INSTANCE_CHECK(player);
192 int ret = PLAYER_ERROR_NONE;
193 muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
194 player_cli_s *pc = (player_cli_s *) player;
195 char *ret_buf = NULL;
196 wl_win_msg_type wl_win;
197 char *wl_win_msg = (char *)&wl_win;
198 unsigned int wl_surface_id;
199 struct wl_surface *wl_surface;
200 struct wl_display *wl_display;
201 Ecore_Wl_Window *wl_window = NULL;
204 if (type != PLAYER_DISPLAY_TYPE_OVERLAY) {
205 LOGE("Display type(%d) is not overlay", type);
206 return PLAYER_ERROR_INVALID_PARAMETER;
208 if (!ecore_wl_window)
209 return PLAYER_ERROR_INVALID_PARAMETER;
211 LOGI("Wayland overlay surface type");
212 LOGD("Ecore Wayland Window handle(%p), size (%d, %d, %d, %d)", ecore_wl_window, x, y, width, height);
213 wl_window = ecore_wl_window;
217 wl_win.wl_window_x = x;
218 wl_win.wl_window_y = y;
219 wl_win.wl_window_width = width;
220 wl_win.wl_window_height = height;
222 wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window);
224 wl_display = (struct wl_display *)ecore_wl_display_get();
227 ret = _wl_client_create(&pc->wlclient);
228 if (ret != MM_ERROR_NONE) {
229 LOGE("Wayland client create failure");
234 if (wl_surface && wl_display) {
235 LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
236 wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display);
237 LOGD("wl_surface_id = %d", wl_surface_id);
238 wl_win.wl_surface_id = wl_surface_id;
239 LOGD("wl_win.wl_surface_id = %d", wl_win.wl_surface_id);
241 LOGE("Fail to get wl_surface or wl_display");
242 return PLAYER_ERROR_INVALID_OPERATION;
246 g_free(pc->wlclient);
250 player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
258 int player_set_next_uri(player_h player, const char *uri)
260 PLAYER_INSTANCE_CHECK(player);
261 PLAYER_NULL_ARG_CHECK(uri);
262 int ret = PLAYER_ERROR_NONE;
263 muse_player_api_e api = MUSE_PLAYER_API_SET_NEXT_URI;
264 player_cli_s *pc = (player_cli_s *) player;
265 char *ret_buf = NULL;
266 char path[MAX_URL_LEN];
270 _player_replace_old_path(uri, path);
271 player_msg_send1(api, pc, ret_buf, ret, STRING, path);
277 int player_get_next_uri(player_h player, char **uri)
279 PLAYER_INSTANCE_CHECK(player);
280 PLAYER_NULL_ARG_CHECK(uri);
281 int ret = PLAYER_ERROR_NONE;
282 muse_player_api_e api = MUSE_PLAYER_API_GET_NEXT_URI;
283 player_cli_s *pc = (player_cli_s *) player;
284 char *ret_buf = NULL;
285 char next_uri[MUSE_MSG_MAX_LENGTH] = { 0, };
289 player_msg_send(api, pc, ret_buf, ret);
290 if (ret == PLAYER_ERROR_NONE) {
291 player_msg_get_string(next_uri, ret_buf);
292 *uri = strndup(next_uri, MUSE_MSG_MAX_LENGTH);
298 int player_set_gapless(player_h player, bool gapless)
300 PLAYER_INSTANCE_CHECK(player);
301 int ret = PLAYER_ERROR_NONE;
302 muse_player_api_e api = MUSE_PLAYER_API_SET_GAPLESS;
303 player_cli_s *pc = (player_cli_s *) player;
304 char *ret_buf = NULL;
308 player_msg_send1(api, pc, ret_buf, ret, INT, gapless);
313 int player_is_gapless(player_h player, bool *gapless)
315 PLAYER_INSTANCE_CHECK(player);
316 PLAYER_NULL_ARG_CHECK(gapless);
317 int ret = PLAYER_ERROR_NONE;
318 muse_player_api_e api = MUSE_PLAYER_API_IS_GAPLESS;
319 player_cli_s *pc = (player_cli_s *) player;
320 char *ret_buf = NULL;
325 player_msg_send(api, pc, ret_buf, ret);
326 if (ret == PLAYER_ERROR_NONE) {
327 player_msg_get(value, ret_buf);
334 int player_enable_tsurf_pool(player_h player, bool enable)
336 PLAYER_INSTANCE_CHECK(player);
337 int ret = PLAYER_ERROR_NONE;
338 player_cli_s *pc = (player_cli_s *) player;
340 LOGD("ENTER enable:%d", enable);
342 if (pc && pc->cb_info) {
343 pc->cb_info->use_tsurf_pool = enable;
345 LOGE("failed to enable the tbm surf pool");
346 ret = PLAYER_ERROR_INVALID_OPERATION;
352 int player_is_enabled_tsurf_pool(player_h player, bool *enabled)
354 PLAYER_INSTANCE_CHECK(player);
355 PLAYER_NULL_ARG_CHECK(enabled);
356 int ret = PLAYER_ERROR_NONE;
357 player_cli_s *pc = (player_cli_s *) player;
360 if (pc && pc->cb_info) {
361 *enabled = pc->cb_info->use_tsurf_pool;
363 LOGE("failed to get the tbm surf pool state");
364 ret = PLAYER_ERROR_INVALID_OPERATION;
370 int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
372 PLAYER_INSTANCE_CHECK(player);
373 PLAYER_NULL_ARG_CHECK(size);
375 int ret = PLAYER_ERROR_NONE;
376 muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
377 player_cli_s *pc = (player_cli_s *) player;
378 char *ret_buf = NULL;
383 player_msg_send(api, pc, ret_buf, ret);
384 if (ret == PLAYER_ERROR_NONE) {
385 player_msg_get(value, ret_buf);
387 pc->cb_info->video_frame_pool_size = value;
388 LOGD("packet pool size : %d", *size);
394 int player_enable_media_packet_video_frame_decoded_cb(player_h player, bool enable)
396 PLAYER_INSTANCE_CHECK(player);
397 int ret = PLAYER_ERROR_NONE;
398 muse_player_api_e api = MUSE_PLAYER_API_ENABLE_MEDIA_PACKET_VIDEO_FRAME_DECODED_CB;
399 player_cli_s *pc = (player_cli_s *) player;
400 char *ret_buf = NULL;
404 player_msg_send1(api, pc, ret_buf, ret, INT, enable);