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

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

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

Powered by Google App Engine
This is Rietveld 408576698