fftools/ffmpeg: move sending filtergraph commands to a separate function

Stop accessing filtergraph internals from keyboard reading code.
This commit is contained in:
Anton Khirnov 2023-07-16 12:38:24 +02:00
parent bff48e8d69
commit 3c397a1d46
3 changed files with 31 additions and 22 deletions

View File

@ -97,10 +97,6 @@
#include "libswresample/swresample.h" #include "libswresample/swresample.h"
#include "libavfilter/avfilter.h"
#include "libavfilter/buffersrc.h"
#include "libavfilter/buffersink.h"
#include "cmdutils.h" #include "cmdutils.h"
#include "ffmpeg.h" #include "ffmpeg.h"
#include "sync_queue.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) static int check_keyboard_interaction(int64_t cur_time)
{ {
int i, ret, key; int i, key;
static int64_t last_time; static int64_t last_time;
if (received_nb_signals) if (received_nb_signals)
return AVERROR_EXIT; 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) { (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", av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f command:%s arg:%s",
target, time, command, arg); target, time, command, arg);
for (i = 0; i < nb_filtergraphs; i++) { for (i = 0; i < nb_filtergraphs; i++)
FilterGraph *fg = filtergraphs[i]; fg_send_command(filtergraphs[i], time, target, command, arg,
if (fg->graph) { key == 'C');
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));
}
}
}
} else { } else {
av_log(NULL, AV_LOG_ERROR, av_log(NULL, AV_LOG_ERROR,
"Parse error, at least 3 arguments were expected, " "Parse error, at least 3 arguments were expected, "

View File

@ -759,6 +759,9 @@ void fg_free(FilterGraph **pfg);
*/ */
int fg_transcode_step(FilterGraph *graph, InputStream **best_ist); 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 * Get and encode new output from specified filtergraph, without causing
* activity. * activity.

View File

@ -1741,6 +1741,30 @@ int filtergraph_is_simple(const FilterGraph *fg)
return fgp->is_simple; 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) static int fg_output_step(OutputFilterPriv *ofp, int flush)
{ {
FilterGraphPriv *fgp = fgp_from_fg(ofp->ofilter.graph); FilterGraphPriv *fgp = fgp_from_fg(ofp->ofilter.graph);