From patchwork Sun Jan 1 12:14:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bodecs Bela X-Patchwork-Id: 2006 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp3577291vsb; Sun, 1 Jan 2017 04:14:55 -0800 (PST) X-Received: by 10.28.178.205 with SMTP id b196mr48858591wmf.8.1483272895184; Sun, 01 Jan 2017 04:14:55 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t187si39315976wme.1.2017.01.01.04.14.54; Sun, 01 Jan 2017 04:14:55 -0800 (PST) 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 6585A689214; Sun, 1 Jan 2017 14:14:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.vivacom.hu (mail.vivacom.hu [217.173.41.231]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 00EC8687993 for ; Sun, 1 Jan 2017 14:14:41 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.vivacom.hu (Postfix) with ESMTP id 821E48544C for ; Sun, 1 Jan 2017 13:14:45 +0100 (CET) X-Virus-Scanned: amavisd-new at example.com Received: from mail.vivacom.hu ([127.0.0.1]) by localhost (mail.vivacom.intra [127.0.0.1]) (amavisd-new, port 10024) with LMTP id fqrz-gxJfuOk for ; Sun, 1 Jan 2017 13:14:43 +0100 (CET) Received: from [192.168.3.9] (pool-dsl-2f-0001.externet.hu [217.173.47.1]) by mail.vivacom.hu (Postfix) with ESMTPA id 5F2BA83B93 for ; Sun, 1 Jan 2017 13:14:43 +0100 (CET) References: <0e75dacf-46ad-5d16-5b4e-e6732fb4d91f@vivanet.hu> To: ffmpeg-devel@ffmpeg.org From: Bodecs Bela Message-ID: <991d8f90-33fd-1cf8-6ed0-9ce939873c29@vivanet.hu> Date: Sun, 1 Jan 2017 13:14:43 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: Duplicated segment filenames and use_localtime_mkdir 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" 2017.01.01. 12:57 keltezéssel, Steven Liu írta: > 2017-01-01 19:40 GMT+08:00 Bodecs Bela : > >> Dear All, >> >> current implementation of finding duplicated segment filenames may fail if >> use_localtime_mkdir and use_localtime are in effect and segment_filename >> option expression contains subdirectories with date/time specifiers in them. >> This patch fixes this false behaviour. >> >> >> thank you, >> >> Bela >> >> >> _______________________________________________ >> ffmpeg-devel mailing list >> ffmpeg-devel@ffmpeg.org >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >> >> > +static HLSSegment *find_segment_by_filename(HLSSegment *segment, const > char *filename) > +{ > + while (segment) { > + if (!strcmp(segment->filename,filename)) > + return segment; > + segment = segment->next; > + } > + return (HLSSegment *) NULL; > +} > + > use av_strcasecmp will better。 yes, I have changed it. > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From 1fec0300d75130f3c398ef3a4a403886a5016916 Mon Sep 17 00:00:00 2001 From: Bela Bodecs Date: Sun, 1 Jan 2017 13:11:08 +0100 Subject: [PATCH] Duplicated segment filenames and use_localtime_mkdir Current implementation of finding duplicate segment filenames may fail if use_localtime_mkdir and use_localtime are in effect and segment_filename option expression contains subdirectories with date/time specifiers. This patch fixes this false behaviour. Signed-off-by: Bela Bodecs --- libavformat/hlsenc.c | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 57fc9c1..591ab73 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -367,6 +367,16 @@ static int hls_mux_init(AVFormatContext *s) return 0; } +static HLSSegment *find_segment_by_filename(HLSSegment *segment, const char *filename) +{ + while (segment) { + if (!av_strcasecmp(segment->filename,filename)) + return segment; + segment = segment->next; + } + return (HLSSegment *) NULL; +} + /* Create a new segment and append it to the segment list */ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double duration, int64_t pos, int64_t size) @@ -383,6 +393,10 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double if (hls->use_localtime_mkdir) { filename = hls->avf->filename; } + if (find_segment_by_filename(hls->segments, filename) + || find_segment_by_filename(hls->old_segments, en->filename)) { + av_log(hls, AV_LOG_WARNING, "Duplicated segment filename detected: %s\n", filename); + } av_strlcpy(en->filename, filename, sizeof(en->filename)); if(hls->has_subtitle) @@ -659,38 +673,6 @@ fail: return ret; } -static HLSSegment *find_segment_by_filename(HLSSegment *segment, const char *filename) -{ - /* filename may contain rel/abs path, but segments store only basename */ - char *p = NULL, *dirname = NULL, *path = NULL; - int path_size; - HLSSegment *ret_segment = NULL; - dirname = av_strdup(filename); - if (!dirname) - return NULL; - p = (char *)av_basename(dirname); // av_dirname would return . in case of no dir - *p = '\0'; // maybe empty - - while (segment) { - path_size = strlen(dirname) + strlen(segment->filename) + 1; - path = av_malloc(path_size); - if (!path) - goto end; - av_strlcpy(path, dirname, path_size); - av_strlcat(path, segment->filename, path_size); - if (!strcmp(path,filename)) { - ret_segment = segment; - av_free(path); - goto end; - } - av_free(path); - segment = segment->next; - } -end: - av_free(dirname); - return ret_segment; -} - static int hls_start(AVFormatContext *s) { HLSContext *c = s->priv_data; @@ -736,10 +718,6 @@ static int hls_start(AVFormatContext *s) } av_free(filename); } - if (find_segment_by_filename(c->segments, oc->filename) - || find_segment_by_filename(c->old_segments, oc->filename)) { - av_log(c, AV_LOG_WARNING, "Duplicated segment filename detected: %s\n", oc->filename); - } if (c->use_localtime_mkdir) { const char *dir; char *fn_copy = av_strdup(oc->filename); -- 2.5.3.windows.1