SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
qrtplib::RTPTime Class Reference

#include <rtptimeutilities.h>

Public Member Functions

 RTPTime (double t)
 
 RTPTime (RTPNTPTime ntptime)
 
 RTPTime (int64_t seconds, uint32_t microseconds)
 
int64_t GetSeconds () const
 
uint32_t GetMicroSeconds () const
 
double GetDouble () const
 
RTPNTPTime GetNTPTime () const
 
RTPTimeoperator-= (const RTPTime &t)
 
RTPTimeoperator+= (const RTPTime &t)
 
bool operator< (const RTPTime &t) const
 
bool operator> (const RTPTime &t) const
 
bool operator<= (const RTPTime &t) const
 
bool operator>= (const RTPTime &t) const
 
bool IsZero () const
 

Static Public Member Functions

static RTPTime CurrentTime ()
 
static void Wait (const RTPTime &delay)
 

Private Attributes

double m_t
 

Detailed Description

This class is used to specify wallclock time, delay intervals etc. This class is used to specify wallclock time, delay intervals etc. It stores a number of seconds and a number of microseconds.

Definition at line 103 of file rtptimeutilities.h.

Constructor & Destructor Documentation

◆ RTPTime() [1/3]

qrtplib::RTPTime::RTPTime ( double  t)
inline

Creates an RTPTime instance representing t, which is expressed in units of seconds.

Definition at line 162 of file rtptimeutilities.h.

163 {
164  m_t = t;
165 }

◆ RTPTime() [2/3]

qrtplib::RTPTime::RTPTime ( RTPNTPTime  ntptime)
inline

Creates an instance that corresponds to ntptime. Creates an instance that corresponds to ntptime. If the conversion cannot be made, both the seconds and the microseconds are set to zero.

Definition at line 182 of file rtptimeutilities.h.

References qrtplib::RTPNTPTime::GetLSW(), qrtplib::RTPNTPTime::GetMSW(), and RTP_NTPTIMEOFFSET.

183 {
184  if (ntptime.GetMSW() < RTP_NTPTIMEOFFSET)
185  {
186  m_t = 0;
187  }
188  else
189  {
190  uint32_t sec = ntptime.GetMSW() - RTP_NTPTIMEOFFSET;
191 
192  double x = (double) ntptime.GetLSW();
193  x /= (65536.0 * 65536.0);
194  x *= 1000000.0;
195  uint32_t microsec = (uint32_t) x;
196 
197  m_t = (double) sec + 1e-6 * (double) microsec;
198  }
199 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define RTP_NTPTIMEOFFSET
+ Here is the call graph for this function:

◆ RTPTime() [3/3]

qrtplib::RTPTime::RTPTime ( int64_t  seconds,
uint32_t  microseconds 
)
inline

Creates an instance corresponding to seconds and microseconds.

Definition at line 167 of file rtptimeutilities.h.

168 {
169  if (seconds >= 0)
170  {
171  m_t = (double) seconds + 1e-6 * (double) microseconds;
172  }
173  else
174  {
175  int64_t possec = -seconds;
176 
177  m_t = (double) possec + 1e-6 * (double) microseconds;
178  m_t = -m_t;
179  }
180 }
__int64 int64_t
Definition: rtptypes_win.h:47

Member Function Documentation

◆ CurrentTime()

RTPTime qrtplib::RTPTime::CurrentTime ( )
inlinestatic

Returns an RTPTime instance representing the current wallclock time. Returns an RTPTime instance representing the current wallclock time. This is expressed as a number of seconds since 00:00:00 UTC, January 1, 1970.

Definition at line 293 of file rtptimeutilities.h.

References qrtplib::RTPTime_timespecToDouble().

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), qrtplib::RTCPPacketBuilder::BuildNextPacket(), qrtplib::RTPSession::BYEDestroy(), qrtplib::RTCPScheduler::CalculateNextRTCPTime(), GetMicroSeconds(), qrtplib::RTCPScheduler::GetTransmissionDelay(), qrtplib::RTCPScheduler::IsTime(), qrtplib::RTCPScheduler::PerformReverseReconsideration(), qrtplib::RTPPacketBuilder::PrivateBuildPacket(), qrtplib::RTPSession::ProcessPolledData(), qrtplib::RTPUDPTransmitter::readRTCPPendingDatagrams(), qrtplib::RTPUDPTransmitter::readRTPPendingDatagrams(), qrtplib::RTCPScheduler::ScheduleBYEPacket(), and qrtplib::RTPInternalSourceData::SentRTPPacket().

294 {
295  static bool s_initialized = false;
296  static double s_startOffet = 0;
297 
298  if (!s_initialized)
299  {
300  s_initialized = true;
301 
302  // Get the corresponding times in system time and monotonic time
303  struct timespec tpSys, tpMono;
304 
305  clock_gettime(CLOCK_REALTIME, &tpSys);
306  clock_gettime(CLOCK_MONOTONIC, &tpMono);
307 
308  double tSys = RTPTime_timespecToDouble(tpSys);
309  double tMono = RTPTime_timespecToDouble(tpMono);
310 
311  s_startOffet = tSys - tMono;
312  return tSys;
313  }
314 
315  struct timespec tpMono;
316  clock_gettime(CLOCK_MONOTONIC, &tpMono);
317 
318  double tMono0 = RTPTime_timespecToDouble(tpMono);
319  return tMono0 + s_startOffet;
320 }
double RTPTime_timespecToDouble(struct timespec &ts)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetDouble()

