From 7fc14c3d51a8cee91c7a44ea2cc5cd71349604f8 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 26 Sep 2023 10:54:58 +0200 Subject: [PATCH] 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. --- src/audio/audio.cpp | 22 ++++++++++++++++------ src/control_socket.cpp | 36 +++++++++++++++++++++++++++++++----- src/messaging.h | 4 ++++ src/video_rxtx/rtp.cpp | 2 ++ 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index cf5a80906..399822d18 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -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: diff --git a/src/control_socket.cpp b/src/control_socket.cpp index 600afcf89..89db72bc9 100644 --- a/src/control_socket.cpp +++ b/src/control_socket.cpp @@ -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 ") "\n" TBOLD("\tvolume {up|down}") u8"¹\n" TBOLD("\tav-delay ") 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 | flush") "\n" TBOLD("\tdump-tree")"\n"); color_printf("\nOther commands can be issued directly to individual " diff --git a/src/messaging.h b/src/messaging.h index 60b697b47..296d03460 100644 --- a/src/messaging.h +++ b/src/messaging.h @@ -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 { diff --git a/src/video_rxtx/rtp.cpp b/src/video_rxtx/rtp.cpp index 1c7c6140e..c9c97ed92 100644 --- a/src/video_rxtx/rtp.cpp +++ b/src/video_rxtx/rtp.cpp @@ -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;