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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return; | 92 return; |
93 } | 93 } |
94 | 94 |
95 // Synchronize with process() to protect m_sourceNumberOfChannels, | 95 // Synchronize with process() to protect m_sourceNumberOfChannels, |
96 // m_sourceSampleRate, and m_multiChannelResampler. | 96 // m_sourceSampleRate, and m_multiChannelResampler. |
97 Locker<MediaElementAudioSourceHandler> locker(*this); | 97 Locker<MediaElementAudioSourceHandler> locker(*this); |
98 | 98 |
99 m_sourceNumberOfChannels = numberOfChannels; | 99 m_sourceNumberOfChannels = numberOfChannels; |
100 m_sourceSampleRate = sourceSampleRate; | 100 m_sourceSampleRate = sourceSampleRate; |
101 | 101 |
102 if (sourceSampleRate != sampleRate()) { | 102 if (sourceSampleRate != context()->sampleRate()) { |
103 double scaleFactor = sourceSampleRate / sampleRate(); | 103 double scaleFactor = sourceSampleRate / context()->sampleRate(); |
104 m_multiChannelResampler = | 104 m_multiChannelResampler = |
105 WTF::makeUnique<MultiChannelResampler>(scaleFactor, numberOfChannels); | 105 WTF::makeUnique<MultiChannelResampler>(scaleFactor, numberOfChannels); |
106 } else { | 106 } else { |
107 // Bypass resampling. | 107 // Bypass resampling. |
108 m_multiChannelResampler.reset(); | 108 m_multiChannelResampler.reset(); |
109 } | 109 } |
110 | 110 |
111 { | 111 { |
112 // The context must be locked when changing the number of output channels. | 112 // The context must be locked when changing the number of output channels. |
113 BaseAudioContext::AutoLocker contextLocker(context()); | 113 BaseAudioContext::AutoLocker contextLocker(context()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 MutexTryLocker tryLocker(m_processLock); | 170 MutexTryLocker tryLocker(m_processLock); |
171 if (tryLocker.locked()) { | 171 if (tryLocker.locked()) { |
172 if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate) { | 172 if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate) { |
173 outputBus->zero(); | 173 outputBus->zero(); |
174 return; | 174 return; |
175 } | 175 } |
176 AudioSourceProvider& provider = mediaElement()->getAudioSourceProvider(); | 176 AudioSourceProvider& provider = mediaElement()->getAudioSourceProvider(); |
177 // Grab data from the provider so that the element continues to make | 177 // Grab data from the provider so that the element continues to make |
178 // progress, even if we're going to output silence anyway. | 178 // progress, even if we're going to output silence anyway. |
179 if (m_multiChannelResampler.get()) { | 179 if (m_multiChannelResampler.get()) { |
180 DCHECK_NE(m_sourceSampleRate, sampleRate()); | 180 DCHECK_NE(m_sourceSampleRate, context()->sampleRate()); |
181 m_multiChannelResampler->process(&provider, outputBus, numberOfFrames); | 181 m_multiChannelResampler->process(&provider, outputBus, numberOfFrames); |
182 } else { | 182 } else { |
183 // Bypass the resampler completely if the source is at the context's | 183 // Bypass the resampler completely if the source is at the context's |
184 // sample-rate. | 184 // sample-rate. |
185 DCHECK_EQ(m_sourceSampleRate, sampleRate()); | 185 DCHECK_EQ(m_sourceSampleRate, context()->sampleRate()); |
186 provider.provideInput(outputBus, numberOfFrames); | 186 provider.provideInput(outputBus, numberOfFrames); |
187 } | 187 } |
188 // Output silence if we don't have access to the element. | 188 // Output silence if we don't have access to the element. |
189 if (!passesCORSAccessCheck()) { | 189 if (!passesCORSAccessCheck()) { |
190 if (m_maybePrintCORSMessage) { | 190 if (m_maybePrintCORSMessage) { |
191 // Print a CORS message, but just once for each change in the current | 191 // Print a CORS message, but just once for each change in the current |
192 // media element source, and only if we have a document to print to. | 192 // media element source, and only if we have a document to print to. |
193 m_maybePrintCORSMessage = false; | 193 m_maybePrintCORSMessage = false; |
194 if (context()->getExecutionContext()) { | 194 if (context()->getExecutionContext()) { |
195 context()->getExecutionContext()->postTask( | 195 context()->getExecutionContext()->postTask( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 void MediaElementAudioSourceNode::lock() { | 296 void MediaElementAudioSourceNode::lock() { |
297 mediaElementAudioSourceHandler().lock(); | 297 mediaElementAudioSourceHandler().lock(); |
298 } | 298 } |
299 | 299 |
300 void MediaElementAudioSourceNode::unlock() { | 300 void MediaElementAudioSourceNode::unlock() { |
301 mediaElementAudioSourceHandler().unlock(); | 301 mediaElementAudioSourceHandler().unlock(); |
302 } | 302 } |
303 | 303 |
304 } // namespace blink | 304 } // namespace blink |
OLD | NEW |