mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/evc_frame_merge: use av_fast_realloc()
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
1617d1a752
commit
96fc192733
|
@ -26,13 +26,11 @@
|
||||||
#include "evc.h"
|
#include "evc.h"
|
||||||
#include "evc_parse.h"
|
#include "evc_parse.h"
|
||||||
|
|
||||||
#define INIT_AU_BUF_CAPACITY 1024
|
|
||||||
|
|
||||||
// Access unit data
|
// Access unit data
|
||||||
typedef struct AccessUnitBuffer {
|
typedef struct AccessUnitBuffer {
|
||||||
uint8_t *data; // the data buffer
|
uint8_t *data; // the data buffer
|
||||||
size_t data_size; // size of data in bytes
|
size_t data_size; // size of data in bytes
|
||||||
size_t capacity; // buffer capacity
|
unsigned capacity; // buffer capacity
|
||||||
} AccessUnitBuffer;
|
} AccessUnitBuffer;
|
||||||
|
|
||||||
typedef struct EVCFMergeContext {
|
typedef struct EVCFMergeContext {
|
||||||
|
@ -72,9 +70,8 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
|
||||||
|
|
||||||
AVPacket *in = ctx->in;
|
AVPacket *in = ctx->in;
|
||||||
|
|
||||||
int free_space = 0;
|
|
||||||
size_t nalu_size = 0;
|
size_t nalu_size = 0;
|
||||||
uint8_t *nalu = NULL;
|
uint8_t *buffer, *nalu = NULL;
|
||||||
int au_end_found = 0;
|
int au_end_found = 0;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -102,15 +99,14 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
|
||||||
|
|
||||||
au_end_found = end_of_access_unit_found(parser_ctx);
|
au_end_found = end_of_access_unit_found(parser_ctx);
|
||||||
|
|
||||||
free_space = ctx->au_buffer.capacity - ctx->au_buffer.data_size;
|
buffer = av_fast_realloc(ctx->au_buffer.data, &ctx->au_buffer.capacity,
|
||||||
while (free_space < in->size) {
|
ctx->au_buffer.data_size + in->size);
|
||||||
ctx->au_buffer.capacity *= 2;
|
if (!buffer) {
|
||||||
free_space = ctx->au_buffer.capacity - ctx->au_buffer.data_size;
|
av_freep(&ctx->au_buffer.data);
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
if (free_space >= in->size)
|
|
||||||
ctx->au_buffer.data = av_realloc(ctx->au_buffer.data, ctx->au_buffer.capacity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->au_buffer.data = buffer;
|
||||||
memcpy(ctx->au_buffer.data + ctx->au_buffer.data_size, in->data, in->size);
|
memcpy(ctx->au_buffer.data + ctx->au_buffer.data_size, in->data, in->size);
|
||||||
|
|
||||||
ctx->au_buffer.data_size += in->size;
|
ctx->au_buffer.data_size += in->size;
|
||||||
|
@ -143,10 +139,6 @@ static int evc_frame_merge_init(AVBSFContext *bsf)
|
||||||
if (!ctx->in)
|
if (!ctx->in)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
ctx->au_buffer.capacity = INIT_AU_BUF_CAPACITY;
|
|
||||||
ctx->au_buffer.data = av_malloc(INIT_AU_BUF_CAPACITY);
|
|
||||||
ctx->au_buffer.data_size = 0;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue