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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
28 | 28 |
29 #include "modules/webaudio/MediaElementAudioSourceNode.h" | 29 #include "modules/webaudio/MediaElementAudioSourceNode.h" |
30 | 30 |
31 #include "core/html/HTMLMediaElement.h" | 31 #include "core/html/HTMLMediaElement.h" |
32 #include "modules/webaudio/AudioContext.h" | 32 #include "modules/webaudio/AudioContext.h" |
33 #include "modules/webaudio/AudioNodeOutput.h" | 33 #include "modules/webaudio/AudioNodeOutput.h" |
34 #include "platform/Logging.h" | 34 #include "platform/Logging.h" |
35 #include "platform/graphics/media/MediaPlayer.h" | 35 #include "platform/graphics/media/MediaPlayer.h" |
| 36 #include "platform/weborigin/SecurityOrigin.h" |
36 #include "wtf/Locker.h" | 37 #include "wtf/Locker.h" |
37 | 38 |
38 // These are somewhat arbitrary limits, but we need to do some kind of sanity-ch
ecking. | 39 // These are somewhat arbitrary limits, but we need to do some kind of sanity-ch
ecking. |
39 const unsigned minSampleRate = 8000; | 40 const unsigned minSampleRate = 8000; |
40 const unsigned maxSampleRate = 192000; | 41 const unsigned maxSampleRate = 192000; |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 MediaElementAudioSourceNode* MediaElementAudioSourceNode::create(AudioContext* c
ontext, HTMLMediaElement* mediaElement) | 45 MediaElementAudioSourceNode* MediaElementAudioSourceNode::create(AudioContext* c
ontext, HTMLMediaElement* mediaElement) |
45 { | 46 { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 outputBus->zero(); | 117 outputBus->zero(); |
117 return; | 118 return; |
118 } | 119 } |
119 | 120 |
120 // Use a tryLock() to avoid contention in the real-time audio thread. | 121 // Use a tryLock() to avoid contention in the real-time audio thread. |
121 // If we fail to acquire the lock then the HTMLMediaElement must be in the m
iddle of | 122 // If we fail to acquire the lock then the HTMLMediaElement must be in the m
iddle of |
122 // reconfiguring its playback engine, so we output silence in this case. | 123 // reconfiguring its playback engine, so we output silence in this case. |
123 MutexTryLocker tryLocker(m_processLock); | 124 MutexTryLocker tryLocker(m_processLock); |
124 if (tryLocker.locked()) { | 125 if (tryLocker.locked()) { |
125 if (AudioSourceProvider* provider = mediaElement()->audioSourceProvider(
)) { | 126 if (AudioSourceProvider* provider = mediaElement()->audioSourceProvider(
)) { |
| 127 // Grab data from the provider so that the element continues to make
progress, even if |
| 128 // we're going to output silence anyway. |
126 if (m_multiChannelResampler.get()) { | 129 if (m_multiChannelResampler.get()) { |
127 ASSERT(m_sourceSampleRate != sampleRate()); | 130 ASSERT(m_sourceSampleRate != sampleRate()); |
128 m_multiChannelResampler->process(provider, outputBus, numberOfFr
ames); | 131 m_multiChannelResampler->process(provider, outputBus, numberOfFr
ames); |
129 } else { | 132 } else { |
130 // Bypass the resampler completely if the source is at the conte
xt's sample-rate. | 133 // Bypass the resampler completely if the source is at the conte
xt's sample-rate. |
131 ASSERT(m_sourceSampleRate == sampleRate()); | 134 ASSERT(m_sourceSampleRate == sampleRate()); |
132 provider->provideInput(outputBus, numberOfFrames); | 135 provider->provideInput(outputBus, numberOfFrames); |
133 } | 136 } |
| 137 // Output silence if we don't have access to the element. |
| 138 if (!context()->securityOrigin()->canRequest(m_mediaElement->current
Src())) |
| 139 outputBus->zero(); |
134 } else { | 140 } else { |
135 // Either this port doesn't yet support HTMLMediaElement audio strea
m access, | 141 // Either this port doesn't yet support HTMLMediaElement audio strea
m access, |
136 // or the stream is not yet available. | 142 // or the stream is not yet available. |
137 outputBus->zero(); | 143 outputBus->zero(); |
138 } | 144 } |
139 } else { | 145 } else { |
140 // We failed to acquire the lock. | 146 // We failed to acquire the lock. |
141 outputBus->zero(); | 147 outputBus->zero(); |
142 } | 148 } |
143 } | 149 } |
(...skipping 11 matching lines...) Expand all Loading... |
155 void MediaElementAudioSourceNode::trace(Visitor* visitor) | 161 void MediaElementAudioSourceNode::trace(Visitor* visitor) |
156 { | 162 { |
157 visitor->trace(m_mediaElement); | 163 visitor->trace(m_mediaElement); |
158 AudioSourceNode::trace(visitor); | 164 AudioSourceNode::trace(visitor); |
159 AudioSourceProviderClient::trace(visitor); | 165 AudioSourceProviderClient::trace(visitor); |
160 } | 166 } |
161 | 167 |
162 } // namespace blink | 168 } // namespace blink |
163 | 169 |
164 #endif // ENABLE(WEB_AUDIO) | 170 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |