Paraslash Audio Streaming | |
About News Download Documentation Development |
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... | |
Helper functions for dealing with time values.
long unsigned tv2ms | ( | const struct timeval * | tv | ) |
Convert struct timeval to milliseconds.
tv | The time value value to convert. |
Referenced by sched_request_timeout(), and vss_init().
void ms2tv | ( | long unsigned | n, |
struct timeval * | tv | ||
) |
Convert milliseconds to a struct timeval.
n | The number of milliseconds. |
tv | Result pointer. |
Referenced by sched_request_timeout_ms(), and vss_init().
int tv_diff | ( | const struct timeval * | b, |
const struct timeval * | a, | ||
struct timeval * | diff | ||
) |
Compute the difference of two time values.
b | Minuend. |
a | Subtrahend. |
diff | Result pointer. |
If diff is not NULL
, it contains the absolute value |b - a| on return.
Referenced by audiod_get_btr_root(), sched_request_barrier(), sched_request_barrier_or_min_delay(), and tv_convex_combination().
void tv_add | ( | const struct timeval * | a, |
const struct timeval * | b, | ||
struct timeval * | sum | ||
) |
Add two time values.
a | First addend. |
b | Second addend. |
sum | Contains the sum a + b on return. |
Referenced by compute_chunk_time(), and tv_convex_combination().
void tv_scale | ( | const unsigned long | mult, |
const struct timeval * | tv, | ||
struct timeval * | result | ||
) |
Compute integer multiple of given struct timeval.
mult | The integer value to multiply with. |
tv | The timevalue to multiply. |
result | Contains mult * tv on return. |
Referenced by compute_chunk_time(), and tv_convex_combination().
void tv_divide | ( | const unsigned long | divisor, |
const struct timeval * | tv, | ||
struct timeval * | result | ||
) |
Compute a fraction of given struct timeval.
divisor | The integer value to divide by. |
tv | The timevalue to divide. |
result | Contains (1 / mult) * tv on return. |
Referenced by 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.
a | The first coefficient. |
tv1 | The first time value. |
b | The second coefficient. |
tv2 | The second time value. |
result | Contains 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.
References PARA_ABS, tv_add(), tv_diff(), tv_divide(), and tv_scale().
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.
chunk_num | The number of the chunk. |
chunk_tv | The duration of one chunk. |
stream_start | When the first chunk was sent. |
result | The time when to send chunk number chunk_num. |
This function computes stream_start + chunk_num * chunk_time.
References tv_add(), and tv_scale().
struct timeval* clock_get_realtime | ( | struct timeval * | tv | ) |
Retrieve the time of the realtime clock.
tv | Where 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.
Referenced by schedule().