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(true) | |
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; | |
Raymond Toy
2016/06/03 17:57:52
You initialized m_userGestureRequired to true in l
mlamouri (slow - plz ping)
2016/06/05 14:44:57
I meant `false` above. I changed before uploading
| |
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 : AbstractAudioContext(document) |
Raymond Toy
2016/06/03 17:57:52
Why the change? It seems that it nothing to do wit
mlamouri (slow - plz ping)
2016/06/05 14:44:57
Instead of adding yet another init in there, I thi
Raymond Toy
2016/06/06 15:10:07
Thanks. We'll do this fix some other day; it make
| |
106 , ActiveDOMObject(document) | |
107 , m_destinationNode(nullptr) | |
108 , m_isCleared(false) | |
109 , m_isResolvingResumePromises(false) | |
110 , m_connectionCount(0) | |
111 , m_deferredTaskHandler(DeferredTaskHandler::create()) | |
112 , m_contextState(Suspended) | |
113 , m_closedContextSampleRate(-1) | |
114 , m_periodicWaveSine(nullptr) | |
115 , m_periodicWaveSquare(nullptr) | |
116 , m_periodicWaveSawtooth(nullptr) | |
117 , m_periodicWaveTriangle(nullptr) | |
118 { | 128 { |
119 } | 129 } |
120 | 130 |
121 AbstractAudioContext::~AbstractAudioContext() | 131 AbstractAudioContext::~AbstractAudioContext() |
122 { | 132 { |
123 deferredTaskHandler().contextWillBeDestroyed(); | 133 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. | 134 // 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()); | 135 ASSERT(!isDestinationInitialized()); |
126 ASSERT(!m_activeSourceNodes.size()); | 136 ASSERT(!m_activeSourceNodes.size()); |
127 ASSERT(!m_finishedSourceHandlers.size()); | 137 ASSERT(!m_finishedSourceHandlers.size()); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 // Initialize the table if necessary | 476 // Initialize the table if necessary |
467 if (!m_periodicWaveTriangle) | 477 if (!m_periodicWaveTriangle) |
468 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate()); | 478 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate()); |
469 return m_periodicWaveTriangle; | 479 return m_periodicWaveTriangle; |
470 default: | 480 default: |
471 ASSERT_NOT_REACHED(); | 481 ASSERT_NOT_REACHED(); |
472 return nullptr; | 482 return nullptr; |
473 } | 483 } |
474 } | 484 } |
475 | 485 |
486 void AbstractAudioContext::recordUserGesture() | |
Raymond Toy
2016/06/03 17:57:52
I think recordUserGestureState() is a better name.
mlamouri (slow - plz ping)
2016/06/05 14:44:57
Done.
| |
487 { | |
488 DEFINE_STATIC_LOCAL(EnumerationHistogram, userGestureHistogram, ("WebAudio.U serGesture", UserGestureRecordMax)); | |
489 | |
490 if (!m_userGestureRequired) { | |
491 if (UserGestureIndicator::processingUserGesture()) | |
492 userGestureHistogram.count(UserGestureNotRequiredAndAvailable); | |
493 else | |
494 userGestureHistogram.count(UserGestureNotRequiredAndNotAvailable); | |
495 return; | |
496 } | |
497 if (!UserGestureIndicator::processingUserGesture()) { | |
498 userGestureHistogram.count(UserGestureRequiredAndNotAvailable); | |
499 return; | |
500 } | |
501 userGestureHistogram.count(UserGestureRequiredAndAvailable); | |
502 m_userGestureRequired = false; | |
503 } | |
504 | |
476 String AbstractAudioContext::state() const | 505 String AbstractAudioContext::state() const |
477 { | 506 { |
478 // These strings had better match the strings for AudioContextState in Audio Context.idl. | 507 // These strings had better match the strings for AudioContextState in Audio Context.idl. |
479 switch (m_contextState) { | 508 switch (m_contextState) { |
480 case Suspended: | 509 case Suspended: |
481 return "suspended"; | 510 return "suspended"; |
482 case Running: | 511 case Running: |
483 return "running"; | 512 return "running"; |
484 case Closed: | 513 case Closed: |
485 return "closed"; | 514 return "closed"; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 { | 739 { |
711 return ActiveDOMObject::getExecutionContext(); | 740 return ActiveDOMObject::getExecutionContext(); |
712 } | 741 } |
713 | 742 |
714 void AbstractAudioContext::startRendering() | 743 void AbstractAudioContext::startRendering() |
715 { | 744 { |
716 // This is called for both online and offline contexts. | 745 // This is called for both online and offline contexts. |
717 ASSERT(isMainThread()); | 746 ASSERT(isMainThread()); |
718 ASSERT(m_destinationNode); | 747 ASSERT(m_destinationNode); |
719 | 748 |
749 recordUserGesture(); | |
Raymond Toy
2016/06/03 17:57:52
Can you explain why this is here? startRendering(
mlamouri (slow - plz ping)
2016/06/05 14:44:57
This is basically added to places where WebKit doe
Raymond Toy
2016/06/06 15:10:07
Ok, it makes some sense to do the same.
| |
750 | |
720 if (m_contextState == Suspended) { | 751 if (m_contextState == Suspended) { |
721 destination()->audioDestinationHandler().startRendering(); | 752 destination()->audioDestinationHandler().startRendering(); |
722 setContextState(Running); | 753 setContextState(Running); |
723 } | 754 } |
724 } | 755 } |
725 | 756 |
726 DEFINE_TRACE(AbstractAudioContext) | 757 DEFINE_TRACE(AbstractAudioContext) |
727 { | 758 { |
728 visitor->trace(m_destinationNode); | 759 visitor->trace(m_destinationNode); |
729 visitor->trace(m_listener); | 760 visitor->trace(m_listener); |
(...skipping 11 matching lines...) Expand all Loading... | |
741 | 772 |
742 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const | 773 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const |
743 { | 774 { |
744 if (getExecutionContext()) | 775 if (getExecutionContext()) |
745 return getExecutionContext()->getSecurityOrigin(); | 776 return getExecutionContext()->getSecurityOrigin(); |
746 | 777 |
747 return nullptr; | 778 return nullptr; |
748 } | 779 } |
749 | 780 |
750 } // namespace blink | 781 } // namespace blink |
OLD | NEW |