Commit 7549f0ac authored by Andreas Rheinhardt's avatar Andreas Rheinhardt Committed by Mark Thompson

av1_metadata: Avoid allocations and copies of packet structures

This commit changes av1_metadata to (a) use ff_bsf_get_packet_ref
instead of ff_bsf_get_packet (thereby avoiding one malloc and free per
filtered packet) and (b) to use only one packet structure at all,
thereby avoiding a call to av_packet_copy_props.

(b) has been made possible by the recent changes to ff_cbs_write_packet.
Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
parent 1e93f506
...@@ -116,19 +116,18 @@ static int av1_metadata_update_sequence_header(AVBSFContext *bsf, ...@@ -116,19 +116,18 @@ static int av1_metadata_update_sequence_header(AVBSFContext *bsf,
return 0; return 0;
} }
static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out) static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
{ {
AV1MetadataContext *ctx = bsf->priv_data; AV1MetadataContext *ctx = bsf->priv_data;
AVPacket *in = NULL;
CodedBitstreamFragment *frag = &ctx->access_unit; CodedBitstreamFragment *frag = &ctx->access_unit;
AV1RawOBU td, *obu; AV1RawOBU td, *obu;
int err, i; int err, i;
err = ff_bsf_get_packet(bsf, &in); err = ff_bsf_get_packet_ref(bsf, pkt);
if (err < 0) if (err < 0)
return err; return err;
err = ff_cbs_read_packet(ctx->cbc, frag, in); err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
goto fail; goto fail;
...@@ -173,23 +172,18 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -173,23 +172,18 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out)
} }
} }
err = ff_cbs_write_packet(ctx->cbc, out, frag); err = ff_cbs_write_packet(ctx->cbc, pkt, frag);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
goto fail; goto fail;
} }
err = av_packet_copy_props(out, in);
if (err < 0)
goto fail;
err = 0; err = 0;
fail: fail:
ff_cbs_fragment_reset(ctx->cbc, frag); ff_cbs_fragment_reset(ctx->cbc, frag);
if (err < 0) if (err < 0)
av_packet_unref(out); av_packet_unref(pkt);
av_packet_free(&in);
return err; return err;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment