From patchwork Fri Apr 6 10:27:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodecs Bela X-Patchwork-Id: 8345 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp502535jad; Fri, 6 Apr 2018 03:27:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+7FvCt+lvQIHfBapdvGMdw0GRfmuERfdDfhOfL/NrCAzfH0I46B7rVhy1UeCEDsslfj2vb X-Received: by 10.223.130.50 with SMTP id 47mr17186990wrb.99.1523010430867; Fri, 06 Apr 2018 03:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523010430; cv=none; d=google.com; s=arc-20160816; b=ygl31PX2V5s8cQN2x0qT8SkoLP77471L+Rd7boqzA2wwCxcF8xfI5c1Bu6+PF7BTaB epRUsU91HgnS3CJpxAE3dDRPqlRdDwUDQoXWv/Qsz1UpGj+oMD02fVjE4jra80L2B2k7 wLZJzNwv5wCJXRQ+4mjuBhOGtrLv57IJk9dYA1Hn4uSgmMIGI0jqoiozITlbbOlY8+YL 3Z+6eCfZHMRS0uDkyJrjJroj6CHS+HINpismIukpE4PNST/aaGv+uozYro5i+HULqGM9 bxJ86QOdRy/L5wBmxJV1CZAD8I+YWyY6uN6WP7lBYIv2RGEA7aCR3mjJZ1tiP77cwyIn GIBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:user-agent:date:message-id:from:to :delivered-to:arc-authentication-results; bh=Rq4CZQX67OKHW/EueFjFTadolPdPMlusbN95t9XgYqc=; b=l3bDDSkB1dblusLopLVVzRNhWLfxmL8Y0bN0jwC7BSSnuip8QjWE8upmRK7EzpLsC4 0V38pZIz3hd63U5RSPlIAQymsVVNQ8hUB4sJjgkCZo16O75SZa9SzgGDmXgFhPPrkkLT t+RlRtOuRDHVaNEzCUPlNVDqYlBXpLGv2q900O0Jt9wwqGdQ20gJqjyEy5v1W3NPP+dW LLM0YvHk0nF8sG3ExXU5NGavGrsHWIIM48MFaF4CkzjPExRaYw7bYY30YCJVi10q335o GhlL8tSV3YwXt+YAprQarWUO6El4VKZyofAMg9tTVpXy5hbrb0Fly7Ili+1MbViJJnMh o1QA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q4si5330232wmf.72.2018.04.06.03.27.10; Fri, 06 Apr 2018 03:27:10 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A05D6899F7; Fri, 6 Apr 2018 13:26:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-xsmtp1.externet.hu (mail-xsmtp4.externet.hu [212.40.96.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 20A3168987F for ; Fri, 6 Apr 2018 13:26:41 +0300 (EEST) Received: (qmail 7804 invoked from network); 6 Apr 2018 10:27:02 -0000 Received: from mail.officeline.hu (HELO ?10.0.0.10?) (bodecsb@vivanet.hu@217.173.32.91) by 0 with ESMTPA; 6 Apr 2018 10:27:02 -0000 To: FFmpeg development discussions and patches From: Bodecs Bela Message-ID: Date: Fri, 6 Apr 2018 12:27:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Language: hu Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix handling of delete_segments when %v is present 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Dear All, when var_stream_map option is used, %v must appear either in segment name template or in the directory path. This latter case currently is not handled and using delete_segments flag of hls_flags is broken now. This patch fixes this issue. The root cause of the bug was that HLSSegment struct only stores the final filename part, but not the final directory path. Most of the cases, final path info is unneded, It only necessary when you want to delete old segments (e.g in case of live streaming). Without variant streams it was unnecessary to store the final directory path, because all segment were stored into the same directory. But introducing %v in directory names either require to store the final directory path into HLSSegment or associate segments with their variant streams to be able deleting them later. I have choosen the second solution and introduced a variant index data member into the segment struct. please review this patch. thank you in advance, Bela Bodecs From ad97bcd1c4ff0b734de3bffc58e7421192a33e43 Mon Sep 17 00:00:00 2001 From: Bela Bodecs Date: Fri, 6 Apr 2018 12:21:59 +0200 Subject: [PATCH] avformat/hlsenc: fix handling of delete_segments when %v is present When var_stream_map option is used, %v must appear either in segment name template or in the directory path. This latter case currently is not handled and delete_segments flag of hls_flags is broken now. This patch fix this. The root cause of the bug was that HLSSegment struct only stores the final filename part, but not the final directory path. Most of the cases, final path info is unneded, It only necessary when you want to delete old segments (e.g in case of live streaming). Without variant streams it was unnecessary to store the final directory path, because all segment were stored into the same directory. But introducing %v in directory names either require to store the final directory path into HLSSegment or associate segments with their variant streams to be able deleting them later. I have choosen the second solution and introduced a variant index data member into the segment struct. Signed-off-by: Bela Bodecs --- libavformat/hlsenc.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 2a54b43..8eb8421 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -75,6 +75,7 @@ typedef struct HLSSegment { int discont; int64_t pos; int64_t size; + unsigned var_stream_idx; char key_uri[LINE_BUFFER_SIZE + 1]; char iv_string[KEYSIZE*2 + 1]; @@ -106,6 +107,7 @@ typedef enum { } SegmentType; typedef struct VariantStream { + unsigned var_stream_idx; unsigned number; int64_t sequence; AVOutputFormat *oformat; @@ -478,9 +480,23 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls, } p = (char *)av_basename(dirname); *p = '\0'; + } while (segment) { + char * r_dirname = dirname; + + /* if %v is present in the file's directory */ + if (av_stristr(dirname, "%v")) { + + if (replace_int_data_in_filename(&r_dirname, dirname, 'v', segment->var_stream_idx) < 1) { + ret = AVERROR(EINVAL); + goto fail; + } + av_free(dirname); + dirname = r_dirname; + } + av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n", segment->filename); path_size = (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1; @@ -965,6 +981,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, if (!en) return AVERROR(ENOMEM); + en->var_stream_idx = vs->var_stream_idx; ret = sls_flags_filename_process(s, hls, vs, en, duration, pos, size); if (ret < 0) { return ret; @@ -1824,9 +1841,11 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) while (varstr = av_strtok(p, " \t", &saveptr1)) { p = NULL; - if (nb_varstreams < hls->nb_varstreams) - vs = &(hls->var_streams[nb_varstreams++]); - else + if (nb_varstreams < hls->nb_varstreams) { + vs = &(hls->var_streams[nb_varstreams]); + vs->var_stream_idx = nb_varstreams; + nb_varstreams++; + } else return AVERROR(EINVAL); q = varstr; @@ -1984,6 +2003,7 @@ static int update_variant_stream_info(AVFormatContext *s) { if (!hls->var_streams) return AVERROR(ENOMEM); + hls->var_streams[0].var_stream_idx = 0; hls->var_streams[0].nb_streams = s->nb_streams; hls->var_streams[0].streams = av_mallocz(sizeof(AVStream *) * hls->var_streams[0].nb_streams);