Skip to content

refactor: let the PeerConnectionFactory own its worker thread - #355

Merged
devopvoid merged 1 commit into
mainfrom
worktree-worker-thread-nullptr
Oct 11, 2026
Merged

devopvoid merged 1 commit into
mainfrom
worktree-worker-thread-nullptr

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

PeerConnectionFactoryDependencies::worker_thread is being deprecated, so it is now left default-initialized to nullptr and WebRTC creates and owns the factory's worker thread.

Changes

  • Factory creation (JNI_PeerConnectionFactory.cpp): PeerConnectionFactoryDependencies is filled in directly, mirroring webrtc::CreatePeerConnectionFactory(), but without ever assigning worker_thread. That helper takes a worker thread as a parameter, so it is the part likely to change with the deprecation. The network and signaling threads are still ours.
  • Removed our worker thread: its creation, the workerThreadHandle field in PeerConnectionFactory, and its shutdown in dispose().
  • Device capture switching (ProxyAudioDeviceModule): setDeviceCaptureEnabled used our worker thread handle to switch capture without interleaving with AudioState starting a recording. The proxy now learns the factory's own worker thread in RegisterAudioCallback, which WebRtcVoiceEngine calls on that thread, and makes the switch there. Before the transport is registered no send stream can exist, so the switch is made on the calling thread.

Tests

  • New PeerConnectionFactoryTests.deviceAudioSourceAfterPeerConnection: device capture is enabled after a peer connection has started the media engine, so the switch goes through the factory-owned worker thread.
  • mvn -pl webrtc-jni,webrtc package on windows-x86_64: 283 tests, 0 failures, 3 skipped.
  • PeerConnectionFactoryTests, AudioTrackTests and RTCPeerConnectionTests under -Pjni-check: 56 tests pass, no JNI errors.

PeerConnectionFactoryDependencies::worker_thread is being deprecated, so the
factory is now created from dependencies filled in directly, with
worker_thread left at its default of nullptr. WebRTC then creates and owns
the worker thread itself.

Device capture is still switched on that thread so it cannot interleave with
AudioState starting a recording. ProxyAudioDeviceModule learns the thread
when WebRtcVoiceEngine registers its transport, which it does on the worker
thread, and switches on the calling thread before that, when no send stream
can exist yet.
@devopvoid
devopvoid merged commit 43b7420 into main Oct 11, 2026
22 checks passed
@devopvoid
devopvoid deleted the worktree-worker-thread-nullptr branch October 11, 2026 22:43
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