From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C33374709B for ; Sat, 26 Aug 2023 15:14:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA4EE68C700; Sat, 26 Aug 2023 18:13:24 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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); -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".