Commit 3ccf22c6 authored by Nicolas George's avatar Nicolas George

ffmpeg: keep packet/frame availability in global structures.

This replaces the use of the no_packet and no_frame arrays.
parent b9c129be
...@@ -262,6 +262,7 @@ typedef struct InputStream { ...@@ -262,6 +262,7 @@ typedef struct InputStream {
typedef struct InputFile { typedef struct InputFile {
AVFormatContext *ctx; AVFormatContext *ctx;
int eof_reached; /* true if eof reached */ int eof_reached; /* true if eof reached */
int unavailable; /* true if the file is unavailable (possibly temporarily) */
int ist_index; /* index of first stream in input_streams */ int ist_index; /* index of first stream in input_streams */
int64_t ts_offset; int64_t ts_offset;
int nb_streams; /* number of stream that ffmpeg is aware of; may be different int nb_streams; /* number of stream that ffmpeg is aware of; may be different
...@@ -325,6 +326,7 @@ typedef struct OutputStream { ...@@ -325,6 +326,7 @@ typedef struct OutputStream {
double swr_dither_scale; double swr_dither_scale;
AVDictionary *opts; AVDictionary *opts;
int is_past_recording_time; int is_past_recording_time;
int unavailable; /* true if the steram is unavailable (possibly temporarily) */
int stream_copy; int stream_copy;
const char *attachment_filename; const char *attachment_filename;
int copy_initial_nonkeyframes; int copy_initial_nonkeyframes;
...@@ -3337,14 +3339,14 @@ static int need_output(void) ...@@ -3337,14 +3339,14 @@ static int need_output(void)
return 0; return 0;
} }
static int input_acceptable(InputStream *ist, uint8_t *no_packet) static int input_acceptable(InputStream *ist)
{ {
av_assert1(!ist->discard); av_assert1(!ist->discard);
return !no_packet[ist->file_index] && return !input_files[ist->file_index]->unavailable &&
!input_files[ist->file_index]->eof_reached; !input_files[ist->file_index]->eof_reached;
} }
static int find_graph_input(FilterGraph *graph, uint8_t *no_packet) static int find_graph_input(FilterGraph *graph)
{ {
int i, nb_req_max = 0, file_index = -1; int i, nb_req_max = 0, file_index = -1;
...@@ -3352,7 +3354,7 @@ static int find_graph_input(FilterGraph *graph, uint8_t *no_packet) ...@@ -3352,7 +3354,7 @@ static int find_graph_input(FilterGraph *graph, uint8_t *no_packet)
int nb_req = av_buffersrc_get_nb_failed_requests(graph->inputs[i]->filter); int nb_req = av_buffersrc_get_nb_failed_requests(graph->inputs[i]->filter);
if (nb_req > nb_req_max) { if (nb_req > nb_req_max) {
InputStream *ist = graph->inputs[i]->ist; InputStream *ist = graph->inputs[i]->ist;
if (input_acceptable(ist, no_packet)) { if (input_acceptable(ist)) {
nb_req_max = nb_req; nb_req_max = nb_req;
file_index = ist->file_index; file_index = ist->file_index;
} }
...@@ -3365,23 +3367,20 @@ static int find_graph_input(FilterGraph *graph, uint8_t *no_packet) ...@@ -3365,23 +3367,20 @@ static int find_graph_input(FilterGraph *graph, uint8_t *no_packet)
/** /**
* Select the input file to read from. * Select the input file to read from.
* *
* @param no_packet array of booleans, one per input file;
* if set, the input file must not be considered
* @param no_frame array of boolean, one per output stream;
* if set, the stream must not be considered;
* for internal use
* @return >=0 index of the input file to use; * @return >=0 index of the input file to use;
* -1 if no file is acceptable; * -1 if no file is acceptable;
* -2 to read from filters without reading from a file * -2 to read from filters without reading from a file
*/ */
static int select_input_file(uint8_t *no_packet, uint8_t *no_frame) static int select_input_file(void)
{ {
int i, ret, nb_active_out = nb_output_streams, ost_index = -1; int i, ret, nb_active_out = nb_output_streams, ost_index = -1;
int64_t opts_min; int64_t opts_min;
OutputStream *ost; OutputStream *ost;
AVFilterBufferRef *dummy; AVFilterBufferRef *dummy;
memset(no_frame, 0, nb_output_streams); for (i = 0; i < nb_output_streams; i++)
nb_active_out -= output_streams[i]->unavailable =
output_streams[i]->is_past_recording_time;
while (nb_active_out) { while (nb_active_out) {
opts_min = INT64_MAX; opts_min = INT64_MAX;
ost_index = -1; ost_index = -1;
...@@ -3389,8 +3388,7 @@ static int select_input_file(uint8_t *no_packet, uint8_t *no_frame) ...@@ -3389,8 +3388,7 @@ static int select_input_file(uint8_t *no_packet, uint8_t *no_frame)
OutputStream *ost = output_streams[i]; OutputStream *ost = output_streams[i];
int64_t opts = av_rescale_q(ost->st->cur_dts, ost->st->time_base, int64_t opts = av_rescale_q(ost->st->cur_dts, ost->st->time_base,
AV_TIME_BASE_Q); AV_TIME_BASE_Q);
if (!no_frame[i] && !ost->is_past_recording_time && if (!ost->unavailable && opts < opts_min) {
opts < opts_min) {
opts_min = opts; opts_min = opts;
ost_index = i; ost_index = i;
} }
...@@ -3402,7 +3400,7 @@ static int select_input_file(uint8_t *no_packet, uint8_t *no_frame) ...@@ -3402,7 +3400,7 @@ static int select_input_file(uint8_t *no_packet, uint8_t *no_frame)
if (ost->source_index >= 0) { if (ost->source_index >= 0) {
/* ost is directly connected to an input */ /* ost is directly connected to an input */
InputStream *ist = input_streams[ost->source_index]; InputStream *ist = input_streams[ost->source_index];
if (input_acceptable(ist, no_packet)) if (input_acceptable(ist))
return ist->file_index; return ist->file_index;
} else { } else {
/* ost is connected to a complex filtergraph */ /* ost is connected to a complex filtergraph */
...@@ -3411,11 +3409,11 @@ static int select_input_file(uint8_t *no_packet, uint8_t *no_frame) ...@@ -3411,11 +3409,11 @@ static int select_input_file(uint8_t *no_packet, uint8_t *no_frame)
AV_BUFFERSINK_FLAG_PEEK); AV_BUFFERSINK_FLAG_PEEK);
if (ret >= 0) if (ret >= 0)
return -2; return -2;
ret = find_graph_input(ost->filter->graph, no_packet); ret = find_graph_input(ost->filter->graph);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
} }
no_frame[ost_index] = 1; ost->unavailable = 1;
nb_active_out--; nb_active_out--;
} }
return -1; return -1;
...@@ -3642,14 +3640,9 @@ static int transcode(void) ...@@ -3642,14 +3640,9 @@ static int transcode(void)
AVFormatContext *is, *os; AVFormatContext *is, *os;
OutputStream *ost; OutputStream *ost;
InputStream *ist; InputStream *ist;
uint8_t *no_packet, *no_frame;
int no_packet_count = 0; int no_packet_count = 0;
int64_t timer_start; int64_t timer_start;
if (!(no_packet = av_mallocz(nb_input_files + nb_output_streams)))
exit_program(1);
no_frame = no_packet + nb_input_files;
ret = transcode_init(); ret = transcode_init();
if (ret < 0) if (ret < 0)
goto fail; goto fail;
...@@ -3682,7 +3675,7 @@ static int transcode(void) ...@@ -3682,7 +3675,7 @@ static int transcode(void)
} }
/* select the stream that we must read now */ /* select the stream that we must read now */
file_index = select_input_file(no_packet, no_frame); file_index = select_input_file();
/* if none, if is finished */ /* if none, if is finished */
if (file_index == -2) { if (file_index == -2) {
poll_filters() ; poll_filters() ;
...@@ -3691,7 +3684,8 @@ static int transcode(void) ...@@ -3691,7 +3684,8 @@ static int transcode(void)
if (file_index < 0) { if (file_index < 0) {
if (no_packet_count) { if (no_packet_count) {
no_packet_count = 0; no_packet_count = 0;
memset(no_packet, 0, nb_input_files); for (i = 0; i < nb_input_files; i++)
input_files[i]->unavailable = 0;
av_usleep(10000); av_usleep(10000);
continue; continue;
} }
...@@ -3703,7 +3697,7 @@ static int transcode(void) ...@@ -3703,7 +3697,7 @@ static int transcode(void)
ret = get_input_packet(input_files[file_index], &pkt); ret = get_input_packet(input_files[file_index], &pkt);
if (ret == AVERROR(EAGAIN)) { if (ret == AVERROR(EAGAIN)) {
no_packet[file_index] = 1; input_files[file_index]->unavailable = 1;
no_packet_count++; no_packet_count++;
continue; continue;
} }
...@@ -3729,7 +3723,8 @@ static int transcode(void) ...@@ -3729,7 +3723,8 @@ static int transcode(void)
} }
no_packet_count = 0; no_packet_count = 0;
memset(no_packet, 0, nb_input_files); for (i = 0; i < nb_input_files; i++)
input_files[i]->unavailable = 0;
if (do_pkt_dump) { if (do_pkt_dump) {
av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump, av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump,
...@@ -3866,7 +3861,6 @@ static int transcode(void) ...@@ -3866,7 +3861,6 @@ static int transcode(void)
ret = 0; ret = 0;
fail: fail:
av_freep(&no_packet);
#if HAVE_PTHREADS #if HAVE_PTHREADS
free_input_threads(); free_input_threads();
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment