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();
53 if(result != MM_ERROR_NONE)
56 __ta__("mm_player_audio_effect_ini_load",
57 result = mm_player_audio_effect_ini_load();
59 if(result != MM_ERROR_NONE)
62 /* alloc player structure */
63 new_player = g_malloc(sizeof(mm_player_t));
66 debug_critical("Cannot allocate memory for player\n");
69 memset(new_player, 0, sizeof(mm_player_t));
71 /* create player lock */
72 new_player->cmd_lock = g_mutex_new();
74 if ( ! new_player->cmd_lock )
76 debug_critical("failed to create player lock\n");
80 /* create msg callback lock */
81 new_player->msg_cb_lock = g_mutex_new();
83 if ( ! new_player->msg_cb_lock )
85 debug_critical("failed to create msg cb lock\n");
88 __ta__("[KPI] create media player service",
89 result = _mmplayer_create_player((MMHandleType)new_player);
92 if(result != MM_ERROR_NONE)
95 *player = (MMHandleType)new_player;
103 if (new_player->cmd_lock)
105 g_mutex_free(new_player->cmd_lock);
106 new_player->cmd_lock = NULL;
109 _mmplayer_destroy( (MMHandleType)new_player );
110 MMPLAYER_FREEIF( new_player );
113 *player = (MMHandleType)0;
114 return MM_ERROR_PLAYER_NO_FREE_SPACE; // are you sure?
117 int mm_player_destroy(MMHandleType player)
119 int result = MM_ERROR_NONE;
123 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
125 MMPLAYER_CMD_LOCK( player );
127 __ta__("[KPI] destroy media player service",
128 result = _mmplayer_destroy(player);
131 MMPLAYER_CMD_UNLOCK( player );
133 if (((mm_player_t*)player)->cmd_lock)
135 g_mutex_free(((mm_player_t*)player)->cmd_lock);
136 ((mm_player_t*)player)->cmd_lock = NULL;
140 g_free( (void*)player );
142 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
150 int mm_player_realize(MMHandleType player)
152 int result = MM_ERROR_NONE;
156 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
158 MMPLAYER_CMD_LOCK( player );
160 __ta__("[KPI] initialize media player service",
161 result = _mmplayer_realize(player);
164 MMPLAYER_CMD_UNLOCK( player );
170 int mm_player_unrealize(MMHandleType player)
172 int result = MM_ERROR_NONE;
176 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
178 MMPLAYER_CMD_LOCK( player );
180 __ta__("[KPI] cleanup media player service",
181 result = _mmplayer_unrealize(player);
184 MMPLAYER_CMD_UNLOCK( player );
190 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
192 int result = MM_ERROR_NONE;
196 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
198 MMPLAYER_CMD_LOCK( player );
200 result = _mmplayer_set_message_callback(player, callback, user_param);
202 MMPLAYER_CMD_UNLOCK( player );
207 int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
209 int result = MM_ERROR_NONE;
213 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
215 result = _mm_player_set_pd_downloader_message_cb(player, callback, user_param);
220 int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_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_audiostream_cb(player, callback, user_param);
232 MMPLAYER_CMD_UNLOCK( player );
238 int mm_player_set_audio_buffer_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
240 int result = MM_ERROR_NONE;
244 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
246 MMPLAYER_CMD_LOCK( player );
248 result = _mmplayer_set_audiobuffer_cb(player, callback, user_param);
250 MMPLAYER_CMD_UNLOCK( player );
255 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
257 int result = MM_ERROR_NONE;
261 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
263 MMPLAYER_CMD_LOCK( player );
265 result = _mmplayer_set_videostream_cb(player, callback, user_param);
267 MMPLAYER_CMD_UNLOCK( player );
272 int mm_player_do_video_capture(MMHandleType player)
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_do_video_capture(player);
284 MMPLAYER_CMD_UNLOCK( player );
289 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
291 int result = MM_ERROR_NONE;
295 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
297 MMPLAYER_CMD_LOCK( player );
299 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
301 MMPLAYER_CMD_UNLOCK( player );
307 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
309 int result = MM_ERROR_NONE;
313 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
315 MMPLAYER_CMD_LOCK( player );
317 result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
319 MMPLAYER_CMD_UNLOCK( player );
325 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
327 int result = MM_ERROR_NONE;
331 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
333 MMPLAYER_CMD_LOCK( player );
335 result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
337 MMPLAYER_CMD_UNLOCK( player );
343 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
345 int result = MM_ERROR_NONE;
349 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
350 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
352 MMPLAYER_CMD_LOCK( player );
354 result = _mmplayer_set_volume(player, *volume);
356 MMPLAYER_CMD_UNLOCK( player );
362 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
364 int result = MM_ERROR_NONE;
368 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
369 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
371 MMPLAYER_CMD_LOCK( player );
373 result = _mmplayer_get_volume(player, volume);
375 MMPLAYER_CMD_UNLOCK( player );
381 int mm_player_set_mute(MMHandleType player, int mute)
383 int result = MM_ERROR_NONE;
387 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
389 MMPLAYER_CMD_LOCK( player );
391 result = _mmplayer_set_mute(player, mute);
393 MMPLAYER_CMD_UNLOCK( player );
399 int mm_player_get_mute(MMHandleType player, int *mute)
401 int result = MM_ERROR_NONE;
405 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
406 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
408 MMPLAYER_CMD_LOCK( player );
410 result = _mmplayer_get_mute(player, mute);
412 MMPLAYER_CMD_UNLOCK( player );
418 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
420 int result = MM_ERROR_NONE;
424 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
425 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
427 *state = MM_PLAYER_STATE_NULL;
429 MMPLAYER_CMD_LOCK( player );
431 result = _mmplayer_get_state(player, (int*)state); /* FIXIT : why int* ? */
433 MMPLAYER_CMD_UNLOCK( player );
438 /* NOTE : Not supported */
439 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
441 int result = MM_ERROR_NONE;
445 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
447 return MM_ERROR_NOT_SUPPORT_API;
450 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
452 int result = MM_ERROR_NONE;
456 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
458 //MMPLAYER_CMD_LOCK( player );
460 //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
461 result = _mmplayer_push_buffer(player, buf, size);
463 //MMPLAYER_CMD_UNLOCK( player );
469 int mm_player_start(MMHandleType player)
471 int result = MM_ERROR_NONE;
475 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
477 MMPLAYER_CMD_LOCK( player );
479 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
480 result = _mmplayer_start(player);
482 MMPLAYER_CMD_UNLOCK( player );
488 int mm_player_stop(MMHandleType player)
490 int result = MM_ERROR_NONE;
494 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
496 MMPLAYER_CMD_LOCK( player );
498 __ta__("[KPI] stop media player service",
499 result = _mmplayer_stop(player);
502 MMPLAYER_CMD_UNLOCK( player );
508 int mm_player_pause(MMHandleType player)
510 int result = MM_ERROR_NONE;
514 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
516 MMPLAYER_CMD_LOCK( player );
518 __ta__("[KPI] pause media player service",
519 result = _mmplayer_pause(player);
522 MMPLAYER_CMD_UNLOCK( player );
528 int mm_player_resume(MMHandleType player)
530 int result = MM_ERROR_NONE;
534 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
536 MMPLAYER_CMD_LOCK( player );
538 __ta__("[KPI] resume media player service",
539 result = _mmplayer_resume(player);
542 MMPLAYER_CMD_UNLOCK( player );
548 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
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_activate_section_repeat(player, start_pos, end_pos);
558 MMPLAYER_CMD_UNLOCK( player );
564 int mm_player_deactivate_section_repeat(MMHandleType player)
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_deactivate_section_repeat(player);
574 MMPLAYER_CMD_UNLOCK( player );
580 int mm_player_set_play_speed(MMHandleType player, float rate)
582 int result = MM_ERROR_NONE;
584 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
586 MMPLAYER_CMD_LOCK( player );
588 result = _mmplayer_set_playspeed(player, rate);
590 MMPLAYER_CMD_UNLOCK( player );
596 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
598 int result = MM_ERROR_NONE;
602 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
604 if (format >= MM_PLAYER_POS_FORMAT_NUM)
606 debug_error("wrong format\n");
607 return MM_ERROR_COMMON_INVALID_ARGUMENT;
610 MMPLAYER_CMD_LOCK( player );
612 result = _mmplayer_set_position(player, format, pos);
614 MMPLAYER_CMD_UNLOCK( player );
620 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
622 int result = MM_ERROR_NONE;
626 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
627 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
629 if (format >= MM_PLAYER_POS_FORMAT_NUM)
631 debug_error("wrong format\n");
632 return MM_ERROR_COMMON_INVALID_ARGUMENT;
635 MMPLAYER_CMD_LOCK( player );
637 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
639 MMPLAYER_CMD_UNLOCK( player );
644 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
646 int result = MM_ERROR_NONE;
650 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
651 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
653 MMPLAYER_CMD_LOCK( player );
655 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
657 MMPLAYER_CMD_UNLOCK( player );
662 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
664 int result = MM_ERROR_NONE;
668 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
670 if (format >= MM_PLAYER_POS_FORMAT_NUM)
672 debug_error("wrong format\n");
673 return MM_ERROR_COMMON_INVALID_ARGUMENT;
676 MMPLAYER_CMD_LOCK( player );
678 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
680 MMPLAYER_CMD_UNLOCK( player );
686 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
688 int result = MM_ERROR_NONE;
692 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
694 MMPLAYER_CMD_LOCK( player );
696 result = _mmplayer_set_subtitle_silent(player, silent);
698 MMPLAYER_CMD_UNLOCK( player );
704 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
706 int result = MM_ERROR_NONE;
710 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
712 MMPLAYER_CMD_LOCK( player );
714 result = _mmplayer_get_subtitle_silent(player, silent);
716 MMPLAYER_CMD_UNLOCK( player );
722 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
724 int result = MM_ERROR_NONE;
729 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
730 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
732 va_start (var_args, first_attribute_name);
733 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
740 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
742 int result = MM_ERROR_NONE;
747 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
748 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
750 va_start (var_args, first_attribute_name);
751 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
758 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
760 int result = MM_ERROR_NONE;
763 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
764 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
765 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
767 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
772 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
774 int result = MM_ERROR_NONE;
778 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
779 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
780 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
782 result = _mmplayer_get_pd_downloader_status(player, current_pos, total_size);
787 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType track_type, int *count)
789 int result = MM_ERROR_NONE;
793 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
794 return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
796 result = _mmplayer_get_track_count(player, track_type, count);