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>, YoungHwan An <younghwan_.an@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include <mm_message.h>
28 #include "mm_player.h"
29 #include "mm_player_priv.h"
30 #include "mm_player_attrs.h"
31 #include "mm_player_utils.h"
32 #include "mm_player_ini.h"
34 #include "mm_player_capture.h"
36 int mm_player_create(MMHandleType *player)
38 int result = MM_ERROR_NONE;
39 mm_player_t* new_player = NULL;
43 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
45 if (!g_thread_supported ())
50 __ta__("mm_player_ini_load",
51 result = mm_player_ini_load();
54 if(result != MM_ERROR_NONE)
55 return MM_ERROR_PLAYER_INTERNAL;
57 /* alloc player structure */
58 new_player = g_malloc(sizeof(mm_player_t));
61 debug_critical("Cannot allocate memory for player\n");
64 memset(new_player, 0, sizeof(mm_player_t));
66 /* create player lock */
67 new_player->cmd_lock = g_mutex_new();
69 if ( ! new_player->cmd_lock )
71 debug_critical("failed to create player lock\n");
75 /* create msg callback lock */
76 new_player->msg_cb_lock = g_mutex_new();
78 if ( ! new_player->msg_cb_lock )
80 debug_critical("failed to create msg cb lock\n");
83 __ta__("[KPI] create media player service",
84 result = _mmplayer_create_player((MMHandleType)new_player);
87 if(result != MM_ERROR_NONE)
90 *player = (MMHandleType)new_player;
98 if (new_player->cmd_lock)
100 g_mutex_free(new_player->cmd_lock);
101 new_player->cmd_lock = NULL;
104 _mmplayer_destroy( (MMHandleType)new_player );
105 MMPLAYER_FREEIF( new_player );
108 *player = (MMHandleType)0;
109 return MM_ERROR_PLAYER_NO_FREE_SPACE; // are you sure?
112 int mm_player_destroy(MMHandleType player)
114 int result = MM_ERROR_NONE;
118 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
120 MMPLAYER_CMD_LOCK( player );
122 __ta__("[KPI] destroy media player service",
123 result = _mmplayer_destroy(player);
126 MMPLAYER_CMD_UNLOCK( player );
128 if (((mm_player_t*)player)->cmd_lock)
130 g_mutex_free(((mm_player_t*)player)->cmd_lock);
131 ((mm_player_t*)player)->cmd_lock = NULL;
135 g_free( (void*)player );
137 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
145 int mm_player_realize(MMHandleType player)
147 int result = MM_ERROR_NONE;
151 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
153 MMPLAYER_CMD_LOCK( player );
155 __ta__("[KPI] initialize media player service",
156 result = _mmplayer_realize(player);
159 MMPLAYER_CMD_UNLOCK( player );
165 int mm_player_unrealize(MMHandleType player)
167 int result = MM_ERROR_NONE;
171 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
173 MMPLAYER_CMD_LOCK( player );
175 __ta__("[KPI] cleanup media player service",
176 result = _mmplayer_unrealize(player);
179 MMPLAYER_CMD_UNLOCK( player );
185 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback 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_message_callback(player, callback, user_param);
197 MMPLAYER_CMD_UNLOCK( player );
202 int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
204 int result = MM_ERROR_NONE;
208 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
210 result = _mm_player_set_pd_message_callback(player, callback, user_param);
215 int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
217 int result = MM_ERROR_NONE;
221 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
223 MMPLAYER_CMD_LOCK( player );
225 result = _mmplayer_set_audiostream_cb(player, callback, user_param);
227 MMPLAYER_CMD_UNLOCK( player );
233 int mm_player_set_audio_buffer_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
235 int result = MM_ERROR_NONE;
239 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
241 MMPLAYER_CMD_LOCK( player );
243 result = _mmplayer_set_audiobuffer_cb(player, callback, user_param);
245 MMPLAYER_CMD_UNLOCK( player );
250 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
252 int result = MM_ERROR_NONE;
256 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
258 MMPLAYER_CMD_LOCK( player );
260 result = _mmplayer_set_videostream_cb(player, callback, user_param);
262 MMPLAYER_CMD_UNLOCK( player );
267 int mm_player_do_video_capture(MMHandleType player)
269 int result = MM_ERROR_NONE;
273 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
275 MMPLAYER_CMD_LOCK( player );
277 result = _mmplayer_do_video_capture(player);
279 MMPLAYER_CMD_UNLOCK( player );
284 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
286 int result = MM_ERROR_NONE;
290 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
292 MMPLAYER_CMD_LOCK( player );
294 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
296 MMPLAYER_CMD_UNLOCK( player );
302 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
304 int result = MM_ERROR_NONE;
308 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
310 MMPLAYER_CMD_LOCK( player );
312 result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
314 MMPLAYER_CMD_UNLOCK( player );
320 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
322 int result = MM_ERROR_NONE;
326 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
328 MMPLAYER_CMD_LOCK( player );
330 result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
332 MMPLAYER_CMD_UNLOCK( player );
338 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
340 int result = MM_ERROR_NONE;
344 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
345 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
347 MMPLAYER_CMD_LOCK( player );
349 result = _mmplayer_set_volume(player, *volume);
351 MMPLAYER_CMD_UNLOCK( player );
357 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
359 int result = MM_ERROR_NONE;
363 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
364 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
366 MMPLAYER_CMD_LOCK( player );
368 result = _mmplayer_get_volume(player, volume);
370 MMPLAYER_CMD_UNLOCK( player );
376 int mm_player_set_mute(MMHandleType player, int mute)
378 int result = MM_ERROR_NONE;
382 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
384 MMPLAYER_CMD_LOCK( player );
386 result = _mmplayer_set_mute(player, mute);
388 MMPLAYER_CMD_UNLOCK( player );
394 int mm_player_get_mute(MMHandleType player, int *mute)
396 int result = MM_ERROR_NONE;
400 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
401 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
403 MMPLAYER_CMD_LOCK( player );
405 result = _mmplayer_get_mute(player, mute);
407 MMPLAYER_CMD_UNLOCK( player );
413 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
415 int result = MM_ERROR_NONE;
419 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
420 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
422 *state = MM_PLAYER_STATE_NULL;
424 MMPLAYER_CMD_LOCK( player );
426 result = _mmplayer_get_state(player, (int*)state); /* FIXIT : why int* ? */
428 MMPLAYER_CMD_UNLOCK( player );
434 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
436 int result = MM_ERROR_NONE;
440 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
442 //MMPLAYER_CMD_LOCK( player );
444 //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
445 result = _mmplayer_push_buffer(player, buf, size);
447 //MMPLAYER_CMD_UNLOCK( player );
453 int mm_player_start(MMHandleType player)
455 int result = MM_ERROR_NONE;
459 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
461 MMPLAYER_CMD_LOCK( player );
463 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
464 result = _mmplayer_start(player);
466 MMPLAYER_CMD_UNLOCK( player );
472 int mm_player_stop(MMHandleType player)
474 int result = MM_ERROR_NONE;
478 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
480 MMPLAYER_CMD_LOCK( player );
482 __ta__("[KPI] stop media player service",
483 result = _mmplayer_stop(player);
486 MMPLAYER_CMD_UNLOCK( player );
492 int mm_player_pause(MMHandleType player)
494 int result = MM_ERROR_NONE;
498 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
500 MMPLAYER_CMD_LOCK( player );
502 __ta__("[KPI] pause media player service",
503 result = _mmplayer_pause(player);
506 MMPLAYER_CMD_UNLOCK( player );
512 int mm_player_resume(MMHandleType player)
514 int result = MM_ERROR_NONE;
518 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
520 MMPLAYER_CMD_LOCK( player );
522 __ta__("[KPI] resume media player service",
523 result = _mmplayer_resume(player);
526 MMPLAYER_CMD_UNLOCK( player );
532 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
534 int result = MM_ERROR_NONE;
536 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
538 MMPLAYER_CMD_LOCK( player );
540 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
542 MMPLAYER_CMD_UNLOCK( player );
548 int mm_player_deactivate_section_repeat(MMHandleType player)
550 int result = MM_ERROR_NONE;
552 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
554 MMPLAYER_CMD_LOCK( player );
556 result = _mmplayer_deactivate_section_repeat(player);
558 MMPLAYER_CMD_UNLOCK( player );
564 int mm_player_set_play_speed(MMHandleType player, float rate)
566 int result = MM_ERROR_NONE;
568 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
570 MMPLAYER_CMD_LOCK( player );
572 result = _mmplayer_set_playspeed(player, rate);
574 MMPLAYER_CMD_UNLOCK( player );
580 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
582 int result = MM_ERROR_NONE;
586 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
588 if (format >= MM_PLAYER_POS_FORMAT_NUM)
590 debug_error("wrong format\n");
591 return MM_ERROR_COMMON_INVALID_ARGUMENT;
594 MMPLAYER_CMD_LOCK( player );
596 result = _mmplayer_set_position(player, format, pos);
598 MMPLAYER_CMD_UNLOCK( player );
604 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
606 int result = MM_ERROR_NONE;
610 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
611 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
613 if (format >= MM_PLAYER_POS_FORMAT_NUM)
615 debug_error("wrong format\n");
616 return MM_ERROR_COMMON_INVALID_ARGUMENT;
619 MMPLAYER_CMD_LOCK( player );
621 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
623 MMPLAYER_CMD_UNLOCK( player );
628 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
630 int result = MM_ERROR_NONE;
634 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
635 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
637 MMPLAYER_CMD_LOCK( player );
639 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
641 MMPLAYER_CMD_UNLOCK( player );
646 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
648 int result = MM_ERROR_NONE;
652 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
654 if (format >= MM_PLAYER_POS_FORMAT_NUM)
656 debug_error("wrong format\n");
657 return MM_ERROR_COMMON_INVALID_ARGUMENT;
660 MMPLAYER_CMD_LOCK( player );
662 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
664 MMPLAYER_CMD_UNLOCK( player );
670 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
672 int result = MM_ERROR_NONE;
676 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
678 MMPLAYER_CMD_LOCK( player );
680 result = _mmplayer_set_subtitle_silent(player, silent);
682 MMPLAYER_CMD_UNLOCK( player );
688 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
690 int result = MM_ERROR_NONE;
694 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
696 MMPLAYER_CMD_LOCK( player );
698 result = _mmplayer_get_subtitle_silent(player, silent);
700 MMPLAYER_CMD_UNLOCK( player );
706 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
708 int result = MM_ERROR_NONE;
713 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
714 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
716 va_start (var_args, first_attribute_name);
717 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
724 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
726 int result = MM_ERROR_NONE;
731 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
732 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
734 va_start (var_args, first_attribute_name);
735 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
742 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
744 int result = MM_ERROR_NONE;
747 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
748 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
749 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
751 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
756 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
758 int result = MM_ERROR_NONE;
762 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
763 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
764 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
766 result = _mmplayer_pd_get_status(player, current_pos, total_size);
771 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType track_type, int *count)
773 int result = MM_ERROR_NONE;
777 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
778 return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
780 result = _mmplayer_get_track_count(player, track_type, count);