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