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

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

Issue 287873004: Adds volume level measurements to the AudioInputController for low-latency clients (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed dependency of content in media 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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "media/audio/audio_io.h" 17 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_manager_base.h" 18 #include "media/audio/audio_manager_base.h"
19 #include "media/audio/audio_parameters.h"
20 #include "media/audio/audio_power_monitor.h"
21 #include "media/base/audio_bus.h"
19 22
20 // An AudioInputController controls an AudioInputStream and records data 23 // An AudioInputController controls an AudioInputStream and records data
21 // from this input stream. The two main methods are Record() and Close() and 24 // from this input stream. The two main methods are Record() and Close() and
22 // they are both executed on the audio thread which is injected by the two 25 // they are both executed on the audio thread which is injected by the two
23 // alternative factory methods, Create() or CreateLowLatency(). 26 // alternative factory methods, Create() or CreateLowLatency().
24 // 27 //
25 // All public methods of AudioInputController are non-blocking. 28 // All public methods of AudioInputController are non-blocking.
26 // 29 //
27 // Here is a state diagram for the AudioInputController: 30 // Here is a state diagram for the AudioInputController:
28 // 31 //
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Closure::Run() <-----------------. 68 // Closure::Run() <-----------------.
66 // (closure-task) 69 // (closure-task)
67 // 70 //
68 // The audio thread itself is owned by the AudioManager that the 71 // The audio thread itself is owned by the AudioManager that the
69 // AudioInputController holds a reference to. When performing tasks on the 72 // AudioInputController holds a reference to. When performing tasks on the
70 // audio thread, the controller must not add or release references to the 73 // audio thread, the controller must not add or release references to the
71 // AudioManager or itself (since it in turn holds a reference to the manager). 74 // AudioManager or itself (since it in turn holds a reference to the manager).
72 // 75 //
73 namespace media { 76 namespace media {
74 77
78 // Only do power monitoring for non-mobile platforms to save resources.
79 #if !defined(OS_ANDROID) && !defined(OS_IOS)
80 #define AUDIO_POWER_MONITORING
81 #endif
82
75 class UserInputMonitor; 83 class UserInputMonitor;
76 84
77 class MEDIA_EXPORT AudioInputController 85 class MEDIA_EXPORT AudioInputController
78 : public base::RefCountedThreadSafe<AudioInputController>, 86 : public base::RefCountedThreadSafe<AudioInputController>,
79 public AudioInputStream::AudioInputCallback { 87 public AudioInputStream::AudioInputCallback {
80 public: 88 public:
81 89
82 // Error codes to make native loggin more clear. These error codes are added 90 // Error codes to make native loggin more clear. These error codes are added
83 // to generic error strings to provide a higher degree of details. 91 // to generic error strings to provide a higher degree of details.
84 // Changing these values can lead to problems when matching native debug 92 // Changing these values can lead to problems when matching native debug
(...skipping 19 matching lines...) Expand all
104 // An event handler that receives events from the AudioInputController. The 112 // An event handler that receives events from the AudioInputController. The
105 // following methods are all called on the audio thread. 113 // following methods are all called on the audio thread.
106 class MEDIA_EXPORT EventHandler { 114 class MEDIA_EXPORT EventHandler {
107 public: 115 public:
108 virtual void OnCreated(AudioInputController* controller) = 0; 116 virtual void OnCreated(AudioInputController* controller) = 0;
109 virtual void OnRecording(AudioInputController* controller) = 0; 117 virtual void OnRecording(AudioInputController* controller) = 0;
110 virtual void OnError(AudioInputController* controller, 118 virtual void OnError(AudioInputController* controller,
111 ErrorCode error_code) = 0; 119 ErrorCode error_code) = 0;
112 virtual void OnData(AudioInputController* controller, const uint8* data, 120 virtual void OnData(AudioInputController* controller, const uint8* data,
113 uint32 size) = 0; 121 uint32 size) = 0;
122 virtual void OnLog(AudioInputController* controller,
123 const std::string& message) = 0;
114 124
115 protected: 125 protected:
116 virtual ~EventHandler() {} 126 virtual ~EventHandler() {}
117 }; 127 };
118 128
119 // A synchronous writer interface used by AudioInputController for 129 // A synchronous writer interface used by AudioInputController for
120 // synchronous writing. 130 // synchronous writing.
121 class SyncWriter { 131 class SyncWriter {
122 public: 132 public:
123 virtual ~SyncWriter() {} 133 virtual ~SyncWriter() {}
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, 255 void DoCreate(AudioManager* audio_manager, const AudioParameters& params,
246 const std::string& device_id); 256 const std::string& device_id);
247 void DoCreateForStream(AudioInputStream* stream_to_control, 257 void DoCreateForStream(AudioInputStream* stream_to_control,
248 bool enable_nodata_timer); 258 bool enable_nodata_timer);
249 void DoRecord(); 259 void DoRecord();
250 void DoClose(); 260 void DoClose();
251 void DoReportError(); 261 void DoReportError();
252 void DoSetVolume(double volume); 262 void DoSetVolume(double volume);
253 void DoSetAutomaticGainControl(bool enabled); 263 void DoSetAutomaticGainControl(bool enabled);
254 void DoOnData(scoped_ptr<uint8[]> data, uint32 size); 264 void DoOnData(scoped_ptr<uint8[]> data, uint32 size);
265 void DoLogAudioLevel();
255 266
256 // 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,
257 // and log the result to UMA. 268 // and log the result to UMA.
258 void FirstCheckForNoData(); 269 void FirstCheckForNoData();
259 270
260 // Method which ensures that OnError() is triggered when data recording 271 // Method which ensures that OnError() is triggered when data recording
261 // times out. Called on the audio thread. 272 // times out. Called on the audio thread.
262 void DoCheckForNoData(); 273 void DoCheckForNoData();
263 274
264 // Helper method that stops, closes, and NULL:s |*stream_|. 275 // Helper method that stops, closes, and NULL:s |*stream_|.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 313
303 // SyncWriter is used only in low-latency mode for synchronous writing. 314 // SyncWriter is used only in low-latency mode for synchronous writing.
304 SyncWriter* sync_writer_; 315 SyncWriter* sync_writer_;
305 316
306 static Factory* factory_; 317 static Factory* factory_;
307 318
308 double max_volume_; 319 double max_volume_;
309 320
310 UserInputMonitor* user_input_monitor_; 321 UserInputMonitor* user_input_monitor_;
311 322
323 #if defined(AUDIO_POWER_MONITORING)
no longer working on chromium 2014/05/26 14:20:16 I don't think you save much by excluding these mem
henrika (OOO until Aug 14) 2014/05/26 15:01:17 I copied how it was done on the output side (in th
henrika (OOO until Aug 14) 2014/05/27 07:46:36 In addition, we should really do our best to simpl
324 // Scans audio samples from OnData() as input to compute audio levels.
325 scoped_ptr<AudioPowerMonitor> audio_level_;
326
327 // We need these to be able to feed data to the AudioPowerMonitor.
328 scoped_ptr<AudioBus> audio_bus_;
329 media::AudioParameters audio_params_;
330 base::TimeTicks last_audio_level_log_time_;
331 #endif
332
312 size_t prev_key_down_count_; 333 size_t prev_key_down_count_;
313 334
314 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 335 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
315 }; 336 };
316 337
317 } // namespace media 338 } // namespace media
318 339
319 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 340 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698