@@ -116,20 +116,18 @@ static int hevc_mp4toannexb_init(AVBSFContext *ctx)
return 0;
}
-static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
+static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt)
{
HEVCBSFContext *s = ctx->priv_data;
PutByteContext pb;
- AVPacket *in;
+ AVBufferRef *out = NULL;
int ret;
- ret = ff_bsf_get_packet(ctx, &in);
+ ret = ff_bsf_get_packet_ref(ctx, pkt);
if (ret < 0)
return ret;
if (!s->extradata_parsed) {
- av_packet_move_ref(out, in);
- av_packet_free(&in);
return 0;
}
@@ -138,7 +136,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
uint64_t out_size = 0;
int got_irap = 0;
- bytestream2_init(&gb, in->data, in->size);
+ bytestream2_init(&gb, pkt->data, pkt->size);
while (bytestream2_get_bytes_left(&gb)) {
uint32_t nalu_size = 0;
@@ -181,7 +179,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
ret = AVERROR(ERANGE);
goto fail;
}
- ret = av_new_packet(out, out_size);
+ ret = ff_buffer_padded_realloc(&out, out_size);
if (ret < 0)
goto fail;
@@ -189,14 +187,11 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
}
}
- ret = av_packet_copy_props(out, in);
- if (ret < 0)
- goto fail;
+ ff_packet_replace_buffer(pkt, out);
fail:
if (ret < 0)
- av_packet_unref(out);
- av_packet_free(&in);
+ av_packet_unref(pkt);
return ret;
}
This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavcodec/hevc_mp4toannexb_bsf.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)