Skip to content

Linux: add AudioDeviceLoopbackLinux (OpenAL loopback ADM)#22

Merged
john-preston merged 1 commit intodesktop-app:masterfrom
paterkleomenis:linux-share-audio
Feb 27, 2026
Merged

Linux: add AudioDeviceLoopbackLinux (OpenAL loopback ADM)#22
john-preston merged 1 commit intodesktop-app:masterfrom
paterkleomenis:linux-share-audio

Conversation

@paterkleomenis
Copy link
Contributor

@paterkleomenis paterkleomenis commented Feb 13, 2026

Summary

Adds a minimal loopback Audio Device Module for Linux that captures system audio output via the OpenAL Soft capture API, by opening the PulseAudio monitor source exposed as an OpenAL capture device.

This is a focused, single-feature PR. It does not include mixing, mic muting, or playback volume control — those are follow-up PRs.

Changes

New files

  • webrtc/platform/linux/webrtc_loopback_adm_linux.h

  • webrtc/platform/linux/webrtc_loopback_adm_linux.cpp

    Implements AudioDeviceLoopbackLinux (a webrtc::AudioDeviceModule):

    • IsSupported() enumerates ALC_CAPTURE_DEVICE_SPECIFIER to detect whether a PulseAudio monitor source is available.
    • captureLoop() runs on a dedicated std::thread, reads 10 ms stereo-16 chunks via alcCaptureSamples, and delivers them through webrtc::AudioDeviceBuffer to the WebRTC pipeline.
    • Uses the existing desktop-app::external_openal CMake target — no new dependencies.

Modified files

  • webrtc/webrtc_create_adm.cpp / .h

    • CreateLoopbackAudioDeviceModule() now instantiates AudioDeviceLoopbackLinux on Linux (mirrors the existing Windows branch).
    • New LoopbackAudioCaptureSupported() function reports whether loopback capture is available on the current platform.
  • CMakeLists.txt

    • Adds the two new source files.
    • Adds WEBRTC_LINUX compile definition under elseif (LINUX), matching the existing WEBRTC_WIN / WEBRTC_MAC pattern.

Platform

Linux only. Windows and macOS are unaffected.

Follow-up PRs

CMakeLists.txt Outdated

if (LINUX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PIPEWIRE REQUIRED IMPORTED_TARGET libpipewire-0.3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change? I don't see pipewire being used anywhere in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You’re right. This pkg_check_modules(PIPEWIRE ...) in lib_webrtc is not needed.
I added it during local Linux bring-up, but lib_webrtc doesn’t directly use PipeWire symbols.
I’ll drop this and keep PipeWire handling in tg_owt/WebRTC.

@ilya-fedin
Copy link
Contributor

Squash the commits please

@paterkleomenis
Copy link
Contributor Author

Squash the commits please

Done.

@ilya-fedin
Copy link
Contributor

Is the second commit required for audio capture? If not, please make a separate PR

@paterkleomenis
Copy link
Contributor Author

moved to #24

@ilya-fedin
Copy link
Contributor

Why? That other PR doesn't seem to contain loopback implementation

@paterkleomenis
Copy link
Contributor Author

Why? That other PR doesn't seem to contain loopback implementation

What do you mean?

@ilya-fedin
Copy link
Contributor

I mean I don't understand why this PR is moved. The other PR doesn't seem complete.

@ilya-fedin
Copy link
Contributor

That other PR also mixes multiple features in one commit which is a bad thing. All features must be separate PRs, there's a high chance features adding new UI will be rejected (as per tdesktop's CONTRIBUTING.md).

@paterkleomenis
Copy link
Contributor Author

That other PR also mixes multiple features in one commit which is a bad thing. All features must be separate PRs, there's a high chance features adding new UI will be rejected (as per tdesktop's CONTRIBUTING.md).

is it better now?

@ilya-fedin
Copy link
Contributor

I still don't understand why we need a new PR... Why couldn't we continue with this one?

@paterkleomenis
Copy link
Contributor Author

