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