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