Browse code

avformat/hlsenc: deprecate hls_wrap option

When user use the hls_wrap, there have many problem:
1. some platform refersh the old but usefull segment
2. CDN(Content Delivery Network) Deliver HLS not friendly

The hls_wrap is used to wrap segments for use little space,
now user can use hls_list_size and hls_flags delete_segments
instead it.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>

Steven Liu authored on 2017/02/11 13:32:31
Showing 3 changed files
... ...
@@ -442,9 +442,8 @@ parameters. Values containing @code{:} special characters must be
442 442
 escaped.
443 443
 
444 444
 @item hls_wrap @var{wrap}
445
-Set the number after which the segment filename number (the number
446
-specified in each segment file) wraps. If set to 0 the number will be
447
-never wrapped. Default value is 0.
445
+This is a deprecated option, you can use @code {hls_list_size}
446
+and @code{hls_flags delete_segments} instead it
448 447
 
449 448
 This option is useful to avoid to fill the disk with many segment
450 449
 files, and limits the maximum number of segment files written to disk
... ...
@@ -101,7 +101,9 @@ typedef struct HLSContext {
101 101
     float time;            // Set by a private option.
102 102
     float init_time;       // Set by a private option.
103 103
     int max_nb_segments;   // Set by a private option.
104
+#if FF_API_HLS_WRAP
104 105
     int  wrap;             // Set by a private option.
106
+#endif
105 107
     uint32_t flags;        // enum HLSFlags
106 108
     uint32_t pl_type;      // enum PlaylistType
107 109
     char *segment_filename;
... ...
@@ -566,7 +568,11 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double
566 566
         hls->initial_prog_date_time += en->duration;
567 567
         hls->segments = en->next;
568 568
         if (en && hls->flags & HLS_DELETE_SEGMENTS &&
569
+#if FF_API_HLS_WRAP
569 570
                 !(hls->flags & HLS_SINGLE_FILE || hls->wrap)) {
571
+#else
572
+                !(hls->flags & HLS_SINGLE_FILE)) {
573
+#endif
570 574
             en->next = hls->old_segments;
571 575
             hls->old_segments = en;
572 576
             if ((ret = hls_delete_old_segments(hls)) < 0)
... ...
@@ -834,7 +840,11 @@ static int hls_start(AVFormatContext *s)
834 834
                   sizeof(vtt_oc->filename));
835 835
     } else if (c->max_seg_size > 0) {
836 836
         if (replace_int_data_in_filename(oc->filename, sizeof(oc->filename),
837
+#if FF_API_HLS_WRAP
837 838
             c->basename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) {
839
+#else
840
+            c->basename, 'd', c->sequence) < 1) {
841
+#endif
838 842
                 av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s', you can try to use -use_localtime 1 with it\n", c->basename);
839 843
                 return AVERROR(EINVAL);
840 844
         }
... ...
@@ -853,7 +863,11 @@ static int hls_start(AVFormatContext *s)
853 853
                 if (!filename)
854 854
                     return AVERROR(ENOMEM);
855 855
                 if (replace_int_data_in_filename(oc->filename, sizeof(oc->filename),
856
+#if FF_API_HLS_WRAP
856 857
                     filename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) {
858
+#else
859
+                    filename, 'd', c->sequence) < 1) {
860
+#endif
857 861
                     av_log(c, AV_LOG_ERROR,
858 862
                            "Invalid second level segment filename template '%s', "
859 863
                             "you can try to remove second_level_segment_index flag\n",
... ...
@@ -910,13 +924,21 @@ static int hls_start(AVFormatContext *s)
910 910
                 av_free(fn_copy);
911 911
             }
912 912
         } else if (replace_int_data_in_filename(oc->filename, sizeof(oc->filename),
913
+#if FF_API_HLS_WRAP
913 914
                    c->basename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) {
915
+#else
916
+                   c->basename, 'd', c->sequence) < 1) {
917
+#endif
914 918
             av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s' you can try to use -use_localtime 1 with it\n", c->basename);
915 919
             return AVERROR(EINVAL);
916 920
         }
917 921
         if( c->vtt_basename) {
918 922
             if (replace_int_data_in_filename(vtt_oc->filename, sizeof(vtt_oc->filename),
923
+#if FF_API_HLS_WRAP
919 924
                 c->vtt_basename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) {
925
+#else
926
+                c->vtt_basename, 'd', c->sequence) < 1) {
927
+#endif
920 928
                 av_log(vtt_oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", c->vtt_basename);
921 929
                 return AVERROR(EINVAL);
922 930
             }
... ...
@@ -1421,7 +1443,9 @@ static const AVOption options[] = {
1421 1421
     {"hls_list_size", "set maximum number of playlist entries",  OFFSET(max_nb_segments),    AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
1422 1422
     {"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},
1423 1423
     {"hls_vtt_options","set hls vtt list of options for the container format used for hls", OFFSET(vtt_format_options_str), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
1424
-    {"hls_wrap",      "set number after which the index wraps",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
1424
+#if FF_API_HLS_WRAP
1425
+    {"hls_wrap",      "set number after which the index wraps (will be deprecated)",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
1426
+#endif
1425 1427
     {"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},
1426 1428
     {"hls_base_url",  "url to prepend to each playlist entry",   OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E},
1427 1429
     {"hls_segment_filename", "filename template for segment files", OFFSET(segment_filename),   AV_OPT_TYPE_STRING, {.str = NULL},            0,       0,         E},
... ...
@@ -85,6 +85,10 @@
85 85
 #ifndef FF_API_HTTP_USER_AGENT
86 86
 #define FF_API_HTTP_USER_AGENT          (LIBAVFORMAT_VERSION_MAJOR < 58)
87 87
 #endif
88
+#ifndef FF_API_HLS_WRAP
89
+#define FF_API_HLS_WRAP                 (LIBAVFORMAT_VERSION_MAJOR < 58)
90
+#endif
91
+
88 92
 
89 93
 #ifndef FF_API_R_FRAME_RATE
90 94
 #define FF_API_R_FRAME_RATE            1