1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavu/fifo: add av_fifo_alloc_array function

Allows to alloc fifo buffer by passing
number of elements and size of element.

Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
This commit is contained in:
Lukasz Marek 2014-05-10 08:06:53 +02:00
parent d43c303038
commit 7336e39f3c
4 changed files with 33 additions and 7 deletions

View File

@ -15,6 +15,9 @@ libavutil: 2012-10-22
API changes, most recent first: API changes, most recent first:
2014-05-xx - xxxxxxx - lavu 52.86.100 - fifo.h
Add av_fifo_alloc_array() function.
2014-05-xx - xxxxxxx - lavu 53.15.0 - frame.h, display.h 2014-05-xx - xxxxxxx - lavu 53.15.0 - frame.h, display.h
Add AV_FRAME_DATA_DISPLAYMATRIX for exporting frame-level Add AV_FRAME_DATA_DISPLAYMATRIX for exporting frame-level
spatial rendering on video frames for proper display. spatial rendering on video frames for proper display.

View File

@ -24,19 +24,34 @@
#include "common.h" #include "common.h"
#include "fifo.h" #include "fifo.h"
AVFifoBuffer *av_fifo_alloc(unsigned int size) static AVFifoBuffer *fifo_alloc_common(void *buffer, size_t size)
{ {
AVFifoBuffer *f = av_mallocz(sizeof(AVFifoBuffer)); AVFifoBuffer *f;
if (!f) if (!buffer)
return NULL; return NULL;
f->buffer = av_malloc(size); f = av_mallocz(sizeof(AVFifoBuffer));
if (!f) {
av_free(buffer);
return NULL;
}
f->buffer = buffer;
f->end = f->buffer + size; f->end = f->buffer + size;
av_fifo_reset(f); av_fifo_reset(f);
if (!f->buffer)
av_freep(&f);
return f; return f;
} }
AVFifoBuffer *av_fifo_alloc(unsigned int size)
{
void *buffer = av_malloc(size);
return fifo_alloc_common(buffer, size);
}
AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
{
void *buffer = av_malloc_array(nmemb, size);
return fifo_alloc_common(buffer, nmemb * size);
}
void av_fifo_free(AVFifoBuffer *f) void av_fifo_free(AVFifoBuffer *f)
{ {
if (f) { if (f) {

View File

@ -41,6 +41,14 @@ typedef struct AVFifoBuffer {
*/ */
AVFifoBuffer *av_fifo_alloc(unsigned int size); AVFifoBuffer *av_fifo_alloc(unsigned int size);
/**
* Initialize an AVFifoBuffer.
* @param nmemb number of elements
* @param size size of the single element
* @return AVFifoBuffer or NULL in case of memory allocation failure
*/
AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size);
/** /**
* Free an AVFifoBuffer. * Free an AVFifoBuffer.
* @param f AVFifoBuffer to free * @param f AVFifoBuffer to free

View File

@ -56,7 +56,7 @@
*/ */
#define LIBAVUTIL_VERSION_MAJOR 52 #define LIBAVUTIL_VERSION_MAJOR 52
#define LIBAVUTIL_VERSION_MINOR 85 #define LIBAVUTIL_VERSION_MINOR 86
#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \