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_downloader_message_cb(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 );
433 /* NOTE : Not supported */
434 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
436 int result = MM_ERROR_NONE;
440 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
442 return MM_ERROR_NOT_SUPPORT_API;
445 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
447 int result = MM_ERROR_NONE;
451 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
453 //MMPLAYER_CMD_LOCK( player );
455 //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
456 result = _mmplayer_push_buffer(player, buf, size);
458 //MMPLAYER_CMD_UNLOCK( player );
464 int mm_player_start(MMHandleType player)
466 int result = MM_ERROR_NONE;
470 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
472 MMPLAYER_CMD_LOCK( player );
474 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
475 result = _mmplayer_start(player);
477 MMPLAYER_CMD_UNLOCK( player );
483 int mm_player_stop(MMHandleType player)
485 int result = MM_ERROR_NONE;
489 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
491 MMPLAYER_CMD_LOCK( player );
493 __ta__("[KPI] stop media player service",
494 result = _mmplayer_stop(player);
497 MMPLAYER_CMD_UNLOCK( player );
503 int mm_player_pause(MMHandleType player)
505 int result = MM_ERROR_NONE;
509 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
511 MMPLAYER_CMD_LOCK( player );
513 __ta__("[KPI] pause media player service",
514 result = _mmplayer_pause(player);
517 MMPLAYER_CMD_UNLOCK( player );
523 int mm_player_resume(MMHandleType player)
525 int result = MM_ERROR_NONE;
529 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
531 MMPLAYER_CMD_LOCK( player );
533 __ta__("[KPI] resume media player service",
534 result = _mmplayer_resume(player);
537 MMPLAYER_CMD_UNLOCK( player );
543 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
545 int result = MM_ERROR_NONE;
547 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
549 MMPLAYER_CMD_LOCK( player );
551 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
553 MMPLAYER_CMD_UNLOCK( player );
559 int mm_player_deactivate_section_repeat(MMHandleType player)
561 int result = MM_ERROR_NONE;
563 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
565 MMPLAYER_CMD_LOCK( player );
567 result = _mmplayer_deactivate_section_repeat(player);
569 MMPLAYER_CMD_UNLOCK( player );
575 int mm_player_set_play_speed(MMHandleType player, float rate)
577 int result = MM_ERROR_NONE;
579 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
581 MMPLAYER_CMD_LOCK( player );
583 result = _mmplayer_set_playspeed(player, rate);
585 MMPLAYER_CMD_UNLOCK( player );
591 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
593 int result = MM_ERROR_NONE;
597 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
599 if (format >= MM_PLAYER_POS_FORMAT_NUM)
601 debug_error("wrong format\n");
602 return MM_ERROR_COMMON_INVALID_ARGUMENT;
605 MMPLAYER_CMD_LOCK( player );
607 result = _mmplayer_set_position(player, format, pos);
609 MMPLAYER_CMD_UNLOCK( player );
615 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
617 int result = MM_ERROR_NONE;
621 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
622 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
624 if (format >= MM_PLAYER_POS_FORMAT_NUM)
626 debug_error("wrong format\n");
627 return MM_ERROR_COMMON_INVALID_ARGUMENT;
630 MMPLAYER_CMD_LOCK( player );
632 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
634 MMPLAYER_CMD_UNLOCK( player );
639 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
641 int result = MM_ERROR_NONE;
645 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
646 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
648 MMPLAYER_CMD_LOCK( player );
650 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
652 MMPLAYER_CMD_UNLOCK( player );
657 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
659 int result = MM_ERROR_NONE;
663 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
665 if (format >= MM_PLAYER_POS_FORMAT_NUM)
667 debug_error("wrong format\n");
668 return MM_ERROR_COMMON_INVALID_ARGUMENT;
671 MMPLAYER_CMD_LOCK( player );
673 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
675 MMPLAYER_CMD_UNLOCK( player );
681 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
683 int result = MM_ERROR_NONE;
687 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
689 MMPLAYER_CMD_LOCK( player );
691 result = _mmplayer_set_subtitle_silent(player, silent);
693 MMPLAYER_CMD_UNLOCK( player );
699 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
701 int result = MM_ERROR_NONE;
705 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
707 MMPLAYER_CMD_LOCK( player );
709 result = _mmplayer_get_subtitle_silent(player, silent);
711 MMPLAYER_CMD_UNLOCK( player );
717 int mm_player_set_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 va_start (var_args, first_attribute_name);
728 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
735 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
737 int result = MM_ERROR_NONE;
742 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
743 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
745 va_start (var_args, first_attribute_name);
746 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
753 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
755 int result = MM_ERROR_NONE;
758 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
759 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
760 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
762 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
767 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
769 int result = MM_ERROR_NONE;
773 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
774 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
775 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
777 result = _mmplayer_get_pd_downloader_status(player, current_pos, total_size);
782 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType track_type, int *count)
784 int result = MM_ERROR_NONE;
788 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
789 return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
791 result = _mmplayer_get_track_count(player, track_type, count);