Skip to content

Add MixingAudioDeviceModule and loopback mixing transport#28

Open
paterkleomenis wants to merge 1 commit intodesktop-app:masterfrom
paterkleomenis:mixing-audio-loopback
Open

Add MixingAudioDeviceModule and loopback mixing transport#28
paterkleomenis wants to merge 1 commit intodesktop-app:masterfrom
paterkleomenis:mixing-audio-loopback

Conversation

@paterkleomenis
Copy link
Contributor

Introduces infrastructure to mix system-audio loopback into the outgoing microphone stream during a call, on both Linux and Windows.

New types (in webrtc_create_adm.cpp, anonymous namespace):

LoopbackCollector
Thread-safe mono ring buffer (max 2 s at 48 kHz). Loopback capture
threads call pushSamples(); MixingAudioTransport calls readAndMix()
to saturating-add loopback audio into the mic frame.

DirectLoopbackCapture (Linux only, guarded by WEBRTC_LINUX)
Background std::thread that opens the PulseAudio monitor source via
alcCaptureOpenDevice (stereo preferred, mono fallback), feeds decoded
frames into LoopbackCollector, and stops cleanly on destruction.
findMonitorDevice() prefers the monitor that matches the current
default playback sink.

MixingAudioTransport
webrtc::AudioTransport decorator. When mixing is enabled it copies the
mic buffer, calls LoopbackCollector::readAndMix, then forwards the
blended frame to the inner transport. Disabled path is zero-overhead.

MixingAudioDeviceModule (details namespace)
webrtc::AudioDeviceModule wrapper. Installs MixingAudioTransport in
RegisterAudioCallback(), starts/stops DirectLoopbackCapture (Linux) or
a dedicated loopback ADM + LoopbackAdmTransport (Windows) when
setLoopbackEnabled() is toggled via MixingAudioControl.

New public API (webrtc_create_adm.h):

MixingAudioControl
Shared handle that survives ADM recreation. setLoopbackEnabled() /
loopbackEnabled() let callers toggle mixing at any time; the control
re-applies pending state whenever a new MixingAudioDeviceModule
attaches itself.

MixingAudioDeviceModuleCreator(innerCreator, control)
Returns a creator lambda that wraps any ADM (e.g. the OpenAL ADM)
inside a MixingAudioDeviceModule.

Introduces infrastructure to mix system-audio loopback into the outgoing
microphone stream during a call, on both Linux and Windows.

New types (in webrtc_create_adm.cpp, anonymous namespace):

  LoopbackCollector
    Thread-safe mono ring buffer (max 2 s at 48 kHz). Loopback capture
    threads call pushSamples(); MixingAudioTransport calls readAndMix()
    to saturating-add loopback audio into the mic frame.

  DirectLoopbackCapture  (Linux only, guarded by WEBRTC_LINUX)
    Background std::thread that opens the PulseAudio monitor source via
    alcCaptureOpenDevice (stereo preferred, mono fallback), feeds decoded
    frames into LoopbackCollector, and stops cleanly on destruction.
    findMonitorDevice() prefers the monitor that matches the current
    default playback sink.

  MixingAudioTransport
    webrtc::AudioTransport decorator. When mixing is enabled it copies the
    mic buffer, calls LoopbackCollector::readAndMix, then forwards the
    blended frame to the inner transport. Disabled path is zero-overhead.

  MixingAudioDeviceModule  (details namespace)
    webrtc::AudioDeviceModule wrapper. Installs MixingAudioTransport in
    RegisterAudioCallback(), starts/stops DirectLoopbackCapture (Linux) or
    a dedicated loopback ADM + LoopbackAdmTransport (Windows) when
    setLoopbackEnabled() is toggled via MixingAudioControl.

New public API (webrtc_create_adm.h):

  MixingAudioControl
    Shared handle that survives ADM recreation. setLoopbackEnabled() /
    loopbackEnabled() let callers toggle mixing at any time; the control
    re-applies pending state whenever a new MixingAudioDeviceModule
    attaches itself.

  MixingAudioDeviceModuleCreator(innerCreator, control)
    Returns a creator lambda that wraps any ADM (e.g. the OpenAL ADM)
    inside a MixingAudioDeviceModule.
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.

1 participant