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

Side by Side Diff: Source/modules/webaudio/AudioContext.cpp

Issue 773273002: Update the current frame count in a safe place (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 , m_isStopScheduled(false) 102 , m_isStopScheduled(false)
103 , m_isCleared(false) 103 , m_isCleared(false)
104 , m_isInitialized(false) 104 , m_isInitialized(false)
105 , m_destinationNode(nullptr) 105 , m_destinationNode(nullptr)
106 , m_isResolvingResumePromises(false) 106 , m_isResolvingResumePromises(false)
107 , m_automaticPullNodesNeedUpdating(false) 107 , m_automaticPullNodesNeedUpdating(false)
108 , m_connectionCount(0) 108 , m_connectionCount(0)
109 , m_audioThread(0) 109 , m_audioThread(0)
110 , m_isOfflineContext(false) 110 , m_isOfflineContext(false)
111 , m_contextState(Suspended) 111 , m_contextState(Suspended)
112 , m_shadowCurrentSampleFrame(0)
112 { 113 {
113 m_referencedNodes = new HeapVector<Member<AudioNode>>(); 114 m_referencedNodes = new HeapVector<Member<AudioNode>>();
114 m_destinationNode = DefaultAudioDestinationNode::create(this); 115 m_destinationNode = DefaultAudioDestinationNode::create(this);
115 116
116 initialize(); 117 initialize();
117 #if DEBUG_AUDIONODE_REFERENCES 118 #if DEBUG_AUDIONODE_REFERENCES
118 fprintf(stderr, "%p: AudioContext::AudioContext() #%u\n", this, AudioContext ::s_hardwareContextCount); 119 fprintf(stderr, "%p: AudioContext::AudioContext() #%u\n", this, AudioContext ::s_hardwareContextCount);
119 #endif 120 #endif
120 } 121 }
121 122
122 // Constructor for offline (non-realtime) rendering. 123 // Constructor for offline (non-realtime) rendering.
123 AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate) 124 AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
124 : ActiveDOMObject(document) 125 : ActiveDOMObject(document)
125 , m_isStopScheduled(false) 126 , m_isStopScheduled(false)
126 , m_isCleared(false) 127 , m_isCleared(false)
127 , m_isInitialized(false) 128 , m_isInitialized(false)
128 , m_destinationNode(nullptr) 129 , m_destinationNode(nullptr)
129 , m_isResolvingResumePromises(false) 130 , m_isResolvingResumePromises(false)
130 , m_automaticPullNodesNeedUpdating(false) 131 , m_automaticPullNodesNeedUpdating(false)
131 , m_connectionCount(0) 132 , m_connectionCount(0)
132 , m_audioThread(0) 133 , m_audioThread(0)
133 , m_isOfflineContext(true) 134 , m_isOfflineContext(true)
134 , m_contextState(Suspended) 135 , m_contextState(Suspended)
136 , m_shadowCurrentSampleFrame(0)
135 { 137 {
136 m_referencedNodes = new HeapVector<Member<AudioNode>>(); 138 m_referencedNodes = new HeapVector<Member<AudioNode>>();
137 // Create a new destination for offline rendering. 139 // Create a new destination for offline rendering.
138 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate); 140 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate);
139 if (m_renderTarget.get()) 141 if (m_renderTarget.get())
140 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get()); 142 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get());
141 143
142 initialize(); 144 initialize();
143 } 145 }
144 146
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 exceptionState.throwDOMException( 548 exceptionState.throwDOMException(
547 IndexSizeError, 549 IndexSizeError,
548 "length of imaginary array (" + String::number(imag->length()) 550 "length of imaginary array (" + String::number(imag->length())
549 + ") exceeds allowed maximum of 4096"); 551 + ") exceeds allowed maximum of 4096");
550 return 0; 552 return 0;
551 } 553 }
552 554
553 return PeriodicWave::create(sampleRate(), real, imag); 555 return PeriodicWave::create(sampleRate(), real, imag);
554 } 556 }
555 557
558 size_t AudioContext::sampleFrame() const
559 {
560 ASSERT(isMainThread());
561
562 return m_shadowCurrentSampleFrame;
563 }
564
556 String AudioContext::state() const 565 String AudioContext::state() const
557 { 566 {
558 // These strings had better match the strings for AudioContextState in Audio Context.idl. 567 // These strings had better match the strings for AudioContextState in Audio Context.idl.
559 switch (m_contextState) { 568 switch (m_contextState) {
560 case Suspended: 569 case Suspended:
561 return "suspended"; 570 return "suspended";
562 case Running: 571 case Running:
563 return "running"; 572 return "running";
564 case Closed: 573 case Closed:
565 return "closed"; 574 return "closed";
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 // Update the channel count mode. 767 // Update the channel count mode.
759 updateChangedChannelCountMode(); 768 updateChangedChannelCountMode();
760 769
761 // Fixup the state of any dirty AudioSummingJunctions and AudioNodeOutpu ts. 770 // Fixup the state of any dirty AudioSummingJunctions and AudioNodeOutpu ts.
762 handleDirtyAudioSummingJunctions(); 771 handleDirtyAudioSummingJunctions();
763 handleDirtyAudioNodeOutputs(); 772 handleDirtyAudioNodeOutputs();
764 773
765 updateAutomaticPullNodes(); 774 updateAutomaticPullNodes();
766 resolvePromisesForResume(); 775 resolvePromisesForResume();
767 776
777 // Update the shadow frame value.
778 m_shadowCurrentSampleFrame = currentSampleFrame();
779
768 unlock(); 780 unlock();
769 } 781 }
770 } 782 }
771 783
772 void AudioContext::handlePostRenderTasks() 784 void AudioContext::handlePostRenderTasks()
773 { 785 {
774 ASSERT(isAudioThread()); 786 ASSERT(isAudioThread());
775 787
776 // Must use a tryLock() here too. Don't worry, the lock will very rarely be contended and this method is called frequently. 788 // Must use a tryLock() here too. Don't worry, the lock will very rarely be contended and this method is called frequently.
777 // The worst that can happen is that there will be some nodes which will tak e slightly longer than usual to be deleted or removed 789 // The worst that can happen is that there will be some nodes which will tak e slightly longer than usual to be deleted or removed
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 1122
1111 for (HashSet<AudioNode*>::iterator k = m_deferredCountModeChange.begin(); k != m_deferredCountModeChange.end(); ++k) 1123 for (HashSet<AudioNode*>::iterator k = m_deferredCountModeChange.begin(); k != m_deferredCountModeChange.end(); ++k)
1112 (*k)->updateChannelCountMode(); 1124 (*k)->updateChannelCountMode();
1113 1125
1114 m_deferredCountModeChange.clear(); 1126 m_deferredCountModeChange.clear();
1115 } 1127 }
1116 1128
1117 } // namespace blink 1129 } // namespace blink
1118 1130
1119 #endif // ENABLE(WEB_AUDIO) 1131 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698