Commit 9d2ce527 authored by hongchan's avatar hongchan Committed by Commit bot

Fix premature access on m_fifo in AudioDestination.

In the AudioDestination construction process, WebAudioDevice can start
the thread even before m_fifo is ready. This may result a crash when
render() method is called by AudioDeviceThread.

This CL implements a speculative fix of the incorrect order of
initialization.

BUG=692423
TEST=(none)

Review-Url: https://codereview.chromium.org/2740103005
Cr-Commit-Position: refs/heads/master@{#456204}
parent b21b7a3b
...@@ -70,7 +70,14 @@ AudioDestination::AudioDestination(AudioIOCallback& callback, ...@@ -70,7 +70,14 @@ AudioDestination::AudioDestination(AudioIOCallback& callback,
false)), false)),
m_renderBus(AudioBus::create(numberOfOutputChannels, m_renderBus(AudioBus::create(numberOfOutputChannels,
AudioUtilities::kRenderQuantumFrames)), AudioUtilities::kRenderQuantumFrames)),
m_fifo(
WTF::wrapUnique(new PushPullFIFO(numberOfOutputChannels, kFIFOSize))),
m_framesElapsed(0) { m_framesElapsed(0) {
m_callbackBufferSize = hardwareBufferSize();
if (!checkBufferSize()) {
NOTREACHED();
}
// Create WebAudioDevice. blink::WebAudioDevice is designed to support the // Create WebAudioDevice. blink::WebAudioDevice is designed to support the
// local input (e.g. loopback from OS audio system), but Chromium's media // local input (e.g. loopback from OS audio system), but Chromium's media
// renderer does not support it currently. Thus, we use zero for the number // renderer does not support it currently. Thus, we use zero for the number
...@@ -79,15 +86,6 @@ AudioDestination::AudioDestination(AudioIOCallback& callback, ...@@ -79,15 +86,6 @@ AudioDestination::AudioDestination(AudioIOCallback& callback,
0, numberOfOutputChannels, latencyHint, this, String(), 0, numberOfOutputChannels, latencyHint, this, String(),
std::move(securityOrigin))); std::move(securityOrigin)));
DCHECK(m_webAudioDevice); DCHECK(m_webAudioDevice);
m_callbackBufferSize = m_webAudioDevice->framesPerBuffer();
if (!checkBufferSize()) {
NOTREACHED();
}
// Create a FIFO.
m_fifo = WTF::wrapUnique(new PushPullFIFO(numberOfOutputChannels, kFIFOSize));
} }
AudioDestination::~AudioDestination() { AudioDestination::~AudioDestination() {
...@@ -102,6 +100,12 @@ void AudioDestination::render(const WebVector<float*>& destinationData, ...@@ -102,6 +100,12 @@ void AudioDestination::render(const WebVector<float*>& destinationData,
CHECK_EQ(destinationData.size(), m_numberOfOutputChannels); CHECK_EQ(destinationData.size(), m_numberOfOutputChannels);
CHECK_EQ(numberOfFrames, m_callbackBufferSize); CHECK_EQ(numberOfFrames, m_callbackBufferSize);
// Note that this method is called by AudioDeviceThread. If FIFO is not ready,
// or the requested render size is greater than FIFO size return here.
// (crbug.com/692423)
if (!m_fifo || m_fifo->length() < numberOfFrames)
return;
m_framesElapsed -= std::min(m_framesElapsed, priorFramesSkipped); m_framesElapsed -= std::min(m_framesElapsed, priorFramesSkipped);
double outputPosition = double outputPosition =
m_framesElapsed / static_cast<double>(m_webAudioDevice->sampleRate()) - m_framesElapsed / static_cast<double>(m_webAudioDevice->sampleRate()) -
......
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