[0.6.164] Apply tizen coding rule
[platform/core/multimedia/libmm-player.git] / src / include / mm_player_streaming.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_STREAMING_H__
24 #define __MM_PLAYER_STREAMING_H__
25
26 #include <glib.h>
27 #include <gst/gst.h>
28 #include <string.h>
29 #include <math.h>
30 #include <dlog.h>
31 #include "mm_player.h"
32
33 #define MAX_FILE_BUFFER_NAME_LEN 256
34
35 #define MIN_BUFFER_PERCENT 0.0
36 #define MAX_BUFFER_PERCENT 100.0
37 #define MIN_BUFFERING_TIME 3.0
38 #define MAX_BUFFERING_TIME (10 * 1000) /* ms */
39
40 #define MAX_DECODEBIN_BUFFER_BYTES      (32 * 1024 * 1024) /* byte */
41 #define MAX_DECODEBIN_BUFFER_TIME       (15 * 1000) /* ms */
42 #define MAX_DECODEBIN_ADAPTIVE_BUFFER_BYTES     (2 * 1024 * 1024) /* byte */
43 #define MAX_DECODEBIN_ADAPTIVE_BUFFER_TIME      (5 * 1000) /* ms */
44
45 #define DEFAULT_BUFFER_SIZE_BYTES 4194304   /* 4 MBytes */
46 #define DEFAULT_PLAYING_TIME (10 * 1000) /* ms */
47 #define DEFAULT_ADAPTIVE_PLAYING_TIME (3 * 1000) /* ms */
48
49 #define DEFAULT_BUFFERING_TIME (3 * 1000) /* ms */
50 #define DEFAULT_BUFFER_HIGH_PERCENT 99.0
51 #define DEFAULT_RING_BUFFER_SIZE (20 * 1024 * 1024) /* 20MBytes */
52
53 #define STREAMING_USE_FILE_BUFFER
54 #define STREAMING_USE_MEMORY_BUFFER
55
56 #define GET_BYTE_FROM_BIT(bit) (bit / 8)
57 #define GET_BIT_FROM_BYTE(byte) (byte * 8)
58 #define CALC_PERCENT(a, b) ((gdouble)(a) * 100 / (gdouble)(b))
59 #define GET_PERCENT(a, b, c, d) \
60         do { \
61                 if (((a) > 0) && ((b) > 0)) { \
62                         d = CALC_PERCENT(a, b); \
63                 } else { \
64                         LOGW("set default per info"); \
65                         d = c; \
66                 } \
67         } while (0)
68
69
70 #define PLAYER_BUFFER_CAST(handle)      ((streaming_buffer_t *)(handle))
71 #define PLAYER_STREAM_CAST(sr)          ((mm_player_streaming_t *)(sr))
72
73 #define GET_CURRENT_BUFFERING_BYTE(handle)      (PLAYER_BUFFER_CAST(handle)->buffering_bytes)
74 #define GET_CURRENT_BUFFERING_TIME(handle)      (PLAYER_BUFFER_CAST(handle)->buffering_time)
75
76 #define IS_MUXED_BUFFERING_MODE(sr)             (PLAYER_STREAM_CAST(sr)->streaming_buffer_type == BUFFER_TYPE_MUXED) ? (TRUE) : (FALSE)
77 #define IS_DEMUXED_BUFFERING_MODE(sr)   (PLAYER_STREAM_CAST(sr)->streaming_buffer_type == BUFFER_TYPE_DEMUXED) ? (TRUE) : (FALSE)
78
79 #define GET_NEW_BUFFERING_BYTE(size)    ((size) < MAX_DECODEBIN_BUFFER_BYTES) ? (size) : (MAX_DECODEBIN_BUFFER_BYTES)
80 #define GET_MAX_BUFFER_BYTES(sr)                ((PLAYER_STREAM_CAST(sr)->is_adaptive_streaming) ? (MAX_DECODEBIN_ADAPTIVE_BUFFER_BYTES) : (MAX_DECODEBIN_BUFFER_BYTES))
81 #define GET_MAX_BUFFER_TIME(sr)                 ((PLAYER_STREAM_CAST(sr)->is_adaptive_streaming) ? (MAX_DECODEBIN_ADAPTIVE_BUFFER_TIME) : (MAX_DECODEBIN_BUFFER_TIME))
82 #define GET_DEFAULT_PLAYING_TIME(sr)    ((PLAYER_STREAM_CAST(sr)->is_adaptive_streaming) ? (DEFAULT_ADAPTIVE_PLAYING_TIME) : (DEFAULT_PLAYING_TIME))
83
84 typedef enum {
85         BUFFER_TYPE_DEFAULT,
86         BUFFER_TYPE_MUXED = BUFFER_TYPE_DEFAULT,        /* queue2 */
87         BUFFER_TYPE_DEMUXED,            /* multi Q in decodebin */
88         BUFFER_TYPE_MAX,
89 } BufferType;
90
91 typedef enum {
92         MUXED_BUFFER_TYPE_MEM_QUEUE, /* push mode in queue2 */
93         MUXED_BUFFER_TYPE_MEM_RING_BUFFER, /* pull mode in queue2 */
94         MUXED_BUFFER_TYPE_FILE, /* pull mode in queue2 */
95         MUXED_BUFFER_TYPE_MAX,
96 } MuxedBufferType;
97
98 typedef enum {
99         MM_PLAYER_BUFFERING_DEFAULT = 0x00,
100         MM_PLAYER_BUFFERING_IN_PROGRESS = 0x01,
101         MM_PLAYER_BUFFERING_ABORT = 0x02,
102         MM_PLAYER_BUFFERING_COMPLETE = 0x04,
103 } MMPlayerBufferingState;
104
105 typedef struct {
106         MMPlayerBufferingMode mode;
107         gboolean is_pre_buffering;
108         gint prebuffer_time; /* ms */
109         gint rebuffer_time;  /* ms */
110 } streaming_requirement_t;
111
112 typedef struct {
113         GstElement *buffer;                     /* buffering element of playback pipeline */
114
115         guint buffering_bytes;
116         gint buffering_time;            // mq : max buffering time value till now
117         gdouble buffer_high_percent;
118         gdouble buffer_low_percent;
119
120         gboolean is_live;
121 } streaming_buffer_t;
122
123 typedef struct {
124         gboolean buffering_monitor;
125         gint64 prev_pos;
126         gint buffering_time;    // DEFAULT_BUFFERING_TIME
127 } streaming_default_t;
128
129 typedef struct {
130         BufferType      streaming_buffer_type;
131         streaming_buffer_t buffer_handle[BUFFER_TYPE_MAX];      /* front buffer : queue2 */
132
133         streaming_requirement_t buffering_req;
134         streaming_default_t default_val;
135
136         MMPlayerBufferingState buffering_state;
137         gboolean        is_adaptive_streaming;
138
139         gint            buffering_percent;
140         guint           buffer_max_bitrate;
141         guint           buffer_avg_bitrate;
142         gboolean        need_update;
143         gboolean        need_sync;
144         gint            ring_buffer_size;
145 } mm_player_streaming_t;
146
147
148 mm_player_streaming_t *__mm_player_streaming_create(void);
149 void __mm_player_streaming_initialize(mm_player_streaming_t *streaming_player);
150 void __mm_player_streaming_deinitialize(mm_player_streaming_t *streaming_player);
151 void __mm_player_streaming_destroy(mm_player_streaming_t *streaming_player);
152 void __mm_player_streaming_set_queue2(mm_player_streaming_t *streamer,
153                                                                                 GstElement *buffer,
154                                                                                 gboolean use_buffering,
155                                                                                 guint buffering_bytes,
156                                                                                 gint buffering_time,
157                                                                                 MuxedBufferType type,
158                                                                                 gchar *file_path,
159                                                                                 guint64 content_size);
160 void __mm_player_streaming_set_multiqueue(mm_player_streaming_t *streamer,
161                                                                                 GstElement *buffer,
162                                                                                 gint buffering_time);
163 void __mm_player_streaming_sync_property(mm_player_streaming_t *streamer, GstElement *decodebin);
164 void __mm_player_streaming_buffering(mm_player_streaming_t *streamer,
165                                                                           GstMessage *buffering_msg,
166                                                                           guint64 content_size,
167                                                                           gint64 position,
168                                                                           gint64 duration);
169 void __mm_player_streaming_set_content_bitrate(mm_player_streaming_t *streaming_player, guint max_bitrate, guint avg_bitrate);
170
171 #endif