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>,
7 * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <mm_message.h>
29 #include "mm_player.h"
30 #include "mm_player_priv.h"
31 #include "mm_player_attrs.h"
32 #include "mm_player_utils.h"
33 #include "mm_player_ini.h"
35 #include "mm_player_capture.h"
37 int mm_player_create(MMHandleType *player)
39 int result = MM_ERROR_NONE;
40 mm_player_t* new_player = NULL;
44 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
46 if (!g_thread_supported ())
51 __ta__("mm_player_ini_load",
52 result = mm_player_ini_load();
55 if(result != MM_ERROR_NONE)
56 return MM_ERROR_PLAYER_INTERNAL;
58 /* alloc player structure */
59 new_player = g_malloc(sizeof(mm_player_t));
62 debug_critical("Cannot allocate memory for player\n");
65 memset(new_player, 0, sizeof(mm_player_t));
67 /* create player lock */
68 new_player->cmd_lock = g_mutex_new();
70 if ( ! new_player->cmd_lock )
72 debug_critical("failed to create player lock\n");
76 /* create msg callback lock */
77 new_player->msg_cb_lock = g_mutex_new();
79 if ( ! new_player->msg_cb_lock )
81 debug_critical("failed to create msg cb lock\n");
84 __ta__("[KPI] create media player service",
85 result = _mmplayer_create_player((MMHandleType)new_player);
88 if(result != MM_ERROR_NONE)
91 *player = (MMHandleType)new_player;
99 if (new_player->cmd_lock)
101 g_mutex_free(new_player->cmd_lock);
102 new_player->cmd_lock = NULL;
105 _mmplayer_destroy( (MMHandleType)new_player );
106 MMPLAYER_FREEIF( new_player );
109 *player = (MMHandleType)0;
110 return MM_ERROR_PLAYER_NO_FREE_SPACE; // are you sure?
113 int mm_player_destroy(MMHandleType player)
115 int result = MM_ERROR_NONE;
119 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
121 MMPLAYER_CMD_LOCK( player );
123 __ta__("[KPI] destroy media player service",
124 result = _mmplayer_destroy(player);
127 MMPLAYER_CMD_UNLOCK( player );
129 if (((mm_player_t*)player)->cmd_lock)
131 g_mutex_free(((mm_player_t*)player)->cmd_lock);
132 ((mm_player_t*)player)->cmd_lock = NULL;
136 g_free( (void*)player );
138 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
146 int mm_player_realize(MMHandleType player)
148 int result = MM_ERROR_NONE;
152 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
154 MMPLAYER_CMD_LOCK( player );
156 __ta__("[KPI] initialize media player service",
157 result = _mmplayer_realize(player);
160 MMPLAYER_CMD_UNLOCK( player );
166 int mm_player_unrealize(MMHandleType player)
168 int result = MM_ERROR_NONE;
172 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
174 MMPLAYER_CMD_LOCK( player );
176 __ta__("[KPI] cleanup media player service",
177 result = _mmplayer_unrealize(player);
180 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_message_callback(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 );
234 int mm_player_set_audio_buffer_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
236 int result = MM_ERROR_NONE;
240 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
242 MMPLAYER_CMD_LOCK( player );
244 result = _mmplayer_set_audiobuffer_cb(player, callback, user_param);
246 MMPLAYER_CMD_UNLOCK( player );
251 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
253 int result = MM_ERROR_NONE;
257 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
259 MMPLAYER_CMD_LOCK( player );
261 result = _mmplayer_set_videostream_cb(player, callback, user_param);
263 MMPLAYER_CMD_UNLOCK( player );
268 int mm_player_do_video_capture(MMHandleType player)
270 int result = MM_ERROR_NONE;
274 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
276 MMPLAYER_CMD_LOCK( player );
278 result = _mmplayer_do_video_capture(player);
280 MMPLAYER_CMD_UNLOCK( player );
285 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
287 int result = MM_ERROR_NONE;
291 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
293 MMPLAYER_CMD_LOCK( player );
295 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
297 MMPLAYER_CMD_UNLOCK( player );
303 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
305 int result = MM_ERROR_NONE;
309 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
311 MMPLAYER_CMD_LOCK( player );
313 result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
315 MMPLAYER_CMD_UNLOCK( player );
321 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_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_seek_data_cb(player, callback, user_param);
333 MMPLAYER_CMD_UNLOCK( player );
339 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
341 int result = MM_ERROR_NONE;
345 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
346 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
348 MMPLAYER_CMD_LOCK( player );
350 result = _mmplayer_set_volume(player, *volume);
352 MMPLAYER_CMD_UNLOCK( player );
358 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
360 int result = MM_ERROR_NONE;
364 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
365 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
367 MMPLAYER_CMD_LOCK( player );
369 result = _mmplayer_get_volume(player, volume);
371 MMPLAYER_CMD_UNLOCK( player );
377 int mm_player_set_mute(MMHandleType player, int mute)
379 int result = MM_ERROR_NONE;
383 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
385 MMPLAYER_CMD_LOCK( player );
387 result = _mmplayer_set_mute(player, mute);
389 MMPLAYER_CMD_UNLOCK( player );
395 int mm_player_get_mute(MMHandleType player, int *mute)
397 int result = MM_ERROR_NONE;
401 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
402 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
404 MMPLAYER_CMD_LOCK( player );
406 result = _mmplayer_get_mute(player, mute);
408 MMPLAYER_CMD_UNLOCK( player );
414 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
416 int result = MM_ERROR_NONE;
420 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
421 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
423 *state = MM_PLAYER_STATE_NULL;
425 MMPLAYER_CMD_LOCK( player );
427 result = _mmplayer_get_state(player, (int*)state); /* FIXIT : why int* ? */
429 MMPLAYER_CMD_UNLOCK( player );
435 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
437 int result = MM_ERROR_NONE;
441 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
443 //MMPLAYER_CMD_LOCK( player );
445 //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
446 result = _mmplayer_push_buffer(player, buf, size);
448 //MMPLAYER_CMD_UNLOCK( player );
454 int mm_player_start(MMHandleType player)
456 int result = MM_ERROR_NONE;
460 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
462 MMPLAYER_CMD_LOCK( player );
464 MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
465 result = _mmplayer_start(player);
467 MMPLAYER_CMD_UNLOCK( player );
473 int mm_player_stop(MMHandleType player)
475 int result = MM_ERROR_NONE;
479 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
481 MMPLAYER_CMD_LOCK( player );
483 __ta__("[KPI] stop media player service",
484 result = _mmplayer_stop(player);
487 MMPLAYER_CMD_UNLOCK( player );
493 int mm_player_pause(MMHandleType player)
495 int result = MM_ERROR_NONE;
499 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
501 MMPLAYER_CMD_LOCK( player );
503 __ta__("[KPI] pause media player service",
504 result = _mmplayer_pause(player);
507 MMPLAYER_CMD_UNLOCK( player );
513 int mm_player_resume(MMHandleType player)
515 int result = MM_ERROR_NONE;
519 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
521 MMPLAYER_CMD_LOCK( player );
523 __ta__("[KPI] resume media player service",
524 result = _mmplayer_resume(player);
527 MMPLAYER_CMD_UNLOCK( player );
533 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
535 int result = MM_ERROR_NONE;
537 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
539 MMPLAYER_CMD_LOCK( player );
541 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
543 MMPLAYER_CMD_UNLOCK( player );
549 int mm_player_deactivate_section_repeat(MMHandleType player)
551 int result = MM_ERROR_NONE;
553 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
555 MMPLAYER_CMD_LOCK( player );
557 result = _mmplayer_deactivate_section_repeat(player);
559 MMPLAYER_CMD_UNLOCK( player );
565 int mm_player_set_play_speed(MMHandleType player, float rate)
567 int result = MM_ERROR_NONE;
569 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
571 MMPLAYER_CMD_LOCK( player );
573 result = _mmplayer_set_playspeed(player, rate);
575 MMPLAYER_CMD_UNLOCK( player );
581 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
583 int result = MM_ERROR_NONE;
587 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
589 if (format >= MM_PLAYER_POS_FORMAT_NUM)
591 debug_error("wrong format\n");
592 return MM_ERROR_COMMON_INVALID_ARGUMENT;
595 MMPLAYER_CMD_LOCK( player );
597 result = _mmplayer_set_position(player, format, pos);
599 MMPLAYER_CMD_UNLOCK( player );
605 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
607 int result = MM_ERROR_NONE;
611 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
612 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
614 if (format >= MM_PLAYER_POS_FORMAT_NUM)
616 debug_error("wrong format\n");
617 return MM_ERROR_COMMON_INVALID_ARGUMENT;
620 MMPLAYER_CMD_LOCK( player );
622 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
624 MMPLAYER_CMD_UNLOCK( player );
629 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
631 int result = MM_ERROR_NONE;
635 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
636 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
638 MMPLAYER_CMD_LOCK( player );
640 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
642 MMPLAYER_CMD_UNLOCK( player );
647 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
649 int result = MM_ERROR_NONE;
653 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
655 if (format >= MM_PLAYER_POS_FORMAT_NUM)
657 debug_error("wrong format\n");
658 return MM_ERROR_COMMON_INVALID_ARGUMENT;
661 MMPLAYER_CMD_LOCK( player );
663 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
665 MMPLAYER_CMD_UNLOCK( player );
671 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
673 int result = MM_ERROR_NONE;
677 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
679 MMPLAYER_CMD_LOCK( player );
681 result = _mmplayer_set_subtitle_silent(player, silent);
683 MMPLAYER_CMD_UNLOCK( player );
689 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
691 int result = MM_ERROR_NONE;
695 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
697 MMPLAYER_CMD_LOCK( player );
699 result = _mmplayer_get_subtitle_silent(player, silent);
701 MMPLAYER_CMD_UNLOCK( player );
707 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
709 int result = MM_ERROR_NONE;
714 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
715 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
717 va_start (var_args, first_attribute_name);
718 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
725 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
727 int result = MM_ERROR_NONE;
732 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
733 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
735 va_start (var_args, first_attribute_name);
736 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
743 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
745 int result = MM_ERROR_NONE;
748 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
749 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
750 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
752 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
757 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
759 int result = MM_ERROR_NONE;
763 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
764 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
765 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
767 result = _mmplayer_pd_get_status(player, current_pos, total_size);
772 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType track_type, int *count)
774 int result = MM_ERROR_NONE;
778 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
779 return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
781 result = _mmplayer_get_track_count(player, track_type, count);