From patchwork Thu Jan 17 09:05:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 11781 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 F0EDA44DF70 for ; Thu, 17 Jan 2019 11:05:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 22C4668ABB1; Thu, 17 Jan 2019 11:05:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from a1i868.smtp2go.com (a1i868.smtp2go.com [43.228.187.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF25868AB93 for ; Thu, 17 Jan 2019 11:05:18 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1547716839; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=71/HKdDtdi0qciJFJXj38CybAC3GSoK3OVkxpnjbkI0=; b=hJ3n4wUS E/gGNYiLw3QkSsn5IxXjcSCkfsRF69ofZOnBg4L91cuOuxX+UtSY2ekdWoVjkvbodM9BUfZUPA54A 7ebTf/FNnEkZhphyNx39KTBZRmSTvlXfx3abBV1i4ieAXNUPIVaiUBMiAxpay3waiGXV71MeDuuEK kqOFCSACSYMyztffmwyXuu04gJKodKIvGPtry7YJUY2KRcUXLs9aGBKXhzz7nN2ra8D2Ljhl8o35K 4kX2O3s9A3lVW2cdz/AqQAM2uZ6aNLgt9xtn0SKexAlhLvGvPzIYLNGJhhy+VyUvnNhjlfUK/jaUe BYKEFlTQCAyltUD+XeNRCWYjYA==; Received: from [10.66.228.43] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1gk3cC-4pkV44-Gc; Thu, 17 Jan 2019 09:05:32 +0000 Received: from [10.63.208.195] (helo=blr-mp4tf.bangalore.corp.akamai.com) by smtpcorp.com with esmtpa (Exim 4.91) (envelope-from ) id 1gk3cB-wSEVLj-9r; Thu, 17 Jan 2019 09:05:31 +0000 From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Jan 2019 14:35:22 +0530 Message-Id: <20190117090522.45328-1-kjeyapal@akamai.com> X-Mailer: git-send-email 2.17.1 (Apple Git-112) In-Reply-To: <20190117090136.45200-1-kjeyapal@akamai.com> References: <20190117090136.45200-1-kjeyapal@akamai.com> X-Smtpcorp-Track: 1gk3cUwSEVLM9r.QjVa65WFI Feedback-ID: 337386m:337386asVRLGB:337386sLsbQfmxNq X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH v2] avformat/dashenc: Format xs:datetime in millisecond precision 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 Cc: Karthick J MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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); } }