UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
messaging.h File Reference
#include <cstring>
#include "types.h"
Include dependency graph for messaging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  message
 
struct  msg_change_compress_data
 
struct  msg_receiver
 
struct  msg_sender
 
struct  msg_stats
 
struct  msg_universal
 

Macros

#define MSG_UNIVERSAL_TAG_TX   "TX_msg "
 
#define RESPONSE_ACCEPTED   202
 
#define RESPONSE_BAD_REQUEST   400
 
#define RESPONSE_INT_SERV_ERR   500
 
#define RESPONSE_NO_CONTENT   204
 
#define RESPONSE_NOT_FOUND   404
 
#define RESPONSE_NOT_IMPL   501
 
#define RESPONSE_OK   200
 
#define RESPONSE_REQ_TIMEOUT   408
 
#define RESPONSE_SUCCESSFUL(code)
 
#define SEND_MESSAGE_FLAG_NO_STORE   (1<<1)
 if receiver doesn't exist, doesn't store it and retur 404 instead
 
#define SEND_MESSAGE_FLAG_QUIET   (1<<0)
 do not print error messages on console (recv not found/queue full)
 

Enumerations

enum  compress_change_type { CHANGE_COMPRESS , CHANGE_PARAMS }
 
enum  msg_receiver_type {
  RECEIVER_MSG_CHANGE_RX_PORT , RECEIVER_MSG_VIDEO_PROP_CHANGED , RECEIVER_MSG_GET_AUDIO_STATUS , RECEIVER_MSG_INCREASE_VOLUME ,
  RECEIVER_MSG_DECREASE_VOLUME , RECEIVER_MSG_MUTE , RECEIVER_MSG_UNMUTE , RECEIVER_MSG_MUTE_TOGGLE
}
 
enum  msg_sender_type {
  SENDER_MSG_CHANGE_RECEIVER , SENDER_MSG_CHANGE_PORT , SENDER_MSG_GET_STATUS , SENDER_MSG_MUTE ,
  SENDER_MSG_UNMUTE , SENDER_MSG_MUTE_TOGGLE , SENDER_MSG_CHANGE_FEC , SENDER_MSG_QUERY_VIDEO_MODE ,
  SENDER_MSG_RESET_SSRC
}
 

Functions

struct message * check_message (struct module *)
 
void free_message (struct message *m, struct response *r)
 
void free_message_for_child (void *m, struct response *r)
 
void free_response (struct response *r)
 
void module_check_undelivered_messages (struct module *)
 Sends message with waiting for response.
 
void module_store_message (struct module *node, struct message *m)
 
struct message * new_message (size_t length) __attribute__((warn_unused_result))
 
struct response * new_response (int status, const char *optional_message)
 
int response_get_status (struct response *r)
 
const char * response_get_text (struct response *r)
 
const char * response_status_to_text (int status)
 
struct response * send_message (struct module *, const char *path, struct message *msg) __attribute__((warn_unused_result))
 Sends message without waiting for response.
 
struct response * send_message_sync (struct module *, const char *path, struct message *msg, int timeout_ms, int flags) __attribute__((warn_unused_result))
 Sends message without waiting for response.
 
struct response * send_message_to_receiver (struct module *, struct message *msg) __attribute__((warn_unused_result))
 

Detailed Description

Macro Definition Documentation

◆ MSG_UNIVERSAL_TAG_TX

#define MSG_UNIVERSAL_TAG_TX   "TX_msg "

Definition at line 160 of file messaging.h.

Referenced by fec_check_messages(), and process_msg().

◆ RESPONSE_ACCEPTED

#define RESPONSE_ACCEPTED   202

◆ RESPONSE_BAD_REQUEST

◆ RESPONSE_INT_SERV_ERR

◆ RESPONSE_NO_CONTENT

#define RESPONSE_NO_CONTENT   204

Definition at line 59 of file messaging.h.

Referenced by rtp_video_rxtx::process_sender_message(), and response_status_to_text().

◆ RESPONSE_NOT_FOUND

◆ RESPONSE_NOT_IMPL

#define RESPONSE_NOT_IMPL   501

