Chromium Code Reviews| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 waiting_handle_ = NULL; | 197 waiting_handle_ = NULL; |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 state_ = PCMA_PLAYING; | 201 state_ = PCMA_PLAYING; |
| 202 | 202 |
| 203 // Queue the buffers. | 203 // Queue the buffers. |
| 204 pending_bytes_ = 0; | 204 pending_bytes_ = 0; |
| 205 for (int ix = 0; ix != num_buffers_; ++ix) { | 205 for (int ix = 0; ix != num_buffers_; ++ix) { |
| 206 WAVEHDR* buffer = GetBuffer(ix); | 206 WAVEHDR* buffer = GetBuffer(ix); |
| 207 // Caller waits for 1st packet to become available, but not for others, | |
| 208 // so we wait for them here. | |
| 209 if (ix != 0) | |
|
henrika (OOO until Aug 14)
2013/06/03 07:57:18
Great that you was able to get rid of this one.
| |
| 210 callback_->WaitTillDataReady(); | |
| 211 QueueNextPacket(buffer); // Read more data. | 207 QueueNextPacket(buffer); // Read more data. |
| 212 pending_bytes_ += buffer->dwBufferLength; | 208 pending_bytes_ += buffer->dwBufferLength; |
| 213 } | 209 } |
| 214 | 210 |
| 215 // From now on |pending_bytes_| would be accessed by callback thread. | 211 // From now on |pending_bytes_| would be accessed by callback thread. |
| 216 // Most likely waveOutPause() or waveOutRestart() has its own memory barrier, | 212 // Most likely waveOutPause() or waveOutRestart() has its own memory barrier, |
| 217 // but issuing our own is safer. | 213 // but issuing our own is safer. |
| 218 base::subtle::MemoryBarrier(); | 214 base::subtle::MemoryBarrier(); |
| 219 | 215 |
| 220 MMRESULT result = ::waveOutPause(waveout_); | 216 MMRESULT result = ::waveOutPause(waveout_); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 if (callback_) | 332 if (callback_) |
| 337 callback_->OnError(this); | 333 callback_->OnError(this); |
| 338 } | 334 } |
| 339 | 335 |
| 340 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { | 336 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { |
| 341 DCHECK_EQ(channels_, format_.Format.nChannels); | 337 DCHECK_EQ(channels_, format_.Format.nChannels); |
| 342 // Call the source which will fill our buffer with pleasant sounds and | 338 // Call the source which will fill our buffer with pleasant sounds and |
| 343 // return to us how many bytes were used. | 339 // return to us how many bytes were used. |
| 344 // TODO(fbarchard): Handle used 0 by queueing more. | 340 // TODO(fbarchard): Handle used 0 by queueing more. |
| 345 | 341 |
| 346 // HACK: Yield if Read() is called too often. On older platforms which are | |
| 347 // still using the WaveOut backend, we run into synchronization issues where | |
| 348 // the renderer has not finished filling the shared memory when Read() is | |
| 349 // called. Reading too early will lead to clicks and pops. See issues: | |
| 350 // http://crbug.com/161307 and http://crbug.com/61022 | |
| 351 callback_->WaitTillDataReady(); | |
| 352 | |
| 353 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. | 342 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. |
| 354 int frames_filled = callback_->OnMoreData( | 343 int frames_filled = callback_->OnMoreData( |
| 355 audio_bus_.get(), AudioBuffersState(pending_bytes_, 0)); | 344 audio_bus_.get(), AudioBuffersState(pending_bytes_, 0)); |
| 356 uint32 used = frames_filled * audio_bus_->channels() * | 345 uint32 used = frames_filled * audio_bus_->channels() * |
| 357 format_.Format.wBitsPerSample / 8; | 346 format_.Format.wBitsPerSample / 8; |
| 358 | 347 |
| 359 if (used <= buffer_size_) { | 348 if (used <= buffer_size_) { |
| 360 // Note: If this ever changes to output raw float the data must be clipped | 349 // Note: If this ever changes to output raw float the data must be clipped |
| 361 // and sanitized since it may come from an untrusted source such as NaCl. | 350 // and sanitized since it may come from an untrusted source such as NaCl. |
| 362 audio_bus_->Scale(volume_); | 351 audio_bus_->Scale(volume_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 buffer, | 401 buffer, |
| 413 sizeof(WAVEHDR)); | 402 sizeof(WAVEHDR)); |
| 414 if (result != MMSYSERR_NOERROR) | 403 if (result != MMSYSERR_NOERROR) |
| 415 stream->HandleError(result); | 404 stream->HandleError(result); |
| 416 stream->pending_bytes_ += buffer->dwBufferLength; | 405 stream->pending_bytes_ += buffer->dwBufferLength; |
| 417 } | 406 } |
| 418 } | 407 } |
| 419 } | 408 } |
| 420 | 409 |
| 421 } // namespace media | 410 } // namespace media |
| OLD | NEW |