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;
42 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
44 if (!g_thread_supported ())
47 /* alloc player structure */
48 new_player = g_malloc(sizeof(mm_player_t));
51 debug_error("Cannot allocate memory for player\n");
54 memset(new_player, 0, sizeof(mm_player_t));
56 /* create player lock */
57 new_player->cmd_lock = g_mutex_new();
59 if ( ! new_player->cmd_lock )
61 debug_error("failed to create player lock\n");
65 /* create player lock */
66 new_player->playback_lock = g_mutex_new();
68 if ( ! new_player->playback_lock )
70 debug_error("failed to create playback_lock\n");
74 /* create msg callback lock */
75 new_player->msg_cb_lock = g_mutex_new();
77 if ( ! new_player->msg_cb_lock )
79 debug_error("failed to create msg cb lock\n");
84 result = mm_player_ini_load(&new_player->ini);
85 if(result != MM_ERROR_NONE)
87 debug_error("can't load ini");
91 result = mm_player_audio_effect_ini_load(&new_player->ini);
92 if(result != MM_ERROR_NONE)
94 debug_error("can't load audio ini");
100 result = _mmplayer_create_player((MMHandleType)new_player);
102 if(result != MM_ERROR_NONE)
104 debug_error("failed to create player");
108 *player = (MMHandleType)new_player;
116 if (new_player->cmd_lock)
118 g_mutex_free(new_player->cmd_lock);
119 new_player->cmd_lock = NULL;
122 if (new_player->playback_lock)
124 g_mutex_free(new_player->playback_lock);
125 new_player->playback_lock = NULL;
128 _mmplayer_destroy( (MMHandleType)new_player );
130 MMPLAYER_FREEIF( new_player );
133 *player = (MMHandleType)0;
134 return MM_ERROR_PLAYER_NO_FREE_SPACE; // are you sure?
137 int mm_player_destroy(MMHandleType player)
139 int result = MM_ERROR_NONE;
141 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
143 MMPLAYER_CMD_LOCK( player );
145 result = _mmplayer_destroy(player);
147 MMPLAYER_CMD_UNLOCK( player );
149 g_mutex_free(((mm_player_t*)player)->cmd_lock);
150 g_mutex_free(((mm_player_t*)player)->playback_lock);
152 memset( (mm_player_t*)player, 0x00, sizeof(mm_player_t) );
155 g_free( (void*)player );
160 int mm_player_realize(MMHandleType player)
162 int result = MM_ERROR_NONE;
164 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
166 MMPLAYER_CMD_LOCK( player );
168 result = _mmplayer_realize(player);
170 MMPLAYER_CMD_UNLOCK( player );
175 int mm_player_unrealize(MMHandleType player)
177 int result = MM_ERROR_NONE;
179 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
181 MMPLAYER_CMD_LOCK( player );
183 result = _mmplayer_unrealize(player);
185 MMPLAYER_CMD_UNLOCK( player );
190 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
192 int result = MM_ERROR_NONE;
194 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
196 MMPLAYER_CMD_LOCK( player );
198 result = _mmplayer_set_message_callback(player, callback, user_param);
200 MMPLAYER_CMD_UNLOCK( player );
205 int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
207 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;
220 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
222 MMPLAYER_CMD_LOCK( player );
224 result = _mmplayer_set_audiostream_cb(player, callback, user_param);
226 MMPLAYER_CMD_UNLOCK( player );
231 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
233 int result = MM_ERROR_NONE;
235 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
237 MMPLAYER_CMD_LOCK( player );
239 result = _mmplayer_set_videostream_cb(player, callback, user_param);
241 MMPLAYER_CMD_UNLOCK( player );
246 int mm_player_do_video_capture(MMHandleType player)
248 int result = MM_ERROR_NONE;
250 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
252 MMPLAYER_CMD_LOCK( player );
254 result = _mmplayer_do_video_capture(player);
256 MMPLAYER_CMD_UNLOCK( player );
261 int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
263 int result = MM_ERROR_NONE;
265 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
267 MMPLAYER_CMD_LOCK( player );
269 result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
271 MMPLAYER_CMD_UNLOCK( player );
276 int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
278 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_buffer_enough_data_cb(player, callback, user_param);
286 MMPLAYER_CMD_UNLOCK( player );
292 int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
294 int result = MM_ERROR_NONE;
296 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
298 MMPLAYER_CMD_LOCK( player );
300 result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
302 MMPLAYER_CMD_UNLOCK( player );
307 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
309 int result = MM_ERROR_NONE;
311 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
312 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
314 MMPLAYER_CMD_LOCK( player );
316 result = _mmplayer_set_volume(player, *volume);
318 MMPLAYER_CMD_UNLOCK( player );
323 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
325 int result = MM_ERROR_NONE;
327 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
328 return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
330 MMPLAYER_CMD_LOCK( player );
332 result = _mmplayer_get_volume(player, volume);
334 MMPLAYER_CMD_UNLOCK( player );
339 int mm_player_set_mute(MMHandleType player, int mute)
341 int result = MM_ERROR_NONE;
343 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
345 MMPLAYER_CMD_LOCK( player );
347 result = _mmplayer_set_mute(player, mute);
349 MMPLAYER_CMD_UNLOCK( player );
354 int mm_player_get_mute(MMHandleType player, int *mute)
356 int result = MM_ERROR_NONE;
358 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
359 return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
361 MMPLAYER_CMD_LOCK( player );
363 result = _mmplayer_get_mute(player, mute);
365 MMPLAYER_CMD_UNLOCK( player );
370 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
372 int result = MM_ERROR_NONE;
374 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
375 return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
377 *state = MM_PLAYER_STATE_NULL;
379 result = _mmplayer_get_state(player, (int*)state);
384 /* NOTE : It does not support some use cases, eg using colorspace converter */
385 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
387 int result = MM_ERROR_NONE;
389 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
391 MMPLAYER_CMD_LOCK( player );
393 result = _mmplayer_change_videosink(player, display_surface_type, display_overlay);
395 MMPLAYER_CMD_UNLOCK( player );
400 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
402 int result = MM_ERROR_NONE;
404 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
406 //MMPLAYER_CMD_LOCK( player );
408 result = _mmplayer_push_buffer(player, buf, size);
410 //MMPLAYER_CMD_UNLOCK( player );
415 int mm_player_start(MMHandleType player)
417 int result = MM_ERROR_NONE;
419 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
421 MMPLAYER_CMD_LOCK( player );
423 result = _mmplayer_start(player);
425 MMPLAYER_CMD_UNLOCK( player );
430 int mm_player_stop(MMHandleType player)
432 int result = MM_ERROR_NONE;
434 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
436 MMPLAYER_CMD_LOCK( player );
438 result = _mmplayer_stop(player);
440 MMPLAYER_CMD_UNLOCK( player );
445 int mm_player_pause(MMHandleType player)
447 int result = MM_ERROR_NONE;
449 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
451 MMPLAYER_CMD_LOCK( player );
453 result = _mmplayer_pause(player);
455 MMPLAYER_CMD_UNLOCK( player );
460 int mm_player_resume(MMHandleType player)
462 int result = MM_ERROR_NONE;
464 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
466 MMPLAYER_CMD_LOCK( player );
468 result = _mmplayer_resume(player);
470 MMPLAYER_CMD_UNLOCK( player );
475 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
477 int result = MM_ERROR_NONE;
479 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
481 MMPLAYER_CMD_LOCK( player );
483 result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
485 MMPLAYER_CMD_UNLOCK( player );
490 int mm_player_deactivate_section_repeat(MMHandleType player)
492 int result = MM_ERROR_NONE;
494 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
496 MMPLAYER_CMD_LOCK( player );
498 result = _mmplayer_deactivate_section_repeat(player);
500 MMPLAYER_CMD_UNLOCK( player );
505 int mm_player_gst_set_audio_channel(MMHandleType player, MMPlayerAudioChannel ch)
507 int result = MM_ERROR_NONE;
509 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
510 MMPLAYER_CMD_LOCK( player );
512 result = _mmplayer_gst_set_audio_channel(player, ch);
514 MMPLAYER_CMD_UNLOCK( player );
518 int mm_player_set_play_speed(MMHandleType player, float rate)
520 int result = MM_ERROR_NONE;
522 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
524 MMPLAYER_CMD_LOCK( player );
526 result = _mmplayer_set_playspeed(player, rate);
528 MMPLAYER_CMD_UNLOCK( player );
533 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
535 int result = MM_ERROR_NONE;
537 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
539 if (format >= MM_PLAYER_POS_FORMAT_NUM)
541 debug_error("wrong format\n");
542 return MM_ERROR_COMMON_INVALID_ARGUMENT;
545 MMPLAYER_CMD_LOCK( player );
547 result = _mmplayer_set_position(player, format, pos);
549 MMPLAYER_CMD_UNLOCK( player );
554 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
556 int result = MM_ERROR_NONE;
558 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
559 return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
561 if (format >= MM_PLAYER_POS_FORMAT_NUM)
563 debug_error("wrong format\n");
564 return MM_ERROR_COMMON_INVALID_ARGUMENT;
567 MMPLAYER_CMD_LOCK( player );
569 result = _mmplayer_get_position(player, (int)format, (unsigned long*)pos);
571 MMPLAYER_CMD_UNLOCK( player );
576 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, int *start_pos, int *stop_pos)
578 int result = MM_ERROR_NONE;
580 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
581 return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
583 MMPLAYER_CMD_LOCK( player );
585 result = _mmplayer_get_buffer_position(player, (int)format, (unsigned long*)start_pos, (unsigned long*)stop_pos );
587 MMPLAYER_CMD_UNLOCK( player );
592 int mm_player_set_external_subtitle_path(MMHandleType player, const char* path)
594 int result = MM_ERROR_NONE;
596 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
598 MMPLAYER_CMD_LOCK( player );
600 result = _mmplayer_set_external_subtitle_path(player, path);
602 MMPLAYER_CMD_UNLOCK( player );
606 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
608 int result = MM_ERROR_NONE;
610 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
612 if (format >= MM_PLAYER_POS_FORMAT_NUM)
614 debug_error("wrong format(%d) \n", format);
615 return MM_ERROR_INVALID_ARGUMENT;
618 MMPLAYER_CMD_LOCK( player );
620 result = _mmplayer_adjust_subtitle_postion(player, format, pos);
622 MMPLAYER_CMD_UNLOCK( player );
627 int mm_player_set_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
629 int result = MM_ERROR_NONE;
632 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
633 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
635 va_start (var_args, first_attribute_name);
636 result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
642 int mm_player_get_attribute(MMHandleType player, char **err_attr_name, const char *first_attribute_name, ...)
644 int result = MM_ERROR_NONE;
647 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
648 return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
650 va_start (var_args, first_attribute_name);
651 result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
657 int mm_player_get_attribute_info(MMHandleType player, const char *attribute_name, MMPlayerAttrsInfo *info)
659 int result = MM_ERROR_NONE;
662 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
663 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
664 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
666 result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
671 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
673 int result = MM_ERROR_NONE;
675 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
676 return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
677 return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
679 result = _mmplayer_get_pd_downloader_status(player, current_pos, total_size);
684 int mm_player_set_display_zoom(MMHandleType player, float level, int x, int y)
686 int result = MM_ERROR_NONE;
688 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
690 MMPLAYER_CMD_LOCK( player );
692 result = _mmplayer_set_display_zoom(player, level, x, y);
694 MMPLAYER_CMD_UNLOCK( player );
699 int mm_player_get_display_zoom(MMHandleType player, float *level, int *x, int *y)
701 int result = MM_ERROR_NONE;
703 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
704 return_val_if_fail(level, MM_ERROR_COMMON_INVALID_ARGUMENT);
706 MMPLAYER_CMD_LOCK( player );
708 result = _mmplayer_get_display_zoom(player, level, x, y);
710 MMPLAYER_CMD_UNLOCK( player );
715 int mm_player_set_uri(MMHandleType player, const char *uri)
717 int result = MM_ERROR_NONE;
719 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
721 MMPLAYER_CMD_LOCK( player );
723 result = _mmplayer_set_uri(player, uri);
725 MMPLAYER_CMD_UNLOCK( player );
731 int mm_player_set_next_uri(MMHandleType player, const char *uri)
733 int result = MM_ERROR_NONE;
735 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
737 MMPLAYER_CMD_LOCK( player );
739 result = _mmplayer_set_next_uri(player, uri, FALSE);
741 MMPLAYER_CMD_UNLOCK( player );
747 int mm_player_get_next_uri(MMHandleType player, char **uri)
749 int result = MM_ERROR_NONE;
751 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
753 MMPLAYER_CMD_LOCK( player );
755 result = _mmplayer_get_next_uri(player, uri);
757 MMPLAYER_CMD_UNLOCK( player );
763 int mm_player_enable_media_packet_video_stream(MMHandleType player, bool enable)
765 int result = MM_ERROR_NONE;
767 return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
768 return_val_if_fail(enable, MM_ERROR_INVALID_ARGUMENT);
770 MMPLAYER_CMD_LOCK( player );
772 result = _mmplayer_enable_media_packet_video_stream(player, enable);
774 MMPLAYER_CMD_UNLOCK( player );