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

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

Issue 22801007: Adds the UserInputMonitor implementation for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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/audio_input_controller.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) 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/base/user_input_monitor.h"
20 19
21 // An AudioInputController controls an AudioInputStream and records data 20 // An AudioInputController controls an AudioInputStream and records data
22 // from this input stream. The two main methods are Record() and Close() and 21 // from this input stream. The two main methods are Record() and Close() and
23 // they are both executed on the audio thread which is injected by the two 22 // they are both executed on the audio thread which is injected by the two
24 // alternative factory methods, Create() or CreateLowLatency(). 23 // alternative factory methods, Create() or CreateLowLatency().
25 // 24 //
26 // All public methods of AudioInputController are non-blocking. 25 // All public methods of AudioInputController are non-blocking.
27 // 26 //
28 // Here is a state diagram for the AudioInputController: 27 // Here is a state diagram for the AudioInputController:
29 // 28 //
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // Closure::Run() <-----------------. 65 // Closure::Run() <-----------------.
67 // (closure-task) 66 // (closure-task)
68 // 67 //
69 // The audio thread itself is owned by the AudioManager that the 68 // The audio thread itself is owned by the AudioManager that the
70 // AudioInputController holds a reference to. When performing tasks on the 69 // AudioInputController holds a reference to. When performing tasks on the
71 // audio thread, the controller must not add or release references to the 70 // audio thread, the controller must not add or release references to the
72 // AudioManager or itself (since it in turn holds a reference to the manager). 71 // AudioManager or itself (since it in turn holds a reference to the manager).
73 // 72 //
74 namespace media { 73 namespace media {
75 74
75 class UserInputMonitor;
76
76 class MEDIA_EXPORT AudioInputController 77 class MEDIA_EXPORT AudioInputController
77 : public base::RefCountedThreadSafe<AudioInputController>, 78 : public base::RefCountedThreadSafe<AudioInputController>,
78 public AudioInputStream::AudioInputCallback, 79 public AudioInputStream::AudioInputCallback {
79 public UserInputMonitor::KeyStrokeListener {
80 public: 80 public:
81 // An event handler that receives events from the AudioInputController. The 81 // An event handler that receives events from the AudioInputController. The
82 // following methods are all called on the audio thread. 82 // following methods are all called on the audio thread.
83 class MEDIA_EXPORT EventHandler { 83 class MEDIA_EXPORT EventHandler {
84 public: 84 public:
85 virtual void OnCreated(AudioInputController* controller) = 0; 85 virtual void OnCreated(AudioInputController* controller) = 0;
86 virtual void OnRecording(AudioInputController* controller) = 0; 86 virtual void OnRecording(AudioInputController* controller) = 0;
87 virtual void OnError(AudioInputController* controller) = 0; 87 virtual void OnError(AudioInputController* controller) = 0;
88 virtual void OnData(AudioInputController* controller, const uint8* data, 88 virtual void OnData(AudioInputController* controller, const uint8* data,
89 uint32 size) = 0; 89 uint32 size) = 0;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 // AudioInputCallback implementation. Threading details depends on the 197 // AudioInputCallback implementation. Threading details depends on the
198 // device-specific implementation. 198 // device-specific implementation.
199 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, 199 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size,
200 uint32 hardware_delay_bytes, double volume) OVERRIDE; 200 uint32 hardware_delay_bytes, double volume) OVERRIDE;
201 virtual void OnClose(AudioInputStream* stream) OVERRIDE; 201 virtual void OnClose(AudioInputStream* stream) OVERRIDE;
202 virtual void OnError(AudioInputStream* stream) OVERRIDE; 202 virtual void OnError(AudioInputStream* stream) OVERRIDE;
203 203
204 bool LowLatencyMode() const { return sync_writer_ != NULL; } 204 bool LowLatencyMode() const { return sync_writer_ != NULL; }
205 205
206 // Impl of KeyStrokeListener.
207 virtual void OnKeyStroke() OVERRIDE;
208
209 protected: 206 protected:
210 friend class base::RefCountedThreadSafe<AudioInputController>; 207 friend class base::RefCountedThreadSafe<AudioInputController>;
211 208
212 // Internal state of the source. 209 // Internal state of the source.
213 enum State { 210 enum State {
214 kEmpty, 211 kEmpty,
215 kCreated, 212 kCreated,
216 kRecording, 213 kRecording,
217 kClosed, 214 kClosed,
218 kError 215 kError
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 277
281 // SyncWriter is used only in low-latency mode for synchronous writing. 278 // SyncWriter is used only in low-latency mode for synchronous writing.
282 SyncWriter* sync_writer_; 279 SyncWriter* sync_writer_;
283 280
284 static Factory* factory_; 281 static Factory* factory_;
285 282
286 double max_volume_; 283 double max_volume_;
287 284
288 UserInputMonitor* user_input_monitor_; 285 UserInputMonitor* user_input_monitor_;
289 286
290 // True if any key has been pressed after the last OnData call. 287 size_t prev_key_down_count_;
291 bool key_pressed_;
292 288
293 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 289 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
294 }; 290 };
295 291
296 } // namespace media 292 } // namespace media
297 293
298 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 294 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_input_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698