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 / |
| 329 format_.Format.nAvgBytesPerSec); |
| 330 const base::TimeTicks target_playout_time = base::TimeTicks::Now() + delay; |
327 int frames_filled = | 331 int frames_filled = |
328 callback_->OnMoreData(audio_bus_.get(), total_delay_bytes, 0); | 332 callback_->OnMoreData(target_playout_time, 0, audio_bus_.get()); |
329 uint32_t used = frames_filled * audio_bus_->channels() * | 333 uint32_t used = frames_filled * audio_bus_->channels() * |
330 format_.Format.wBitsPerSample / 8; | 334 format_.Format.wBitsPerSample / 8; |
331 | 335 |
332 if (used <= buffer_size_) { | 336 if (used <= buffer_size_) { |
333 // Note: If this ever changes to output raw float the data must be clipped | 337 // 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. | 338 // and sanitized since it may come from an untrusted source such as NaCl. |
335 audio_bus_->Scale(volume_); | 339 audio_bus_->Scale(volume_); |
336 audio_bus_->ToInterleaved( | 340 audio_bus_->ToInterleaved( |
337 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); | 341 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); |
338 | 342 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 buffer, | 389 buffer, |
386 sizeof(WAVEHDR)); | 390 sizeof(WAVEHDR)); |
387 if (result != MMSYSERR_NOERROR) | 391 if (result != MMSYSERR_NOERROR) |
388 stream->HandleError(result); | 392 stream->HandleError(result); |
389 stream->pending_bytes_ += buffer->dwBufferLength; | 393 stream->pending_bytes_ += buffer->dwBufferLength; |
390 } | 394 } |
391 } | 395 } |
392 } | 396 } |
393 | 397 |
394 } // namespace media | 398 } // namespace media |
OLD | NEW |