From patchwork Mon Oct 10 11:55:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gnattu OC X-Patchwork-Id: 38667 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp325505pzb; Mon, 10 Oct 2022 04:56:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KCU8GGAH4wwnWxPDYfnV6KV7NQ9mlvmTZhtURoaeM642SQ31MlT/Q4GA0MDNFLYNp6w2y X-Received: by 2002:a17:907:2d91:b0:78d:8747:71b4 with SMTP id gt17-20020a1709072d9100b0078d874771b4mr12035151ejc.545.1665402989850; Mon, 10 Oct 2022 04:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665402989; cv=none; d=google.com; s=arc-20160816; b=VL2Ihglg1Ct55xgZvOoiWZe4KSLUkMmDVXisrgVtQmGLlwHR0PbHBc3Cd3ITKqi+XW 9UbBxi/0+BV4dLff4jKiyuqu6yALkn4RhjXAM1ASlMoEkkEOxdOAbJhGkWP3IfrUyNAf gZkWIIW03uVtEEx0pX1Okw69iJuSOfOUc2tDci1EMIL5wNaI+UuNPPKiR2C5x17pwWw8 xnNUNloNGHvNtuMstp7dfQDwNni9MTeKOMg1POCo/1gU9csglD8x42op275ZeANePXEN EP8EBae5tJNmudW3McROCdmZSjyWDpBufI0XxqGmpmpXxFFYNQE865Or4SRZMVwGQEdM 5mSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=iH4+A3+5eodw7vk5ff87PjxONk6MMjV3VkD2T5O6zD8=; b=qAhzwiJPkJlwvNv67ITJNWdTcfDDHmsWY8R0Kbomj0gBzDUlR7d5EKV+GvkkXUPoXA 1GVXp6VsQabFzG5HPIeyfGcuqFXA3AeucX0b4ucCegek2fyGKCGyUsNIOpk9VQFdlv+U qa1KzE2KDG7pg8JzVkaCFjGSXvb77dKn8w/RUCjM8f2l1IsxlPJHOhFRDWJ07c2duBQC JT0yEWvz0ygbPfPDrrZfAyyGBn5i4MI2EuEOwC7ZdDdKYtSPtKzODOWsub9SLnx8BmGM 1Ubz94uotE7ib6f4V+dzFThRHL4i4BQYd/Hgz78S36wx7cYfsE301xWls1DSe0KQuLWd RQKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@me.com header.s=1a1hai header.b=Tu1yhsRL; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hb11-20020a170907160b00b007707ab4be23si11594930ejc.560.2022.10.10.04.56.29; Mon, 10 Oct 2022 04:56:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@me.com header.s=1a1hai header.b=Tu1yhsRL; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3702668BA95; Mon, 10 Oct 2022 14:56:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ci74p00im-qukt09082501.me.com (ci74p00im-qukt09082501.me.com [17.57.156.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B157468BA95 for ; Mon, 10 Oct 2022 14:56:18 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1665402976; bh=zhE2s1yeB+S6hTMaDENTIKCjJPYLHlgeyuiJq7jf5Fc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Tu1yhsRL/dRxl3vu/W0rx8tHcY9nzqKtN9gVY0PF6Xs7gLjJMN3wC4+WrEbZyrwZo laI78mao0GShUHGzHsSqSGDAtr4g4kLSuhcjFCEWyjY6yAihLzd1naembRI9On97yK TTXRh+fBGPhIZ8lqp7Hxgt3mWYL5OzPZ3hgZ2m/aKQM+jWVHn6Ue53eOlJ0xGomlOa qk7ygpSTK/u66wFyiALD8gg5a6HhMIqCwK7Fa8EuyNocKOckZK+Xwqz7V1lSvwMVT5 gPDLDhdGlvZfSUIqxpzK7qSiQ4JFZ9hbF7DewVIqvrCffppLPuXxKGo656xcoFKkID BeXlnOTZ7GpPw== Received: from localhost.localdomain (ci77p00im-dlb-asmtp-mailmevip.me.com [17.57.156.26]) by ci74p00im-qukt09082501.me.com (Postfix) with ESMTPSA id E38A84AA03AA; Mon, 10 Oct 2022 11:56:14 +0000 (UTC) From: gnattu To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Oct 2022 19:55:03 +0800 Message-Id: <20221010115503.38066-1-gnattuoc@me.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 8MZzYtJ-0d2DfIMUG42YzkPpnPsFkpKd X-Proofpoint-GUID: 8MZzYtJ-0d2DfIMUG42YzkPpnPsFkpKd X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E138=2C18=2E0?= =?utf-8?q?=2E572=2C17=2E11=2E62=2E513=2E0000000_definitions=3D2020-02-14=5F?= =?utf-8?q?11=3A2020-02-14=5F02=2C2020-02-14=5F11=2C2021-12-02=5F01_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 malwarescore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210100072 Subject: [FFmpeg-devel] [PATCH v2] 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 Cc: gnattu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: X4kLK96ftnhT 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 --- Previous version was trashed by my email client, sorry. 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} };