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