4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #ifndef __MM_PLAYER_STREAMING_H__
24 #define __MM_PLAYER_STREAMING_H__
31 #include "mm_player.h"
33 #define MAX_FILE_BUFFER_NAME_LEN 256
34 #define MAX_BUFFER_PERCENT 100.0
36 #define DEFAULT_BUFFER_HIGH_WATERMARK 0.99
37 #define DEFAULT_BUFFER_LOW_WATERMARK 0.1 /* max of low watermark */
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
43 /* low and high watermark criteria */
44 #define MIN_BUFFER_WATERMARK 0.0
45 #define MAX_BUFFER_WATERMARK 1.0
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)
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)
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 */
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) \
70 if (((a) > 0) && ((b) > 0)) { \
71 d = CALC_WATERMARK(a, b); \
73 LOGW("set default watermark value %f", c); \
78 #define GET_VALID_VALUE(a, min, max) \
81 LOGW("invalid max value, take min"); \
89 #define PLAYER_BUFFER_CAST(handle) ((streaming_buffer_t *)(handle))
90 #define PLAYER_STREAM_CAST(sr) ((mmplayer_streaming_t *)(sr))
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)
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)
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)
103 BUFFER_TYPE_MUXED = BUFFER_TYPE_DEFAULT, /* queue2 */
104 BUFFER_TYPE_DEMUXED, /* multi Q in decodebin */
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;
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;
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;
129 GstElement *buffer; /* buffering element of playback pipeline */
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;
137 } streaming_buffer_t;
140 gboolean buffering_monitor;
142 gint buffering_time; // DEFAULT_BUFFERING_TIME
143 } streaming_default_t;
146 buffer_type_e streaming_buffer_type;
147 streaming_buffer_t buffer_handle[BUFFER_TYPE_MAX]; /* front buffer : queue2 */
149 streaming_requirement_t buffering_req;
150 streaming_default_t default_val;
152 mmplayer_buffering_state_e buffering_state;
153 gboolean is_adaptive_streaming;
155 gint buffering_percent;
156 guint buffer_max_bitrate;
157 guint buffer_avg_bitrate;
158 gboolean need_update;
160 gint ring_buffer_size;
161 } mmplayer_streaming_t;
164 mmplayer_streaming_t *__mm_player_streaming_create(void);
166 void __mm_player_streaming_initialize(mmplayer_streaming_t *streaming_player, gboolean buffer_init);
168 void __mm_player_streaming_destroy(mmplayer_streaming_t *streaming_player);
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);
173 void __mm_player_streaming_set_multiqueue(mmplayer_streaming_t *streamer, GstElement *buffer);
175 void __mm_player_streaming_sync_property(mmplayer_streaming_t *streamer, GstElement *decodebin);
177 void __mm_player_streaming_buffering(mmplayer_streaming_t *streamer, GstMessage *buffering_msg,
178 guint64 content_size, gint64 position, gint64 duration);
180 void __mm_player_streaming_set_content_bitrate(mmplayer_streaming_t *streaming_player, guint max_bitrate, guint avg_bitrate);