diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2019-06-17 05:42:11 +0200 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2019-07-07 22:17:07 +0100 |
commit | b0810454e473dd321a27c43de2d0e9d02fdba556 (patch) | |
tree | 4564345d67710217c4476d22ce9ebe05307a10e4 /libavcodec/filter_units_bsf.c | |
parent | 57f9bc90ae0993768c3ee70c5d9041aecc8593ed (diff) | |
download | ffmpeg-b0810454e473dd321a27c43de2d0e9d02fdba556.tar.gz |
filter_units: Avoid allocations and copies of packet structures
This commit changes filter_units 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 (or, in case of
passthrough, to av_packet_move_ref).
(b) has been made possible by the recent changes to ff_cbs_write_packet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/filter_units_bsf.c')
-rw-r--r-- | libavcodec/filter_units_bsf.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index 8c501e1726..f3691a5755 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -98,24 +98,20 @@ invalid: return AVERROR(EINVAL); } -static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) +static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) { FilterUnitsContext *ctx = bsf->priv_data; CodedBitstreamFragment *frag = &ctx->fragment; - AVPacket *in = NULL; int err, i, j; - err = ff_bsf_get_packet(bsf, &in); + err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) return err; - if (ctx->mode == NOOP) { - av_packet_move_ref(out, in); - av_packet_free(&in); + if (ctx->mode == NOOP) return 0; - } - 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; @@ -139,21 +135,16 @@ static int filter_units_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; - fail: if (err < 0) - av_packet_unref(out); + av_packet_unref(pkt); ff_cbs_fragment_reset(ctx->cbc, frag); - av_packet_free(&in); return err; } |