Definition at line 64 of file messaging.h.

Referenced by process_messages(), and response_status_to_text().

◆ RESPONSE_OK

◆ RESPONSE_REQ_TIMEOUT

#define RESPONSE_REQ_TIMEOUT   408

Definition at line 62 of file messaging.h.

Referenced by response_status_to_text().

◆ RESPONSE_SUCCESSFUL

#define RESPONSE_SUCCESSFUL ( code)
Value:
((code) >= 200 && (code) < 300)

Definition at line 66 of file messaging.h.

Referenced by AudioDriftFixer::update().

◆ SEND_MESSAGE_FLAG_NO_STORE

#define SEND_MESSAGE_FLAG_NO_STORE   (1<<1)

◆ SEND_MESSAGE_FLAG_QUIET

#define SEND_MESSAGE_FLAG_QUIET   (1<<0)

Enumeration Type Documentation

◆ compress_change_type

Enumerator
CHANGE_COMPRESS 
CHANGE_PARAMS 

Definition at line 128 of file messaging.h.

128 {
131};
@ CHANGE_COMPRESS
Definition messaging.h:129
@ CHANGE_PARAMS
Definition messaging.h:130

◆ msg_receiver_type

Enumerator
RECEIVER_MSG_CHANGE_RX_PORT 
RECEIVER_MSG_VIDEO_PROP_CHANGED 
RECEIVER_MSG_GET_AUDIO_STATUS 
RECEIVER_MSG_INCREASE_VOLUME 
RECEIVER_MSG_DECREASE_VOLUME 
RECEIVER_MSG_MUTE 
RECEIVER_MSG_UNMUTE 
RECEIVER_MSG_MUTE_TOGGLE 

Definition at line 108 of file messaging.h.

108 {
117};
@ RECEIVER_MSG_MUTE_TOGGLE
Definition messaging.h:116
@ RECEIVER_MSG_DECREASE_VOLUME
Definition messaging.h:113
@ RECEIVER_MSG_UNMUTE
Definition messaging.h:115
@ RECEIVER_MSG_CHANGE_RX_PORT
Definition messaging.h:109
@ RECEIVER_MSG_INCREASE_VOLUME
Definition messaging.h:112
@ RECEIVER_MSG_MUTE
Definition messaging.h:114
@ RECEIVER_MSG_GET_AUDIO_STATUS
Definition messaging.h:111
@ RECEIVER_MSG_VIDEO_PROP_CHANGED
Definition messaging.h:110

◆ msg_sender_type

Enumerator
SENDER_MSG_CHANGE_RECEIVER 
SENDER_MSG_CHANGE_PORT 
SENDER_MSG_GET_STATUS 
SENDER_MSG_MUTE 
SENDER_MSG_UNMUTE 
SENDER_MSG_MUTE_TOGGLE 
SENDER_MSG_CHANGE_FEC 
SENDER_MSG_QUERY_VIDEO_MODE 
SENDER_MSG_RESET_SSRC 

Definition at line 83 of file messaging.h.

83 {
93};
@ SENDER_MSG_MUTE_TOGGLE
Definition messaging.h:89
@ SENDER_MSG_RESET_SSRC
Definition messaging.h:92
@ SENDER_MSG_QUERY_VIDEO_MODE
Definition messaging.h:91
@ SENDER_MSG_GET_STATUS
Definition messaging.h:86
@ SENDER_MSG_MUTE
Definition messaging.h:87
@ SENDER_MSG_CHANGE_FEC
Definition messaging.h:90
@ SENDER_MSG_CHANGE_RECEIVER
Definition messaging.h:84
@ SENDER_MSG_UNMUTE
Definition messaging.h:88
@ SENDER_MSG_CHANGE_PORT
Definition messaging.h:85

Function Documentation

◆ check_message()

struct message * check_message ( struct module * mod)

Definition at line 394 of file messaging.cpp.

