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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 MediaElementAudioSourceHandler::MediaElementAudioSourceHandler(AudioNode& node,
HTMLMediaElement& mediaElement) | 39 MediaElementAudioSourceHandler::MediaElementAudioSourceHandler(AudioNode& node,
HTMLMediaElement& mediaElement) |
40 : AudioHandler(NodeTypeMediaElementAudioSource, node, node.context()->sample
Rate()) | 40 : AudioHandler(NodeTypeMediaElementAudioSource, node, node.context()->sample
Rate()) |
41 , m_mediaElement(mediaElement) | 41 , m_mediaElement(mediaElement) |
42 , m_sourceNumberOfChannels(0) | 42 , m_sourceNumberOfChannels(0) |
43 , m_sourceSampleRate(0) | 43 , m_sourceSampleRate(0) |
44 , m_passesCurrentSrcCORSAccessCheck(passesCurrentSrcCORSAccessCheck(mediaEle
ment.currentSrc())) | 44 , m_passesCurrentSrcCORSAccessCheck(passesCurrentSrcCORSAccessCheck(mediaEle
ment.currentSrc())) |
45 , m_maybePrintCORSMessage(!m_passesCurrentSrcCORSAccessCheck) | 45 , m_maybePrintCORSMessage(!m_passesCurrentSrcCORSAccessCheck) |
46 , m_currentSrcString(mediaElement.currentSrc().getString()) | 46 , m_currentSrcString(mediaElement.currentSrc().getString()) |
47 { | 47 { |
48 ASSERT(isMainThread()); | 48 DCHECK(isMainThread()); |
49 // Default to stereo. This could change depending on what the media element | 49 // Default to stereo. This could change depending on what the media element |
50 // .src is set to. | 50 // .src is set to. |
51 addOutput(2); | 51 addOutput(2); |
52 | 52 |
53 initialize(); | 53 initialize(); |
54 } | 54 } |
55 | 55 |
56 PassRefPtr<MediaElementAudioSourceHandler> MediaElementAudioSourceHandler::creat
e(AudioNode& node, HTMLMediaElement& mediaElement) | 56 PassRefPtr<MediaElementAudioSourceHandler> MediaElementAudioSourceHandler::creat
e(AudioNode& node, HTMLMediaElement& mediaElement) |
57 { | 57 { |
58 return adoptRef(new MediaElementAudioSourceHandler(node, mediaElement)); | 58 return adoptRef(new MediaElementAudioSourceHandler(node, mediaElement)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 BaseAudioContext::AutoLocker contextLocker(context()); | 102 BaseAudioContext::AutoLocker contextLocker(context()); |
103 | 103 |
104 // Do any necesssary re-configuration to the output's number of chan
nels. | 104 // Do any necesssary re-configuration to the output's number of chan
nels. |
105 output(0).setNumberOfChannels(numberOfChannels); | 105 output(0).setNumberOfChannels(numberOfChannels); |
106 } | 106 } |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 bool MediaElementAudioSourceHandler::passesCORSAccessCheck() | 110 bool MediaElementAudioSourceHandler::passesCORSAccessCheck() |
111 { | 111 { |
112 ASSERT(mediaElement()); | 112 DCHECK(mediaElement()); |
113 | 113 |
114 return (mediaElement()->webMediaPlayer() && mediaElement()->webMediaPlayer()
->didPassCORSAccessCheck()) | 114 return (mediaElement()->webMediaPlayer() && mediaElement()->webMediaPlayer()
->didPassCORSAccessCheck()) |
115 || m_passesCurrentSrcCORSAccessCheck; | 115 || m_passesCurrentSrcCORSAccessCheck; |
116 } | 116 } |
117 | 117 |
118 void MediaElementAudioSourceHandler::onCurrentSrcChanged(const KURL& currentSrc) | 118 void MediaElementAudioSourceHandler::onCurrentSrcChanged(const KURL& currentSrc) |
119 { | 119 { |
120 ASSERT(isMainThread()); | 120 DCHECK(isMainThread()); |
121 | 121 |
122 // Synchronize with process(). | 122 // Synchronize with process(). |
123 Locker<MediaElementAudioSourceHandler> locker(*this); | 123 Locker<MediaElementAudioSourceHandler> locker(*this); |
124 | 124 |
125 m_passesCurrentSrcCORSAccessCheck = passesCurrentSrcCORSAccessCheck(currentS
rc); | 125 m_passesCurrentSrcCORSAccessCheck = passesCurrentSrcCORSAccessCheck(currentS
rc); |
126 | 126 |
127 // Make a note if we need to print a console message and save the |curentSrc
| for use in the | 127 // Make a note if we need to print a console message and save the |curentSrc
| for use in the |
128 // message. Need to wait until later to print the message in case HTMLMedia
Element allows | 128 // message. Need to wait until later to print the message in case HTMLMedia
Element allows |
129 // access. | 129 // access. |
130 m_maybePrintCORSMessage = !m_passesCurrentSrcCORSAccessCheck; | 130 m_maybePrintCORSMessage = !m_passesCurrentSrcCORSAccessCheck; |
131 m_currentSrcString = currentSrc.getString(); | 131 m_currentSrcString = currentSrc.getString(); |
132 } | 132 } |
133 | 133 |
134 bool MediaElementAudioSourceHandler::passesCurrentSrcCORSAccessCheck(const KURL&
currentSrc) | 134 bool MediaElementAudioSourceHandler::passesCurrentSrcCORSAccessCheck(const KURL&
currentSrc) |
135 { | 135 { |
136 ASSERT(isMainThread()); | 136 DCHECK(isMainThread()); |
137 return context()->getSecurityOrigin() && context()->getSecurityOrigin()->can
Request(currentSrc); | 137 return context()->getSecurityOrigin() && context()->getSecurityOrigin()->can
Request(currentSrc); |
138 } | 138 } |
139 | 139 |
140 void MediaElementAudioSourceHandler::printCORSMessage(const String& message) | 140 void MediaElementAudioSourceHandler::printCORSMessage(const String& message) |
141 { | 141 { |
142 if (context()->getExecutionContext()) { | 142 if (context()->getExecutionContext()) { |
143 context()->getExecutionContext()->addConsoleMessage( | 143 context()->getExecutionContext()->addConsoleMessage( |
144 ConsoleMessage::create(SecurityMessageSource, InfoMessageLevel, | 144 ConsoleMessage::create(SecurityMessageSource, InfoMessageLevel, |
145 "MediaElementAudioSource outputs zeroes due to CORS access restr
ictions for " + message)); | 145 "MediaElementAudioSource outputs zeroes due to CORS access restr
ictions for " + message)); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 void MediaElementAudioSourceHandler::process(size_t numberOfFrames) | 149 void MediaElementAudioSourceHandler::process(size_t numberOfFrames) |
150 { | 150 { |
151 AudioBus* outputBus = output(0).bus(); | 151 AudioBus* outputBus = output(0).bus(); |
152 | 152 |
153 // Use a tryLock() to avoid contention in the real-time audio thread. | 153 // Use a tryLock() to avoid contention in the real-time audio thread. |
154 // If we fail to acquire the lock then the HTMLMediaElement must be in the m
iddle of | 154 // If we fail to acquire the lock then the HTMLMediaElement must be in the m
iddle of |
155 // reconfiguring its playback engine, so we output silence in this case. | 155 // reconfiguring its playback engine, so we output silence in this case. |
156 MutexTryLocker tryLocker(m_processLock); | 156 MutexTryLocker tryLocker(m_processLock); |
157 if (tryLocker.locked()) { | 157 if (tryLocker.locked()) { |
158 if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate)
{ | 158 if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate)
{ |
159 outputBus->zero(); | 159 outputBus->zero(); |
160 return; | 160 return; |
161 } | 161 } |
162 AudioSourceProvider& provider = mediaElement()->getAudioSourceProvider()
; | 162 AudioSourceProvider& provider = mediaElement()->getAudioSourceProvider()
; |
163 // Grab data from the provider so that the element continues to make pro
gress, even if | 163 // Grab data from the provider so that the element continues to make pro
gress, even if |
164 // we're going to output silence anyway. | 164 // we're going to output silence anyway. |
165 if (m_multiChannelResampler.get()) { | 165 if (m_multiChannelResampler.get()) { |
166 ASSERT(m_sourceSampleRate != sampleRate()); | 166 DCHECK_NE(m_sourceSampleRate, sampleRate()); |
167 m_multiChannelResampler->process(&provider, outputBus, numberOfFrame
s); | 167 m_multiChannelResampler->process(&provider, outputBus, numberOfFrame
s); |
168 } else { | 168 } else { |
169 // Bypass the resampler completely if the source is at the context's
sample-rate. | 169 // Bypass the resampler completely if the source is at the context's
sample-rate. |
170 ASSERT(m_sourceSampleRate == sampleRate()); | 170 DCHECK_EQ(m_sourceSampleRate, sampleRate()); |
171 provider.provideInput(outputBus, numberOfFrames); | 171 provider.provideInput(outputBus, numberOfFrames); |
172 } | 172 } |
173 // Output silence if we don't have access to the element. | 173 // Output silence if we don't have access to the element. |
174 if (!passesCORSAccessCheck()) { | 174 if (!passesCORSAccessCheck()) { |
175 if (m_maybePrintCORSMessage) { | 175 if (m_maybePrintCORSMessage) { |
176 // Print a CORS message, but just once for each change in the cu
rrent media | 176 // Print a CORS message, but just once for each change in the cu
rrent media |
177 // element source, and only if we have a document to print to. | 177 // element source, and only if we have a document to print to. |
178 m_maybePrintCORSMessage = false; | 178 m_maybePrintCORSMessage = false; |
179 if (context()->getExecutionContext()) { | 179 if (context()->getExecutionContext()) { |
180 context()->getExecutionContext()->postTask(BLINK_FROM_HERE, | 180 context()->getExecutionContext()->postTask(BLINK_FROM_HERE, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 mediaElementAudioSourceHandler().lock(); | 266 mediaElementAudioSourceHandler().lock(); |
267 } | 267 } |
268 | 268 |
269 void MediaElementAudioSourceNode::unlock() | 269 void MediaElementAudioSourceNode::unlock() |
270 { | 270 { |
271 mediaElementAudioSourceHandler().unlock(); | 271 mediaElementAudioSourceHandler().unlock(); |
272 } | 272 } |
273 | 273 |
274 } // namespace blink | 274 } // namespace blink |
275 | 275 |
OLD | NEW |