diff options
author | Anton Khirnov <anton@khirnov.net> | 2022-08-18 11:13:08 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2022-08-29 15:42:11 +0200 |
commit | 8d26a21bf63514cc566bf8c9de940a786bb33167 (patch) | |
tree | 83908ac26d0305fc1abe1e9d3e38202e483758af /fftools/ffmpeg_demux.c | |
parent | 47b85c5a7642b6ec942c052bbe7d163b70e017a8 (diff) | |
download | ffmpeg-8d26a21bf63514cc566bf8c9de940a786bb33167.tar.gz |
fftools/ffmpeg: stop accessing av_stream_get_parser() from the main thread
It races with the demuxing thread. Instead, send the information along
with the demuxed packets.
Ideally, the code should stop using the stream-internal parsing
completely, but that requires considerably more effort.
Fixes races, e.g. in:
- fate-h264-brokensps-2580
- fate-h264-extradata-reload
- fate-iv8-demux
- fate-m4v-cfr
- fate-m4v
Diffstat (limited to 'fftools/ffmpeg_demux.c')
-rw-r--r-- | fftools/ffmpeg_demux.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 6dfb5bb35b..6e89f5999a 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -32,6 +32,9 @@ typedef struct DemuxMsg { AVPacket *pkt; int looping; + + // repeat_pict from the demuxer-internal parser + int repeat_pict; } DemuxMsg; static void report_new_stream(InputFile *file, const AVPacket *pkt) @@ -114,7 +117,7 @@ static int seek_to_start(InputFile *ifile) return ret; } -static void ts_fixup(InputFile *ifile, AVPacket *pkt) +static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) { InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index]; const int64_t start_time = ifile->ctx->start_time; @@ -167,6 +170,11 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt) if (pkt->dts != AV_NOPTS_VALUE) pkt->dts += duration; + + *repeat_pict = -1; + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + av_stream_get_parser(ist->st)) + *repeat_pict = av_stream_get_parser(ist->st)->repeat_pict; } static void *input_thread(void *arg) @@ -231,7 +239,7 @@ static void *input_thread(void *arg) } } - ts_fixup(f, pkt); + ts_fixup(f, pkt, &msg.repeat_pict); msg.pkt = av_packet_alloc(); if (!msg.pkt) { @@ -352,6 +360,7 @@ int init_input_threads(void) int ifile_get_packet(InputFile *f, AVPacket **pkt) { + InputStream *ist; DemuxMsg msg; int ret; @@ -382,6 +391,9 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) if (msg.looping) return 1; + ist = input_streams[f->ist_index + msg.pkt->stream_index]; + ist->last_pkt_repeat_pict = msg.repeat_pict; + *pkt = msg.pkt; return 0; } |