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);
151 int mm_player_realize(MMHandleType player)
153 int result = MM_ERROR_NONE;
157 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
159 MMPLAYER_CMD_LOCK( player );
161 __ta__("[KPI] initialize media player service",
162 result = _mmplayer_realize(player);
165 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 );
189 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
191 int result = MM_ERROR_NONE;
195 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
197 MMPLAYER_CMD_LOCK( player );
199 result = _mmplayer_set_message_callback(player, callback, user_param);
201 MMPLAYER_CMD_UNLOCK( player );
206 int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
208 int result = MM_ERROR_NONE;
212 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
214 result = _mm_player_set_pd_downloader_message_cb(player, callback, user_param);
219 int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
221 int result = MM_ERROR_NONE;
225 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
227 MMPLAYER_CMD_LOCK( player );
229 result = _mmplayer_set_audiostream_cb(player, callback, user_param);
231 MMPLAYER_CMD_UNLOCK( player );
236 int mm_player_set_audio_buffer_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
238 int result = MM_ERROR_NONE;
242 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
244 MMPLAYER_CMD_LOCK( player );
246 result = _mmplayer_set_audiobuffer_cb(player, callback, user_param);
248 MMPLAYER_CMD_UNLOCK( player );
253 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
255 int result = MM_ERROR_NONE;
259 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
261 MMPLAYER_CMD_LOCK( player );
263 result = _mmplayer_set_videostream_cb(player, callback, user_param);
265 MMPLAYER_CMD_UNLOCK( player );
270 int mm_player_set_video_frame_render_error_callback(MMHandleType player, mm_player_video_frame_render_error_callback callback, void *user_param)
272 int result = MM_ERROR_NONE;
276 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
278 MMPLAYER_CMD_LOCK( player );
280 result = _mmplayer_set_videoframe_render_error_cb(player, callback, user_param);
282 MMPLAYER_CMD_UNLOCK( player );
287 int mm_player_do_video_capture(MMHandleType player)
289 int result = MM_ERROR_NONE;
293 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
295 MMPLAYER_CMD_LOCK( player );
297 result = _mmplayer_do_video_capture(player);
299 MMPLAYER_CMD_UNLOCK( player );
304 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
306 int result = MM_ERROR_NONE;
310 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
312 MMPLAYER_CMD_LOCK( player );
314 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
316 MMPLAYER_CMD_UNLOCK( player );
321 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
323 int result = MM_ERROR_NONE;
327 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
329 MMPLAYER_CMD_LOCK( player );
331 result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
333 MMPLAYER_CMD_UNLOCK( player );
339 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
341 int result = MM_ERROR_NONE;
345 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
347 MMPLAYER_CMD_LOCK( player );
349 result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
351 MMPLAYER_CMD_UNLOCK( player );
356 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
358 int result = MM_ERROR_NONE;
362 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
363 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
365 MMPLAYER_CMD_LOCK( player );
367 result = _mmplayer_set_volume(player, *volume);
369 MMPLAYER_CMD_UNLOCK( player );
374 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
376 int result = MM_ERROR_NONE;
380 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
381 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
383 MMPLAYER_CMD_LOCK( player );
385 result = _mmplayer_get_volume(player, volume);
387 MMPLAYER_CMD_UNLOCK( player );
392 int mm_player_set_mute(MMHandleType player, int mute)
394 int result = MM_ERROR_NONE;
398 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
400 MMPLAYER_CMD_LOCK( player );
402 result = _mmplayer_set_mute(player, mute);
404 MMPLAYER_CMD_UNLOCK( player );
409 int mm_player_get_mute(MMHandleType player, int *mute)
411 int result = MM_ERROR_NONE;
415 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
416 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
418 MMPLAYER_CMD_LOCK( player );
420 result = _mmplayer_get_mute(player, mute);
422 MMPLAYER_CMD_UNLOCK( player );
427 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
429 int result = MM_ERROR_NONE;
433 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
434 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
436 *state = MM_PLAYER_STATE_NULL;
438 result = _mmplayer_get_state(player, (int*)state);
443 /* NOTE : Not supported */
444 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
448 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
450 return MM_ERROR_NOT_SUPPORT_API;
453 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
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_push_buffer(player, buf, size);
466 //MMPLAYER_CMD_UNLOCK( player );
471 int mm_player_start(MMHandleType player)
473 int result = MM_ERROR_NONE;
477 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
479 MMPLAYER_CMD_LOCK( player );
481 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
482 result = _mmplayer_start(player);
484 MMPLAYER_CMD_UNLOCK( player );
489 int mm_player_stop(MMHandleType player)
491 int result = MM_ERROR_NONE;
495 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
497 MMPLAYER_CMD_LOCK( player );
499 __ta__("[KPI] stop media player service",
500 result = _mmplayer_stop(player);
503 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 );
527 int mm_player_resume(MMHandleType player)
529 int result = MM_ERROR_NONE;
533 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
535 MMPLAYER_CMD_LOCK( player );
537 __ta__("[KPI] resume media player service",
538 result = _mmplayer_resume(player);
541 MMPLAYER_CMD_UNLOCK( player );
546 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
548 int result = MM_ERROR_NONE;
550 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
552 MMPLAYER_CMD_LOCK( player );
554 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
556 MMPLAYER_CMD_UNLOCK( player );
561 int mm_player_deactivate_section_repeat(MMHandleType player)
563 int result = MM_ERROR_NONE;
565 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
567 MMPLAYER_CMD_LOCK( player );
569 result = _mmplayer_deactivate_section_repeat(player);
571 MMPLAYER_CMD_UNLOCK( player );
576 int mm_player_set_play_speed(MMHandleType player, float rate)
578 int result = MM_ERROR_NONE;
580 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
582 MMPLAYER_CMD_LOCK( player );
584 result = _mmplayer_set_playspeed(player, rate);
586 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 );
614 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
616 int result = MM_ERROR_NONE;
620 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
621 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
623 if (format >= MM_PLAYER_POS_FORMAT_NUM)
625 debug_error("wrong format\n");
626 return MM_ERROR_COMMON_INVALID_ARGUMENT;
629 MMPLAYER_CMD_LOCK( player );
631 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
633 MMPLAYER_CMD_UNLOCK( player );
638 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
640 int result = MM_ERROR_NONE;
644 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
645 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
647 MMPLAYER_CMD_LOCK( player );
649 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
651 MMPLAYER_CMD_UNLOCK( player );
656 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
658 int result = MM_ERROR_NONE;
662 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
664 if (format >= MM_PLAYER_POS_FORMAT_NUM)
666 debug_error("wrong format\n");
667 return MM_ERROR_COMMON_INVALID_ARGUMENT;
670 MMPLAYER_CMD_LOCK( player );
672 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
674 MMPLAYER_CMD_UNLOCK( player );
679 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
681 int result = MM_ERROR_NONE;
685 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
687 MMPLAYER_CMD_LOCK( player );
689 result = _mmplayer_set_subtitle_silent(player, silent);
691 MMPLAYER_CMD_UNLOCK( player );
696 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
698 int result = MM_ERROR_NONE;
702 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
704 MMPLAYER_CMD_LOCK( player );
706 result = _mmplayer_get_subtitle_silent(player, silent);
708 MMPLAYER_CMD_UNLOCK( player );
713 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
715 int result = MM_ERROR_NONE;
720 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
721 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
723 va_start (var_args, first_attribute_name);
724 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
730 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
732 int result = MM_ERROR_NONE;
737 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
738 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
740 va_start (var_args, first_attribute_name);
741 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
747 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
749 int result = MM_ERROR_NONE;
752 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
753 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
754 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
756 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
761 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
763 int result = MM_ERROR_NONE;
767 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
768 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
769 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
771 result = _mmplayer_get_pd_downloader_status(player, current_pos, total_size);
776 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType track_type, int *count)
778 int result = MM_ERROR_NONE;
782 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
783 return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
785 result = _mmplayer_get_track_count(player, track_type, count);
791 int mm_player_ignore_session(MMHandleType player)
793 int result = MM_ERROR_NONE;
797 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
799 result = _mmplayer_asm_ignore_session(player);
804 int mm_player_set_display_zoom(MMHandleType player, float level)
806 int result = MM_ERROR_NONE;
807 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
809 MMPLAYER_CMD_LOCK( player );
811 result = _mmplayer_set_display_zoom(player, level);
813 MMPLAYER_CMD_UNLOCK( player );
818 int mm_player_get_display_zoom(MMHandleType player, float *level)
820 int result = MM_ERROR_NONE;
822 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
823 return_val_if_fail(level, MM_ERROR_COMMON_INVALID_ARGUMENT);
825 MMPLAYER_CMD_LOCK( player );
827 result = _mmplayer_get_display_zoom(player, level);
829 MMPLAYER_CMD_UNLOCK( player );
834 int mm_player_set_display_zoom_start_position(MMHandleType player, int x, int y)
836 int result = MM_ERROR_NONE;
838 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
840 MMPLAYER_CMD_LOCK( player );
842 result = _mmplayer_set_display_zoom_start_pos(player, x, y);
844 MMPLAYER_CMD_UNLOCK( player );
849 int mm_player_get_display_zoom_start_position(MMHandleType player, int *x, int *y)
851 int result = MM_ERROR_NONE;
853 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
855 MMPLAYER_CMD_LOCK( player );
857 result = _mmplayer_get_display_zoom_start_pos(player, x, y);
859 MMPLAYER_CMD_UNLOCK( player );