Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Add baseLatency and fix use of hardwareSampleRate. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26 matching lines...) Expand all
37 #include "core/frame/Settings.h" 37 #include "core/frame/Settings.h"
38 #include "core/html/HTMLMediaElement.h" 38 #include "core/html/HTMLMediaElement.h"
39 #include "core/inspector/ConsoleMessage.h" 39 #include "core/inspector/ConsoleMessage.h"
40 #include "core/inspector/ConsoleTypes.h" 40 #include "core/inspector/ConsoleTypes.h"
41 #include "modules/mediastream/MediaStream.h" 41 #include "modules/mediastream/MediaStream.h"
42 #include "modules/webaudio/AnalyserNode.h" 42 #include "modules/webaudio/AnalyserNode.h"
43 #include "modules/webaudio/AudioBuffer.h" 43 #include "modules/webaudio/AudioBuffer.h"
44 #include "modules/webaudio/AudioBufferCallback.h" 44 #include "modules/webaudio/AudioBufferCallback.h"
45 #include "modules/webaudio/AudioBufferSourceNode.h" 45 #include "modules/webaudio/AudioBufferSourceNode.h"
46 #include "modules/webaudio/AudioContext.h" 46 #include "modules/webaudio/AudioContext.h"
47 #include "modules/webaudio/AudioContextOptions.h"
47 #include "modules/webaudio/AudioListener.h" 48 #include "modules/webaudio/AudioListener.h"
48 #include "modules/webaudio/AudioNodeInput.h" 49 #include "modules/webaudio/AudioNodeInput.h"
49 #include "modules/webaudio/AudioNodeOutput.h" 50 #include "modules/webaudio/AudioNodeOutput.h"
50 #include "modules/webaudio/BiquadFilterNode.h" 51 #include "modules/webaudio/BiquadFilterNode.h"
51 #include "modules/webaudio/ChannelMergerNode.h" 52 #include "modules/webaudio/ChannelMergerNode.h"
52 #include "modules/webaudio/ChannelSplitterNode.h" 53 #include "modules/webaudio/ChannelSplitterNode.h"
53 #include "modules/webaudio/ConstantSourceNode.h" 54 #include "modules/webaudio/ConstantSourceNode.h"
54 #include "modules/webaudio/ConvolverNode.h" 55 #include "modules/webaudio/ConvolverNode.h"
55 #include "modules/webaudio/DefaultAudioDestinationNode.h" 56 #include "modules/webaudio/DefaultAudioDestinationNode.h"
56 #include "modules/webaudio/DelayNode.h" 57 #include "modules/webaudio/DelayNode.h"
(...skipping 11 matching lines...) Expand all
68 #include "modules/webaudio/PeriodicWave.h" 69 #include "modules/webaudio/PeriodicWave.h"
69 #include "modules/webaudio/PeriodicWaveConstraints.h" 70 #include "modules/webaudio/PeriodicWaveConstraints.h"
70 #include "modules/webaudio/ScriptProcessorNode.h" 71 #include "modules/webaudio/ScriptProcessorNode.h"
71 #include "modules/webaudio/StereoPannerNode.h" 72 #include "modules/webaudio/StereoPannerNode.h"
72 #include "modules/webaudio/WaveShaperNode.h" 73 #include "modules/webaudio/WaveShaperNode.h"
73 #include "platform/CrossThreadFunctional.h" 74 #include "platform/CrossThreadFunctional.h"
74 #include "platform/Histogram.h" 75 #include "platform/Histogram.h"
75 #include "platform/UserGestureIndicator.h" 76 #include "platform/UserGestureIndicator.h"
76 #include "platform/audio/IIRFilter.h" 77 #include "platform/audio/IIRFilter.h"
77 #include "public/platform/Platform.h" 78 #include "public/platform/Platform.h"
79 #include "public/platform/WebAudioLatencyHint.h"
78 #include "wtf/text/WTFString.h" 80 #include "wtf/text/WTFString.h"
79 81
80 namespace blink { 82 namespace blink {
81 83
82 BaseAudioContext* BaseAudioContext::create(Document& document, 84 BaseAudioContext* BaseAudioContext::create(
83 ExceptionState& exceptionState) { 85 Document& document,
84 return AudioContext::create(document, exceptionState); 86 const WebAudioLatencyHint& latencyHint,
87 ExceptionState& exceptionState) {
88 return AudioContext::create(document, latencyHint, exceptionState);
85 } 89 }
86 90
87 // FIXME(dominicc): Devolve these constructors to AudioContext 91 // FIXME(dominicc): Devolve these constructors to AudioContext
88 // and OfflineAudioContext respectively. 92 // and OfflineAudioContext respectively.
89 93
90 // Constructor for rendering to the audio hardware. 94 // Constructor for rendering to the audio hardware.
91 BaseAudioContext::BaseAudioContext(Document* document) 95 BaseAudioContext::BaseAudioContext(Document* document,
96 const WebAudioLatencyHint& latencyHint)
92 : ActiveScriptWrappable(this), 97 : ActiveScriptWrappable(this),
93 ActiveDOMObject(document), 98 ActiveDOMObject(document),
94 m_destinationNode(nullptr), 99 m_destinationNode(nullptr),
95 m_isCleared(false), 100 m_isCleared(false),
96 m_isResolvingResumePromises(false), 101 m_isResolvingResumePromises(false),
97 m_userGestureRequired(false), 102 m_userGestureRequired(false),
98 m_connectionCount(0), 103 m_connectionCount(0),
99 m_deferredTaskHandler(DeferredTaskHandler::create()), 104 m_deferredTaskHandler(DeferredTaskHandler::create()),
100 m_contextState(Suspended), 105 m_contextState(Suspended),
101 m_closedContextSampleRate(-1), 106 m_closedContextSampleRate(-1),
102 m_periodicWaveSine(nullptr), 107 m_periodicWaveSine(nullptr),
103 m_periodicWaveSquare(nullptr), 108 m_periodicWaveSquare(nullptr),
104 m_periodicWaveSawtooth(nullptr), 109 m_periodicWaveSawtooth(nullptr),
105 m_periodicWaveTriangle(nullptr) { 110 m_periodicWaveTriangle(nullptr) {
106 // If mediaPlaybackRequiresUserGesture is enabled, cross origin iframes will 111 // If mediaPlaybackRequiresUserGesture is enabled, cross origin iframes will
107 // require user gesture for the AudioContext to produce sound. 112 // require user gesture for the AudioContext to produce sound.
108 if (document->settings() && 113 if (document->settings() &&
109 document->settings()->mediaPlaybackRequiresUserGesture() && 114 document->settings()->mediaPlaybackRequiresUserGesture() &&
110 document->frame() && document->frame()->isCrossOriginSubframe()) { 115 document->frame() && document->frame()->isCrossOriginSubframe()) {
111 m_autoplayStatus = AutoplayStatus::AutoplayStatusFailed; 116 m_autoplayStatus = AutoplayStatus::AutoplayStatusFailed;
112 m_userGestureRequired = true; 117 m_userGestureRequired = true;
113 } 118 }
114 119
115 m_destinationNode = DefaultAudioDestinationNode::create(this); 120 m_destinationNode = DefaultAudioDestinationNode::create(this, latencyHint);
116 121
117 initialize(); 122 initialize();
118 } 123 }
119 124
120 // Constructor for offline (non-realtime) rendering. 125 // Constructor for offline (non-realtime) rendering.
121 BaseAudioContext::BaseAudioContext(Document* document, 126 BaseAudioContext::BaseAudioContext(Document* document,
122 unsigned numberOfChannels, 127 unsigned numberOfChannels,
123 size_t numberOfFrames, 128 size_t numberOfFrames,
124 float sampleRate) 129 float sampleRate)
125 : ActiveScriptWrappable(this), 130 : ActiveScriptWrappable(this),
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 return "suspended"; 588 return "suspended";
584 case Running: 589 case Running:
585 return "running"; 590 return "running";
586 case Closed: 591 case Closed:
587 return "closed"; 592 return "closed";
588 } 593 }
589 NOTREACHED(); 594 NOTREACHED();
590 return ""; 595 return "";
591 } 596 }
592 597
598 double BaseAudioContext::baseLatency() const {
599 return framesPerBuffer() * 2 / sampleRate();
Raymond Toy 2016/11/30 21:50:27 Cast sampleRate() to double so that we get double
Andrew MacPherson 2016/12/01 12:11:56 Done.
600 }
601
593 void BaseAudioContext::setContextState(AudioContextState newState) { 602 void BaseAudioContext::setContextState(AudioContextState newState) {
594 DCHECK(isMainThread()); 603 DCHECK(isMainThread());
595 604
596 // Validate the transitions. The valid transitions are Suspended->Running, 605 // Validate the transitions. The valid transitions are Suspended->Running,
597 // Running->Suspended, and anything->Closed. 606 // Running->Suspended, and anything->Closed.
598 switch (newState) { 607 switch (newState) {
599 case Suspended: 608 case Suspended:
600 DCHECK_EQ(m_contextState, Running); 609 DCHECK_EQ(m_contextState, Running);
601 break; 610 break;
602 case Running: 611 case Running:
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 } 890 }
882 891
883 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { 892 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const {
884 if (getExecutionContext()) 893 if (getExecutionContext())
885 return getExecutionContext()->getSecurityOrigin(); 894 return getExecutionContext()->getSecurityOrigin();
886 895
887 return nullptr; 896 return nullptr;
888 } 897 }
889 898
890 } // namespace blink 899 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698