| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/lock.h" | 8 #include "base/lock.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 class EventHandler { | 42 class EventHandler { |
| 43 public: | 43 public: |
| 44 virtual ~EventHandler() {} | 44 virtual ~EventHandler() {} |
| 45 virtual void OnCreated(AudioInputController* controller) = 0; | 45 virtual void OnCreated(AudioInputController* controller) = 0; |
| 46 virtual void OnRecording(AudioInputController* controller) = 0; | 46 virtual void OnRecording(AudioInputController* controller) = 0; |
| 47 virtual void OnError(AudioInputController* controller, int error_code) = 0; | 47 virtual void OnError(AudioInputController* controller, int error_code) = 0; |
| 48 virtual void OnData(AudioInputController* controller, const uint8* data, | 48 virtual void OnData(AudioInputController* controller, const uint8* data, |
| 49 uint32 size) = 0; | 49 uint32 size) = 0; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // AudioInputController::Create uses the currently registered Factory to |
| 53 // create the AudioInputController. Factory is intended for testing. |
| 54 class Factory { |
| 55 public: |
| 56 virtual AudioInputController* Create(EventHandler* event_handler, |
| 57 AudioManager::Format format, |
| 58 int channels, |
| 59 int sample_rate, |
| 60 int bits_per_sample, |
| 61 int samples_per_packet) = 0; |
| 62 |
| 63 protected: |
| 64 virtual ~Factory() {} |
| 65 }; |
| 66 |
| 52 virtual ~AudioInputController(); | 67 virtual ~AudioInputController(); |
| 53 | 68 |
| 54 // Factory method for creating an AudioInputController. | 69 // Factory method for creating an AudioInputController. |
| 55 // If successful, an audio input controller thread is created. The audio | 70 // If successful, an audio input controller thread is created. The audio |
| 56 // device will be created on the new thread and when that is done event | 71 // device will be created on the new thread and when that is done event |
| 57 // handler will receive a OnCreated() call. | 72 // handler will receive a OnCreated() call. |
| 58 static scoped_refptr<AudioInputController> Create( | 73 static scoped_refptr<AudioInputController> Create( |
| 59 EventHandler* event_handler, | 74 EventHandler* event_handler, |
| 60 AudioManager::Format format, // Format of the stream. | 75 AudioManager::Format format, // Format of the stream. |
| 61 int channels, // Number of channels. | 76 int channels, // Number of channels. |
| 62 int sample_rate, // Sampling frequency/rate. | 77 int sample_rate, // Sampling frequency/rate. |
| 63 int bits_per_sample, // Number of bits per sample. | 78 int bits_per_sample, // Number of bits per sample. |
| 64 int samples_per_packet); // Size of the hardware buffer. | 79 int samples_per_packet); // Size of the hardware buffer. |
| 65 | 80 |
| 81 // Sets the factory used by the static method Create. AudioInputController |
| 82 // does not take ownership of |factory|. A value of NULL results in an |
| 83 // AudioInputController being created directly. |
| 84 #if defined(UNIT_TEST) |
| 85 static void set_factory(Factory* factory) { factory_ = factory; } |
| 86 #endif |
| 87 |
| 66 // Starts recording in this audio input stream. | 88 // Starts recording in this audio input stream. |
| 67 void Record(); | 89 virtual void Record(); |
| 68 | 90 |
| 69 // Closes the audio input stream and shutdown the audio input controller | 91 // Closes the audio input stream and shutdown the audio input controller |
| 70 // thread. This method returns only after all operations are completed. This | 92 // thread. This method returns only after all operations are completed. This |
| 71 // input controller cannot be used after this method is called. | 93 // input controller cannot be used after this method is called. |
| 72 // | 94 // |
| 73 // It is safe to call this method more than once. Calls after the first one | 95 // It is safe to call this method more than once. Calls after the first one |
| 74 // will have no effect. | 96 // will have no effect. |
| 75 void Close(); | 97 virtual void Close(); |
| 76 | 98 |
| 77 /////////////////////////////////////////////////////////////////////////// | 99 /////////////////////////////////////////////////////////////////////////// |
| 78 // AudioInputCallback methods. | 100 // AudioInputCallback methods. |
| 79 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size); | 101 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size); |
| 80 virtual void OnClose(AudioInputStream* stream); | 102 virtual void OnClose(AudioInputStream* stream); |
| 81 virtual void OnError(AudioInputStream* stream, int code); | 103 virtual void OnError(AudioInputStream* stream, int code); |
| 82 | 104 |
| 83 private: | 105 protected: |
| 84 // Internal state of the source. | 106 // Internal state of the source. |
| 85 enum State { | 107 enum State { |
| 86 kEmpty, | 108 kEmpty, |
| 87 kCreated, | 109 kCreated, |
| 88 kRecording, | 110 kRecording, |
| 89 kClosed, | 111 kClosed, |
| 90 kError | 112 kError |
| 91 }; | 113 }; |
| 92 | 114 |
| 93 AudioInputController(EventHandler* handler); | 115 AudioInputController(EventHandler* handler); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 // |state_| is written on the audio input controller thread and is read on | 128 // |state_| is written on the audio input controller thread and is read on |
| 107 // the hardware audio thread. These operations need to be locked. But lock | 129 // the hardware audio thread. These operations need to be locked. But lock |
| 108 // is not required for reading on the audio input controller thread. | 130 // is not required for reading on the audio input controller thread. |
| 109 State state_; | 131 State state_; |
| 110 | 132 |
| 111 Lock lock_; | 133 Lock lock_; |
| 112 | 134 |
| 113 // The audio input controller thread that this object runs on. | 135 // The audio input controller thread that this object runs on. |
| 114 base::Thread thread_; | 136 base::Thread thread_; |
| 115 | 137 |
| 138 static Factory* factory_; |
| 139 |
| 116 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 140 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 117 }; | 141 }; |
| 118 | 142 |
| 119 } // namespace media | 143 } // namespace media |
| 120 | 144 |
| 121 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 145 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |