gmerlin
msgqueue.h
1 /*****************************************************************
2  * gmerlin - a general purpose multimedia framework and applications
3  *
4  * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5  * gmerlin-general@lists.sourceforge.net
6  * http://gmerlin.sourceforge.net
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  * *****************************************************************/
21 
22 #ifndef __BG_MSGQUEUE_H_
23 #define __BG_MSGQUEUE_H_
24 
25 #include <gavl/gavl.h>
26 #include <gavl/gavldsp.h>
27 #include <gmerlin/streaminfo.h>
28 
29 
48 #define BG_MSG_NONE -1
49 #define BG_MSG_MAX_ARGS 4
50 
51 
54 typedef struct bg_msg_s bg_msg_t;
55 
63 typedef int (*bg_msg_read_callback_t)(void * priv, uint8_t * data, int len);
64 
72 typedef int (*bg_msg_write_callback_t)(void * priv, const uint8_t * data, int len);
73 
79 
84 void bg_msg_destroy(bg_msg_t * msg);
85 
93 void bg_msg_free(bg_msg_t * msg);
94 
95 /* Functions for messages */
96 
102 void bg_msg_set_id(bg_msg_t * msg, int id);
103 
109 int bg_msg_get_id(bg_msg_t * msg);
110 
111 
118 void bg_msg_set_arg_int(bg_msg_t * msg, int arg, int value);
119 
126 int bg_msg_get_arg_int(bg_msg_t * msg, int arg);
127 
134 void bg_msg_set_arg_time(bg_msg_t * msg, int arg, gavl_time_t value);
135 
143 
150 void bg_msg_set_arg_string(bg_msg_t * msg, int arg, const char * value);
151 
161 char * bg_msg_get_arg_string(bg_msg_t * msg, int arg);
162 
163 
169 void bg_msg_set_arg_float(bg_msg_t * msg, int arg, double value);
170 
177 double bg_msg_get_arg_float(bg_msg_t * msg, int arg);
178 
184 void bg_msg_set_arg_color_rgb(bg_msg_t * msg, int arg, const float * value);
185 
191 void bg_msg_get_arg_color_rgb(bg_msg_t * msg, int arg, float * value);
192 
193 
199 void bg_msg_set_arg_color_rgba(bg_msg_t * msg, int arg, const float * value);
200 
206 void bg_msg_get_arg_color_rgba(bg_msg_t * msg, int arg, float * value);
207 
213 void bg_msg_set_arg_position(bg_msg_t * msg, int arg, const double * value);
214 
215 
221 void bg_msg_get_arg_position(bg_msg_t * msg, int arg, double * value);
222 
229 void * bg_msg_set_arg_ptr(bg_msg_t * msg, int arg, int len);
230 
241 void * bg_msg_get_arg_ptr(bg_msg_t * msg, int arg, int * len);
242 
251 void bg_msg_set_arg_ptr_nocopy(bg_msg_t * msg, int arg, void * ptr);
252 
261 void * bg_msg_get_arg_ptr_nocopy(bg_msg_t * msg, int arg);
262 
263 
270 void bg_msg_set_arg_audio_format(bg_msg_t * msg, int arg,
271  const gavl_audio_format_t * format);
272 
280 void bg_msg_get_arg_audio_format(bg_msg_t * msg, int arg,
281  gavl_audio_format_t * format, int * big_endian);
282 
283 
290 void bg_msg_set_arg_video_format(bg_msg_t * msg, int arg,
291  const gavl_video_format_t * format);
292 
300 void bg_msg_get_arg_video_format(bg_msg_t * msg, int arg,
301  gavl_video_format_t * format, int * big_endian);
302 
303 
310 void bg_msg_set_arg_metadata(bg_msg_t * msg, int arg,
311  const gavl_metadata_t * m);
312 
321 void bg_msg_get_arg_metadata(bg_msg_t * msg, int arg,
322  gavl_metadata_t * m);
323 
324 /*
325  * This on will be used for remote controls,
326  * return FALSE on error
327  */
328 
336 int bg_msg_read(bg_msg_t * ret, bg_msg_read_callback_t cb, void * cb_data);
337 
345 int bg_msg_write(bg_msg_t * msg, bg_msg_write_callback_t cb, void * cb_data);
346 
347 
355 int bg_msg_read_socket(bg_msg_t * ret, int fd, int milliseconds);
356 
363 int bg_msg_write_socket(bg_msg_t * msg, int fd);
364 
365 /*
366  * Read/Write audio frame over sockets
367  */
368 
381  const gavl_audio_format_t * format,
382  const gavl_audio_frame_t * frame,
383  bg_msg_write_callback_t cb, void * cb_data);
384 
401  bg_msg_t * msg,
402  const gavl_audio_format_t * format,
403  gavl_audio_frame_t * frame,
405  void * cb_data, int big_endian);
406 
414 void bg_msg_set_parameter(bg_msg_t * msg,
415  const char * name,
416  bg_parameter_type_t type,
417  const bg_parameter_value_t * val);
418 
419 
429 void bg_msg_get_parameter(bg_msg_t * msg,
430  char ** name,
431  bg_parameter_type_t * type,
432  bg_parameter_value_t * val);
433 
434 
447 typedef struct bg_msg_queue_s bg_msg_queue_t;
448 
454 
460 
461 /*
462  * Lock message queue for reading, block until something arrives,
463  * return the message ID
464  */
465 
478 
489 
497 
506 
514 
521 int bg_msg_queue_peek(bg_msg_queue_t * mq, uint32_t * id);
522 
538 typedef struct bg_msg_queue_list_s bg_msg_queue_list_t;
539 
545 
551 
558 void
560  void (*set_message)(bg_msg_t * message,
561  const void * data),
562  const void * data);
563 
570  bg_msg_queue_t * queue);
571 
578  bg_msg_queue_t * queue);
579 
583 #endif /* __BG_MSGQUEUE_H_ */
bg_msg_t * bg_msg_create()
Create a message.
bg_msg_queue_list_t * bg_msg_queue_list_create()
Create a message queue list.
void bg_msg_get_arg_metadata(bg_msg_t *msg, int arg, gavl_metadata_t *m)
Get a matadata argument.
void bg_msg_get_arg_color_rgb(bg_msg_t *msg, int arg, float *value)
Get an RGB color argument.
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.
void bg_msg_queue_unlock_read(bg_msg_queue_t *mq)
Unlock a message queue for reading.
void bg_msg_destroy(bg_msg_t *msg)
Destroy a message.
void bg_msg_queue_list_destroy(bg_msg_queue_list_t *list)
Destroy a message queue list.
struct gavl_dsp_context_s gavl_dsp_context_t
void bg_msg_get_arg_position(bg_msg_t *msg, int arg, double *value)
Get a position argument.
void bg_msg_queue_list_add(bg_msg_queue_list_t *list, bg_msg_queue_t *queue)
Add a queue to the list.
void bg_msg_set_id(bg_msg_t *msg, int id)
Set the ID of a message.
struct bg_msg_queue_list_s bg_msg_queue_list_t
Opaque message queue list type. You don't want to know what's inside.
Definition: msgqueue.h:538
void bg_msg_set_arg_int(bg_msg_t *msg, int arg, int value)
Set an integer argument.
double bg_msg_get_arg_float(bg_msg_t *msg, int arg)
Get a float argument.
void bg_msg_set_arg_string(bg_msg_t *msg, int arg, const char *value)
Set a string argument.
void bg_msg_set_arg_ptr_nocopy(bg_msg_t *msg, int arg, void *ptr)
Set a pointer argument without copying data.
bg_msg_t * bg_msg_queue_lock_write(bg_msg_queue_t *mq)
Lock a message queue for writing.
void bg_msg_set_arg_time(bg_msg_t *msg, int arg, gavl_time_t value)
Set a time argument.
bg_msg_t * bg_msg_queue_try_lock_read(bg_msg_queue_t *mq)
Try to lock a message queue for reading.
void bg_msg_set_arg_color_rgba(bg_msg_t *msg, int arg, const float *value)
Set an RGBA color argument.
void bg_msg_set_arg_position(bg_msg_t *msg, int arg, const double *value)
Set a position argument.
int(* bg_msg_write_callback_t)(void *priv, const uint8_t *data, int len)
Callback for bg_msg_write.
Definition: msgqueue.h:72
void bg_msg_set_arg_metadata(bg_msg_t *msg, int arg, const gavl_metadata_t *m)
Set a matadata argument.
int bg_msg_read_socket(bg_msg_t *ret, int fd, int milliseconds)
Read a message from a socket.
void bg_msg_queue_unlock_write(bg_msg_queue_t *mq)
Unlock a message queue for writing.
int bg_msg_queue_peek(bg_msg_queue_t *mq, uint32_t *id)
Check, if there is a message for readinbg available and get the ID.
void * bg_msg_get_arg_ptr_nocopy(bg_msg_t *msg, int arg)
Get a pointer argument without copying data.
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.
void bg_msg_free(bg_msg_t *msg)
Free internal memory of the message.
void bg_msg_set_arg_audio_format(bg_msg_t *msg, int arg, const gavl_audio_format_t *format)
Set an audio format argument.
void bg_msg_get_parameter(bg_msg_t *msg, char **name, bg_parameter_type_t *type, bg_parameter_value_t *val)
Get a parameter.
char * bg_msg_get_arg_string(bg_msg_t *msg, int arg)
Get a string argument.
int bg_msg_get_arg_int(bg_msg_t *msg, int arg)
Get an integer argument.
void bg_msg_set_arg_video_format(bg_msg_t *msg, int arg, const gavl_video_format_t *format)
Set a video format argument.
int bg_msg_read(bg_msg_t *ret, bg_msg_read_callback_t cb, void *cb_data)
Read a message using a callback.
void * bg_msg_set_arg_ptr(bg_msg_t *msg, int arg, int len)
Set a binary data argument.
bg_msg_queue_t * bg_msg_queue_create()
Create a message queue.
int64_t gavl_time_t
struct bg_msg_s bg_msg_t
Opaque message type, you don't want to know what's inside.
Definition: msgqueue.h:54
int bg_msg_get_id(bg_msg_t *msg)
Get the ID of a message.
gavl_time_t bg_msg_get_arg_time(bg_msg_t *msg, int arg)
Get a time argument.
bg_parameter_type_t
Parameter type.
Definition: parameter.h:53
void bg_msg_set_arg_color_rgb(bg_msg_t *msg, int arg, const float *value)
Set an RGB color argument.
void bg_msg_queue_list_remove(bg_msg_queue_list_t *list, bg_msg_queue_t *queue)
Remove a queue from the list.
void bg_msg_get_arg_color_rgba(bg_msg_t *msg, int arg, float *value)
Get an RGBA color argument.
Container for a parameter value.
Definition: parameter.h:82
void * bg_msg_get_arg_ptr(bg_msg_t *msg, int arg, int *len)
Set a binary data argument.
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.
void bg_msg_set_arg_float(bg_msg_t *msg, int arg, double value)
Set a float argument.
int bg_msg_write_socket(bg_msg_t *msg, int fd)
Write a message to a socket.
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.
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.
void bg_msg_queue_destroy(bg_msg_queue_t *mq)
Destroy a message queue.
void bg_msg_queue_list_send(bg_msg_queue_list_t *list, void(*set_message)(bg_msg_t *message, const void *data), const void *data)
Send a message to all queues in the list.
struct bg_msg_queue_s bg_msg_queue_t
Opaque message queue type. You don't want to know what's inside.
Definition: msgqueue.h:447
bg_msg_t * bg_msg_queue_lock_read(bg_msg_queue_t *mq)
Lock a message queue for reading.
int bg_msg_write(bg_msg_t *msg, bg_msg_write_callback_t cb, void *cb_data)
Write a message using a callback.
int(* bg_msg_read_callback_t)(void *priv, uint8_t *data, int len)
Callback for bg_msg_read.
Definition: msgqueue.h:63