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 "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time/time.h" | |
| 9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 10 #include "media/audio/audio_io.h" | 11 #include "media/audio/audio_io.h" |
| 11 #include "media/audio/win/audio_manager_win.h" | 12 #include "media/audio/win/audio_manager_win.h" |
| 12 | 13 |
| 13 namespace media { | 14 namespace media { |
| 14 | 15 |
| 15 // Some general thoughts about the waveOut API which is badly documented : | 16 // Some general thoughts about the waveOut API which is badly documented : |
| 16 // - We use CALLBACK_EVENT mode in which XP signals events such as buffer | 17 // - We use CALLBACK_EVENT mode in which XP signals events such as buffer |
| 17 // releases. | 18 // releases. |
| 18 // - We use RegisterWaitForSingleObject() so one of threads in thread pool | 19 // - We use RegisterWaitForSingleObject() so one of threads in thread pool |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 if (callback_) | 316 if (callback_) |
| 316 callback_->OnError(this); | 317 callback_->OnError(this); |
| 317 } | 318 } |
| 318 | 319 |
| 319 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { | 320 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { |
| 320 DCHECK_EQ(channels_, format_.Format.nChannels); | 321 DCHECK_EQ(channels_, format_.Format.nChannels); |
| 321 // Call the source which will fill our buffer with pleasant sounds and | 322 // Call the source which will fill our buffer with pleasant sounds and |
| 322 // return to us how many bytes were used. | 323 // return to us how many bytes were used. |
| 323 // TODO(fbarchard): Handle used 0 by queueing more. | 324 // TODO(fbarchard): Handle used 0 by queueing more. |
| 324 | 325 |
| 325 // TODO(sergeyu): Specify correct hardware delay for |total_delay_bytes|. | 326 // TODO(sergeyu): Specify correct hardware delay for |delay|. |
| 326 uint32_t total_delay_bytes = pending_bytes_; | 327 const base::TimeDelta delay = base::TimeDelta::FromMicroseconds( |
| 328 pending_bytes_ * base::Time::kMicrosecondsPerSecond / | |
|
chcunningham
2016/09/23 20:53:30
int division
jameswest
2016/09/29 00:52:24
As discussed, this integer division is safe.
| |
| 329 format_.Format.nAvgBytesPerSec); | |
| 327 int frames_filled = | 330 int frames_filled = |
| 328 callback_->OnMoreData(audio_bus_.get(), total_delay_bytes, 0); | 331 callback_->OnMoreData(delay, base::TimeTicks::Now(), 0, audio_bus_.get()); |
| 329 uint32_t used = frames_filled * audio_bus_->channels() * | 332 uint32_t used = frames_filled * audio_bus_->channels() * |
| 330 format_.Format.wBitsPerSample / 8; | 333 format_.Format.wBitsPerSample / 8; |
| 331 | 334 |
| 332 if (used <= buffer_size_) { | 335 if (used <= buffer_size_) { |
| 333 // Note: If this ever changes to output raw float the data must be clipped | 336 // Note: If this ever changes to output raw float the data must be clipped |
| 334 // and sanitized since it may come from an untrusted source such as NaCl. | 337 // and sanitized since it may come from an untrusted source such as NaCl. |
| 335 audio_bus_->Scale(volume_); | 338 audio_bus_->Scale(volume_); |
| 336 audio_bus_->ToInterleaved( | 339 audio_bus_->ToInterleaved( |
| 337 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); | 340 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); |
| 338 | 341 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 buffer, | 388 buffer, |
| 386 sizeof(WAVEHDR)); | 389 sizeof(WAVEHDR)); |
| 387 if (result != MMSYSERR_NOERROR) | 390 if (result != MMSYSERR_NOERROR) |
| 388 stream->HandleError(result); | 391 stream->HandleError(result); |
| 389 stream->pending_bytes_ += buffer->dwBufferLength; | 392 stream->pending_bytes_ += buffer->dwBufferLength; |
| 390 } | 393 } |
| 391 } | 394 } |
| 392 } | 395 } |
| 393 | 396 |
| 394 } // namespace media | 397 } // namespace media |
| OLD | NEW |