From patchwork Mon Jun 15 12:37:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 20417 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 449A944A33D for ; Mon, 15 Jun 2020 15:37:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F63C68B5D8; Mon, 15 Jun 2020 15:37:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 33F8E6802C1 for ; Mon, 15 Jun 2020 15:37:49 +0300 (EEST) X-QQ-mid: bizesmtp4t1592224663tzpvouj6g Received: from localhost (unknown [103.107.216.233]) by esmtp6.qq.com (ESMTP) with id ; Mon, 15 Jun 2020 20:37:43 +0800 (CST) X-QQ-SSF: 01100000002000Y0ZXF0000A0000000 X-QQ-FEAT: Tp2hW+Mew+dwB/SvJLLhULGE1QrgLioGUl0LT9UiqA3yDtXPUKu5CRrAMi/Xb SXsrqdP48BueCX1f2sIcCbmrOI/5UKBQQlIb2G66cV1AcTnY874/uHT8BV0BpOlXz7ei2IN IWFT3Xu71xBIvdf08XzHDHoyKA5OEovKOUrXCZ7Y2CajIydIm0cX7IPwdem8KGLikiJWE/v cyRxBGxfJFNqp9oEUMG2vPDnpM7cfPX2jujZTH4ICZ+7htWYlPiQzwpeH3zyA2vBxSogJgD hSs1CrBnvPG8T+khhNpkcsieFVlgxejJ75aMJ2pCxRAuAbDqUUrBcNHFbq1Rjdw1+Y1Kz4T Hv8JBBH X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Jun 2020 20:37:40 +0800 Message-Id: <20200615123741.55735-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH v2 1/2] avformat/hlsenc: check fragment size plus start_pos large than hls_segment_size X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" if vs->size + vs->start_pos > hls->max_seg_size, should split segment. Signed-off-by: Steven Liu --- libavformat/hlsenc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 71fa3db060..ca2e1bb4a8 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2392,7 +2392,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) && (hls->flags & HLS_TEMP_FILE); } - if ((hls->max_seg_size > 0 && (vs->size >= hls->max_seg_size)) || !byterange_mode) { + if ((hls->max_seg_size > 0 && (vs->size + vs->start_pos >= hls->max_seg_size)) || !byterange_mode) { AVDictionary *options = NULL; char *filename = NULL; if (hls->key_info_file || hls->encrypt) { @@ -2487,14 +2487,15 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (hls->flags & HLS_SINGLE_FILE) { vs->start_pos += vs->size; } else if (hls->max_seg_size > 0) { - vs->start_pos = new_start_pos; - if (vs->size >= hls->max_seg_size) { + if (vs->size + vs->start_pos >= hls->max_seg_size) { vs->sequence++; sls_flag_file_rename(hls, vs, old_filename); ret = hls_start(s, vs); vs->start_pos = 0; /* When split segment by byte, the duration is short than hls_time, * so it is not enough one segment duration as hls_time, */ + } else { + vs->start_pos = new_start_pos; } } else { vs->start_pos = new_start_pos;