From patchwork Mon Dec 26 01:14:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodecs Bela X-Patchwork-Id: 1926 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp827801vsb; Sun, 25 Dec 2016 17:14:50 -0800 (PST) X-Received: by 10.28.141.18 with SMTP id p18mr22558321wmd.31.1482714890674; Sun, 25 Dec 2016 17:14:50 -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 qq8si44237959wjc.143.2016.12.25.17.14.50; Sun, 25 Dec 2016 17:14:50 -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 7D98F6899BE; Mon, 26 Dec 2016 03:14:45 +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 9F650680AF2 for ; Mon, 26 Dec 2016 03:14:38 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.vivacom.hu (Postfix) with ESMTP id 29A568828B for ; Mon, 26 Dec 2016 02:14:40 +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 k2lNf5g7LVxa for ; Mon, 26 Dec 2016 02:14:38 +0100 (CET) Received: from [192.168.0.10] (pool-dsl-27-004b.externet.hu [217.173.39.75]) by mail.vivacom.hu (Postfix) with ESMTPA id BCE7C881C8 for ; Mon, 26 Dec 2016 02:14:38 +0100 (CET) From: Bodecs Bela To: FFmpeg development discussions and patches Message-ID: <265596b3-7944-f533-5bf3-76a8781f3c09@vivanet.hu> Date: Mon, 26 Dec 2016 02:14:39 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: detecting duplicated segment filenames 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, with use_localtime parameter hlsenc may produce identical filenames for different but still existing segments. It happens when hls_segment_filename contains syntacticaly correct but inadequate format parameters. Currently there is no any log message when such a situaton occurs but these cases should be avoided in most times. This patch generate warning log messages in these cases. best regards, bb From 7055e0b0bec3fee61373dd446bcab24d15117b7e Mon Sep 17 00:00:00 2001 From: Bela Bodecs Date: Mon, 26 Dec 2016 02:00:49 +0100 Subject: [PATCH] avformat/hlsenc: detecting duplicated segment filenames with use_localtime parameter hlsenc may produce identical filenames for different but still existing segments. It happens when hls_segment_filename contains syntacticaly correct but inadequate format parameters. Currently there is no any log message when such a situaton occurs but these cases should be avoided in most times. This patch generate warning messages in these cases. Signed-off-by: Bela Bodecs --- libavformat/hlsenc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index acf3a30..11ec3b8 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -653,6 +653,38 @@ 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, *dirname, *path; + 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; @@ -685,6 +717,8 @@ static int hls_start(AVFormatContext *s) av_log(oc, AV_LOG_ERROR, "Could not get segment filename with use_localtime\n"); return AVERROR(EINVAL); } + 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; -- 2.5.3.windows.1