From 36fcdc3fbe089bc01066e2afa5645f383025f0ec Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 17 Jun 2019 05:42:12 +0200 Subject: av1/h264_metadata, filter_units: Count down when deleting units When testing whether a particular unit should be kept or discarded, it is best to start at the very last unit of a fragment and count down, because that way a unit that will eventually be deleted won't be memmoved during earlier deletions; and frag/au->nb_units need only be evaluated once in this case and the counter is automatically correct when a unit got deleted. It also works for double loops, i.e. when looping over all SEI messages in all SEI units of an access unit. Signed-off-by: Andreas Rheinhardt --- libavcodec/filter_units_bsf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'libavcodec/filter_units_bsf.c') diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index f3691a5755..380f23e5a7 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -117,16 +117,14 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) goto fail; } - for (i = 0; i < frag->nb_units; i++) { + for (i = frag->nb_units - 1; i >= 0; i--) { for (j = 0; j < ctx->nb_types; j++) { if (frag->units[i].type == ctx->type_list[j]) break; } if (ctx->mode == REMOVE ? j < ctx->nb_types - : j >= ctx->nb_types) { + : j >= ctx->nb_types) ff_cbs_delete_unit(ctx->cbc, frag, i); - --i; - } } if (frag->nb_units == 0) { -- cgit v1.2.3