diff mbox series

[FFmpeg-devel] avformat/hlsenc: add support for microseconds since epoch based sequence number

Message ID 20200418203332.30713-1-cus@passwd.hu
State Accepted
Headers show
Series [FFmpeg-devel] avformat/hlsenc: add support for microseconds since epoch based sequence number | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Marton Balint April 18, 2020, 8:33 p.m. UTC
Sequence numbers of segments should be unique, if an encoder is using shorter
than 1 second segments and it is restarted, then future segments will be using
already used sequence numbers if initial sequence number is based on the number
of seconds since epoch and not microseconds.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 doc/muxers.texi       |  3 +++
 libavformat/hlsenc.c  | 13 ++++++++++---
 libavformat/version.h |  2 +-
 3 files changed, 14 insertions(+), 4 deletions(-)

Comments

Marton Balint April 29, 2020, 4:29 p.m. UTC | #1
On Sat, 18 Apr 2020, Marton Balint wrote:

> Sequence numbers of segments should be unique, if an encoder is using shorter
> than 1 second segments and it is restarted, then future segments will be using
> already used sequence numbers if initial sequence number is based on the number
> of seconds since epoch and not microseconds.

Ping.

Thanks,
Marton

>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> doc/muxers.texi       |  3 +++
> libavformat/hlsenc.c  | 13 ++++++++++---
> libavformat/version.h |  2 +-
> 3 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index e5b8debcb3..cf1c9a8622 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -640,6 +640,9 @@ Set the starting sequence numbers according to @var{start_number} option value.
> @item epoch
> The start number will be the seconds since epoch (1970-01-01 00:00:00)
> 
> +@item epoch_us
> +The start number will be the microseconds since epoch (1970-01-01 00:00:00)
> +
> @item datetime
> The start number will be based on the current date/time as YYYYmmddHHMMSS. e.g. 20161231235759.
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index d75684741f..008a3f3947 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -41,6 +41,7 @@
> #include "libavutil/random_seed.h"
> #include "libavutil/opt.h"
> #include "libavutil/log.h"
> +#include "libavutil/time.h"
> #include "libavutil/time_internal.h"
> 
> #include "avformat.h"
> @@ -56,6 +57,8 @@ typedef enum {
>     HLS_START_SEQUENCE_AS_START_NUMBER = 0,
>     HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH = 1,
>     HLS_START_SEQUENCE_AS_FORMATTED_DATETIME = 2,  // YYYYMMDDhhmmss
> +    HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH = 3,
> +    HLS_START_SEQUENCE_LAST, // unused
> } StartSequenceSourceType;
> 
> typedef enum {
> @@ -2788,9 +2791,12 @@ static int hls_init(AVFormatContext *s)
>         pattern = "%d.m4s";
>     }
>     if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) ||
> +        (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) ||
>         (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) {
> -        time_t t = time(NULL); // we will need it in either case
> -        if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
> +        time_t t = time(NULL);
> +        if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) {
> +            hls->start_sequence = av_gettime();
> +        } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
>             hls->start_sequence = (int64_t)t;
>         } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME) {
>             char b[15];
> @@ -3083,9 +3089,10 @@ static const AVOption options[] = {
>     {"event", "EVENT playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_EVENT }, INT_MIN, INT_MAX, E, "pl_type" },
>     {"vod", "VOD playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_VOD }, INT_MIN, INT_MAX, E, "pl_type" },
>     {"method", "set the HTTP method(default: PUT)", OFFSET(method), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
> -    {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_AS_FORMATTED_DATETIME, E, "start_sequence_source_type" },
> +    {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_LAST-1, E, "start_sequence_source_type" },
>     {"generic", "start_number value (default)", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
>     {"epoch", "seconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
> +    {"epoch_us", "microseconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
>     {"datetime", "current datetime as YYYYMMDDhhmmss", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_FORMATTED_DATETIME }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
>     {"http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
>     {"var_stream_map", "Variant stream map string", OFFSET(var_stream_map), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
> diff --git a/libavformat/version.h b/libavformat/version.h
> index 18c2f5fec2..719cda6b98 100644
> --- a/libavformat/version.h
> +++ b/libavformat/version.h
> @@ -33,7 +33,7 @@
> // Also please add any ticket numbers that you believe might be affected here
> #define LIBAVFORMAT_VERSION_MAJOR  58
> #define LIBAVFORMAT_VERSION_MINOR  42
> -#define LIBAVFORMAT_VERSION_MICRO 100
> +#define LIBAVFORMAT_VERSION_MICRO 101
> 
> #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
>                                                LIBAVFORMAT_VERSION_MINOR, \
> -- 
> 2.16.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Liu Steven April 30, 2020, 1:21 a.m. UTC | #2
> 2020年4月30日 上午12:29,Marton Balint <cus@passwd.hu> 写道:
> 
> 
> 
> On Sat, 18 Apr 2020, Marton Balint wrote:
> 
>> Sequence numbers of segments should be unique, if an encoder is using shorter
>> than 1 second segments and it is restarted, then future segments will be using
>> already used sequence numbers if initial sequence number is based on the number
>> of seconds since epoch and not microseconds.
> 
> Ping.
Sorry response so late.
LGTM
> 
> Thanks,
> Marton
> 
>> 
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>> doc/muxers.texi       |  3 +++
>> libavformat/hlsenc.c  | 13 ++++++++++---
>> libavformat/version.h |  2 +-
>> 3 files changed, 14 insertions(+), 4 deletions(-)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index e5b8debcb3..cf1c9a8622 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -640,6 +640,9 @@ Set the starting sequence numbers according to @var{start_number} option value.
>> @item epoch
>> The start number will be the seconds since epoch (1970-01-01 00:00:00)
>> +@item epoch_us
>> +The start number will be the microseconds since epoch (1970-01-01 00:00:00)
>> +
>> @item datetime
>> The start number will be based on the current date/time as YYYYmmddHHMMSS. e.g. 20161231235759.
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index d75684741f..008a3f3947 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -41,6 +41,7 @@
>> #include "libavutil/random_seed.h"
>> #include "libavutil/opt.h"
>> #include "libavutil/log.h"
>> +#include "libavutil/time.h"
>> #include "libavutil/time_internal.h"
>> #include "avformat.h"
>> @@ -56,6 +57,8 @@ typedef enum {
>>    HLS_START_SEQUENCE_AS_START_NUMBER = 0,
>>    HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH = 1,
>>    HLS_START_SEQUENCE_AS_FORMATTED_DATETIME = 2,  // YYYYMMDDhhmmss
>> +    HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH = 3,
>> +    HLS_START_SEQUENCE_LAST, // unused
>> } StartSequenceSourceType;
>> typedef enum {
>> @@ -2788,9 +2791,12 @@ static int hls_init(AVFormatContext *s)
>>        pattern = "%d.m4s";
>>    }
>>    if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) ||
>> +        (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) ||
>>        (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) {
>> -        time_t t = time(NULL); // we will need it in either case
>> -        if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
>> +        time_t t = time(NULL);
>> +        if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) {
>> +            hls->start_sequence = av_gettime();
>> +        } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
>>            hls->start_sequence = (int64_t)t;
>>        } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME) {
>>            char b[15];
>> @@ -3083,9 +3089,10 @@ static const AVOption options[] = {
>>    {"event", "EVENT playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_EVENT }, INT_MIN, INT_MAX, E, "pl_type" },
>>    {"vod", "VOD playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_VOD }, INT_MIN, INT_MAX, E, "pl_type" },
>>    {"method", "set the HTTP method(default: PUT)", OFFSET(method), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
>> -    {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_AS_FORMATTED_DATETIME, E, "start_sequence_source_type" },
>> +    {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_LAST-1, E, "start_sequence_source_type" },
>>    {"generic", "start_number value (default)", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
>>    {"epoch", "seconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
>> +    {"epoch_us", "microseconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
>>    {"datetime", "current datetime as YYYYMMDDhhmmss", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_FORMATTED_DATETIME }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
>>    {"http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
>>    {"var_stream_map", "Variant stream map string", OFFSET(var_stream_map), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
>> diff --git a/libavformat/version.h b/libavformat/version.h
>> index 18c2f5fec2..719cda6b98 100644
>> --- a/libavformat/version.h
>> +++ b/libavformat/version.h
>> @@ -33,7 +33,7 @@
>> // Also please add any ticket numbers that you believe might be affected here
>> #define LIBAVFORMAT_VERSION_MAJOR  58
>> #define LIBAVFORMAT_VERSION_MINOR  42
>> -#define LIBAVFORMAT_VERSION_MICRO 100
>> +#define LIBAVFORMAT_VERSION_MICRO 101
>> #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
>>                                               LIBAVFORMAT_VERSION_MINOR, \
>> -- 
>> 2.16.4
>> 
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Thanks

Steven Liu
Marton Balint May 1, 2020, 3:26 p.m. UTC | #3
On Thu, 30 Apr 2020, Steven Liu wrote:

>
>
>> 2020年4月30日 上午12:29,Marton Balint <cus@passwd.hu> 写道:
>> 
>> 
>> 
>> On Sat, 18 Apr 2020, Marton Balint wrote:
>> 
>>> Sequence numbers of segments should be unique, if an encoder is using shorter
>>> than 1 second segments and it is restarted, then future segments will be using
>>> already used sequence numbers if initial sequence number is based on the number
>>> of seconds since epoch and not microseconds.
>> 
>> Ping.
> Sorry response so late.
> LGTM

Thanks, applied.

Regards,
Marton
diff mbox series

Patch

diff --git a/doc/muxers.texi b/doc/muxers.texi
index e5b8debcb3..cf1c9a8622 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -640,6 +640,9 @@  Set the starting sequence numbers according to @var{start_number} option value.
 @item epoch
 The start number will be the seconds since epoch (1970-01-01 00:00:00)
 
+@item epoch_us
+The start number will be the microseconds since epoch (1970-01-01 00:00:00)
+
 @item datetime
 The start number will be based on the current date/time as YYYYmmddHHMMSS. e.g. 20161231235759.
 
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d75684741f..008a3f3947 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -41,6 +41,7 @@ 
 #include "libavutil/random_seed.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
+#include "libavutil/time.h"
 #include "libavutil/time_internal.h"
 
 #include "avformat.h"
@@ -56,6 +57,8 @@  typedef enum {
     HLS_START_SEQUENCE_AS_START_NUMBER = 0,
     HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH = 1,
     HLS_START_SEQUENCE_AS_FORMATTED_DATETIME = 2,  // YYYYMMDDhhmmss
+    HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH = 3,
+    HLS_START_SEQUENCE_LAST, // unused
 } StartSequenceSourceType;
 
 typedef enum {
@@ -2788,9 +2791,12 @@  static int hls_init(AVFormatContext *s)
         pattern = "%d.m4s";
     }
     if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) ||
+        (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) ||
         (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) {
-        time_t t = time(NULL); // we will need it in either case
-        if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
+        time_t t = time(NULL);
+        if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) {
+            hls->start_sequence = av_gettime();
+        } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
             hls->start_sequence = (int64_t)t;
         } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME) {
             char b[15];
@@ -3083,9 +3089,10 @@  static const AVOption options[] = {
     {"event", "EVENT playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_EVENT }, INT_MIN, INT_MAX, E, "pl_type" },
     {"vod", "VOD playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_VOD }, INT_MIN, INT_MAX, E, "pl_type" },
     {"method", "set the HTTP method(default: PUT)", OFFSET(method), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
-    {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_AS_FORMATTED_DATETIME, E, "start_sequence_source_type" },
+    {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_LAST-1, E, "start_sequence_source_type" },
     {"generic", "start_number value (default)", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
     {"epoch", "seconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
+    {"epoch_us", "microseconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
     {"datetime", "current datetime as YYYYMMDDhhmmss", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_FORMATTED_DATETIME }, INT_MIN, INT_MAX, E, "start_sequence_source_type" },
     {"http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
     {"var_stream_map", "Variant stream map string", OFFSET(var_stream_map), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
diff --git a/libavformat/version.h b/libavformat/version.h
index 18c2f5fec2..719cda6b98 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@ 
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
 #define LIBAVFORMAT_VERSION_MINOR  42
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \