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

Side by Side Diff: Source/core/platform/audio/AudioDSPKernelProcessor.cpp

Issue 23931002: Fix threading races on AudioDSPKernelProcessor::m_kernels (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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/core/platform/audio/AudioDSPKernelProcessor.h ('k') | no next file » | 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 : AudioProcessor(sampleRate, numberOfChannels) 43 : AudioProcessor(sampleRate, numberOfChannels)
44 , m_hasJustReset(true) 44 , m_hasJustReset(true)
45 { 45 {
46 } 46 }
47 47
48 void AudioDSPKernelProcessor::initialize() 48 void AudioDSPKernelProcessor::initialize()
49 { 49 {
50 if (isInitialized()) 50 if (isInitialized())
51 return; 51 return;
52 52
53 MutexLocker locker(m_processLock);
53 ASSERT(!m_kernels.size()); 54 ASSERT(!m_kernels.size());
54 55
55 // Create processing kernels, one per channel. 56 // Create processing kernels, one per channel.
56 for (unsigned i = 0; i < numberOfChannels(); ++i) 57 for (unsigned i = 0; i < numberOfChannels(); ++i)
57 m_kernels.append(createKernel()); 58 m_kernels.append(createKernel());
58 59
59 m_initialized = true; 60 m_initialized = true;
60 m_hasJustReset = true; 61 m_hasJustReset = true;
61 } 62 }
62 63
63 void AudioDSPKernelProcessor::uninitialize() 64 void AudioDSPKernelProcessor::uninitialize()
64 { 65 {
65 if (!isInitialized()) 66 if (!isInitialized())
66 return; 67 return;
67 68
69 MutexLocker locker(m_processLock);
68 m_kernels.clear(); 70 m_kernels.clear();
69 71
70 m_initialized = false; 72 m_initialized = false;
71 } 73 }
72 74
73 void AudioDSPKernelProcessor::process(const AudioBus* source, AudioBus* destinat ion, size_t framesToProcess) 75 void AudioDSPKernelProcessor::process(const AudioBus* source, AudioBus* destinat ion, size_t framesToProcess)
74 { 76 {
75 ASSERT(source && destination); 77 ASSERT(source && destination);
76 if (!source || !destination) 78 if (!source || !destination)
77 return; 79 return;
78 80
79 if (!isInitialized()) { 81 if (!isInitialized()) {
80 destination->zero(); 82 destination->zero();
81 return; 83 return;
82 } 84 }
83 85
84 bool channelCountMatches = source->numberOfChannels() == destination->number OfChannels() && source->numberOfChannels() == m_kernels.size(); 86 MutexTryLocker tryLocker(m_processLock);
85 ASSERT(channelCountMatches); 87 if (tryLocker.locked()) {
86 if (!channelCountMatches) 88 bool channelCountMatches = source->numberOfChannels() == destination->nu mberOfChannels() && source->numberOfChannels() == m_kernels.size();
87 return; 89 ASSERT(channelCountMatches);
90 if (!channelCountMatches)
91 return;
88 92
89 for (unsigned i = 0; i < m_kernels.size(); ++i) 93 for (unsigned i = 0; i < m_kernels.size(); ++i)
90 m_kernels[i]->process(source->channel(i)->data(), destination->channel(i )->mutableData(), framesToProcess); 94 m_kernels[i]->process(source->channel(i)->data(), destination->chann el(i)->mutableData(), framesToProcess);
95 } else {
96 // Unfortunately, the kernel is being processed by another thread.
97 // See also ConvolverNode::process().
98 destination->zero();
99 }
91 } 100 }
92 101
93 // Resets filter state 102 // Resets filter state
94 void AudioDSPKernelProcessor::reset() 103 void AudioDSPKernelProcessor::reset()
Ken Russell (switch to Gerrit) 2013/09/04 18:18:46 Please add an assertion that this is called on the
haraken 2013/09/04 19:50:05 Done.
95 { 104 {
96 if (!isInitialized()) 105 if (!isInitialized())
97 return; 106 return;
98 107
99 // Forces snap to parameter values - first time. 108 // Forces snap to parameter values - first time.
100 // Any processing depending on this value must set it to false at the approp riate time. 109 // Any processing depending on this value must set it to false at the approp riate time.
101 m_hasJustReset = true; 110 m_hasJustReset = true;
102 111
112 MutexLocker locker(m_processLock);
103 for (unsigned i = 0; i < m_kernels.size(); ++i) 113 for (unsigned i = 0; i < m_kernels.size(); ++i)
104 m_kernels[i]->reset(); 114 m_kernels[i]->reset();
105 } 115 }
106 116
107 void AudioDSPKernelProcessor::setNumberOfChannels(unsigned numberOfChannels) 117 void AudioDSPKernelProcessor::setNumberOfChannels(unsigned numberOfChannels)
108 { 118 {
109 if (numberOfChannels == m_numberOfChannels) 119 if (numberOfChannels == m_numberOfChannels)
110 return; 120 return;
111 121
112 ASSERT(!isInitialized()); 122 ASSERT(!isInitialized());
113 if (!isInitialized()) 123 if (!isInitialized())
114 m_numberOfChannels = numberOfChannels; 124 m_numberOfChannels = numberOfChannels;
115 } 125 }
116 126
117 double AudioDSPKernelProcessor::tailTime() const 127 double AudioDSPKernelProcessor::tailTime() const
118 { 128 {
129 MutexLocker locker(m_processLock);
Ken Russell (switch to Gerrit) 2013/09/04 18:18:46 I believe this is called on the audio thread and t
haraken 2013/09/04 19:50:05 Done.
119 // It is expected that all the kernels have the same tailTime. 130 // It is expected that all the kernels have the same tailTime.
120 return !m_kernels.isEmpty() ? m_kernels.first()->tailTime() : 0; 131 return !m_kernels.isEmpty() ? m_kernels.first()->tailTime() : 0;
121 } 132 }
122 133
123 double AudioDSPKernelProcessor::latencyTime() const 134 double AudioDSPKernelProcessor::latencyTime() const
124 { 135 {
136 MutexLocker locker(m_processLock);
Ken Russell (switch to Gerrit) 2013/09/04 18:18:46 trylock needed here too.
haraken 2013/09/04 19:50:05 Done.
125 // It is expected that all the kernels have the same latencyTime. 137 // It is expected that all the kernels have the same latencyTime.
126 return !m_kernels.isEmpty() ? m_kernels.first()->latencyTime() : 0; 138 return !m_kernels.isEmpty() ? m_kernels.first()->latencyTime() : 0;
127 } 139 }
128 140
129 } // namespace WebCore 141 } // namespace WebCore
130 142
131 #endif // ENABLE(WEB_AUDIO) 143 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/core/platform/audio/AudioDSPKernelProcessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698