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