allocate a new buffer and override its free() callback so that * it is returned to the pool on free */
| 359 | /* allocate a new buffer and override its free() callback so that |
| 360 | * it is returned to the pool on free */ |
| 361 | static AVBufferRef *pool_alloc_buffer(AVBufferPool *pool) |
| 362 | { |
| 363 | BufferPoolEntry *buf; |
| 364 | AVBufferRef *ret; |
| 365 | |
| 366 | av_assert0(pool->alloc || pool->alloc2); |
| 367 | |
| 368 | ret = pool->alloc2 ? pool->alloc2(pool->opaque, pool->size) : |
| 369 | pool->alloc(pool->size); |
| 370 | if (!ret) |
| 371 | return NULL; |
| 372 | |
| 373 | buf = av_mallocz(sizeof(*buf)); |
| 374 | if (!buf) { |
| 375 | av_buffer_unref(&ret); |
| 376 | return NULL; |
| 377 | } |
| 378 | |
| 379 | buf->data = ret->buffer->data; |
| 380 | buf->opaque = ret->buffer->opaque; |
| 381 | buf->free = ret->buffer->free; |
| 382 | buf->pool = pool; |
| 383 | |
| 384 | ret->buffer->opaque = buf; |
| 385 | ret->buffer->free = pool_release_buffer; |
| 386 | |
| 387 | return ret; |
| 388 | } |
| 389 | |
| 390 | AVBufferRef *av_buffer_pool_get(AVBufferPool *pool) |
| 391 | { |
no test coverage detected