Browse code

avformat/hlsenc: Added parameter -hls_allow_cache

The -hls_allow_cache parameter 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 1 (=YES) or 0 (=NO) and the EXT-X-ALLOW-CACHE
will not show in the manifest for other values (or if
-hls_allow_cache is not used.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Joakim Roubert authored on 2014/09/22 17:17:01
Showing 2 changed files
... ...
@@ -242,6 +242,10 @@ to @var{wrap}.
242 242
 Start the playlist sequence number from @var{number}. Default value is
243 243
 0.
244 244
 
245
+@item hls_allow_cache @var{allowcache}
246
+Explicitly set whether the client MAY (1) or MUST NOT (0) cache media
247
+segments.
248
+
245 249
 @item hls_base_url @var{baseurl}
246 250
 Append @var{baseurl} to every entry in the playlist.
247 251
 Useful to generate playlists with absolute paths.
... ...
@@ -59,6 +59,8 @@ typedef struct HLSContext {
59 59
     int  wrap;             // Set by a private option.
60 60
     uint32_t flags;        // enum HLSFlags
61 61
 
62
+    int allowcache;
63
+
62 64
     int64_t recording_time;
63 65
     int has_video;
64 66
     int64_t start_pts;
... ...
@@ -171,6 +173,9 @@ static int hls_window(AVFormatContext *s, int last)
171 171
 
172 172
     avio_printf(hls->pb, "#EXTM3U\n");
173 173
     avio_printf(hls->pb, "#EXT-X-VERSION:%d\n", version);
174
+    if (hls->allowcache == 0 || hls->allowcache == 1) {
175
+        avio_printf(hls->pb, "#EXT-X-ALLOW-CACHE:%s\n", hls->allowcache == 0 ? "NO" : "YES");
176
+    }
174 177
     avio_printf(hls->pb, "#EXT-X-TARGETDURATION:%d\n", target_duration);
175 178
     avio_printf(hls->pb, "#EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence);
176 179
 
... ...
@@ -394,6 +399,7 @@ static const AVOption options[] = {
394 394
     {"hls_list_size", "set maximum number of playlist entries",  OFFSET(max_nb_segments),    AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
395 395
     {"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
396 396
     {"hls_wrap",      "set number after which the index wraps",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
397
+    {"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, E},
397 398
     {"hls_base_url",  "url to prepend to each playlist entry",   OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E},
398 399
     {"hls_flags",     "set flags affecting HLS playlist and media file generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, "flags"},
399 400
     {"single_file",   "generate a single media file indexed with byte ranges", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},