[0.6.184] change mute type
[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 #define MAX_BUFFER_PERCENT 100.0
35
36 #define DEFAULT_BUFFER_HIGH_WATERMARK 0.99
37 #define DEFAULT_BUFFER_LOW_WATERMARK  0.1 /* max of low watermark */
38
39 /* low watermark min criteria to avoid buffer underrun */
40 #define LOW_WATERMARK_MIN_BYTE_LEVEL 0.05
41 #define LOW_WATERMARK_MIN_TIME_VALUE 500
42
43 /* low and high watermark criteria */
44 #define MIN_BUFFER_WATERMARK 0.0
45 #define MAX_BUFFER_WATERMARK 1.0
46
47 /* buffering time criteria (ms) */
48 #define DEFAULT_BUFFERING_TIME   (3 * 1000)
49 #define MIN_BUFFERING_TIME       (0)
50 #define MAX_BUFFERING_TIME       (10 * 1000)
51
52 #define DEFAULT_PREBUFFERING_TIME      (3 * 1000)
53 #define DEFAULT_REBUFFERING_TIME       (10 * 1000)
54 #define DEFAULT_ADAPTIVE_REBUFFER_TIME (5 * 1000)
55 #define DEFAULT_LIVE_REBUFFER_TIME     (3 * 1000)
56
57 /* buffer size */
58 #define DEFAULT_BUFFER_SIZE_BYTES      (5 * 1024 * 1024)  /* 5 MBytes */
59 #define DEFAULT_RING_BUFFER_SIZE_BYTES (20 * 1024 * 1024) /* 20 MBytes, for queue2 */
60 #define MIN_BUFFER_SIZE_BYTES          (1 * 1024 * 1024)  /* 1 MBytes */
61 #define MAX_BUFFER_SIZE_BYTES          (32 * 1024 * 1024) /* 32 MBytes */
62 #define MAX_BUFFER_SIZE_TIME           (15 * 1000)        /* 15 sec, for mq */
63
64
65 #define GET_BYTE_FROM_BIT(bit) (bit / 8)
66 #define GET_BIT_FROM_BYTE(byte) (byte * 8)
67 #define CALC_WATERMARK(a, b) ((gdouble)(a) / (gdouble)(b))
68 #define GET_WATERMARK(a, b, c, d) \
69         do { \
70                 if (((a) > 0) && ((b) > 0)) { \
71                         d = CALC_WATERMARK(a, b);       \
72                 } else { \
73                         LOGW("set default watermark value %f", c); \
74                         d = c; \
75                 } \
76         } while (0)
77
78 #define GET_VALID_VALUE(a, min, max) \
79         do { \
80                 if (min >= max) {\
81                         LOGW("invalid max value, take min"); \
82                         a = min; \
83                 } else { \
84                         a = MAX(a, min); \
85                         a = MIN(a, max); \
86                 } \
87         } while (0)
88
89 #define PLAYER_BUFFER_CAST(handle)      ((streaming_buffer_t *)(handle))
90 #define PLAYER_STREAM_CAST(sr)          ((mmplayer_streaming_t *)(sr))
91
92 #define GET_CURRENT_BUFFERING_BYTE(handle)      (PLAYER_BUFFER_CAST(handle)->buffering_bytes)
93 #define GET_CURRENT_BUFFERING_TIME(handle)      (PLAYER_BUFFER_CAST(handle)->buffering_time)
94
95 #define IS_MUXED_BUFFERING_MODE(sr)             (PLAYER_STREAM_CAST(sr)->streaming_buffer_type == BUFFER_TYPE_MUXED) ? (TRUE) : (FALSE)
96 #define IS_DEMUXED_BUFFERING_MODE(sr)   (PLAYER_STREAM_CAST(sr)->streaming_buffer_type == BUFFER_TYPE_DEMUXED) ? (TRUE) : (FALSE)
97
98 #define GET_MAX_BUFFER_SIZE_BYTES(type) ((type == BUFFER_TYPE_MUXED) ? (DEFAULT_RING_BUFFER_SIZE_BYTES) : (MAX_BUFFER_SIZE_BYTES))
99 #define GET_NEW_BUFFERING_BYTE(size, max) ((size) < (max)) ? (size) : (max)
100
101 typedef enum {
102         BUFFER_TYPE_DEFAULT,
103         BUFFER_TYPE_MUXED = BUFFER_TYPE_DEFAULT,        /* queue2 */
104         BUFFER_TYPE_DEMUXED,            /* multi Q in decodebin */
105         BUFFER_TYPE_MAX,
106 } buffer_type_e;
107
108 typedef enum {
109         MUXED_BUFFER_TYPE_MEM_QUEUE, /* push mode in queue2 */
110         MUXED_BUFFER_TYPE_MEM_RING_BUFFER, /* pull mode in queue2 */
111         MUXED_BUFFER_TYPE_MAX,
112 } muxed_buffer_type_e;
113
114 typedef enum {
115         MM_PLAYER_BUFFERING_DEFAULT = 0x00,
116         MM_PLAYER_BUFFERING_IN_PROGRESS = 0x01,
117         MM_PLAYER_BUFFERING_ABORT = 0x02,
118         MM_PLAYER_BUFFERING_COMPLETE = 0x04,
119 } mmplayer_buffering_state_e;
120
121 typedef struct {
122         mmplayer_buffering_mode_e mode;
123         gboolean is_pre_buffering;
124         gint prebuffer_time; /* ms */
125         gint rebuffer_time;  /* ms */
126 } streaming_requirement_t;
127
128 typedef struct {
129         GstElement *buffer;                     /* buffering element of playback pipeline */
130
131         guint buffering_bytes;          /* max buffer size of byte */
132         gint buffering_time;            /* max buffer size of time */
133         gdouble buffer_high_watermark;
134         gdouble buffer_low_watermark;
135
136         gboolean is_live;
137 } streaming_buffer_t;
138
139 typedef struct {
140         gboolean buffering_monitor;
141         gint64 prev_pos;
142         gint buffering_time;    // DEFAULT_BUFFERING_TIME
143 } streaming_default_t;
144
145 typedef struct {
146         buffer_type_e   streaming_buffer_type;
147         streaming_buffer_t buffer_handle[BUFFER_TYPE_MAX];      /* front buffer : queue2 */
148
149         streaming_requirement_t buffering_req;
150         streaming_default_t default_val;
151
152         mmplayer_buffering_state_e buffering_state;
153         gboolean        is_adaptive_streaming;
154
155         gint            buffering_percent;
156         guint           buffer_max_bitrate;
157         guint           buffer_avg_bitrate;
158         gboolean        need_update;
159         gboolean        need_sync;
160         gint            ring_buffer_size;
161 } mmplayer_streaming_t;
162
163
164 mmplayer_streaming_t *__mm_player_streaming_create(void);
165
166 void __mm_player_streaming_initialize(mmplayer_streaming_t *streaming_player, gboolean buffer_init);
167
168 void __mm_player_streaming_destroy(mmplayer_streaming_t *streaming_player);
169
170 void __mm_player_streaming_set_queue2(mmplayer_streaming_t *streamer, GstElement *buffer,
171                                         gboolean use_buffering, muxed_buffer_type_e type, guint64 content_size);
172
173 void __mm_player_streaming_set_multiqueue(mmplayer_streaming_t *streamer, GstElement *buffer);
174
175 void __mm_player_streaming_sync_property(mmplayer_streaming_t *streamer, GstElement *decodebin);
176
177 void __mm_player_streaming_buffering(mmplayer_streaming_t *streamer, GstMessage *buffering_msg,
178                                         guint64 content_size, gint64 position, gint64 duration);
179
180 void __mm_player_streaming_set_content_bitrate(mmplayer_streaming_t *streaming_player, guint max_bitrate, guint avg_bitrate);
181
182 #endif