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 <bode...@vivanet.hu> 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 <bode...@vivanet.hu> --- 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
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel