diff options
author | Anton Khirnov <anton@khirnov.net> | 2022-03-21 17:29:21 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2022-08-08 16:20:58 +0200 |
commit | 07da07ddb0fb7ee6a4ddd26fc5676e4939dd7441 (patch) | |
tree | df8932ceda3875eca886f5b01224aa193e2930db /fftools/ffmpeg_demux.c | |
parent | 9c16310fe509bd81b355207160ce5afc5f645855 (diff) | |
download | ffmpeg-07da07ddb0fb7ee6a4ddd26fc5676e4939dd7441.tar.gz |
fftools/ffmpeg: report new streams from the input thread
This avoids a potential race with the demuxer adding new streams. It is
also more efficient, since we no longer do inter-thread transfers of
packets that will be just discarded.
Diffstat (limited to 'fftools/ffmpeg_demux.c')
-rw-r--r-- | fftools/ffmpeg_demux.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index f9bd6d47fe..2d49a3c48c 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -20,6 +20,7 @@ #include "libavutil/error.h" #include "libavutil/time.h" +#include "libavutil/timestamp.h" #include "libavutil/thread.h" #include "libavutil/threadmessage.h" @@ -27,6 +28,20 @@ #include "libavformat/avformat.h" +static void report_new_stream(InputFile *file, const AVPacket *pkt) +{ + AVStream *st = file->ctx->streams[pkt->stream_index]; + + if (pkt->stream_index < file->nb_streams_warn) + return; + av_log(file->ctx, AV_LOG_WARNING, + "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n", + av_get_media_type_string(st->codecpar->codec_type), + file->index, pkt->stream_index, + pkt->pos, av_ts2timestr(pkt->dts, &st->time_base)); + file->nb_streams_warn = pkt->stream_index + 1; +} + static void *input_thread(void *arg) { InputFile *f = arg; @@ -51,6 +66,14 @@ static void *input_thread(void *arg) f->ctx->streams[pkt->stream_index]); } + /* the following test is needed in case new streams appear + dynamically in stream : we ignore them */ + if (pkt->stream_index >= f->nb_streams) { + report_new_stream(f, pkt); + av_packet_unref(pkt); + continue; + } + queue_pkt = av_packet_alloc(); if (!queue_pkt) { av_packet_unref(pkt); |