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.
23 #include <mm_player.h>
24 #include <mm_player_internal.h>
25 #include <mm_player_mused.h>
28 #include <player_internal.h>
29 #include <player_private.h>
35 #define PLAYER_SET_CALLBACK(event_type, handle, callback, user_data) \
38 PLAYER_INSTANCE_CHECK(handle); \
39 PLAYER_NULL_ARG_CHECK(callback); \
40 handle->user_cb[event_type] = callback; \
41 handle->user_data[event_type] = user_data; \
42 LOGI("[%s] Event type : %d ",__FUNCTION__, event_type); \
45 bool __audio_stream_callback_ex(MMPlayerAudioStreamDataType *stream, void *user_data)
47 player_s * handle = (player_s*)user_data;
48 if( handle->user_cb[_PLAYER_EVENT_TYPE_AUDIO_FRAME] )
50 if(handle->state==PLAYER_STATE_PLAYING || handle->state==PLAYER_STATE_PAUSED)
52 ((player_audio_pcm_extraction_cb)handle->user_cb[_PLAYER_EVENT_TYPE_AUDIO_FRAME])((player_audio_raw_data_s *)stream, handle->user_data[_PLAYER_EVENT_TYPE_AUDIO_FRAME]);
56 LOGE("[%s] Skip stream - current state : %d", __FUNCTION__,handle->state);
62 int player_set_pcm_extraction_mode(player_h player, bool sync, player_audio_pcm_extraction_cb callback, void *user_data)
64 PLAYER_INSTANCE_CHECK(player);
65 PLAYER_NULL_ARG_CHECK(callback);
66 player_s * handle = (player_s *) player;
67 int ret = MM_ERROR_NONE;
69 PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
71 ret = mm_player_set_attribute(handle->mm_handle, NULL, "pcm_extraction",TRUE, "pcm_extraction_start_msec", 0, "pcm_extraction_end_msec", 0, NULL);
72 if(ret != MM_ERROR_NONE)
73 return __player_convert_error_code(ret,(char*)__FUNCTION__);
75 ret = mm_player_set_audio_stream_callback_ex(handle->mm_handle, sync, __audio_stream_callback_ex, (void*)handle);
76 if(ret != MM_ERROR_NONE)
77 return __player_convert_error_code(ret,(char*)__FUNCTION__);
79 PLAYER_SET_CALLBACK(_PLAYER_EVENT_TYPE_AUDIO_FRAME, handle, callback, user_data);
80 return PLAYER_ERROR_NONE;
83 int player_set_pcm_spec(player_h player, const char *format, int samplerate, int channel)
85 PLAYER_INSTANCE_CHECK(player);
87 player_s * handle = (player_s *) player;
88 int ret = MM_ERROR_NONE;
90 LOGE("[%s] player_set_pcm_spec %s %d %d", __FUNCTION__, format, samplerate, channel);
91 ret = mm_player_set_attribute(handle->mm_handle, NULL, "pcm_audioformat", format , strlen(format), NULL);
92 if(ret != MM_ERROR_NONE)
93 return __player_convert_error_code(ret,(char*)__FUNCTION__);
95 ret = mm_player_set_pcm_spec(handle->mm_handle, samplerate, channel);
96 if(ret != MM_ERROR_NONE)
97 return __player_convert_error_code(ret,(char*)__FUNCTION__);
99 return PLAYER_ERROR_NONE;
103 * Internal Implementation for mused
105 int player_set_shm_stream_path_for_mused (player_h player, const char *stream_path)
107 PLAYER_INSTANCE_CHECK(player);
108 PLAYER_NULL_ARG_CHECK(stream_path);
110 player_s * handle = (player_s *) player;
112 if(mm_player_set_shm_stream_path(handle->mm_handle, stream_path)
114 LOGE("Fail to set attribute stream path");
115 return PLAYER_ERROR_INVALID_OPERATION;
117 return PLAYER_ERROR_NONE;
120 static MMDisplaySurfaceType __player_mused_convet_display_type(player_display_type_e type)
123 case PLAYER_DISPLAY_TYPE_OVERLAY:
124 return MM_DISPLAY_SURFACE_REMOTE;
126 case PLAYER_DISPLAY_TYPE_EVAS:
127 return MM_DISPLAY_SURFACE_EVAS;
129 case PLAYER_DISPLAY_TYPE_NONE:
130 return MM_DISPLAY_SURFACE_NULL;
132 return MM_DISPLAY_SURFACE_NULL;
138 int player_set_display_wl_for_mused(player_h player, player_display_type_e type, intptr_t surface,
139 int x, int y, int w, int h)
141 PLAYER_INSTANCE_CHECK(player);
142 player_s * handle = (player_s *) player;
143 void *set_handle = NULL;
144 MMDisplaySurfaceType mmType = __player_mused_convet_display_type(type);
147 if (!__player_state_validate(handle, PLAYER_STATE_IDLE))
149 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d" ,__FUNCTION__,PLAYER_ERROR_INVALID_STATE, handle->state);
150 return PLAYER_ERROR_INVALID_STATE;
152 if (handle->is_set_pixmap_cb)
154 if (handle->state < PLAYER_STATE_READY)
156 /* just set below and go to "changing surface case" */
157 handle->is_set_pixmap_cb = false;
161 LOGE("[%s] pixmap callback was set, try it again after calling player_unprepare()" ,__FUNCTION__,PLAYER_ERROR_INVALID_OPERATION);
162 LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION(0x%08x)" ,__FUNCTION__,PLAYER_ERROR_INVALID_OPERATION);
163 return PLAYER_ERROR_INVALID_OPERATION;
168 if (type == PLAYER_DISPLAY_TYPE_NONE)
171 handle->display_handle = 0;
172 handle->display_type = type;
177 /* get handle from overlay or evas surface */
178 temp = handle->display_handle;
179 if (type == PLAYER_DISPLAY_TYPE_OVERLAY)
181 LOGI("Wayland overlay surface type");
182 handle->display_handle = (void *)surface;
183 set_handle = &(handle->display_handle);
185 LOGE("invalid surface type");
186 return PLAYER_ERROR_INVALID_PARAMETER;
190 /* set display handle */
191 if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE || type == handle->display_type) // first time or same type
193 LOGW("first time or same type");
194 ret = mm_player_set_attribute(handle->mm_handle, NULL,
195 "display_surface_type", mmType,
196 "display_overlay", set_handle,
197 sizeof(void *), (char*)NULL);
199 if (ret != MM_ERROR_NONE)
201 handle->display_handle = temp;
202 LOGE("[%s] Failed to display surface change :%d",__FUNCTION__,ret);
206 if (type != PLAYER_DISPLAY_TYPE_NONE)
208 handle->display_type = type;
209 LOGI("[%s] video display has been changed- type :%d, addr : 0x%x",
210 __FUNCTION__,handle->display_type, handle->display_handle);
213 LOGI("NULL surface");
215 LOGI("get window rectangle: x(%d) y(%d) width(%d) height(%d)", x, y, w, h);
216 ret = mm_player_set_attribute(handle->mm_handle, NULL,
217 "wl_window_render_x", x,
218 "wl_window_render_y", y,
219 "wl_window_render_width", w,
220 "wl_window_render_height", h,
223 if (ret != MM_ERROR_NONE)
225 handle->display_handle = temp;
226 LOGE("[%s] Failed to set wl_window render rectangle :%d",__FUNCTION__,ret);
229 else //changing surface case
231 ret = mm_player_change_videosink(handle->mm_handle, mmType, set_handle);
232 if (ret != MM_ERROR_NONE)
234 handle->display_handle = temp;
235 if(ret == MM_ERROR_NOT_SUPPORT_API)
237 LOGE("[%s] change video sink is not available.",__FUNCTION__);
238 ret = PLAYER_ERROR_NONE;
242 LOGE("[%s] Failed to display surface change :%d",__FUNCTION__,ret);
247 handle->display_type = type;
248 LOGI("[%s] video display has been changed- type :%d, addr : 0x%x",
249 __FUNCTION__,handle->display_type, handle->display_handle);
253 if(ret != MM_ERROR_NONE)
255 handle->display_type = PLAYER_DISPLAY_TYPE_NONE;
256 return __player_convert_error_code(ret,(char*)__FUNCTION__);
260 return PLAYER_ERROR_NONE;
266 int player_set_display_for_mused(player_h player, player_display_type_e type, unsigned int xhandle)
268 PLAYER_INSTANCE_CHECK(player);
269 player_s * handle = (player_s *) player;
270 void *set_handle = NULL;
271 MMDisplaySurfaceType mmType = __player_mused_convet_display_type(type);
274 if (!__player_state_validate(handle, PLAYER_STATE_IDLE))
276 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d" ,__FUNCTION__,PLAYER_ERROR_INVALID_STATE, handle->state);
277 return PLAYER_ERROR_INVALID_STATE;
280 if (handle->is_set_pixmap_cb)
282 if (handle->state < PLAYER_STATE_READY)
284 /* just set below and go to "changing surface case" */
285 handle->is_set_pixmap_cb = false;
289 LOGE("[%s] pixmap callback was set, try it again after calling player_unprepare()" ,__FUNCTION__,PLAYER_ERROR_INVALID_OPERATION);
290 LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION(0x%08x)" ,__FUNCTION__,PLAYER_ERROR_INVALID_OPERATION);
291 return PLAYER_ERROR_INVALID_OPERATION;
296 if (type == PLAYER_DISPLAY_TYPE_NONE)
299 handle->display_handle = 0;
300 handle->display_type = PLAYER_DISPLAY_TYPE_NONE;
305 /* get handle from overlay or evas surface */
306 temp = handle->display_handle;
307 if (type == PLAYER_DISPLAY_TYPE_OVERLAY /*&& !strcmp(object_type, "elm_win")*/)
309 /* x window overlay surface */
310 LOGI("overlay surface type");
311 handle->display_handle = (void *)xhandle;
312 set_handle = &(handle->display_handle);
316 LOGE("invalid surface type");
317 return PLAYER_ERROR_INVALID_PARAMETER;
321 /* set display handle */
322 if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE || type == handle->display_type) // first time or same type
324 ret = mm_player_set_attribute(handle->mm_handle, NULL,
325 "display_surface_type", mmType,
326 "display_overlay", set_handle,
327 sizeof(xhandle), (char*)NULL);
329 if (ret != MM_ERROR_NONE)
331 handle->display_handle = temp;
332 LOGE("[%s] Failed to display surface change :%d",__FUNCTION__,ret);
336 if (type != PLAYER_DISPLAY_TYPE_NONE)
338 handle->display_type = type;
339 LOGI("[%s] video display has been changed- type :%d, addr : 0x%x",
340 __FUNCTION__,handle->display_type, handle->display_handle);
343 LOGI("NULL surface");
346 else //changing surface case
348 ret = mm_player_change_videosink(handle->mm_handle, mmType, set_handle);
349 if (ret != MM_ERROR_NONE)
351 handle->display_handle = temp;
352 if(ret == MM_ERROR_NOT_SUPPORT_API)
354 LOGE("[%s] change video sink is not available.",__FUNCTION__);
355 ret = PLAYER_ERROR_NONE;
359 LOGE("[%s] Failed to display surface change :%d",__FUNCTION__,ret);
364 handle->display_type = type;
365 LOGI("[%s] video display has been changed- type :%d, addr : 0x%x",
366 __FUNCTION__,handle->display_type, handle->display_handle);
370 if(ret != MM_ERROR_NONE)
372 handle->display_type = PLAYER_DISPLAY_TYPE_NONE;
373 return __player_convert_error_code(ret,(char*)__FUNCTION__);
377 return PLAYER_ERROR_NONE;
382 int player_get_raw_video_caps(player_h player, char **caps)
385 PLAYER_INSTANCE_CHECK(player);
386 PLAYER_NULL_ARG_CHECK(caps);
387 player_s * handle = (player_s *) player;
389 if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE)
390 return PLAYER_ERROR_INVALID_STATE;
392 ret = mm_player_get_raw_video_caps(handle->mm_handle, caps);
393 if(ret != MM_ERROR_NONE) {
394 return __player_convert_error_code(ret,(char*)__FUNCTION__);
397 return PLAYER_ERROR_NONE;