| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // Round size of buffer up to the nearest 16 bytes. | 69 // Round size of buffer up to the nearest 16 bytes. |
| 70 return (sizeof(WAVEHDR) + buffer_size_ + 15u) & static_cast<size_t>(~15); | 70 return (sizeof(WAVEHDR) + buffer_size_ + 15u) & static_cast<size_t>(~15); |
| 71 } | 71 } |
| 72 | 72 |
| 73 inline WAVEHDR* PCMWaveOutAudioOutputStream::GetBuffer(int n) const { | 73 inline WAVEHDR* PCMWaveOutAudioOutputStream::GetBuffer(int n) const { |
| 74 DCHECK_GE(n, 0); | 74 DCHECK_GE(n, 0); |
| 75 DCHECK_LT(n, num_buffers_); | 75 DCHECK_LT(n, num_buffers_); |
| 76 return reinterpret_cast<WAVEHDR*>(&buffers_[n * BufferSize()]); | 76 return reinterpret_cast<WAVEHDR*>(&buffers_[n * BufferSize()]); |
| 77 } | 77 } |
| 78 | 78 |
| 79 | |
| 80 PCMWaveOutAudioOutputStream::PCMWaveOutAudioOutputStream( | 79 PCMWaveOutAudioOutputStream::PCMWaveOutAudioOutputStream( |
| 81 AudioManagerWin* manager, const AudioParameters& params, int num_buffers, | 80 AudioManagerWin* manager, const AudioParameters& params, int num_buffers, |
| 82 UINT device_id) | 81 UINT device_id) |
| 83 : state_(PCMA_BRAND_NEW), | 82 : state_(PCMA_BRAND_NEW), |
| 84 manager_(manager), | 83 manager_(manager), |
| 85 device_id_(device_id), | 84 device_id_(device_id), |
| 86 waveout_(NULL), | 85 waveout_(NULL), |
| 87 callback_(NULL), | 86 callback_(NULL), |
| 88 num_buffers_(num_buffers), | 87 num_buffers_(num_buffers), |
| 89 buffer_size_(params.GetBytesPerBuffer()), | 88 buffer_size_(params.GetBytesPerBuffer()), |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 if (callback_) | 334 if (callback_) |
| 336 callback_->OnError(this, error); | 335 callback_->OnError(this, error); |
| 337 } | 336 } |
| 338 | 337 |
| 339 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { | 338 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { |
| 340 DCHECK_EQ(channels_, format_.Format.nChannels); | 339 DCHECK_EQ(channels_, format_.Format.nChannels); |
| 341 // Call the source which will fill our buffer with pleasant sounds and | 340 // Call the source which will fill our buffer with pleasant sounds and |
| 342 // return to us how many bytes were used. | 341 // return to us how many bytes were used. |
| 343 // TODO(fbarchard): Handle used 0 by queueing more. | 342 // TODO(fbarchard): Handle used 0 by queueing more. |
| 344 | 343 |
| 344 // HACK: Yield if Read() is called too often. On older platforms which are |
| 345 // still using the WaveOut backend, we run into synchronization issues where |
| 346 // the renderer has not finished filling the shared memory when Read() is |
| 347 // called. Reading too early will lead to clicks and pops. See issues: |
| 348 // http://crbug.com/161307 and http://crbug.com/61022 |
| 349 callback_->WaitTillDataReady(); |
| 350 |
| 345 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. | 351 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. |
| 346 int frames_filled = callback_->OnMoreData( | 352 int frames_filled = callback_->OnMoreData( |
| 347 audio_bus_.get(), AudioBuffersState(pending_bytes_, 0)); | 353 audio_bus_.get(), AudioBuffersState(pending_bytes_, 0)); |
| 348 uint32 used = frames_filled * audio_bus_->channels() * | 354 uint32 used = frames_filled * audio_bus_->channels() * |
| 349 format_.Format.wBitsPerSample / 8; | 355 format_.Format.wBitsPerSample / 8; |
| 350 | 356 |
| 351 if (used <= buffer_size_) { | 357 if (used <= buffer_size_) { |
| 352 // Note: If this ever changes to output raw float the data must be clipped | 358 // Note: If this ever changes to output raw float the data must be clipped |
| 353 // and sanitized since it may come from an untrusted source such as NaCl. | 359 // and sanitized since it may come from an untrusted source such as NaCl. |
| 354 audio_bus_->ToInterleaved( | 360 audio_bus_->ToInterleaved( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 buffer, | 413 buffer, |
| 408 sizeof(WAVEHDR)); | 414 sizeof(WAVEHDR)); |
| 409 if (result != MMSYSERR_NOERROR) | 415 if (result != MMSYSERR_NOERROR) |
| 410 stream->HandleError(result); | 416 stream->HandleError(result); |
| 411 stream->pending_bytes_ += buffer->dwBufferLength; | 417 stream->pending_bytes_ += buffer->dwBufferLength; |
| 412 } | 418 } |
| 413 } | 419 } |
| 414 } | 420 } |
| 415 | 421 |
| 416 } // namespace media | 422 } // namespace media |
| OLD | NEW |