i thought you wanted it to be more clean (so there wouldn't be any reason to be rejected)

@ilya-fedin
Copy link
Contributor

Okay... If it was just cleanings, you could force push instead of a new PR

@paterkleomenis paterkleomenis changed the title Linux: add system audio capture for desktop sharing Linux: add AudioDeviceLoopbackLinux (OpenAL loopback ADM) Feb 22, 2026
paterkleomenis added a commit to paterkleomenis/tdesktop that referenced this pull request Feb 22, 2026
Enables the desktop share audio flow on Linux within Calls UI and plumbing.

- calls_call: add withAudio parameter to toggleScreenSharing, track
  _screenWithAudio flag, create/destroy SystemAudioCapture when sharing
  starts with audio, and clean it up in destroyController.

- calls_panel / calls_group_panel: use LoopbackAudioCaptureSupported()
  to report audio support on all platforms; implement chooseSourceUniqueId()
  so the chooser can handle single-source (Wayland/PipeWire) mode; open
  the source chooser when audio is supported instead of bypassing it.

- desktop_capture_choose_source: add unique-source mode that skips the
  screen/window list and shows only the audio toggle + start/stop buttons,
  used on Linux when a single desktop capture source is pre-selected.

Depends on desktop-app/lib_webrtc#22
Closes telegramdesktop#26642
Adds Linux system audio loopback capture support for desktop sharing.
This serves as a prerequisite for Linux desktop share audio support
in Telegram Desktop.

- Added Linux loopback ADM and capture infrastructure
  (webrtc_loopback_adm_linux, webrtc_loopback_capture_linux,
  webrtc_system_audio_capture_linux)
- Added platform-agnostic SystemAudioCapture interface
  (webrtc_system_audio_capture)
- Wired Linux loopback into webrtc_create_adm (CreateLoopbackAudioDeviceModule,
  LoopbackAudioCaptureSupported)
- Integrated new sources into the build system; removed unused direct
  PipeWire dependency from CMakeLists
@ilya-fedin
Copy link
Contributor

The code is back to what it was... right? What was with the new code, was it completely broken?

@paterkleomenis
Copy link
Contributor Author

The code from pr 24 had replaced the code in pr 22 that was the issue

@ilya-fedin
Copy link
Contributor

@paterkleomenis
Copy link
Contributor Author

I separated the feature changes per your instructions. Unfortunately the force pushing did not go well initially, so the changes of PR 26 ended up being merged in both PRs 24 and 22.

This has now been fixed, and each change is separately kept in its own PR (although some changes depend on others, for example PR 24 which depends on 26 touches the same files to make extensions to them, so it also includes the code introduced in 26 but shouldn't conflict is 26 is merged first). Git is a mess and i also don't know how to use it well.

@john-preston
Copy link
Contributor

Thank you for your work! Let's test that in this implementation, but then I'd like to improve some things, like remove duplication of hardcoded strings for loopback device detection and maybe some more.

@john-preston john-preston merged commit 01e1575 into desktop-app:master Feb 27, 2026
paterkleomenis added a commit to paterkleomenis/tdesktop that referenced this pull request Mar 2, 2026
Enables the desktop share audio flow on Linux within Calls UI and plumbing.

- calls_call: add withAudio parameter to toggleScreenSharing, track
  _screenWithAudio flag, create/destroy SystemAudioCapture when sharing
  starts with audio, and clean it up in destroyController.

- calls_panel / calls_group_panel: use LoopbackAudioCaptureSupported()
  to report audio support on all platforms; show a GenericBox with audio
  toggle when a unique desktop capture source is available (PipeWire),
  then start sharing with the chosen audio setting.

Depends on desktop-app/lib_webrtc#22
Closes telegramdesktop#26642
paterkleomenis added a commit to paterkleomenis/tdesktop that referenced this pull request Mar 4, 2026
Enables the desktop share audio flow on Linux within Calls UI and plumbing.

- calls_call: add withAudio parameter to toggleScreenSharing, track
  _screenWithAudio flag, create/destroy SystemAudioCapture when sharing
  starts with audio, and clean it up in destroyController.

- calls_panel / calls_group_panel: use LoopbackAudioCaptureSupported()
  to report audio support on all platforms; show a GenericBox with audio
  toggle when a unique desktop capture source is available (PipeWire),
  then start sharing with the chosen audio setting.

Depends on desktop-app/lib_webrtc#22
Closes telegramdesktop#26642
paterkleomenis added a commit to paterkleomenis/tdesktop that referenced this pull request Mar 4, 2026
Enables the desktop share audio flow on Linux within Calls UI and plumbing.

- calls_call: add withAudio parameter to toggleScreenSharing, track
  _screenWithAudio flag, create/destroy SystemAudioCapture when sharing
  starts with audio, and clean it up in destroyController.

- calls_panel / calls_group_panel: use LoopbackAudioCaptureSupported()
  to report audio support on all platforms; show a GenericBox with audio
  toggle when a unique desktop capture source is available (PipeWire),
  then start sharing with the chosen audio setting.

Depends on desktop-app/lib_webrtc#22
Closes telegramdesktop#26642
john-preston pushed a commit to telegramdesktop/tdesktop that referenced this pull request Mar 5, 2026
Enables the desktop share audio flow on Linux within Calls UI and plumbing.

- calls_call: add withAudio parameter to toggleScreenSharing, track
  _screenWithAudio flag, create/destroy SystemAudioCapture when sharing
  starts with audio, and clean it up in destroyController.

- calls_panel / calls_group_panel: use LoopbackAudioCaptureSupported()
  to report audio support on all platforms; show a GenericBox with audio
  toggle when a unique desktop capture source is available (PipeWire),
  then start sharing with the chosen audio setting.

Depends on desktop-app/lib_webrtc#22
Closes #26642
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.

3 participants