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 |
11 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
16 #include "media/audio/audio_util.h" | |
17 #include "media/audio/win/audio_manager_win.h" | 16 #include "media/audio/win/audio_manager_win.h" |
18 | 17 |
19 namespace media { | 18 namespace media { |
20 | 19 |
21 // Some general thoughts about the waveOut API which is badly documented : | 20 // Some general thoughts about the waveOut API which is badly documented : |
22 // - We use CALLBACK_EVENT mode in which XP signals events such as buffer | 21 // - We use CALLBACK_EVENT mode in which XP signals events such as buffer |
23 // releases. | 22 // releases. |
24 // - We use RegisterWaitForSingleObject() so one of threads in thread pool | 23 // - We use RegisterWaitForSingleObject() so one of threads in thread pool |
25 // automatically calls our callback that feeds more data to Windows. | 24 // automatically calls our callback that feeds more data to Windows. |
26 // - Windows does not provide a way to query if the device is playing or paused | 25 // - Windows does not provide a way to query if the device is playing or paused |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 352 |
354 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. | 353 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. |
355 int frames_filled = callback_->OnMoreData( | 354 int frames_filled = callback_->OnMoreData( |
356 audio_bus_.get(), AudioBuffersState(pending_bytes_, 0)); | 355 audio_bus_.get(), AudioBuffersState(pending_bytes_, 0)); |
357 uint32 used = frames_filled * audio_bus_->channels() * | 356 uint32 used = frames_filled * audio_bus_->channels() * |
358 format_.Format.wBitsPerSample / 8; | 357 format_.Format.wBitsPerSample / 8; |
359 | 358 |
360 if (used <= buffer_size_) { | 359 if (used <= buffer_size_) { |
361 // Note: If this ever changes to output raw float the data must be clipped | 360 // Note: If this ever changes to output raw float the data must be clipped |
362 // and sanitized since it may come from an untrusted source such as NaCl. | 361 // and sanitized since it may come from an untrusted source such as NaCl. |
| 362 audio_bus_->Scale(volume_); |
363 audio_bus_->ToInterleaved( | 363 audio_bus_->ToInterleaved( |
364 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); | 364 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData); |
365 | 365 |
366 buffer->dwBufferLength = used * format_.Format.nChannels / channels_; | 366 buffer->dwBufferLength = used * format_.Format.nChannels / channels_; |
367 media::AdjustVolume(buffer->lpData, used, | |
368 format_.Format.nChannels, | |
369 format_.Format.wBitsPerSample >> 3, | |
370 volume_); | |
371 } else { | 367 } else { |
372 HandleError(0); | 368 HandleError(0); |
373 return; | 369 return; |
374 } | 370 } |
375 buffer->dwFlags = WHDR_PREPARED; | 371 buffer->dwFlags = WHDR_PREPARED; |
376 } | 372 } |
377 | 373 |
378 // One of the threads in our thread pool asynchronously calls this function when | 374 // One of the threads in our thread pool asynchronously calls this function when |
379 // buffer_event_ is signalled. Search through all the buffers looking for freed | 375 // buffer_event_ is signalled. Search through all the buffers looking for freed |
380 // ones, fills them with data, and "feed" the Windows. | 376 // ones, fills them with data, and "feed" the Windows. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 buffer, | 412 buffer, |
417 sizeof(WAVEHDR)); | 413 sizeof(WAVEHDR)); |
418 if (result != MMSYSERR_NOERROR) | 414 if (result != MMSYSERR_NOERROR) |
419 stream->HandleError(result); | 415 stream->HandleError(result); |
420 stream->pending_bytes_ += buffer->dwBufferLength; | 416 stream->pending_bytes_ += buffer->dwBufferLength; |
421 } | 417 } |
422 } | 418 } |
423 } | 419 } |
424 | 420 |
425 } // namespace media | 421 } // namespace media |
OLD | NEW |