Repository navigation
refactor: let the PeerConnectionFactory own its worker thread - #355
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PeerConnectionFactoryDependencies::worker_threadis being deprecated, so it is now left default-initialized tonullptrand WebRTC creates and owns the factory's worker thread.Changes
JNI_PeerConnectionFactory.cpp):PeerConnectionFactoryDependenciesis filled in directly, mirroringwebrtc::CreatePeerConnectionFactory(), but without ever assigningworker_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.workerThreadHandlefield inPeerConnectionFactory, and its shutdown indispose().ProxyAudioDeviceModule):setDeviceCaptureEnabledused our worker thread handle to switch capture without interleaving withAudioStatestarting a recording. The proxy now learns the factory's own worker thread inRegisterAudioCallback, whichWebRtcVoiceEnginecalls 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
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 packageon windows-x86_64: 283 tests, 0 failures, 3 skipped.PeerConnectionFactoryTests,AudioTrackTestsandRTCPeerConnectionTestsunder-Pjni-check: 56 tests pass, no JNI errors.