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);
47 __ta__("mm_player_ini_load",
48 result = mm_player_ini_load();
50 if(result != MM_ERROR_NONE)
53 __ta__("mm_player_audio_effect_ini_load",
54 result = mm_player_audio_effect_ini_load();
56 if(result != MM_ERROR_NONE)
59 /* alloc player structure */
60 new_player = g_malloc(sizeof(mm_player_t));
63 debug_critical("Cannot allocate memory for player\n");
66 memset(new_player, 0, sizeof(mm_player_t));
68 /* create player lock */
69 new_player->cmd_lock = g_mutex_new();
71 if ( ! new_player->cmd_lock )
73 debug_critical("failed to create player lock\n");
77 /* create msg callback lock */
78 new_player->msg_cb_lock = g_mutex_new();
80 if ( ! new_player->msg_cb_lock )
82 debug_critical("failed to create msg cb lock\n");
85 __ta__("[KPI] create media player service",
86 result = _mmplayer_create_player((MMHandleType)new_player);
89 if(result != MM_ERROR_NONE)
92 *player = (MMHandleType)new_player;
100 if (new_player->cmd_lock)
102 g_mutex_free(new_player->cmd_lock);
103 new_player->cmd_lock = NULL;
106 _mmplayer_destroy( (MMHandleType)new_player );
107 MMPLAYER_FREEIF( new_player );
110 *player = (MMHandleType)0;
111 return MM_ERROR_PLAYER_NO_FREE_SPACE; // are you sure?
114 int mm_player_destroy(MMHandleType player)
116 int result = MM_ERROR_NONE;
120 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
122 MMPLAYER_CMD_LOCK( player );
124 __ta__("[KPI] destroy media player service",
125 result = _mmplayer_destroy(player);
128 MMPLAYER_CMD_UNLOCK( player );
130 if (((mm_player_t*)player)->cmd_lock)
132 g_mutex_free(((mm_player_t*)player)->cmd_lock);
133 ((mm_player_t*)player)->cmd_lock = NULL;
136 memset( (mm_player_t*)player, 0x00, sizeof(mm_player_t) );
139 g_free( (void*)player );
141 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
148 int mm_player_realize(MMHandleType player)
150 int result = MM_ERROR_NONE;
154 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
156 MMPLAYER_CMD_LOCK( player );
158 __ta__("[KPI] initialize media player service",
159 result = _mmplayer_realize(player);
162 MMPLAYER_CMD_UNLOCK( player );
167 int mm_player_unrealize(MMHandleType player)
169 int result = MM_ERROR_NONE;
173 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
175 MMPLAYER_CMD_LOCK( player );
177 __ta__("[KPI] cleanup media player service",
178 result = _mmplayer_unrealize(player);
181 MMPLAYER_CMD_UNLOCK( player );
186 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
188 int result = MM_ERROR_NONE;
192 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
194 MMPLAYER_CMD_LOCK( player );
196 result = _mmplayer_set_message_callback(player, callback, user_param);
198 MMPLAYER_CMD_UNLOCK( player );
203 int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
205 int result = MM_ERROR_NONE;
209 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
211 result = _mm_player_set_pd_downloader_message_cb(player, callback, user_param);
216 int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
218 int result = MM_ERROR_NONE;
222 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
224 MMPLAYER_CMD_LOCK( player );
226 result = _mmplayer_set_audiostream_cb(player, callback, user_param);
228 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_set_video_frame_render_error_callback(MMHandleType player, mm_player_video_frame_render_error_callback callback, void *user_param)
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_set_videoframe_render_error_cb(player, callback, user_param);
279 MMPLAYER_CMD_UNLOCK( player );
284 int mm_player_do_video_capture(MMHandleType player)
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_do_video_capture(player);
296 MMPLAYER_CMD_UNLOCK( player );
301 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
303 int result = MM_ERROR_NONE;
307 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
309 MMPLAYER_CMD_LOCK( player );
311 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
313 MMPLAYER_CMD_UNLOCK( player );
318 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
320 int result = MM_ERROR_NONE;
324 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
326 MMPLAYER_CMD_LOCK( player );
328 result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
330 MMPLAYER_CMD_UNLOCK( player );
336 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
338 int result = MM_ERROR_NONE;
342 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
344 MMPLAYER_CMD_LOCK( player );
346 result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
348 MMPLAYER_CMD_UNLOCK( player );
353 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
355 int result = MM_ERROR_NONE;
359 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
360 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
362 MMPLAYER_CMD_LOCK( player );
364 result = _mmplayer_set_volume(player, *volume);
366 MMPLAYER_CMD_UNLOCK( player );
371 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
373 int result = MM_ERROR_NONE;
377 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
378 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
380 MMPLAYER_CMD_LOCK( player );
382 result = _mmplayer_get_volume(player, volume);
384 MMPLAYER_CMD_UNLOCK( player );
389 int mm_player_set_mute(MMHandleType player, int mute)
391 int result = MM_ERROR_NONE;
395 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
397 MMPLAYER_CMD_LOCK( player );
399 result = _mmplayer_set_mute(player, mute);
401 MMPLAYER_CMD_UNLOCK( player );
406 int mm_player_get_mute(MMHandleType player, int *mute)
408 int result = MM_ERROR_NONE;
412 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
413 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
415 MMPLAYER_CMD_LOCK( player );
417 result = _mmplayer_get_mute(player, mute);
419 MMPLAYER_CMD_UNLOCK( player );
424 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
426 int result = MM_ERROR_NONE;
430 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
431 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
433 *state = MM_PLAYER_STATE_NULL;
435 result = _mmplayer_get_state(player, (int*)state);
440 /* NOTE : Not supported */
441 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
443 int result = MM_ERROR_NONE;
447 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
449 return MM_ERROR_NOT_SUPPORT_API;
452 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
454 int result = MM_ERROR_NONE;
458 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
460 //MMPLAYER_CMD_LOCK( player );
462 //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
463 result = _mmplayer_push_buffer(player, buf, size);
465 //MMPLAYER_CMD_UNLOCK( player );
470 int mm_player_start(MMHandleType player)
472 int result = MM_ERROR_NONE;
476 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
478 MMPLAYER_CMD_LOCK( player );
480 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
481 result = _mmplayer_start(player);
483 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 );
507 int mm_player_pause(MMHandleType player)
509 int result = MM_ERROR_NONE;
513 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
515 MMPLAYER_CMD_LOCK( player );
517 __ta__("[KPI] pause media player service",
518 result = _mmplayer_pause(player);
521 MMPLAYER_CMD_UNLOCK( player );
526 int mm_player_resume(MMHandleType player)
528 int result = MM_ERROR_NONE;
532 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
534 MMPLAYER_CMD_LOCK( player );
536 __ta__("[KPI] resume media player service",
537 result = _mmplayer_resume(player);
540 MMPLAYER_CMD_UNLOCK( player );
545 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
547 int result = MM_ERROR_NONE;
549 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
551 MMPLAYER_CMD_LOCK( player );
553 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
555 MMPLAYER_CMD_UNLOCK( player );
560 int mm_player_deactivate_section_repeat(MMHandleType player)
562 int result = MM_ERROR_NONE;
564 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
566 MMPLAYER_CMD_LOCK( player );
568 result = _mmplayer_deactivate_section_repeat(player);
570 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 );
590 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
592 int result = MM_ERROR_NONE;
596 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
598 if (format >= MM_PLAYER_POS_FORMAT_NUM)
600 debug_error("wrong format\n");
601 return MM_ERROR_COMMON_INVALID_ARGUMENT;
604 MMPLAYER_CMD_LOCK( player );
606 result = _mmplayer_set_position(player, format, pos);
608 MMPLAYER_CMD_UNLOCK( player );
613 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
615 int result = MM_ERROR_NONE;
619 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
620 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
622 if (format >= MM_PLAYER_POS_FORMAT_NUM)
624 debug_error("wrong format\n");
625 return MM_ERROR_COMMON_INVALID_ARGUMENT;
628 MMPLAYER_CMD_LOCK( player );
630 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
632 MMPLAYER_CMD_UNLOCK( player );
637 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
639 int result = MM_ERROR_NONE;
643 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
644 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
646 MMPLAYER_CMD_LOCK( player );
648 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
650 MMPLAYER_CMD_UNLOCK( player );
655 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
657 int result = MM_ERROR_NONE;
661 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
663 if (format >= MM_PLAYER_POS_FORMAT_NUM)
665 debug_error("wrong format\n");
666 return MM_ERROR_COMMON_INVALID_ARGUMENT;
669 MMPLAYER_CMD_LOCK( player );
671 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
673 MMPLAYER_CMD_UNLOCK( player );
678 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
680 int result = MM_ERROR_NONE;
684 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
686 MMPLAYER_CMD_LOCK( player );
688 result = _mmplayer_set_subtitle_silent(player, silent);
690 MMPLAYER_CMD_UNLOCK( player );
695 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
697 int result = MM_ERROR_NONE;
701 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
703 MMPLAYER_CMD_LOCK( player );
705 result = _mmplayer_get_subtitle_silent(player, silent);
707 MMPLAYER_CMD_UNLOCK( player );
712 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
714 int result = MM_ERROR_NONE;
719 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
720 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
722 va_start (var_args, first_attribute_name);
723 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
729 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
731 int result = MM_ERROR_NONE;
736 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
737 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
739 va_start (var_args, first_attribute_name);
740 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
746 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
748 int result = MM_ERROR_NONE;
751 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
752 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
753 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
755 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
760 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
762 int result = MM_ERROR_NONE;
766 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
767 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
768 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
770 result = _mmplayer_get_pd_downloader_status(player, current_pos, total_size);
775 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType track_type, int *count)
777 int result = MM_ERROR_NONE;
781 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
782 return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
784 result = _mmplayer_get_track_count(player, track_type, count);
790 int mm_player_ignore_session(MMHandleType player)
792 int result = MM_ERROR_NONE;
796 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
798 result = _mmplayer_asm_ignore_session(player);