diff mbox

[FFmpeg-devel,v2] avformat/dashenc: Format xs:datetime in millisecond precision

Message ID 20190117090522.45328-1-kjeyapal@akamai.com
State Accepted
Commit b6d96a6bcc531c216623fbcdf9d5034f51abf216
Headers show

Commit Message

Jeyapal, Karthick Jan. 17, 2019, 9:05 a.m. UTC
For low latency streaming even milliseconds matter!
---
 libavformat/dashenc.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Jeyapal, Karthick Jan. 21, 2019, 9:30 a.m. UTC | #1
On 1/17/19 2:35 PM, Karthick J wrote:
> For low latency streaming even milliseconds matter!

> ---

>  libavformat/dashenc.c | 15 ++++++++++++---

>  1 file changed, 12 insertions(+), 3 deletions(-)

>

> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c

> index cfd0f601d4..9c90cf17e5 100644

> --- a/libavformat/dashenc.c

> +++ b/libavformat/dashenc.c

> @@ -32,6 +32,7 @@

>  #include "libavutil/mathematics.h"

>  #include "libavutil/opt.h"

>  #include "libavutil/rational.h"

> +#include "libavutil/time.h"

>  #include "libavutil/time_internal.h"

>  

>  #include "avc.h"

> @@ -668,12 +669,20 @@ static void write_time(AVIOContext *out, int64_t time)

>  

>  static void format_date_now(char *buf, int size)

>  {

> -    time_t t = time(NULL);

>      struct tm *ptm, tmbuf;

> -    ptm = gmtime_r(&t, &tmbuf);

> +    int64_t time_us = av_gettime();

> +    int64_t time_ms = time_us / 1000;

> +    const time_t time_s = time_ms / 1000;

> +    int millisec = time_ms - (time_s * 1000);

> +    ptm = gmtime_r(&time_s, &tmbuf);

>      if (ptm) {

> -        if (!strftime(buf, size, "%Y-%m-%dT%H:%M:%SZ", ptm))

> +        int len;

> +        if (!strftime(buf, size, "%Y-%m-%dT%H:%M:%S", ptm)) {

>              buf[0] = '\0';

> +            return;

> +        }

> +        len = strlen(buf);

> +        snprintf(buf + len, size - len, ".%03dZ", millisec);

>      }

>  }

>  

Pushed.
diff mbox

Patch

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index cfd0f601d4..9c90cf17e5 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -32,6 +32,7 @@ 
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "libavutil/rational.h"
+#include "libavutil/time.h"
 #include "libavutil/time_internal.h"
 
 #include "avc.h"
@@ -668,12 +669,20 @@  static void write_time(AVIOContext *out, int64_t time)
 
 static void format_date_now(char *buf, int size)
 {
-    time_t t = time(NULL);
     struct tm *ptm, tmbuf;
-    ptm = gmtime_r(&t, &tmbuf);
+    int64_t time_us = av_gettime();
+    int64_t time_ms = time_us / 1000;
+    const time_t time_s = time_ms / 1000;
+    int millisec = time_ms - (time_s * 1000);
+    ptm = gmtime_r(&time_s, &tmbuf);
     if (ptm) {
-        if (!strftime(buf, size, "%Y-%m-%dT%H:%M:%SZ", ptm))
+        int len;
+        if (!strftime(buf, size, "%Y-%m-%dT%H:%M:%S", ptm)) {
             buf[0] = '\0';
+            return;
+        }
+        len = strlen(buf);
+        snprintf(buf + len, size - len, ".%03dZ", millisec);
     }
 }