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