| 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 "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 13 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
| 14 | 15 |
| 15 // An AudioInputController controls an AudioInputStream and records data | 16 // An AudioInputController controls an AudioInputStream and records data |
| 16 // 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 |
| 17 // audio operations like record, pause, stop, etc. on a separate thread. | 18 // audio operations like record, pause, stop, etc. on a separate thread. |
| 18 // | 19 // |
| 19 // All the public methods of AudioInputController are non-blocking except | 20 // All the public methods of AudioInputController are non-blocking except |
| 20 // close, the actual operations are performed on the audio input controller | 21 // close, the actual operations are performed on the audio input controller |
| 21 // thread. | 22 // thread. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 EventHandler* event_handler, | 94 EventHandler* event_handler, |
| 94 AudioParameters params, | 95 AudioParameters params, |
| 95 // External synchronous reader for audio controller. | 96 // External synchronous reader for audio controller. |
| 96 SyncWriter* sync_writer); | 97 SyncWriter* sync_writer); |
| 97 | 98 |
| 98 // Sets the factory used by the static method Create. AudioInputController | 99 // Sets the factory used by the static method Create. AudioInputController |
| 99 // does not take ownership of |factory|. A value of NULL results in an | 100 // does not take ownership of |factory|. A value of NULL results in an |
| 100 // AudioInputController being created directly. | 101 // AudioInputController being created directly. |
| 101 #if defined(UNIT_TEST) | 102 #if defined(UNIT_TEST) |
| 102 static void set_factory(Factory* factory) { factory_ = factory; } | 103 static void set_factory(Factory* factory) { factory_ = factory; } |
| 104 AudioInputStream* stream() { return stream_; } |
| 103 #endif | 105 #endif |
| 104 | 106 |
| 105 // Starts recording in this audio input stream. | 107 // Starts recording in this audio input stream. |
| 106 virtual void Record(); | 108 virtual void Record(); |
| 107 | 109 |
| 108 // Closes the audio input stream and shutdown the audio input controller | 110 // Closes the audio input stream and shutdown the audio input controller |
| 109 // thread. This method returns only after all operations are completed. This | 111 // thread. This method returns only after all operations are completed. This |
| 110 // input controller cannot be used after this method is called. | 112 // input controller cannot be used after this method is called. |
| 111 // | 113 // |
| 112 // It is safe to call this method more than once. Calls after the first one | 114 // It is safe to call this method more than once. Calls after the first one |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 kError | 133 kError |
| 132 }; | 134 }; |
| 133 | 135 |
| 134 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); | 136 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); |
| 135 | 137 |
| 136 // The following methods are executed on the audio controller thread. | 138 // The following methods are executed on the audio controller thread. |
| 137 void DoCreate(AudioParameters params); | 139 void DoCreate(AudioParameters params); |
| 138 void DoRecord(); | 140 void DoRecord(); |
| 139 void DoClose(); | 141 void DoClose(); |
| 140 void DoReportError(int code); | 142 void DoReportError(int code); |
| 143 void DoReportNoDataError(); |
| 144 void DoResetNoDataTimer(); |
| 141 | 145 |
| 142 EventHandler* handler_; | 146 EventHandler* handler_; |
| 143 AudioInputStream* stream_; | 147 AudioInputStream* stream_; |
| 144 | 148 |
| 149 // |no_data_timer_| is used to call DoReportNoDataError when we stop |
| 150 // receiving OnData calls without an OnClose call. This can occur when an |
| 151 // audio input device is unplugged whilst recording on Windows. |
| 152 // See http://crbug.com/79936 for details. |
| 153 base::DelayTimer<AudioInputController> no_data_timer_; |
| 154 |
| 145 // |state_| is written on the audio input controller thread and is read on | 155 // |state_| is written on the audio input controller thread and is read on |
| 146 // the hardware audio thread. These operations need to be locked. But lock | 156 // the hardware audio thread. These operations need to be locked. But lock |
| 147 // is not required for reading on the audio input controller thread. | 157 // is not required for reading on the audio input controller thread. |
| 148 State state_; | 158 State state_; |
| 149 | 159 |
| 150 base::Lock lock_; | 160 base::Lock lock_; |
| 151 | 161 |
| 152 // The audio input controller thread that this object runs on. | 162 // The audio input controller thread that this object runs on. |
| 153 base::Thread thread_; | 163 base::Thread thread_; |
| 154 | 164 |
| 155 // SyncWriter is used only in low latency mode for synchronous writing. | 165 // SyncWriter is used only in low latency mode for synchronous writing. |
| 156 SyncWriter* sync_writer_; | 166 SyncWriter* sync_writer_; |
| 157 | 167 |
| 158 static Factory* factory_; | 168 static Factory* factory_; |
| 159 | 169 |
| 160 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 170 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 161 }; | 171 }; |
| 162 | 172 |
| 163 } // namespace media | 173 } // namespace media |
| 164 | 174 |
| 165 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 175 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |