Merge "Remove Profile Build Dependency: Do it at runtime" into tizen
[platform/core/multimedia/libmm-player.git] / src / mm_player.c
1 /*
2  * libmm-player
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22
23 #include <gst/gst.h>
24 #include <string.h>
25
26 #include <dlog.h>
27 #include <mm_types.h>
28 #include <mm_message.h>
29
30 #include "mm_player.h"
31 #include "mm_player_priv.h"
32 #include "mm_player_attrs.h"
33 #include "mm_player_utils.h"
34 #include "mm_player_ini.h"
35 #include "mm_player_capture.h"
36 #include "mm_player_tracks.h"
37 #include "mm_player_es.h"
38
39 int mm_player_create(MMHandleType *player)
40 {
41         int result = MM_ERROR_PLAYER_INTERNAL;
42         mm_player_t* new_player = NULL;
43
44         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
45
46         /* alloc player structure */
47         new_player = g_malloc(sizeof(mm_player_t));
48         if (!new_player)
49         {
50                 LOGE("Cannot allocate memory for player\n");
51                 result = MM_ERROR_PLAYER_RESOURCE_LIMIT;
52                 goto ERROR;
53         }
54         memset(new_player, 0, sizeof(mm_player_t));
55
56         /* create player lock */
57         g_mutex_init(&new_player->cmd_lock);
58
59         /* create player lock */
60         g_mutex_init(&new_player->playback_lock);
61
62         /* load ini files */
63         if (MM_ERROR_NONE != mm_player_ini_load(&new_player->ini))
64         {
65                 LOGE("can't load ini");
66                 goto ERROR;
67         }
68
69         if (MM_ERROR_NONE != mm_player_audio_effect_ini_load(&new_player->ini))
70         {
71                 LOGE("can't load audio ini");
72                 goto ERROR;
73         }
74
75         /* create player */
76         result = _mmplayer_create_player((MMHandleType)new_player);
77         if(result != MM_ERROR_NONE)
78         {
79                 LOGE("failed to create player");
80                 if (result != MM_ERROR_PLAYER_RESOURCE_LIMIT)
81                         result = MM_ERROR_PLAYER_INTERNAL;
82                 goto ERROR;
83         }
84
85         *player = (MMHandleType)new_player;
86
87         return MM_ERROR_NONE;
88
89 ERROR:
90
91         if ( new_player )
92         {
93                 _mmplayer_destroy( (MMHandleType)new_player );
94                 g_mutex_clear(&new_player->cmd_lock);
95                 g_mutex_clear(&new_player->playback_lock);
96
97                 MMPLAYER_FREEIF( new_player );
98         }
99
100         *player = (MMHandleType)0;
101         return result; /* MM_ERROR_PLAYER_INTERNAL or MM_ERROR_PLAYER_RESOURCE_LIMIT */
102 }
103
104 int  mm_player_destroy(MMHandleType player)
105 {
106         int result = MM_ERROR_NONE;
107
108         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
109
110         MMPLAYER_CMD_LOCK( player );
111
112         result = _mmplayer_destroy(player);
113
114         MMPLAYER_CMD_UNLOCK( player );
115
116         g_mutex_clear(&((mm_player_t*)player)->cmd_lock);
117         g_mutex_clear(&((mm_player_t*)player)->playback_lock);
118
119         memset( (mm_player_t*)player, 0x00, sizeof(mm_player_t) );
120
121         /* free player */
122         g_free( (void*)player );
123
124         return result;
125 }
126
127 int mm_player_sound_register(MMHandleType player, int pid)
128 {
129         int result = MM_ERROR_NONE;
130
131         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
132
133         MMPLAYER_CMD_LOCK( player );
134
135         result = _mmplayer_sound_register_with_pid(player, pid);
136
137         MMPLAYER_CMD_UNLOCK( player );
138
139         return result;
140 }
141
142 int mm_player_get_client_pid (MMHandleType player, int* pid)
143 {
144         int result = MM_ERROR_NONE;
145
146         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
147         MMPLAYER_RETURN_VAL_IF_FAIL(pid, MM_ERROR_INVALID_ARGUMENT);
148
149         MMPLAYER_CMD_LOCK( player );
150
151         result = _mmplayer_get_client_pid(player, pid);
152
153         MMPLAYER_CMD_UNLOCK( player );
154
155         return result;
156 }
157
158 int mm_player_realize(MMHandleType player)
159 {
160         int result = MM_ERROR_NONE;
161
162         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
163
164         MMPLAYER_CMD_LOCK( player );
165
166         result = _mmplayer_realize(player);
167
168         MMPLAYER_CMD_UNLOCK( player );
169
170         return result;
171 }
172
173 int mm_player_unrealize(MMHandleType player)
174 {
175         int result = MM_ERROR_NONE;
176
177         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
178
179         MMPLAYER_CMD_LOCK( player );
180
181         result = _mmplayer_unrealize(player);
182
183         MMPLAYER_CMD_UNLOCK( player );
184
185         return result;
186 }
187
188 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
189 {
190         int result = MM_ERROR_NONE;
191
192         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
193
194         MMPLAYER_CMD_LOCK( player );
195
196         result = _mmplayer_set_message_callback(player, callback, user_param);
197
198         MMPLAYER_CMD_UNLOCK( player );
199
200         return result;
201 }
202
203 int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
204 {
205         int result = MM_ERROR_NONE;
206
207         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
208
209         result = _mm_player_set_pd_downloader_message_cb(player, callback, user_param);
210
211         return result;
212 }
213
214 int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
215 {
216         int result = MM_ERROR_NONE;
217
218         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
219
220         MMPLAYER_CMD_LOCK( player );
221
222         result = _mmplayer_set_audiostream_cb(player, callback, user_param);
223
224         MMPLAYER_CMD_UNLOCK( player );
225
226         return result;
227 }
228
229 int mm_player_set_audio_stream_callback_ex(MMHandleType player, bool sync, mm_player_audio_stream_callback_ex callback, void *user_param)
230 {
231         int result = MM_ERROR_NONE;
232
233         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
234
235         MMPLAYER_CMD_LOCK( player );
236
237         result = _mmplayer_set_audiostream_cb_ex(player, sync, callback, user_param);
238
239         MMPLAYER_CMD_UNLOCK( player );
240
241         return result;
242 }
243
244 int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_stream_callback callback, void *user_param)
245 {
246         int result = MM_ERROR_NONE;
247
248         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
249
250         MMPLAYER_CMD_LOCK( player );
251
252         result = _mmplayer_set_videostream_cb(player, callback, user_param);
253
254         MMPLAYER_CMD_UNLOCK( player );
255
256         return result;
257 }
258
259 int mm_player_do_video_capture(MMHandleType player)
260 {
261         int result = MM_ERROR_NONE;
262
263         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
264
265         MMPLAYER_CMD_LOCK( player );
266
267         result = _mmplayer_do_video_capture(player);
268
269         MMPLAYER_CMD_UNLOCK( player );
270
271         return result;
272 }
273
274 int mm_player_set_prepare_buffering_time(MMHandleType player, int second)
275 {
276         int result = MM_ERROR_NONE;
277
278         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
279
280         MMPLAYER_CMD_LOCK( player );
281
282         result = _mmplayer_set_prepare_buffering_time(player, second);
283
284         MMPLAYER_CMD_UNLOCK( player );
285
286         return result;
287 }
288
289 int mm_player_set_runtime_buffering_mode(MMHandleType player, MMPlayerBufferingMode mode, int second)
290 {
291         int result = MM_ERROR_NONE;
292
293         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
294
295         MMPLAYER_CMD_LOCK( player );
296
297         result = _mmplayer_set_runtime_buffering_mode(player, mode, second);
298
299         MMPLAYER_CMD_UNLOCK( player );
300
301         return result;
302 }
303
304 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
305 {
306         int result = MM_ERROR_NONE;
307
308         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
309         MMPLAYER_RETURN_VAL_IF_FAIL(volume, MM_ERROR_INVALID_ARGUMENT);
310
311         MMPLAYER_CMD_LOCK( player );
312
313         result = _mmplayer_set_volume(player, *volume);
314
315         MMPLAYER_CMD_UNLOCK( player );
316
317         return result;
318 }
319
320 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
321 {
322         int result = MM_ERROR_NONE;
323
324         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
325         MMPLAYER_RETURN_VAL_IF_FAIL(volume, MM_ERROR_INVALID_ARGUMENT);
326
327         MMPLAYER_CMD_LOCK( player );
328
329         result = _mmplayer_get_volume(player, volume);
330
331         MMPLAYER_CMD_UNLOCK( player );
332
333         return result;
334 }
335
336 int mm_player_set_mute(MMHandleType player, int mute)
337 {
338         int result = MM_ERROR_NONE;
339
340         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
341
342         MMPLAYER_CMD_LOCK( player );
343
344         result = _mmplayer_set_mute(player, mute);
345
346         MMPLAYER_CMD_UNLOCK( player );
347
348         return result;
349 }
350
351 int mm_player_get_mute(MMHandleType player, int *mute)
352 {
353         int result = MM_ERROR_NONE;
354
355         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
356         MMPLAYER_RETURN_VAL_IF_FAIL(mute, MM_ERROR_INVALID_ARGUMENT);
357
358         MMPLAYER_CMD_LOCK( player );
359
360         result = _mmplayer_get_mute(player, mute);
361
362         MMPLAYER_CMD_UNLOCK( player );
363
364         return result;
365 }
366
367 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
368 {
369         int result = MM_ERROR_NONE;
370
371         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
372         MMPLAYER_RETURN_VAL_IF_FAIL(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
373
374         *state = MM_PLAYER_STATE_NULL;
375
376         result = _mmplayer_get_state(player, (int*)state);
377
378         return result;
379 }
380
381 /* NOTE : It does not support some use cases, eg using colorspace converter */
382 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
383 {
384         int result = MM_ERROR_NONE;
385
386         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
387
388         MMPLAYER_CMD_LOCK( player );
389
390         result = _mmplayer_change_videosink(player, display_surface_type, display_overlay);
391
392         MMPLAYER_CMD_UNLOCK( player );
393
394         return result;
395 }
396
397 int mm_player_start(MMHandleType player)
398 {
399         int result = MM_ERROR_NONE;
400
401         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
402
403         MMPLAYER_CMD_LOCK( player );
404
405         result = _mmplayer_start(player);
406
407         MMPLAYER_CMD_UNLOCK( player );
408
409         return result;
410 }
411
412 int  mm_player_stop(MMHandleType player)
413 {
414         int result = MM_ERROR_NONE;
415
416         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
417
418         MMPLAYER_CMD_LOCK( player );
419
420         result = _mmplayer_stop(player);
421
422         MMPLAYER_CMD_UNLOCK( player );
423
424         return result;
425 }
426
427 int mm_player_pause(MMHandleType player)
428 {
429         int result = MM_ERROR_NONE;
430
431         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
432
433         MMPLAYER_CMD_LOCK( player );
434
435         result = _mmplayer_pause(player);
436
437         MMPLAYER_CMD_UNLOCK( player );
438
439         return result;
440 }
441
442 int mm_player_resume(MMHandleType player)
443 {
444         int result = MM_ERROR_NONE;
445
446         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
447
448         MMPLAYER_CMD_LOCK( player );
449
450         result = _mmplayer_resume(player);
451
452         MMPLAYER_CMD_UNLOCK( player );
453
454         return result;
455 }
456
457 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
458 {
459         int result = MM_ERROR_NONE;
460
461         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
462
463         MMPLAYER_CMD_LOCK( player );
464
465         result = _mmplayer_activate_section_repeat(player, start_pos, end_pos);
466
467         MMPLAYER_CMD_UNLOCK( player );
468
469         return result;
470 }
471
472 int mm_player_deactivate_section_repeat(MMHandleType player)
473 {
474         int result = MM_ERROR_NONE;
475
476         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
477
478         MMPLAYER_CMD_LOCK( player );
479
480         result = _mmplayer_deactivate_section_repeat(player);
481
482         MMPLAYER_CMD_UNLOCK( player );
483
484         return result;
485 }
486
487 int mm_player_gst_set_audio_channel(MMHandleType player, MMPlayerAudioChannel ch)
488 {
489         int result = MM_ERROR_NONE;
490
491         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
492         MMPLAYER_CMD_LOCK( player );
493
494         result = _mmplayer_gst_set_audio_channel(player, ch);
495
496         MMPLAYER_CMD_UNLOCK( player );
497         return result;
498 }
499
500 int mm_player_set_play_speed(MMHandleType player, float rate, bool streaming)
501 {
502         int result = MM_ERROR_NONE;
503
504         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
505
506         MMPLAYER_CMD_LOCK( player );
507
508         result = _mmplayer_set_playspeed(player, rate, streaming);
509
510         MMPLAYER_CMD_UNLOCK( player );
511
512         return result;
513 }
514
515 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
516 {
517         int result = MM_ERROR_NONE;
518
519         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
520
521         if (format >= MM_PLAYER_POS_FORMAT_NUM)
522         {
523                 LOGE("wrong format\n");
524                 return MM_ERROR_COMMON_INVALID_ARGUMENT;
525         }
526
527         MMPLAYER_CMD_LOCK( player );
528
529         result = _mmplayer_set_position(player, format, pos);
530
531         MMPLAYER_CMD_UNLOCK( player );
532
533         return result;
534 }
535
536 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, unsigned long *pos)
537 {
538         int result = MM_ERROR_NONE;
539
540         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
541         MMPLAYER_RETURN_VAL_IF_FAIL(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
542
543         if (format >= MM_PLAYER_POS_FORMAT_NUM)
544         {
545                 LOGE("wrong format\n");
546                 return MM_ERROR_COMMON_INVALID_ARGUMENT;
547         }
548
549         MMPLAYER_CMD_LOCK( player );
550
551         result = _mmplayer_get_position(player, (int)format, pos);
552
553         MMPLAYER_CMD_UNLOCK( player );
554
555         return result;
556 }
557
558 int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType format, unsigned long *start_pos, unsigned long *stop_pos)
559 {
560         int result = MM_ERROR_NONE;
561
562         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
563         MMPLAYER_RETURN_VAL_IF_FAIL(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
564
565         MMPLAYER_CMD_LOCK( player );
566
567         result = _mmplayer_get_buffer_position(player, (int)format, start_pos, stop_pos );
568
569         MMPLAYER_CMD_UNLOCK( player );
570
571         return result;
572 }
573
574 int mm_player_set_external_subtitle_path(MMHandleType player, const char* path)
575 {
576         int result = MM_ERROR_NONE;
577
578         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
579
580         MMPLAYER_CMD_LOCK( player );
581
582         result = _mmplayer_set_external_subtitle_path(player, path);
583
584         MMPLAYER_CMD_UNLOCK( player );
585         return result;
586 }
587
588 int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
589 {
590         int result = MM_ERROR_NONE;
591
592         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
593
594         if (format >= MM_PLAYER_POS_FORMAT_NUM)
595         {
596                 LOGE("wrong format(%d) \n", format);
597                 return MM_ERROR_INVALID_ARGUMENT;
598         }
599
600         MMPLAYER_CMD_LOCK( player );
601
602         result = _mmplayer_adjust_subtitle_postion(player, format, pos);
603
604         MMPLAYER_CMD_UNLOCK( player );
605
606         return result;
607 }
608
609 int mm_player_adjust_video_position(MMHandleType player, int offset)
610 {
611         int result = MM_ERROR_NONE;
612         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
613         MMPLAYER_CMD_LOCK( player );
614
615         result = _mmplayer_adjust_video_postion(player, offset);
616
617         MMPLAYER_CMD_UNLOCK( player );
618
619         return result;
620 }
621
622 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
623 {
624         int result = MM_ERROR_NONE;
625
626         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
627
628         MMPLAYER_CMD_LOCK( player );
629
630         result = _mmplayer_set_subtitle_silent(player, silent);
631
632         MMPLAYER_CMD_UNLOCK( player );
633
634         return result;
635 }
636
637 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
638 {
639         int result = MM_ERROR_NONE;
640
641         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
642
643         MMPLAYER_CMD_LOCK( player );
644
645         result = _mmplayer_get_subtitle_silent(player, silent);
646
647         MMPLAYER_CMD_UNLOCK( player );
648
649         return result;
650 }
651
652 int mm_player_set_attribute(MMHandleType player,  char **err_attr_name, const char *first_attribute_name, ...)
653 {
654         int result = MM_ERROR_NONE;
655         va_list var_args;
656
657         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
658         MMPLAYER_RETURN_VAL_IF_FAIL(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
659
660         va_start (var_args, first_attribute_name);
661         result = _mmplayer_set_attribute(player, err_attr_name, first_attribute_name, var_args);
662         va_end (var_args);
663
664         return result;
665 }
666
667 int mm_player_get_attribute(MMHandleType player,  char **err_attr_name, const char *first_attribute_name, ...)
668 {
669         int result = MM_ERROR_NONE;
670         va_list var_args;
671
672         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
673         MMPLAYER_RETURN_VAL_IF_FAIL(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
674
675         va_start (var_args, first_attribute_name);
676         result = _mmplayer_get_attribute(player, err_attr_name, first_attribute_name, var_args);
677         va_end (var_args);
678
679         return result;
680 }
681
682 int mm_player_get_attribute_info(MMHandleType player,  const char *attribute_name, MMPlayerAttrsInfo *info)
683 {
684         int result = MM_ERROR_NONE;
685
686
687         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
688         MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
689         MMPLAYER_RETURN_VAL_IF_FAIL(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
690
691         result = _mmplayer_get_attributes_info((MMHandleType)player, attribute_name, info);
692
693         return result;
694 }
695
696 int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *total_size)
697 {
698         int result = MM_ERROR_NONE;
699
700         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
701         MMPLAYER_RETURN_VAL_IF_FAIL(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
702         MMPLAYER_RETURN_VAL_IF_FAIL(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
703
704         result = _mmplayer_get_pd_downloader_status(player, current_pos, total_size);
705
706         return result;
707 }
708
709 int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType type, int *count)
710 {
711         int result = MM_ERROR_NONE;
712
713         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
714         MMPLAYER_RETURN_VAL_IF_FAIL(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
715
716         MMPLAYER_CMD_LOCK( player );
717
718         result = _mmplayer_get_track_count(player, type, count);
719
720         MMPLAYER_CMD_UNLOCK( player );
721
722         return result;
723 }
724
725 int mm_player_select_track(MMHandleType player, MMPlayerTrackType type, int index)
726 {
727         int result = MM_ERROR_NONE;
728
729         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
730
731         MMPLAYER_CMD_LOCK( player );
732
733         result = _mmplayer_select_track(player, type, index);
734
735         MMPLAYER_CMD_UNLOCK( player );
736
737         return result;
738 }
739 #ifdef _MULTI_TRACK
740 int mm_player_track_add_subtitle_language(MMHandleType player, int index)
741 {
742         int result = MM_ERROR_NONE;
743
744         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
745
746         MMPLAYER_CMD_LOCK( player );
747
748         result = _mmplayer_track_add_subtitle_language(player, index);
749
750         MMPLAYER_CMD_UNLOCK( player );
751
752         return result;
753 }
754
755 int mm_player_track_remove_subtitle_language(MMHandleType player, int index)
756 {
757         int result = MM_ERROR_NONE;
758
759         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
760
761         MMPLAYER_CMD_LOCK( player );
762
763         result = _mmplayer_track_remove_subtitle_language(player, index);
764
765         MMPLAYER_CMD_UNLOCK( player );
766
767         return result;
768
769 }
770 #endif
771 int mm_player_get_current_track(MMHandleType player, MMPlayerTrackType type, int *index)
772 {
773         int result = MM_ERROR_NONE;
774
775         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
776         MMPLAYER_RETURN_VAL_IF_FAIL(index, MM_ERROR_COMMON_INVALID_ARGUMENT);
777
778         MMPLAYER_CMD_LOCK( player );
779
780         result = _mmplayer_get_current_track(player, type, index);
781
782         MMPLAYER_CMD_UNLOCK( player );
783
784         return result;
785 }
786
787 int mm_player_get_track_language_code(MMHandleType player,  MMPlayerTrackType type, int index, char **code)
788 {
789         int result = MM_ERROR_NONE;
790
791         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
792
793         MMPLAYER_CMD_LOCK( player );
794
795         result = _mmplayer_get_track_language_code(player, type, index, code);
796
797         MMPLAYER_CMD_UNLOCK( player );
798
799         return result;
800 }
801
802 int mm_player_set_display_zoom(MMHandleType player, float level, int x, int y)
803 {
804         int result = MM_ERROR_NONE;
805
806         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
807
808         MMPLAYER_CMD_LOCK( player );
809
810         result = _mmplayer_set_display_zoom(player, level, x, y);
811
812         MMPLAYER_CMD_UNLOCK( player );
813
814         return result;
815 }
816
817 int mm_player_get_display_zoom(MMHandleType player, float *level, int *x, int *y)
818 {
819         int result = MM_ERROR_NONE;
820
821         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
822         MMPLAYER_RETURN_VAL_IF_FAIL(level, MM_ERROR_COMMON_INVALID_ARGUMENT);
823
824         MMPLAYER_CMD_LOCK( player );
825
826         result = _mmplayer_get_display_zoom(player, level, x, y);
827
828         MMPLAYER_CMD_UNLOCK( player );
829
830         return result;
831 }
832
833 int mm_player_set_video_share_master_clock(MMHandleType player,
834                                                 long long clock,
835                                                 long long clock_delta,
836                                                 long long video_time,
837                                                 long long media_clock,
838                                                 long long audio_time)
839 {
840         int result = MM_ERROR_NONE;
841
842         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
843
844         MMPLAYER_CMD_LOCK( player );
845
846         result = _mmplayer_set_video_share_master_clock(player, clock, clock_delta, video_time, media_clock, audio_time);
847
848         MMPLAYER_CMD_UNLOCK( player );
849
850         return result;
851 }
852
853 int mm_player_get_video_share_master_clock(MMHandleType player,
854                                                 long long *video_time,
855                                                 long long *media_clock,
856                                                 long long *audio_time)
857 {
858         int result = MM_ERROR_NONE;
859
860         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
861         MMPLAYER_RETURN_VAL_IF_FAIL(video_time, MM_ERROR_COMMON_INVALID_ARGUMENT);
862         MMPLAYER_RETURN_VAL_IF_FAIL(media_clock, MM_ERROR_COMMON_INVALID_ARGUMENT);
863         MMPLAYER_RETURN_VAL_IF_FAIL(audio_time, MM_ERROR_COMMON_INVALID_ARGUMENT);
864
865         MMPLAYER_CMD_LOCK( player );
866
867         result = _mmplayer_get_video_share_master_clock(player, video_time, media_clock, audio_time);
868
869         MMPLAYER_CMD_UNLOCK( player );
870
871         return result;
872 }
873
874 int mm_player_get_video_rotate_angle(MMHandleType player, int *angle)
875 {
876         int result = MM_ERROR_NONE;
877
878         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
879         MMPLAYER_RETURN_VAL_IF_FAIL(angle, MM_ERROR_COMMON_INVALID_ARGUMENT);
880
881         MMPLAYER_CMD_LOCK( player );
882
883         result = _mmplayer_get_video_rotate_angle(player, angle);
884
885         MMPLAYER_CMD_UNLOCK( player );
886
887         return result;
888 }
889
890 int mm_player_set_video_hub_download_mode(MMHandleType player, bool mode)
891 {
892         int result = MM_ERROR_NONE;
893
894         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
895
896         MMPLAYER_CMD_LOCK( player );
897
898         result = _mmplayer_set_video_hub_download_mode(player, mode);
899
900         MMPLAYER_CMD_UNLOCK( player );
901
902         return result;
903 }
904
905 int mm_player_enable_sync_handler(MMHandleType player, bool enable)
906 {
907         int result = MM_ERROR_NONE;
908
909         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
910
911         MMPLAYER_CMD_LOCK( player );
912
913         result = _mmplayer_enable_sync_handler(player, enable);
914
915         MMPLAYER_CMD_UNLOCK( player );
916
917         return result;
918 }
919
920 int mm_player_set_uri(MMHandleType player, const char *uri)
921 {
922         int result = MM_ERROR_NONE;
923
924         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
925
926         MMPLAYER_CMD_LOCK( player );
927
928         result = _mmplayer_set_uri(player, uri);
929
930         MMPLAYER_CMD_UNLOCK( player );
931
932         return result;
933
934 }
935
936 int mm_player_set_next_uri(MMHandleType player, const char *uri)
937 {
938         int result = MM_ERROR_NONE;
939
940         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
941
942         MMPLAYER_CMD_LOCK( player );
943
944         result = _mmplayer_set_next_uri(player, uri, FALSE);
945
946         MMPLAYER_CMD_UNLOCK( player );
947
948         return result;
949
950 }
951
952 int mm_player_get_next_uri(MMHandleType player, char **uri)
953 {
954         int result = MM_ERROR_NONE;
955
956         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
957
958         MMPLAYER_CMD_LOCK( player );
959
960         result = _mmplayer_get_next_uri(player, uri);
961
962         MMPLAYER_CMD_UNLOCK( player );
963
964         return result;
965
966 }
967 #ifdef _MULTI_TRACK
968 int mm_player_track_foreach_selected_subtitle_language(MMHandleType player, mm_player_track_selected_subtitle_language_callback callback, void *user_param)
969 {
970         int result = MM_ERROR_NONE;
971
972         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
973
974         MMPLAYER_CMD_LOCK( player );
975
976         result = _mmplayer_track_foreach_selected_subtitle_language(player, callback, user_param);
977
978         MMPLAYER_CMD_UNLOCK( player );
979
980         return result;
981 }
982 #endif
983
984 int mm_player_has_closed_caption(MMHandleType player, bool *exist)
985 {
986         int result = MM_ERROR_NONE;
987
988         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
989         MMPLAYER_RETURN_VAL_IF_FAIL(exist, MM_ERROR_INVALID_ARGUMENT);
990
991         MMPLAYER_CMD_LOCK( player );
992
993         result = _mmplayer_has_closed_caption(player, exist);
994
995         MMPLAYER_CMD_UNLOCK( player );
996
997         return result;
998 }
999
1000 void * mm_player_media_packet_video_stream_internal_buffer_ref(void *buffer)
1001 {
1002         void * result;
1003         result = _mm_player_media_packet_video_stream_internal_buffer_ref(buffer);
1004
1005         return result;
1006 }
1007
1008 void mm_player_media_packet_video_stream_internal_buffer_unref(void *buffer)
1009 {
1010         _mm_player_media_packet_video_stream_internal_buffer_unref(buffer);
1011 }
1012
1013 int mm_player_submit_packet(MMHandleType player, media_packet_h packet)
1014 {
1015
1016         int result = MM_ERROR_NONE;
1017
1018         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1019
1020         /* no lock here, otherwise callback for the "need-data" signal of appsrc will be blocking */
1021         //MMPLAYER_CMD_LOCK( player );
1022
1023         result = _mmplayer_submit_packet(player, packet);
1024
1025         //MMPLAYER_CMD_UNLOCK( player );
1026
1027         return result;
1028 }
1029
1030 int mm_player_set_video_info (MMHandleType player, media_format_h format)
1031 {
1032         int result = MM_ERROR_NONE;
1033
1034         LOGD("\n");
1035
1036         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1037
1038         MMPLAYER_CMD_LOCK( player );
1039
1040         result = _mmplayer_set_video_info(player, format);
1041
1042         MMPLAYER_CMD_UNLOCK( player );
1043
1044         return result;
1045
1046 }
1047
1048 int mm_player_set_audio_info (MMHandleType player, media_format_h format)
1049 {
1050         int result = MM_ERROR_NONE;
1051
1052         LOGD("\n");
1053
1054         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1055
1056         MMPLAYER_CMD_LOCK( player );
1057
1058         result = _mmplayer_set_audio_info(player, format);
1059
1060         MMPLAYER_CMD_UNLOCK( player );
1061
1062         return result;
1063 }
1064
1065 int mm_player_set_subtitle_info (MMHandleType player, MMPlayerSubtitleStreamInfo *subtitle_stream_info)
1066 {
1067         int result = MM_ERROR_NONE;
1068
1069         LOGD("\n");
1070
1071         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1072
1073         MMPLAYER_CMD_LOCK( player );
1074
1075         result = _mmplayer_set_subtitle_info(player, subtitle_stream_info);
1076
1077         MMPLAYER_CMD_UNLOCK( player );
1078
1079         return result;
1080 }
1081
1082 int mm_player_set_media_stream_buffer_max_size(MMHandleType player, MMPlayerStreamType type, unsigned long long max_size)
1083 {
1084         int result = MM_ERROR_NONE;
1085
1086         LOGD("\n");
1087
1088         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1089
1090         MMPLAYER_CMD_LOCK( player );
1091
1092         result = _mmplayer_set_media_stream_max_size(player, type, max_size);
1093
1094         MMPLAYER_CMD_UNLOCK( player );
1095
1096         return result;
1097 }
1098
1099 int mm_player_get_media_stream_buffer_max_size(MMHandleType player, MMPlayerStreamType type, unsigned long long *max_size)
1100 {
1101         int result = MM_ERROR_NONE;
1102         guint64 _max_size = 0;
1103
1104         LOGD("\n");
1105
1106         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1107         MMPLAYER_RETURN_VAL_IF_FAIL(max_size, MM_ERROR_INVALID_ARGUMENT);
1108
1109         MMPLAYER_CMD_LOCK( player );
1110
1111         result = _mmplayer_get_media_stream_max_size(player, type, &_max_size);
1112         *max_size = _max_size;
1113
1114         MMPLAYER_CMD_UNLOCK( player );
1115
1116         return result;
1117 }
1118
1119 int mm_player_set_media_stream_buffer_min_percent(MMHandleType player, MMPlayerStreamType type, unsigned min_percent)
1120 {
1121         int result = MM_ERROR_NONE;
1122
1123         LOGD("\n");
1124
1125         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1126
1127         MMPLAYER_CMD_LOCK( player );
1128
1129         result = _mmplayer_set_media_stream_min_percent(player, type, min_percent);
1130
1131         MMPLAYER_CMD_UNLOCK( player );
1132
1133         return result;
1134 }
1135
1136 int mm_player_get_media_stream_buffer_min_percent(MMHandleType player, MMPlayerStreamType type, unsigned int *min_percent)
1137 {
1138         int result = MM_ERROR_NONE;
1139
1140         LOGD("\n");
1141
1142         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1143         MMPLAYER_RETURN_VAL_IF_FAIL(min_percent, MM_ERROR_INVALID_ARGUMENT);
1144
1145         MMPLAYER_CMD_LOCK( player );
1146
1147         result = _mmplayer_get_media_stream_min_percent(player, type, min_percent);
1148
1149         MMPLAYER_CMD_UNLOCK( player );
1150
1151         return result;
1152 }
1153
1154 int mm_player_set_media_stream_buffer_status_callback(MMHandleType player, MMPlayerStreamType type, mm_player_media_stream_buffer_status_callback callback, void * user_param)
1155 {
1156         int result = MM_ERROR_NONE;
1157
1158         LOGD("\n");
1159
1160         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1161
1162         MMPLAYER_CMD_LOCK( player );
1163
1164         result = _mmplayer_set_media_stream_buffer_status_cb(player, type, callback, user_param);
1165
1166         MMPLAYER_CMD_UNLOCK( player );
1167
1168         return result;
1169 }
1170
1171 int mm_player_set_media_stream_seek_data_callback(MMHandleType player, MMPlayerStreamType type, mm_player_media_stream_seek_data_callback callback, void * user_param)
1172 {
1173         int result = MM_ERROR_NONE;
1174
1175         LOGD("\n");
1176
1177         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1178
1179         MMPLAYER_CMD_LOCK( player );
1180
1181         result = _mmplayer_set_media_stream_seek_data_cb(player, type, callback, user_param);
1182
1183         MMPLAYER_CMD_UNLOCK( player );
1184
1185         return result;
1186 }
1187
1188 int mm_player_set_audio_stream_changed_callback(MMHandleType player, mm_player_stream_changed_callback callback, void *user_param)
1189 {
1190         int result = MM_ERROR_NONE;
1191
1192         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1193
1194         MMPLAYER_CMD_LOCK( player );
1195
1196         result = _mmplayer_set_audiostream_changed_cb(player, callback, user_param);
1197
1198         MMPLAYER_CMD_UNLOCK( player );
1199
1200         return result;
1201 }
1202
1203 int mm_player_set_video_stream_changed_callback(MMHandleType player, mm_player_stream_changed_callback callback, void *user_param)
1204 {
1205         int result = MM_ERROR_NONE;
1206
1207         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1208
1209         MMPLAYER_CMD_LOCK( player );
1210
1211         result = _mmplayer_set_videostream_changed_cb(player, callback, user_param);
1212
1213         MMPLAYER_CMD_UNLOCK( player );
1214
1215         return result;
1216 }
1217
1218 int mm_player_set_pcm_spec(MMHandleType player, int samplerate, int channel)
1219 {
1220         int result = MM_ERROR_NONE;
1221
1222         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1223
1224         MMPLAYER_CMD_LOCK( player );
1225
1226         result = _mmplayer_set_pcm_spec(player, samplerate, channel);
1227
1228         MMPLAYER_CMD_UNLOCK( player );
1229
1230         return result;
1231 }
1232
1233 int mm_player_get_timeout(MMHandleType player, int *timeout)
1234 {
1235         int result = MM_ERROR_NONE;
1236
1237         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1238         MMPLAYER_RETURN_VAL_IF_FAIL(timeout, MM_ERROR_COMMON_INVALID_ARGUMENT);
1239
1240         MMPLAYER_CMD_LOCK( player );
1241
1242         result = _mmplayer_get_timeout(player, timeout);
1243
1244         MMPLAYER_CMD_UNLOCK( player );
1245
1246         return result;
1247 }
1248
1249 int mm_player_get_num_of_video_out_buffers(MMHandleType player, int *num, int *extra_num)
1250 {
1251         int result = MM_ERROR_NONE;
1252
1253         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1254         MMPLAYER_RETURN_VAL_IF_FAIL(num && extra_num, MM_ERROR_COMMON_INVALID_ARGUMENT);
1255
1256         MMPLAYER_CMD_LOCK( player );
1257
1258         result = _mmplayer_get_num_of_video_out_buffers(player, num, extra_num);
1259
1260         MMPLAYER_CMD_UNLOCK( player );
1261
1262         return result;
1263 }
1264
1265 int mm_player_set_media_stream_dynamic_resolution(MMHandleType player, bool drc)
1266 {
1267         int result = MM_ERROR_NONE;
1268
1269         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1270
1271         MMPLAYER_CMD_LOCK( player );
1272
1273         result = _mmplayer_set_media_stream_dynamic_resolution(player, drc);
1274
1275         MMPLAYER_CMD_UNLOCK( player );
1276
1277         return result;
1278 }
1279
1280 int mm_player_release_video_stream_bo(MMHandleType player, void* bo)
1281 {
1282         int result = MM_ERROR_NONE;
1283
1284         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1285         MMPLAYER_RETURN_VAL_IF_FAIL(bo, MM_ERROR_COMMON_INVALID_ARGUMENT);
1286 //      MMPLAYER_CMD_LOCK( player );
1287
1288         result = _mmplayer_video_stream_release_bo(player, bo);
1289
1290 //      MMPLAYER_CMD_UNLOCK( player );
1291         return result;
1292 }
1293
1294 int mm_player_set_file_buffering_path(MMHandleType player, const char *file_path)
1295 {
1296         int result = MM_ERROR_NONE;
1297
1298         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
1299
1300         MMPLAYER_CMD_LOCK( player );
1301
1302         result = _mmplayer_set_file_buffering_path(player, file_path);
1303
1304         MMPLAYER_CMD_UNLOCK( player );
1305
1306         return result;
1307 }