paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Functions
time.c File Reference

Helper functions for dealing with time values. More...

#include "para.h"

Functions

long unsigned tv2ms (const struct timeval *tv)
 Convert struct timeval to milliseconds. More...
 
void ms2tv (long unsigned n, struct timeval *tv)
 Convert milliseconds to a struct timeval. More...
 
int tv_diff (const struct timeval *b, const struct timeval *a, struct timeval *diff)
 Compute the difference of two time values. More...
 
void tv_add (const struct timeval *a, const struct timeval *b, struct timeval *sum)
 Add two time values. More...
 
void tv_scale (const unsigned long mult, const struct timeval *tv, struct timeval *result)
 Compute integer multiple of given struct timeval. More...
 
void tv_divide (const unsigned long divisor, const struct timeval *tv, struct timeval *result)
 Compute a fraction of given struct timeval. More...
 
int tv_convex_combination (const long a, const struct timeval *tv1, const long b, const struct timeval *tv2, struct timeval *result)
 Compute a convex combination of two time values. More...
 
void compute_chunk_time (long unsigned chunk_num, struct timeval *chunk_tv, struct timeval *stream_start, struct timeval *result)
 Compute when to send a chunk of an audio file. More...
 
struct timeval * clock_get_realtime (struct timeval *tv)
 Retrieve the time of the realtime clock. More...
 

Detailed Description

Helper functions for dealing with time values.

Function Documentation

◆ tv2ms()

long unsigned tv2ms ( const struct timeval *  tv)

Convert struct timeval to milliseconds.

Parameters
tvThe time value value to convert.
Returns
The number of milliseconds in tv.

Referenced by sched_request_timeout(), and vss_init().

◆ ms2tv()

void ms2tv ( long unsigned  n,
struct timeval *  tv 
)

Convert milliseconds to a struct timeval.

Parameters
nThe number of milliseconds.
tvResult pointer.

Referenced by sched_request_timeout_ms(), and vss_init().

◆ tv_diff()

int tv_diff ( const struct timeval *  b,
const struct timeval *  a,
struct timeval *  diff 
)

Compute the difference of two time values.

Parameters
bMinuend.
aSubtrahend.
diffResult pointer.

If diff is not NULL, it contains the absolute value |b - a| on return.

Returns
If b < a, this function returns -1, otherwise it returns 1.

Referenced by audiod_get_btr_root(), sched_request_barrier(), sched_request_barrier_or_min_delay(), and tv_convex_combination().

◆ tv_add()

void tv_add ( const struct timeval *  a,
const struct timeval *  b,
struct timeval *  sum 
)

Add two time values.

Parameters
aFirst addend.
bSecond addend.
sumContains the sum a + b on return.

Referenced by compute_chunk_time(), and tv_convex_combination().

◆ tv_scale()

void tv_scale ( const unsigned long  mult,
const struct timeval *  tv,
struct timeval *  result 
)

Compute integer multiple of given struct timeval.

Parameters
multThe integer value to multiply with.
tvThe timevalue to multiply.
resultContains mult * tv on return.

Referenced by compute_chunk_time(), and tv_convex_combination().

◆ tv_divide()

void tv_divide ( const unsigned long  divisor,
const struct timeval *  tv,
struct timeval *  result 
)

Compute a fraction of given struct timeval.

Parameters
divisorThe integer value to divide by.
tvThe timevalue to divide.
resultContains (1 / mult) * tv on return.

Referenced by tv_convex_combination().

◆ tv_convex_combination()

int tv_convex_combination ( const long  a,
const struct timeval *  tv1,
const long  b,
const struct timeval *  tv2,
struct timeval *  result 
)

Compute a convex combination of two time values.

Parameters
aThe first coefficient.
tv1The first time value.
bThe second coefficient.
tv2The second time value.
resultContains the convex combination upon return.

Compute x := (a * tv1 + b * tv2) / (|a| + |b|) and store |x| in result. Both a and b may be negative.

Returns
Zero, 1 or -1, if x is zero, positive or negative, respectively.

References PARA_ABS, tv_add(), tv_diff(), tv_divide(), and tv_scale().

◆ compute_chunk_time()

void compute_chunk_time ( long unsigned  chunk_num,
struct timeval *  chunk_tv,
struct timeval *  stream_start,
struct timeval *  result 
)

Compute when to send a chunk of an audio file.

Parameters
chunk_numThe number of the chunk.
chunk_tvThe duration of one chunk.
stream_startWhen the first chunk was sent.
resultThe time when to send chunk number chunk_num.

This function computes stream_start + chunk_num * chunk_time.

References tv_add(), and tv_scale().

◆ clock_get_realtime()

struct timeval* clock_get_realtime ( struct timeval *  tv)

Retrieve the time of the realtime clock.

Parameters
tvWhere to store the result.

Gets the current value of the system-wide real-time clock (identified by id CLOCK_REALTIME). If tv is NULL, the value is stored in a static buffer, otherwise it is stored at the location given by tv.

Returns
This function aborts on errors. On success it returns a pointer to memory containing the current time.
See also
clock_gettime(2), gettimeofday(2).

Referenced by schedule().