From patchwork Thu Oct 17 18:59:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 15820 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 3D18C44A238 for ; Thu, 17 Oct 2019 22:00:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 240CA68AB1E; Thu, 17 Oct 2019 22:00:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A29B68AAF2 for ; Thu, 17 Oct 2019 22:00:07 +0300 (EEST) Received: by mail-qt1-f193.google.com with SMTP id c21so5117714qtj.12 for ; Thu, 17 Oct 2019 12:00:07 -0700 (PDT) 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=MMegrAyt6QHAVMSqZuIRAbWVNmFXXr+gVVwOs0pXZpA=; b=iXq2gcOleavdwo/NW9GChtdwZ+3kEdn6sWkDmq9809FUaUh94PwXLjxxOwb2JgIrT0 Q9lxZPLoBVzGtyvFWVdtTOQ8hPDA+ImIfR2IBruu5hhAxe6GdeaYmzJpt2pUNY8cVWUq zJWVte7sy0t5jX9bivYpe5d/uNt04gqoZagCh4T3rijp0Rhq6hAQjAIEqeqrkX3AMbA7 VJ4eCDv4TmuKoEacxqpcr7Es9m3PR0rp4Vna7Ci7z8Q0ThMzPUP7I7rbLJBcIixDlumI 4CgtPSDIJ3HX/D7u/MN844DDWAj31QD98HxWmOoZwIFFSX3nPWWpPQ4jBQMBUV0l+kce PDtg== 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=MMegrAyt6QHAVMSqZuIRAbWVNmFXXr+gVVwOs0pXZpA=; b=ni5x36r5b5Se+VQAv+bRqvVg7Bpr66f53P+Jii+WdwvX0m56RlSzD8ybz1X9XCdbdM 7viJQrgXPnVhRZ03dmEOW7cJE3C48Up0f3KbHbHdafKjiURG17m/tNEtLdnLg+whTUwS +kRqWV4k3CGuBcYHLHHNMX3o58z+OOPOAjjs0cByEvreRAXTICwLiAfBfNJdbDmoIrVL CXsOyqNCTIjpzvR4kat2G37afufoTOgOHvYhw0MdGN26ViUe4+7Kejss/xrxLqO9sk58 qsjrPLo2K/Gbv9aOR2paoRC39PjB7VTwsAlEqvMGhlRMGKzWisRbtOQnEiPolLd5nsTD VvNQ== X-Gm-Message-State: APjAAAVYbQ+ecGt13LmJUEA8FU5j5Nn7z4PiC5/PEJHMeyli44mMB/nx BsGJo0ehwgOcaCZIa5Xt7eANpogI X-Google-Smtp-Source: APXvYqzdG47azksFZ573c7ZuHtWsHCFksJAbr7D0Kg+XCN4gcJc7BAYeXmE7jh7h1IIZSQJwiKfFug== X-Received: by 2002:ac8:53cb:: with SMTP id c11mr2040190qtq.162.1571338805843; Thu, 17 Oct 2019 12:00:05 -0700 (PDT) Received: from localhost.localdomain ([191.83.221.234]) by smtp.gmail.com with ESMTPSA id v141sm798933qka.59.2019.10.17.12.00.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 12:00:05 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Oct 2019 15:59:09 -0300 Message-Id: <20191017185916.2957-5-jamrial@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191017185916.2957-1-jamrial@gmail.com> References: <20191017185916.2957-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/11] avformat/dashenc: Write a Producer Reference Time element 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" As defined in section 5.12 from ISO/IEC FDIS 23009-1:2019 Initial implementation using capture time. Will be replaced by a following commit. Signed-off-by: James Almer --- libavformat/dashenc.c | 50 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 7be22b268f..63a3853110 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -116,9 +116,11 @@ typedef struct OutputStream { char full_path[1024]; char temp_path[1024]; double availability_time_offset; + char producer_reference_time[100]; int total_pkt_size; int total_pkt_duration; int muxer_overhead; + int64_t start_time_us; } OutputStream; typedef struct DASHContext { @@ -143,6 +145,7 @@ typedef struct DASHContext { int64_t total_duration; char availability_start_time[100]; time_t start_time_s; + int64_t presentation_time_offset; char dirname[1024]; const char *single_file_name; /* file names as specified in options */ const char *init_seg_name; @@ -167,6 +170,7 @@ typedef struct DASHContext { int nr_of_streams_to_flush; int nr_of_streams_flushed; int frag_type; + int write_prft; } DASHContext; static struct codec_string { @@ -636,7 +640,10 @@ static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatCont avio_printf(out, "availabilityTimeOffset=\"%.3f\" ", os->availability_time_offset); } - avio_printf(out, "initialization=\"%s\" media=\"%s\" startNumber=\"%d\">\n", os->init_seg_name, os->media_seg_name, c->use_timeline ? start_number : 1); + 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); + avio_printf(out, ">\n"); if (c->use_timeline) { int64_t cur_time = 0; avio_printf(out, "\t\t\t\t\t\n"); @@ -745,10 +752,9 @@ static void write_time(AVIOContext *out, int64_t time) avio_printf(out, "%d.%dS", seconds, fractions / (AV_TIME_BASE / 10)); } -static void format_date_now(char *buf, int size) +static void format_date(char *buf, int size, int64_t time_us) { struct tm *ptm, 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); @@ -787,6 +793,7 @@ static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_ind if (as->descriptor) avio_printf(out, "\t\t\t%s\n", as->descriptor); for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; OutputStream *os = &c->streams[i]; char bandwidth_str[64] = {'\0'}; @@ -798,7 +805,6 @@ static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_ind os->bit_rate); if (as->media_type == AVMEDIA_TYPE_VIDEO) { - AVStream *st = s->streams[i]; avio_printf(out, "\t\t\tformat_name, os->codec_str, bandwidth_str, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height); if (st->avg_frame_rate.num) @@ -810,6 +816,12 @@ static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_ind avio_printf(out, "\t\t\t\t\n", s->streams[i]->codecpar->channels); } + if (!final && c->write_prft && os->producer_reference_time[0]) { + avio_printf(out, "\t\t\t\t\n", + i, os->producer_reference_time, c->presentation_time_offset); + avio_printf(out, "\t\t\t\t\t\n", c->utc_timing_url); + avio_printf(out, "\t\t\t\t\n"); + } output_segment_list(os, out, s, i, final); avio_printf(out, "\t\t\t\n"); } @@ -1038,7 +1050,7 @@ static int write_manifest(AVFormatContext *s, int final) 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(now_str, sizeof(now_str)); + format_date(now_str, sizeof(now_str), av_gettime()); if (now_str[0]) avio_printf(out, "\tpublishTime=\"%s\"\n", now_str); if (c->window_size && c->use_template) { @@ -1230,6 +1242,16 @@ static int dash_init(AVFormatContext *s) c->frag_type = FRAG_TYPE_EVERY_FRAME; } + if (c->write_prft && !c->utc_timing_url) { + av_log(s, AV_LOG_WARNING, "Producer Reference Time element option will be ignored as utc_timing_url is not set\n"); + c->write_prft = 0; + } + + if (c->write_prft && !c->streaming) { + av_log(s, AV_LOG_WARNING, "Producer Reference Time element option will be ignored as streaming is not enabled\n"); + c->write_prft = 0; + } + av_strlcpy(c->dirname, s->url, sizeof(c->dirname)); ptr = strrchr(c->dirname, '/'); if (ptr) { @@ -1793,15 +1815,16 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) pkt->dts = 0; } - if (os->first_pts == AV_NOPTS_VALUE) + if (os->first_pts == AV_NOPTS_VALUE) { os->first_pts = pkt->pts; + os->start_time_us = av_gettime(); + } os->last_pts = pkt->pts; if (!c->availability_start_time[0]) { - int64_t start_time_us = av_gettime(); - c->start_time_s = start_time_us / 1000000; - format_date_now(c->availability_start_time, - sizeof(c->availability_start_time)); + c->start_time_s = os->start_time_us / 1000000; + format_date(c->availability_start_time, + sizeof(c->availability_start_time), os->start_time_us); } if (!os->packets_written) @@ -1858,6 +1881,12 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) } } + if (c->write_prft && !os->producer_reference_time[0]) + format_date(os->producer_reference_time, + sizeof(os->producer_reference_time), + os->start_time_us + (av_rescale_q(os->first_pts, st->time_base, AV_TIME_BASE_Q) - + c->presentation_time_offset)); + if ((ret = dash_flush(s, 0, pkt->stream_index)) < 0) return ret; } @@ -2060,6 +2089,7 @@ static const AVOption options[] = { { "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 }, { "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 }, };