4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
7 * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <mm_message.h>
29 #include "mm_player.h"
30 #include "mm_player_priv.h"
31 #include "mm_player_attrs.h"
32 #include "mm_player_utils.h"
33 #include "mm_player_ini.h"
35 #include "mm_player_capture.h"
37 int mm_player_create(MMHandleType *player)
39 int result = MM_ERROR_NONE;
40 mm_player_t* new_player = NULL;
44 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
46 if (!g_thread_supported ())
51 __ta__("mm_player_ini_load",
52 result = mm_player_ini_load();
55 if(result != MM_ERROR_NONE)
56 return MM_ERROR_PLAYER_INTERNAL;
58 /* alloc player structure */
59 new_player = g_malloc(sizeof(mm_player_t));
62 debug_critical("Cannot allocate memory for player\n");
65 memset(new_player, 0, sizeof(mm_player_t));
67 /* create player lock */
68 new_player->cmd_lock = g_mutex_new();
70 if ( ! new_player->cmd_lock )
72 debug_critical("failed to create player lock\n");
77 __ta__("[KPI] create media player service",
78 result = _mmplayer_create_player((MMHandleType)new_player);
81 if(result != MM_ERROR_NONE)
84 *player = (MMHandleType)new_player;
92 _mmplayer_destroy( (MMHandleType)new_player );
93 MMPLAYER_FREEIF( new_player );
96 *player = (MMHandleType)0;
97 return MM_ERROR_PLAYER_NO_FREE_SPACE; // are you sure?
100 int mm_player_destroy(MMHandleType player)
102 int result = MM_ERROR_NONE;
106 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
108 MMPLAYER_CMD_LOCK( player );
110 __ta__("[KPI] destroy media player service",
111 result = _mmplayer_destroy(player);
114 MMPLAYER_CMD_UNLOCK( player );
117 g_free( (void*)player );
119 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
127 int mm_player_realize(MMHandleType player)
129 int result = MM_ERROR_NONE;
133 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
135 MMPLAYER_CMD_LOCK( player );
137 __ta__("[KPI] initialize media player service",
138 result = _mmplayer_realize(player);
141 MMPLAYER_CMD_UNLOCK( player );
147 int mm_player_unrealize(MMHandleType player)
149 int result = MM_ERROR_NONE;
153 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
155 MMPLAYER_CMD_LOCK( player );
157 __ta__("[KPI] cleanup media player service",
158 result = _mmplayer_unrealize(player);
161 MMPLAYER_CMD_UNLOCK( player );
167 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
169 int result = MM_ERROR_NONE;
173 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
175 MMPLAYER_CMD_LOCK( player );
177 result = _mmplayer_set_message_callback(player, callback, user_param);
179 MMPLAYER_CMD_UNLOCK( player );
185 int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
187 int result = MM_ERROR_NONE;
191 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
193 MMPLAYER_CMD_LOCK( player );
195 result = _mmplayer_set_audiostream_cb(player, callback, user_param);
197 MMPLAYER_CMD_UNLOCK( player );
203 int mm_player_set_audio_buffer_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
205 int result = MM_ERROR_NONE;
209 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
211 MMPLAYER_CMD_LOCK( player );
213 result = _mmplayer_set_audiobuffer_cb(player, callback, user_param);
215 MMPLAYER_CMD_UNLOCK( player );
220 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
222 int result = MM_ERROR_NONE;
226 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
228 MMPLAYER_CMD_LOCK( player );
230 result = _mmplayer_set_videostream_cb(player, callback, user_param);
232 MMPLAYER_CMD_UNLOCK( player );
237 int mm_player_do_video_capture(MMHandleType player)
239 int result = MM_ERROR_NONE;
243 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
245 MMPLAYER_CMD_LOCK( player );
247 result = _mmplayer_do_video_capture(player);
249 MMPLAYER_CMD_UNLOCK( player );
254 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
256 int result = MM_ERROR_NONE;
260 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
262 MMPLAYER_CMD_LOCK( player );
264 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
266 MMPLAYER_CMD_UNLOCK( player );
272 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
274 int result = MM_ERROR_NONE;
278 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
280 MMPLAYER_CMD_LOCK( player );
282 result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
284 MMPLAYER_CMD_UNLOCK( player );
290 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
292 int result = MM_ERROR_NONE;
296 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
298 MMPLAYER_CMD_LOCK( player );
300 result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
302 MMPLAYER_CMD_UNLOCK( player );
308 int mm_player_apply_sound_filter(MMHandleType player, MMAudioFilterInfo *info)
310 int result = MM_ERROR_NONE;
314 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
315 return_val_if_fail(info, MM_ERROR_INVALID_ARGUMENT);
317 MMPLAYER_CMD_LOCK( player );
319 result = _mmplayer_apply_sound_filter(player, info);
321 MMPLAYER_CMD_UNLOCK( player );
327 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
329 int result = MM_ERROR_NONE;
333 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
334 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
336 MMPLAYER_CMD_LOCK( player );
338 result = _mmplayer_set_volume(player, *volume);
340 MMPLAYER_CMD_UNLOCK( player );
346 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
348 int result = MM_ERROR_NONE;
352 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
353 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
355 MMPLAYER_CMD_LOCK( player );
357 result = _mmplayer_get_volume(player, volume);
359 MMPLAYER_CMD_UNLOCK( player );
365 int mm_player_set_mute(MMHandleType player, int mute)
367 int result = MM_ERROR_NONE;
371 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
373 MMPLAYER_CMD_LOCK( player );
375 result = _mmplayer_set_mute(player, mute);
377 MMPLAYER_CMD_UNLOCK( player );
383 int mm_player_get_mute(MMHandleType player, int *mute)
385 int result = MM_ERROR_NONE;
389 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
390 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
392 MMPLAYER_CMD_LOCK( player );
394 result = _mmplayer_get_mute(player, mute);
396 MMPLAYER_CMD_UNLOCK( player );
402 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
404 int result = MM_ERROR_NONE;
408 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
409 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
411 *state = MM_PLAYER_STATE_NULL;
413 MMPLAYER_CMD_LOCK( player );
415 result = _mmplayer_get_state(player, (int*)state); /* FIXIT : why int* ? */
417 MMPLAYER_CMD_UNLOCK( player );
423 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
425 int result = MM_ERROR_NONE;
429 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
431 //MMPLAYER_CMD_LOCK( player );
433 //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
434 result = _mmplayer_push_buffer(player, buf, size);
436 //MMPLAYER_CMD_UNLOCK( player );
442 int mm_player_start(MMHandleType player)
444 int result = MM_ERROR_NONE;
448 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
450 MMPLAYER_CMD_LOCK( player );
452 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
453 result = _mmplayer_start(player);
455 MMPLAYER_CMD_UNLOCK( player );
461 int mm_player_stop(MMHandleType player)
463 int result = MM_ERROR_NONE;
467 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
469 MMPLAYER_CMD_LOCK( player );
471 __ta__("[KPI] stop media player service",
472 result = _mmplayer_stop(player);
475 MMPLAYER_CMD_UNLOCK( player );
481 int mm_player_pause(MMHandleType player)
483 int result = MM_ERROR_NONE;
487 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
489 MMPLAYER_CMD_LOCK( player );
491 __ta__("[KPI] pause media player service",
492 result = _mmplayer_pause(player);
495 MMPLAYER_CMD_UNLOCK( player );
501 int mm_player_resume(MMHandleType player)
503 int result = MM_ERROR_NONE;
507 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
509 MMPLAYER_CMD_LOCK( player );
511 __ta__("[KPI] resume media player service",
512 result = _mmplayer_resume(player);
515 MMPLAYER_CMD_UNLOCK( player );
521 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
523 int result = MM_ERROR_NONE;
525 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
527 MMPLAYER_CMD_LOCK( player );
529 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
531 MMPLAYER_CMD_UNLOCK( player );
537 int mm_player_deactivate_section_repeat(MMHandleType player)
539 int result = MM_ERROR_NONE;
541 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
543 MMPLAYER_CMD_LOCK( player );
545 result = _mmplayer_deactivate_section_repeat(player);
547 MMPLAYER_CMD_UNLOCK( player );
553 int mm_player_set_play_speed(MMHandleType player, float rate)
555 int result = MM_ERROR_NONE;
557 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
559 MMPLAYER_CMD_LOCK( player );
561 result = _mmplayer_set_playspeed(player, rate);
563 MMPLAYER_CMD_UNLOCK( player );
569 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
571 int result = MM_ERROR_NONE;
575 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
577 if (format >= MM_PLAYER_POS_FORMAT_NUM)
579 debug_error("wrong format\n");
580 return MM_ERROR_COMMON_INVALID_ARGUMENT;
583 MMPLAYER_CMD_LOCK( player );
585 result = _mmplayer_set_position(player, format, pos);
587 MMPLAYER_CMD_UNLOCK( player );
593 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
595 int result = MM_ERROR_NONE;
599 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
600 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
602 if (format >= MM_PLAYER_POS_FORMAT_NUM)
604 debug_error("wrong format\n");
605 return MM_ERROR_COMMON_INVALID_ARGUMENT;
608 MMPLAYER_CMD_LOCK( player );
610 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
612 MMPLAYER_CMD_UNLOCK( player );
617 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
619 int result = MM_ERROR_NONE;
623 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
624 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
626 MMPLAYER_CMD_LOCK( player );
628 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
630 MMPLAYER_CMD_UNLOCK( player );
635 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
637 int result = MM_ERROR_NONE;
641 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
643 if (format >= MM_PLAYER_POS_FORMAT_NUM)
645 debug_error("wrong format\n");
646 return MM_ERROR_COMMON_INVALID_ARGUMENT;
649 MMPLAYER_CMD_LOCK( player );
651 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
653 MMPLAYER_CMD_UNLOCK( player );
659 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
661 int result = MM_ERROR_NONE;
665 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
667 MMPLAYER_CMD_LOCK( player );
669 result = _mmplayer_set_subtitle_silent(player, silent);
671 MMPLAYER_CMD_UNLOCK( player );
677 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
679 int result = MM_ERROR_NONE;
683 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
685 MMPLAYER_CMD_LOCK( player );
687 result = _mmplayer_get_subtitle_silent(player, silent);
689 MMPLAYER_CMD_UNLOCK( player );
695 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
697 int result = MM_ERROR_NONE;
702 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
703 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
705 MMPLAYER_CMD_LOCK( player );
707 va_start (var_args, first_attribute_name);
708 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
711 MMPLAYER_CMD_UNLOCK( player );
717 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
719 int result = MM_ERROR_NONE;
724 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
725 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
727 MMPLAYER_CMD_LOCK( player );
729 va_start (var_args, first_attribute_name);
730 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
733 MMPLAYER_CMD_UNLOCK( player );
739 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
741 int result = MM_ERROR_NONE;
744 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
745 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
746 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
748 MMPLAYER_CMD_LOCK( player );
750 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
752 MMPLAYER_CMD_UNLOCK( player );