| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 m_isCleared(false), | 95 m_isCleared(false), |
| 96 m_isResolvingResumePromises(false), | 96 m_isResolvingResumePromises(false), |
| 97 m_userGestureRequired(false), | 97 m_userGestureRequired(false), |
| 98 m_connectionCount(0), | 98 m_connectionCount(0), |
| 99 m_deferredTaskHandler(DeferredTaskHandler::create()), | 99 m_deferredTaskHandler(DeferredTaskHandler::create()), |
| 100 m_contextState(Suspended), | 100 m_contextState(Suspended), |
| 101 m_closedContextSampleRate(-1), | 101 m_closedContextSampleRate(-1), |
| 102 m_periodicWaveSine(nullptr), | 102 m_periodicWaveSine(nullptr), |
| 103 m_periodicWaveSquare(nullptr), | 103 m_periodicWaveSquare(nullptr), |
| 104 m_periodicWaveSawtooth(nullptr), | 104 m_periodicWaveSawtooth(nullptr), |
| 105 m_periodicWaveTriangle(nullptr) { | 105 m_periodicWaveTriangle(nullptr), |
| 106 m_outputPosition() { |
| 106 // If mediaPlaybackRequiresUserGesture is enabled, cross origin iframes will | 107 // If mediaPlaybackRequiresUserGesture is enabled, cross origin iframes will |
| 107 // require user gesture for the AudioContext to produce sound. | 108 // require user gesture for the AudioContext to produce sound. |
| 108 if (document->settings() && | 109 if (document->settings() && |
| 109 document->settings()->mediaPlaybackRequiresUserGesture() && | 110 document->settings()->mediaPlaybackRequiresUserGesture() && |
| 110 document->frame() && document->frame()->isCrossOriginSubframe()) { | 111 document->frame() && document->frame()->isCrossOriginSubframe()) { |
| 111 m_autoplayStatus = AutoplayStatus::AutoplayStatusFailed; | 112 m_autoplayStatus = AutoplayStatus::AutoplayStatusFailed; |
| 112 m_userGestureRequired = true; | 113 m_userGestureRequired = true; |
| 113 } | 114 } |
| 114 | 115 |
| 115 m_destinationNode = DefaultAudioDestinationNode::create(this); | 116 m_destinationNode = DefaultAudioDestinationNode::create(this); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 128 m_isCleared(false), | 129 m_isCleared(false), |
| 129 m_isResolvingResumePromises(false), | 130 m_isResolvingResumePromises(false), |
| 130 m_userGestureRequired(false), | 131 m_userGestureRequired(false), |
| 131 m_connectionCount(0), | 132 m_connectionCount(0), |
| 132 m_deferredTaskHandler(DeferredTaskHandler::create()), | 133 m_deferredTaskHandler(DeferredTaskHandler::create()), |
| 133 m_contextState(Suspended), | 134 m_contextState(Suspended), |
| 134 m_closedContextSampleRate(-1), | 135 m_closedContextSampleRate(-1), |
| 135 m_periodicWaveSine(nullptr), | 136 m_periodicWaveSine(nullptr), |
| 136 m_periodicWaveSquare(nullptr), | 137 m_periodicWaveSquare(nullptr), |
| 137 m_periodicWaveSawtooth(nullptr), | 138 m_periodicWaveSawtooth(nullptr), |
| 138 m_periodicWaveTriangle(nullptr) {} | 139 m_periodicWaveTriangle(nullptr), |
| 140 m_outputPosition() {} |
| 139 | 141 |
| 140 BaseAudioContext::~BaseAudioContext() { | 142 BaseAudioContext::~BaseAudioContext() { |
| 141 deferredTaskHandler().contextWillBeDestroyed(); | 143 deferredTaskHandler().contextWillBeDestroyed(); |
| 142 // AudioNodes keep a reference to their context, so there should be no way to | 144 // AudioNodes keep a reference to their context, so there should be no way to |
| 143 // be in the destructor if there are still AudioNodes around. | 145 // be in the destructor if there are still AudioNodes around. |
| 144 DCHECK(!isDestinationInitialized()); | 146 DCHECK(!isDestinationInitialized()); |
| 145 DCHECK(!m_activeSourceNodes.size()); | 147 DCHECK(!m_activeSourceNodes.size()); |
| 146 DCHECK(!m_finishedSourceHandlers.size()); | 148 DCHECK(!m_finishedSourceHandlers.size()); |
| 147 DCHECK(!m_isResolvingResumePromises); | 149 DCHECK(!m_isResolvingResumePromises); |
| 148 DCHECK(!m_resumeResolvers.size()); | 150 DCHECK(!m_resumeResolvers.size()); |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 continue; | 701 continue; |
| 700 if (node->handler().getNodeType() == | 702 if (node->handler().getNodeType() == |
| 701 AudioHandler::NodeTypeAudioBufferSource) { | 703 AudioHandler::NodeTypeAudioBufferSource) { |
| 702 AudioBufferSourceNode* sourceNode = | 704 AudioBufferSourceNode* sourceNode = |
| 703 static_cast<AudioBufferSourceNode*>(node); | 705 static_cast<AudioBufferSourceNode*>(node); |
| 704 sourceNode->audioBufferSourceHandler().handleStoppableSourceNode(); | 706 sourceNode->audioBufferSourceHandler().handleStoppableSourceNode(); |
| 705 } | 707 } |
| 706 } | 708 } |
| 707 } | 709 } |
| 708 | 710 |
| 709 void BaseAudioContext::handlePreRenderTasks() { | 711 void BaseAudioContext::handlePreRenderTasks( |
| 712 const AudioIOPosition& outputPosition) { |
| 710 DCHECK(isAudioThread()); | 713 DCHECK(isAudioThread()); |
| 711 | 714 |
| 712 // At the beginning of every render quantum, try to update the internal | 715 // At the beginning of every render quantum, try to update the internal |
| 713 // rendering graph state (from main thread changes). It's OK if the tryLock() | 716 // rendering graph state (from main thread changes). It's OK if the tryLock() |
| 714 // fails, we'll just take slightly longer to pick up the changes. | 717 // fails, we'll just take slightly longer to pick up the changes. |
| 715 if (tryLock()) { | 718 if (tryLock()) { |
| 716 deferredTaskHandler().handleDeferredTasks(); | 719 deferredTaskHandler().handleDeferredTasks(); |
| 717 | 720 |
| 718 resolvePromisesForResume(); | 721 resolvePromisesForResume(); |
| 719 | 722 |
| 720 // Check to see if source nodes can be stopped because the end time has | 723 // Check to see if source nodes can be stopped because the end time has |
| 721 // passed. | 724 // passed. |
| 722 handleStoppableSourceNodes(); | 725 handleStoppableSourceNodes(); |
| 723 | 726 |
| 724 // Update the dirty state of the listener. | 727 // Update the dirty state of the listener. |
| 725 listener()->updateState(); | 728 listener()->updateState(); |
| 726 | 729 |
| 730 // Update output timestamp. |
| 731 m_outputPosition = outputPosition; |
| 732 |
| 727 unlock(); | 733 unlock(); |
| 728 } | 734 } |
| 729 } | 735 } |
| 730 | 736 |
| 731 void BaseAudioContext::handlePostRenderTasks() { | 737 void BaseAudioContext::handlePostRenderTasks() { |
| 732 DCHECK(isAudioThread()); | 738 DCHECK(isAudioThread()); |
| 733 | 739 |
| 734 // Must use a tryLock() here too. Don't worry, the lock will very rarely be | 740 // Must use a tryLock() here too. Don't worry, the lock will very rarely be |
| 735 // contended and this method is called frequently. The worst that can happen | 741 // contended and this method is called frequently. The worst that can happen |
| 736 // is that there will be some nodes which will take slightly longer than usual | 742 // is that there will be some nodes which will take slightly longer than usual |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 return true; | 816 return true; |
| 811 | 817 |
| 812 toDocument(getExecutionContext()) | 818 toDocument(getExecutionContext()) |
| 813 ->addConsoleMessage(ConsoleMessage::create( | 819 ->addConsoleMessage(ConsoleMessage::create( |
| 814 JSMessageSource, WarningMessageLevel, | 820 JSMessageSource, WarningMessageLevel, |
| 815 "An AudioContext in a cross origin iframe must be created or resumed " | 821 "An AudioContext in a cross origin iframe must be created or resumed " |
| 816 "from a user gesture to enable audio output.")); | 822 "from a user gesture to enable audio output.")); |
| 817 return false; | 823 return false; |
| 818 } | 824 } |
| 819 | 825 |
| 826 AudioIOPosition BaseAudioContext::outputPosition() { |
| 827 AutoLocker locker(this); |
| 828 return m_outputPosition; |
| 829 } |
| 830 |
| 820 void BaseAudioContext::rejectPendingResolvers() { | 831 void BaseAudioContext::rejectPendingResolvers() { |
| 821 DCHECK(isMainThread()); | 832 DCHECK(isMainThread()); |
| 822 | 833 |
| 823 // Audio context is closing down so reject any resume promises that are still | 834 // Audio context is closing down so reject any resume promises that are still |
| 824 // pending. | 835 // pending. |
| 825 | 836 |
| 826 for (auto& resolver : m_resumeResolvers) { | 837 for (auto& resolver : m_resumeResolvers) { |
| 827 resolver->reject( | 838 resolver->reject( |
| 828 DOMException::create(InvalidStateError, "Audio context is going away")); | 839 DOMException::create(InvalidStateError, "Audio context is going away")); |
| 829 } | 840 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 } | 892 } |
| 882 | 893 |
| 883 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { | 894 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { |
| 884 if (getExecutionContext()) | 895 if (getExecutionContext()) |
| 885 return getExecutionContext()->getSecurityOrigin(); | 896 return getExecutionContext()->getSecurityOrigin(); |
| 886 | 897 |
| 887 return nullptr; | 898 return nullptr; |
| 888 } | 899 } |
| 889 | 900 |
| 890 } // namespace blink | 901 } // namespace blink |
| OLD | NEW |