double qrtplib::RTPTime::GetDouble ( ) const
inline

◆ GetMicroSeconds()

uint32_t qrtplib::RTPTime::GetMicroSeconds ( ) const
inline

Returns the number of microseconds stored in this instance.

Definition at line 206 of file rtptimeutilities.h.

References C1000000, CEPOCH, CurrentTime(), m_t, and Wait().

207 {
208  uint32_t microsec;
209 
210  if (m_t >= 0)
211  {
212  int64_t sec = (int64_t) m_t;
213  microsec = (uint32_t) (1e6 * (m_t - (double) sec) + 0.5);
214  }
215  else // m_t < 0
216  {
217  int64_t sec = (int64_t) (-m_t);
218  microsec = (uint32_t) (1e6 * ((-m_t) - (double) sec) + 0.5);
219  }
220 
221  if (microsec >= 1000000)
222  return 999999;
223  // Unsigned, it can never be less than 0
224  // if (microsec < 0)
225  // return 0;
226  return microsec;
227 }
__int64 int64_t
Definition: rtptypes_win.h:47
unsigned int uint32_t
Definition: rtptypes_win.h:46
+ Here is the call graph for this function:

◆ GetNTPTime()

RTPNTPTime qrtplib::RTPTime::GetNTPTime ( ) const
inline

Returns the NTP time corresponding to the time stored in this instance.

Definition at line 367 of file rtptimeutilities.h.

References RTP_NTPTIMEOFFSET.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), qrtplib::RTCPPacketBuilder::BuildNextPacket(), and qrtplib::RTPSourceData::INF_GetRoundtripTime().

368 {
369  uint32_t sec = (uint32_t) m_t;
370  uint32_t microsec = (uint32_t) ((m_t - (double) sec) * 1e6);
371 
372  uint32_t msw = sec + RTP_NTPTIMEOFFSET;
373  uint32_t lsw;
374  double x;
375 
376  x = microsec / 1000000.0;
377  x *= (65536.0 * 65536.0);
378  lsw = (uint32_t) x;
379 
380  return RTPNTPTime(msw, lsw);
381 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define RTP_NTPTIMEOFFSET
+ Here is the caller graph for this function:

◆ GetSeconds()

int64_t qrtplib::RTPTime::GetSeconds ( ) const
inline

Returns the number of seconds stored in this instance.

Definition at line 201 of file rtptimeutilities.h.

202 {
203  return (int64_t) m_t;
204 }
__int64 int64_t
Definition: rtptypes_win.h:47

◆ IsZero()

bool qrtplib::RTPTime::IsZero ( ) const
inline

Definition at line 150 of file rtptimeutilities.h.

Referenced by qrtplib::RTPSourceData::INF_GetEstimatedTimestampUnit().

151  {
152  return m_t == 0.0;
153  }
+ Here is the caller graph for this function:

◆ operator+=()

RTPTime & qrtplib::RTPTime::operator+= ( const RTPTime t)
inline

Definition at line 361 of file rtptimeutilities.h.

References m_t.

362 {
363  m_t += t.m_t;
364  return *this;
365 }

◆ operator-=()

RTPTime & qrtplib::RTPTime::operator-= ( const RTPTime t)
inline

Definition at line 355 of file rtptimeutilities.h.

References m_t.

356 {
357  m_t -= t.m_t;
358  return *this;
359 }

◆ operator<()

bool qrtplib::RTPTime::operator< ( const RTPTime t) const
inline

Definition at line 383 of file rtptimeutilities.h.

References m_t.

384 {
385  return m_t < t.m_t;
386 }

◆ operator<=()

bool qrtplib::RTPTime::operator<= ( const RTPTime t) const
inline

Definition at line 393 of file rtptimeutilities.h.

References m_t.

394 {
395  return m_t <= t.m_t;
396 }

◆ operator>()

bool qrtplib::RTPTime::operator> ( const RTPTime t) const
inline

Definition at line 388 of file rtptimeutilities.h.

References m_t.

389 {
390  return m_t > t.m_t;
391 }

◆ operator>=()

bool qrtplib::RTPTime::operator>= ( const RTPTime t) const
inline

Definition at line 398 of file rtptimeutilities.h.

References m_t.

399 {
400  return m_t >= t.m_t;
401 }

◆ Wait()

void qrtplib::RTPTime::Wait ( const RTPTime delay)
inlinestatic

This function waits the amount of time specified in delay.

Definition at line 333 of file rtptimeutilities.h.

References m_t.

Referenced by qrtplib::RTPSession::BYEDestroy(), and GetMicroSeconds().

334 {
335  if (delay.m_t <= 0)
336  return;
337 
338  uint64_t sec = (uint64_t) delay.m_t;
339  uint64_t nanosec = (uint32_t) (1e9 * (delay.m_t - (double) sec));
340 
341  struct timespec req, rem;
342  int ret;
343 
344  req.tv_sec = (time_t) sec;
345  req.tv_nsec = ((long) nanosec);
346  do
347  {
348  ret = nanosleep(&req, &rem);
349  req = rem;
350  } while (ret == -1 && errno == EINTR);
351 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_t

double qrtplib::RTPTime::m_t
private

The documentation for this class was generated from the following file: