OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/audio_io.h" | 5 #include "media/audio/audio_io.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <mmsystem.h> | 8 #include <mmsystem.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "media/audio/fake_audio_input_stream.h" | 11 #include "media/audio/fake_audio_input_stream.h" |
12 #include "media/audio/fake_audio_output_stream.h" | 12 #include "media/audio/fake_audio_output_stream.h" |
13 #include "media/audio/win/audio_manager_win.h" | 13 #include "media/audio/win/audio_manager_win.h" |
14 #include "media/audio/win/wavein_input_win.h" | 14 #include "media/audio/win/wavein_input_win.h" |
15 #include "media/audio/win/waveout_output_win.h" | 15 #include "media/audio/win/waveout_output_win.h" |
16 #include "media/base/limits.h" | 16 #include "media/base/limits.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Up to 8 channels can be passed to the driver. | 20 // Up to 8 channels can be passed to the driver. |
21 // This should work, given the right drivers, but graceful error handling is | 21 // This should work, given the right drivers, but graceful error handling is |
22 // needed. | 22 // needed. |
23 const int kWinMaxChannels = 8; | 23 const int kWinMaxChannels = 8; |
24 | 24 |
25 const int kWinMaxInputChannels = 2; | 25 const int kWinMaxInputChannels = 2; |
26 const int kMaxSamplesPerPacket = media::Limits::kMaxSampleRate; | |
27 // We use 3 buffers for recording audio so that if a recording callback takes | 26 // We use 3 buffers for recording audio so that if a recording callback takes |
28 // some time to return we won't lose audio. More buffers while recording are | 27 // some time to return we won't lose audio. More buffers while recording are |
29 // ok because they don't introduce any delay in recording, unlike in playback | 28 // ok because they don't introduce any delay in recording, unlike in playback |
30 // where you first need to fill in that number of buffers before starting to | 29 // where you first need to fill in that number of buffers before starting to |
31 // play. | 30 // play. |
32 const int kNumInputBuffers = 3; | 31 const int kNumInputBuffers = 3; |
33 | 32 |
34 } // namespace. | 33 } // namespace. |
35 | 34 |
36 bool AudioManagerWin::HasAudioOutputDevices() { | 35 bool AudioManagerWin::HasAudioOutputDevices() { |
37 return (::waveOutGetNumDevs() != 0); | 36 return (::waveOutGetNumDevs() != 0); |
38 } | 37 } |
39 | 38 |
40 bool AudioManagerWin::HasAudioInputDevices() { | 39 bool AudioManagerWin::HasAudioInputDevices() { |
41 return (::waveInGetNumDevs() != 0); | 40 return (::waveInGetNumDevs() != 0); |
42 } | 41 } |
43 | 42 |
44 // Factory for the implementations of AudioOutputStream. Two implementations | 43 // Factory for the implementations of AudioOutputStream. Two implementations |
45 // should suffice most windows user's needs. | 44 // should suffice most windows user's needs. |
46 // - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) | 45 // - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) |
47 // - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). | 46 // - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). |
48 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( | 47 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( |
49 AudioParameters params) { | 48 AudioParameters params) { |
50 if (!params.IsValid() || (params.channels > kWinMaxChannels)) | 49 if (!params.IsValid() || (params.channels > kWinMaxChannels)) |
51 return NULL; | 50 return NULL; |
52 | 51 |
53 if (params.format == AudioParameters::AUDIO_MOCK) { | 52 if (params.format == AudioParameters::AUDIO_MOCK) { |
54 return FakeAudioOutputStream::MakeFakeStream(); | 53 return FakeAudioOutputStream::MakeFakeStream(params); |
55 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 54 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
56 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); | 55 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); |
57 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 56 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
58 // TODO(cpu): waveout cannot hit 20ms latency. Use other method. | 57 // TODO(cpu): waveout cannot hit 20ms latency. Use other method. |
59 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); | 58 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); |
60 } | 59 } |
61 return NULL; | 60 return NULL; |
62 } | 61 } |
63 | 62 |
64 // Factory for the implementations of AudioInputStream. | 63 // Factory for the implementations of AudioInputStream. |
65 AudioInputStream* AudioManagerWin::MakeAudioInputStream( | 64 AudioInputStream* AudioManagerWin::MakeAudioInputStream( |
66 AudioParameters params, int samples_per_packet) { | 65 AudioParameters params) { |
67 if (!params.IsValid() || (params.channels > kWinMaxInputChannels) || | 66 if (!params.IsValid() || (params.channels > kWinMaxInputChannels)) |
68 (samples_per_packet > kMaxSamplesPerPacket) || (samples_per_packet < 0)) | |
69 return NULL; | 67 return NULL; |
70 | 68 |
71 if (params.format == AudioParameters::AUDIO_MOCK) { | 69 if (params.format == AudioParameters::AUDIO_MOCK) { |
72 return FakeAudioInputStream::MakeFakeStream(params, samples_per_packet); | 70 return FakeAudioInputStream::MakeFakeStream(params); |
73 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 71 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
74 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 72 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
75 samples_per_packet, WAVE_MAPPER); | 73 WAVE_MAPPER); |
76 } | 74 } |
77 return NULL; | 75 return NULL; |
78 } | 76 } |
79 | 77 |
80 void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { | 78 void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { |
81 if (stream) | 79 if (stream) |
82 delete stream; | 80 delete stream; |
83 } | 81 } |
84 | 82 |
85 void AudioManagerWin::ReleaseInputStream(PCMWaveInAudioInputStream* stream) { | 83 void AudioManagerWin::ReleaseInputStream(PCMWaveInAudioInputStream* stream) { |
86 if (stream) | 84 if (stream) |
87 delete stream; | 85 delete stream; |
88 } | 86 } |
89 | 87 |
90 void AudioManagerWin::MuteAll() { | 88 void AudioManagerWin::MuteAll() { |
91 } | 89 } |
92 | 90 |
93 void AudioManagerWin::UnMuteAll() { | 91 void AudioManagerWin::UnMuteAll() { |
94 } | 92 } |
95 | 93 |
96 AudioManagerWin::~AudioManagerWin() { | 94 AudioManagerWin::~AudioManagerWin() { |
97 } | 95 } |
98 | 96 |
99 // static | 97 // static |
100 AudioManager* AudioManager::CreateAudioManager() { | 98 AudioManager* AudioManager::CreateAudioManager() { |
101 return new AudioManagerWin(); | 99 return new AudioManagerWin(); |
102 } | 100 } |
OLD | NEW |