control: added commands to (un)mute audio

In addition to already existing "mute", that toggled mutte for the
receiver, [un]mute-{sender,receiver} was added, which mutes or unmutes
the sender or receiver.
This commit is contained in:
Martin Pulec
2023-09-26 10:54:58 +02:00
parent e4bcac7f84
commit 7fc14c3d51
4 changed files with 53 additions and 11 deletions

View File

@@ -624,14 +624,19 @@ static struct response * audio_receiver_process_message(struct state_audio *s, s
}
case RECEIVER_MSG_INCREASE_VOLUME:
case RECEIVER_MSG_DECREASE_VOLUME:
case RECEIVER_MSG_MUTE:
case RECEIVER_MSG_UNMUTE:
case RECEIVER_MSG_MUTE_TOGGLE:
{
if (msg->type == RECEIVER_MSG_MUTE_TOGGLE) {
s->muted_receiver = !s->muted_receiver;
} else if (msg->type == RECEIVER_MSG_INCREASE_VOLUME) {
if (msg->type == RECEIVER_MSG_INCREASE_VOLUME) {
s->volume *= 1.1;
} else {
} else if (msg->type == RECEIVER_MSG_DECREASE_VOLUME) {
s->volume /= 1.1;
} else {
s->muted_receiver =
msg->type == RECEIVER_MSG_MUTE_TOGGLE
? !s->muted_receiver
: msg->type == RECEIVER_MSG_MUTE;
}
double new_volume = s->muted_receiver ? 0.0 : s->volume;
double db = 20.0 * log10(new_volume);
@@ -653,7 +658,7 @@ static struct response * audio_receiver_process_message(struct state_audio *s, s
pdb_iter_done(&it);
break;
}
default:
case RECEIVER_MSG_VIDEO_PROP_CHANGED:
abort();
}
@@ -938,8 +943,13 @@ static struct response *audio_sender_process_message(struct state_audio *s, stru
return new_response(RESPONSE_OK, status);
break;
}
case SENDER_MSG_MUTE:
case SENDER_MSG_UNMUTE:
case SENDER_MSG_MUTE_TOGGLE:
s->muted_sender = !s->muted_sender;
s->muted_sender =
msg->type == SENDER_MSG_MUTE_TOGGLE
? !s->muted_sender
: msg->type == SENDER_MSG_MUTE;
log_msg(LOG_LEVEL_NOTICE, "Audio sender %smuted.\n", s->muted_sender ? "" : "un");
break;
case SENDER_MSG_QUERY_VIDEO_MODE:

View File

@@ -309,11 +309,34 @@ static struct response *
process_audio_message(struct module *root_module, const char *cmd)
{
char path[STR_LEN] = "";
if (strcmp(cmd, "mute") == 0) {
if (strcmp(cmd, "mute") == 0 || strstr(cmd, "-receiver") != nullptr) {
strncpy(path, "audio.receiver", sizeof path);
auto *msg = (struct msg_receiver *) new_message(
sizeof(struct msg_receiver));
msg->type = RECEIVER_MSG_MUTE_TOGGLE;
if (strcmp(cmd, "mute") == 0) {
msg->type = RECEIVER_MSG_MUTE_TOGGLE;
} else if (prefix_matches(cmd, "mute-")) {
msg->type = RECEIVER_MSG_MUTE;
} else if (prefix_matches(cmd, "unmute-")) {
msg->type = RECEIVER_MSG_UNMUTE;
} else {
return new_response(RESPONSE_BAD_REQUEST,
"malformed audio recv mute msg");
}
return send_message(root_module, path, (struct message *) msg);
}
if (strstr(cmd, "-sender") != nullptr) {
strncpy(path, "audio.sender", sizeof path);
auto *msg = (struct msg_sender *) new_message(
sizeof(struct msg_sender));
if (prefix_matches(cmd, "mute-")) {
msg->type = SENDER_MSG_MUTE;
} else if (prefix_matches(cmd, "unmute-")) {
msg->type = SENDER_MSG_UNMUTE;
} else {
return new_response(RESPONSE_BAD_REQUEST,
"malformed audio send mute msg");
}
return send_message(root_module, path, (struct message *) msg);
}
if (prefix_matches(cmd, "volume ")) {
@@ -331,7 +354,7 @@ process_audio_message(struct module *root_module, const char *cmd)
}
return send_message(root_module, path, (struct message *) msg);
}
abort();
return new_response(RESPONSE_BAD_REQUEST, "unexpected audio msg");
}
/**
@@ -584,7 +607,8 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s
resp = send_message(s->root_module, path, (struct message *) msg);
}
} else if (prefix_matches(message, "volume ") ||
strcmp(message, "mute") == 0) {
prefix_matches(message, "mute") ||
prefix_matches(message, "unmute")) {
resp = process_audio_message(s->root_module, message);
} else if (prefix_matches(message, "av-delay ")) {
int val = atoi(suffix(message, "av-delay "));
@@ -997,7 +1021,9 @@ static void print_control_help() {
TBOLD("\tcompress param <new-compress-param>") "\n"
TBOLD("\tvolume {up|down}") u8"¹\n"
TBOLD("\tav-delay <ms>") u8"¹\n"
TBOLD("\tmute") u8"¹ - toggles mute\n"
TBOLD("\tmute") " - toggles receiver mute\n"
TBOLD("\t[un]mute-{receiver,sender}")
" - (un)mutes audio sender or receiver\n"
TBOLD("\tpostprocess <new_postprocess> | flush") "\n"
TBOLD("\tdump-tree")"\n");
color_printf("\nOther commands can be issued directly to individual "

View File

@@ -99,6 +99,8 @@ 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,
@@ -124,6 +126,8 @@ enum msg_receiver_type {
RECEIVER_MSG_GET_AUDIO_STATUS,
RECEIVER_MSG_INCREASE_VOLUME,
RECEIVER_MSG_DECREASE_VOLUME,
RECEIVER_MSG_MUTE,
RECEIVER_MSG_UNMUTE,
RECEIVER_MSG_MUTE_TOGGLE,
};
struct msg_receiver {

View File

@@ -183,6 +183,8 @@ struct response *rtp_video_rxtx::process_sender_message(struct msg_sender *msg)
}
break;
case SENDER_MSG_GET_STATUS:
case SENDER_MSG_MUTE:
case SENDER_MSG_UNMUTE:
case SENDER_MSG_MUTE_TOGGLE:
log_msg(LOG_LEVEL_ERROR, "Unexpected message!\n");
break;