From patchwork Sat Aug 26 15:11:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 43343 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:906:4f0f:b0:99c:ff93:59c5 with SMTP id t15csp996487eju; Sat, 26 Aug 2023 08:14:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPdUUXPcdeDlp5SDW6RLUx9yMtzpFbHrioEXb+TjBnEO9YdGNPUSqBQrA6fi8Y2eiwVuQm X-Received: by 2002:a2e:86d8:0:b0:2bc:c771:5498 with SMTP id n24-20020a2e86d8000000b002bcc7715498mr12946632ljj.18.1693062884432; Sat, 26 Aug 2023 08:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693062884; cv=none; d=google.com; s=arc-20160816; b=Z8jJNy8TD0O/1prv2HDIwv86hG9nxGxuHMVE0Y8u6vYfda3/6HN+IIgfMJWfUHpBjP jcRgj6rDMeOGqEMmd5OnHZsEFUmJ8hO0b2f827C9g+kwmuSgrwNnSkyzttzDyY5s0eWD Dx7/oi95Sv4AmgUTrR31Nuyj1lLfuQtI4ddXocPL5qlrA5C72KGFL3dPQBhsj1E70/im mPIyY9tRDkhC8YiBK3L709SsK/sD6dBe20ftIcEbcs4wM7p+lMhzEKRyZN9KZQ6oIsxE TnLXO4CDekch5xPkITWW4HfgST5j9qhVXfQ6KrRf4FUiA5k/y/GJUH/VAT7A3pmyUXk3 iXXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=gpfYn2mevj7aOMYlXAv6nw+l6w6cTu6Rkqlxkyf8ZbY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=iMCA3k28w4ciC1PPoCWMBa54K/15soRM5fLFswFXvi0vPpR5ZZhDhofCoPTWmffuE3 lQOL2uUYkA+PQB4fzwITVfxGeq9/mOpl/Zw1EQtfLMynRwmetUHi3JQnOtnewFSnimvz ta34TH/hzSYB7k7m5Z7+FfjlsCrmXc0I8pUkqPt0739e+olYd9nSIaKT6Iu5vd6ArxLe xy/fzFcTgd5mjSXawlsNfCl+J60XImsaGxkgpkIG0zKD0KptqwdTGWIn13+uYQ7+XUQn 2SZ9a1Cunq/wOSG+fBpUvpDjojiAucEcFHeq1HZv5WEzl8ZiKF1OOkPquG6tIXuUnkQ8 Cd0A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id pw7-20020a17090720a700b0099bd68129dcsi2244553ejb.760.2023.08.26.08.14.44; Sat, 26 Aug 2023 08:14:44 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1251368C608; Sat, 26 Aug 2023 18:13:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D493D68C67A for ; Sat, 26 Aug 2023 18:13:16 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A903C240D9B for ; Sat, 26 Aug 2023 17:13:15 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id rw1Qxd9fEyOi for ; Sat, 26 Aug 2023 17:13:13 +0200 (CEST) Received: from mail1.khirnov.net (mail1.khirnov.net [IPv6:2a00:c500:561:206::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail1.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 587322404EA for ; Sat, 26 Aug 2023 17:13:12 +0200 (CEST) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id A92C740FA for ; Sat, 26 Aug 2023 17:15:15 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 3ProfpE16_5O for ; Sat, 26 Aug 2023 17:15:15 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 65068410E for ; Sat, 26 Aug 2023 17:15:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0C1D53A17A1 for ; Sat, 26 Aug 2023 17:11:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Aug 2023 17:11:44 +0200 Message-Id: <20230826151144.24858-18-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230826151144.24858-1-anton@khirnov.net> References: <20230826151144.24858-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/18] fftools/ffmpeg: move sending filtergraph commands to a separate function 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: qPy8+I5vbTPm Stop accessing filtergraph internals from keyboard reading code. --- fftools/ffmpeg.c | 26 ++++---------------------- fftools/ffmpeg.h | 3 +++ fftools/ffmpeg_filter.c | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 45844b489f..f1c5f40caf 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -97,10 +97,6 @@ #include "libswresample/swresample.h" -#include "libavfilter/avfilter.h" -#include "libavfilter/buffersrc.h" -#include "libavfilter/buffersink.h" - #include "cmdutils.h" #include "ffmpeg.h" #include "sync_queue.h" @@ -977,7 +973,7 @@ static void set_tty_echo(int on) static int check_keyboard_interaction(int64_t cur_time) { - int i, ret, key; + int i, key; static int64_t last_time; if (received_nb_signals) return AVERROR_EXIT; @@ -1010,23 +1006,9 @@ static int check_keyboard_interaction(int64_t cur_time) (n = sscanf(buf, "%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) { av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f command:%s arg:%s", target, time, command, arg); - for (i = 0; i < nb_filtergraphs; i++) { - FilterGraph *fg = filtergraphs[i]; - if (fg->graph) { - if (time < 0) { - ret = avfilter_graph_send_command(fg->graph, target, command, arg, buf, sizeof(buf), - key == 'c' ? AVFILTER_CMD_FLAG_ONE : 0); - fprintf(stderr, "Command reply for stream %d: ret:%d res:\n%s", i, ret, buf); - } else if (key == 'c') { - fprintf(stderr, "Queuing commands only on filters supporting the specific command is unsupported\n"); - ret = AVERROR_PATCHWELCOME; - } else { - ret = avfilter_graph_queue_command(fg->graph, target, command, arg, 0, time); - if (ret < 0) - fprintf(stderr, "Queuing command failed with error %s\n", av_err2str(ret)); - } - } - } + for (i = 0; i < nb_filtergraphs; i++) + fg_send_command(filtergraphs[i], time, target, command, arg, + key == 'C'); } else { av_log(NULL, AV_LOG_ERROR, "Parse error, at least 3 arguments were expected, " diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9c85df5bdf..b146f1f2dc 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -759,6 +759,9 @@ void fg_free(FilterGraph **pfg); */ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist); +void fg_send_command(FilterGraph *fg, double time, const char *target, + const char *command, const char *arg, int all_filters); + /** * Get and encode new output from specified filtergraph, without causing * activity. diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index e65e7cb64d..4ba20342a9 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1741,6 +1741,30 @@ int filtergraph_is_simple(const FilterGraph *fg) return fgp->is_simple; } +void fg_send_command(FilterGraph *fg, double time, const char *target, + const char *command, const char *arg, int all_filters) +{ + int ret; + + if (!fg->graph) + return; + + if (time < 0) { + char response[4096]; + ret = avfilter_graph_send_command(fg->graph, target, command, arg, + response, sizeof(response), + all_filters ? 0 : AVFILTER_CMD_FLAG_ONE); + fprintf(stderr, "Command reply for stream %d: ret:%d res:\n%s", + fg->index, ret, response); + } else if (!all_filters) { + fprintf(stderr, "Queuing commands only on filters supporting the specific command is unsupported\n"); + } else { + ret = avfilter_graph_queue_command(fg->graph, target, command, arg, 0, time); + if (ret < 0) + fprintf(stderr, "Queuing command failed with error %s\n", av_err2str(ret)); + } +} + static int fg_output_step(OutputFilterPriv *ofp, int flush) { FilterGraphPriv *fgp = fgp_from_fg(ofp->ofilter.graph);