Paraslash Audio Streaming | |
About News Download Documentation Development |
global paraslash definitions More...
#include "config.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include <inttypes.h>
#include <sys/uio.h>
#include <poll.h>
#include "gcc-compat.h"
Macros | |
#define | MAXLINE 255 |
used in various contexts More... | |
#define | PARA_MIN(x, y) |
Compute the minimum of x and y. More... | |
#define | PARA_MAX(x, y) |
Compute the maximum of x and y. More... | |
#define | PARA_ABS(x) |
Compute the absolute value of x. More... | |
#define | DEFINE_STDERR_LOGGER(funcname, loglevel_barrier) |
Define a standard log function that always writes to stderr. More... | |
#define | INIT_STDERR_LOGGING(loglevel_barrier) |
Define the standard log function and activate it. More... | |
#define | AUTH_REQUEST_MSG "auth rsa " |
Sent by para_client to initiate the authentication procedure. More... | |
#define | ROUND_UP(x, y) |
Round up x to next multiple of y. More... | |
#define | ROUND_DOWN(x, y) |
Round down x to multiple of y. More... | |
#define | DIV_ROUND_UP(x, y) |
Divide and round up to next integer. More... | |
#define | EXPR_BUILD_ASSERT(cond) (sizeof(char [1 - 2 * !(cond)]) - 1) |
Assert a build-time dependency, as an expression. More... | |
#define | _array_size_chk(arr) |
&a[0] degrades to a pointer: a different type from an array More... | |
#define | ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) |
Get the size of an array. More... | |
#define | para_isspace(c) isspace((int)(unsigned char)(c)) |
Wrapper for isspace. More... | |
#define | FEC_EOF_PACKET |
Data that indicates an eof-condition for a fec-encoded stream. More... | |
#define | FEC_EOF_PACKET_LEN 32 |
The number of bytes of the FEC_EOF_PACKET. More... | |
#define | EMBRACE(...) { __VA_ARGS__} |
Used to avoid a shortcoming in vim's syntax highlighting. More... | |
#define | do_nothing do {/* nothing */} while (0) |
A nice cup of STFU for Mr gcc. More... | |
#define | SAMPLE_FORMATS |
The sample formats supported by paraslash. More... | |
#define | PARA_DEBUG_LOG(f, ...) para_log(LL_DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define | PARA_INFO_LOG(f, ...) para_log(LL_INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define | PARA_NOTICE_LOG(f, ...) para_log(LL_NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define | PARA_WARNING_LOG(f, ...) para_log(LL_WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define | PARA_ERROR_LOG(f, ...) para_log(LL_ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define | PARA_CRIT_LOG(f, ...) para_log(LL_CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define | PARA_EMERG_LOG(f, ...) para_log(LL_EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define | FOR_EACH_STATUS_ITEM(i) for (i = 0; i < NUM_STAT_ITEMS; i++) |
Loop over each status item. More... | |
Enumerations | |
enum | loglevels { LOGLEVELS, NUM_LOGLEVELS } |
sample_format More... | |
Functions | |
int | para_exec_cmdline_pid (pid_t *pid, const char *cmdline, int *fds) |
Execute a file as a background process, honoring $PATH. More... | |
int | tv_diff (const struct timeval *b, const struct timeval *a, struct timeval *diff) |
Compute the difference of two time values. More... | |
long unsigned | tv2ms (const struct timeval *tv) |
Convert struct timeval to milliseconds. 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 | ms2tv (long unsigned n, struct timeval *tv) |
Convert milliseconds to a struct timeval. 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... | |
_static_inline_ long int | para_random (unsigned max) |
Return a random non-negative integer in an interval. More... | |
_static_inline_ bool | iov_valid (const struct iovec *iov) |
Simple sanity check for I/O vectors. More... | |
int | for_each_stat_item (char *item_buf, size_t num_bytes, int(*item_handler)(int, char *)) |
Call a function for each complete status item of a buffer. More... | |
Variables | |
__printf_2_3 void(* | para_log )(int, const char *,...) |
The log function of para_gui, always set to curses_log(). More... | |
const char * | status_item_list [] |
status items More... | |
global paraslash definitions
#define MAXLINE 255 |
used in various contexts
#define PARA_MIN | ( | x, | |
y | |||
) |
Compute the minimum of x and y.
#define PARA_MAX | ( | x, | |
y | |||
) |
Compute the maximum of x and y.
#define PARA_ABS | ( | x | ) |
Compute the absolute value of x.
#define DEFINE_STDERR_LOGGER | ( | funcname, | |
loglevel_barrier | |||
) |
Define a standard log function that always writes to stderr.
funcname | The name of the function to be defined. |
loglevel_barrier | If the loglevel of the current message is less than that, the message is going to be ignored. |
#define INIT_STDERR_LOGGING | ( | loglevel_barrier | ) |
Define the standard log function and activate it.
loglevel_barrier | See DEFINE_STDERR_LOGGER. |
#define AUTH_REQUEST_MSG "auth rsa " |
Sent by para_client to initiate the authentication procedure.
#define ROUND_UP | ( | x, | |
y | |||
) |
Round up x to next multiple of y.
#define ROUND_DOWN | ( | x, | |
y | |||
) |
Round down x to multiple of y.
#define DIV_ROUND_UP | ( | x, | |
y | |||
) |
Divide and round up to next integer.
#define EXPR_BUILD_ASSERT | ( | cond | ) | (sizeof(char [1 - 2 * !(cond)]) - 1) |
Assert a build-time dependency, as an expression.
cond | The compile-time condition which must be true. |
Compilation will fail if the condition isn't true, or can't be evaluated by the compiler. This can be used in an expression: its value is "0".
Taken from ccan.
#define _array_size_chk | ( | arr | ) |
&a[0] degrades to a pointer: a different type from an array
#define ARRAY_SIZE | ( | arr | ) | (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) |
Get the size of an array.
#define para_isspace | ( | c | ) | isspace((int)(unsigned char)(c)) |
Wrapper for isspace.
NetBSD needs this.
#define FEC_EOF_PACKET |
Data that indicates an eof-condition for a fec-encoded stream.
#define FEC_EOF_PACKET_LEN 32 |
The number of bytes of the FEC_EOF_PACKET.
#define EMBRACE | ( | ... | ) | { __VA_ARGS__} |
Used to avoid a shortcoming in vim's syntax highlighting.
#define do_nothing do {/* nothing */} while (0) |
A nice cup of STFU for Mr gcc.
#define SAMPLE_FORMATS |
The sample formats supported by paraslash.
It may be determined by one of the following sources:
1. The decoding filter (para_audiod only). In this case, it is always \p SF_S16_LE which is the canonical format used within decoders. 2. The wav header (para_write only). 3. The --sample-format option of para_write.
#define PARA_DEBUG_LOG | ( | f, | |
... | |||
) | para_log(LL_DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define PARA_INFO_LOG | ( | f, | |
... | |||
) | para_log(LL_INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define PARA_NOTICE_LOG | ( | f, | |
... | |||
) | para_log(LL_NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define PARA_WARNING_LOG | ( | f, | |
... | |||
) | para_log(LL_WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define PARA_ERROR_LOG | ( | f, | |
... | |||
) | para_log(LL_ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define PARA_CRIT_LOG | ( | f, | |
... | |||
) | para_log(LL_CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define PARA_EMERG_LOG | ( | f, | |
... | |||
) | para_log(LL_EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__) |
#define FOR_EACH_STATUS_ITEM | ( | i | ) | for (i = 0; i < NUM_STAT_ITEMS; i++) |
Loop over each status item.
enum loglevels |
int para_exec_cmdline_pid | ( | pid_t * | pid, |
const char * | cmdline, | ||
int * | fds | ||
) |
Execute a file as a background process, honoring $PATH.
pid | Contains the PID of the child process on return. |
cmdline | Path to the file to execute, followed by arguments. |
fds | A pointer to a value-result array. |
This function first splits the command line argument by calling create_argv(), then calls fork(2) to create a new process. The parent returns without waiting for the child to terminate. The child calls execvp(2) to replace itself with the process image that corresponds to the first word of the given command line.
The fd pointer must point to an array of three integers. Initially, the integers specify how to deal with fd 0, 1, 2 in the child:
- < 0: Leave fd alone. - == 0: Dup fd to /dev/null. - > 0: Create a pipe and dup to one end of that pipe.
In the third case, the corresponding integer in the fd array is set to the file descriptor of the pipe that has been created. In any case, all unneeded file descriptors are closed.
References create_argv().
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().
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 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 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().
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().
_static_inline_ long int para_random | ( | unsigned | max | ) |
Return a random non-negative integer in an interval.
max | Determines maximal possible return value. |
max
- 1, inclusively. _static_inline_ bool iov_valid | ( | const struct iovec * | iov | ) |
Simple sanity check for I/O vectors.
iov | Pointer to the I/O vector to check. |
Referenced by sb_get_send_buffers().
int for_each_stat_item | ( | char * | item_buf, |
size_t | num_bytes, | ||
int(*)(int, char *) | item_handler | ||
) |
Call a function for each complete status item of a buffer.
item_buf | The source buffer. |
num_bytes | The length of buf. |
item_handler | Function to call for each complete item. |
Status items are expected in the format used by parser-friendly output mode of the stat command of para_client/para_audioc.
References MIN_STAT_ITEM_LEN, PARA_WARNING_LOG, and read_size_header().
|
extern |
The log function of para_gui, always set to curses_log().
|
extern |