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 #pragma comment(lib, "winmm.lib") | 7 #pragma comment(lib, "winmm.lib") |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/basictypes.h" | |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
13 #include "media/audio/audio_io.h" | 12 #include "media/audio/audio_io.h" |
14 #include "media/audio/win/audio_manager_win.h" | 13 #include "media/audio/win/audio_manager_win.h" |
15 | 14 |
16 namespace media { | 15 namespace media { |
17 | 16 |
18 // Some general thoughts about the waveOut API which is badly documented : | 17 // Some general thoughts about the waveOut API which is badly documented : |
19 // - We use CALLBACK_EVENT mode in which XP signals events such as buffer | 18 // - We use CALLBACK_EVENT mode in which XP signals events such as buffer |
20 // releases. | 19 // releases. |
21 // - We use RegisterWaitForSingleObject() so one of threads in thread pool | 20 // - We use RegisterWaitForSingleObject() so one of threads in thread pool |
22 // automatically calls our callback that feeds more data to Windows. | 21 // automatically calls our callback that feeds more data to Windows. |
23 // - Windows does not provide a way to query if the device is playing or paused | 22 // - Windows does not provide a way to query if the device is playing or paused |
24 // thus it forces you to maintain state, which naturally is not exactly | 23 // thus it forces you to maintain state, which naturally is not exactly |
25 // synchronized to the actual device state. | 24 // synchronized to the actual device state. |
26 | 25 |
27 // Sixty four MB is the maximum buffer size per AudioOutputStream. | 26 // Sixty four MB is the maximum buffer size per AudioOutputStream. |
28 static const uint32 kMaxOpenBufferSize = 1024 * 1024 * 64; | 27 static const uint32_t kMaxOpenBufferSize = 1024 * 1024 * 64; |
29 | 28 |
30 // See Also | 29 // See Also |
31 // http://www.thx.com/consumer/home-entertainment/home-theater/surround-sound-sp
eaker-set-up/ | 30 // http://www.thx.com/consumer/home-entertainment/home-theater/surround-sound-sp
eaker-set-up/ |
32 // http://en.wikipedia.org/wiki/Surround_sound | 31 // http://en.wikipedia.org/wiki/Surround_sound |
33 | 32 |
34 static const int kMaxChannelsToMask = 8; | 33 static const int kMaxChannelsToMask = 8; |
35 static const unsigned int kChannelsToMask[kMaxChannelsToMask + 1] = { | 34 static const unsigned int kChannelsToMask[kMaxChannelsToMask + 1] = { |
36 0, | 35 0, |
37 // 1 = Mono | 36 // 1 = Mono |
38 SPEAKER_FRONT_CENTER, | 37 SPEAKER_FRONT_CENTER, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 callback_->OnError(this); | 318 callback_->OnError(this); |
320 } | 319 } |
321 | 320 |
322 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { | 321 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { |
323 DCHECK_EQ(channels_, format_.Format.nChannels); | 322 DCHECK_EQ(channels_, format_.Format.nChannels); |
324 // Call the source which will fill our buffer with pleasant sounds and | 323 // Call the source which will fill our buffer with pleasant sounds and |
325 // return to us how many bytes were used. | 324 // return to us how many bytes were used. |
326 // TODO(fbarchard): Handle used 0 by queueing more. | 325 // TODO(fbarchard): Handle used 0 by queueing more. |
327 | 326 |
328 // TODO(sergeyu): Specify correct hardware delay for |total_delay_bytes|. | 327 // TODO(sergeyu): Specify correct hardware delay for |total_delay_bytes|. |
329 uint32 total_delay_bytes = pending_bytes_; | 328 uint32_t total_delay_bytes = pending_bytes_; |
330 int frames_filled = | 329 int frames_filled = |
331 callback_->OnMoreData(audio_bus_.get(), total_delay_bytes, 0); | 330 callback_->OnMoreData(audio_bus_.get(), total_delay_bytes, 0); |
332 uint32 used = frames_filled * audio_bus_->channels() * | 331 uint32_t used = frames_filled * audio_bus_->channels() * |
333 format_.Format.wBitsPerSample / 8; | 332 format_.Format.wBitsPerSample / 8; |
334 | 333 |
335 if (used <= buffer_size_) { | 334 if (used <= buffer_size_) { |
336 // Note: If this ever changes to output raw float the data must be clipped | 335 // Note: If this ever changes to output raw float the data must be clipped |
337 // and sanitized since it may come from an untrusted source such as NaCl. | 336 // and sanitized since it may come from an untrusted source such as NaCl. |
338 audio_bus_->Scale(volume_); | 337 audio_bus_->Scale(volume_); |
339 audio_bus_->ToInterleaved( | 338 audio_bus_->ToInterleaved( |
340 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); | 339 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); |
341 | 340 |
342 buffer->dwBufferLength = used * format_.Format.nChannels / channels_; | 341 buffer->dwBufferLength = used * format_.Format.nChannels / channels_; |
343 } else { | 342 } else { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 buffer, | 387 buffer, |
389 sizeof(WAVEHDR)); | 388 sizeof(WAVEHDR)); |
390 if (result != MMSYSERR_NOERROR) | 389 if (result != MMSYSERR_NOERROR) |
391 stream->HandleError(result); | 390 stream->HandleError(result); |
392 stream->pending_bytes_ += buffer->dwBufferLength; | 391 stream->pending_bytes_ += buffer->dwBufferLength; |
393 } | 392 } |
394 } | 393 } |
395 } | 394 } |
396 | 395 |
397 } // namespace media | 396 } // namespace media |
OLD | NEW |