MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / mf_push

Function mf_push

libhb/muxcommon.c:274–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274static void mf_push( hb_mux_t * mux, int tk, hb_buffer_t *buf )
275{
276 hb_track_t * track = mux->track[tk];
277 uint32_t mask = track->mf.flen - 1;
278 uint32_t in = track->mf.in;
279
280 hb_buffer_reduce( buf, buf->size );
281 if ( track->buffered_size > MAX_BUFFERING )
282 {
283 hb_bitvec_cpy(mux->rdy, mux->allRdy);
284 }
285 if ( ( ( in + 1 ) & mask ) == ( track->mf.out & mask ) )
286 {
287 // fifo is full - expand it to double the current size.
288 // This is a bit tricky because when we change the size
289 // it changes the modulus (mask) used to convert the in
290 // and out counters to fifo indices. Since existing items
291 // will be referenced at a new location after the expand
292 // we can't just realloc the fifo. If there were
293 // hundreds of fifo entries it would be worth it to have code
294 // for each of the four possible before/after configurations
295 // but these fifos are small so we just allocate a new chunk
296 // of memory then do element by element copies using the old &
297 // new masks then free the old fifo's memory..
298 track->mf.flen *= 2;
299 uint32_t nmask = track->mf.flen - 1;
300 hb_buffer_t **nfifo = malloc( track->mf.flen * sizeof(*nfifo) );
301 int indx = track->mf.out;
302 while ( indx != track->mf.in )
303 {
304 nfifo[indx & nmask] = track->mf.fifo[indx & mask];
305 ++indx;
306 }
307 free( track->mf.fifo );
308 track->mf.fifo = nfifo;
309 mask = nmask;
310 }
311 track->mf.fifo[in & mask] = buf;
312 track->mf.in = in + 1;
313 track->buffered_size += buf->size;
314 mux->buffered_size += buf->size;
315}
316
317static hb_buffer_t *mf_pull( hb_mux_t * mux, int tk )
318{

Callers 1

MoveToInternalFifosFunction · 0.85

Calls 2

hb_buffer_reduceFunction · 0.85
hb_bitvec_cpyFunction · 0.85

Tested by

no test coverage detected