ffmpeg: move keyboard interaction in a function.

It makes the transcode loop easier to read (30% less code)
and the differences with avconv easier to spot.
This commit is contained in:
Nicolas George 2012-06-06 15:56:34 +02:00
parent 9915a33fc2
commit 25e87fc5f6
1 changed files with 95 additions and 89 deletions

View File

@ -3210,43 +3210,12 @@ static int select_input_file(uint8_t *no_packet)
return file_index;
}
/*
* The following code is the main loop of the file converter
*/
static int transcode(void)
static int check_keyboard_interaction(int64_t cur_time)
{
int ret, i;
AVFormatContext *is, *os;
OutputStream *ost;
InputStream *ist;
uint8_t *no_packet;
int no_packet_count = 0;
int64_t timer_start;
int key;
if (!(no_packet = av_mallocz(nb_input_files)))
exit_program(1);
ret = transcode_init();
if (ret < 0)
goto fail;
if (!using_stdin) {
av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
}
timer_start = av_gettime();
for (; received_sigterm == 0;) {
int file_index, ist_index;
AVPacket pkt;
int64_t cur_time= av_gettime();
/* if 'q' pressed, exits */
if (!using_stdin) {
int i, ret, key;
static int64_t last_time;
if (received_nb_signals)
break;
return AVERROR_EXIT;
/* read_key() returns 0 on EOF */
if(cur_time - last_time >= 100000 && !run_as_daemon){
key = read_key();
@ -3254,7 +3223,7 @@ static int transcode(void)
}else
key = -1;
if (key == 'q')
break;
return AVERROR_EXIT;
if (key == '+') av_log_set_level(av_log_get_level()+10);
if (key == '-') av_log_set_level(av_log_get_level()-10);
if (key == 's') qp_hist ^= 1;
@ -3313,7 +3282,7 @@ static int transcode(void)
input_streams[i]->st->codec->debug = debug;
}
for(i=0;i<nb_output_streams;i++) {
ost = output_streams[i];
OutputStream *ost = output_streams[i];
ost->st->codec->debug = debug;
}
if(debug) av_log_set_level(AV_LOG_DEBUG);
@ -3331,8 +3300,45 @@ static int transcode(void)
"s Show QP histogram\n"
);
}
return 0;
}
/*
* The following code is the main loop of the file converter
*/
static int transcode(void)
{
int ret, i;
AVFormatContext *is, *os;
OutputStream *ost;
InputStream *ist;
uint8_t *no_packet;
int no_packet_count = 0;
int64_t timer_start;
if (!(no_packet = av_mallocz(nb_input_files)))
exit_program(1);
ret = transcode_init();
if (ret < 0)
goto fail;
if (!using_stdin) {
av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
}
timer_start = av_gettime();
for (; received_sigterm == 0;) {
int file_index, ist_index;
AVPacket pkt;
int64_t cur_time= av_gettime();
/* if 'q' pressed, exits */
if (!using_stdin)
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");