diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2019-06-20 01:45:07 +0200 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2019-07-07 22:59:25 +0100 |
commit | dd5ce54d2a44ecb8be6c3bb9396839a8d8fb1742 (patch) | |
tree | 0014e638ce34e08b15e2c37d11362f52ac0b8edc | |
parent | bc8b623b83d7962528594e2ee453b96a4ceeeb1e (diff) | |
download | ffmpeg-dd5ce54d2a44ecb8be6c3bb9396839a8d8fb1742.tar.gz |
mpeg2_metadata: Avoid allocations and copies of packet structures
This commit changes mpeg2_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: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r-- | libavcodec/mpeg2_metadata_bsf.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c index ba3a74afda..082137d786 100644 --- a/libavcodec/mpeg2_metadata_bsf.c +++ b/libavcodec/mpeg2_metadata_bsf.c @@ -179,18 +179,17 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, return 0; } -static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out) +static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) { MPEG2MetadataContext *ctx = bsf->priv_data; - AVPacket *in = NULL; CodedBitstreamFragment *frag = &ctx->fragment; int err; - err = ff_bsf_get_packet(bsf, &in); + err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) return err; - err = ff_cbs_read_packet(ctx->cbc, frag, in); + err = ff_cbs_read_packet(ctx->cbc, frag, pkt); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); goto fail; @@ -202,23 +201,18 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out) goto fail; } - err = ff_cbs_write_packet(ctx->cbc, out, frag); + err = ff_cbs_write_packet(ctx->cbc, pkt, frag); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); goto fail; } - err = av_packet_copy_props(out, in); - if (err < 0) - goto fail; - err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, frag); if (err < 0) - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return err; } |