tizen 2.3.1 release
[framework/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 "mm_debug.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.0
39
40 #define MAX_DECODEBIN_BUFFER_BYTES      (32 * 1024 * 1024)      // byte
41 #define MAX_DECODEBIN_BUFFER_TIME       15      // sec
42
43 #define DEFAULT_BUFFER_SIZE_BYTES 4194304       // 4 MBytes
44 #define DEFAULT_PLAYING_TIME 10                         // 10 sec
45
46 #define DEFAULT_BUFFERING_TIME 3.0              // 3sec
47 #define DEFAULT_BUFFER_LOW_PERCENT 1.0          // 1%
48 #define DEFAULT_BUFFER_HIGH_PERCENT 99.0        // 15%
49
50 #define DEFAULT_FILE_BUFFER_PATH "/opt/media"
51
52 #define STREAMING_USE_FILE_BUFFER
53 #define STREAMING_USE_MEMORY_BUFFER
54
55 #define GET_BYTE_FROM_BIT(bit) (bit/8)
56 #define GET_BIT_FROM_BYTE(byte) (byte*8)
57 #define CALC_PERCENT(a,b) ((gdouble)(a) * 100 / (gdouble)(b))
58 #define GET_PERCENT(a, b, c, d) \
59 do \
60 { \
61         if (((a) > 0) && ((b) > 0))             \
62         {       \
63                 d = CALC_PERCENT(a, b); \
64         }       \
65         else    \
66         {       \
67                 debug_warning ("set default per info\n");       \
68                 d = c;  \
69         } \
70 } while ( 0 );
71
72
73 #define PLAYER_BUFFER_CAST(handle)      ((streaming_buffer_t *)(handle))
74 #define PLAYER_STREAM_CAST(sr)          ((mm_player_streaming_t *)(sr))
75
76 #define GET_CURRENT_BUFFERING_BYTE(handle)      (PLAYER_BUFFER_CAST(handle)->buffering_bytes)
77 #define GET_CURRENT_BUFFERING_TIME(handle)      (PLAYER_BUFFER_CAST(handle)->buffering_time)
78
79 #define IS_MUXED_BUFFERING_MODE(sr)             (PLAYER_STREAM_CAST(sr)->streaming_buffer_type == BUFFER_TYPE_MUXED)?(TRUE):(FALSE)
80 #define IS_DEMUXED_BUFFERING_MODE(sr)   (PLAYER_STREAM_CAST(sr)->streaming_buffer_type == BUFFER_TYPE_DEMUXED)?(TRUE):(FALSE)
81
82 #define GET_NEW_BUFFERING_BYTE(size)    ((size) < MAX_DECODEBIN_BUFFER_BYTES)?(size):(MAX_DECODEBIN_BUFFER_BYTES)
83
84
85 typedef enum {
86         BUFFER_TYPE_DEFAULT,
87         BUFFER_TYPE_MUXED = BUFFER_TYPE_DEFAULT,        /* queue2 */
88         BUFFER_TYPE_DEMUXED,            /* multi Q in decodebin */
89         BUFFER_TYPE_MAX,
90 } BufferType;
91
92 typedef struct
93 {
94         MMPlayerBufferingMode mode;
95         gboolean is_pre_buffering;
96         gint initial_second;
97         gint runtime_second;
98
99 }streaming_requirement_t;
100
101 typedef struct
102 {
103         GstElement* buffer;             /* buffering element of playback pipeline */
104
105         guint buffering_bytes;
106         gdouble buffering_time;         // mq : max buffering time value till now
107         gdouble buffer_high_percent;
108         gdouble buffer_low_percent;
109
110         gboolean is_live;
111 }streaming_buffer_t;
112
113 typedef struct
114 {
115         gboolean buffering_monitor;
116         gint64  prev_pos;
117         gdouble buffering_time; // DEFAULT_BUFFERING_TIME
118 }streaming_default_t;
119
120 typedef struct
121 {
122         BufferType      streaming_buffer_type;
123         streaming_buffer_t buffer_handle[BUFFER_TYPE_MAX];      /* front buffer : queue2 */
124
125         streaming_requirement_t buffering_req;
126         streaming_default_t default_val;
127
128         gboolean        is_buffering;
129         gboolean        is_buffering_done;      /* get info from bus sync callback */
130
131         gint            buffering_percent;
132
133         guint           buffer_max_bitrate;
134         guint           buffer_avg_bitrate;
135         gboolean        need_update;
136         gboolean        need_sync;
137
138 }mm_player_streaming_t;
139
140
141 mm_player_streaming_t *__mm_player_streaming_create (void);
142 void __mm_player_streaming_initialize (mm_player_streaming_t* streaming_player);
143 void __mm_player_streaming_deinitialize (mm_player_streaming_t* streaming_player);
144 void __mm_player_streaming_destroy(mm_player_streaming_t* streaming_player);
145 void __mm_player_streaming_set_queue2(  mm_player_streaming_t* streamer,
146                                                                                 GstElement* buffer,
147                                                                                 gboolean use_buffering,
148                                                                                 guint buffering_bytes,
149                                                                                 gdouble buffering_time,
150                                                                                 gdouble low_percent,
151                                                                                 gdouble high_percent,
152                                                                                 gboolean use_file,
153                                                                                 gchar* file_path,
154                                                                                 guint64 content_size);
155 void __mm_player_streaming_set_multiqueue(      mm_player_streaming_t* streamer,
156                                                                                 GstElement* buffer,
157                                                                                 gboolean use_buffering,
158                                                                                 guint buffering_bytes,
159                                                                                 gdouble buffering_time,
160                                                                                 gdouble low_percent,
161                                                                                 gdouble high_percent);
162 void __mm_player_streaming_sync_property(mm_player_streaming_t* streamer, GstElement* decodebin);
163 void __mm_player_streaming_buffering( mm_player_streaming_t* streamer,
164                                                                           GstMessage *buffering_msg,
165                                                                           guint64 content_size,
166                                                                           gint64 position,
167                                                                           gint64 duration);
168 void __mm_player_streaming_set_content_bitrate(mm_player_streaming_t* streaming_player, guint max_bitrate, guint avg_bitrate);
169
170 #endif