From: Wolfgang Haupt <haupt.wolfgang@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Wolfgang Haupt <haupt.wolfgang@gmail.com> Subject: [FFmpeg-devel] [PATCH 1/1] Add "no packet" timeout option for mpegts Date: Mon, 31 Oct 2022 11:56:45 +0100 Message-ID: <20221031105645.75816-2-haupt.wolfgang@gmail.com> (raw) In-Reply-To: <20221031105645.75816-1-haupt.wolfgang@gmail.com> Retrieving an mpegts stream with only stuffed PAT, results in endless reading. This change adds a new timeout that specifies a timespan in AV_TIME_BASE units until when a full packet must be read successfully. Signed-off-by: Wolfgang Haupt <haupt.wolfgang@gmail.com> --- libavformat/mpegts.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index d97702fcd7..5b615cca63 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -32,6 +32,7 @@ #include "libavutil/opt.h" #include "libavutil/avassert.h" #include "libavutil/dovi_meta.h" +#include "libavutil/time.h" #include "libavcodec/avcodec.h" #include "libavcodec/bytestream.h" #include "libavcodec/get_bits.h" @@ -180,6 +181,12 @@ struct MpegTSContext { AVStream *epg_stream; AVBufferPool* pools[32]; + + /** + * Timeout in AV_TIME_BASE units, until at least one packet is read + * from the stream. + */ + int64_t packet_read_timeout; }; #define MPEGTS_OPTIONS \ @@ -203,6 +210,8 @@ static const AVOption options[] = { {.i64 = 0}, 0, 1, 0 }, {"max_packet_size", "maximum size of emitted packet", offsetof(MpegTSContext, max_packet_size), AV_OPT_TYPE_INT, {.i64 = 204800}, 1, INT_MAX/2, AV_OPT_FLAG_DECODING_PARAM }, + {"packet_read_timeout", "Maximum time utnil at least one packet is successfully read from the stream", offsetof(MpegTSContext, packet_read_timeout), AV_OPT_TYPE_INT64, + {.i64 = 0 }, 0, INT64_MAX, AV_OPT_FLAG_DECODING_PARAM }, { NULL }, }; @@ -2972,6 +2981,8 @@ static int handle_packets(MpegTSContext *ts, int64_t nb_packets) const uint8_t *data; int64_t packet_num; int ret = 0; + time_t start = 0; + time_t now = 0; if (avio_tell(s->pb) != ts->last_pos) { int i; @@ -2996,8 +3007,15 @@ static int handle_packets(MpegTSContext *ts, int64_t nb_packets) ts->stop_parse = 0; packet_num = 0; memset(packet + TS_PACKET_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE); + start = av_gettime_relative(); for (;;) { packet_num++; + now = av_gettime_relative(); + if (now - start > ts->packet_read_timeout) { + av_log(ts->stream, AV_LOG_TRACE, "No packet after %"PRId64"ms\n", ts->packet_read_timeout/1000); + break; + } + if (nb_packets != 0 && packet_num >= nb_packets || ts->stop_parse > 1) { ret = AVERROR(EAGAIN); -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-10-31 10:57 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-31 10:56 [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts Wolfgang Haupt 2022-10-31 10:56 ` Wolfgang Haupt [this message] 2022-10-31 12:52 ` Wolfgang Haupt 2022-10-31 12:55 ` Wolfgang Haupt 2022-10-31 12:55 ` [FFmpeg-devel] [PATCH] avformat/mpegts: Add "no packet" timeout option Wolfgang Haupt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221031105645.75816-2-haupt.wolfgang@gmail.com \ --to=haupt.wolfgang@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git