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;
139 memset( (mm_player_t*)player, 0x00, sizeof(mm_player_t) );
142 g_free( (void*)player );
144 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
152 int mm_player_realize(MMHandleType player)
154 int result = MM_ERROR_NONE;
158 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
160 MMPLAYER_CMD_LOCK( player );
162 __ta__("[KPI] initialize media player service",
163 result = _mmplayer_realize(player);
166 MMPLAYER_CMD_UNLOCK( player );
172 int mm_player_unrealize(MMHandleType player)
174 int result = MM_ERROR_NONE;
178 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
180 MMPLAYER_CMD_LOCK( player );
182 __ta__("[KPI] cleanup media player service",
183 result = _mmplayer_unrealize(player);
186 MMPLAYER_CMD_UNLOCK( player );
192 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
194 int result = MM_ERROR_NONE;
198 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
200 MMPLAYER_CMD_LOCK( player );
202 result = _mmplayer_set_message_callback(player, callback, user_param);
204 MMPLAYER_CMD_UNLOCK( player );
209 int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
211 int result = MM_ERROR_NONE;
215 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
217 result = _mm_player_set_pd_downloader_message_cb(player, callback, user_param);
222 int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
224 int result = MM_ERROR_NONE;
228 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
230 MMPLAYER_CMD_LOCK( player );
232 result = _mmplayer_set_audiostream_cb(player, callback, user_param);
234 MMPLAYER_CMD_UNLOCK( player );
240 int mm_player_set_audio_buffer_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
242 int result = MM_ERROR_NONE;
246 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
248 MMPLAYER_CMD_LOCK( player );
250 result = _mmplayer_set_audiobuffer_cb(player, callback, user_param);
252 MMPLAYER_CMD_UNLOCK( player );
257 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
259 int result = MM_ERROR_NONE;
263 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
265 MMPLAYER_CMD_LOCK( player );
267 result = _mmplayer_set_videostream_cb(player, callback, user_param);
269 MMPLAYER_CMD_UNLOCK( player );
274 int mm_player_set_video_frame_render_error_callback(MMHandleType player, mm_player_video_frame_render_error_callback callback, void *user_param)
276 int result = MM_ERROR_NONE;
280 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
282 MMPLAYER_CMD_LOCK( player );
284 result = _mmplayer_set_videoframe_render_error_cb(player, callback, user_param);
286 MMPLAYER_CMD_UNLOCK( player );
291 int mm_player_do_video_capture(MMHandleType player)
293 int result = MM_ERROR_NONE;
297 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
299 MMPLAYER_CMD_LOCK( player );
301 result = _mmplayer_do_video_capture(player);
303 MMPLAYER_CMD_UNLOCK( player );
308 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
310 int result = MM_ERROR_NONE;
314 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
316 MMPLAYER_CMD_LOCK( player );
318 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
320 MMPLAYER_CMD_UNLOCK( player );
326 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
328 int result = MM_ERROR_NONE;
332 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
334 MMPLAYER_CMD_LOCK( player );
336 result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
338 MMPLAYER_CMD_UNLOCK( player );
344 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
346 int result = MM_ERROR_NONE;
350 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
352 MMPLAYER_CMD_LOCK( player );
354 result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
356 MMPLAYER_CMD_UNLOCK( player );
362 int mm_player_set_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_set_volume(player, *volume);
375 MMPLAYER_CMD_UNLOCK( player );
381 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
383 int result = MM_ERROR_NONE;
387 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
388 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
390 MMPLAYER_CMD_LOCK( player );
392 result = _mmplayer_get_volume(player, volume);
394 MMPLAYER_CMD_UNLOCK( player );
400 int mm_player_set_mute(MMHandleType player, int mute)
402 int result = MM_ERROR_NONE;
406 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
408 MMPLAYER_CMD_LOCK( player );
410 result = _mmplayer_set_mute(player, mute);
412 MMPLAYER_CMD_UNLOCK( player );
418 int mm_player_get_mute(MMHandleType player, int *mute)
420 int result = MM_ERROR_NONE;
424 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
425 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
427 MMPLAYER_CMD_LOCK( player );
429 result = _mmplayer_get_mute(player, mute);
431 MMPLAYER_CMD_UNLOCK( player );
437 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
439 int result = MM_ERROR_NONE;
443 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
444 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
446 *state = MM_PLAYER_STATE_NULL;
448 result = _mmplayer_get_state(player, (int*)state);
453 /* NOTE : Not supported */
454 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
456 int result = MM_ERROR_NONE;
460 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
462 return MM_ERROR_NOT_SUPPORT_API;
465 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
467 int result = MM_ERROR_NONE;
471 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
473 //MMPLAYER_CMD_LOCK( player );
475 //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
476 result = _mmplayer_push_buffer(player, buf, size);
478 //MMPLAYER_CMD_UNLOCK( player );
484 int mm_player_start(MMHandleType player)
486 int result = MM_ERROR_NONE;
490 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
492 MMPLAYER_CMD_LOCK( player );
494 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
495 result = _mmplayer_start(player);
497 MMPLAYER_CMD_UNLOCK( player );
503 int mm_player_stop(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] stop media player service",
514 result = _mmplayer_stop(player);
517 MMPLAYER_CMD_UNLOCK( player );
523 int mm_player_pause(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] pause media player service",
534 result = _mmplayer_pause(player);
537 MMPLAYER_CMD_UNLOCK( player );
543 int mm_player_resume(MMHandleType player)
545 int result = MM_ERROR_NONE;
549 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
551 MMPLAYER_CMD_LOCK( player );
553 __ta__("[KPI] resume media player service",
554 result = _mmplayer_resume(player);
557 MMPLAYER_CMD_UNLOCK( player );
563 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
565 int result = MM_ERROR_NONE;
567 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
569 MMPLAYER_CMD_LOCK( player );
571 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
573 MMPLAYER_CMD_UNLOCK( player );
579 int mm_player_deactivate_section_repeat(MMHandleType player)
581 int result = MM_ERROR_NONE;
583 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
585 MMPLAYER_CMD_LOCK( player );
587 result = _mmplayer_deactivate_section_repeat(player);
589 MMPLAYER_CMD_UNLOCK( player );
595 int mm_player_set_play_speed(MMHandleType player, float rate)
597 int result = MM_ERROR_NONE;
599 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
601 MMPLAYER_CMD_LOCK( player );
603 result = _mmplayer_set_playspeed(player, rate);
605 MMPLAYER_CMD_UNLOCK( player );
611 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
613 int result = MM_ERROR_NONE;
617 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
619 if (format >= MM_PLAYER_POS_FORMAT_NUM)
621 debug_error("wrong format\n");
622 return MM_ERROR_COMMON_INVALID_ARGUMENT;
625 MMPLAYER_CMD_LOCK( player );
627 result = _mmplayer_set_position(player, format, pos);
629 MMPLAYER_CMD_UNLOCK( player );
635 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
637 int result = MM_ERROR_NONE;
641 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
642 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
644 if (format >= MM_PLAYER_POS_FORMAT_NUM)
646 debug_error("wrong format\n");
647 return MM_ERROR_COMMON_INVALID_ARGUMENT;
650 MMPLAYER_CMD_LOCK( player );
652 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
654 MMPLAYER_CMD_UNLOCK( player );
659 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
661 int result = MM_ERROR_NONE;
665 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
666 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
668 MMPLAYER_CMD_LOCK( player );
670 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
672 MMPLAYER_CMD_UNLOCK( player );
677 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
679 int result = MM_ERROR_NONE;
683 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
685 if (format >= MM_PLAYER_POS_FORMAT_NUM)
687 debug_error("wrong format\n");
688 return MM_ERROR_COMMON_INVALID_ARGUMENT;
691 MMPLAYER_CMD_LOCK( player );
693 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
695 MMPLAYER_CMD_UNLOCK( player );
701 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
703 int result = MM_ERROR_NONE;
707 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
709 MMPLAYER_CMD_LOCK( player );
711 result = _mmplayer_set_subtitle_silent(player, silent);
713 MMPLAYER_CMD_UNLOCK( player );
719 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
721 int result = MM_ERROR_NONE;
725 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
727 MMPLAYER_CMD_LOCK( player );
729 result = _mmplayer_get_subtitle_silent(player, silent);
731 MMPLAYER_CMD_UNLOCK( player );
737 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
739 int result = MM_ERROR_NONE;
744 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
745 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
747 va_start (var_args, first_attribute_name);
748 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
755 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
757 int result = MM_ERROR_NONE;
762 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
763 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
765 va_start (var_args, first_attribute_name);
766 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
773 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
775 int result = MM_ERROR_NONE;
778 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
779 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
780 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
782 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
787 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
789 int result = MM_ERROR_NONE;
793 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
794 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
795 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
797 result = _mmplayer_get_pd_downloader_status(player, current_pos, total_size);
802 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType track_type, int *count)
804 int result = MM_ERROR_NONE;
808 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
809 return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
811 result = _mmplayer_get_track_count(player, track_type, count);