mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-01-30 19:34:43 +00:00
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>
This commit is contained in:
parent
57f9bc90ae
commit
b0810454e4
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user