Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioDestination.cpp

Issue 2740103005: Fix premature access on m_fifo in AudioDestination. (Closed)
Patch Set: Reverting changes in PushPullFIFO Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const WebAudioLatencyHint& latencyHint, 63 const WebAudioLatencyHint& latencyHint,
64 PassRefPtr<SecurityOrigin> securityOrigin) 64 PassRefPtr<SecurityOrigin> securityOrigin)
65 : m_numberOfOutputChannels(numberOfOutputChannels), 65 : m_numberOfOutputChannels(numberOfOutputChannels),
66 m_isPlaying(false), 66 m_isPlaying(false),
67 m_callback(callback), 67 m_callback(callback),
68 m_outputBus(AudioBus::create(numberOfOutputChannels, 68 m_outputBus(AudioBus::create(numberOfOutputChannels,
69 AudioUtilities::kRenderQuantumFrames, 69 AudioUtilities::kRenderQuantumFrames,
70 false)), 70 false)),
71 m_renderBus(AudioBus::create(numberOfOutputChannels, 71 m_renderBus(AudioBus::create(numberOfOutputChannels,
72 AudioUtilities::kRenderQuantumFrames)), 72 AudioUtilities::kRenderQuantumFrames)),
73 m_fifo(
74 WTF::wrapUnique(new PushPullFIFO(numberOfOutputChannels, kFIFOSize))),
73 m_framesElapsed(0) { 75 m_framesElapsed(0) {
76 m_callbackBufferSize = hardwareBufferSize();
77 if (!checkBufferSize()) {
78 NOTREACHED();
79 }
80
74 // Create WebAudioDevice. blink::WebAudioDevice is designed to support the 81 // Create WebAudioDevice. blink::WebAudioDevice is designed to support the
75 // local input (e.g. loopback from OS audio system), but Chromium's media 82 // local input (e.g. loopback from OS audio system), but Chromium's media
76 // renderer does not support it currently. Thus, we use zero for the number 83 // renderer does not support it currently. Thus, we use zero for the number
77 // of input channels. 84 // of input channels.
78 m_webAudioDevice = WTF::wrapUnique(Platform::current()->createAudioDevice( 85 m_webAudioDevice = WTF::wrapUnique(Platform::current()->createAudioDevice(
79 0, numberOfOutputChannels, latencyHint, this, String(), 86 0, numberOfOutputChannels, latencyHint, this, String(),
80 std::move(securityOrigin))); 87 std::move(securityOrigin)));
81 DCHECK(m_webAudioDevice); 88 DCHECK(m_webAudioDevice);
82
83 m_callbackBufferSize = m_webAudioDevice->framesPerBuffer();
84
85 if (!checkBufferSize()) {
86 NOTREACHED();
87 }
88
89 // Create a FIFO.
90 m_fifo = WTF::wrapUnique(new PushPullFIFO(numberOfOutputChannels, kFIFOSize));
91 } 89 }
92 90
93 AudioDestination::~AudioDestination() { 91 AudioDestination::~AudioDestination() {
94 stop(); 92 stop();
95 } 93 }
96 94
97 void AudioDestination::render(const WebVector<float*>& destinationData, 95 void AudioDestination::render(const WebVector<float*>& destinationData,
98 size_t numberOfFrames, 96 size_t numberOfFrames,
99 double delay, 97 double delay,
100 double delayTimestamp, 98 double delayTimestamp,
101 size_t priorFramesSkipped) { 99 size_t priorFramesSkipped) {
102 CHECK_EQ(destinationData.size(), m_numberOfOutputChannels); 100 CHECK_EQ(destinationData.size(), m_numberOfOutputChannels);
103 CHECK_EQ(numberOfFrames, m_callbackBufferSize); 101 CHECK_EQ(numberOfFrames, m_callbackBufferSize);
104 102
103 // Note that this method is called by AudioDeviceThread. If FIFO is not ready,
104 // or the requested render size is greater than FIFO size return here.
105 // (crbug.com/692423)
106 if (!m_fifo || m_fifo->length() < numberOfFrames)
107 return;
108
105 m_framesElapsed -= std::min(m_framesElapsed, priorFramesSkipped); 109 m_framesElapsed -= std::min(m_framesElapsed, priorFramesSkipped);
106 double outputPosition = 110 double outputPosition =
107 m_framesElapsed / static_cast<double>(m_webAudioDevice->sampleRate()) - 111 m_framesElapsed / static_cast<double>(m_webAudioDevice->sampleRate()) -
108 delay; 112 delay;
109 m_outputPosition.position = outputPosition; 113 m_outputPosition.position = outputPosition;
110 m_outputPosition.timestamp = delayTimestamp; 114 m_outputPosition.timestamp = delayTimestamp;
111 m_outputPositionReceivedTimestamp = base::TimeTicks::Now(); 115 m_outputPositionReceivedTimestamp = base::TimeTicks::Now();
112 116
113 // Associate the destination data array with the output bus then fill the 117 // Associate the destination data array with the output bus then fill the
114 // FIFO. 118 // FIFO.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 callbackBufferSizeHistogram.sample(m_callbackBufferSize); 198 callbackBufferSizeHistogram.sample(m_callbackBufferSize);
195 199
196 // Check if the requested buffer size is too large. 200 // Check if the requested buffer size is too large.
197 bool isBufferSizeValid = 201 bool isBufferSizeValid =
198 m_callbackBufferSize + AudioUtilities::kRenderQuantumFrames <= kFIFOSize; 202 m_callbackBufferSize + AudioUtilities::kRenderQuantumFrames <= kFIFOSize;
199 DCHECK(isBufferSizeValid); 203 DCHECK(isBufferSizeValid);
200 return isBufferSizeValid; 204 return isBufferSizeValid;
201 } 205 }
202 206
203 } // namespace blink 207 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698