From f374b319e0db494f83468cf21b3bef1b19c838e7 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Sun, 13 Jun 2021 15:29:53 +0200 Subject: [PATCH] RtpSource: Convert internals partially to std::chrono This allows us to remove the tvNow() helper method. --- src/zm_rtp_source.cpp | 13 +++++-------- src/zm_rtp_source.h | 3 ++- src/zm_time.h | 6 ------ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/zm_rtp_source.cpp b/src/zm_rtp_source.cpp index 0d9330f8e..1862c1886 100644 --- a/src/zm_rtp_source.cpp +++ b/src/zm_rtp_source.cpp @@ -66,7 +66,7 @@ RtpSource::RtpSource( mRtpFactor = mRtpClock; - mBaseTimeReal = tvNow(); + mBaseTimeReal = std::chrono::system_clock::now(); mBaseTimeNtp = {}; mBaseTimeRtp = rtpTime; @@ -159,12 +159,9 @@ bool RtpSource::updateSeq(uint16_t seq) { } void RtpSource::updateJitter( const RtpDataHeader *header ) { - if ( mRtpFactor > 0 ) { - timeval now = {}; - gettimeofday(&now, nullptr); - - FPSeconds time_diff = - zm::chrono::duration_cast(now) - zm::chrono::duration_cast(mBaseTimeReal); + if (mRtpFactor > 0) { + SystemTimePoint now = std::chrono::system_clock::now(); + FPSeconds time_diff = std::chrono::duration_cast(now - mBaseTimeReal); uint32_t localTimeRtp = mBaseTimeRtp + static_cast(time_diff.count() * mRtpFactor); uint32_t packetTransit = localTimeRtp - ntohl(header->timestampN); @@ -202,7 +199,7 @@ void RtpSource::updateRtcpData( Debug(5, "ntpTime: %ld.%06ld, rtpTime: %x", ntpTime.tv_sec, ntpTime.tv_usec, rtpTime); if ( mBaseTimeNtp.tv_sec == 0 ) { - mBaseTimeReal = tvNow(); + mBaseTimeReal = std::chrono::system_clock::now(); mBaseTimeNtp = ntpTime; mBaseTimeRtp = rtpTime; } else if ( !mRtpClock ) { diff --git a/src/zm_rtp_source.h b/src/zm_rtp_source.h index 3736f71cb..a39e8225f 100644 --- a/src/zm_rtp_source.h +++ b/src/zm_rtp_source.h @@ -24,6 +24,7 @@ #include "zm_config.h" #include "zm_define.h" #include "zm_ffmpeg.h" +#include "zm_time.h" #include #include #include @@ -68,7 +69,7 @@ private: // Time keys uint32_t mRtpClock; uint32_t mRtpFactor; - struct timeval mBaseTimeReal; + SystemTimePoint mBaseTimeReal; struct timeval mBaseTimeNtp; uint32_t mBaseTimeRtp; diff --git a/src/zm_time.h b/src/zm_time.h index 0df20345a..f7574bbf7 100644 --- a/src/zm_time.h +++ b/src/zm_time.h @@ -23,12 +23,6 @@ #include #include -inline struct timeval tvNow() { - timeval t = {}; - gettimeofday(&t, nullptr); - return t; -} - typedef std::chrono::microseconds Microseconds; typedef std::chrono::milliseconds Milliseconds; typedef std::chrono::seconds Seconds;