summaryrefslogtreecommitdiff
path: root/libavcodec/cbs_h2645.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2018-03-05 11:04:59 -0300
committerJames Almer <jamrial@gmail.com>2018-03-05 11:44:51 -0300
commitdf3a2ff7670a76c808fa015559b867aecbbdcd54 (patch)
tree506f724c1d1662a8269b21bafed66843dc30c43b /libavcodec/cbs_h2645.c
parent69995a94d8409a704361dce9bc16ede7f88bdf1a (diff)
avcodec/cbs: use a reference to the assembled CodedBitstreamFragment buffer when writing packets
This saves one malloc + memcpy per packet The CodedBitstreamFragment buffer is padded to follow the requirements of AVPacket. Reviewed-by: jkqxz Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/cbs_h2645.c')
-rw-r--r--libavcodec/cbs_h2645.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 5ad0f2b500..5585831cf6 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1298,7 +1298,7 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
max_size += 3 + frag->units[i].data_size * 3 / 2;
}
- data = av_malloc(max_size);
+ data = av_malloc(max_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!data)
return AVERROR(ENOMEM);
@@ -1349,11 +1349,13 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
}
av_assert0(dp <= max_size);
- err = av_reallocp(&data, dp);
+ err = av_reallocp(&data, dp + AV_INPUT_BUFFER_PADDING_SIZE);
if (err)
return err;
+ memset(data + dp, 0, AV_INPUT_BUFFER_PADDING_SIZE);
- frag->data_ref = av_buffer_create(data, dp, NULL, NULL, 0);
+ frag->data_ref = av_buffer_create(data, dp + AV_INPUT_BUFFER_PADDING_SIZE,
+ NULL, NULL, 0);
if (!frag->data_ref) {
av_freep(&data);
return AVERROR(ENOMEM);