| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "base/timer.h" | 12 #include "base/timer.h" |
| 13 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager_base.h" |
| 15 | 15 |
| 16 // An AudioInputController controls an AudioInputStream and records data | 16 // An AudioInputController controls an AudioInputStream and records data |
| 17 // from this input stream. It has an important function that it executes | 17 // from this input stream. It has an important function that it executes |
| 18 // audio operations like record, pause, stop, etc. on a separate thread. | 18 // audio operations like record, pause, stop, etc. on a separate thread. |
| 19 // | 19 // |
| 20 // All the public methods of AudioInputController are non-blocking except | 20 // All the public methods of AudioInputController are non-blocking except |
| 21 // close, the actual operations are performed on the audio input controller | 21 // close, the actual operations are performed on the audio input controller |
| 22 // thread. | 22 // thread. |
| 23 // | 23 // |
| 24 // Here is a state diagram for the AudioInputController: | 24 // Here is a state diagram for the AudioInputController: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // device will be created on the new thread and when that is done event | 86 // device will be created on the new thread and when that is done event |
| 87 // handler will receive a OnCreated() call. | 87 // handler will receive a OnCreated() call. |
| 88 static scoped_refptr<AudioInputController> Create( | 88 static scoped_refptr<AudioInputController> Create( |
| 89 EventHandler* event_handler, | 89 EventHandler* event_handler, |
| 90 const AudioParameters& params); | 90 const AudioParameters& params); |
| 91 | 91 |
| 92 // Factory method for creating a low latency audio stream. | 92 // Factory method for creating a low latency audio stream. |
| 93 static scoped_refptr<AudioInputController> CreateLowLatency( | 93 static scoped_refptr<AudioInputController> CreateLowLatency( |
| 94 EventHandler* event_handler, | 94 EventHandler* event_handler, |
| 95 const AudioParameters& params, | 95 const AudioParameters& params, |
| 96 const std::string& device_id, |
| 96 // External synchronous reader for audio controller. | 97 // External synchronous reader for audio controller. |
| 97 SyncWriter* sync_writer); | 98 SyncWriter* sync_writer); |
| 98 | 99 |
| 99 // Sets the factory used by the static method Create. AudioInputController | 100 // Sets the factory used by the static method Create. AudioInputController |
| 100 // does not take ownership of |factory|. A value of NULL results in an | 101 // does not take ownership of |factory|. A value of NULL results in an |
| 101 // AudioInputController being created directly. | 102 // AudioInputController being created directly. |
| 102 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } | 103 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } |
| 103 AudioInputStream* stream_for_testing() { return stream_; } | 104 AudioInputStream* stream_for_testing() { return stream_; } |
| 104 | 105 |
| 105 // Starts recording in this audio input stream. | 106 // Starts recording in this audio input stream. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 128 kEmpty, | 129 kEmpty, |
| 129 kCreated, | 130 kCreated, |
| 130 kRecording, | 131 kRecording, |
| 131 kClosed, | 132 kClosed, |
| 132 kError | 133 kError |
| 133 }; | 134 }; |
| 134 | 135 |
| 135 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); | 136 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); |
| 136 | 137 |
| 137 // The following methods are executed on the audio controller thread. | 138 // The following methods are executed on the audio controller thread. |
| 138 void DoCreate(const AudioParameters& params); | 139 void DoCreate(const AudioParameters& params, const std::string& device_id); |
| 139 void DoRecord(); | 140 void DoRecord(); |
| 140 void DoClose(); | 141 void DoClose(); |
| 141 void DoReportError(int code); | 142 void DoReportError(int code); |
| 142 void DoReportNoDataError(); | 143 void DoReportNoDataError(); |
| 143 void DoResetNoDataTimer(); | 144 void DoResetNoDataTimer(); |
| 144 | 145 |
| 145 EventHandler* handler_; | 146 EventHandler* handler_; |
| 146 AudioInputStream* stream_; | 147 AudioInputStream* stream_; |
| 147 | 148 |
| 148 // |no_data_timer_| is used to call DoReportNoDataError when we stop | 149 // |no_data_timer_| is used to call DoReportNoDataError when we stop |
| (...skipping 16 matching lines...) Expand all Loading... |
| 165 SyncWriter* sync_writer_; | 166 SyncWriter* sync_writer_; |
| 166 | 167 |
| 167 static Factory* factory_; | 168 static Factory* factory_; |
| 168 | 169 |
| 169 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 170 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 } // namespace media | 173 } // namespace media |
| 173 | 174 |
| 174 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 175 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |