[0.6.188] refactoring the resource managing code
[platform/core/multimedia/libmm-player.git] / src / include / mm_player_priv.h
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 #ifndef __MM_PLAYER_PRIV_H__
24 #define __MM_PLAYER_PRIV_H__
25
26 /*===========================================================================================
27 |                                                                                                                                                                                       |
28 |  INCLUDE FILES                                                                                                                                                        |
29 |                                                                                                                                                                               |
30 ========================================================================================== */
31 #include <glib.h>
32 #include <gst/gst.h>
33 #include <mm_attrs.h>
34 #include <math.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <tbm_bufmgr.h>
40 #include <storage.h>
41 #include "mm_player.h"
42 #include "mm_player_audioeffect.h"
43 #include "mm_message.h"
44 #include "mm_player_ini.h"
45 #include <mm_resource_manager.h>
46 #include "mm_player_streaming.h"
47
48 /*===========================================================================================
49 |                                                                                                                                                                                       |
50 |  GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE                                                                                       |
51 |                                                                                                                                                                                       |
52 ========================================================================================== */
53
54 /*---------------------------------------------------------------------------
55 |    GLOBAL #defines:                                                                                                           |
56 ---------------------------------------------------------------------------*/
57 #define MM_PLAYER_IMGB_MPLANE_MAX       4
58 #define MM_PLAYER_STREAM_COUNT_MAX      3
59
60 #define MM_PLAYER_CAST(x_player)                ((mmplayer_t *)(x_player))
61 /**
62  * @x_player: MMHandleType of player
63  *
64  * Get the attributes handle of this player.
65  */
66 #define MM_PLAYER_GET_ATTRS(x_player)   (MM_PLAYER_CAST(x_player)->attrs)
67
68 #define MM_MAX_STRING_LENGTH    4000 /* have to be less than MUSE_MSG_MAX_LENGTH */
69
70 #define VIDEO360_MAX_ZOOM       10.0f
71
72 /*---------------------------------------------------------------------------
73 |    GLOBAL CONSTANT DEFINITIONS:                                                                                       |
74 ---------------------------------------------------------------------------*/
75 enum latency_mode {
76         AUDIO_LATENCY_MODE_LOW = 0,     /**< Low audio latency mode */
77         AUDIO_LATENCY_MODE_MID,         /**< Middle audio latency mode */
78         AUDIO_LATENCY_MODE_HIGH,        /**< High audio latency mode */
79 };
80
81 enum tag_info {
82         TAG_AUDIO_CODEC = 0x0001,
83         TAG_VIDEO_CODEC = 0x0002,
84         TAG_ARTIST              = 0x0004,
85         TAG_TITLE               = 0x0008,
86         TAG_ALBUM               = 0x0010,
87         TAG_GENRE               = 0x0020,
88         TAG_COPYRIGHT   = 0x0040,
89         TAG_DATE                = 0x0080,
90         TAG_DESCRIPTION = 0x0100,
91         TAG_TRACK_NUMBER = 0x0200
92 };
93
94 enum content_attr_flag {
95         ATTR_MISSING_ONLY = 0x0001,
96         ATTR_DURATION = 0x0002,
97         ATTR_AUDIO  = 0x0004,
98         ATTR_VIDEO = 0x0008,
99         ATTR_BITRATE = 0x0010,
100         ATTR_ALL = 0x0020,
101 };
102
103 enum mmplayer_sink_type {
104         MMPLAYER_VIDEO_SINK = 0x01,
105         MMPLAYER_AUDIO_SINK = 0x02,
106         MMPLAYER_TEXT_SINK = 0x04,
107         MMPLAYER_SINK_ALL = 0x07,
108 };
109
110 /**
111  * Enumerations of Player Uri type
112  */
113 enum mmplayer_uri_type {
114         MM_PLAYER_URI_TYPE_NONE,                        /**< Player URI type None */
115         MM_PLAYER_URI_TYPE_URL_RTSP,            /**< Player URI type RTSP */
116         MM_PLAYER_URI_TYPE_URL_HTTP,            /**< Player URI type HTTP */
117         MM_PLAYER_URI_TYPE_URL_MMS,                     /**< Player URI type MMS */
118         MM_PLAYER_URI_TYPE_MEM,                         /**< Player URI type Mem */
119         MM_PLAYER_URI_TYPE_FILE,                        /**< Player URI type File */
120         MM_PLAYER_URI_TYPE_URL,                         /**< Player URI type URL */
121         MM_PLAYER_URI_TYPE_MS_BUFF,                     /**< Player URI type Media Stream Buffer */
122         MM_PLAYER_URI_TYPE_HLS,                         /**< Player URI type http live streaming */
123         MM_PLAYER_URI_TYPE_SS,                          /**< Player URI type Smooth streaming */
124         MM_PLAYER_URI_TYPE_DASH,                        /**< Player URI type Mpeg Dash */
125         MM_PLAYER_URI_TYPE_NO_PERMISSION,       /**< Player URI type No Permission  */
126         MM_PLAYER_URI_TYPE_TEMP,                        /**< Player URI type Temp */
127 };
128
129 typedef enum {
130         MISSING_PLUGIN_NONE = 0x00,
131         MISSING_PLUGIN_AUDIO = 0x01,
132         MISSING_PLUGIN_VIDEO = 0x02
133 } missing_codec_e;
134
135
136 typedef enum {
137         FOUND_PLUGIN_NONE = 0x00,
138         FOUND_PLUGIN_AUDIO = 0x01,
139         FOUND_PLUGIN_VIDEO = 0x02
140 } found_codec_e;
141
142 /**
143  * Enumeration of signal type
144  */
145 typedef enum {
146         MM_PLAYER_SIGNAL_TYPE_AUTOPLUG = 0,
147         MM_PLAYER_SIGNAL_TYPE_VIDEOBIN,
148         MM_PLAYER_SIGNAL_TYPE_AUDIOBIN,
149         MM_PLAYER_SIGNAL_TYPE_TEXTBIN,
150         MM_PLAYER_SIGNAL_TYPE_OTHERS,
151         MM_PLAYER_SIGNAL_TYPE_ALL,
152         MM_PLAYER_SIGNAL_TYPE_MAX = MM_PLAYER_SIGNAL_TYPE_ALL,
153 } mmplayer_signal_type_e;
154
155 /* main pipeline's element id */
156 typedef enum {
157         MMPLAYER_M_PIPE = 0, /* NOTE : MMPLAYER_M_PIPE should be zero */
158         MMPLAYER_M_SRC,
159         MMPLAYER_M_2ND_SRC,     /* 2nd Source Element for es buff src */
160         MMPLAYER_M_SUBSRC,
161
162         /* it could be a decodebin or could be a typefind. depends on player ini */
163         MMPLAYER_M_TYPEFIND,
164         MMPLAYER_M_AUTOPLUG,
165
166         MMPLAYER_M_AUTOPLUG_V_DEC,
167         MMPLAYER_M_AUTOPLUG_A_DEC,
168
169         /*fakesink will hold whole pipeline state. */
170         MMPLAYER_M_SRC_FAKESINK,
171
172         /* streaming plugin */
173         MMPLAYER_M_MUXED_S_BUFFER,
174         MMPLAYER_M_DEMUXED_S_BUFFER,
175         MMPLAYER_M_ID3DEMUX,
176         MMPLAYER_M_ADAPTIVE_DEMUX,
177
178         /* es buff src queue */
179         MMPLAYER_M_V_BUFFER,
180         MMPLAYER_M_A_BUFFER,
181         MMPLAYER_M_S_BUFFER,
182
183         /* FIXIT : if there's really no usage for following IDs. remove it */
184         MMPLAYER_M_DEC1,
185         MMPLAYER_M_DEC2,
186         MMPLAYER_M_Q1,
187         MMPLAYER_M_Q2,
188         MMPLAYER_M_DEMUX,
189         MMPLAYER_M_SUBPARSE,
190         MMPLAYER_M_V_INPUT_SELECTOR,    // video input_select
191         MMPLAYER_M_A_INPUT_SELECTOR,    // audio input_select
192         MMPLAYER_M_T_INPUT_SELECTOR,    // text input_select
193         MMPLAYER_M_NUM
194 } main_element_id_e;
195
196 /* audio pipeline's element id */
197 enum audio_element_id {
198         MMPLAYER_A_BIN = 0, /* NOTE : MMPLAYER_A_BIN should be zero */
199         MMPLAYER_A_CONV,
200         MMPLAYER_A_VOL,
201         MMPLAYER_A_FILTER,
202         MMPLAYER_A_FILTER_SEC,
203         MMPLAYER_A_CONV_BFORMAT,
204         MMPLAYER_A_CAPS_360,
205         MMPLAYER_A_SINK,
206         MMPLAYER_A_RESAMPLER,
207         MMPLAYER_A_RGVOL,
208         MMPLAYER_A_CONV_PITCH,
209         MMPLAYER_A_PITCH,
210         MMPLAYER_A_TEE,
211         MMPLAYER_A_TEE_Q1,
212         MMPLAYER_A_TEE_Q2,
213         MMPLAYER_A_EXTRACT_CONV,
214         MMPLAYER_A_EXTRACT_RESAMPLER,
215         MMPLAYER_A_EXTRACT_CAPS,
216         MMPLAYER_A_EXTRACT_DEINTERLEAVE,
217         MMPLAYER_A_EXTRACT_SINK,
218         MMPLAYER_A_NUM
219 };
220
221 /* video pipeline's element id */
222 enum video_element_id {
223         MMPLAYER_V_BIN = 0, /* NOTE : MMPLAYER_V_BIN should be zero */
224         MMPLAYER_V_CONV,
225         MMPLAYER_V_CAPS,
226         MMPLAYER_V_SINK,
227         MMPLAYER_V_360,
228         MMPLAYER_V_NUM
229 };
230
231 /* text pipeline's element id */
232 enum text_element_id {
233         MMPLAYER_T_BIN = 0, /* NOTE : MMPLAYER_V_BIN should be zero */
234         MMPLAYER_T_QUEUE,
235         MMPLAYER_T_VIDEO_QUEUE,
236         MMPLAYER_T_VIDEO_CONVERTER,
237         MMPLAYER_T_OVERLAY,
238         MMPLAYER_T_FAKE_SINK,
239         MMPLAYER_T_IDENTITY,
240         MMPLAYER_T_NUM
241 };
242
243 typedef enum {
244         MMPLAYER_COMMAND_NONE,
245         MMPLAYER_COMMAND_CREATE,
246         MMPLAYER_COMMAND_DESTROY,
247         MMPLAYER_COMMAND_UNREALIZE,
248         MMPLAYER_COMMAND_START,
249         MMPLAYER_COMMAND_REALIZE,
250         MMPLAYER_COMMAND_STOP,
251         MMPLAYER_COMMAND_PAUSE,
252         MMPLAYER_COMMAND_RESUME,
253         MMPLAYER_COMMAND_NUM
254 } mmplayer_command_state_e;
255
256 /* Note : mmplayer_streaming_src_error is error enum for streaming source which post error message
257  *      using custom message made by itself. The enum value must start with zero,
258  *      because the streaming source(secrtspsrc) also does.
259  */
260 enum mmplayer_streaming_src_error {
261         MMPLAYER_STREAMING_ERROR_NONE = 0,
262         MMPLAYER_STREAMING_ERROR_UNSUPPORTED_AUDIO,
263         MMPLAYER_STREAMING_ERROR_UNSUPPORTED_VIDEO,
264         MMPLAYER_STREAMING_ERROR_CONNECTION_FAIL,
265         MMPLAYER_STREAMING_ERROR_DNS_FAIL,
266         MMPLAYER_STREAMING_ERROR_SERVER_DISCONNECTED,
267         MMPLAYER_STREAMING_ERROR_BAD_SERVER,
268         MMPLAYER_STREAMING_ERROR_INVALID_PROTOCOL,
269         MMPLAYER_STREAMING_ERROR_INVALID_URL,
270         MMPLAYER_STREAMING_ERROR_UNEXPECTED_MSG,
271         MMPLAYER_STREAMING_ERROR_OUT_OF_MEMORIES,
272         MMPLAYER_STREAMING_ERROR_RTSP_TIMEOUT,
273         MMPLAYER_STREAMING_ERROR_BAD_REQUEST,
274         MMPLAYER_STREAMING_ERROR_NOT_AUTHORIZED,
275         MMPLAYER_STREAMING_ERROR_PAYMENT_REQUIRED,
276         MMPLAYER_STREAMING_ERROR_FORBIDDEN,
277         MMPLAYER_STREAMING_ERROR_CONTENT_NOT_FOUND,
278         MMPLAYER_STREAMING_ERROR_METHOD_NOT_ALLOWED,
279         MMPLAYER_STREAMING_ERROR_NOT_ACCEPTABLE,
280         MMPLAYER_STREAMING_ERROR_PROXY_AUTHENTICATION_REQUIRED,
281         MMPLAYER_STREAMING_ERROR_SERVER_TIMEOUT,
282         MMPLAYER_STREAMING_ERROR_GONE,
283         MMPLAYER_STREAMING_ERROR_LENGTH_REQUIRED,
284         MMPLAYER_STREAMING_ERROR_PRECONDITION_FAILED,
285         MMPLAYER_STREAMING_ERROR_REQUEST_ENTITY_TOO_LARGE,
286         MMPLAYER_STREAMING_ERROR_REQUEST_URI_TOO_LARGE,
287         MMPLAYER_STREAMING_ERROR_UNSUPPORTED_MEDIA_TYPE,
288         MMPLAYER_STREAMING_ERROR_PARAMETER_NOT_UNDERSTOOD,
289         MMPLAYER_STREAMING_ERROR_CONFERENCE_NOT_FOUND,
290         MMPLAYER_STREAMING_ERROR_NOT_ENOUGH_BANDWIDTH,
291         MMPLAYER_STREAMING_ERROR_NO_SESSION_ID,
292         MMPLAYER_STREAMING_ERROR_METHOD_NOT_VALID_IN_THIS_STATE,
293         MMPLAYER_STREAMING_ERROR_HEADER_FIELD_NOT_VALID_FOR_SOURCE,
294         MMPLAYER_STREAMING_ERROR_INVALID_RANGE,
295         MMPLAYER_STREAMING_ERROR_PARAMETER_IS_READONLY,
296         MMPLAYER_STREAMING_ERROR_AGGREGATE_OP_NOT_ALLOWED,
297         MMPLAYER_STREAMING_ERROR_ONLY_AGGREGATE_OP_ALLOWED,
298         MMPLAYER_STREAMING_ERROR_BAD_TRANSPORT,
299         MMPLAYER_STREAMING_ERROR_DESTINATION_UNREACHABLE,
300         MMPLAYER_STREAMING_ERROR_INTERNAL_SERVER_ERROR,
301         MMPLAYER_STREAMING_ERROR_NOT_IMPLEMENTED,
302         MMPLAYER_STREAMING_ERROR_BAD_GATEWAY,
303         MMPLAYER_STREAMING_ERROR_SERVICE_UNAVAILABLE,
304         MMPLAYER_STREAMING_ERROR_GATEWAY_TIME_OUT       ,
305         MMPLAYER_STREAMING_ERROR_RTSP_VERSION_NOT_SUPPORTED,
306         MMPLAYER_STREAMING_ERROR_OPTION_NOT_SUPPORTED,
307 };
308
309 typedef enum {
310         MMPLAYER_SEEK_NONE = 0,
311         MMPLAYER_SEEK_IN_PROGRESS,
312         MMPLAYER_SEEK_COMPLETED,        /* after getting async done but before posting seek complete */
313 } mmplayer_seek_state_e;
314
315 typedef enum {
316         MMPLAYER_PATH_VOD = 0,
317         MMPLAYER_PATH_TEXT,
318         MMPLAYER_PATH_MAX
319 } mmplayer_path_type_e;
320
321 /* Video360 related enums. These are duplication from video360.h from
322  * gst-plugins-tizen.
323  * */
324 typedef enum {
325         VIDEO360_MODE_UNKNOWN = -1,
326         VIDEO360_MODE_MONOSCOPIC = 0,
327         VIDEO360_MODE_STEREOSCOPIC_TOP_BOTTOM = 1,
328         VIDEO360_MODE_STEREOSCOPIC_LEFT_RIGHT = 2,
329         VIDEO360_MODE_STEREOSCOPIC_STEREO_MESH = 3,
330         VIDEO360_MODE_LAST_ITEM
331 } mmplayer_stereo_mode_e;
332
333 typedef enum {
334         VIDEO360_PROJECTION_TYPE_UNKNOWN = -1,
335         VIDEO360_PROJECTION_TYPE_EQUIRECTANGULAR = 0,
336         VIDEO360_PROJECTION_TYPE_CUBEMAP = 1,
337         VIDEO360_PROJECTION_TYPE_MESH = 2,
338         VIDEO360_PROJECTION_TYPE_LAST_ITEM
339 } mmplayer_projection_type_e;
340
341 /* Spatial audio related enums. These are duplication from mm_file.h from
342  * libmm-fileinfo.
343  * */
344 typedef enum {
345         MMFILE_AMBISONIC_TYPE_UNKNOWN = 0,
346         MMFILE_AMBISONIC_TYPE_PERIPHONIC = 1,           /**< To comply with Google's Spatial Audio RFC*/
347         MMFILE_AMBISONIC_TYPE_NON_PERIPHONIC = 2,
348 } mmfile_ambisonic_type_e;
349
350 typedef enum {
351         MMFILE_AMBISONIC_FORMAT_UNKNOWN = 0,
352         MMFILE_AMBISONIC_FORMAT_AMBIX = 1,              /**< AMBIX (Channel sequence: ACN, Normalization: SN3D) */
353         MMFILE_AMBISONIC_FORMAT_AMB = 2,                /**< .AMB, Tetraproc (Channel sequence: FuMa, Normalization: FuMa) */
354         MMFILE_AMBISONIC_FORMAT_UA = 3,                 /**< Universal Ambisonics (Channel sequence: SID, Normalization: N3D) */
355 } mmfile_ambisonic_format_e;
356
357 typedef enum {
358         MMFILE_AMBISONIC_ORDER_UNKNOWN = 0,
359         MMFILE_AMBISONIC_ORDER_FOA = 1,                 /**< First order Ambisonics */
360         MMFILE_AMBISONIC_ORDER_SOA = 2,                 /**< Second order Ambisonics */
361         MMFILE_AMBISONIC_ORDER_TOA = 3,                 /**< Third order Ambisonics */
362 } mmfile_ambisonic_order_e;
363
364 typedef enum {
365         MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER,
366         MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY,
367         /* FIXME: need to add MMPLAYER_RESOURCE_TYPE_AUDIO_OFFLOAD */
368         MMPLAYER_RESOURCE_TYPE_MAX,
369 } mmplayer_resource_type_e;
370
371 /*---------------------------------------------------------------------------
372 |    GLOBAL DATA TYPE DEFINITIONS:                                                                                      |
373 ---------------------------------------------------------------------------*/
374
375 typedef struct {
376         int id;
377         GstElement *gst;
378 } mmplayer_gst_element_t;
379
380 typedef struct {
381         GstTagList *tag_list;
382         mmplayer_gst_element_t *mainbin;
383         mmplayer_gst_element_t *audiobin;
384         mmplayer_gst_element_t *videobin;
385         mmplayer_gst_element_t *textbin;
386 } mmplayer_pipeline_info_t;
387
388 typedef struct {
389         float volume;
390         bool mute;
391         bool rg_enable;
392 } mmplayer_sound_info_t;
393
394 typedef struct {
395         char *buf;
396         int len;
397         int offset;
398 } mmplayer_input_buffer_t;
399
400 typedef struct {
401         int uri_type;
402         mmplayer_input_buffer_t input_mem;
403         char uri[MM_MAX_URL_LEN];
404         char urgent[MM_MAX_FILENAME_LEN];
405 } mmplayer_parse_profile_t;
406
407 typedef struct {
408         storage_type_e type;
409         storage_state_e state;
410         int id;
411         char path[MM_MAX_URL_LEN];
412 } mmplayer_storage_info_t;
413
414 typedef struct {
415         bool is_pending;
416         gint64 pos;
417 } mmplayer_pending_seek_t;
418
419 typedef struct {
420         GObject *obj;
421         gulong sig;
422 } mmplayer_signal_item_t;
423
424 typedef struct {
425         bool rich_audio;
426         bool video_zc; // video zero-copy
427         bool subtitle_off;
428         bool video_export;
429 } mmplayer_setting_mode_t; /* FIXME: renaming */
430
431 typedef struct {
432         GMainContext *global_default;
433         GMainContext *thread_default;
434 } mmplayer_context_info_t;
435
436 typedef struct {
437         gint uri_idx;
438         GList *uri_list;
439 } mmplayer_uri_list_t;
440
441 typedef struct {
442         double scale_x;
443         double scale_y;
444         double scale_width;
445         double scale_height;
446 } mmplayer_video_roi_t;
447
448 typedef struct {
449         gint active_pad_index;
450         gint total_track_num;
451         GPtrArray *channels;
452         gulong block_id;
453         gulong event_probe_id;
454 } mmplayer_selector_t;
455
456 typedef struct {
457         gboolean running;
458
459         gboolean stream_changed;
460         gboolean reconfigure;
461
462         GstClockTime start_time[MM_PLAYER_TRACK_TYPE_MAX];      /* updated once get SEGMENT event */
463         GstSegment segment[MM_PLAYER_TRACK_TYPE_MAX];
464         gboolean update_segment[MM_PLAYER_TRACK_TYPE_MAX];
465
466 } mmplayer_gapless_t;
467
468 typedef struct {
469         int channel;
470         int bitrate;
471         int depth;
472         bool is_little_endian;
473         guint64 channel_mask;
474         void *pcm_data;
475         int data_size;
476         int buff_size;
477         media_format_mimetype_e pcm_format;
478 } mmplayer_audio_stream_buff_t;
479
480 /**
481  * @brief data of video_bo_list
482  * @details this will be used when the sw codec is running.
483  * @since_tizen 3.0
484  */
485 typedef struct {
486         gboolean used;
487         void *bo;
488 } mmplayer_video_bo_info_t;
489
490 typedef struct {
491         gint bandwidth;
492         gint width;
493         gint height;
494 } stream_variant_t;
495
496 typedef struct {
497         GList *var_list;
498         stream_variant_t limit;
499 } mmplayer_adaptive_variant_info_t;
500
501 typedef struct {
502         int is_spherical;
503         int is_stitched;
504         char *stitching_software;
505         char *projection_type_string;
506         char *stereo_mode_string;
507         mmplayer_projection_type_e projection_type;
508         mmplayer_stereo_mode_e stereo_mode;
509         int source_count;
510         int init_view_heading;
511         int init_view_pitch;
512         int init_view_roll;
513         int timestamp;
514         int full_pano_width_pixels;
515         int full_pano_height_pixels;
516         int cropped_area_image_width;
517         int cropped_area_image_height;
518         int cropped_area_left;
519         int cropped_area_top;
520         int ambisonic_type;
521         int ambisonic_format;
522         int ambisonic_order;
523 } mmplayer_spherical_metadata_t;
524
525 typedef struct {
526         /* STATE */
527         int state;                                      // player current state
528         int prev_state;                         // player previous state
529         int pending_state;                      // player state which is going to now
530         int target_state;                               // player state which user want to go to
531         guint state_change_timeout;
532
533         gchar *album_art;
534
535         int cmd;
536
537         /* command lock */
538         GMutex cmd_lock;
539         GMutex playback_lock;
540
541         /* gapless play thread */
542         GThread *gapless_play_thread;
543         gboolean gapless_play_thread_exit;
544         GCond gapless_play_thread_cond;
545         GMutex gapless_play_thread_mutex;
546         mmplayer_gapless_t gapless;
547
548         /* capture thread */
549         GThread *capture_thread;
550         gboolean capture_thread_exit;
551         GCond capture_thread_cond;
552         GMutex capture_thread_mutex;
553         mmplayer_video_capture_t capture;
554         mmplayer_video_color_space_e video_cs;
555         MMVideoBuffer captured;
556
557         /* gst bus msg thread, create during realize */
558         GThread *bus_msg_thread;
559         gboolean bus_msg_thread_exit;
560         GCond bus_msg_thread_cond;
561         GMutex bus_msg_thread_mutex;
562
563         /* fakesink handling lock */
564         GMutex fsink_lock;
565
566         /* update tag lock */
567         GMutex update_tag_lock;
568
569         /* player attributes */
570         MMHandleType attrs;
571
572         /* message callback */
573         MMMessageCallback msg_cb;
574         void *msg_cb_param;
575
576         /* streaming player */
577         mmplayer_streaming_t *streamer;
578
579         /* gstreamer pipeline */
580         mmplayer_pipeline_info_t        *pipeline;
581
582         /* pad */
583         GstPad *ghost_pad_for_videobin;
584
585         guint64 media_stream_buffer_max_size[MM_PLAYER_STREAM_TYPE_MAX];
586         guint media_stream_buffer_min_percent[MM_PLAYER_STREAM_TYPE_MAX];
587         mm_player_media_stream_buffer_status_callback media_stream_buffer_status_cb[MM_PLAYER_STREAM_TYPE_MAX];
588         mm_player_media_stream_seek_data_callback media_stream_seek_data_cb[MM_PLAYER_STREAM_TYPE_MAX];
589         GMutex media_stream_cb_lock;
590
591         int video_num_buffers;  /* total num of buffers in vcodec */
592         int video_extra_num_buffers; /* extra num of buffers in vcodec */
593
594         void *buffer_cb_user_param[MM_PLAYER_STREAM_TYPE_MAX];
595         void *seek_cb_user_param[MM_PLAYER_STREAM_TYPE_MAX];
596
597         /* video stream changed callback */
598         mm_player_stream_changed_callback video_stream_changed_cb;
599         void *video_stream_changed_cb_user_param;
600
601         /* audio stream changed callback */
602         mm_player_stream_changed_callback audio_stream_changed_cb;
603         void *audio_stream_changed_cb_user_param;
604
605         /* video stream callback */
606         mm_player_video_decoded_callback video_decoded_cb;
607         void *video_decoded_cb_user_param;
608         GCond video_bo_cond;
609         GMutex video_bo_mutex;
610         GList *video_bo_list; /* mmplayer_video_bo_info_t, bo list for decoded video data by sw codec */
611         int video_bo_size;
612         bool video_stream_prerolled;
613
614         /* audio stream callback */
615         mm_player_audio_decoded_callback audio_decoded_cb;
616         void *audio_decoded_cb_user_param;
617         GList *audio_stream_buff_list; /* mmplayer_audio_stream_buff_t, buff list of extract pcm data */
618         mmplayer_audio_extract_opt_e audio_extract_opt;
619
620         /* video capture callback*/
621         gulong video_capture_cb_probe_id;
622
623         /* sound info */
624         mmplayer_sound_info_t   sound;
625
626         /* type string */
627         gchar *type;
628
629         /* video stream caps parsed by demuxer */
630         GstCaps *v_stream_caps;
631
632         /* audio effect infomation */
633         mm_audio_effect_info_t audio_effect_info;
634         gboolean bypass_audio_effect;
635
636         /* content profile */
637         mmplayer_parse_profile_t profile;
638         mmplayer_storage_info_t storage_info[MMPLAYER_PATH_MAX];
639
640         /* streaming service type */
641         MMStreamingType streaming_type;
642
643         /* autoplugging */
644         GList *factories;
645         GList *audio_decoders; // list of linked audio name
646         gboolean no_more_pad;
647         gint num_dynamic_pad;
648         gboolean has_many_types;
649
650         /* progress callback timer */
651         /* FIXIT : since duplicated functionality with get_position
652          * this function will be deprecated after fixing all application
653          * which are using it.
654          */
655         guint progress_timer;
656
657         /* timer for sending delayed EOS */
658         guint eos_timer;
659
660         /* last point that player is paused or seeking */
661         gint64 last_position;
662
663         /* duration */
664         gint64 duration;
665
666         /* data size of http streaming  */
667         guint64 http_content_size;
668
669         /* last error */
670         gchar last_error_msg[1024]; /* FIXIT : should it be dynamic ? */
671
672         gboolean smooth_streaming;
673
674         gint videodec_linked;
675         gint audiodec_linked;
676         gint textsink_linked;
677
678         /* missing plugin during autoplugging */
679         missing_codec_e not_supported_codec;
680
681         /* unlinked audio/video mime type */
682         gchar *unlinked_video_mime;
683         gchar *unlinked_audio_mime;
684         gchar *unlinked_demuxer_mime;
685
686         /* found codec during autoplugging */
687         found_codec_e can_support_codec;
688
689         gboolean not_found_demuxer;
690
691         /* support seek even though player is not start */
692         mmplayer_pending_seek_t pending_seek;
693         mmplayer_seek_state_e seek_state;
694
695         /* prevent to post msg over and over */
696         gboolean msg_posted;
697
698         /* list of sink elements */
699         GList *sink_elements;
700
701         /* signal notifiers */
702         GList *signals[MM_PLAYER_SIGNAL_TYPE_MAX];
703         guint bus_watcher;
704         GQueue *bus_msg_q;
705         GMutex bus_msg_q_lock;
706         mmplayer_context_info_t context;
707         mmplayer_uri_list_t uri_info;
708
709         gboolean is_sound_extraction;
710
711         gfloat playback_rate;
712
713         /* player state resumed by fast rewind */
714         gboolean resumed_by_rewind;
715
716         gboolean is_nv12_tiled;
717
718         /* resource manager for H/W resources */
719         mm_resource_manager_h resource_manager;
720         mm_resource_manager_res_h hw_resource[MMPLAYER_RESOURCE_TYPE_MAX];
721         gboolean interrupted_by_resource;
722
723         gboolean is_subtitle_off;
724         gboolean is_external_subtitle_present;
725         gboolean is_external_subtitle_added_now;
726         gboolean pending_resume;
727
728         /* contents bitrate for buffering management */
729         guint bitrate[MM_PLAYER_STREAM_COUNT_MAX];
730         guint total_bitrate;
731         guint maximum_bitrate[MM_PLAYER_STREAM_COUNT_MAX];
732         guint total_maximum_bitrate;
733
734         /* prevent it from posting duplicatly*/
735         gboolean sent_bos;
736
737         gboolean play_subtitle;
738         gboolean is_subtitle_force_drop;        // set TRUE after bus_cb get EOS
739
740         /* adjust subtitle position store */
741         gint64 adjust_subtitle_pos;
742         GList *subtitle_language_list;
743         GCond subtitle_info_cond;
744         GMutex subtitle_info_mutex;
745
746         /* To store the current running audio pad index of demuxer */
747         gint demux_pad_index;
748
749         mmplayer_selector_t selector[MM_PLAYER_TRACK_TYPE_MAX];
750
751         guint internal_text_idx;
752         guint external_text_idx;
753
754         mmplayer_setting_mode_t set_mode;
755
756         /* initialize values */
757         mmplayer_ini_t ini;
758
759         /* store dump pad list */
760         GList *dump_list;
761
762         /* whether a video has closed caption or not */
763         gboolean has_closed_caption;
764
765
766         /* audio stream caps parsed by demuxer or set by external demuxer */
767         GstCaps *a_stream_caps;
768
769         /* subtitle stream caps parsed by demuxer or set by external demuxer */
770         GstCaps *s_stream_caps;
771
772         /* es player using feed-data callback or calling app_src_push_buffer directly*/
773         gboolean es_player_push_mode;
774
775         /* tmb buffer manager for s/w codec tmb_bo */
776         tbm_bufmgr bufmgr;
777
778         mmplayer_adaptive_variant_info_t adaptive_info;
779
780         /* Video360 related stuff
781          * */
782         gboolean is_360_feature_enabled;
783         gboolean is_content_spherical;
784         mmplayer_spherical_metadata_t video360_metadata;
785         gboolean is_openal_plugin_used;
786         /* User settable values */
787         gboolean is_video360_enabled;
788         float video360_yaw_radians;
789         float video360_pitch_radians;
790         float video360_zoom;
791         int video360_horizontal_fov;
792         int video360_vertical_fov;
793
794         /* Video ROI area scale value */
795         mmplayer_video_roi_t video_roi;
796
797         /* build audio offload */
798         gboolean build_audio_offload;
799         guint audio_device_cb_id;
800 } mmplayer_t;
801
802 typedef struct {
803         gchar *language_code;
804         gchar *language_key;
805         gboolean active;
806 } mmplayer_lang_info_t;
807
808 typedef struct {
809         GstPad *dump_pad;
810         gulong probe_handle_id;
811         FILE *dump_element_file;
812 } mmplayer_dump_t;
813
814 typedef struct {
815         char *name;
816         int value_type;
817         int flags;                              // r, w
818         void *default_value;
819         int valid_type;                 // validity type
820         int value_min;                  //<- set validity value range
821         int value_max;          //->
822 } mmplayer_attrs_spec_t;
823
824 /*===========================================================================================
825 |                                                                                                                                                                                       |
826 |  GLOBAL FUNCTION PROTOTYPES                                                                                                                           |
827 |                                                                                                                                                                                       |
828 ========================================================================================== */
829 #ifdef __cplusplus
830         extern "C" {
831 #endif
832
833 int _mmplayer_create_player(MMHandleType hplayer);
834 int _mmplayer_destroy(MMHandleType hplayer);
835 int _mmplayer_realize(MMHandleType hplayer);
836 int _mmplayer_unrealize(MMHandleType hplayer);
837 int _mmplayer_get_state(MMHandleType hplayer, int *state);
838 int _mmplayer_set_volume(MMHandleType hplayer, float volume);
839 int _mmplayer_get_volume(MMHandleType hplayer, float *volume);
840 int _mmplayer_set_mute(MMHandleType hplayer, bool mute);
841 int _mmplayer_get_mute(MMHandleType hplayer, bool *mute);
842 int _mmplayer_start(MMHandleType hplayer);
843 int _mmplayer_stop(MMHandleType hplayer);
844 int _mmplayer_pause(MMHandleType hplayer);
845 int _mmplayer_abort_pause(MMHandleType hplayer);
846 int _mmplayer_resume(MMHandleType hplayer);
847 int _mmplayer_set_position(MMHandleType hplayer, gint64 pos);
848 int _mmplayer_get_duration(MMHandleType hplayer, gint64 *duration);
849 int _mmplayer_adjust_subtitle_postion(MMHandleType hplayer, int pos);
850 int _mmplayer_set_playspeed(MMHandleType hplayer, float rate, bool streaming);
851 int _mmplayer_set_message_callback(MMHandleType hplayer, MMMessageCallback callback, void *user_param);
852 int _mmplayer_set_videostream_changed_cb(MMHandleType hplayer, mm_player_stream_changed_callback callback, void *user_param);
853 int _mmplayer_set_audiostream_changed_cb(MMHandleType hplayer, mm_player_stream_changed_callback callback, void *user_param);
854 int _mmplayer_set_video_decoded_cb(MMHandleType hplayer, mm_player_video_decoded_callback callback, void *user_param);
855 int _mmplayer_set_subtitle_silent(MMHandleType hplayer, int silent);
856 int _mmplayer_get_subtitle_silent(MMHandleType hplayer, int *silent);
857 int _mmplayer_set_external_subtitle_path(MMHandleType hplayer, const char *filepath);
858 int _mmplayer_get_buffer_position(MMHandleType hplayer, int *start_pos, int *end_pos);
859 int _mmplayer_update_video_param(mmplayer_t *player, char *param_name);
860 int _mmplayer_change_videosink(MMHandleType handle, MMDisplaySurfaceType surface_type, void *display_overlay);
861 int _mmplayer_audio_effect_custom_apply(mmplayer_t *player);
862 int _mmplayer_set_audio_decoded_cb(MMHandleType hplayer, mmplayer_audio_extract_opt_e opt, mm_player_audio_decoded_callback callback, void *user_param);
863 int _mmplayer_change_track_language(MMHandleType hplayer, mmplayer_track_type_e type, int index);
864 int _mmplayer_sync_subtitle_pipeline(mmplayer_t *player);
865 int _mmplayer_use_system_clock(MMHandleType hplayer);
866 int _mmplayer_set_uri(MMHandleType hplayer, const char *uri);
867 int _mmplayer_set_next_uri(MMHandleType hplayer, const char *uri, bool is_first_path);
868 int _mmplayer_get_next_uri(MMHandleType hplayer, char **uri);
869 int _mmplayer_has_closed_caption(MMHandleType hplayer, bool *exist);
870 void _mm_player_video_stream_internal_buffer_unref(void *buffer);
871 int _mmplayer_get_timeout(MMHandleType hplayer, int *timeout);
872 int _mmplayer_get_num_of_video_out_buffers(MMHandleType hplayer, int *num, int *extra_num);
873 int _mmplayer_manage_external_storage_state(MMHandleType hplayer, int id, int state);
874 int _mmplayer_video_stream_release_bo(mmplayer_t *player, void *bo);
875 int _mmplayer_get_adaptive_variant_info(MMHandleType hplayer, int *num, char **var_info);
876 int _mmplayer_set_max_adaptive_variant_limit(MMHandleType hplayer, int bandwidth, int width, int height);
877 int _mmplayer_get_max_adaptive_variant_limit(MMHandleType hplayer, int *bandwidth, int *width, int *height);
878 int _mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only);
879 int _mmplayer_get_audio_only(MMHandleType hplayer, bool *paudio_only);
880 int _mmplayer_get_streaming_buffering_time(MMHandleType hplayer, int *prebuffer_ms, int *rebuffer_ms);
881 int _mmplayer_set_codec_type(MMHandleType hplayer, mmplayer_stream_type_e stream_type, mmplayer_video_codec_type_e codec_type);
882 int _mmplayer_set_replaygain_enabled(MMHandleType hplayer, bool enabled);
883 int _mmplayer_is_replaygain_enabled(MMHandleType hplayer, bool *enabled);
884 int _mmplayer_set_video_roi_area(MMHandleType hplayer, double scale_x, double scale_y, double scale_width, double scale_height);
885 int _mmplayer_get_video_roi_area(MMHandleType hplayer, double *scale_x, double *scale_y, double *scale_width, double *scale_height);
886
887 /* internal */
888 void _mmplayer_bus_msg_thread_destroy(MMHandleType hplayer);
889 void _mmplayer_set_state(mmplayer_t *player, int state);
890 int _mmplayer_check_state(mmplayer_t *player, mmplayer_command_state_e command);
891 gboolean _mmplayer_update_content_attrs(mmplayer_t *player, enum content_attr_flag flag);
892 void _mmplayer_cancel_eos_timer(mmplayer_t *player);
893 void _mmplayer_audio_stream_clear_buffer(mmplayer_t *player, gboolean send_all);
894 MMStreamingType _mmplayer_get_stream_service_type(mmplayer_t *player);
895 int _mmplayer_get_video_angle(mmplayer_t *player, int *display_angle, int *orientations);
896 gboolean _mmplayer_gst_remove_fakesink(mmplayer_t *player, mmplayer_gst_element_t *fakesink);
897 void _mmplayer_add_signal_connection(mmplayer_t *player, GObject *object, mmplayer_signal_type_e type, const gchar *signal, GCallback cb_funct, gpointer u_data);
898 void _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data);
899 gint _mmplayer_gst_decode_autoplug_select(GstElement *bin,  GstPad *pad, GstCaps *caps, GstElementFactory *factory, gpointer data);
900 gboolean _mmplayer_gst_create_decoder(mmplayer_t *player, GstPad *srcpad, const GstCaps *caps);
901 void _mmplayer_gst_element_added(GstElement *bin, GstElement *element, gpointer data);
902 GstElement *_mmplayer_gst_make_decodebin(mmplayer_t *player);
903 int _mmplayer_gst_element_add_bucket_to_bin(GstBin *bin, GList *element_bucket);
904 int _mmplayer_gst_element_link_bucket(GList *element_bucket);
905 void _mmplayer_typefind_have_type(GstElement *tf, guint probability, GstCaps *caps, gpointer data);
906 int _mmplayer_parse_profile(const char *uri, void *param, mmplayer_parse_profile_t *data);
907
908 #ifdef __cplusplus
909         }
910 #endif
911
912 #endif  /* __MM_PLAYER_PRIV_H__ */