Go to the documentation of this file.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 #include <sys/types.h>
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 typedef struct block_sys_t block_sys_t;
00055
00056
00057 #define BLOCK_FLAG_DISCONTINUITY 0x0001
00058
00059 #define BLOCK_FLAG_TYPE_I 0x0002
00060
00061 #define BLOCK_FLAG_TYPE_P 0x0004
00062
00063 #define BLOCK_FLAG_TYPE_B 0x0008
00064
00065 #define BLOCK_FLAG_TYPE_PB 0x0010
00066
00067 #define BLOCK_FLAG_HEADER 0x0020
00068
00069 #define BLOCK_FLAG_END_OF_FRAME 0x0040
00070
00071 #define BLOCK_FLAG_NO_KEYFRAME 0x0080
00072
00073 #define BLOCK_FLAG_END_OF_SEQUENCE 0x0100
00074
00075 #define BLOCK_FLAG_CLOCK 0x0200
00076
00077 #define BLOCK_FLAG_SCRAMBLED 0x0400
00078
00079 #define BLOCK_FLAG_PREROLL 0x0800
00080
00081 #define BLOCK_FLAG_CORRUPTED 0x1000
00082
00083 #define BLOCK_FLAG_TOP_FIELD_FIRST 0x2000
00084
00085 #define BLOCK_FLAG_BOTTOM_FIELD_FIRST 0x4000
00086
00087
00088 #define BLOCK_FLAG_INTERLACED_MASK \
00089 (BLOCK_FLAG_TOP_FIELD_FIRST|BLOCK_FLAG_BOTTOM_FIELD_FIRST)
00090
00091 #define BLOCK_FLAG_TYPE_MASK \
00092 (BLOCK_FLAG_TYPE_I|BLOCK_FLAG_TYPE_P|BLOCK_FLAG_TYPE_B|BLOCK_FLAG_TYPE_PB)
00093
00094
00095 #define BLOCK_FLAG_CORE_PRIVATE_MASK 0x00ff0000
00096 #define BLOCK_FLAG_CORE_PRIVATE_SHIFT 16
00097
00098
00099 #define BLOCK_FLAG_PRIVATE_MASK 0xff000000
00100 #define BLOCK_FLAG_PRIVATE_SHIFT 24
00101
00102 typedef void (*block_free_t) (block_t *);
00103
00104 struct block_t
00105 {
00106 block_t *p_next;
00107
00108 uint8_t *p_buffer;
00109 size_t i_buffer;
00110 uint8_t *p_start;
00111 size_t i_size;
00112
00113 uint32_t i_flags;
00114 unsigned i_nb_samples;
00115
00116 mtime_t i_pts;
00117 mtime_t i_dts;
00118 mtime_t i_length;
00119
00120
00121 block_free_t pf_release;
00122 };
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 VLC_API void block_Init( block_t *, void *, size_t );
00141 VLC_API block_t * block_Alloc( size_t ) VLC_USED;
00142 VLC_API block_t * block_Realloc( block_t *, ssize_t i_pre, size_t i_body ) VLC_USED;
00143
00144 #define block_New( dummy, size ) block_Alloc(size)
00145
00146 VLC_USED
00147 static inline block_t *block_Duplicate( block_t *p_block )
00148 {
00149 block_t *p_dup = block_Alloc( p_block->i_buffer );
00150 if( p_dup == NULL )
00151 return NULL;
00152
00153 p_dup->i_flags = p_block->i_flags;
00154 p_dup->i_nb_samples = p_block->i_nb_samples;
00155 p_dup->i_dts = p_block->i_dts;
00156 p_dup->i_pts = p_block->i_pts;
00157 p_dup->i_length = p_block->i_length;
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_API block_t * block_heap_Alloc(void *, size_t) VLC_USED;
00169 VLC_API block_t * block_mmap_Alloc(void *addr, size_t length) VLC_USED;
00170 VLC_API block_t * block_File(int fd) VLC_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
00309 VLC_API block_fifo_t * block_FifoNew( void ) VLC_USED;
00310 VLC_API void block_FifoRelease( block_fifo_t * );
00311 VLC_API void block_FifoPace( block_fifo_t *fifo, size_t max_depth, size_t max_size );
00312 VLC_API void block_FifoEmpty( block_fifo_t * );
00313 VLC_API size_t block_FifoPut( block_fifo_t *, block_t * );
00314 VLC_API void block_FifoWake( block_fifo_t * );
00315 VLC_API block_t * block_FifoGet( block_fifo_t * ) VLC_USED;
00316 VLC_API block_t * block_FifoShow( block_fifo_t * );
00317 size_t block_FifoSize( const block_fifo_t *p_fifo ) VLC_USED;
00318 VLC_API size_t block_FifoCount( const block_fifo_t *p_fifo ) VLC_USED;
00319
00320 #endif