paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Macros | Enumerations | Functions | Variables
para.h File Reference

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)
 Exec the given command. 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...
 

Detailed Description

global paraslash definitions

Macro Definition Documentation

◆ MAXLINE

#define MAXLINE   255

used in various contexts

◆ PARA_MIN

#define PARA_MIN (   x,
 
)
Value:
({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })

Compute the minimum of x and y.

◆ PARA_MAX

#define PARA_MAX (   x,
 
)
Value:
({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 < _max2 ? _max2 : _max1; })

Compute the maximum of x and y.

◆ PARA_ABS

#define PARA_ABS (   x)
Value:
({ \
typeof(x) _x = (x); \
_x > 0? _x : -_x; })

Compute the absolute value of x.

◆ DEFINE_STDERR_LOGGER

#define DEFINE_STDERR_LOGGER (   funcname,
  loglevel_barrier 
)
Value:
static __printf_2_3 void funcname(int ll, const char* fmt,...) \
{ \
va_list argp; \
if (ll < loglevel_barrier) \
return; \
va_start(argp, fmt); \
vfprintf(stderr, fmt, argp); \
va_end(argp); \
}

Define a standard log function that always writes to stderr.

Parameters
funcnameThe name of the function to be defined.
loglevel_barrierIf the loglevel of the current message is less than that, the message is going to be ignored.

◆ INIT_STDERR_LOGGING

#define INIT_STDERR_LOGGING (   loglevel_barrier)
Value:
DEFINE_STDERR_LOGGER(stderr_log, loglevel_barrier); \
__printf_2_3 void (*para_log)(int, const char*, ...) = stderr_log;

Define the standard log function and activate it.

Parameters
loglevel_barrierSee DEFINE_STDERR_LOGGER.

◆ AUTH_REQUEST_MSG

#define AUTH_REQUEST_MSG   "auth rsa "

Sent by para_client to initiate the authentication procedure.

◆ ROUND_UP

#define ROUND_UP (   x,
 
)
Value:
({ \
const typeof(y) _divisor = y; \
((x) + _divisor - 1) / _divisor * _divisor; })

Round up x to next multiple of y.

◆ ROUND_DOWN

#define ROUND_DOWN (   x,
 
)
Value:
({ \
const typeof(y) _divisor = y; \
(x) / _divisor * _divisor; })

Round down x to multiple of y.

◆ DIV_ROUND_UP

#define DIV_ROUND_UP (   x,
 
)
Value:
({ \
typeof(y) _divisor = y; \
((x) + _divisor - 1) / _divisor; })

Divide and round up to next integer.

◆ EXPR_BUILD_ASSERT

#define EXPR_BUILD_ASSERT (   cond)    (sizeof(char [1 - 2 * !(cond)]) - 1)

Assert a build-time dependency, as an expression.

Parameters
condThe 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.

◆ _array_size_chk

#define _array_size_chk (   arr)
Value:
!__builtin_types_compatible_p(typeof(arr), typeof(&(arr)[0])))

&a[0] degrades to a pointer: a different type from an array

◆ ARRAY_SIZE

#define ARRAY_SIZE (   arr)    (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr))

Get the size of an array.

◆ para_isspace

#define para_isspace (   c)    isspace((int)(unsigned char)(c))

Wrapper for isspace.

NetBSD needs this.

◆ FEC_EOF_PACKET

#define FEC_EOF_PACKET
Value:
"\xec\x0d\xcc\xfe\0\0\0\0" \
"\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0"

Data that indicates an eof-condition for a fec-encoded stream.

◆ FEC_EOF_PACKET_LEN

#define FEC_EOF_PACKET_LEN   32

The number of bytes of the FEC_EOF_PACKET.

◆ EMBRACE

#define EMBRACE (   ...)    { __VA_ARGS__}

Used to avoid a shortcoming in vim's syntax highlighting.

◆ do_nothing

#define do_nothing   do {/* nothing */} while (0)

A nice cup of STFU for Mr gcc.

◆ SAMPLE_FORMATS

