[FFmpeg-cvslog] avformat/hlsenc: revamped master playlist url creation logic

Vishwanath Dixit git at videolan.org
Tue Jan 2 04:47:43 EET 2018


ffmpeg | branch: master | Vishwanath Dixit <vdixit at akamai.com> | Tue Jan  2 10:45:28 2018 +0800| [26e1efb04f3864b813c74eaf85fbe1ea352bb7f0] | committer: Steven Liu

avformat/hlsenc: revamped master playlist url creation logic

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=26e1efb04f3864b813c74eaf85fbe1ea352bb7f0
---

 libavformat/hlsenc.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e6f3241765..3ea16c6d7d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1689,28 +1689,30 @@ static int update_variant_stream_info(AVFormatContext *s) {
 
 static int update_master_pl_info(AVFormatContext *s) {
     HLSContext *hls = s->priv_data;
-    int m3u8_name_size, ret;
-    char *p;
+    const char *dir;
+    char *fn;
+    int ret = 0;
 
-    m3u8_name_size = strlen(s->filename) + strlen(hls->master_pl_name) + 1;
-    hls->master_m3u8_url = av_malloc(m3u8_name_size);
-    if (!hls->master_m3u8_url) {
+    fn = av_strdup(s->filename);
+    if (!fn) {
         ret = AVERROR(ENOMEM);
-        return ret;
+        goto fail;
     }
 
-    av_strlcpy(hls->master_m3u8_url, s->filename, m3u8_name_size);
-    p = strrchr(hls->master_m3u8_url, '/') ?
-            strrchr(hls->master_m3u8_url, '/') :
-            strrchr(hls->master_m3u8_url, '\\');
-    if (p) {
-        *(p + 1) = '\0';
-        av_strlcat(hls->master_m3u8_url, hls->master_pl_name, m3u8_name_size);
-    } else {
-        av_strlcpy(hls->master_m3u8_url, hls->master_pl_name, m3u8_name_size);
+    dir = av_dirname(fn);
+    if (dir && strcmp(dir, "."))
+        hls->master_m3u8_url = av_append_path_component(dir, hls->master_pl_name);
+    else
+        hls->master_m3u8_url = av_strdup(hls->master_pl_name);
+
+    if (!hls->master_m3u8_url) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
     }
 
-    return 0;
+fail:
+    av_freep(&fn);
+    return ret;
 }
 
 static int hls_write_header(AVFormatContext *s)



More information about the ffmpeg-cvslog mailing list