From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8469F443AF for ; Mon, 10 Oct 2022 10:57:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CCD0A68BCEF; Mon, 10 Oct 2022 13:57:20 +0300 (EEST) Received: from qs51p00im-qukt01071902.me.com (qs51p00im-qukt01071902.me.com [17.57.155.9]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D71DC680AF6 for ; Mon, 10 Oct 2022 13:57:13 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1665398872; bh=YPco5Xu9jAGgjJgCzH8B/RmM+xv2oTS4OvrdJ/sYifI=; h=Message-ID:Date:MIME-Version:From:Subject:To:Content-Type; b=Lu2B8ZnggWpN3q9GGs6Z/tSIccKcuvru/6by6gb7Du7zp+DSAO9nJKKKW/k70l7KO DuPJ0IHEmcboMtIOiYHt7327/JrMG2i2tZaTaxCT8R07UqXm3XasW6IA/wHmQ3O3qA ZvVnU7r0ddJXlM+vHYTuvnJAB+gzFS4u0hXUfQYKdWrSFV6u0xO3rboveW+5mBMrxs 30SR3yY/4pZ9UazX6siJ2iqBjHmtSVx6Ik9ognhxxcvFweeJHpFyoqgnWFqsB2+BM1 oUzqvYMkcI4xwBAYtkf6jNQUlJ7vaQIlXnJBkVE+OaXYqsTaw2t4e8/G3+gBG6FMaW tqswhtz7g6sFA== Received: from [10.154.215.115] (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01071902.me.com (Postfix) with ESMTPSA id BAA9B5EC0332 for ; Mon, 10 Oct 2022 10:47:51 +0000 (UTC) Message-ID: <268e50a2-e64c-91a3-aa05-fed1ff801624@me.com> Date: Mon, 10 Oct 2022 18:47:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.2 From: Gnattu OC To: ffmpeg-devel@ffmpeg.org Content-Language: en-US X-Proofpoint-GUID: Q-s89OIC30Wbe6kWUg53j-dVOLKP0ew3 X-Proofpoint-ORIG-GUID: Q-s89OIC30Wbe6kWUg53j-dVOLKP0ew3 X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.138,18.0.790,17.0.605.474.0000000_definitions?= =?UTF-8?Q?=3D2022-01-12=5F02:2020-02-14=5F02,2022-01-12=5F02,2020-01-23?= =?UTF-8?Q?=5F02_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210100065 Subject: [FFmpeg-devel] [PATCH] avformat/hls: Add option to retry failed segments for hls X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Current HLS implementation simply skip a failed segment to catch up the stream, but this is not optimal for some use cases like livestream recording. Add an option to retry a failed segment to ensure the output file is a complete stream. Signed-off-by: gnattu --- libavformat/hls.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index e622425e80..2b977f9132 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -225,6 +225,7 @@ typedef struct HLSContext { int http_persistent; int http_multiple; int http_seekable; + int seg_max_retry; AVIOContext *playlist_pb; HLSCryptoContext crypto_ctx; } HLSContext; @@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size) int ret; int just_opened = 0; int reload_count = 0; + int segment_retries = 0; struct segment *seg; restart: @@ -1563,9 +1565,18 @@ reload: av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %"PRId64" of playlist %d\n", v->cur_seq_no, v->index); - v->cur_seq_no += 1; + if (segment_retries >= c->seg_max_retry) { + av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of playlist %d failed too many times, skipping\n", + v->cur_seq_no, + v->index); + v->cur_seq_no += 1; + segment_retries = 0; + } else { + segment_retries += 1; + } goto reload; } + segment_retries = 0; just_opened = 1; } @@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = { OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS}, {"seg_format_options", "Set options for segment demuxer", OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS}, + {"seg_max_retry", "Maximum number of times to reload a segment on error.", + OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS}, {NULL} }; -- 2.37.0 (Apple Git-136) _______________________________________________ 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".