Skip to content

Improve WebRTC build scripts and add external_audio_source patch#1053

Open
xianshijing-lk wants to merge 3 commits intomainfrom
sxian/webrtc-build-improvements-and-patch
Open

Improve WebRTC build scripts and add external_audio_source patch#1053
xianshijing-lk wants to merge 3 commits intomainfrom
sxian/webrtc-build-improvements-and-patch

Conversation

@xianshijing-lk
Copy link
Copy Markdown
Contributor

  • Add external_audio_source.patch for NativeAudioSource support
  • Remove unused use_clang_modules build arg (fixes license generation)
  • Use vpython3 for license generation (Python version compatibility)
  • Make license generation failures non-critical

Before you submit your PR

Make sure the following is true before submitting your PR:

PR description

This PR improves the WebRTC build scripts and adds a patch required for external audio source support (NativeAudioSource).

Changes:

  1. Add external_audio_source.patch - This patch modifies WebRTC to support external audio sources that bypass the Audio Device Module (ADM). It adds an is_external_source() method to both AudioSourceInterface and AudioSource classes, and modifies AudioSendStream to not register with AudioState when using external sources. This prevents mixing of device-captured audio with externally-sourced audio (e.g., from NativeAudioSource).
  2. Remove unused use_clang_modules=false build argument - This argument is no longer recognized by WebRTC m144 and causes GN to output warnings. These warnings break the license generation script because gn desc --format=json outputs warnings before the JSON, causing json.loads() to fail.
  3. Use vpython3 instead of python3 for license generation - vpython3 from depot_tools uses a controlled Python environment (Python 3.11) that is compatible with WebRTC's tooling, rather than relying on the system Python which may be incompatible (e.g., Python 3.14).
  4. Make license generation failures non-critical - Added fallback error handling so that license generation failures don't break the build. The libwebrtc.a static library is the critical output; LICENSE.md is nice-to-have.

Breaking changes

None. These are build script improvements only and do not affect the Rust API.

MSRV

No changes to MSRV.

Testing

The changes were tested by running:
./build_macos.sh --arch arm64 --profile release

The build completes successfully and LICENSE.md is now generated without errors.

The external_audio_source.patch was verified to apply cleanly to a fresh WebRTC m144_release checkout:
cd webrtc-sys/libwebrtc/src
git checkout -- .
git apply ../patches/external_audio_source.patch -v

Async

N/A - This PR only modifies shell build scripts, no Rust code changes.

  - Add external_audio_source.patch for NativeAudioSource support
  - Remove unused use_clang_modules build arg (fixes license generation)
  - Use vpython3 for license generation (Python version compatibility)
  - Make license generation failures non-critical
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

Changeset

The following package versions will be affected by this PR:

Package Bump
libwebrtc patch
livekit patch
livekit-ffi patch
webrtc-sys patch

enable_iterator_debugging=false \
android_package_prefix=\"livekit\" \
use_custom_libcxx=false \
use_clang_modules=false \
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

use_clang_modules=false seem to make the licence generate script fail, @cloudwebrtc , any concern of removing this flag ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, use_clang_modules=false was introduced in the m144 upgrade; I'll double-check if it's a required parameter.

+ // Check if this is an external audio source (delivers audio via AddSink).
+ // If so, mark the config so AudioState doesn't send device audio to this
+ // stream. This must be done before UpdateSendState() calls Start().
+ if (source->is_external_source() && !config_.external_source) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

QQ: This method (AudioSource::is_external_source() const) is looks like not overridden in any inherited class.

In another Rust PR, is_external_source is overridden to webrtc::AudioSourceInterface, but it doesn't seem to be associated with webrtc::AudioSource. I suspect that source->is_external_source() here will always return false.

Perhaps we're missing a copy of the is_external_source state from webrtc::AudioSourceInterface to webrtc::AudioSrouce? The class associated with webrtc::AudioSource is LocalAudioSinkAdapter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I think the problem with the current approach is that it will send both the external source file and mic source to one track.
which will result in duplicating the mic data with some drift there.

I try patching it, can you check it again ?

It might worth coming up with some integration tests, let me work on it

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