OLD | NEW |
1 // Copyright (c) 2011 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/audio_low_latency_output_win.h" | 5 #include "media/audio/win/audio_low_latency_output_win.h" |
6 | 6 |
7 #include <Functiondiscoverykeys_devpkey.h> | 7 #include <Functiondiscoverykeys_devpkey.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
32 num_written_frames_(0), | 32 num_written_frames_(0), |
33 source_(NULL) { | 33 source_(NULL) { |
34 CHECK(com_init_.succeeded()); | 34 CHECK(com_init_.succeeded()); |
35 DCHECK(manager_); | 35 DCHECK(manager_); |
36 | 36 |
37 // Load the Avrt DLL if not already loaded. Required to support MMCSS. | 37 // Load the Avrt DLL if not already loaded. Required to support MMCSS. |
38 bool avrt_init = avrt::Initialize(); | 38 bool avrt_init = avrt::Initialize(); |
39 DCHECK(avrt_init) << "Failed to load the avrt.dll"; | 39 DCHECK(avrt_init) << "Failed to load the avrt.dll"; |
40 | 40 |
41 // Set up the desired render format specified by the client. | 41 // Set up the desired render format specified by the client. |
42 format_.nSamplesPerSec = params.sample_rate; | 42 format_.nSamplesPerSec = params.sample_rate(); |
43 format_.wFormatTag = WAVE_FORMAT_PCM; | 43 format_.wFormatTag = WAVE_FORMAT_PCM; |
44 format_.wBitsPerSample = params.bits_per_sample; | 44 format_.wBitsPerSample = params.bits_per_sample(); |
45 format_.nChannels = params.channels; | 45 format_.nChannels = params.channels(); |
46 format_.nBlockAlign = (format_.wBitsPerSample / 8) * format_.nChannels; | 46 format_.nBlockAlign = (format_.wBitsPerSample / 8) * format_.nChannels; |
47 format_.nAvgBytesPerSec = format_.nSamplesPerSec * format_.nBlockAlign; | 47 format_.nAvgBytesPerSec = format_.nSamplesPerSec * format_.nBlockAlign; |
48 format_.cbSize = 0; | 48 format_.cbSize = 0; |
49 | 49 |
50 // Size in bytes of each audio frame. | 50 // Size in bytes of each audio frame. |
51 frame_size_ = format_.nBlockAlign; | 51 frame_size_ = format_.nBlockAlign; |
52 | 52 |
53 // Store size (in different units) of audio packets which we expect to | 53 // Store size (in different units) of audio packets which we expect to |
54 // get from the audio endpoint device in each render event. | 54 // get from the audio endpoint device in each render event. |
55 packet_size_frames_ = params.GetPacketSize() / format_.nBlockAlign; | 55 packet_size_frames_ = params.GetBytesPerBuffer() / format_.nBlockAlign; |
56 packet_size_bytes_ = params.GetPacketSize(); | 56 packet_size_bytes_ = params.GetBytesPerBuffer(); |
57 packet_size_ms_ = (1000.0 * packet_size_frames_) / params.sample_rate; | 57 packet_size_ms_ = (1000.0 * packet_size_frames_) / params.sample_rate(); |
58 DVLOG(1) << "Number of bytes per audio frame : " << frame_size_; | 58 DVLOG(1) << "Number of bytes per audio frame : " << frame_size_; |
59 DVLOG(1) << "Number of audio frames per packet: " << packet_size_frames_; | 59 DVLOG(1) << "Number of audio frames per packet: " << packet_size_frames_; |
60 DVLOG(1) << "Number of milliseconds per packet: " << packet_size_ms_; | 60 DVLOG(1) << "Number of milliseconds per packet: " << packet_size_ms_; |
61 | 61 |
62 // All events are auto-reset events and non-signaled initially. | 62 // All events are auto-reset events and non-signaled initially. |
63 | 63 |
64 // Create the event which the audio engine will signal each time | 64 // Create the event which the audio engine will signal each time |
65 // a buffer becomes ready to be processed by the client. | 65 // a buffer becomes ready to be processed by the client. |
66 audio_samples_render_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); | 66 audio_samples_render_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); |
67 DCHECK(audio_samples_render_event_.IsValid()); | 67 DCHECK(audio_samples_render_event_.IsValid()); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return; | 246 return; |
247 } | 247 } |
248 volume_ = volume_float; | 248 volume_ = volume_float; |
249 } | 249 } |
250 | 250 |
251 void WASAPIAudioOutputStream::GetVolume(double* volume) { | 251 void WASAPIAudioOutputStream::GetVolume(double* volume) { |
252 *volume = static_cast<double>(volume_); | 252 *volume = static_cast<double>(volume_); |
253 } | 253 } |
254 | 254 |
255 // static | 255 // static |
256 double WASAPIAudioOutputStream::HardwareSampleRate(ERole device_role) { | 256 int WASAPIAudioOutputStream::HardwareSampleRate(ERole device_role) { |
257 // It is assumed that this static method is called from a COM thread, i.e., | 257 // It is assumed that this static method is called from a COM thread, i.e., |
258 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts. | 258 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts. |
259 ScopedComPtr<IMMDeviceEnumerator> enumerator; | 259 ScopedComPtr<IMMDeviceEnumerator> enumerator; |
260 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), | 260 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), |
261 NULL, | 261 NULL, |
262 CLSCTX_INPROC_SERVER, | 262 CLSCTX_INPROC_SERVER, |
263 __uuidof(IMMDeviceEnumerator), | 263 __uuidof(IMMDeviceEnumerator), |
264 enumerator.ReceiveVoid()); | 264 enumerator.ReceiveVoid()); |
265 if (FAILED(hr)) { | 265 if (FAILED(hr)) { |
266 NOTREACHED() << "error code: " << std::hex << hr; | 266 NOTREACHED() << "error code: " << std::hex << hr; |
(...skipping 22 matching lines...) Expand all Loading... |
289 return 0.0; | 289 return 0.0; |
290 } | 290 } |
291 | 291 |
292 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; | 292 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; |
293 hr = audio_client->GetMixFormat(&audio_engine_mix_format); | 293 hr = audio_client->GetMixFormat(&audio_engine_mix_format); |
294 if (FAILED(hr)) { | 294 if (FAILED(hr)) { |
295 NOTREACHED() << "error code: " << std::hex << hr; | 295 NOTREACHED() << "error code: " << std::hex << hr; |
296 return 0.0; | 296 return 0.0; |
297 } | 297 } |
298 | 298 |
299 return static_cast<double>(audio_engine_mix_format->nSamplesPerSec); | 299 return static_cast<int>(audio_engine_mix_format->nSamplesPerSec); |
300 } | 300 } |
301 | 301 |
302 void WASAPIAudioOutputStream::Run() { | 302 void WASAPIAudioOutputStream::Run() { |
303 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 303 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
304 | 304 |
305 // Increase the thread priority. | 305 // Increase the thread priority. |
306 render_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); | 306 render_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
307 | 307 |
308 // Enable MMCSS to ensure that this thread receives prioritized access to | 308 // Enable MMCSS to ensure that this thread receives prioritized access to |
309 // CPU resources. | 309 // CPU resources. |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 | 799 |
800 // All released interfaces (IAudioRenderClient, IAudioClient, IMMDevice) | 800 // All released interfaces (IAudioRenderClient, IAudioClient, IMMDevice) |
801 // are now re-initiated and it is now possible to re-start audio rendering. | 801 // are now re-initiated and it is now possible to re-start audio rendering. |
802 | 802 |
803 // Start rendering again using the new default audio endpoint. | 803 // Start rendering again using the new default audio endpoint. |
804 hr = audio_client_->Start(); | 804 hr = audio_client_->Start(); |
805 | 805 |
806 restart_rendering_mode_ = false; | 806 restart_rendering_mode_ = false; |
807 return SUCCEEDED(hr); | 807 return SUCCEEDED(hr); |
808 } | 808 } |
OLD | NEW |