From patchwork Sat Dec 21 18:02:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 16908 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 8A56844958D for ; Sat, 21 Dec 2019 20:03:43 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 773E868A9F3; Sat, 21 Dec 2019 20:03:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59DB268A6D0 for ; Sat, 21 Dec 2019 20:03:36 +0200 (EET) Received: by mail-pl1-f193.google.com with SMTP id c13so5495540pls.0 for ; Sat, 21 Dec 2019 10:03:36 -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=aletVA92hbsq1evimglgu6eGfWtOsVefXGvFKd72/Bg=; b=tzl7Y/DZgOnvlbnKhqmd6Q/9UhiBasdLkRzBIG3wrqamupLFrTwlD6PG7J+LkOQRNp xo/iDWYkT12YsNrgq4wqWHFhT2AKQRWK1Smzk95lB+OTW07pN3l2P2CV78rUPca5BoSD d7ooJStv51ZpaylXQeqVvHp8Z1jMZeDZE3BZ4riI6rybmFb3YzljefrLBsa1nZy/H+Vq 1QIQTgu4KnaX/RTUyj1O8sdyMYHmKw3njY3Ve/Z3BsIbgk85eFpMG3EuxamzEDEkr/M4 hIokCMr0KGQw/p2ii7MeamprUIgPEiZeoCAmp4IPuBRhpehzwYFgzB1p0pA4wKAYe6zq jNxw== 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=aletVA92hbsq1evimglgu6eGfWtOsVefXGvFKd72/Bg=; b=j82nsZHlTGFc6LHyKiG0ea5hfw8Mzd/RVULfFhk0zKpCJ4l05Cnz1Be0exswQzlI7j 3b8C4reBFZgwfW/97crD4tCiQK8YmlBVUIDk53jVYI646+bqEUJx6czCfIw9Hk9GWDY0 O9tts1DGaR4D2jhca9UhqBvhVQSE0Fibz0s70Hb71Iha6kBBqBemeLgBkytbASj8Y2fL m3hAMR3YNOQq5drkno48oGs//bW/WIOmf9gYB3O5lfIYVOpQyZvOk1VSUyBFwud7452z xYl7pBNog/lArjPuSOWHPUadzUBlIZ6mqiYSD1BatpkJvaXSxHe9644foDM7C7N8gbTQ 078Q== X-Gm-Message-State: APjAAAU2LEbo3LeC8oSYNikqTd0Kua4SpgCba1Yj/zBiNmPZFvs6+n/y 22mcs5u/KHL33P/xfvw96KOlIpie X-Google-Smtp-Source: APXvYqw/V/azfbFfUInqaSQgNw7GIsCuo8pfUSZDDzsl+TxlTU0fgUKB84UcAULsMn/LwQYtSuWX9Q== X-Received: by 2002:a17:902:8601:: with SMTP id f1mr21876297plo.308.1576951414684; Sat, 21 Dec 2019 10:03:34 -0800 (PST) Received: from localhost.localdomain ([191.83.216.116]) by smtp.gmail.com with ESMTPSA id s196sm18223564pfs.136.2019.12.21.10.03.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Dec 2019 10:03:34 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 21 Dec 2019 15:02:43 -0300 Message-Id: <20191221180252.6091-6-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 06/15] avformat/utils: make ff_ntp_time() accept a timestamp as input argument 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" Will be needed by the next patch. Signed-off-by: James Almer --- libavformat/internal.h | 2 +- libavformat/movenc.c | 2 +- libavformat/rtpenc.c | 8 ++++---- libavformat/rtpenc.h | 1 + libavformat/utils.c | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index ec9a29907a..4d04a21871 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -243,7 +243,7 @@ void ff_read_frame_flush(AVFormatContext *s); #define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL) /** Get the current time since NTP epoch in microseconds. */ -uint64_t ff_ntp_time(void); +uint64_t ff_ntp_time(int64_t timestamp); /** * Get the NTP time stamp formatted as per the RFC-5905. diff --git a/libavformat/movenc.c b/libavformat/movenc.c index e422bdd071..4a47df52b5 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -4627,7 +4627,7 @@ static int mov_write_prft_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks) } if (mov->write_prft == MOV_PRFT_SRC_WALLCLOCK) { - ntp_ts = ff_get_formatted_ntp_time(ff_ntp_time()); + ntp_ts = ff_get_formatted_ntp_time(ff_ntp_time(av_gettime())); } else if (mov->write_prft == MOV_PRFT_SRC_PTS) { pts_us = av_rescale_q(first_track->cluster[0].pts, first_track->st->time_base, AV_TIME_BASE_Q); diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 63047beccc..b4f2504123 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -124,7 +124,7 @@ static int rtp_write_header(AVFormatContext *s1) if (!s->ssrc) s->ssrc = av_get_random_seed(); s->first_packet = 1; - s->first_rtcp_ntp_time = ff_ntp_time(); + s->first_rtcp_ntp_time = ff_ntp_time(av_gettime()); if (s1->start_time_realtime != 0 && s1->start_time_realtime != AV_NOPTS_VALUE) /* Round the NTP time to whole milliseconds. */ s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 + @@ -526,9 +526,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / RTCP_TX_RATIO_DEN; if ((s->first_packet || ((rtcp_bytes >= RTCP_SR_SIZE) && - (ff_ntp_time() - s->last_rtcp_ntp_time > 5000000))) && + (ff_ntp_time(av_gettime()) - s->last_rtcp_ntp_time > 5000000))) && !(s->flags & FF_RTP_FLAG_SKIP_RTCP)) { - rtcp_send_sr(s1, ff_ntp_time(), 0); + rtcp_send_sr(s1, ff_ntp_time(av_gettime()), 0); s->last_octet_count = s->octet_count; s->first_packet = 0; } @@ -642,7 +642,7 @@ static int rtp_write_trailer(AVFormatContext *s1) /* If the caller closes and recreates ->pb, this might actually * be NULL here even if it was successfully allocated at the start. */ if (s1->pb && (s->flags & FF_RTP_FLAG_SEND_BYE)) - rtcp_send_sr(s1, ff_ntp_time(), 1); + rtcp_send_sr(s1, ff_ntp_time(av_gettime()), 1); av_freep(&s->buf); return 0; diff --git a/libavformat/rtpenc.h b/libavformat/rtpenc.h index 62dc9ab10a..e67ce665f1 100644 --- a/libavformat/rtpenc.h +++ b/libavformat/rtpenc.h @@ -21,6 +21,7 @@ #ifndef AVFORMAT_RTPENC_H #define AVFORMAT_RTPENC_H +#include "libavutil/time.h" #include "avformat.h" #include "rtp.h" diff --git a/libavformat/utils.c b/libavformat/utils.c index b472762dd1..17a262dfc4 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4686,9 +4686,9 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) } } -uint64_t ff_ntp_time(void) +uint64_t ff_ntp_time(int64_t timestamp) { - return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; + return (timestamp / 1000) * 1000 + NTP_OFFSET_US; } uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)