[FFmpeg-devel] libavformat/hlsenc.c Accurrate time output in program_date_time (corrected)

Submitted by Pavel Pilar on July 9, 2019, 11:42 a.m.

Details

Message ID 20190709114236.8607-1-pilarpav@centrum.cz
State New
Headers show

Commit Message

Pavel Pilar July 9, 2019, 11:42 a.m.
---
 libavformat/hlsenc.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

mypopy@gmail.com July 9, 2019, 12:55 p.m.
On Tue, Jul 9, 2019 at 7:42 PM Pavel Pilar <pilarpav@centrum.cz> wrote:
>
> ---
>  libavformat/hlsenc.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 00c725af18..94fd713834 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2653,6 +2653,9 @@ static int hls_init(AVFormatContext *s)
>      char *p = NULL;
>      int vtt_basename_size = 0;
>      int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
> +#ifdef _POSIX_TIMERS
> +    struct timespec now_accurate;
> +#endif
>
>      hls->has_default_key = 0;
>      hls->has_video_m3u8 = 0;
> @@ -2742,14 +2745,13 @@ static int hls_init(AVFormatContext *s)
>          }
>
>          if (hls->flags & HLS_PROGRAM_DATE_TIME) {
> -#ifdef _POSIX_TIMERS
> -            struct timespec now0;
> -            clock_gettime(CLOCK_MONOTONIC, &now0);
> -            vs->initial_prog_date_time = now0.tv_sec + now0.tv_nsec / 1e9;
> -#else
>              time_t now0;
>              time(&now0);
>              vs->initial_prog_date_time = now0;
> +#ifdef _POSIX_TIMERS
> +            if (clock_gettime(CLOCK_REALTIME, &now_accurate) == 0) {
> +                vs->initial_prog_date_time = now_accurate.tv_sec + now_accurate.tv_nsec / 1e9;
> +            }
>  #endif
>          }
>          if (hls->format_options_str) {
> --
> 2.17.1
As my comments before, av_gettime or av_gettime_relative can be used
in this case,
these functions better handle cross-platform issues like check #ifdef
_POSIX_TIMERS

Patch hide | download patch | download mbox

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 00c725af18..94fd713834 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2653,6 +2653,9 @@  static int hls_init(AVFormatContext *s)
     char *p = NULL;
     int vtt_basename_size = 0;
     int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
+#ifdef _POSIX_TIMERS              
+    struct timespec now_accurate;
+#endif
 
     hls->has_default_key = 0;
     hls->has_video_m3u8 = 0;
@@ -2742,14 +2745,13 @@  static int hls_init(AVFormatContext *s)
         }
 
         if (hls->flags & HLS_PROGRAM_DATE_TIME) {
-#ifdef _POSIX_TIMERS           
-            struct timespec now0;
-            clock_gettime(CLOCK_MONOTONIC, &now0);
-            vs->initial_prog_date_time = now0.tv_sec + now0.tv_nsec / 1e9;
-#else
             time_t now0;
             time(&now0);
             vs->initial_prog_date_time = now0;
+#ifdef _POSIX_TIMERS           
+            if (clock_gettime(CLOCK_REALTIME, &now_accurate) == 0) {
+                vs->initial_prog_date_time = now_accurate.tv_sec + now_accurate.tv_nsec / 1e9;                
+            }
 #endif
         }
         if (hls->format_options_str) {