From patchwork Thu Oct 17 18:59:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 15827 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 309F244A238 for ; Thu, 17 Oct 2019 22:00:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 165EC68AB61; Thu, 17 Oct 2019 22:00:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5A3368AB4E for ; Thu, 17 Oct 2019 22:00:12 +0300 (EEST) Received: by mail-qk1-f193.google.com with SMTP id 4so2900557qki.6 for ; Thu, 17 Oct 2019 12:00:12 -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=Vtk/n75qLQDcC5n5YgRDTE1pw4isMO/r5QbNUBlZi8Y=; b=uxBn2nktcLgpBKT5q0obFWe5KPLDdsX203UrWPb42/aUJtwjupSZVnreqkSoswwqMg UgMstK7MA5k7qGlYKWKSMyyAcmJYnqv+mcGHxE9AwnEydskUoFjTXWa3lDgSytBgs/xQ VZp/bqXaJy24hAWIch1kc6vjFHQezvgXR3zQ2azpPmzrxOQ7/3WvddR9oLzuqYCafq/W V9UaULWtH1/+JiUpARXOkKHWEIFaD1H149qhcueQ1+qMSM5f8zsCZTqVQ6C2f8ua7ZMD g6T5X8tEmFupM0YPWd64lqNTOS0HOUDzvKpCpQuoUtU9Bex5nwL/eT6LesYJapfGd8Kl Ji4Q== 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=Vtk/n75qLQDcC5n5YgRDTE1pw4isMO/r5QbNUBlZi8Y=; b=sVqrAYphH+l8Wty77cfLtnhr4M7l/yk8fu81NKrj1XGQ9MejReqE3a7eMY913aOAAa 4bMj1ZauDuay499lNHBNSLvN7pzYUU2c0dDBzwxmXKTHkHv8NiuikTk4WNd0TRmnr/nh ugGvCNjMjdmvAOre6KOUI4IryYiR/6b+syErAX/gtiO8Ayr/RJ+7kbYmzpuO7/TvCMyy I4PqvJO2sTaNojg7o0B+M9uEZPA4LgecJOmg/q151SUqdFe6s2cIAebsVIuNKaMWQ+xb YqR84WG/0hElJy5IaU18DMmFqFJcG3r3kTvYrIKi+TQbiGLodFeWvjO1Tv3YGS2IoUec znuw== X-Gm-Message-State: APjAAAX/MLi7EWOzyAzJuA5AXSTBZjSIPcnqceBhvZMZxC5hshESsaCp DYA/zVsCKOQ0mOY/4p/kdSgUV7bq X-Google-Smtp-Source: APXvYqz42KRqHtQFhDXtwThLwauVg/gYM5Dw5JBKRhjXhsO8d/TDxExRIqWygyb32cwdN5b0eH5Wnw== X-Received: by 2002:a37:644f:: with SMTP id y76mr4939618qkb.369.1571338811308; Thu, 17 Oct 2019 12:00:11 -0700 (PDT) Received: from localhost.localdomain ([191.83.221.234]) by smtp.gmail.com with ESMTPSA id v141sm798933qka.59.2019.10.17.12.00.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 12:00:11 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Oct 2019 15:59:14 -0300 Message-Id: <20191017185916.2957-10-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 09/11] avformat/dashenc: use AVProducerReferenceTime side data to write the 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" This way it will be in sync with the first wallclock value in the bitstream. Signed-off-by: James Almer --- libavformat/dashenc.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 63a3853110..2ef0461c88 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -116,11 +116,11 @@ typedef struct OutputStream { char full_path[1024]; char temp_path[1024]; double availability_time_offset; - char producer_reference_time[100]; + int64_t producer_reference_time; + char producer_reference_time_str[100]; int total_pkt_size; int total_pkt_duration; int muxer_overhead; - int64_t start_time_us; } OutputStream; typedef struct DASHContext { @@ -816,9 +816,9 @@ 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); + if (!final && c->write_prft && os->producer_reference_time_str[0]) { + avio_printf(out, "\t\t\t\t\n", + i, os->producer_reference_time_str, 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"); } @@ -1402,6 +1402,8 @@ static int dash_init(AVFormatContext *s) av_dict_set(&opts, "movflags", "+frag_custom", AV_DICT_APPEND); if (c->frag_type == FRAG_TYPE_DURATION && os->frag_duration) av_dict_set_int(&opts, "frag_duration", os->frag_duration, 0); + if (c->write_prft) + av_dict_set(&opts, "write_prft", "wallclock", 0); } else { av_dict_set_int(&opts, "cluster_time_limit", c->seg_duration / 1000, 0); av_dict_set_int(&opts, "cluster_size_limit", 5 * 1024 * 1024, 0); // set a large cluster size limit @@ -1816,15 +1818,20 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) } if (os->first_pts == AV_NOPTS_VALUE) { + int side_data_size; + AVProducerReferenceTime *prft = (AVProducerReferenceTime *)av_packet_get_side_data(pkt, AV_PKT_DATA_PRFT, + &side_data_size); + if (prft && side_data_size == sizeof(AVProducerReferenceTime) && !prft->flags) + os->producer_reference_time = prft->wallclock; os->first_pts = pkt->pts; - os->start_time_us = av_gettime(); } os->last_pts = pkt->pts; if (!c->availability_start_time[0]) { - c->start_time_s = os->start_time_us / 1000000; + int64_t start_time_us = av_gettime(); + c->start_time_s = start_time_us / 1000000; format_date(c->availability_start_time, - sizeof(c->availability_start_time), os->start_time_us); + sizeof(c->availability_start_time), start_time_us); } if (!os->packets_written) @@ -1881,11 +1888,11 @@ 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 (c->write_prft && os->producer_reference_time && !os->producer_reference_time_str[0]) + format_date(os->producer_reference_time_str, + sizeof(os->producer_reference_time_str), + os->producer_reference_time + (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;