From patchwork Mon May 15 21:13:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 41635 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1906733pzb; Mon, 15 May 2023 14:13:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69b7e+TUCaruStgBEfzt0HYMs605kVIc+Ut0/3DlJfosBqrrS4R1hdst0BwlcDbzFIizbR X-Received: by 2002:a17:907:3207:b0:957:48c8:b081 with SMTP id xg7-20020a170907320700b0095748c8b081mr26723732ejb.24.1684185237297; Mon, 15 May 2023 14:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684185237; cv=none; d=google.com; s=arc-20160816; b=nEs1b1eM7MtRl7SWg2voA9dBJIM+7ZGg/H+AD/wNYBKCkuuh946/3VnlgnnizaVXsh cOXZJbRT9sYmTSwM9UiUYwfX3XSWjDS6cj11Ud4VbZCikM1WYdLa/ZIxwj/XmAoqS0tz HiNkmKR3YngmSPJ+S6nAlZ6dv/PmjHnw465tzRUXEghYbH4oKBmZ51TuXBuvO9vSftO8 FVrPDZX7sIx3OFogYTnM4yyKnBm3VjBwCe0qVAzwHCRgmRG3m2Zk4s7dwG+X03rWZi55 JChoTdD3PTSls+Jp3Vu7TwgDmVdKSvhZMFF64DioVq5Ncnd5EOx24rIYLcPYEGyapQDW t0kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=GWQOln2zr/0aCqp+J/y0bwV8l6M4fJWgvHUjXkk1U7U=; b=ZWiG2onpZqqVIh04xbmQ+urjzJtUQXjk0wU36hVTUyYktcBI+C7Q6SdKqFoTT2h4o1 ngPop2w9/DLWsbhXndIJdPP+E0iutbR2cnTa2NNiJ065y4PZFuXGtKpAlr8om/SDTXfz gMnTikoJf6SdGB5eaMdqwqUERqJiDTh/2WA1COIbtCQUZTuk5y5QTzs19ugw/0r4aB6w NYSCcdUTekuvkym60zTmBtGvh8yZC2knxLqi0z01Dm3CpeLlMyET3Q+4PojQJP95swo3 bAyzGU2YCY1ab6MHY/jOl/2jgn6EBQ5ZGWLWdywP1nHx10nRkFEbrVPtyq9s06m3KErg 9kKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=EAFNvlV9; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id vh11-20020a170907d38b00b0094edce87118si15052598ejc.1042.2023.05.15.14.13.56; Mon, 15 May 2023 14:13:57 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=EAFNvlV9; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 41B8D68BF99; Tue, 16 May 2023 00:13:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6AE3968BF05 for ; Tue, 16 May 2023 00:13:47 +0300 (EEST) Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-45046c21e55so3377267e0c.1 for ; Mon, 15 May 2023 14:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684185226; x=1686777226; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=i/1LC4d2VShgSdyC9iuMNjXh0LKXtiUWGvlFgIUgs+0=; b=EAFNvlV9GY1npJoZhMwb12dzJWebiB4Cyx4cQNh3LJ+X6XW7kMTcup1FQe9BcBaHr5 fLG+aZmye3mqeXCl/OBdlEpmiwWHdKtJpVFBys2DhGBKSSv1KLvT9I9Y7T/PSNRRnlNN qY61MK0Z9rXbEuikxS9BT3j9Nm6WMoGLTlbTRYjuJLv0uOdKqRuunjfVrV8+wLiY4a0C o/j6TbhI4/WkoBw0kwLGft1oRmMjmCj7L62S7YQ4cGprr6rU/Alj5YIyGzaG8jaR3wrx mC8BZhMR1od1EA7BN54rqxxnluMlme1S1EGLLoSyAkS2y+fnkX1mmh/9wM6FkDnTk1Tr r+2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684185226; x=1686777226; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=i/1LC4d2VShgSdyC9iuMNjXh0LKXtiUWGvlFgIUgs+0=; b=GbU2/AdMh+GFOpMJUtB/T1CX+6hj7JyrvQetAYuwDjfchtQiLpvfGtPadUC3nwKlEU nlsukeNpYk+FrcJ7m3m5bgjSPzz8YHeCFtp+smhwzfotrkuoFvwx+8A5ibPGZgfnhc+S xga7RqGBeKteQ3y/y3H/J0ldZZk5dq1FKibYbyU+tWh3HPjFzdvWaV0IC434+7ns2M6a cDUH6XH+nRFnmbop64li8vBvkjBmgJQeuWaw4mRQKsNNT9c2JkJAs3BvT6oFdLYdYtmE aL61RVILZfvrSLUX8UwapzU7VW7PymvYnnsQa/KgxC5tt9orXqWxC1Av11Ksm8w8048l C8JQ== X-Gm-Message-State: AC+VfDxwngbIjZx6NkNLgksZm3OWTqG+hhvLlwJgbVqIfn0jp0Hj/KMB lGWDm0tKxtbP/7vz80C/1HN2mf0KlWytZBCyitGkbXBu X-Received: by 2002:a1f:3f8a:0:b0:40f:f3e1:53c with SMTP id m132-20020a1f3f8a000000b0040ff3e1053cmr12233448vka.1.1684185225602; Mon, 15 May 2023 14:13:45 -0700 (PDT) MIME-Version: 1.0 From: Paul B Mahol Date: Mon, 15 May 2023 23:13:10 +0200 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] avfilter/src_movie: switch to activate() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3ei1JUstxiHT Attached. From a5bfd2e0856a02989ce7f1d2a4f3b9f45c77189f Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 2 Apr 2022 14:06:22 +0200 Subject: [PATCH 1/3] avfilter/src_movie: switch to activate() Signed-off-by: Paul B Mahol --- libavfilter/src_movie.c | 91 +++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index 5937613d13..a7d7c188e6 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -46,6 +46,7 @@ #include "audio.h" #include "avfilter.h" +#include "filters.h" #include "formats.h" #include "internal.h" #include "video.h" @@ -55,6 +56,7 @@ typedef struct MovieStream { AVCodecContext *codec_ctx; int64_t discontinuity_threshold; int64_t last_pts; + int got_eof; } MovieStream; typedef struct MovieContext { @@ -70,6 +72,7 @@ typedef struct MovieContext { int64_t discontinuity_threshold; int64_t ts_offset; int dec_threads; + int got_eagain; AVFormatContext *format_ctx; @@ -100,7 +103,6 @@ static const AVOption movie_options[]= { }; static int movie_config_output_props(AVFilterLink *outlink); -static int movie_request_frame(AVFilterLink *outlink); static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec) { @@ -314,7 +316,6 @@ static av_cold int movie_common_init(AVFilterContext *ctx) if (!pad.name) return AVERROR(ENOMEM); pad.config_props = movie_config_output_props; - pad.request_frame = movie_request_frame; if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0) return ret; if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && @@ -551,50 +552,70 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id) if (ret < 0) return ret; - return 0; + return 1; } -static int movie_request_frame(AVFilterLink *outlink) +static int activate(AVFilterContext *ctx) { - AVFilterContext *ctx = outlink->src; MovieContext *movie = ctx->priv; - unsigned out_id = FF_OUTLINK_IDX(outlink); + int ret = 0; - while (1) { - int got_eagain = 0, got_eof = 0; - int ret = 0; + /* check all decoders for available output */ + for (int i = 0; i < ctx->nb_outputs; i++) { + if (movie->st[i].got_eof) + continue; - /* check all decoders for available output */ - for (int i = 0; i < ctx->nb_outputs; i++) { + + if (ff_outlink_frame_wanted(ctx->outputs[i])) ret = movie_push_frame(ctx, i); - if (ret == AVERROR(EAGAIN)) - got_eagain++; - else if (ret == AVERROR_EOF) - got_eof++; - else if (ret < 0) - return ret; - else if (i == out_id) - return 0; + if (ret == AVERROR(EAGAIN)) + movie->got_eagain++; + else if (ret == AVERROR_EOF) + movie->st[i].got_eof = 1; + else if (ret < 0) + return ret; + else if (ret == 1) + return 0; + } + + if (movie->got_eagain) { + /* all decoders require more input -> read a new packet */ + movie->got_eagain = 0; + ret = movie_decode_packet(ctx); + if (ret < 0 && ret != AVERROR(EAGAIN)) + return ret; + ff_filter_set_ready(ctx, 100); + return 0; + } else { + int nb_eofs = 0; + + for (int i = 0; i < ctx->nb_outputs; i++) { + if (movie->st[i].got_eof) { + if (movie->loop_count == 1) + ff_outlink_set_status(ctx->outputs[i], AVERROR_EOF, movie->st[i].last_pts); + nb_eofs++; + } + } + + if (nb_eofs != ctx->nb_outputs) { + ff_filter_set_ready(ctx, 100); + return 0; } - if (got_eagain) { - /* all decoders require more input -> read a new packet */ - ret = movie_decode_packet(ctx); + if (movie->loop_count != 1) { + ret = rewind_file(ctx); if (ret < 0) return ret; - } else if (got_eof) { - /* all decoders flushed */ - if (movie->loop_count != 1) { - ret = rewind_file(ctx); - if (ret < 0) - return ret; - movie->loop_count -= movie->loop_count > 1; - av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n"); - continue; - } - return AVERROR_EOF; + movie->loop_count -= movie->loop_count > 1; + av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n"); + for (int i = 0; i < ctx->nb_outputs; i++) + movie->st[i].got_eof = 0; + ff_filter_set_ready(ctx, 100); } + return 0; } + + return FFERROR_NOT_READY; } static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, @@ -651,7 +672,7 @@ const AVFilter ff_avsrc_movie = { .init = movie_common_init, .uninit = movie_uninit, FILTER_QUERY_FUNC(movie_query_formats), - + .activate = activate, .inputs = NULL, .outputs = NULL, .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS, @@ -670,7 +691,7 @@ const AVFilter ff_avsrc_amovie = { .init = movie_common_init, .uninit = movie_uninit, FILTER_QUERY_FUNC(movie_query_formats), - + .activate = activate, .inputs = NULL, .outputs = NULL, .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS, -- 2.39.1