void AudioContext::resume(Promise&& promise) { if (isOfflineContext()) { promise.reject(INVALID_STATE_ERR); return; } if (m_state == State::Running) { promise.resolve(nullptr); return; } if (m_state == State::Closed || !m_destinationNode) { promise.reject(0); return; } addReaction(State::Running, WTFMove(promise)); if (!willBeginPlayback()) return; lazyInitialize(); RefPtr<AudioContext> strongThis(this); m_destinationNode->resume([strongThis] { strongThis->setState(State::Running); }); }
void AudioContext::suspend(Promise&& promise) { if (isOfflineContext()) { promise.reject(INVALID_STATE_ERR); return; } if (m_state == State::Suspended) { promise.resolve(nullptr); return; } if (m_state == State::Closed || m_state == State::Interrupted || !m_destinationNode) { promise.reject(0); return; } addReaction(State::Suspended, WTFMove(promise)); if (!willPausePlayback()) return; lazyInitialize(); RefPtr<AudioContext> strongThis(this); m_destinationNode->suspend([strongThis] { strongThis->setState(State::Suspended); }); }
void AudioContext::isPlayingAudioDidChange() { // Make sure to call Document::updateIsPlayingMedia() on the main thread, since // we could be on the audio I/O thread here and the call into WebCore could block. RefPtr<AudioContext> strongThis(this); callOnMainThread([strongThis] { if (strongThis->document()) strongThis->document()->updateIsPlayingMedia(); }); }
result AccessProviderImpl::Spread(const Call& call) { CoreMutexLock locker(CommonImpl< IAccessProvider >::GetLock()); // Prevent destruction of this object during spreading event. IAccessProviderPtr strongThis( CommonImpl< IAccessProvider >::GetSelf() ); // Walk through the entire list of access points and spread the event. for ( AccessPoints_::iterator iter = accessPoints_.begin() ; accessPoints_.end() != iter ; ++iter ) { (*iter).second->Spread(call); } return _S_OK; }
void AudioContext::suspendPlayback() { if (!m_destinationNode || m_state == State::Closed) return; if (m_state == State::Suspended) { if (m_mediaSession->state() == PlatformMediaSession::Interrupted) setState(State::Interrupted); return; } lazyInitialize(); RefPtr<AudioContext> strongThis(this); m_destinationNode->suspend([strongThis] { bool interrupted = strongThis->m_mediaSession->state() == PlatformMediaSession::Interrupted; strongThis->setState(interrupted ? State::Interrupted : State::Suspended); }); }
void AudioContext::scheduleNodeDeletion() { bool isGood = m_isInitialized && isGraphOwner(); ASSERT(isGood); if (!isGood) return; // Make sure to call deleteMarkedNodes() on main thread. if (m_nodesMarkedForDeletion.size() && !m_isDeletionScheduled) { m_nodesToDelete.appendVector(m_nodesMarkedForDeletion); m_nodesMarkedForDeletion.clear(); m_isDeletionScheduled = true; RefPtr<AudioContext> strongThis(this); callOnMainThread([strongThis] { strongThis->deleteMarkedNodes(); }); } }
void AudioContext::mayResumePlayback(bool shouldResume) { if (!m_destinationNode || m_state == State::Closed || m_state == State::Running) return; if (!shouldResume) { setState(State::Suspended); return; } if (!willBeginPlayback()) return; lazyInitialize(); RefPtr<AudioContext> strongThis(this); m_destinationNode->resume([strongThis] { strongThis->setState(State::Running); }); }
void AudioContext::close(Promise&& promise) { if (isOfflineContext()) { promise.reject(INVALID_STATE_ERR); return; } if (m_state == State::Closed || !m_destinationNode) { promise.resolve(nullptr); return; } addReaction(State::Closed, WTFMove(promise)); lazyInitialize(); RefPtr<AudioContext> strongThis(this); m_destinationNode->close([strongThis] { strongThis->setState(State::Closed); strongThis->uninitialize(); }); }