| 356 | } |
| 357 | |
| 358 | hb_buffer_t * hb_buffer_init_internal( int size ) |
| 359 | { |
| 360 | hb_buffer_t * b; |
| 361 | // Certain libraries (hrm ffmpeg) expect buffers passed to them to |
| 362 | // end on certain alignments. So allocate some extra bytes. |
| 363 | // Note that we can't simply align the end of our buffer because |
| 364 | // sometimes we feed data to these libraries starting from arbitrary |
| 365 | // points within the buffer. |
| 366 | int alloc = size ? size + AV_INPUT_BUFFER_PADDING_SIZE : 0; |
| 367 | hb_fifo_t *buffer_pool = size_to_pool( alloc ); |
| 368 | |
| 369 | if( buffer_pool ) |
| 370 | { |
| 371 | b = hb_fifo_get( buffer_pool ); |
| 372 | |
| 373 | if( b ) |
| 374 | { |
| 375 | /* |
| 376 | * Zero the contents of the buffer, would be nice if we |
| 377 | * didn't have to do this. |
| 378 | */ |
| 379 | uint8_t *data = b->data; |
| 380 | |
| 381 | memset( b, 0, sizeof(hb_buffer_t) ); |
| 382 | b->alloc = buffer_pool->buffer_size; |
| 383 | b->size = size; |
| 384 | if (size) |
| 385 | { |
| 386 | b->data = data; |
| 387 | } |
| 388 | b->storage = NULL; |
| 389 | b->s.start = AV_NOPTS_VALUE; |
| 390 | b->s.stop = AV_NOPTS_VALUE; |
| 391 | b->s.renderOffset = AV_NOPTS_VALUE; |
| 392 | b->s.scr_sequence = -1; |
| 393 | |
| 394 | #if defined(HB_BUFFER_DEBUG) |
| 395 | hb_lock(buffers.lock); |
| 396 | hb_list_add(buffers.alloc_list, b); |
| 397 | hb_unlock(buffers.lock); |
| 398 | #endif |
| 399 | return( b ); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * No existing buffers, create a new one |
| 405 | */ |
| 406 | if( !( b = calloc( sizeof( hb_buffer_t ), 1 ) ) ) |
| 407 | { |
| 408 | hb_error( "out of memory" ); |
| 409 | return NULL; |
| 410 | } |
| 411 | |
| 412 | b->size = size; |
| 413 | b->alloc = buffer_pool ? buffer_pool->buffer_size : alloc; |
| 414 | |
| 415 | if (size) |
no test coverage detected