]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_random.c
avfilter/vf_psnr: remove unnecessary check
[ffmpeg] / libavfilter / vf_random.c
index 373a7db053af1220b4218828a2e7ddf1003cc569..5e4c30a3b5f50687b436564bfa2dd9a1ab7f156f 100644 (file)
@@ -97,8 +97,13 @@ static int request_frame(AVFilterLink *outlink)
 
     ret = ff_request_frame(ctx->inputs[0]);
 
+next:
     if (ret == AVERROR_EOF && !ctx->is_disabled && s->nb_frames > 0) {
         AVFrame *out = s->frames[s->nb_frames - 1];
+        if (!out) {
+            s->nb_frames--;
+            goto next;
+        }
         out->pts = s->pts[s->flush_idx++];
         ret = ff_filter_frame(outlink, out);
         s->frames[s->nb_frames - 1] = NULL;
@@ -108,6 +113,14 @@ static int request_frame(AVFilterLink *outlink)
     return ret;
 }
 
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    RandomContext *s = ctx->priv;
+
+    for (int i = 0; i < s->nb_frames; i++)
+        av_frame_free(&s->frames[i]);
+}
+
 static const AVFilterPad random_inputs[] = {
     {
         .name         = "default",
@@ -126,12 +139,13 @@ static const AVFilterPad random_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_vf_random = {
+const AVFilter ff_vf_random = {
     .name        = "random",
     .description = NULL_IF_CONFIG_SMALL("Return random frames."),
     .priv_size   = sizeof(RandomContext),
     .priv_class  = &random_class,
     .init        = init,
+    .uninit      = uninit,
     .inputs      = random_inputs,
     .outputs     = random_outputs,
 };