395{
397
398 if(simple_linked_list_size(mod->msg_queue) > 0) {
399 return (struct message *) simple_linked_list_pop(mod->msg_queue);
400 } else {
401 return NULL;
402 }
403}
int simple_linked_list_size(struct simple_linked_list *l)
Definition list.cpp:93
void * simple_linked_list_pop(struct simple_linked_list *l)
Definition list.cpp:82
class generic_lock_guard< pthread_mutex_t, pthread_mutex_lock, pthread_mutex_unlock > pthread_mutex_guard
Definition lock_guard.h:43
struct simple_linked_list * msg_queue
Definition module.h:122
pthread_mutex_t msg_queue_lock
Definition module.h:121

References module::msg_queue, module::msg_queue_lock, simple_linked_list_pop(), and simple_linked_list_size().

Referenced by audio_decoder_process_message(), audio_done(), audio_receiver_thread(), audio_sender_thread(), capture_filter(), video_rxtx::check_sender_messages(), compress_frame(), decoder_process_message(), display_conference_worker(), display_get_frame(), display_sdl2_run(), display_sdl_run(), fec_check_messages(), filter(), filter(), filter(), Filter_chain::filter(), gl_process_frames(), module_done(), keyboard_control::impl::msg_received(), process_messages(), process_messages(), ultragrid_rtp_video_rxtx::receiver_process_messages(), vidcap_file_process_messages(), vidcap_import_new_message(), vidcap_switcher_grab(), and writer().

Here is the call graph for this function:

◆ free_message()

void free_message ( struct message * msg,
struct response * r )

Frees message

Additionally, it enforces user to pass response to be sent to sender.

Definition at line 318 of file messaging.cpp.

319{
320 if (!msg) {
321 return;
322 }
323
324 if (r) {
325 if (msg->send_response) {
326 msg->send_response(msg->priv_data, r);
327 } else {
328 free_response(r);
329 }
330 }
331
332 if (msg->data_deleter) {
333 msg->data_deleter(msg);
334 }
335
336 if (msg->priv_data) {
337 delete (shared_ptr<struct responder> *) msg->priv_data;
338 }
339
340 free(msg);
341}
void free_response(struct response *r)

References free_response().

Referenced by audio_decoder_process_message(), audio_done(), audio_receiver_thread(), audio_sender_thread(), capture_filter(), video_rxtx::check_sender_messages(), compress_process_message(), decoder_process_message(), display_conference_worker(), display_get_frame(), display_sdl2_run(), display_sdl_run(), fec_check_messages(), filter(), filter(), filter(), Filter_chain::filter(), free_message_for_child(), gl_process_frames(), module_done(), keyboard_control::impl::msg_received(), process_audio_message(), process_messages(), process_messages(), ultragrid_rtp_video_rxtx::receiver_process_messages(), send_message_common(), set_fec(), vidcap_file_process_messages(), vidcap_import_new_message(), vidcap_switcher_grab(), and writer().

Here is the call graph for this function:

◆ free_message_for_child()

void free_message_for_child ( void * m,
struct response * r )

Definition at line 99 of file messaging.cpp.

99 {
100 struct pair_msg_path *mp = (struct pair_msg_path *) m;
101 free_message(mp->msg, r);
102 free(mp);
103
104}
void free_message(struct message *msg, struct response *r)

References free_message().

Referenced by module_done(), and send_message_common().

Here is the call graph for this function:

◆ free_response()

◆ module_check_undelivered_messages()

void module_check_undelivered_messages ( struct module * node)

Sends message with waiting for response.

Stores message to module message box. If new_message callback is present it is called. Otherwise it may take a long time until module reads the message therefore setting timeout_ms is strongly recommended to prevent freeze (unless knowing that module implements synchronnous message processing via module::new_message callback).

If not set otherwise, when receiver doesn't exist, message is stored by nearest existing parent until it starts (this may be disabled with flag SEND_MESSAGE_FLAG_NO_STORE).

