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