The -hls_allow_cache paramter enables explicitly setting the
EXT-X-ALLOW-CACHE tag in the manifest file. That tag indicates
whether the client MAY or MUST NOT cache downloaded media
segments for later replay.

Valid values are YES or NO and the EXT-X-ALLOW-CACHE will not
show in the manifest for other values (or if -hls_allow_cache
is not used.
---
 doc/muxers.texi      |    2 ++
 libavformat/hlsenc.c |    6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 54109c7..dbd6036 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -116,6 +116,8 @@ Set the number after which index wraps.
 Start the sequence from @var{number}.
 @item -hls_base_url @var{baseurl}
 Append @var{baseurl} to every entry in the playlist.
+@item -hls_allow_cache @var{allowcache}
+Set whether the client MAY (YES) or MUST NOT (NO) cache media segments
 Useful to generate playlists with absolute paths.
 @end table
 
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index aa38d05..5097132 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -57,6 +57,7 @@ typedef struct HLSContext {
     ListEntry *end_list;
     char *basename;
     char *baseurl;
+    char *allowcache;
     AVIOContext *pb;
 } HLSContext;
 
@@ -145,6 +146,10 @@ static int hls_window(AVFormatContext *s, int last)
 
     avio_printf(hls->pb, "#EXTM3U\n");
     avio_printf(hls->pb, "#EXT-X-VERSION:3\n");
+    if (0 == strcmp(hls->allowcache, "YES") ||
+        0 == strcmp(hls->allowcache, "NO")) {
+        avio_printf(hls->pb, "#EXT-X-ALLOW-CACHE:%s\n", hls->allowcache);
+    }
     avio_printf(hls->pb, "#EXT-X-TARGETDURATION:%d\n", target_duration);
     avio_printf(hls->pb, "#EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence);
 
@@ -326,6 +331,7 @@ static const AVOption options[] = {
     {"hls_list_size", "maximum number of playlist entries",      OFFSET(size), 
   AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
     {"hls_wrap",      "number after which the index wraps",      OFFSET(wrap), 
   AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
     {"hls_base_url",  "url to prepend to each playlist entry",   
OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E},
+    {"hls_allow_cache", "(YES/NO) explicitly set whether the client MAY or 
MUST NOT cache downloaded media segments for later replay", OFFSET(allowcache), 
AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
     { NULL },
 };
 
-- 
1.7.10.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to