Skip to content

broadcastradio: Add Audio Generator and PCM Stream Server for Virtual Tuner - #3175

Open
abinba wants to merge 1 commit into
google:mainfrom
abinba:feat/virtual-tuner-audio
Open

abinba wants to merge 1 commit into
google:mainfrom
abinba:feat/virtual-tuner-audio

Conversation

@abinba

@abinba abinba commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Introduce the audio emulation pipeline for the Cuttlefish Virtual Tuner:

  • AudioGenerator: Generates 48 kHz, 16-bit stereo PCM audio frames (white noise while tuned/playing, silence while stopped/untuned).
  • PcmStreamServer: Multi-client PCM stream server delivering 48 kHz 16-bit stereo audio frames over a UNIX domain stream socket to Cuttlefish's virtio-snd virtual sound card backend (CrosVM).
  • Unit and integration tests covering audio frame synthesis and socket streaming.

Test: bazel test //cuttlefish/host/commands/virtual_tuner_daemon:...
Bug: 521329213
TAG=agy
CONV=809829e8-ac68-4c32-b9b7-632f61743e47

@chihchiachen
chihchiachen requested review from jemoreira and removed request for Databean September 18, 2026 16:48

@jemoreira jemoreira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please rebase your branch on top of main instead of creating merge commits.

Comment thread base/cvd/cuttlefish/host/commands/virtual_tuner_daemon/pcm_stream_server.h Outdated
Comment thread base/cvd/cuttlefish/host/commands/virtual_tuner_daemon/pcm_stream_server.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/virtual_tuner_daemon/pcm_stream_server.cpp Outdated
}

::unlink(socket_path_.c_str());
server_fd_ = SharedFD::SocketLocalServer(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because of the way cuttlefish spawns processes there is no guarantee that this socket will be created before the client attempts to connect to it. Our way of dealing with this race is to have the parent process run_cvd create the socket and let the child process (this one) inherit it. The actual fd is passed by command line parameter.

There are several examples under host/commands/run_cvd/launch that you can use for guidance.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added the injection of server_fd into the PCM streaming server.

The changes to the run_cvd for injection would be in the subsequent PR to keep this PR minimal.

}

if (server_fd_->IsOpen()) {
server_fd_->Shutdown(SHUT_RDWR);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why Shutdown? Is Close not enough?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We need Shutdown() because accept_thread_ is sleeping inside blocking Fd::Accept() when Stop() is called. If accept_thread_ weren't sleeping inside Accept(), Close() alone would be sufficient.

Comment thread base/cvd/cuttlefish/host/commands/virtual_tuner_daemon/pcm_stream_server.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/virtual_tuner_daemon/pcm_stream_server.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/virtual_tuner_daemon/pcm_stream_server.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/virtual_tuner_daemon/pcm_stream_server.cpp Outdated
namespace virtualtuner {
namespace {

bool ReadExactly(const SharedFD& fd, std::span<uint8_t> buffer) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We already have ReadExact in shared_buf.h

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Calling ReadExact and casting it to char* here.

Introduce the audio emulation pipeline for the Cuttlefish Virtual Tuner:
- AudioGenerator: Generates 48 kHz, 16-bit stereo PCM audio frames
  (white noise while tuned/playing, silence while stopped/untuned).
- PcmStreamServer: Multi-client PCM stream server delivering 48 kHz 16-bit
  stereo audio frames over a UNIX domain stream socket to Cuttlefish's
  virtio-snd virtual sound card backend (CrosVM).
- Unit and integration tests covering audio frame synthesis and socket
  streaming.

Test: bazel test //cuttlefish/host/commands/virtual_tuner_daemon:...
Bug: 521329213
TAG=agy
CONV=809829e8-ac68-4c32-b9b7-632f61743e47
@abinba
abinba force-pushed the feat/virtual-tuner-audio branch from 8f12d88 to bce0d57 Compare September 22, 2026 22:53
@abinba
abinba requested a review from jemoreira September 22, 2026 23:52

This branch has not been deployed

No deployments
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