fftools/ffmpeg: merge choose_output() and got_eagain()

These two functions are a part of a single logical action - determining
which, if any, output stream needs to be processed next. Keeping them
separate is a historical artifact that obscures what is actually being
done.
pull/389/head
Anton Khirnov 2 years ago
parent f009f84961
commit 5673da4797
  1. 41
      fftools/ffmpeg.c

@ -1683,9 +1683,11 @@ static int need_output(void)
/** /**
* Select the output stream to process. * Select the output stream to process.
* *
* @return selected output stream, or NULL if none available * @retval 0 an output stream was selected
* @retval AVERROR(EAGAIN) need to wait until more input is available
* @retval AVERROR_EOF no more streams need output
*/ */
static OutputStream *choose_output(void) static int choose_output(OutputStream **post)
{ {
int64_t opts_min = INT64_MAX; int64_t opts_min = INT64_MAX;
OutputStream *ost_min = NULL; OutputStream *ost_min = NULL;
@ -1704,15 +1706,19 @@ static OutputStream *choose_output(void)
ost->initialized, ost->inputs_done, ost->finished); ost->initialized, ost->inputs_done, ost->finished);
} }
if (!ost->initialized && !ost->inputs_done && !ost->finished) if (!ost->initialized && !ost->inputs_done && !ost->finished) {
return ost->unavailable ? NULL : ost; ost_min = ost;
break;
}
if (!ost->finished && opts < opts_min) { if (!ost->finished && opts < opts_min) {
opts_min = opts; opts_min = opts;
ost_min = ost->unavailable ? NULL : ost; ost_min = ost;
} }
} }
return ost_min; if (!ost_min)
return AVERROR_EOF;
*post = ost_min;
return ost_min->unavailable ? AVERROR(EAGAIN) : 0;
} }
static void set_tty_echo(int on) static void set_tty_echo(int on)
@ -1800,14 +1806,6 @@ static int check_keyboard_interaction(int64_t cur_time)
return 0; return 0;
} }
static int got_eagain(void)
{
for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost))
if (ost->unavailable)
return 1;
return 0;
}
static void reset_eagain(void) static void reset_eagain(void)
{ {
int i; int i;
@ -2052,13 +2050,12 @@ static int transcode_step(void)
InputStream *ist = NULL; InputStream *ist = NULL;
int ret; int ret;
ost = choose_output(); ret = choose_output(&ost);
if (!ost) { if (ret == AVERROR(EAGAIN)) {
if (got_eagain()) { reset_eagain();
reset_eagain(); av_usleep(10000);
av_usleep(10000); return 0;
return 0; } else if (ret < 0) {
}
av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n"); av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n");
return AVERROR_EOF; return AVERROR_EOF;
} }

Loading…
Cancel
Save