@@ -1235,19 +1235,20 @@ static int cbs_h2645_write_nal_unit(CodedBitstreamContext *ctx,
CodedBitstreamH2645Context *priv = ctx->priv_data;
enum AVCodecID codec_id = ctx->codec->codec_id;
PutBitContext pbc;
+ size_t write_buffer_size;
int err;
if (!priv->write_buffer) {
// Initial write buffer size is 1MB.
- priv->write_buffer_size = 1024 * 1024;
+ write_buffer_size = 1024 * 1024;
reallocate_and_try_again:
- err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);
- if (err < 0) {
+ av_fast_malloc(&priv->write_buffer, &priv->write_buffer_size, write_buffer_size);
+ if (!priv->write_buffer) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
"sufficiently large write buffer (last attempt "
- "%"SIZE_SPECIFIER" bytes).\n", priv->write_buffer_size);
- return err;
+ "%"SIZE_SPECIFIER" bytes).\n", write_buffer_size);
+ return AVERROR(ENOMEM);
}
}
@@ -1260,7 +1261,7 @@ static int cbs_h2645_write_nal_unit(CodedBitstreamContext *ctx,
if (err == AVERROR(ENOSPC)) {
// Overflow.
- priv->write_buffer_size *= 2;
+ write_buffer_size = priv->write_buffer_size * 2;
goto reallocate_and_try_again;
}
// Overflow but we didn't notice.
@@ -36,7 +36,7 @@ typedef struct CodedBitstreamH2645Context {
// Write buffer
uint8_t *write_buffer;
- size_t write_buffer_size;
+ unsigned write_buffer_size;
} CodedBitstreamH2645Context;
@@ -298,19 +298,20 @@ static int cbs_mpeg2_write_unit(CodedBitstreamContext *ctx,
{
CodedBitstreamMPEG2Context *priv = ctx->priv_data;
PutBitContext pbc;
+ size_t write_buffer_size;
int err;
if (!priv->write_buffer) {
// Initial write buffer size is 1MB.
- priv->write_buffer_size = 1024 * 1024;
+ write_buffer_size = 1024 * 1024;
reallocate_and_try_again:
- err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);
- if (err < 0) {
+ av_fast_malloc(&priv->write_buffer, &priv->write_buffer_size, write_buffer_size);
+ if (!priv->write_buffer) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
"sufficiently large write buffer (last attempt "
- "%"SIZE_SPECIFIER" bytes).\n", priv->write_buffer_size);
- return err;
+ "%"SIZE_SPECIFIER" bytes).\n", write_buffer_size);
+ return AVERROR(ENOMEM);
}
}
@@ -323,7 +324,7 @@ static int cbs_mpeg2_write_unit(CodedBitstreamContext *ctx,
if (err == AVERROR(ENOSPC)) {
// Overflow.
- priv->write_buffer_size *= 2;
+ write_buffer_size = priv->write_buffer_size * 2;
goto reallocate_and_try_again;
}
if (err < 0) {
@@ -222,7 +222,7 @@ typedef struct CodedBitstreamMPEG2Context {
// Write buffer.
uint8_t *write_buffer;
- size_t write_buffer_size;
+ unsigned write_buffer_size;
} CodedBitstreamMPEG2Context;
@@ -514,19 +514,20 @@ static int cbs_vp9_write_unit(CodedBitstreamContext *ctx,
CodedBitstreamVP9Context *priv = ctx->priv_data;
VP9RawFrame *frame = unit->content;
PutBitContext pbc;
+ size_t write_buffer_size;
int err;
if (!priv->write_buffer) {
// Initial write buffer size is 1MB.
- priv->write_buffer_size = 1024 * 1024;
+ write_buffer_size = 1024 * 1024;
reallocate_and_try_again:
- err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);
- if (err < 0) {
+ av_fast_malloc(&priv->write_buffer, &priv->write_buffer_size, write_buffer_size);
+ if (!priv->write_buffer) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
"sufficiently large write buffer (last attempt "
- "%zu bytes).\n", priv->write_buffer_size);
- return err;
+ "%"SIZE_SPECIFIER" bytes).\n", write_buffer_size);
+ return AVERROR(ENOMEM);
}
}
@@ -534,7 +535,7 @@ static int cbs_vp9_write_unit(CodedBitstreamContext *ctx,
err = cbs_vp9_write_frame(ctx, &pbc, frame);
if (err == AVERROR(ENOSPC)) {
- priv->write_buffer_size *= 2;
+ write_buffer_size = priv->write_buffer_size * 2;
goto reallocate_and_try_again;
}
if (err < 0)
@@ -550,7 +551,7 @@ static int cbs_vp9_write_unit(CodedBitstreamContext *ctx,
if (frame->data) {
if (unit->data_size + frame->data_size >
priv->write_buffer_size) {
- priv->write_buffer_size *= 2;
+ write_buffer_size = priv->write_buffer_size * 2;
goto reallocate_and_try_again;
}
@@ -194,7 +194,7 @@ typedef struct CodedBitstreamVP9Context {
// Write buffer.
uint8_t *write_buffer;
- size_t write_buffer_size;
+ unsigned write_buffer_size;
} CodedBitstreamVP9Context;
Use it instead of av_reallocp, as the contents of the existing buffer are ultimately discarded. Signed-off-by: James Almer <jamrial@gmail.com> --- Barely any speed gain in most cases, but realloc of this data is nonetheless unnecessary. libavcodec/cbs_h2645.c | 13 +++++++------ libavcodec/cbs_h2645.h | 2 +- libavcodec/cbs_mpeg2.c | 13 +++++++------ libavcodec/cbs_mpeg2.h | 2 +- libavcodec/cbs_vp9.c | 15 ++++++++------- libavcodec/cbs_vp9.h | 2 +- 6 files changed, 25 insertions(+), 22 deletions(-)