From patchwork Sat Dec 21 18:02:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 16912 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 548F144958D for ; Sat, 21 Dec 2019 20:03:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3FD5F68AAAB; Sat, 21 Dec 2019 20:03:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42A0068AA47 for ; Sat, 21 Dec 2019 20:03:40 +0200 (EET) Received: by mail-pj1-f65.google.com with SMTP id l35so5594644pje.3 for ; Sat, 21 Dec 2019 10:03:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5nJvdXYWNuhc2pxjXgj83egSPWVn4AcMPGwXeep0+4E=; b=lQveFRBiqfcTsopFmX88Q2Yr0+3LnRTFEaPZg3zDAcenifRr5JepTiYBh7ls9aK5kv kFresox8gJjRUaxVokNA7thGZ2couoyv8+HFlap1IS0/twW9IDxcgQVCz56ub+cz8NZG e4OPkw4WnfYoicCp7ol1Elj/MaAYYAsxQMkIACN3+9Cind5QsnmqmMD8HtlDKNu/VK7+ XMzcXKcGiQwsFc+VgR00y0kjDX6Pc07iS+Pb1vuTl8h1uXgbYlSh3PI4Yr5+LNFEGKB4 V1oCGh3F5uSrMeQNh5abBG3ENrjf1pWlV1m7jyTsS56HQoF/cl0K/m99rseXVRQu8F6N Vo0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5nJvdXYWNuhc2pxjXgj83egSPWVn4AcMPGwXeep0+4E=; b=M6fU2oYr2KvijhW1ZE5g9yn5kvoxQqrwItubfcsu+b1aqFRWidGqM56j/gA+cYUhU9 q1LpykxsZ05dTaYVjV4tUBoi4GGfZU2AP3lv/vp8qZOcZ93rdt8wiDrCQCeupz07vklM 4TM4tQ8jmt6PL4H/0xJoZ8bBmvNB5rskhy1Iwy8FiVI7esakyAVRIlnmK/RYh4JOBflR RgTrPG8LTthWJWKSV4VN1eUsgG/qELs5WVM//n5oFbUwAksnxVN2mUpayuCPTD/mHVdw E6iDxBHguHUi2S4bEBsGfDD2MK6mVlkvqTjdHpKlUpQTAOIWLhWG30/0SzG8BOK5hXJ7 XszQ== X-Gm-Message-State: APjAAAX8T9vyZwx7vmpPi/+OlARpP50SXma8NNHiURWdY8b0bBc9q2jz LrIv0qBr7QKYtVpQp1U9wTYcdTgc X-Google-Smtp-Source: APXvYqwOlMK0KAy/OEXgeKa9MC00WNbonx/iZNP0CWxCZ4278Y5spdLPnJVMuB44L7TxRIElWtpwIA== X-Received: by 2002:a17:902:700c:: with SMTP id y12mr21439862plk.227.1576951418525; Sat, 21 Dec 2019 10:03:38 -0800 (PST) Received: from localhost.localdomain ([191.83.216.116]) by smtp.gmail.com with ESMTPSA id s196sm18223564pfs.136.2019.12.21.10.03.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Dec 2019 10:03:38 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 21 Dec 2019 15:02:46 -0300 Message-Id: <20191221180252.6091-9-jamrial@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191221180252.6091-1-jamrial@gmail.com> References: <20191221180252.6091-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/15] avformat/dashenc: add an option to enable low latency Dash manifest X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" In combination with the streaming option it constrains the value of a few elements, to prevet clients from buffering too much data before starting presentation. Signed-off-by: James Almer --- libavformat/dashenc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index baed933d6a..e352d37da4 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -144,6 +144,7 @@ typedef struct DASHContext { int has_video; int64_t last_duration; int64_t total_duration; + int64_t max_frag_duration; char availability_start_time[100]; time_t start_time_s; int64_t presentation_time_offset; @@ -167,6 +168,7 @@ typedef struct DASHContext { SegmentType segment_type_option; /* segment type as specified in options */ int ignore_io_errors; int lhls; + int ldash; int master_publish_rate; int nr_of_streams_to_flush; int nr_of_streams_flushed; @@ -640,6 +642,9 @@ static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatCont avio_printf(out, "availabilityTimeOffset=\"%.3f\" ", os->availability_time_offset); } + if (c->streaming && c->ldash && !final) + avio_printf(out, "availabilityTimeComplete=\"false\" "); + avio_printf(out, "initialization=\"%s\" media=\"%s\" startNumber=\"%d\"", os->init_seg_name, os->media_seg_name, c->use_timeline ? start_number : 1); if (c->presentation_time_offset) avio_printf(out, " presentationTimeOffset=\"%"PRId64"\"", c->presentation_time_offset); @@ -1047,7 +1052,8 @@ static int write_manifest(AVFormatContext *s, int final) if (c->use_template && !c->use_timeline) update_period = 500; avio_printf(out, "\tminimumUpdatePeriod=\"PT%"PRId64"S\"\n", update_period); - avio_printf(out, "\tsuggestedPresentationDelay=\"PT%"PRId64"S\"\n", c->last_duration / AV_TIME_BASE); + if (!c->ldash) + avio_printf(out, "\tsuggestedPresentationDelay=\"PT%"PRId64"S\"\n", c->last_duration / AV_TIME_BASE); if (c->availability_start_time[0]) avio_printf(out, "\tavailabilityStartTime=\"%s\"\n", c->availability_start_time); format_date(now_str, sizeof(now_str), av_gettime()); @@ -1060,7 +1066,7 @@ static int write_manifest(AVFormatContext *s, int final) } } avio_printf(out, "\tminBufferTime=\""); - write_time(out, c->last_duration * 2); + write_time(out, c->ldash && c->max_frag_duration ? c->max_frag_duration : c->last_duration * 2); avio_printf(out, "\">\n"); avio_printf(out, "\t\n"); if (title) { @@ -1228,6 +1234,11 @@ static int dash_init(AVFormatContext *s) c->lhls = 0; } + if (c->ldash && !c->streaming) { + av_log(s, AV_LOG_WARNING, "LDash option will be ignored as streaming is not enabled\n"); + c->ldash = 0; + } + if (c->global_sidx && !c->single_file) { av_log(s, AV_LOG_WARNING, "Global SIDX option will be ignored as single_file is not enabled\n"); c->global_sidx = 0; @@ -1857,6 +1868,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) os->availability_time_offset = ((double) os->seg_duration - frame_duration) / AV_TIME_BASE; + c->max_frag_duration = FFMAX(frame_duration, c->max_frag_duration); } if (c->use_template && !c->use_timeline) { @@ -1935,6 +1947,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) AV_TIME_BASE_Q); os->availability_time_offset = ((double) os->seg_duration - frag_duration) / AV_TIME_BASE; + c->max_frag_duration = FFMAX(frag_duration, c->max_frag_duration); } } } @@ -2097,6 +2110,7 @@ static const AVOption options[] = { { "webm", "make segment file in WebM format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_WEBM }, 0, UINT_MAX, E, "segment_type"}, { "ignore_io_errors", "Ignore IO errors during open and write. Useful for long-duration runs with network output", OFFSET(ignore_io_errors), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, { "lhls", "Enable Low-latency HLS(Experimental). Adds #EXT-X-PREFETCH tag with current segment's URI", OFFSET(lhls), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, + { "ldash", "Enable Low-latency dash. Constrains the value of a few elements", OFFSET(ldash), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, { "master_m3u8_publish_rate", "Publish master playlist every after this many segment intervals", OFFSET(master_publish_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, UINT_MAX, E}, { "write_prft", "Write producer reference time element", OFFSET(write_prft), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E}, { NULL },