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

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

Issue 1149913002: Access current frame counter carefully and remove m_cachedSampleFrame. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove workaround in scriptprocessornode test Created 5 years, 7 months 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
« no previous file with comments | « Source/modules/webaudio/AudioContext.h ('k') | Source/modules/webaudio/AudioDestinationNode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_connectionCount(0) 107 , m_connectionCount(0)
108 , m_didInitializeContextGraphMutex(false) 108 , m_didInitializeContextGraphMutex(false)
109 , m_deferredTaskHandler(DeferredTaskHandler::create()) 109 , m_deferredTaskHandler(DeferredTaskHandler::create())
110 , m_isOfflineContext(false) 110 , m_isOfflineContext(false)
111 , m_contextState(Suspended) 111 , m_contextState(Suspended)
112 , m_cachedSampleFrame(0)
113 { 112 {
114 m_didInitializeContextGraphMutex = true; 113 m_didInitializeContextGraphMutex = true;
115 m_destinationNode = DefaultAudioDestinationNode::create(this); 114 m_destinationNode = DefaultAudioDestinationNode::create(this);
116 115
117 initialize(); 116 initialize();
118 } 117 }
119 118
120 // Constructor for offline (non-realtime) rendering. 119 // Constructor for offline (non-realtime) rendering.
121 AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate) 120 AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
122 : ActiveDOMObject(document) 121 : ActiveDOMObject(document)
123 , m_isStopScheduled(false) 122 , m_isStopScheduled(false)
124 , m_isCleared(false) 123 , m_isCleared(false)
125 , m_isInitialized(false) 124 , m_isInitialized(false)
126 , m_destinationNode(nullptr) 125 , m_destinationNode(nullptr)
127 , m_isResolvingResumePromises(false) 126 , m_isResolvingResumePromises(false)
128 , m_connectionCount(0) 127 , m_connectionCount(0)
129 , m_didInitializeContextGraphMutex(false) 128 , m_didInitializeContextGraphMutex(false)
130 , m_deferredTaskHandler(DeferredTaskHandler::create()) 129 , m_deferredTaskHandler(DeferredTaskHandler::create())
131 , m_isOfflineContext(true) 130 , m_isOfflineContext(true)
132 , m_contextState(Suspended) 131 , m_contextState(Suspended)
133 , m_cachedSampleFrame(0)
134 { 132 {
135 m_didInitializeContextGraphMutex = true; 133 m_didInitializeContextGraphMutex = true;
136 // Create a new destination for offline rendering. 134 // Create a new destination for offline rendering.
137 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate); 135 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate);
138 if (m_renderTarget.get()) 136 if (m_renderTarget.get())
139 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get()); 137 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get());
140 138
141 initialize(); 139 initialize();
142 } 140 }
143 141
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 IndexSizeError, 670 IndexSizeError,
673 "length of real array (" + String::number(real->length()) 671 "length of real array (" + String::number(real->length())
674 + ") and length of imaginary array (" + String::number(imag->length ()) 672 + ") and length of imaginary array (" + String::number(imag->length ())
675 + ") must match."); 673 + ") must match.");
676 return nullptr; 674 return nullptr;
677 } 675 }
678 676
679 return PeriodicWave::create(sampleRate(), real, imag); 677 return PeriodicWave::create(sampleRate(), real, imag);
680 } 678 }
681 679
682 size_t AudioContext::currentSampleFrame() const
683 {
684 if (isAudioThread())
685 return m_destinationNode ? m_destinationNode->audioDestinationHandler(). currentSampleFrame() : 0;
686
687 return m_cachedSampleFrame;
688 }
689
690 double AudioContext::currentTime() const
691 {
692 if (isAudioThread())
693 return m_destinationNode ? m_destinationNode->audioDestinationHandler(). currentTime() : 0;
694
695 return m_cachedSampleFrame / static_cast<double>(sampleRate());
696 }
697
698 String AudioContext::state() const 680 String AudioContext::state() const
699 { 681 {
700 // These strings had better match the strings for AudioContextState in Audio Context.idl. 682 // These strings had better match the strings for AudioContextState in Audio Context.idl.
701 switch (m_contextState) { 683 switch (m_contextState) {
702 case Suspended: 684 case Suspended:
703 return "suspended"; 685 return "suspended";
704 case Running: 686 case Running:
705 return "running"; 687 return "running";
706 case Closed: 688 case Closed:
707 return "closed"; 689 return "closed";
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 // At the beginning of every render quantum, try to update the internal rend ering graph state (from main thread changes). 855 // At the beginning of every render quantum, try to update the internal rend ering graph state (from main thread changes).
874 // It's OK if the tryLock() fails, we'll just take slightly longer to pick u p the changes. 856 // It's OK if the tryLock() fails, we'll just take slightly longer to pick u p the changes.
875 if (tryLock()) { 857 if (tryLock()) {
876 deferredTaskHandler().handleDeferredTasks(); 858 deferredTaskHandler().handleDeferredTasks();
877 859
878 resolvePromisesForResume(); 860 resolvePromisesForResume();
879 861
880 // Check to see if source nodes can be stopped because the end time has passed. 862 // Check to see if source nodes can be stopped because the end time has passed.
881 handleStoppableSourceNodes(); 863 handleStoppableSourceNodes();
882 864
883 // Update the cached sample frame value.
884 m_cachedSampleFrame = currentSampleFrame();
885
886 unlock(); 865 unlock();
887 } 866 }
888 } 867 }
889 868
890 void AudioContext::handlePostRenderTasks() 869 void AudioContext::handlePostRenderTasks()
891 { 870 {
892 ASSERT(isAudioThread()); 871 ASSERT(isAudioThread());
893 872
894 // Must use a tryLock() here too. Don't worry, the lock will very rarely be contended and this method is called frequently. 873 // Must use a tryLock() here too. Don't worry, the lock will very rarely be contended and this method is called frequently.
895 // 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 874 // 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 // the destination node can GCed if JS has no references. stop() will also r esolve the Promise 1045 // the destination node can GCed if JS has no references. stop() will also r esolve the Promise
1067 // created here. 1046 // created here.
1068 stop(); 1047 stop();
1069 1048
1070 return promise; 1049 return promise;
1071 } 1050 }
1072 1051
1073 } // namespace blink 1052 } // namespace blink
1074 1053
1075 #endif // ENABLE(WEB_AUDIO) 1054 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioContext.h ('k') | Source/modules/webaudio/AudioDestinationNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698