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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/MediaElementAudioSourceNode.cpp

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

Powered by Google App Engine
This is Rietveld 408576698