Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: media/audio/win/audio_manager_win.cc

Issue 5350003: Move audio output number limit to AudioManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/win/audio_manager_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <objbase.h> // This has to be before initguid.h 8 #include <objbase.h> // This has to be before initguid.h
9 #include <initguid.h> 9 #include <initguid.h>
10 #include <mmsystem.h> 10 #include <mmsystem.h>
(...skipping 16 matching lines...) Expand all
27 // The following are defined in various DDK headers, and we (re)define them 27 // The following are defined in various DDK headers, and we (re)define them
28 // here to avoid adding the DDK as a chrome dependency. 28 // here to avoid adding the DDK as a chrome dependency.
29 #define DRV_QUERYDEVICEINTERFACE 0x80c 29 #define DRV_QUERYDEVICEINTERFACE 0x80c
30 #define DRVM_MAPPER_PREFERRED_GET 0x2015 30 #define DRVM_MAPPER_PREFERRED_GET 0x2015
31 #define DRV_QUERYDEVICEINTERFACESIZE 0x80d 31 #define DRV_QUERYDEVICEINTERFACESIZE 0x80d
32 DEFINE_GUID(AM_KSCATEGORY_AUDIO, 0x6994ad04, 0x93ef, 0x11d0, 32 DEFINE_GUID(AM_KSCATEGORY_AUDIO, 0x6994ad04, 0x93ef, 0x11d0,
33 0xa3, 0xcc, 0x00, 0xa0, 0xc9, 0x22, 0x31, 0x96); 33 0xa3, 0xcc, 0x00, 0xa0, 0xc9, 0x22, 0x31, 0x96);
34 34
35 namespace { 35 namespace {
36 36
37 // Maximum number of output streams that can be open simultaneously.
38 const size_t kMaxOutputStreams = 50;
39
37 // Up to 8 channels can be passed to the driver. 40 // Up to 8 channels can be passed to the driver.
38 // This should work, given the right drivers, but graceful error handling is 41 // This should work, given the right drivers, but graceful error handling is
39 // needed. 42 // needed.
40 const int kWinMaxChannels = 8; 43 const int kWinMaxChannels = 8;
41 44
42 const int kWinMaxInputChannels = 2; 45 const int kWinMaxInputChannels = 2;
43 // We use 3 buffers for recording audio so that if a recording callback takes 46 // We use 3 buffers for recording audio so that if a recording callback takes
44 // some time to return we won't lose audio. More buffers while recording are 47 // some time to return we won't lose audio. More buffers while recording are
45 // ok because they don't introduce any delay in recording, unlike in playback 48 // ok because they don't introduce any delay in recording, unlike in playback
46 // where you first need to fill in that number of buffers before starting to 49 // where you first need to fill in that number of buffers before starting to
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 87 }
85 88
86 SetupDiSetDeviceInstallParams(device_info, device_data, 89 SetupDiSetDeviceInstallParams(device_info, device_data,
87 &old_device_install_params); 90 &old_device_install_params);
88 91
89 return device_and_driver_info; 92 return device_and_driver_info;
90 } 93 }
91 94
92 } // namespace 95 } // namespace
93 96
97 AudioManagerWin::AudioManagerWin()
98 : num_output_streams_(0) {
99 }
100
101 AudioManagerWin::~AudioManagerWin() {
102 }
103
94 bool AudioManagerWin::HasAudioOutputDevices() { 104 bool AudioManagerWin::HasAudioOutputDevices() {
95 return (::waveOutGetNumDevs() != 0); 105 return (::waveOutGetNumDevs() != 0);
96 } 106 }
97 107
98 bool AudioManagerWin::HasAudioInputDevices() { 108 bool AudioManagerWin::HasAudioInputDevices() {
99 return (::waveInGetNumDevs() != 0); 109 return (::waveInGetNumDevs() != 0);
100 } 110 }
101 111
102 // Factory for the implementations of AudioOutputStream. Two implementations 112 // Factory for the implementations of AudioOutputStream. Two implementations
103 // should suffice most windows user's needs. 113 // should suffice most windows user's needs.
104 // - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) 114 // - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress)
105 // - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). 115 // - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work).
106 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( 116 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream(
107 AudioParameters params) { 117 AudioParameters params) {
108 if (!params.IsValid() || (params.channels > kWinMaxChannels)) 118 if (!params.IsValid() || (params.channels > kWinMaxChannels))
109 return NULL; 119 return NULL;
110 120
121 // Limit the number of audio streams opened.
122 if (num_output_streams_ >= kMaxOutputStreams) {
123 return NULL;
124 }
125
111 if (params.format == AudioParameters::AUDIO_MOCK) { 126 if (params.format == AudioParameters::AUDIO_MOCK) {
112 return FakeAudioOutputStream::MakeFakeStream(params); 127 return FakeAudioOutputStream::MakeFakeStream(params);
113 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { 128 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) {
129 num_output_streams_++;
114 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); 130 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER);
115 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { 131 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) {
132 num_output_streams_++;
116 // TODO(cpu): waveout cannot hit 20ms latency. Use other method. 133 // TODO(cpu): waveout cannot hit 20ms latency. Use other method.
117 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); 134 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER);
118 } 135 }
119 return NULL; 136 return NULL;
120 } 137 }
121 138
122 // Factory for the implementations of AudioInputStream. 139 // Factory for the implementations of AudioInputStream.
123 AudioInputStream* AudioManagerWin::MakeAudioInputStream( 140 AudioInputStream* AudioManagerWin::MakeAudioInputStream(
124 AudioParameters params) { 141 AudioParameters params) {
125 if (!params.IsValid() || (params.channels > kWinMaxInputChannels)) 142 if (!params.IsValid() || (params.channels > kWinMaxInputChannels))
126 return NULL; 143 return NULL;
127 144
128 if (params.format == AudioParameters::AUDIO_MOCK) { 145 if (params.format == AudioParameters::AUDIO_MOCK) {
129 return FakeAudioInputStream::MakeFakeStream(params); 146 return FakeAudioInputStream::MakeFakeStream(params);
130 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { 147 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) {
131 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, 148 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers,
132 WAVE_MAPPER); 149 WAVE_MAPPER);
133 } 150 }
134 return NULL; 151 return NULL;
135 } 152 }
136 153
137 void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { 154 void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) {
138 if (stream) 155 DCHECK(stream);
139 delete stream; 156 num_output_streams_--;
157 delete stream;
140 } 158 }
141 159
142 void AudioManagerWin::ReleaseInputStream(PCMWaveInAudioInputStream* stream) { 160 void AudioManagerWin::ReleaseInputStream(PCMWaveInAudioInputStream* stream) {
143 if (stream) 161 delete stream;
144 delete stream;
145 } 162 }
146 163
147 void AudioManagerWin::MuteAll() { 164 void AudioManagerWin::MuteAll() {
148 } 165 }
149 166
150 void AudioManagerWin::UnMuteAll() { 167 void AudioManagerWin::UnMuteAll() {
151 } 168 }
152 169
153 AudioManagerWin::~AudioManagerWin() {
154 }
155
156 string16 AudioManagerWin::GetAudioInputDeviceModel() { 170 string16 AudioManagerWin::GetAudioInputDeviceModel() {
157 // Get the default audio capture device and its device interface name. 171 // Get the default audio capture device and its device interface name.
158 DWORD device_id = 0; 172 DWORD device_id = 0;
159 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER), 173 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER),
160 DRVM_MAPPER_PREFERRED_GET, 174 DRVM_MAPPER_PREFERRED_GET,
161 reinterpret_cast<DWORD_PTR>(&device_id), NULL); 175 reinterpret_cast<DWORD_PTR>(&device_id), NULL);
162 ULONG device_interface_name_size = 0; 176 ULONG device_interface_name_size = 0;
163 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), 177 waveInMessage(reinterpret_cast<HWAVEIN>(device_id),
164 DRV_QUERYDEVICEINTERFACESIZE, 178 DRV_QUERYDEVICEINTERFACESIZE,
165 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0); 179 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 return GetDeviceAndDriverInfo(device_info, &device_data); 223 return GetDeviceAndDriverInfo(device_info, &device_data);
210 } 224 }
211 225
212 return string16(); 226 return string16();
213 } 227 }
214 228
215 // static 229 // static
216 AudioManager* AudioManager::CreateAudioManager() { 230 AudioManager* AudioManager::CreateAudioManager() {
217 return new AudioManagerWin(); 231 return new AudioManagerWin();
218 } 232 }
OLDNEW
« no previous file with comments | « media/audio/win/audio_manager_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698