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