mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-16 03:50:05 +01:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user