| 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 14 matching lines...) Expand all Loading... |
| 25 #include "modules/webaudio/AbstractAudioContext.h" | 25 #include "modules/webaudio/AbstractAudioContext.h" |
| 26 #include "bindings/core/v8/Dictionary.h" | 26 #include "bindings/core/v8/Dictionary.h" |
| 27 #include "bindings/core/v8/ExceptionMessages.h" | 27 #include "bindings/core/v8/ExceptionMessages.h" |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ScriptPromiseResolver.h" | 29 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 30 #include "bindings/core/v8/ScriptState.h" | 30 #include "bindings/core/v8/ScriptState.h" |
| 31 #include "core/dom/DOMException.h" | 31 #include "core/dom/DOMException.h" |
| 32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 33 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 34 #include "core/dom/ExecutionContextTask.h" | 34 #include "core/dom/ExecutionContextTask.h" |
| 35 #include "core/frame/Settings.h" |
| 35 #include "core/html/HTMLMediaElement.h" | 36 #include "core/html/HTMLMediaElement.h" |
| 36 #include "modules/mediastream/MediaStream.h" | 37 #include "modules/mediastream/MediaStream.h" |
| 37 #include "modules/webaudio/AnalyserNode.h" | 38 #include "modules/webaudio/AnalyserNode.h" |
| 38 #include "modules/webaudio/AudioBuffer.h" | 39 #include "modules/webaudio/AudioBuffer.h" |
| 39 #include "modules/webaudio/AudioBufferCallback.h" | 40 #include "modules/webaudio/AudioBufferCallback.h" |
| 40 #include "modules/webaudio/AudioBufferSourceNode.h" | 41 #include "modules/webaudio/AudioBufferSourceNode.h" |
| 41 #include "modules/webaudio/AudioContext.h" | 42 #include "modules/webaudio/AudioContext.h" |
| 42 #include "modules/webaudio/AudioListener.h" | 43 #include "modules/webaudio/AudioListener.h" |
| 43 #include "modules/webaudio/AudioNodeInput.h" | 44 #include "modules/webaudio/AudioNodeInput.h" |
| 44 #include "modules/webaudio/AudioNodeOutput.h" | 45 #include "modules/webaudio/AudioNodeOutput.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 #include "modules/webaudio/OfflineAudioCompletionEvent.h" | 58 #include "modules/webaudio/OfflineAudioCompletionEvent.h" |
| 58 #include "modules/webaudio/OfflineAudioContext.h" | 59 #include "modules/webaudio/OfflineAudioContext.h" |
| 59 #include "modules/webaudio/OfflineAudioDestinationNode.h" | 60 #include "modules/webaudio/OfflineAudioDestinationNode.h" |
| 60 #include "modules/webaudio/OscillatorNode.h" | 61 #include "modules/webaudio/OscillatorNode.h" |
| 61 #include "modules/webaudio/PannerNode.h" | 62 #include "modules/webaudio/PannerNode.h" |
| 62 #include "modules/webaudio/PeriodicWave.h" | 63 #include "modules/webaudio/PeriodicWave.h" |
| 63 #include "modules/webaudio/PeriodicWaveConstraints.h" | 64 #include "modules/webaudio/PeriodicWaveConstraints.h" |
| 64 #include "modules/webaudio/ScriptProcessorNode.h" | 65 #include "modules/webaudio/ScriptProcessorNode.h" |
| 65 #include "modules/webaudio/StereoPannerNode.h" | 66 #include "modules/webaudio/StereoPannerNode.h" |
| 66 #include "modules/webaudio/WaveShaperNode.h" | 67 #include "modules/webaudio/WaveShaperNode.h" |
| 68 #include "platform/Histogram.h" |
| 67 #include "platform/ThreadSafeFunctional.h" | 69 #include "platform/ThreadSafeFunctional.h" |
| 70 #include "platform/UserGestureIndicator.h" |
| 68 #include "platform/audio/IIRFilter.h" | 71 #include "platform/audio/IIRFilter.h" |
| 69 #include "public/platform/Platform.h" | 72 #include "public/platform/Platform.h" |
| 70 #include "wtf/text/WTFString.h" | 73 #include "wtf/text/WTFString.h" |
| 71 | 74 |
| 72 namespace blink { | 75 namespace blink { |
| 73 | 76 |
| 77 namespace { |
| 78 |
| 79 enum UserGestureRecord { |
| 80 UserGestureRequiredAndAvailable = 0, |
| 81 UserGestureRequiredAndNotAvailable, |
| 82 UserGestureNotRequiredAndAvailable, |
| 83 UserGestureNotRequiredAndNotAvailable, |
| 84 UserGestureRecordMax |
| 85 }; |
| 86 |
| 87 } // anonymous namespace |
| 88 |
| 74 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception
State& exceptionState) | 89 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception
State& exceptionState) |
| 75 { | 90 { |
| 76 return AudioContext::create(document, exceptionState); | 91 return AudioContext::create(document, exceptionState); |
| 77 } | 92 } |
| 78 | 93 |
| 79 // FIXME(dominicc): Devolve these constructors to AudioContext | 94 // FIXME(dominicc): Devolve these constructors to AudioContext |
| 80 // and OfflineAudioContext respectively. | 95 // and OfflineAudioContext respectively. |
| 81 | 96 |
| 82 // Constructor for rendering to the audio hardware. | 97 // Constructor for rendering to the audio hardware. |
| 83 AbstractAudioContext::AbstractAudioContext(Document* document) | 98 AbstractAudioContext::AbstractAudioContext(Document* document) |
| 84 : ActiveScriptWrappable(this) | 99 : ActiveScriptWrappable(this) |
| 85 , ActiveDOMObject(document) | 100 , ActiveDOMObject(document) |
| 86 , m_destinationNode(nullptr) | 101 , m_destinationNode(nullptr) |
| 87 , m_isCleared(false) | 102 , m_isCleared(false) |
| 88 , m_isResolvingResumePromises(false) | 103 , m_isResolvingResumePromises(false) |
| 104 , m_userGestureRequired(false) |
| 89 , m_connectionCount(0) | 105 , m_connectionCount(0) |
| 90 , m_deferredTaskHandler(DeferredTaskHandler::create()) | 106 , m_deferredTaskHandler(DeferredTaskHandler::create()) |
| 91 , m_contextState(Suspended) | 107 , m_contextState(Suspended) |
| 92 , m_closedContextSampleRate(-1) | 108 , m_closedContextSampleRate(-1) |
| 93 , m_periodicWaveSine(nullptr) | 109 , m_periodicWaveSine(nullptr) |
| 94 , m_periodicWaveSquare(nullptr) | 110 , m_periodicWaveSquare(nullptr) |
| 95 , m_periodicWaveSawtooth(nullptr) | 111 , m_periodicWaveSawtooth(nullptr) |
| 96 , m_periodicWaveTriangle(nullptr) | 112 , m_periodicWaveTriangle(nullptr) |
| 97 { | 113 { |
| 114 // TODO(mlamouri): we might want to use other ways of checking for this but |
| 115 // in order to record metrics, re-using the HTMLMediaElement setting is |
| 116 // probably the simplest solution. |
| 117 if (document->settings() && document->settings()->mediaPlaybackRequiresUserG
esture()) |
| 118 m_userGestureRequired = true; |
| 119 |
| 98 m_destinationNode = DefaultAudioDestinationNode::create(this); | 120 m_destinationNode = DefaultAudioDestinationNode::create(this); |
| 99 | 121 |
| 100 initialize(); | 122 initialize(); |
| 101 } | 123 } |
| 102 | 124 |
| 103 // Constructor for offline (non-realtime) rendering. | 125 // Constructor for offline (non-realtime) rendering. |
| 104 AbstractAudioContext::AbstractAudioContext(Document* document, unsigned numberOf
Channels, size_t numberOfFrames, float sampleRate) | 126 AbstractAudioContext::AbstractAudioContext(Document* document, unsigned numberOf
Channels, size_t numberOfFrames, float sampleRate) |
| 105 : ActiveScriptWrappable(this) | 127 : ActiveScriptWrappable(this) |
| 106 , ActiveDOMObject(document) | 128 , ActiveDOMObject(document) |
| 107 , m_destinationNode(nullptr) | 129 , m_destinationNode(nullptr) |
| 108 , m_isCleared(false) | 130 , m_isCleared(false) |
| 109 , m_isResolvingResumePromises(false) | 131 , m_isResolvingResumePromises(false) |
| 132 , m_userGestureRequired(false) |
| 110 , m_connectionCount(0) | 133 , m_connectionCount(0) |
| 111 , m_deferredTaskHandler(DeferredTaskHandler::create()) | 134 , m_deferredTaskHandler(DeferredTaskHandler::create()) |
| 112 , m_contextState(Suspended) | 135 , m_contextState(Suspended) |
| 113 , m_closedContextSampleRate(-1) | 136 , m_closedContextSampleRate(-1) |
| 114 , m_periodicWaveSine(nullptr) | 137 , m_periodicWaveSine(nullptr) |
| 115 , m_periodicWaveSquare(nullptr) | 138 , m_periodicWaveSquare(nullptr) |
| 116 , m_periodicWaveSawtooth(nullptr) | 139 , m_periodicWaveSawtooth(nullptr) |
| 117 , m_periodicWaveTriangle(nullptr) | 140 , m_periodicWaveTriangle(nullptr) |
| 118 { | 141 { |
| 142 // TODO(mlamouri): we might want to use other ways of checking for this but |
| 143 // in order to record metrics, re-using the HTMLMediaElement setting is |
| 144 // probably the simplest solution. |
| 145 if (document->settings() && document->settings()->mediaPlaybackRequiresUserG
esture()) |
| 146 m_userGestureRequired = true; |
| 119 } | 147 } |
| 120 | 148 |
| 121 AbstractAudioContext::~AbstractAudioContext() | 149 AbstractAudioContext::~AbstractAudioContext() |
| 122 { | 150 { |
| 123 deferredTaskHandler().contextWillBeDestroyed(); | 151 deferredTaskHandler().contextWillBeDestroyed(); |
| 124 // AudioNodes keep a reference to their context, so there should be no way t
o be in the destructor if there are still AudioNodes around. | 152 // AudioNodes keep a reference to their context, so there should be no way t
o be in the destructor if there are still AudioNodes around. |
| 125 ASSERT(!isDestinationInitialized()); | 153 ASSERT(!isDestinationInitialized()); |
| 126 ASSERT(!m_activeSourceNodes.size()); | 154 ASSERT(!m_activeSourceNodes.size()); |
| 127 ASSERT(!m_finishedSourceHandlers.size()); | 155 ASSERT(!m_finishedSourceHandlers.size()); |
| 128 ASSERT(!m_isResolvingResumePromises); | 156 ASSERT(!m_isResolvingResumePromises); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 // Initialize the table if necessary | 734 // Initialize the table if necessary |
| 707 if (!m_periodicWaveTriangle) | 735 if (!m_periodicWaveTriangle) |
| 708 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate()); | 736 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate()); |
| 709 return m_periodicWaveTriangle; | 737 return m_periodicWaveTriangle; |
| 710 default: | 738 default: |
| 711 ASSERT_NOT_REACHED(); | 739 ASSERT_NOT_REACHED(); |
| 712 return nullptr; | 740 return nullptr; |
| 713 } | 741 } |
| 714 } | 742 } |
| 715 | 743 |
| 744 void AbstractAudioContext::recordUserGestureState() |
| 745 { |
| 746 DEFINE_STATIC_LOCAL(EnumerationHistogram, userGestureHistogram, ("WebAudio.U
serGesture", UserGestureRecordMax)); |
| 747 |
| 748 if (!m_userGestureRequired) { |
| 749 if (UserGestureIndicator::processingUserGesture()) |
| 750 userGestureHistogram.count(UserGestureNotRequiredAndAvailable); |
| 751 else |
| 752 userGestureHistogram.count(UserGestureNotRequiredAndNotAvailable); |
| 753 return; |
| 754 } |
| 755 if (!UserGestureIndicator::processingUserGesture()) { |
| 756 userGestureHistogram.count(UserGestureRequiredAndNotAvailable); |
| 757 return; |
| 758 } |
| 759 userGestureHistogram.count(UserGestureRequiredAndAvailable); |
| 760 m_userGestureRequired = false; |
| 761 } |
| 762 |
| 716 String AbstractAudioContext::state() const | 763 String AbstractAudioContext::state() const |
| 717 { | 764 { |
| 718 // These strings had better match the strings for AudioContextState in Audio
Context.idl. | 765 // These strings had better match the strings for AudioContextState in Audio
Context.idl. |
| 719 switch (m_contextState) { | 766 switch (m_contextState) { |
| 720 case Suspended: | 767 case Suspended: |
| 721 return "suspended"; | 768 return "suspended"; |
| 722 case Running: | 769 case Running: |
| 723 return "running"; | 770 return "running"; |
| 724 case Closed: | 771 case Closed: |
| 725 return "closed"; | 772 return "closed"; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 { | 997 { |
| 951 return ActiveDOMObject::getExecutionContext(); | 998 return ActiveDOMObject::getExecutionContext(); |
| 952 } | 999 } |
| 953 | 1000 |
| 954 void AbstractAudioContext::startRendering() | 1001 void AbstractAudioContext::startRendering() |
| 955 { | 1002 { |
| 956 // This is called for both online and offline contexts. | 1003 // This is called for both online and offline contexts. |
| 957 ASSERT(isMainThread()); | 1004 ASSERT(isMainThread()); |
| 958 ASSERT(m_destinationNode); | 1005 ASSERT(m_destinationNode); |
| 959 | 1006 |
| 1007 recordUserGestureState(); |
| 1008 |
| 960 if (m_contextState == Suspended) { | 1009 if (m_contextState == Suspended) { |
| 961 destination()->audioDestinationHandler().startRendering(); | 1010 destination()->audioDestinationHandler().startRendering(); |
| 962 setContextState(Running); | 1011 setContextState(Running); |
| 963 } | 1012 } |
| 964 } | 1013 } |
| 965 | 1014 |
| 966 DEFINE_TRACE(AbstractAudioContext) | 1015 DEFINE_TRACE(AbstractAudioContext) |
| 967 { | 1016 { |
| 968 visitor->trace(m_destinationNode); | 1017 visitor->trace(m_destinationNode); |
| 969 visitor->trace(m_listener); | 1018 visitor->trace(m_listener); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 981 | 1030 |
| 982 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const | 1031 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const |
| 983 { | 1032 { |
| 984 if (getExecutionContext()) | 1033 if (getExecutionContext()) |
| 985 return getExecutionContext()->getSecurityOrigin(); | 1034 return getExecutionContext()->getSecurityOrigin(); |
| 986 | 1035 |
| 987 return nullptr; | 1036 return nullptr; |
| 988 } | 1037 } |
| 989 | 1038 |
| 990 } // namespace blink | 1039 } // namespace blink |
| OLD | NEW |