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

Side by Side Diff: trunk/src/media/audio/audio_input_controller.h

Issue 335343004: Revert 277794 "Modifies AudioInputCallback::OnData and use media..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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 #ifndef MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
6 #define MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 6 #define MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include "base/atomicops.h" 9 #include "base/atomicops.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 }; 110 };
111 111
112 // An event handler that receives events from the AudioInputController. The 112 // An event handler that receives events from the AudioInputController. The
113 // following methods are all called on the audio thread. 113 // following methods are all called on the audio thread.
114 class MEDIA_EXPORT EventHandler { 114 class MEDIA_EXPORT EventHandler {
115 public: 115 public:
116 virtual void OnCreated(AudioInputController* controller) = 0; 116 virtual void OnCreated(AudioInputController* controller) = 0;
117 virtual void OnRecording(AudioInputController* controller) = 0; 117 virtual void OnRecording(AudioInputController* controller) = 0;
118 virtual void OnError(AudioInputController* controller, 118 virtual void OnError(AudioInputController* controller,
119 ErrorCode error_code) = 0; 119 ErrorCode error_code) = 0;
120 virtual void OnData(AudioInputController* controller, 120 virtual void OnData(AudioInputController* controller, const uint8* data,
121 const AudioBus* data) = 0; 121 uint32 size) = 0;
122 virtual void OnLog(AudioInputController* controller, 122 virtual void OnLog(AudioInputController* controller,
123 const std::string& message) = 0; 123 const std::string& message) = 0;
124 124
125 protected: 125 protected:
126 virtual ~EventHandler() {} 126 virtual ~EventHandler() {}
127 }; 127 };
128 128
129 // A synchronous writer interface used by AudioInputController for 129 // A synchronous writer interface used by AudioInputController for
130 // synchronous writing. 130 // synchronous writing.
131 class SyncWriter { 131 class SyncWriter {
132 public: 132 public:
133 virtual ~SyncWriter() {} 133 virtual ~SyncWriter() {}
134 134
135 // Notify the synchronous writer about the number of bytes in the 135 // Notify the synchronous writer about the number of bytes in the
136 // soundcard which has been recorded. 136 // soundcard which has been recorded.
137 virtual void UpdateRecordedBytes(uint32 bytes) = 0; 137 virtual void UpdateRecordedBytes(uint32 bytes) = 0;
138 138
139 // Write certain amount of data from |data|. 139 // Write certain amount of data from |data|. This method returns
140 virtual void Write(const AudioBus* data, 140 // number of written bytes.
141 double volume, 141 virtual uint32 Write(const void* data,
142 bool key_pressed) = 0; 142 uint32 size,
143 double volume,
144 bool key_pressed) = 0;
143 145
144 // Close this synchronous writer. 146 // Close this synchronous writer.
145 virtual void Close() = 0; 147 virtual void Close() = 0;
146 }; 148 };
147 149
148 // AudioInputController::Create() can use the currently registered Factory 150 // AudioInputController::Create() can use the currently registered Factory
149 // to create the AudioInputController. Factory is intended for testing only. 151 // to create the AudioInputController. Factory is intended for testing only.
150 // |user_input_monitor| is used for typing detection and can be NULL. 152 // |user_input_monitor| is used for typing detection and can be NULL.
151 class Factory { 153 class Factory {
152 public: 154 public:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Sets the capture volume of the input stream. The value 0.0 corresponds 223 // Sets the capture volume of the input stream. The value 0.0 corresponds
222 // to muted and 1.0 to maximum volume. 224 // to muted and 1.0 to maximum volume.
223 virtual void SetVolume(double volume); 225 virtual void SetVolume(double volume);
224 226
225 // Sets the Automatic Gain Control (AGC) state of the input stream. 227 // Sets the Automatic Gain Control (AGC) state of the input stream.
226 // Changing the AGC state is not supported while recording is active. 228 // Changing the AGC state is not supported while recording is active.
227 virtual void SetAutomaticGainControl(bool enabled); 229 virtual void SetAutomaticGainControl(bool enabled);
228 230
229 // AudioInputCallback implementation. Threading details depends on the 231 // AudioInputCallback implementation. Threading details depends on the
230 // device-specific implementation. 232 // device-specific implementation.
231 virtual void OnData(AudioInputStream* stream, 233 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size,
232 const AudioBus* source, 234 uint32 hardware_delay_bytes, double volume) OVERRIDE;
233 uint32 hardware_delay_bytes,
234 double volume) OVERRIDE;
235 virtual void OnError(AudioInputStream* stream) OVERRIDE; 235 virtual void OnError(AudioInputStream* stream) OVERRIDE;
236 236
237 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } 237 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; }
238 238
239 protected: 239 protected:
240 friend class base::RefCountedThreadSafe<AudioInputController>; 240 friend class base::RefCountedThreadSafe<AudioInputController>;
241 241
242 // Internal state of the source. 242 // Internal state of the source.
243 enum State { 243 enum State {
244 CREATED, 244 CREATED,
245 RECORDING, 245 RECORDING,
246 CLOSED 246 CLOSED
247 }; 247 };
248 248
249 AudioInputController(EventHandler* handler, 249 AudioInputController(EventHandler* handler,
250 SyncWriter* sync_writer, 250 SyncWriter* sync_writer,
251 UserInputMonitor* user_input_monitor); 251 UserInputMonitor* user_input_monitor);
252 virtual ~AudioInputController(); 252 virtual ~AudioInputController();
253 253
254 // Methods called on the audio thread (owned by the AudioManager). 254 // Methods called on the audio thread (owned by the AudioManager).
255 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, 255 void DoCreate(AudioManager* audio_manager, const AudioParameters& params,
256 const std::string& device_id); 256 const std::string& device_id);
257 void DoCreateForStream(AudioInputStream* stream_to_control, 257 void DoCreateForStream(AudioInputStream* stream_to_control,
258 bool enable_nodata_timer); 258 bool enable_nodata_timer);
259 void DoRecord(); 259 void DoRecord();
260 void DoClose(); 260 void DoClose();
261 void DoReportError(); 261 void DoReportError();
262 void DoSetVolume(double volume); 262 void DoSetVolume(double volume);
263 void DoSetAutomaticGainControl(bool enabled); 263 void DoSetAutomaticGainControl(bool enabled);
264 void DoOnData(scoped_ptr<AudioBus> data); 264 void DoOnData(scoped_ptr<uint8[]> data, uint32 size);
265 void DoLogAudioLevel(float level_dbfs); 265 void DoLogAudioLevel(float level_dbfs);
266 266
267 // Method to check if we get recorded data after a stream was started, 267 // Method to check if we get recorded data after a stream was started,
268 // and log the result to UMA. 268 // and log the result to UMA.
269 void FirstCheckForNoData(); 269 void FirstCheckForNoData();
270 270
271 // Method which ensures that OnError() is triggered when data recording 271 // Method which ensures that OnError() is triggered when data recording
272 // times out. Called on the audio thread. 272 // times out. Called on the audio thread.
273 void DoCheckForNoData(); 273 void DoCheckForNoData();
274 274
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 double max_volume_; 319 double max_volume_;
320 320
321 UserInputMonitor* user_input_monitor_; 321 UserInputMonitor* user_input_monitor_;
322 322
323 #if defined(AUDIO_POWER_MONITORING) 323 #if defined(AUDIO_POWER_MONITORING)
324 // Scans audio samples from OnData() as input to compute audio levels. 324 // Scans audio samples from OnData() as input to compute audio levels.
325 scoped_ptr<AudioPowerMonitor> audio_level_; 325 scoped_ptr<AudioPowerMonitor> audio_level_;
326 326
327 // We need these to be able to feed data to the AudioPowerMonitor. 327 // We need these to be able to feed data to the AudioPowerMonitor.
328 scoped_ptr<AudioBus> audio_bus_;
328 media::AudioParameters audio_params_; 329 media::AudioParameters audio_params_;
329 base::TimeTicks last_audio_level_log_time_; 330 base::TimeTicks last_audio_level_log_time_;
330 #endif 331 #endif
331 332
332 size_t prev_key_down_count_; 333 size_t prev_key_down_count_;
333 334
334 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 335 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
335 }; 336 };
336 337
337 } // namespace media 338 } // namespace media
338 339
339 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 340 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « trunk/src/media/audio/android/opensles_input.cc ('k') | trunk/src/media/audio/audio_input_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698