[FFmpeg-devel,v3,06/11] avformat/dashenc: addition of @availabilityTimeOffset in MPD

Submitted by Dixit, Vishwanath on April 11, 2018, 7:01 a.m.

Details

Message ID 1523430107-17265-1-git-send-email-vdixit@akamai.com
State New
Headers show

Commit Message

Dixit, Vishwanath April 11, 2018, 7:01 a.m.
From: Vishwanath Dixit <vdixit@akamai.com>

availability time of Nth segment = availabilityStartTime + (N*segment duration) - availabilityTimeOffset.
This field helps to reduce the latency by about a segment duration in streaming mode.
---
 libavformat/dashenc.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 5d5310d..70409e5 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -85,6 +85,7 @@  typedef struct OutputStream {
     char filename[1024];
     char full_path[1024];
     char temp_path[1024];
+    double availability_time_offset;
 } OutputStream;
 
 typedef struct DASHContext {
@@ -346,8 +347,12 @@  static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatCont
     if (c->use_template) {
         int timescale = c->use_timeline ? os->ctx->streams[0]->time_base.den : AV_TIME_BASE;
         avio_printf(out, "\t\t\t\t<SegmentTemplate timescale=\"%d\" ", timescale);
-        if (!c->use_timeline)
+        if (!c->use_timeline) {
             avio_printf(out, "duration=\"%"PRId64"\" ", c->seg_duration);
+            if (c->streaming && os->availability_time_offset)
+                avio_printf(out, "availabilityTimeOffset=\"%.3f\" ",
+                            os->availability_time_offset);
+        }
         avio_printf(out, "initialization=\"%s\" media=\"%s\" startNumber=\"%d\">\n", c->init_seg_name, c->media_seg_name, c->use_timeline ? start_number : 1);
         if (c->use_timeline) {
             int64_t cur_time = 0;
@@ -1293,6 +1298,13 @@  static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
         format_date_now(c->availability_start_time,
                         sizeof(c->availability_start_time));
 
+    if (!os->availability_time_offset && pkt->duration) {
+        int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base,
+                                              AV_TIME_BASE_Q);
+         os->availability_time_offset = ((double) c->seg_duration -
+                                         frame_duration) / AV_TIME_BASE;
+    }
+
     if (c->use_template && !c->use_timeline) {
         elapsed_duration = pkt->pts - os->first_pts;
         seg_end_duration = (int64_t) os->segment_index * c->seg_duration;