Removed msg_change_fec_data, use msg_universal

Removed msg_change_fec_data, use msg_universal instead.

This is a more versatile solution allowing further extensions without
a need to modify the global structure at an expese of worse type control.
As a replacement, a tag starting msg_universal::text is used/suggested.
This commit is contained in:
Martin Pulec
2021-10-05 08:56:03 +02:00
parent 99c3a1c221
commit e90cdeb647
3 changed files with 32 additions and 23 deletions

View File

@@ -499,16 +499,17 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s
send_message(s->root_module, path_audio, (struct message *) msg_audio);
free_response(resp_audio);
} else if(prefix_matches(message, "fec ")) {
struct msg_change_fec_data *msg = (struct msg_change_fec_data *)
new_message(sizeof(struct msg_change_fec_data));
auto *msg = reinterpret_cast<struct msg_universal *>(new_message(sizeof(struct msg_universal)));
char *fec = suffix(message, "fec ");
enum tx_media_type media_type{};
strncpy(msg->text, MSG_UNIVERSAL_TAG_TX "fec ", sizeof(msg->text) - 1);
if(strncasecmp(fec, "audio ", 6) == 0) {
msg->media_type = TX_MEDIA_AUDIO;
strncpy(msg->fec, fec + 6, sizeof(msg->fec) - 1);
media_type = TX_MEDIA_AUDIO;
strncat(msg->text, fec + 6, sizeof(msg->text) - strlen(msg->text) - 1);
} else if(strncasecmp(fec, "video ", 6) == 0) {
msg->media_type = TX_MEDIA_VIDEO;
strncpy(msg->fec, fec + 6, sizeof(msg->fec) - 1);
media_type = TX_MEDIA_VIDEO;
strncat(msg->text, fec + 6, sizeof(msg->text) - strlen(msg->text) - 1);
} else {
resp = new_response(RESPONSE_NOT_FOUND, "unknown media type");
free(msg);
@@ -516,7 +517,7 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s
}
if (msg) {
if(msg->media_type == TX_MEDIA_VIDEO) {
if (media_type == TX_MEDIA_VIDEO) {
enum module_class path_tx[] = { MODULE_CLASS_SENDER, MODULE_CLASS_TX, MODULE_CLASS_NONE };
append_message_path(path, sizeof(path),
path_tx);

View File

@@ -130,12 +130,6 @@ struct msg_receiver {
};
};
struct msg_change_fec_data {
struct message m;
enum tx_media_type media_type;
char fec[128];
};
enum compress_change_type {
CHANGE_COMPRESS,
CHANGE_PARAMS
@@ -153,11 +147,17 @@ struct msg_stats {
int value;
};
/**
* It is suggested to use a tag at the beginning of
* msg_universal::text to identify the receiving module.
*/
struct msg_universal {
struct message m;
char text[8192];
};
#define MSG_UNIVERSAL_TAG_TX "TX_msg "
struct response *new_response(int status, const char *optional_message);
void free_response(struct response *r);
int response_get_status(struct response *r);

View File

@@ -317,19 +317,27 @@ static void fec_check_messages(struct tx *tx)
{
struct message *msg;
while ((msg = check_message(&tx->mod))) {
struct msg_change_fec_data *data = (struct msg_change_fec_data *) msg;
if(tx->media_type != data->media_type) {
fprintf(stderr, "[Transmit] FEC media type mismatch!\n");
free_message(msg, new_response(RESPONSE_BAD_REQUEST, NULL));
auto *data = reinterpret_cast<struct msg_universal *>(msg);
const char *text = data->text;
if (strstr(text, MSG_UNIVERSAL_TAG_TX) != text) {
LOG(LOG_LEVEL_ERROR) << "[Transmit] Unexpected TX message: " << text << "\n";
free_message(msg, new_response(RESPONSE_BAD_REQUEST, "Unexpected message"));
continue;
}
struct response *r;
if (set_fec(tx, data->fec)) {
r = new_response(RESPONSE_OK, NULL);
printf("[Transmit] FEC set to new setting.\n");
text += strlen(MSG_UNIVERSAL_TAG_TX);
struct response *r = nullptr;
if (strstr(text, "fec ") == text) {
text += strlen("fec ");
if (set_fec(tx, text)) {
r = new_response(RESPONSE_OK, nullptr);
LOG(LOG_LEVEL_NOTICE) << "[Transmit] FEC set to new setting: " << text << "\n";
} else {
r = new_response(RESPONSE_INT_SERV_ERR, "cannot set FEC");
LOG(LOG_LEVEL_ERROR) << "[Transmit] Unable to reconfiure FEC to: " << text << "\n";
}
} else {
r = new_response(RESPONSE_INT_SERV_ERR, NULL);
fprintf(stderr, "[Transmit] Unable to reconfigure FEC!\n");
r = new_response(RESPONSE_BAD_REQUEST, "Unknown TX message");
LOG(LOG_LEVEL_ERROR) << "[Transmit] Unknown TX message: " << text << "\n";
}
free_message(msg, r);