ffmpeg: factorize process_input() out

Based-on:
	commit 0c00fd80ee
	Author: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/28/head
Michael Niedermayer 13 years ago
parent b7e9eea31f
commit fc97f8e0e2
  1. 117
      ffmpeg.c

@ -2691,64 +2691,37 @@ static void reset_eagain(void)
input_files[i]->eagain = 0;
}
/*
* The following code is the main loop of the file converter
/**
* @return
* - 0 -- one packet was read and processed
* - AVERROR(EAGAIN) -- no packets were available for selected file,
* this function should be called again
* - AVERROR_EOF -- this function should not be called again
*/
static int transcode(void)
static int process_input(void)
{
int ret, i;
AVFormatContext *is, *os;
OutputStream *ost;
InputStream *ist;
int64_t timer_start;
ret = transcode_init();
if (ret < 0)
goto fail;
if (stdin_interaction) {
av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
}
timer_start = av_gettime();
#if HAVE_PTHREADS
if ((ret = init_input_threads()) < 0)
goto fail;
#endif
while (!received_sigterm) {
InputFile *ifile;
AVFormatContext *is;
InputStream *ist;
AVPacket pkt;
int ret, i, j;
int file_index;
int64_t cur_time= av_gettime();
/* if 'q' pressed, exits */
if (stdin_interaction)
if (check_keyboard_interaction(cur_time) < 0)
break;
/* check if there's any stream where output is still needed */
if (!need_output()) {
av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n");
break;
}
/* select the stream that we must read now */
file_index = select_input_file();
/* if none, if is finished */
if (file_index == -2) {
poll_filters() ;
continue;
return AVERROR(EAGAIN);
}
if (file_index < 0) {
if (got_eagain()) {
reset_eagain();
av_usleep(10000);
continue;
return AVERROR(EAGAIN);
}
av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n");
break;
return AVERROR_EOF;
}
ifile = input_files[file_index];
@ -2757,7 +2730,7 @@ static int transcode(void)
if (ret == AVERROR(EAGAIN)) {
ifile->eagain = 1;
continue;
return ret;
}
if (ret < 0) {
if (ret != AVERROR_EOF) {
@ -2775,9 +2748,9 @@ static int transcode(void)
}
if (opt_shortest)
break;
return AVERROR_EOF;
else
continue;
return AVERROR(EAGAIN);
}
reset_eagain();
@ -2832,7 +2805,8 @@ static int transcode(void)
input_files[ist->file_index]->ts_offset);
}
if (pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE && !copy_ts) {
if (pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
!copy_ts) {
int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
int64_t delta = pkt_dts - ist->next_dts;
if (is->iformat->flags & AVFMT_TS_DISCONT) {
@ -2879,12 +2853,65 @@ static int transcode(void)
if (exit_on_error)
exit_program(1);
av_free_packet(&pkt);
continue;
return AVERROR(EAGAIN);
}
discard_packet:
av_free_packet(&pkt);
return 0;
}
/*
* The following code is the main loop of the file converter
*/
static int transcode(void)
{
int ret, i;
AVFormatContext *os;
OutputStream *ost;
InputStream *ist;
int64_t timer_start;
ret = transcode_init();
if (ret < 0)
goto fail;
if (stdin_interaction) {
av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
}
timer_start = av_gettime();
#if HAVE_PTHREADS
if ((ret = init_input_threads()) < 0)
goto fail;
#endif
while (!received_sigterm) {
int64_t cur_time= av_gettime();
/* if 'q' pressed, exits */
if (stdin_interaction)
if (check_keyboard_interaction(cur_time) < 0)
break;
/* check if there's any stream where output is still needed */
if (!need_output()) {
av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n");
break;
}
ret = process_input();
if (ret < 0) {
if (ret == AVERROR(EAGAIN))
continue;
if (ret == AVERROR_EOF)
break;
av_log(NULL, AV_LOG_ERROR, "Error while filtering.\n");
break;
}
/* dump report by using the output first video and audio streams */
print_report(0, timer_start, cur_time);
}

Loading…
Cancel
Save