gmerlin
msgqueue.h
1 /*****************************************************************
2  * gmerlin - a general purpose multimedia framework and applications
3  *
4  * Copyright (c) 2001 - 2012 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 
279 void bg_msg_get_arg_audio_format(bg_msg_t * msg, int arg,
280  gavl_audio_format_t * format);
281 
282 
289 void bg_msg_set_arg_video_format(bg_msg_t * msg, int arg,
290  const gavl_video_format_t * format);
291 
298 void bg_msg_get_arg_video_format(bg_msg_t * msg, int arg,
299  gavl_video_format_t * format);
300 
301 
308 void bg_msg_set_arg_metadata(bg_msg_t * msg, int arg,
309  const gavl_metadata_t * m);
310 
319 void bg_msg_get_arg_metadata(bg_msg_t * msg, int arg,
320  gavl_metadata_t * m);
321 
322 /*
323  * This on will be used for remote controls,
324  * return FALSE on error
325  */
326 
334 int bg_msg_read(bg_msg_t * ret, bg_msg_read_callback_t cb, void * cb_data);
335 
343 int bg_msg_write(bg_msg_t * msg, bg_msg_write_callback_t cb, void * cb_data);
344 
345 
353 int bg_msg_read_socket(bg_msg_t * ret, int fd, int milliseconds);
354 
361 int bg_msg_write_socket(bg_msg_t * msg, int fd);
362 
363 /*
364  * Read/Write audio frame over sockets
365  */
366 
379  const gavl_audio_format_t * format,
380  const gavl_audio_frame_t * frame,
381  bg_msg_write_callback_t cb, void * cb_data);
382 
399  bg_msg_t * msg,
400  const gavl_audio_format_t * format,
401  const gavl_metadata_t * m,
402  gavl_audio_frame_t * frame,
404  void * cb_data);
405 
413 void bg_msg_set_parameter(bg_msg_t * msg,
414  const char * name,
415  bg_parameter_type_t type,
416  const bg_parameter_value_t * val);
417 
418 
428 void bg_msg_get_parameter(bg_msg_t * msg,
429  char ** name,
430  bg_parameter_type_t * type,
431  bg_parameter_value_t * val);
432 
433 
446 typedef struct bg_msg_queue_s bg_msg_queue_t;
447 
453 
459 
460 /*
461  * Lock message queue for reading, block until something arrives,
462  * return the message ID
463  */
464 
477 
488 
496 
505 
513 
520 int bg_msg_queue_peek(bg_msg_queue_t * mq, uint32_t * id);
521 
537 typedef struct bg_msg_queue_list_s bg_msg_queue_list_t;
538 
544 
550 
557 void
559  void (*set_message)(bg_msg_t * message,
560  const void * data),
561  const void * data);
562 
569  bg_msg_queue_t * queue);
570 
577  bg_msg_queue_t * queue);
578 
582 #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_audio_format(bg_msg_t *msg, int arg, gavl_audio_format_t *format)
Get an audio format argument.
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_get_arg_video_format(bg_msg_t *msg, int arg, gavl_video_format_t *format)
Get a video format argument.
int bg_msg_read_audio_frame(gavl_dsp_context_t **ctx, bg_msg_t *msg, const gavl_audio_format_t *format, const gavl_metadata_t *m, gavl_audio_frame_t *frame, bg_msg_read_callback_t cb, void *cb_data)
Read an audio frame.
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:537
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_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_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_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:446
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