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

Side by Side Diff: media/audio/audio_io.h

Issue 2966005: Add recording capability to AudioManager, and implemented on windows using the WaveIn APIs. (Closed)
Patch Set: Patch Created 10 years, 5 months 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
« no previous file with comments | « no previous file | media/audio/linux/alsa_output_unittest.cc » ('j') | 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 #ifndef MEDIA_AUDIO_AUDIO_IO_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_IO_H_
6 #define MEDIA_AUDIO_AUDIO_IO_H_ 6 #define MEDIA_AUDIO_AUDIO_IO_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 9
10 // Low-level audio output support. To make sound there are 3 objects involved: 10 // Low-level audio output support. To make sound there are 3 objects involved:
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 virtual void GetVolume(double* volume) = 0; 100 virtual void GetVolume(double* volume) = 0;
101 101
102 // Close the stream. This also generates AudioSourceCallback::OnClose(). 102 // Close the stream. This also generates AudioSourceCallback::OnClose().
103 // After calling this method, the object should not be used anymore. 103 // After calling this method, the object should not be used anymore.
104 virtual void Close() = 0; 104 virtual void Close() = 0;
105 105
106 protected: 106 protected:
107 virtual ~AudioOutputStream() {} 107 virtual ~AudioOutputStream() {}
108 }; 108 };
109 109
110 // Models an audio sink receiving recorded audio from the audio driver.
111 class AudioInputStream {
112 public:
113 class AudioInputCallback {
114 public:
115 virtual ~AudioInputCallback() {}
116
117 // Called by the audio recorder when a full packet of audio data is
118 // available. This is called from a special audio thread and the
119 // implementation should return as soon as possible.
120 virtual void OnData(AudioInputStream* stream, const uint8* src,
121 uint32 size) = 0;
122
123 // The stream is done with this callback, the last call received by this
124 // audio sink.
125 virtual void OnClose(AudioInputStream* stream) = 0;
126
127 // There was an error while recording audio. The audio sink cannot be
128 // destroyed yet. No direct action needed by the AudioInputStream, but it
129 // is a good place to stop accumulating sound data since is is likely that
130 // recording will not continue. |code| is an error code that is platform
131 // specific.
132 virtual void OnError(AudioInputStream* stream, int code) = 0;
133 };
134
135 // Open the stream and prepares it for recording. Call Start() to actually
136 // begin recording.
137 virtual bool Open() = 0;
138
139 // Starts recording audio and generating AudioInputCallback::OnData().
140 // The input stream does not take ownership of this callback.
141 virtual void Start(AudioInputCallback* callback) = 0;
142
143 // Stops recording audio. Effect might not be instantaneous as there could be
144 // pending audio callbacks in the queue which will be issued first before
145 // recording stops.
146 virtual void Stop() = 0;
147
148 // Close the stream. This also generates AudioInputCallback::OnClose(). This
149 // should be the last call made on this object.
150 virtual void Close() = 0;
151
152 protected:
153 virtual ~AudioInputStream() {}
154 };
155
110 // Manages all audio resources. In particular it owns the AudioOutputStream 156 // Manages all audio resources. In particular it owns the AudioOutputStream
111 // objects. Provides some convenience functions that avoid the need to provide 157 // objects. Provides some convenience functions that avoid the need to provide
112 // iterators over the existing streams. 158 // iterators over the existing streams.
113 class AudioManager { 159 class AudioManager {
114 public: 160 public:
115 enum Format { 161 enum Format {
116 AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. 162 AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples.
117 AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. 163 AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested.
118 AUDIO_MOCK, // Creates a dummy AudioOutputStream object. 164 AUDIO_MOCK, // Creates a dummy AudioOutputStream object.
119 AUDIO_LAST_FORMAT // Only used for validation of format. 165 AUDIO_LAST_FORMAT // Only used for validation of format.
120 }; 166 };
121 167
122 // Telephone quality sample rate, mostly for speech-only audio. 168 // Telephone quality sample rate, mostly for speech-only audio.
123 static const uint32 kTelephoneSampleRate = 8000; 169 static const uint32 kTelephoneSampleRate = 8000;
124 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. 170 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7.
125 static const uint32 kAudioCDSampleRate = 44100; 171 static const uint32 kAudioCDSampleRate = 44100;
126 // Digital Audio Tape sample rate. 172 // Digital Audio Tape sample rate.
127 static const uint32 kAudioDATSampleRate = 48000; 173 static const uint32 kAudioDATSampleRate = 48000;
128 174
129 // Returns true if the OS reports existence of audio devices. This does not 175 // Returns true if the OS reports existence of audio devices. This does not
130 // guarantee that the existing devices support all formats and sample rates. 176 // guarantee that the existing devices support all formats and sample rates.
131 virtual bool HasAudioOutputDevices() = 0; 177 virtual bool HasAudioOutputDevices() = 0;
132 178
179 // Returns true if the OS reports existence of audio recording devices. This
180 // does not guarantee that the existing devices support all formats and
181 // sample rates.
182 virtual bool HasAudioInputDevices() = 0;
183
133 // Factory for all the supported stream formats. The |channels| can be 1 to 5. 184 // Factory for all the supported stream formats. The |channels| can be 1 to 5.
134 // The |sample_rate| is in hertz and can be any value supported by the 185 // The |sample_rate| is in hertz and can be any value supported by the
135 // platform. For some future formats the |sample_rate| and |bits_per_sample| 186 // platform. For some future formats the |sample_rate| and |bits_per_sample|
136 // can take special values. 187 // can take special values.
137 // Returns NULL if the combination of the parameters is not supported, or if 188 // Returns NULL if the combination of the parameters is not supported, or if
138 // we have reached some other platform specific limit. 189 // we have reached some other platform specific limit.
139 // 190 //
140 // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects: 191 // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects:
141 // 1- Instead of triple buffered the audio will be double buffered. 192 // 1- Instead of triple buffered the audio will be double buffered.
142 // 2- A low latency driver or alternative audio subsystem will be used when 193 // 2- A low latency driver or alternative audio subsystem will be used when
143 // available. 194 // available.
144 // 195 //
145 // Do not free the returned AudioOutputStream. It is owned by AudioManager. 196 // Do not free the returned AudioOutputStream. It is owned by AudioManager.
146 virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, 197 virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels,
147 int sample_rate, 198 int sample_rate,
148 char bits_per_sample) = 0; 199 char bits_per_sample) = 0;
149 200
201 // Factory to create audio recording streams.
202 // |channels| can be 1 or 2.
203 // |sample_rate| is in hertz and can be any value supported by the platform.
204 // |bits_per_sample| can be any value supported by the platform.
205 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|,
206 // with 0 suggesting that the implementation use a default value for that
207 // platform.
208 // Returns NULL if the combination of the parameters is not supported, or if
209 // we have reached some other platform specific limit.
210 //
211 // Do not free the returned AudioInputStream. It is owned by AudioManager.
212 // When you are done with it, call |Stop()| and |Close()| to release it.
213 virtual AudioInputStream* MakeAudioInputStream(Format format, int channels,
214 int sample_rate,
215 char bits_per_sample,
216 uint32 samples_per_packet) = 0;
217
150 // Muting continues playback but effectively the volume is set to zero. 218 // Muting continues playback but effectively the volume is set to zero.
151 // Un-muting returns the volume to the previous level. 219 // Un-muting returns the volume to the previous level.
152 virtual void MuteAll() = 0; 220 virtual void MuteAll() = 0;
153 virtual void UnMuteAll() = 0; 221 virtual void UnMuteAll() = 0;
154 222
155 // Get AudioManager singleton. 223 // Get AudioManager singleton.
156 // TODO(cpu): Define threading requirements for interacting with AudioManager. 224 // TODO(cpu): Define threading requirements for interacting with AudioManager.
157 static AudioManager* GetAudioManager(); 225 static AudioManager* GetAudioManager();
158 226
159 protected: 227 protected:
160 virtual ~AudioManager() {} 228 virtual ~AudioManager() {}
161 }; 229 };
162 230
163 231
164 #endif // MEDIA_AUDIO_AUDIO_IO_H_ 232 #endif // MEDIA_AUDIO_AUDIO_IO_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/linux/alsa_output_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698