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
00048
00049
00050
00051
00052
00053 typedef struct block_sys_t block_sys_t;
00054
00055
00056 #define BLOCK_FLAG_DISCONTINUITY 0x0001
00057
00058 #define BLOCK_FLAG_TYPE_I 0x0002
00059
00060 #define BLOCK_FLAG_TYPE_P 0x0004
00061
00062 #define BLOCK_FLAG_TYPE_B 0x0008
00063
00064 #define BLOCK_FLAG_TYPE_PB 0x0010
00065
00066 #define BLOCK_FLAG_HEADER 0x0020
00067
00068 #define BLOCK_FLAG_END_OF_FRAME 0x0040
00069
00070 #define BLOCK_FLAG_NO_KEYFRAME 0x0080
00071
00072 #define BLOCK_FLAG_END_OF_SEQUENCE 0x0100
00073
00074 #define BLOCK_FLAG_CLOCK 0x0200
00075
00076 #define BLOCK_FLAG_SCRAMBLED 0x0400
00077
00078 #define BLOCK_FLAG_PREROLL 0x0800
00079
00080 #define BLOCK_FLAG_CORRUPTED 0x1000
00081
00082 #define BLOCK_FLAG_TOP_FIELD_FIRST 0x2000
00083
00084 #define BLOCK_FLAG_BOTTOM_FIELD_FIRST 0x4000
00085
00086
00087 #define BLOCK_FLAG_INTERLACED_MASK \
00088 (BLOCK_FLAG_TOP_FIELD_FIRST|BLOCK_FLAG_BOTTOM_FIELD_FIRST)
00089
00090 #define BLOCK_FLAG_TYPE_MASK \
00091 (BLOCK_FLAG_TYPE_I|BLOCK_FLAG_TYPE_P|BLOCK_FLAG_TYPE_B|BLOCK_FLAG_TYPE_PB)
00092
00093
00094 #define BLOCK_FLAG_CORE_PRIVATE_MASK 0x00ff0000
00095 #define BLOCK_FLAG_CORE_PRIVATE_SHIFT 16
00096
00097
00098 #define BLOCK_FLAG_PRIVATE_MASK 0xff000000
00099 #define BLOCK_FLAG_PRIVATE_SHIFT 24
00100
00101 typedef void (*block_free_t) (block_t *);
00102
00103 struct block_t
00104 {
00105 block_t *p_next;
00106
00107 uint32_t i_flags;
00108
00109 mtime_t i_pts;
00110 mtime_t i_dts;
00111 mtime_t i_length;
00112
00113 unsigned i_nb_samples;
00114 int i_rate;
00115
00116 size_t i_buffer;
00117 uint8_t *p_buffer;
00118
00119
00120 block_free_t pf_release;
00121 };
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 VLC_EXPORT( void, block_Init, ( block_t *, void *, size_t ) );
00140 VLC_EXPORT( block_t *, block_Alloc, ( size_t ) LIBVLC_USED );
00141 VLC_EXPORT( block_t *, block_Realloc, ( block_t *, ssize_t i_pre, size_t i_body ) LIBVLC_USED );
00142
00143 #define block_New( dummy, size ) block_Alloc(size)
00144
00145 LIBVLC_USED
00146 static inline block_t *block_Duplicate( block_t *p_block )
00147 {
00148 block_t *p_dup = block_Alloc( p_block->i_buffer );
00149 if( p_dup == NULL )
00150 return NULL;
00151
00152 p_dup->i_dts = p_block->i_dts;
00153 p_dup->i_pts = p_block->i_pts;
00154 p_dup->i_flags = p_block->i_flags;
00155 p_dup->i_length = p_block->i_length;
00156 p_dup->i_rate = p_block->i_rate;
00157 p_dup->i_nb_samples = p_block->i_nb_samples;
00158 memcpy( p_dup->p_buffer, p_block->p_buffer, p_block->i_buffer );
00159
00160 return p_dup;
00161 }
00162
00163 static inline void block_Release( block_t *p_block )
00164 {
00165 p_block->pf_release( p_block );
00166 }
00167
00168 VLC_EXPORT( block_t *, block_heap_Alloc, (void *, void *, size_t) LIBVLC_USED );
00169 VLC_EXPORT( block_t *, block_mmap_Alloc, (void *addr, size_t length) LIBVLC_USED );
00170 VLC_EXPORT( block_t *, block_File, (int fd) LIBVLC_USED );
00171
00172 static inline void block_Cleanup (void *block)
00173 {
00174 block_Release ((block_t *)block);
00175 }
00176 #define block_cleanup_push( block ) vlc_cleanup_push (block_Cleanup, block)
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 static inline void block_ChainAppend( block_t **pp_list, block_t *p_block )
00191 {
00192 if( *pp_list == NULL )
00193 {
00194 *pp_list = p_block;
00195 }
00196 else
00197 {
00198 block_t *p = *pp_list;
00199
00200 while( p->p_next ) p = p->p_next;
00201 p->p_next = p_block;
00202 }
00203 }
00204
00205 static inline void block_ChainLastAppend( block_t ***ppp_last, block_t *p_block )
00206 {
00207 block_t *p_last = p_block;
00208
00209 **ppp_last = p_block;
00210
00211 while( p_last->p_next ) p_last = p_last->p_next;
00212 *ppp_last = &p_last->p_next;
00213 }
00214
00215 static inline void block_ChainRelease( block_t *p_block )
00216 {
00217 while( p_block )
00218 {
00219 block_t *p_next = p_block->p_next;
00220 block_Release( p_block );
00221 p_block = p_next;
00222 }
00223 }
00224
00225 static size_t block_ChainExtract( block_t *p_list, void *p_data, size_t i_max )
00226 {
00227 size_t i_total = 0;
00228 uint8_t *p = (uint8_t*)p_data;
00229
00230 while( p_list && i_max )
00231 {
00232 size_t i_copy = __MIN( i_max, p_list->i_buffer );
00233 memcpy( p, p_list->p_buffer, i_copy );
00234 i_max -= i_copy;
00235 i_total += i_copy;
00236 p += i_copy;
00237
00238 p_list = p_list->p_next;
00239 }
00240 return i_total;
00241 }
00242
00243 static inline void block_ChainProperties( block_t *p_list, int *pi_count, size_t *pi_size, mtime_t *pi_length )
00244 {
00245 size_t i_size = 0;
00246 mtime_t i_length = 0;
00247 int i_count = 0;
00248
00249 while( p_list )
00250 {
00251 i_size += p_list->i_buffer;
00252 i_length += p_list->i_length;
00253 i_count++;
00254
00255 p_list = p_list->p_next;
00256 }
00257
00258 if( pi_size )
00259 *pi_size = i_size;
00260 if( pi_length )
00261 *pi_length = i_length;
00262 if( pi_count )
00263 *pi_count = i_count;
00264 }
00265
00266 static inline block_t *block_ChainGather( block_t *p_list )
00267 {
00268 size_t i_total = 0;
00269 mtime_t i_length = 0;
00270 block_t *g;
00271
00272 if( p_list->p_next == NULL )
00273 return p_list;
00274
00275 block_ChainProperties( p_list, NULL, &i_total, &i_length );
00276
00277 g = block_Alloc( i_total );
00278 block_ChainExtract( p_list, g->p_buffer, g->i_buffer );
00279
00280 g->i_flags = p_list->i_flags;
00281 g->i_pts = p_list->i_pts;
00282 g->i_dts = p_list->i_dts;
00283 g->i_length = i_length;
00284
00285
00286 block_ChainRelease( p_list );
00287 return g;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 VLC_EXPORT( block_fifo_t *, block_FifoNew, ( void ) LIBVLC_USED );
00309 VLC_EXPORT( void, block_FifoRelease, ( block_fifo_t * ) );
00310
00311 void block_FifoPace (block_fifo_t *fifo, size_t max_depth, size_t max_size);
00312 VLC_EXPORT( void, block_FifoEmpty, ( block_fifo_t * ) );
00313 VLC_EXPORT( size_t, block_FifoPut, ( block_fifo_t *, block_t * ) );
00314 VLC_EXPORT( void, block_FifoWake, ( block_fifo_t * ) );
00315 VLC_EXPORT( block_t *, block_FifoGet, ( block_fifo_t * ) LIBVLC_USED );
00316 VLC_EXPORT( block_t *, block_FifoShow, ( block_fifo_t * ) );
00317 size_t block_FifoSize( const block_fifo_t *p_fifo ) LIBVLC_USED;
00318 VLC_EXPORT( size_t, block_FifoCount, ( const block_fifo_t *p_fifo ) LIBVLC_USED );
00319
00320 #endif