Parameters
syncwait for response timeout_ms milliseconds, if false, 202 is immediately returned (or 404 if NO_STORE flag is set and receiver doesn't exist)
timeout_msif sync==true number of ms to wait for response (-1 means infinitely), ignored if sync is false, @params flags bit mask of SEND_MESSAGE_FLAG_NO_STORE and SEND_MESSAGE_FLAG_QUIET

Definition at line 265 of file messaging.cpp.

266{
267 pthread_mutex_guard guard(node->lock);
268
269 for(void *it = simple_linked_list_it_init(node->msg_queue_children); it != NULL; ) {
270 struct pair_msg_path *msg = (struct pair_msg_path *) simple_linked_list_it_next(&it);
271 struct module *receiver = get_matching_child(node, msg->path);
272 if (receiver) {
273 struct response *resp = send_message_to_receiver(receiver, msg->msg);
274 free_response(resp);
276 free(msg);
277 // reinit iterator
279 }
280 }
281}
struct module * get_matching_child(struct module *node, const char *const_path)
Definition module.c:300
void * simple_linked_list_it_next(void **i)
Definition list.cpp:119
bool simple_linked_list_remove(struct simple_linked_list *l, void *item)
Definition list.cpp:144
void * simple_linked_list_it_init(struct simple_linked_list *l)
Definition list.cpp:108
struct response * send_message_to_receiver(struct module *receiver, struct message *msg)
pthread_mutex_t lock
Definition module.h:114
struct simple_linked_list * msg_queue_children
messages for childern that were not delivered
Definition module.h:124

References free_response(), get_matching_child(), module::lock, module::msg_queue_children, send_message_to_receiver(), simple_linked_list_it_init(), simple_linked_list_it_next(), and simple_linked_list_remove().

Referenced by module_register().

Here is the call graph for this function:

◆ module_store_message()

void module_store_message ( struct module * node,
struct message * m )

Definition at line 283 of file messaging.cpp.

284{
287}
void simple_linked_list_append(struct simple_linked_list *l, void *data)
Definition list.cpp:68

References module::msg_queue, module::msg_queue_lock, and simple_linked_list_append().

Here is the call graph for this function:

◆ new_message()

struct message * new_message ( size_t length)

Definition at line 303 of file messaging.cpp.

304{
305 assert(len >= sizeof(struct message));
306
307 struct message *ret = (struct message *)
308 calloc(1, len);
309
310 return ret;
311}
int void size_t * len

References len.

◆ new_response()

◆ response_get_status()

◆ response_get_text()

const char * response_get_text ( struct response * r)

Definition at line 369 of file messaging.cpp.

369 {
370 return r->text;
371}

References response::text.

Referenced by keyboard_control::impl::info(), send_response(), and AudioDriftFixer::update().

◆ response_status_to_text()

const char * response_status_to_text ( int status)

Definition at line 373 of file messaging.cpp.

374{
375 const static unordered_map<int, const char *> mapping = {
376 { RESPONSE_OK, "OK" },
377 { RESPONSE_ACCEPTED, "Accepted" },
378 { RESPONSE_NO_CONTENT, "No Content" },
379 { RESPONSE_BAD_REQUEST, "Bad Request" },
380 { RESPONSE_NOT_FOUND, "Not Found" },
381 { RESPONSE_REQ_TIMEOUT, "Request Timeout" },
382 { RESPONSE_INT_SERV_ERR, "Internal Server Error" },
383 { RESPONSE_NOT_IMPL, "Not Implemented" },
384 };
385
386 auto it = mapping.find(status);
387 if (it != mapping.end()) {
388 return it->second;
389 }
390
391 return NULL;
392}
static const struct codec_param mapping[AC_COUNT]
Definition libavcodec.c:87
#define RESPONSE_NO_CONTENT
Definition messaging.h:59
#define RESPONSE_NOT_IMPL
Definition messaging.h:64
#define RESPONSE_REQ_TIMEOUT
Definition messaging.h:62
#define RESPONSE_OK
Definition messaging.h:57
#define RESPONSE_BAD_REQUEST
Definition messaging.h:60
#define RESPONSE_INT_SERV_ERR
Definition messaging.h:63
#define RESPONSE_ACCEPTED
Definition messaging.h:58
#define RESPONSE_NOT_FOUND
Definition messaging.h:61

References mapping, RESPONSE_ACCEPTED, RESPONSE_BAD_REQUEST, RESPONSE_INT_SERV_ERR, RESPONSE_NO_CONTENT, RESPONSE_NOT_FOUND, RESPONSE_NOT_IMPL, RESPONSE_OK, and RESPONSE_REQ_TIMEOUT.

Referenced by send_response().

◆ send_message()

struct response * send_message ( struct module * root,
const char * const_path,
struct message * msg )

Sends message without waiting for response.

Stores message to module message box. If new_message callback is present it is called. Otherwise it may take a long time until module reads the message therefore setting timeout_ms is strongly recommended to prevent freeze (unless knowing that module implements synchronnous message processing via module::new_message callback).

If not set otherwise, when receiver doesn't exist, message is stored by nearest existing parent until it starts (this may be disabled with flag SEND_MESSAGE_FLAG_NO_STORE).

Parameters
syncwait for response timeout_ms milliseconds, if false, 202 is immediately returned (or 404 if NO_STORE flag is set and receiver doesn't exist)
timeout_msif sync==true number of ms to wait for response (-1 means infinitely), ignored if sync is false, @params flags bit mask of SEND_MESSAGE_FLAG_NO_STORE and SEND_MESSAGE_FLAG_QUIET

Definition at line 249 of file messaging.cpp.

250{
251 return send_message_common(root, const_path, msg, false, 0, 0);
252}
static struct response * send_message_common(struct module *root, const char *const_path, struct message *msg, bool sync, int timeout_ms, int flags)

References send_message_common().

Referenced by BasicRTSPOnlySubsession::deleteStream(), process_audio_message(), process_msg(), keyboard_control::impl::run(), sdp_send_change_address_message(), h264_sdp_video_rxtx::send_frame(), and BasicRTSPOnlySubsession::startStream().

Here is the call graph for this function:

◆ send_message_sync()

struct response * send_message_sync ( struct module * root,
const char * const_path,
struct message * msg,
int timeout_ms,
int flags )

Sends message without waiting for response.

Stores message to module message box. If new_message callback is present it is called. Otherwise it may take a long time until module reads the message therefore setting timeout_ms is strongly recommended to prevent freeze (unless knowing that module implements synchronnous message processing via module::new_message callback).

If not set otherwise, when receiver doesn't exist, message is stored by nearest existing parent until it starts (this may be disabled with flag SEND_MESSAGE_FLAG_NO_STORE).

Parameters
syncwait for response timeout_ms milliseconds, if false, 202 is immediately returned (or 404 if NO_STORE flag is set and receiver doesn't exist)
timeout_msif sync==true number of ms to wait for response (-1 means infinitely), ignored if sync is false, @params flags bit mask of SEND_MESSAGE_FLAG_NO_STORE and SEND_MESSAGE_FLAG_QUIET

Definition at line 257 of file messaging.cpp.

258{
259 return send_message_common(root, const_path, msg, true, timeout_ms, flags);
260}
const char unsigned int flags

References flags, and send_message_common().

Referenced by keyboard_control::impl::exec_external_commands(), keyboard_control::impl::info(), keycontrol_register_key(), keycontrol_send_key(), AudioDriftFixer::update(), and vidcap_switcher_register_keyboard_ctl().

Here is the call graph for this function:

◆ send_message_to_receiver()

struct response * send_message_to_receiver ( struct module * receiver,
struct message * msg )

Definition at line 289 of file messaging.cpp.

290{
291 pthread_mutex_lock(&receiver->msg_queue_lock);
293 pthread_mutex_unlock(&receiver->msg_queue_lock);
294
295 pthread_mutex_guard guard(receiver->lock);
296 if (receiver->new_message) {
297 receiver->new_message(receiver);
298 }
299
300 return new_response(RESPONSE_ACCEPTED, NULL);
301}
struct response * new_response(int status, const char *text)
notify_t new_message
if set, notifies module that new message is in queue, receiver lock is hold during the call
Definition module.h:119

References module::lock, module::msg_queue, module::msg_queue_lock, module::new_message, new_response(), RESPONSE_ACCEPTED, and simple_linked_list_append().

Referenced by compress_process_message(), module_check_undelivered_messages(), reconfigure_decoder(), set_fec(), Participant_manager::tick(), and tx_update().

Here is the call graph for this function: