1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-28 20:53:54 +02:00

fftools/ffmpeg_demux: add demuxer private data

Move InputFile.loop into it.
This commit is contained in:
Anton Khirnov 2022-10-17 11:17:34 +02:00
parent 78efefa9a5
commit 6975320506
2 changed files with 27 additions and 11 deletions

View File

@ -441,7 +441,6 @@ typedef struct InputFile {
int eof_reached; /* true if eof reached */ int eof_reached; /* true if eof reached */
int eagain; /* true if last read attempt returned EAGAIN */ int eagain; /* true if last read attempt returned EAGAIN */
int ist_index; /* index of first stream in input_streams */ int ist_index; /* index of first stream in input_streams */
int loop; /* set number of times input stream should be looped */
int64_t duration; /* actual duration of the longest stream in a file int64_t duration; /* actual duration of the longest stream in a file
at the moment when looping happens */ at the moment when looping happens */
AVRational time_base; /* time base of the duration */ AVRational time_base; /* time base of the duration */

View File

@ -52,6 +52,13 @@ static const char *const opt_name_display_rotations[] = {"display_rotati
static const char *const opt_name_display_hflips[] = {"display_hflip", NULL}; static const char *const opt_name_display_hflips[] = {"display_hflip", NULL};
static const char *const opt_name_display_vflips[] = {"display_vflip", NULL}; static const char *const opt_name_display_vflips[] = {"display_vflip", NULL};
typedef struct Demuxer {
InputFile f;
/* number of times input stream should be looped */
int loop;
} Demuxer;
typedef struct DemuxMsg { typedef struct DemuxMsg {
AVPacket *pkt; AVPacket *pkt;
int looping; int looping;
@ -60,6 +67,11 @@ typedef struct DemuxMsg {
int repeat_pict; int repeat_pict;
} DemuxMsg; } DemuxMsg;
static Demuxer *demuxer_from_ifile(InputFile *f)
{
return (Demuxer*)f;
}
static void report_new_stream(InputFile *file, const AVPacket *pkt) static void report_new_stream(InputFile *file, const AVPacket *pkt)
{ {
AVStream *st = file->ctx->streams[pkt->stream_index]; AVStream *st = file->ctx->streams[pkt->stream_index];
@ -91,8 +103,9 @@ static void ifile_duration_update(InputFile *f, InputStream *ist,
} }
} }
static int seek_to_start(InputFile *ifile) static int seek_to_start(Demuxer *d)
{ {
InputFile *ifile = &d->f;
AVFormatContext *is = ifile->ctx; AVFormatContext *is = ifile->ctx;
InputStream *ist; InputStream *ist;
int ret; int ret;
@ -134,8 +147,8 @@ static int seek_to_start(InputFile *ifile)
} }
} }
if (ifile->loop > 0) if (d->loop > 0)
ifile->loop--; d->loop--;
return ret; return ret;
} }
@ -209,7 +222,8 @@ static void thread_set_name(InputFile *f)
static void *input_thread(void *arg) static void *input_thread(void *arg)
{ {
InputFile *f = arg; Demuxer *d = arg;
InputFile *f = &d->f;
AVPacket *pkt; AVPacket *pkt;
unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
int ret = 0; int ret = 0;
@ -232,12 +246,12 @@ static void *input_thread(void *arg)
continue; continue;
} }
if (ret < 0) { if (ret < 0) {
if (f->loop) { if (d->loop) {
/* signal looping to the consumer thread */ /* signal looping to the consumer thread */
msg.looping = 1; msg.looping = 1;
ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0); ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0);
if (ret >= 0) if (ret >= 0)
ret = seek_to_start(f); ret = seek_to_start(d);
if (ret >= 0) if (ret >= 0)
continue; continue;
@ -336,6 +350,7 @@ static int init_input_thread(int i)
{ {
int ret; int ret;
InputFile *f = input_files[i]; InputFile *f = input_files[i];
Demuxer *d = demuxer_from_ifile(f);
if (f->thread_queue_size <= 0) if (f->thread_queue_size <= 0)
f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); f->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
@ -348,7 +363,7 @@ static int init_input_thread(int i)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (f->loop) { if (d->loop) {
int nb_audio_dec = 0; int nb_audio_dec = 0;
for (int i = 0; i < f->nb_streams; i++) { for (int i = 0; i < f->nb_streams; i++) {
@ -366,7 +381,7 @@ static int init_input_thread(int i)
} }
} }
if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { if ((ret = pthread_create(&f->thread, NULL, input_thread, d))) {
av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
ret = AVERROR(ret); ret = AVERROR(ret);
goto fail; goto fail;
@ -771,6 +786,7 @@ static void dump_attachment(AVStream *st, const char *filename)
int ifile_open(OptionsContext *o, const char *filename) int ifile_open(OptionsContext *o, const char *filename)
{ {
Demuxer *d;
InputFile *f; InputFile *f;
AVFormatContext *ic; AVFormatContext *ic;
const AVInputFormat *file_iformat = NULL; const AVInputFormat *file_iformat = NULL;
@ -974,7 +990,8 @@ int ifile_open(OptionsContext *o, const char *filename)
/* dump the file content */ /* dump the file content */
av_dump_format(ic, nb_input_files, filename, 0); av_dump_format(ic, nb_input_files, filename, 0);
f = ALLOC_ARRAY_ELEM(input_files, nb_input_files); d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files);
f = &d->f;
f->ctx = ic; f->ctx = ic;
f->index = nb_input_files - 1; f->index = nb_input_files - 1;
@ -987,7 +1004,7 @@ int ifile_open(OptionsContext *o, const char *filename)
f->nb_streams = ic->nb_streams; f->nb_streams = ic->nb_streams;
f->rate_emu = o->rate_emu; f->rate_emu = o->rate_emu;
f->accurate_seek = o->accurate_seek; f->accurate_seek = o->accurate_seek;
f->loop = o->loop; d->loop = o->loop;
f->duration = 0; f->duration = 0;
f->time_base = (AVRational){ 1, 1 }; f->time_base = (AVRational){ 1, 1 };