Skip to content

webrtc: Add Sound volume and mute controls support#2213

Draft
thjnk wants to merge 1 commit intogoogle:mainfrom
thjnk:main
Draft

webrtc: Add Sound volume and mute controls support#2213
thjnk wants to merge 1 commit intogoogle:mainfrom
thjnk:main

Conversation

@thjnk
Copy link
Contributor

@thjnk thjnk commented Mar 3, 2026

This change implements volume and mute controls for the WebRTC audio backend in Cuttlefish. These controls allow the guest to dynamically adjust playback and capture audio levels via Virtio Sound control messages.

  • AudioMixer: Apply playback volume scaling during audio stream resampling by modifying the channel mix map.
  • Implement read/write logic for Virtio audio volume/mute control commands.
  • Guest Config: Allow enabling of Virtio Sound controls per stream.

@jemoreira jemoreira self-requested a review March 3, 2026 19:02
@thjnk thjnk force-pushed the main branch 2 times, most recently from 5da5ae4 to 3400ea9 Compare March 4, 2026 13:51
This change implements volume and mute controls for the WebRTC audio
backend in Cuttlefish. These controls allow the guest to dynamically
adjust playback and capture audio levels via Virtio Sound control messages.

- AudioMixer: Apply playback volume scaling during audio stream
  resampling by modifying the channel mix map.
- Implement read/write logic for Virtio audio volume/mute control commands.
- Guest Config: Allow enabling of Virtio Sound controls per stream.
@jemoreira
Copy link
Member

The three bullet points in the PR description sound like they should be different commits. That would make the PR much easier to review.

#include <strings.h>
#include <unistd.h>

#include <cstdint>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please include <stdint.h> instead

{SampleRate::Audio_SampleRate_RATE_64000, 64000},
};

static const auto parse_stream_settings =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this could be a regular function in an anonymous namespace instead of a lambda. Any reason to make it a lambda?

if (is_muted_by_control) {
memset(rx_buffer, 0, bytes_read);
} else if (volume < 1.){
static const auto apply_volume = [](auto* data, size_t size, float volume) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a template function instead of a lambda, and you could avoid some repetition by accepting the size in bytes as parameter and dividing by the size of the template parameter. Something like this:

template<typename T>
void apply_volume(T* data, size_bytes, float volume) {
  for (T& val: std::span(data, size_bytes / sizeof(T))) {
    val *= volume;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants