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

Side by Side Diff: media/audio/win/waveout_output_win.cc

Issue 173022: Possible deadlock in PCM audio Start() method... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | « media/audio/win/audio_output_win_unittest.cc ('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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 #include <mmsystem.h> 6 #include <mmsystem.h>
7 #pragma comment(lib, "winmm.lib") 7 #pragma comment(lib, "winmm.lib")
8 8
9 #include "media/audio/win/waveout_output_win.h" 9 #include "media/audio/win/waveout_output_win.h"
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (state_ != PCMA_READY) 146 if (state_ != PCMA_READY)
147 return; 147 return;
148 callback_ = callback; 148 callback_ = callback;
149 state_ = PCMA_PLAYING; 149 state_ = PCMA_PLAYING;
150 WAVEHDR* buffer = buffer_; 150 WAVEHDR* buffer = buffer_;
151 for (int ix = 0; ix != kNumBuffers; ++ix) { 151 for (int ix = 0; ix != kNumBuffers; ++ix) {
152 QueueNextPacket(buffer); // Read more data. 152 QueueNextPacket(buffer); // Read more data.
153 buffer = GetNextBuffer(buffer); 153 buffer = GetNextBuffer(buffer);
154 } 154 }
155 buffer = buffer_; 155 buffer = buffer_;
156 156 MMRESULT result = ::waveOutPause(waveout_);
157 // Send the buffers to the audio driver. 157 if (result != MMSYSERR_NOERROR) {
158 HandleError(result);
159 return;
160 }
161 // Send the buffers to the audio driver. Note that the device is paused
162 // so we avoid entering the callback method while still here.
158 for (int ix = 0; ix != kNumBuffers; ++ix) { 163 for (int ix = 0; ix != kNumBuffers; ++ix) {
159 MMRESULT result = ::waveOutWrite(waveout_, buffer, sizeof(WAVEHDR)); 164 result = ::waveOutWrite(waveout_, buffer, sizeof(WAVEHDR));
160 if (result != MMSYSERR_NOERROR) { 165 if (result != MMSYSERR_NOERROR) {
161 HandleError(result); 166 HandleError(result);
162 break; 167 break;
163 } 168 }
164 buffer = GetNextBuffer(buffer); 169 buffer = GetNextBuffer(buffer);
165 } 170 }
171 result = ::waveOutRestart(waveout_);
172 if (result != MMSYSERR_NOERROR) {
173 HandleError(result);
174 return;
175 }
166 } 176 }
167 177
168 // Stopping is tricky. First, no buffer should be locked by the audio driver 178 // Stopping is tricky. First, no buffer should be locked by the audio driver
169 // or else the waveOutReset will deadlock and secondly, the callback should not 179 // or else the waveOutReset will deadlock and secondly, the callback should not
170 // be inside the AudioSource's OnMoreData because waveOutReset() forcefully 180 // be inside the AudioSource's OnMoreData because waveOutReset() forcefully
171 // kills the callback thread. 181 // kills the callback thread.
172 void PCMWaveOutAudioOutputStream::Stop() { 182 void PCMWaveOutAudioOutputStream::Stop() {
173 if (state_ != PCMA_PLAYING) 183 if (state_ != PCMA_PLAYING)
174 return; 184 return;
175 state_ = PCMA_STOPPING; 185 state_ = PCMA_STOPPING;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (result != MMSYSERR_NOERROR) 296 if (result != MMSYSERR_NOERROR)
287 obj->HandleError(result); 297 obj->HandleError(result);
288 298
289 } else if (msg == WOM_CLOSE) { 299 } else if (msg == WOM_CLOSE) {
290 // We can be closed before calling Start, so it is possible to have a 300 // We can be closed before calling Start, so it is possible to have a
291 // null callback at this point. 301 // null callback at this point.
292 if (obj->callback_) 302 if (obj->callback_)
293 obj->callback_->OnClose(obj); 303 obj->callback_->OnClose(obj);
294 } 304 }
295 } 305 }
OLDNEW
« no previous file with comments | « media/audio/win/audio_output_win_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698