OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 void MediaElementAudioSourceHandler::onCurrentSrcChanged( | 128 void MediaElementAudioSourceHandler::onCurrentSrcChanged( |
129 const KURL& currentSrc) { | 129 const KURL& currentSrc) { |
130 DCHECK(isMainThread()); | 130 DCHECK(isMainThread()); |
131 | 131 |
132 // Synchronize with process(). | 132 // Synchronize with process(). |
133 Locker<MediaElementAudioSourceHandler> locker(*this); | 133 Locker<MediaElementAudioSourceHandler> locker(*this); |
134 | 134 |
135 m_passesCurrentSrcCORSAccessCheck = | 135 m_passesCurrentSrcCORSAccessCheck = |
136 passesCurrentSrcCORSAccessCheck(currentSrc); | 136 passesCurrentSrcCORSAccessCheck(currentSrc); |
137 | 137 |
138 // Make a note if we need to print a console message and save the |curentSrc|
for use in the | 138 // Make a note if we need to print a console message and save the |curentSrc| |
139 // message. Need to wait until later to print the message in case HTMLMediaEl
ement allows | 139 // for use in the message. Need to wait until later to print the message in |
140 // access. | 140 // case HTMLMediaElement allows access. |
141 m_maybePrintCORSMessage = !m_passesCurrentSrcCORSAccessCheck; | 141 m_maybePrintCORSMessage = !m_passesCurrentSrcCORSAccessCheck; |
142 m_currentSrcString = currentSrc.getString(); | 142 m_currentSrcString = currentSrc.getString(); |
143 } | 143 } |
144 | 144 |
145 bool MediaElementAudioSourceHandler::passesCurrentSrcCORSAccessCheck( | 145 bool MediaElementAudioSourceHandler::passesCurrentSrcCORSAccessCheck( |
146 const KURL& currentSrc) { | 146 const KURL& currentSrc) { |
147 DCHECK(isMainThread()); | 147 DCHECK(isMainThread()); |
148 return context()->getSecurityOrigin() && | 148 return context()->getSecurityOrigin() && |
149 context()->getSecurityOrigin()->canRequest(currentSrc); | 149 context()->getSecurityOrigin()->canRequest(currentSrc); |
150 } | 150 } |
151 | 151 |
152 void MediaElementAudioSourceHandler::printCORSMessage(const String& message) { | 152 void MediaElementAudioSourceHandler::printCORSMessage(const String& message) { |
153 if (context()->getExecutionContext()) { | 153 if (context()->getExecutionContext()) { |
154 context()->getExecutionContext()->addConsoleMessage( | 154 context()->getExecutionContext()->addConsoleMessage( |
155 ConsoleMessage::create(SecurityMessageSource, InfoMessageLevel, | 155 ConsoleMessage::create(SecurityMessageSource, InfoMessageLevel, |
156 "MediaElementAudioSource outputs zeroes due to " | 156 "MediaElementAudioSource outputs zeroes due to " |
157 "CORS access restrictions for " + | 157 "CORS access restrictions for " + |
158 message)); | 158 message)); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 void MediaElementAudioSourceHandler::process(size_t numberOfFrames) { | 162 void MediaElementAudioSourceHandler::process(size_t numberOfFrames) { |
163 AudioBus* outputBus = output(0).bus(); | 163 AudioBus* outputBus = output(0).bus(); |
164 | 164 |
165 // Use a tryLock() to avoid contention in the real-time audio thread. | 165 // Use a tryLock() to avoid contention in the real-time audio thread. |
166 // If we fail to acquire the lock then the HTMLMediaElement must be in the mid
dle of | 166 // If we fail to acquire the lock then the HTMLMediaElement must be in the |
167 // reconfiguring its playback engine, so we output silence in this case. | 167 // middle of reconfiguring its playback engine, so we output silence in this |
| 168 // case. |
168 MutexTryLocker tryLocker(m_processLock); | 169 MutexTryLocker tryLocker(m_processLock); |
169 if (tryLocker.locked()) { | 170 if (tryLocker.locked()) { |
170 if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate) { | 171 if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate) { |
171 outputBus->zero(); | 172 outputBus->zero(); |
172 return; | 173 return; |
173 } | 174 } |
174 AudioSourceProvider& provider = mediaElement()->getAudioSourceProvider(); | 175 AudioSourceProvider& provider = mediaElement()->getAudioSourceProvider(); |
175 // Grab data from the provider so that the element continues to make progres
s, even if | 176 // Grab data from the provider so that the element continues to make |
176 // we're going to output silence anyway. | 177 // progress, even if we're going to output silence anyway. |
177 if (m_multiChannelResampler.get()) { | 178 if (m_multiChannelResampler.get()) { |
178 DCHECK_NE(m_sourceSampleRate, sampleRate()); | 179 DCHECK_NE(m_sourceSampleRate, sampleRate()); |
179 m_multiChannelResampler->process(&provider, outputBus, numberOfFrames); | 180 m_multiChannelResampler->process(&provider, outputBus, numberOfFrames); |
180 } else { | 181 } else { |
181 // Bypass the resampler completely if the source is at the context's sampl
e-rate. | 182 // Bypass the resampler completely if the source is at the context's |
| 183 // sample-rate. |
182 DCHECK_EQ(m_sourceSampleRate, sampleRate()); | 184 DCHECK_EQ(m_sourceSampleRate, sampleRate()); |
183 provider.provideInput(outputBus, numberOfFrames); | 185 provider.provideInput(outputBus, numberOfFrames); |
184 } | 186 } |
185 // Output silence if we don't have access to the element. | 187 // Output silence if we don't have access to the element. |
186 if (!passesCORSAccessCheck()) { | 188 if (!passesCORSAccessCheck()) { |
187 if (m_maybePrintCORSMessage) { | 189 if (m_maybePrintCORSMessage) { |
188 // Print a CORS message, but just once for each change in the current me
dia | 190 // Print a CORS message, but just once for each change in the current |
189 // element source, and only if we have a document to print to. | 191 // media element source, and only if we have a document to print to. |
190 m_maybePrintCORSMessage = false; | 192 m_maybePrintCORSMessage = false; |
191 if (context()->getExecutionContext()) { | 193 if (context()->getExecutionContext()) { |
192 context()->getExecutionContext()->postTask( | 194 context()->getExecutionContext()->postTask( |
193 BLINK_FROM_HERE, | 195 BLINK_FROM_HERE, |
194 createCrossThreadTask( | 196 createCrossThreadTask( |
195 &MediaElementAudioSourceHandler::printCORSMessage, | 197 &MediaElementAudioSourceHandler::printCORSMessage, |
196 PassRefPtr<MediaElementAudioSourceHandler>(this), | 198 PassRefPtr<MediaElementAudioSourceHandler>(this), |
197 m_currentSrcString)); | 199 m_currentSrcString)); |
198 } | 200 } |
199 } | 201 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 294 |
293 void MediaElementAudioSourceNode::lock() { | 295 void MediaElementAudioSourceNode::lock() { |
294 mediaElementAudioSourceHandler().lock(); | 296 mediaElementAudioSourceHandler().lock(); |
295 } | 297 } |
296 | 298 |
297 void MediaElementAudioSourceNode::unlock() { | 299 void MediaElementAudioSourceNode::unlock() { |
298 mediaElementAudioSourceHandler().unlock(); | 300 mediaElementAudioSourceHandler().unlock(); |
299 } | 301 } |
300 | 302 |
301 } // namespace blink | 303 } // namespace blink |
OLD | NEW |