gmerlin
|
Communication inside and between applications. More...
Modules | |
Macros | |
#define | BG_MSG_NONE -1 |
Reserved ID for non valid message. More... | |
#define | BG_MSG_MAX_ARGS 4 |
Maximum number of args. More... | |
Typedefs | |
typedef struct bg_msg_s | bg_msg_t |
Opaque message type, you don't want to know what's inside. More... | |
typedef int(* | bg_msg_read_callback_t )(void *priv, uint8_t *data, int len) |
Callback for bg_msg_read. More... | |
typedef int(* | bg_msg_write_callback_t )(void *priv, const uint8_t *data, int len) |
Callback for bg_msg_write. More... | |
Functions | |
bg_msg_t * | bg_msg_create () |
Create a message. More... | |
void | bg_msg_destroy (bg_msg_t *msg) |
Destroy a message. More... | |
void | bg_msg_free (bg_msg_t *msg) |
Free internal memory of the message. More... | |
void | bg_msg_set_id (bg_msg_t *msg, int id) |
Set the ID of a message. More... | |
int | bg_msg_get_id (bg_msg_t *msg) |
Get the ID of a message. More... | |
void | bg_msg_set_arg_int (bg_msg_t *msg, int arg, int value) |
Set an integer argument. More... | |
int | bg_msg_get_arg_int (bg_msg_t *msg, int arg) |
Get an integer argument. More... | |
void | bg_msg_set_arg_time (bg_msg_t *msg, int arg, gavl_time_t value) |
Set a time argument. More... | |
gavl_time_t | bg_msg_get_arg_time (bg_msg_t *msg, int arg) |
Get a time argument. More... | |
void | bg_msg_set_arg_string (bg_msg_t *msg, int arg, const char *value) |
Set a string argument. More... | |
char * | bg_msg_get_arg_string (bg_msg_t *msg, int arg) |
Get a string argument. More... | |
void | bg_msg_set_arg_float (bg_msg_t *msg, int arg, double value) |
Set a float argument. More... | |
double | bg_msg_get_arg_float (bg_msg_t *msg, int arg) |
Get a float argument. More... | |
void | bg_msg_set_arg_color_rgb (bg_msg_t *msg, int arg, const float *value) |
Set an RGB color argument. More... | |
void | bg_msg_get_arg_color_rgb (bg_msg_t *msg, int arg, float *value) |
Get an RGB color argument. More... | |
void | bg_msg_set_arg_color_rgba (bg_msg_t *msg, int arg, const float *value) |
Set an RGBA color argument. More... | |
void | bg_msg_get_arg_color_rgba (bg_msg_t *msg, int arg, float *value) |
Get an RGBA color argument. More... | |
void | bg_msg_set_arg_position (bg_msg_t *msg, int arg, const double *value) |
Set a position argument. More... | |
void | bg_msg_get_arg_position (bg_msg_t *msg, int arg, double *value) |
Get a position argument. More... | |
void * | bg_msg_set_arg_ptr (bg_msg_t *msg, int arg, int len) |
Set a binary data argument. More... | |
void * | bg_msg_get_arg_ptr (bg_msg_t *msg, int arg, int *len) |
Set a binary data argument. More... | |
void | bg_msg_set_arg_ptr_nocopy (bg_msg_t *msg, int arg, void *ptr) |
Set a pointer argument without copying data. More... | |
void * | bg_msg_get_arg_ptr_nocopy (bg_msg_t *msg, int arg) |
Get a pointer argument without copying data. More... | |
void | bg_msg_set_arg_audio_format (bg_msg_t *msg, int arg, const gavl_audio_format_t *format) |
Set an audio format argument. More... | |
void | bg_msg_get_arg_audio_format (bg_msg_t *msg, int arg, gavl_audio_format_t *format, int *big_endian) |
Get an audio format argument. More... | |
void | bg_msg_set_arg_video_format (bg_msg_t *msg, int arg, const gavl_video_format_t *format) |
Set a video format argument. More... | |
void | bg_msg_get_arg_video_format (bg_msg_t *msg, int arg, gavl_video_format_t *format, int *big_endian) |
Get a video format argument. More... | |
void | bg_msg_set_arg_metadata (bg_msg_t *msg, int arg, const gavl_metadata_t *m) |
Set a matadata argument. More... | |
void | bg_msg_get_arg_metadata (bg_msg_t *msg, int arg, gavl_metadata_t *m) |
Get a matadata argument. More... | |
int | bg_msg_read (bg_msg_t *ret, bg_msg_read_callback_t cb, void *cb_data) |
Read a message using a callback. More... | |
int | bg_msg_write (bg_msg_t *msg, bg_msg_write_callback_t cb, void *cb_data) |
Write a message using a callback. More... | |
int | bg_msg_read_socket (bg_msg_t *ret, int fd, int milliseconds) |
Read a message from a socket. More... | |
int | bg_msg_write_socket (bg_msg_t *msg, int fd) |
Write a message to a socket. More... | |
int | bg_msg_write_audio_frame (bg_msg_t *msg, const gavl_audio_format_t *format, const gavl_audio_frame_t *frame, bg_msg_write_callback_t cb, void *cb_data) |
Write an audio frame. More... | |
int | bg_msg_read_audio_frame (gavl_dsp_context_t *ctx, bg_msg_t *msg, const gavl_audio_format_t *format, gavl_audio_frame_t *frame, bg_msg_read_callback_t cb, void *cb_data, int big_endian) |
Read an audio frame. More... | |
void | bg_msg_set_parameter (bg_msg_t *msg, const char *name, bg_parameter_type_t type, const bg_parameter_value_t *val) |
Set a parameter. More... | |
void | bg_msg_get_parameter (bg_msg_t *msg, char **name, bg_parameter_type_t *type, bg_parameter_value_t *val) |
Get a parameter. More... | |
Communication inside and between applications.
Gmerlin messages are a universal method to do communication between processes or threads. Each message consists of an integer ID and a number of arguments. Arguments can be strings, numbers or complex types like gavl_audio_format_t. For inter-thread comminucation, you can pass pointers as arguments as well.
For multithread applications, there are message queues (bg_msg_queue_t). They are thread save FIFO structures, which allow asynchronous communication between threads.
For communication via sockets, there are the ultra-simple functions bg_msg_read_socket and bg_msg_write_socket, which can be used to build network protocols (e.g. remote control of applications)
#define BG_MSG_NONE -1 |
Reserved ID for non valid message.
#define BG_MSG_MAX_ARGS 4 |
Maximum number of args.
typedef struct bg_msg_s bg_msg_t |
Opaque message type, you don't want to know what's inside.
typedef int(* bg_msg_read_callback_t)(void *priv, uint8_t *data, int len) |
Callback for bg_msg_read.
priv | The private data you passed to bg_msg_read |
data | A buffer |
len | Number of bytes to read |
typedef int(* bg_msg_write_callback_t)(void *priv, const uint8_t *data, int len) |
Callback for bg_msg_write.
priv | The private data you passed to bg_msg_write |
data | A buffer |
len | Number of bytes to write |
bg_msg_t* bg_msg_create | ( | ) |
Create a message.
void bg_msg_destroy | ( | bg_msg_t * | msg | ) |
Destroy a message.
msg | A message |
void bg_msg_free | ( | bg_msg_t * | msg | ) |
Free internal memory of the message.
msg | A message |
Use this, if you want to reuse the message with a different ID or args
void bg_msg_set_id | ( | bg_msg_t * | msg, |
int | id | ||
) |
Set the ID of a message.
msg | A message |
id | The ID |
int bg_msg_get_id | ( | bg_msg_t * | msg | ) |
Get the ID of a message.
msg | A message |
void bg_msg_set_arg_int | ( | bg_msg_t * | msg, |
int | arg, | ||
int | value | ||
) |
Set an integer argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
int bg_msg_get_arg_int | ( | bg_msg_t * | msg, |
int | arg | ||
) |
Get an integer argument.
msg | A message |
arg | Argument index (starting with 0) |
void bg_msg_set_arg_time | ( | bg_msg_t * | msg, |
int | arg, | ||
gavl_time_t | value | ||
) |
Set a time argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
gavl_time_t bg_msg_get_arg_time | ( | bg_msg_t * | msg, |
int | arg | ||
) |
Get a time argument.
msg | A message |
arg | Argument index (starting with 0) |
void bg_msg_set_arg_string | ( | bg_msg_t * | msg, |
int | arg, | ||
const char * | value | ||
) |
Set a string argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
char* bg_msg_get_arg_string | ( | bg_msg_t * | msg, |
int | arg | ||
) |
Get a string argument.
msg | A message |
arg | Argument index (starting with 0) |
You can get the string value only once from each arg and must free() it, when you are done with it
void bg_msg_set_arg_float | ( | bg_msg_t * | msg, |
int | arg, | ||
double | value | ||
) |
Set a float argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
double bg_msg_get_arg_float | ( | bg_msg_t * | msg, |
int | arg | ||
) |
Get a float argument.
msg | A message |
arg | Argument index (starting with 0) |
void bg_msg_set_arg_color_rgb | ( | bg_msg_t * | msg, |
int | arg, | ||
const float * | value | ||
) |
Set an RGB color argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
void bg_msg_get_arg_color_rgb | ( | bg_msg_t * | msg, |
int | arg, | ||
float * | value | ||
) |
Get an RGB color argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
void bg_msg_set_arg_color_rgba | ( | bg_msg_t * | msg, |
int | arg, | ||
const float * | value | ||
) |
Set an RGBA color argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
void bg_msg_get_arg_color_rgba | ( | bg_msg_t * | msg, |
int | arg, | ||
float * | value | ||
) |
Get an RGBA color argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
void bg_msg_set_arg_position | ( | bg_msg_t * | msg, |
int | arg, | ||
const double * | value | ||
) |
Set a position argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
void bg_msg_get_arg_position | ( | bg_msg_t * | msg, |
int | arg, | ||
double * | value | ||
) |
Get a position argument.
msg | A message |
arg | Argument index (starting with 0) |
value | Value |
void* bg_msg_set_arg_ptr | ( | bg_msg_t * | msg, |
int | arg, | ||
int | len | ||
) |
Set a binary data argument.
msg | A message |
arg | Argument index (starting with 0) |
len | Number of bytes requested |
void* bg_msg_get_arg_ptr | ( | bg_msg_t * | msg, |
int | arg, | ||
int * | len | ||
) |
Set a binary data argument.
msg | A message |
arg | Argument index (starting with 0) |
len | Returns the number of bytes |
You can get the buffer only once from each arg and must free() it, when you are done with it
void bg_msg_set_arg_ptr_nocopy | ( | bg_msg_t * | msg, |
int | arg, | ||
void * | ptr | ||
) |
Set a pointer argument without copying data.
msg | A message |
arg | Argument index (starting with 0) |
ptr | A pointer |
Use this only for communication inside the same address space
void* bg_msg_get_arg_ptr_nocopy | ( | bg_msg_t * | msg, |
int | arg | ||
) |
Get a pointer argument without copying data.
msg | A message |
arg | Argument index (starting with 0) |
Use this only for communication inside the same address space
void bg_msg_set_arg_audio_format | ( | bg_msg_t * | msg, |
int | arg, | ||
const gavl_audio_format_t * | format | ||
) |
Set an audio format argument.
msg | A message |
arg | Argument index (starting with 0) |
format | An audio format |
void bg_msg_get_arg_audio_format | ( | bg_msg_t * | msg, |
int | arg, | ||
gavl_audio_format_t * | format, | ||
int * | big_endian | ||
) |
Get an audio format argument.
msg | A message |
arg | Argument index (starting with 0) |
format | Returns the audio format |
big_endian | If non-null, returns 1 if multibyte numbers are in big endian |
void bg_msg_set_arg_video_format | ( | bg_msg_t * | msg, |
int | arg, | ||
const gavl_video_format_t * | format | ||
) |
Set a video format argument.
msg | A message |
arg | Argument index (starting with 0) |
format | A video format |
void bg_msg_get_arg_video_format | ( | bg_msg_t * | msg, |
int | arg, | ||
gavl_video_format_t * | format, | ||
int * | big_endian | ||
) |
Get a video format argument.
msg | A message |
arg | Argument index (starting with 0) |
format | Returns the video format |
big_endian | If non-null, returns 1 if multibyte numbers are in big endian |
void bg_msg_set_arg_metadata | ( | bg_msg_t * | msg, |
int | arg, | ||
const gavl_metadata_t * | m | ||
) |
Set a matadata argument.
msg | A message |
arg | Argument index (starting with 0) |
m | Metadata |
void bg_msg_get_arg_metadata | ( | bg_msg_t * | msg, |
int | arg, | ||
gavl_metadata_t * | m | ||
) |
Get a matadata argument.
msg | A message |
arg | Argument index (starting with 0) |
m | Returns metadata |
Don't pass uninitalized memory as metadata.
int bg_msg_read | ( | bg_msg_t * | ret, |
bg_msg_read_callback_t | cb, | ||
void * | cb_data | ||
) |
Read a message using a callback.
ret | Where the message will be copied |
cb | read callback |
cb_data | data to pass to the callback |
int bg_msg_write | ( | bg_msg_t * | msg, |
bg_msg_write_callback_t | cb, | ||
void * | cb_data | ||
) |
Write a message using a callback.
msg | A message |
cb | write callback |
cb_data | data to pass to the callback |
int bg_msg_read_socket | ( | bg_msg_t * | ret, |
int | fd, | ||
int | milliseconds | ||
) |
Read a message from a socket.
ret | Where the message will be copied |
fd | A socket |
milliseconds | Read timeout |
int bg_msg_write_socket | ( | bg_msg_t * | msg, |
int | fd | ||
) |
Write a message to a socket.
msg | Message |
fd | A socket |
int bg_msg_write_audio_frame | ( | bg_msg_t * | msg, |
const gavl_audio_format_t * | format, | ||
const gavl_audio_frame_t * | frame, | ||
bg_msg_write_callback_t | cb, | ||
void * | cb_data | ||
) |
Write an audio frame.
msg | Message to use for communication |
format | An audio format |
frame | An audio frame |
cb | Callback |
cb_data | Data to pass to callback |
Note, that the format must be transferred separately
int bg_msg_read_audio_frame | ( | gavl_dsp_context_t * | ctx, |
bg_msg_t * | msg, | ||
const gavl_audio_format_t * | format, | ||
gavl_audio_frame_t * | frame, | ||
bg_msg_read_callback_t | cb, | ||
void * | cb_data, | ||
int | big_endian | ||
) |
Read an audio frame.
ctx | A gavl dsp context |
msg | Message containing the frame header |
format | Audio format |
frame | An audio frame |
cb | Callback |
cb_data | Data to pass to callback |
big_endian | 1 if data should be sent in big endian format |
Before you can use this function, msg must contain a valid audio frame header. The DSP context is needed to convert the endianess if necessary.
void bg_msg_set_parameter | ( | bg_msg_t * | msg, |
const char * | name, | ||
bg_parameter_type_t | type, | ||
const bg_parameter_value_t * | val | ||
) |
Set a parameter.
msg | A message |
type | Type of the parameter |
name | Name of the parameter |
val | Value for the parameter |
void bg_msg_get_parameter | ( | bg_msg_t * | msg, |
char ** | name, | ||
bg_parameter_type_t * | type, | ||
bg_parameter_value_t * | val | ||
) |
Get a parameter.
msg | A message |
type | Type of the parameter |
name | Name of the parameter |
val | Value for the parameter |
Name and val must be freef if no longer used