00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _VLC_BLOCK_H
00025 #define _VLC_BLOCK_H 1
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 typedef struct block_sys_t block_sys_t;
00048
00050 #define BLOCK_FLAG_DISCONTINUITY 0x0001
00051
00052 #define BLOCK_FLAG_TYPE_I 0x0002
00053
00054 #define BLOCK_FLAG_TYPE_P 0x0004
00055
00056 #define BLOCK_FLAG_TYPE_B 0x0008
00057
00058 #define BLOCK_FLAG_TYPE_PB 0x0010
00059
00060 #define BLOCK_FLAG_HEADER 0x0020
00061
00062 #define BLOCK_FLAG_END_OF_FRAME 0x0040
00063
00064 #define BLOCK_FLAG_NO_KEYFRAME 0x0080
00065
00066 #define BLOCK_FLAG_CLOCK 0x0200
00067
00068 #define BLOCK_FLAG_SCRAMBLED 0x0400
00069
00070 #define BLOCK_FLAG_PREROLL 0x0800
00071
00072 #define BLOCK_FLAG_CORRUPTED 0x1000
00073
00074 #define BLOCK_FLAG_PRIVATE_MASK 0xffff0000
00075 #define BLOCK_FLAG_PRIVATE_SHIFT 16
00076
00077 struct block_t
00078 {
00079 block_t *p_next;
00080 block_t *p_prev;
00081
00082 uint32_t i_flags;
00083
00084 mtime_t i_pts;
00085 mtime_t i_dts;
00086 mtime_t i_length;
00087
00088 int i_samples;
00089 int i_rate;
00090
00091 int i_buffer;
00092 uint8_t *p_buffer;
00093
00094
00095
00096
00097 void (*pf_release) ( block_t * );
00098
00099
00100
00101 vlc_object_t *p_manager;
00102
00103
00104
00105
00106 block_sys_t *p_sys;
00107 };
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 #define block_New( a, b ) __block_New( VLC_OBJECT(a), b )
00126 VLC_EXPORT( block_t *, __block_New, ( vlc_object_t *, int ) );
00127 VLC_EXPORT( block_t *, block_Realloc, ( block_t *, int i_pre, int i_body ) );
00128
00129 static inline block_t *block_Duplicate( block_t *p_block )
00130 {
00131 block_t *p_dup = block_New( p_block->p_manager, p_block->i_buffer );
00132
00133 p_dup->i_dts = p_block->i_dts;
00134 p_dup->i_pts = p_block->i_pts;
00135 p_dup->i_flags = p_block->i_flags;
00136 p_dup->i_length = p_block->i_length;
00137 p_dup->i_rate = p_block->i_rate;
00138 p_dup->i_samples = p_block->i_samples;
00139
00140 if( p_dup && p_block->i_buffer > 0 )
00141 memcpy( p_dup->p_buffer, p_block->p_buffer, p_block->i_buffer );
00142
00143 return p_dup;
00144 }
00145 static inline void block_Release( block_t *p_block )
00146 {
00147 p_block->pf_release( p_block );
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 static inline void block_ChainAppend( block_t **pp_list, block_t *p_block )
00163 {
00164 if( *pp_list == NULL )
00165 {
00166 *pp_list = p_block;
00167 }
00168 else
00169 {
00170 block_t *p = *pp_list;
00171
00172 while( p->p_next ) p = p->p_next;
00173 p->p_next = p_block;
00174 }
00175 }
00176
00177 static inline void block_ChainLastAppend( block_t ***ppp_last, block_t *p_block )
00178 {
00179 block_t *p_last = p_block;
00180
00181 **ppp_last = p_block;
00182
00183 while( p_last->p_next ) p_last = p_last->p_next;
00184 *ppp_last = &p_last->p_next;
00185 }
00186
00187 static inline void block_ChainRelease( block_t *p_block )
00188 {
00189 while( p_block )
00190 {
00191 block_t *p_next = p_block->p_next;
00192 block_Release( p_block );
00193 p_block = p_next;
00194 }
00195 }
00196 static int block_ChainExtract( block_t *p_list, void *p_data, int i_max )
00197 {
00198 block_t *b;
00199 int i_total = 0;
00200 uint8_t *p = (uint8_t*)p_data;
00201
00202 for( b = p_list; b != NULL; b = b->p_next )
00203 {
00204 int i_copy = __MIN( i_max, b->i_buffer );
00205 if( i_copy > 0 )
00206 {
00207 memcpy( p, b->p_buffer, i_copy );
00208 i_max -= i_copy;
00209 i_total += i_copy;
00210 p += i_copy;
00211
00212 if( i_max == 0 )
00213 return i_total;
00214 }
00215 }
00216 return i_total;
00217 }
00218
00219 static inline block_t *block_ChainGather( block_t *p_list )
00220 {
00221 int i_total = 0;
00222 mtime_t i_length = 0;
00223 block_t *b, *g;
00224
00225 if( p_list->p_next == NULL )
00226 return p_list;
00227
00228 for( b = p_list; b != NULL; b = b->p_next )
00229 {
00230 i_total += b->i_buffer;
00231 i_length += b->i_length;
00232 }
00233
00234 g = block_New( p_list->p_manager, i_total );
00235 block_ChainExtract( p_list, g->p_buffer, g->i_buffer );
00236
00237 g->i_flags = p_list->i_flags;
00238 g->i_pts = p_list->i_pts;
00239 g->i_dts = p_list->i_dts;
00240 g->i_length = i_length;
00241
00242
00243 block_ChainRelease( p_list );
00244 return g;
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 struct block_fifo_t
00263 {
00264 vlc_mutex_t lock;
00265 vlc_cond_t wait;
00266
00267 int i_depth;
00268 block_t *p_first;
00269 block_t **pp_last;
00270 int i_size;
00271 };
00272
00273
00274 #define block_FifoNew( a ) __block_FifoNew( VLC_OBJECT(a) )
00275 VLC_EXPORT( block_fifo_t *, __block_FifoNew, ( vlc_object_t * ) );
00276 VLC_EXPORT( void, block_FifoRelease, ( block_fifo_t * ) );
00277 VLC_EXPORT( void, block_FifoEmpty, ( block_fifo_t * ) );
00278 VLC_EXPORT( int, block_FifoPut, ( block_fifo_t *, block_t * ) );
00279 VLC_EXPORT( block_t *, block_FifoGet, ( block_fifo_t * ) );
00280 VLC_EXPORT( block_t *, block_FifoShow, ( block_fifo_t * ) );
00281
00282 #endif