#define SAMPLE_FORMATS
Value:
SAMPLE_FORMAT(SF_S8, "8 bit signed"), \
SAMPLE_FORMAT(SF_U8, "8 bit unsigned"), \
SAMPLE_FORMAT(SF_S16_LE, "16 bit signed, little endian"), \
SAMPLE_FORMAT(SF_S16_BE, "16 bit signed, big endian"), \
SAMPLE_FORMAT(SF_U16_LE, "16 bit unsigned, little endian"), \
SAMPLE_FORMAT(SF_U16_BE, "16 bit unsigned, big endian"), \

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.

◆ PARA_DEBUG_LOG

#define PARA_DEBUG_LOG (   f,
  ... 
)    para_log(LL_DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)

◆ PARA_INFO_LOG

#define PARA_INFO_LOG (   f,
  ... 
)    para_log(LL_INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)

◆ PARA_NOTICE_LOG

#define PARA_NOTICE_LOG (   f,
  ... 
)    para_log(LL_NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)

◆ PARA_WARNING_LOG

#define PARA_WARNING_LOG (   f,
  ... 
)    para_log(LL_WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__)

◆ PARA_ERROR_LOG

#define PARA_ERROR_LOG (   f,
  ... 
)    para_log(LL_ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)

◆ PARA_CRIT_LOG

#define PARA_CRIT_LOG (   f,
  ... 
)    para_log(LL_CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)

◆ PARA_EMERG_LOG

#define PARA_EMERG_LOG (   f,
  ... 
)    para_log(LL_EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)

◆ FOR_EACH_STATUS_ITEM

#define FOR_EACH_STATUS_ITEM (   i)    for (i = 0; i < NUM_STAT_ITEMS; i++)

Loop over each status item.

Enumeration Type Documentation

◆ loglevels

enum loglevels

sample_format

Debug, Info, etc.

Enumerator
LOGLEVELS 
NUM_LOGLEVELS 

Function Documentation

◆ para_exec_cmdline_pid()

int para_exec_cmdline_pid ( pid_t *  pid,
const char *  cmdline,
int *  fds 
)

Exec the given command.

Parameters
pidWill hold the pid of the created process upon return.
cmdlineHolds the command and its arguments, separated by spaces.
fdsA pointer to a value-result array.

This function uses fork/exec to create a new process. fds must be a pointer to three integers, corresponding to stdin, stdout and stderr respectively. It specifies how to deal with fd 0, 1, 2 in the child. The contents of fds are interpreted as follows:

 - fd[i] < 0: leave fd \a i alone.
 - fd[i] = 0: dup fd \a i to \p /dev/null.
 - fd[i] > 0: create a pipe and dup i to one end of that pipe.
 Upon return, fd[i] contains the file descriptor of the pipe.

    In any case, all unneeded file descriptors are closed.
Returns
Standard.

References create_argv().

◆ 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().

◆ 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().

◆ 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().

◆ 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().

◆ 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().

◆ para_random()

_static_inline_ long int para_random ( unsigned  max)

Return a random non-negative integer in an interval.

Parameters
maxDetermines maximal possible return value.
Returns
An integer between zero and max - 1, inclusively.

◆ iov_valid()

_static_inline_ bool iov_valid ( const struct iovec *  iov)

Simple sanity check for I/O vectors.

Parameters
iovPointer to the I/O vector to check.
Returns
True if iov points to a non-empty buffer.

Referenced by sb_get_send_buffers().

◆ for_each_stat_item()

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.

Parameters
item_bufThe source buffer.
num_bytesThe length of buf.
item_handlerFunction to call for each complete item.
Returns
Negative on errors, the number of bytes not passed to item_handler on success.

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().

Variable Documentation

◆ para_log

__printf_2_3 void(* para_log) (int, const char *,...)
extern

The log function of para_gui, always set to curses_log().

◆ status_item_list

const char* status_item_list[]
extern

status items

status items

Referenced by afh_get_afhi_txt().

DEFINE_STDERR_LOGGER
#define DEFINE_STDERR_LOGGER(funcname, loglevel_barrier)
Define a standard log function that always writes to stderr.
Definition: para.h:59
para_log
__printf_2_3 void(* para_log)(int, const char *,...)
The log function of para_gui, always set to curses_log().
Definition: afh.c:28
EXPR_BUILD_ASSERT
#define EXPR_BUILD_ASSERT(cond)
Assert a build-time dependency, as an expression.
Definition: para.h:152