| 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 <string> |
| 8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 12 #include "base/timer.h" | 13 #include "base/timer.h" |
| 13 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_manager_base.h" | 15 #include "media/audio/audio_manager_base.h" |
| 15 | 16 |
| 16 // An AudioInputController controls an AudioInputStream and records data | 17 // An AudioInputController controls an AudioInputStream and records data |
| 17 // from this input stream. It has an important function that it executes | 18 // from this input stream. It has an important function that it executes |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 virtual uint32 Write(const void* data, uint32 size) = 0; | 67 virtual uint32 Write(const void* data, uint32 size) = 0; |
| 67 | 68 |
| 68 // Close this synchronous writer. | 69 // Close this synchronous writer. |
| 69 virtual void Close() = 0; | 70 virtual void Close() = 0; |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 // AudioInputController::Create uses the currently registered Factory to | 73 // AudioInputController::Create uses the currently registered Factory to |
| 73 // create the AudioInputController. Factory is intended for testing. | 74 // create the AudioInputController. Factory is intended for testing. |
| 74 class Factory { | 75 class Factory { |
| 75 public: | 76 public: |
| 76 virtual AudioInputController* Create(EventHandler* event_handler, | 77 virtual AudioInputController* Create( |
| 77 AudioParameters params) = 0; | 78 AudioManager* audio_manager, |
| 79 EventHandler* event_handler, |
| 80 AudioParameters params) = 0; |
| 78 protected: | 81 protected: |
| 79 virtual ~Factory() {} | 82 virtual ~Factory() {} |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 virtual ~AudioInputController(); | 85 virtual ~AudioInputController(); |
| 83 | 86 |
| 84 // Factory method for creating an AudioInputController. | 87 // Factory method for creating an AudioInputController. |
| 85 // If successful, an audio input controller thread is created. The audio | 88 // If successful, an audio input controller thread is created. The audio |
| 86 // device will be created on the new thread and when that is done event | 89 // device will be created on the new thread and when that is done event |
| 87 // handler will receive a OnCreated() call. | 90 // handler will receive a OnCreated() call. |
| 88 static scoped_refptr<AudioInputController> Create( | 91 static scoped_refptr<AudioInputController> Create( |
| 92 AudioManager* audio_manager, |
| 89 EventHandler* event_handler, | 93 EventHandler* event_handler, |
| 90 const AudioParameters& params); | 94 const AudioParameters& params); |
| 91 | 95 |
| 92 // Factory method for creating a low latency audio stream. | 96 // Factory method for creating a low latency audio stream. |
| 93 static scoped_refptr<AudioInputController> CreateLowLatency( | 97 static scoped_refptr<AudioInputController> CreateLowLatency( |
| 98 AudioManager* audio_manager, |
| 94 EventHandler* event_handler, | 99 EventHandler* event_handler, |
| 95 const AudioParameters& params, | 100 const AudioParameters& params, |
| 96 const std::string& device_id, | 101 const std::string& device_id, |
| 97 // External synchronous reader for audio controller. | 102 // External synchronous reader for audio controller. |
| 98 SyncWriter* sync_writer); | 103 SyncWriter* sync_writer); |
| 99 | 104 |
| 100 // Sets the factory used by the static method Create. AudioInputController | 105 // Sets the factory used by the static method Create. AudioInputController |
| 101 // does not take ownership of |factory|. A value of NULL results in an | 106 // does not take ownership of |factory|. A value of NULL results in an |
| 102 // AudioInputController being created directly. | 107 // AudioInputController being created directly. |
| 103 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } | 108 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 protected: | 131 protected: |
| 127 // Internal state of the source. | 132 // Internal state of the source. |
| 128 enum State { | 133 enum State { |
| 129 kEmpty, | 134 kEmpty, |
| 130 kCreated, | 135 kCreated, |
| 131 kRecording, | 136 kRecording, |
| 132 kClosed, | 137 kClosed, |
| 133 kError | 138 kError |
| 134 }; | 139 }; |
| 135 | 140 |
| 136 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); | 141 AudioInputController(AudioManager* audio_manager, EventHandler* handler, |
| 142 SyncWriter* sync_writer); |
| 137 | 143 |
| 138 // The following methods are executed on the audio controller thread. | 144 // The following methods are executed on the audio controller thread. |
| 139 void DoCreate(const AudioParameters& params, const std::string& device_id); | 145 void DoCreate(const AudioParameters& params, const std::string& device_id); |
| 140 void DoRecord(); | 146 void DoRecord(); |
| 141 void DoClose(); | 147 void DoClose(); |
| 142 void DoReportError(int code); | 148 void DoReportError(int code); |
| 143 void DoReportNoDataError(); | 149 void DoReportNoDataError(); |
| 144 void DoResetNoDataTimer(); | 150 void DoResetNoDataTimer(); |
| 145 | 151 |
| 152 scoped_refptr<AudioManager> audio_manager_; |
| 146 EventHandler* handler_; | 153 EventHandler* handler_; |
| 147 AudioInputStream* stream_; | 154 AudioInputStream* stream_; |
| 148 | 155 |
| 149 // |no_data_timer_| is used to call DoReportNoDataError when we stop | 156 // |no_data_timer_| is used to call DoReportNoDataError when we stop |
| 150 // receiving OnData calls without an OnClose call. This can occur when an | 157 // receiving OnData calls without an OnClose call. This can occur when an |
| 151 // audio input device is unplugged whilst recording on Windows. | 158 // audio input device is unplugged whilst recording on Windows. |
| 152 // See http://crbug.com/79936 for details. | 159 // See http://crbug.com/79936 for details. |
| 153 base::DelayTimer<AudioInputController> no_data_timer_; | 160 base::DelayTimer<AudioInputController> no_data_timer_; |
| 154 | 161 |
| 155 // |state_| is written on the audio input controller thread and is read on | 162 // |state_| is written on the audio input controller thread and is read on |
| (...skipping 10 matching lines...) Expand all Loading... |
| 166 SyncWriter* sync_writer_; | 173 SyncWriter* sync_writer_; |
| 167 | 174 |
| 168 static Factory* factory_; | 175 static Factory* factory_; |
| 169 | 176 |
| 170 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 177 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 171 }; | 178 }; |
| 172 | 179 |
| 173 } // namespace media | 180 } // namespace media |
| 174 | 181 |
| 175 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 182 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |