* [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts @ 2022-10-31 10:56 Wolfgang Haupt 2022-10-31 10:56 ` [FFmpeg-devel] [PATCH 1/1] Add "no packet" timeout option for mpegts Wolfgang Haupt 0 siblings, 1 reply; 5+ messages in thread From: Wolfgang Haupt @ 2022-10-31 10:56 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Wolfgang Haupt This fixes mpegts infinitely parsing streams that contain only stuffed PATs, which apparently happens on some dead livetv sources. Wolfgang Haupt (1): Add "no packet" timeout option for mpegts libavformat/mpegts.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 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". ^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 1/1] Add "no packet" timeout option for mpegts 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 2022-10-31 12:52 ` [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts Wolfgang Haupt 2022-10-31 12:55 ` Wolfgang Haupt 0 siblings, 2 replies; 5+ messages in thread From: Wolfgang Haupt @ 2022-10-31 10:56 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Wolfgang Haupt 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". ^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts 2022-10-31 10:56 ` [FFmpeg-devel] [PATCH 1/1] Add "no packet" timeout option for mpegts Wolfgang Haupt @ 2022-10-31 12:52 ` Wolfgang Haupt 2022-10-31 12:55 ` Wolfgang Haupt 1 sibling, 0 replies; 5+ messages in thread From: Wolfgang Haupt @ 2022-10-31 12:52 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Wolfgang Haupt This fixes mpegts infinitely parsing streams that contain only stuffed PATs, which apparently happens on some dead livetv sources. Wolfgang Haupt (1): Add "no packet" timeout option for mpegts libavformat/mpegts.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 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". ^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts 2022-10-31 10:56 ` [FFmpeg-devel] [PATCH 1/1] Add "no packet" timeout option for mpegts Wolfgang Haupt 2022-10-31 12:52 ` [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts 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 1 sibling, 1 reply; 5+ messages in thread From: Wolfgang Haupt @ 2022-10-31 12:55 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Wolfgang Haupt This fixes mpegts infinitely parsing streams that contain only stuffed PATs, which apparently happens on some dead livetv sources. Wolfgang Haupt (1): Add "no packet" timeout option for mpegts libavformat/mpegts.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 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". ^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH] avformat/mpegts: Add "no packet" timeout option 2022-10-31 12:55 ` Wolfgang Haupt @ 2022-10-31 12:55 ` Wolfgang Haupt 0 siblings, 0 replies; 5+ messages in thread From: Wolfgang Haupt @ 2022-10-31 12:55 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Wolfgang Haupt 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index d97702fcd7..45bf82f61c 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,7 @@ 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; if (avio_tell(s->pb) != ts->last_pos) { int i; @@ -2996,8 +3006,14 @@ 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++; + if (ts->packet_read_timeout > 0 && (av_gettime_relative() - 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". ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-31 12:55 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-10-31 10:56 [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts Wolfgang Haupt 2022-10-31 10:56 ` [FFmpeg-devel] [PATCH 1/1] Add "no packet" timeout option for mpegts Wolfgang Haupt 2022-10-31 12:52 ` [FFmpeg-devel] [PATCH 0/1] Add "no packet timeout" to mpegts 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
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