OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/audio/win/waveout_output_win.h" | 5 #include "media/audio/win/waveout_output_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <mmsystem.h> | 8 #include <mmsystem.h> |
9 #pragma comment(lib, "winmm.lib") | 9 #pragma comment(lib, "winmm.lib") |
10 | 10 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 | 272 |
273 // Stop playback. | 273 // Stop playback. |
274 MMRESULT res = ::waveOutReset(waveout_); | 274 MMRESULT res = ::waveOutReset(waveout_); |
275 if (res != MMSYSERR_NOERROR) { | 275 if (res != MMSYSERR_NOERROR) { |
276 state_ = PCMA_PLAYING; | 276 state_ = PCMA_PLAYING; |
277 HandleError(res); | 277 HandleError(res); |
278 return; | 278 return; |
279 } | 279 } |
280 | 280 |
| 281 // Wait for lock to ensure all outstanding callbacks have completed. |
| 282 base::AutoLock auto_lock(lock_); |
| 283 |
281 // waveOutReset() leaves buffers in the unpredictable state, causing | 284 // waveOutReset() leaves buffers in the unpredictable state, causing |
282 // problems if we want to close, release, or reuse them. Fix the states. | 285 // problems if we want to close, release, or reuse them. Fix the states. |
283 for (int ix = 0; ix != num_buffers_; ++ix) { | 286 for (int ix = 0; ix != num_buffers_; ++ix) { |
284 GetBuffer(ix)->dwFlags = WHDR_PREPARED; | 287 GetBuffer(ix)->dwFlags = WHDR_PREPARED; |
285 } | 288 } |
286 | 289 |
287 // Don't use callback after Stop(). | 290 // Don't use callback after Stop(). |
288 callback_ = NULL; | 291 callback_ = NULL; |
289 | 292 |
290 state_ = PCMA_READY; | 293 state_ = PCMA_READY; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 buffer, | 407 buffer, |
405 sizeof(WAVEHDR)); | 408 sizeof(WAVEHDR)); |
406 if (result != MMSYSERR_NOERROR) | 409 if (result != MMSYSERR_NOERROR) |
407 stream->HandleError(result); | 410 stream->HandleError(result); |
408 stream->pending_bytes_ += buffer->dwBufferLength; | 411 stream->pending_bytes_ += buffer->dwBufferLength; |
409 } | 412 } |
410 } | 413 } |
411 } | 414 } |
412 | 415 |
413 } // namespace media | 416 } // namespace media |
OLD | NEW |