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/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop_proxy.h" | |
15 #include "base/threading/platform_thread.h" | |
16 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
17 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
18 #include "media/audio/win/audio_manager_win.h" | 16 #include "media/audio/win/audio_manager_win.h" |
19 | 17 |
20 namespace media { | 18 namespace media { |
21 | 19 |
22 // Some general thoughts about the waveOut API which is badly documented : | 20 // Some general thoughts about the waveOut API which is badly documented : |
23 // - 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 |
24 // releases. | 22 // releases. |
25 // - We use RegisterWaitForSingleObject() so one of threads in thread pool | 23 // - We use RegisterWaitForSingleObject() so one of threads in thread pool |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 format_.Format.wBitsPerSample) / 8; | 101 format_.Format.wBitsPerSample) / 8; |
104 format_.Format.nAvgBytesPerSec = format_.Format.nBlockAlign * | 102 format_.Format.nAvgBytesPerSec = format_.Format.nBlockAlign * |
105 format_.Format.nSamplesPerSec; | 103 format_.Format.nSamplesPerSec; |
106 if (params.channels() > kMaxChannelsToMask) { | 104 if (params.channels() > kMaxChannelsToMask) { |
107 format_.dwChannelMask = kChannelsToMask[kMaxChannelsToMask]; | 105 format_.dwChannelMask = kChannelsToMask[kMaxChannelsToMask]; |
108 } else { | 106 } else { |
109 format_.dwChannelMask = kChannelsToMask[params.channels()]; | 107 format_.dwChannelMask = kChannelsToMask[params.channels()]; |
110 } | 108 } |
111 format_.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; | 109 format_.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; |
112 format_.Samples.wValidBitsPerSample = params.bits_per_sample(); | 110 format_.Samples.wValidBitsPerSample = params.bits_per_sample(); |
113 | |
114 // Boost thread priority. Required for glitch free background audio. | |
115 DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread()); | |
116 base::PlatformThread::SetThreadPriority( | |
117 GetCurrentThread(), base::kThreadPriority_RealtimeAudio); | |
118 } | 111 } |
119 | 112 |
120 PCMWaveOutAudioOutputStream::~PCMWaveOutAudioOutputStream() { | 113 PCMWaveOutAudioOutputStream::~PCMWaveOutAudioOutputStream() { |
121 DCHECK(NULL == waveout_); | 114 DCHECK(NULL == waveout_); |
122 } | 115 } |
123 | 116 |
124 bool PCMWaveOutAudioOutputStream::Open() { | 117 bool PCMWaveOutAudioOutputStream::Open() { |
125 if (state_ != PCMA_BRAND_NEW) | 118 if (state_ != PCMA_BRAND_NEW) |
126 return false; | 119 return false; |
127 if (BufferSize() * num_buffers_ > kMaxOpenBufferSize) | 120 if (BufferSize() * num_buffers_ > kMaxOpenBufferSize) |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 buffer, | 413 buffer, |
421 sizeof(WAVEHDR)); | 414 sizeof(WAVEHDR)); |
422 if (result != MMSYSERR_NOERROR) | 415 if (result != MMSYSERR_NOERROR) |
423 stream->HandleError(result); | 416 stream->HandleError(result); |
424 stream->pending_bytes_ += buffer->dwBufferLength; | 417 stream->pending_bytes_ += buffer->dwBufferLength; |
425 } | 418 } |
426 } | 419 } |
427 } | 420 } |
428 | 421 |
429 } // namespace media | 422 } // namespace media |
OLD | NEW |