From patchwork Thu Oct 17 18:59:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 15824 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 6B8BA44A238 for ; Thu, 17 Oct 2019 22:00:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4172268AB3E; Thu, 17 Oct 2019 22:00:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 907F668AB17 for ; Thu, 17 Oct 2019 22:00:10 +0300 (EEST) Received: by mail-qt1-f196.google.com with SMTP id n17so5187564qtr.4 for ; Thu, 17 Oct 2019 12:00:10 -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=nEv3D9YSP+4kgBQj36yaiG1ke0LPGSB4dq60hIn0scs=; b=V6ULWYyWnMw0jxlZDvbMn5Zo/W2/jFw+tvlcC15nYohMpooTIZVWfixh8LoueLprkR Nc8ngFlzw6CgEwnMQs5MyZIN/2OlJAK/CiNjZ/pgodLWeOaKWvfqq0nVhld7P/dPmWaG grT34jKAxLCqFgnOEjGEElFCVd/db/qk259UjTja7d6I8lQ4VEbZoilMEemCWIYm/XKy aWmzIWl6Rs0EKyI6ijrr9/kZl9lkSL9acXuvYogcx1hnC3vpo8CtCwk9fvhLk9zR4VDu QJ0n1/W9UWqvj7w5k7jHVl/BT3KpbJuQow34CtQnkQiTF5Btwp3qq4A3O0S27i6BXX7B wVHQ== 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=nEv3D9YSP+4kgBQj36yaiG1ke0LPGSB4dq60hIn0scs=; b=HnGSsUw0BmMV576pE4xy6NxVp9fGtDAicOYGTiQeofXrNLgraAx1V7Ez4bm9S0Jc0p 6xrQV2FLJHm4F5W6aGXulaHgyxN+NpvVsODrDM5udM8Lnr4AQsZdFpXGbpO8fJ+RZThO CKywxdtn7Ndi/k9XIcQNcEGx4vzFzu/Z6rfSo/y/SCdR0DBHOw+7ceFNUrXpQimiYu8J zOYCggYXTVBq2eNXLz8AFaAR3M7z3W1KEh0cmw4++I/bR6aQUh7vusVTvEnW1q6g7+7W wu+GVhJLpEwUnGMQVU/Nx/cgehjbOrJ9ira6JdjQAV7ofTLIasjUZyUErthJEOVtmw9Y wsyw== X-Gm-Message-State: APjAAAU0gO+he9s88i31jtAZka3ljAJ5prXNf9m5jBunv1rUJI9Dhx41 7GLKRcOWk5wHWdjVNAm4mSlvvN9X X-Google-Smtp-Source: APXvYqwUSUNv7cDie6ayJuNNBumEDji68PPT4ynicmKARFeAuSN8dR+17I4YbfWQxze790PZdP9xYw== X-Received: by 2002:a0c:e70c:: with SMTP id d12mr5376061qvn.114.1571338809121; Thu, 17 Oct 2019 12:00:09 -0700 (PDT) Received: from localhost.localdomain ([191.83.221.234]) by smtp.gmail.com with ESMTPSA id v141sm798933qka.59.2019.10.17.12.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 12:00:08 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Oct 2019 15:59:12 -0300 Message-Id: <20191017185916.2957-8-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 07/11] 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 67c35cc3e1..9266e00e2f 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -245,7 +245,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 715bec1c2f..ec9890a7cd 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -4626,7 +4626,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 60f0229adc..9dbc7b850d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4682,9 +4682,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)