void MediaElementAudioSourceHandler::process(size_t numberOfFrames) { AudioBus* outputBus = output(0).bus(); if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate) { outputBus->zero(); return; } // Use a tryLock() to avoid contention in the real-time audio thread. // If we fail to acquire the lock then the HTMLMediaElement must be in the middle of // reconfiguring its playback engine, so we output silence in this case. MutexTryLocker tryLocker(m_processLock); if (tryLocker.locked()) { if (AudioSourceProvider* provider = mediaElement()->audioSourceProvider()) { // Grab data from the provider so that the element continues to make progress, even if // we're going to output silence anyway. if (m_multiChannelResampler.get()) { ASSERT(m_sourceSampleRate != sampleRate()); m_multiChannelResampler->process(provider, outputBus, numberOfFrames); } else { // Bypass the resampler completely if the source is at the context's sample-rate. ASSERT(m_sourceSampleRate == sampleRate()); provider->provideInput(outputBus, numberOfFrames); } // Output silence if we don't have access to the element. if (!passesCORSAccessCheck()) { if (m_maybePrintCORSMessage) { // Print a CORS message, but just once for each change in the current media // element source, and only if we have a document to print to. m_maybePrintCORSMessage = false; if (context()->executionContext()) { context()->executionContext()->postTask(FROM_HERE, createCrossThreadTask(&MediaElementAudioSourceHandler::printCORSMessage, this, m_currentSrcString)); } } outputBus->zero(); } } else { // Either this port doesn't yet support HTMLMediaElement audio stream access, // or the stream is not yet available. outputBus->zero(); } } else { // We failed to acquire the lock. outputBus->zero(); } }
void MediaElementAudioSourceHandler::process(size_t numberOfFrames) { AudioBus* outputBus = output(0).bus(); // Use a tryLock() to avoid contention in the real-time audio thread. // If we fail to acquire the lock then the HTMLMediaElement must be in the // middle of reconfiguring its playback engine, so we output silence in this // case. MutexTryLocker tryLocker(m_processLock); if (tryLocker.locked()) { if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate) { outputBus->zero(); return; } AudioSourceProvider& provider = mediaElement()->getAudioSourceProvider(); // Grab data from the provider so that the element continues to make // progress, even if we're going to output silence anyway. if (m_multiChannelResampler.get()) { DCHECK_NE(m_sourceSampleRate, sampleRate()); m_multiChannelResampler->process(&provider, outputBus, numberOfFrames); } else { // Bypass the resampler completely if the source is at the context's // sample-rate. DCHECK_EQ(m_sourceSampleRate, sampleRate()); provider.provideInput(outputBus, numberOfFrames); } // Output silence if we don't have access to the element. if (!passesCORSAccessCheck()) { if (m_maybePrintCORSMessage) { // Print a CORS message, but just once for each change in the current // media element source, and only if we have a document to print to. m_maybePrintCORSMessage = false; if (context()->getExecutionContext()) { context()->getExecutionContext()->postTask( BLINK_FROM_HERE, createCrossThreadTask( &MediaElementAudioSourceHandler::printCORSMessage, PassRefPtr<MediaElementAudioSourceHandler>(this), m_currentSrcString)); } } outputBus->zero(); } } else { // We failed to acquire the lock. outputBus->zero(); } }