Commit f7f43442 authored by xians@chromium.org's avatar xians@chromium.org

Fixed the racing in the resampler of webrtc when two streams are calling OnData().

There can be multiple streams calling OnData() when the users setup multiple getUserMedia with WebAudio and microphone. We have no way to avoid this situation since it is a valid user cases from the JS perspective.
But unfortunately webrtc does not support it since it has one global transmit mixer, and it will crash when more than 1 stream getting into its resampler.

This CL introduces a lock to sequence the calls to avoid the racing, which should fix the crash.


BUG=332126
TEST=https://devpool-13.talkgadget.google.com/hangouts, go to setting page and play the rington, verify no crash and sound good.
Or go to https://x20web.corp.google.com/~xians/multiple_sources.html, start the call, AddWebAUdio, then Playout a clip, verify the audio sounds good and no crash.

Review URL: https://codereview.chromium.org/131213003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243902 0039d316-1c4b-4281-b951-d872f2087c98
parent f00a38b0
......@@ -81,6 +81,16 @@ int WebRtcAudioDeviceImpl::OnData(const int16* audio_data,
CHECK_EQ(number_of_frames % samples_per_10_msec, 0);
int accumulated_audio_samples = 0;
uint32_t new_volume = 0;
// The lock here is to protect the racing in the resampler inside webrtc when
// there are more than one input stream calling OnData(), which can happen
// when the users setup two getUserMedia, one for the microphone, another
// for WebAudio. Currently we don't have a better way to fix it except for
// adding a lock here to sequence the call.
// TODO(xians): Remove this workaround after we move the
// webrtc::AudioProcessing module to Chrome. See http://crbug/264611 for
// details.
base::AutoLock auto_lock(capture_callback_lock_);
while (accumulated_audio_samples < number_of_frames) {
// Deliver 10ms of recorded 16-bit linear PCM audio.
int new_mic_level = audio_transport_callback_->OnDataAvailable(
......
......@@ -385,6 +385,10 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
// |recording_| and |microphone_volume_|.
mutable base::Lock lock_;
// Used to protect the racing of calling OnData() since there can be more
// than one input stream calling OnData().
mutable base::Lock capture_callback_lock_;
bool initialized_;
bool playing_;
bool recording_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment