[FFmpeg-cvslog] filter_units: Avoid allocations and copies of packet structures
Andreas Rheinhardt
git at videolan.org
Mon Jul 8 00:17:23 EEST 2019
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Mon Jun 17 05:42:11 2019 +0200| [b0810454e473dd321a27c43de2d0e9d02fdba556] | committer: Mark Thompson
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 at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b0810454e473dd321a27c43de2d0e9d02fdba556
---
libavcodec/filter_units_bsf.c | 21 ++++++---------------
1 file 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;
}
More information about the ffmpeg-cvslog
mailing list