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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 virtual void OnError(AudioInputController* controller, int error_code) = 0; | 48 virtual void OnError(AudioInputController* controller, int error_code) = 0; |
49 virtual void OnData(AudioInputController* controller, const uint8* data, | 49 virtual void OnData(AudioInputController* controller, const uint8* data, |
50 uint32 size) = 0; | 50 uint32 size) = 0; |
51 }; | 51 }; |
52 | 52 |
53 // AudioInputController::Create uses the currently registered Factory to | 53 // AudioInputController::Create uses the currently registered Factory to |
54 // create the AudioInputController. Factory is intended for testing. | 54 // create the AudioInputController. Factory is intended for testing. |
55 class Factory { | 55 class Factory { |
56 public: | 56 public: |
57 virtual AudioInputController* Create(EventHandler* event_handler, | 57 virtual AudioInputController* Create(EventHandler* event_handler, |
58 AudioParameters params, | 58 AudioParameters params) = 0; |
59 int samples_per_packet) = 0; | |
60 | 59 |
61 protected: | 60 protected: |
62 virtual ~Factory() {} | 61 virtual ~Factory() {} |
63 }; | 62 }; |
64 | 63 |
65 virtual ~AudioInputController(); | 64 virtual ~AudioInputController(); |
66 | 65 |
67 // Factory method for creating an AudioInputController. | 66 // Factory method for creating an AudioInputController. |
68 // If successful, an audio input controller thread is created. The audio | 67 // If successful, an audio input controller thread is created. The audio |
69 // device will be created on the new thread and when that is done event | 68 // device will be created on the new thread and when that is done event |
70 // handler will receive a OnCreated() call. | 69 // handler will receive a OnCreated() call. |
71 static scoped_refptr<AudioInputController> Create( | 70 static scoped_refptr<AudioInputController> Create( |
72 EventHandler* event_handler, | 71 EventHandler* event_handler, |
73 AudioParameters params, | 72 AudioParameters params); |
74 int samples_per_packet); // Size of the hardware buffer. | |
75 | 73 |
76 // Sets the factory used by the static method Create. AudioInputController | 74 // Sets the factory used by the static method Create. AudioInputController |
77 // does not take ownership of |factory|. A value of NULL results in an | 75 // does not take ownership of |factory|. A value of NULL results in an |
78 // AudioInputController being created directly. | 76 // AudioInputController being created directly. |
79 #if defined(UNIT_TEST) | 77 #if defined(UNIT_TEST) |
80 static void set_factory(Factory* factory) { factory_ = factory; } | 78 static void set_factory(Factory* factory) { factory_ = factory; } |
81 #endif | 79 #endif |
82 | 80 |
83 // Starts recording in this audio input stream. | 81 // Starts recording in this audio input stream. |
84 virtual void Record(); | 82 virtual void Record(); |
(...skipping 18 matching lines...) Expand all Loading... |
103 kEmpty, | 101 kEmpty, |
104 kCreated, | 102 kCreated, |
105 kRecording, | 103 kRecording, |
106 kClosed, | 104 kClosed, |
107 kError | 105 kError |
108 }; | 106 }; |
109 | 107 |
110 AudioInputController(EventHandler* handler); | 108 AudioInputController(EventHandler* handler); |
111 | 109 |
112 // The following methods are executed on the audio controller thread. | 110 // The following methods are executed on the audio controller thread. |
113 void DoCreate(AudioParameters params, | 111 void DoCreate(AudioParameters params); |
114 uint32 samples_per_packet); | |
115 void DoRecord(); | 112 void DoRecord(); |
116 void DoClose(); | 113 void DoClose(); |
117 void DoReportError(int code); | 114 void DoReportError(int code); |
118 | 115 |
119 EventHandler* handler_; | 116 EventHandler* handler_; |
120 AudioInputStream* stream_; | 117 AudioInputStream* stream_; |
121 | 118 |
122 // |state_| is written on the audio input controller thread and is read on | 119 // |state_| is written on the audio input controller thread and is read on |
123 // the hardware audio thread. These operations need to be locked. But lock | 120 // the hardware audio thread. These operations need to be locked. But lock |
124 // is not required for reading on the audio input controller thread. | 121 // is not required for reading on the audio input controller thread. |
125 State state_; | 122 State state_; |
126 | 123 |
127 Lock lock_; | 124 Lock lock_; |
128 | 125 |
129 // The audio input controller thread that this object runs on. | 126 // The audio input controller thread that this object runs on. |
130 base::Thread thread_; | 127 base::Thread thread_; |
131 | 128 |
132 static Factory* factory_; | 129 static Factory* factory_; |
133 | 130 |
134 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 131 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
135 }; | 132 }; |
136 | 133 |
137 } // namespace media | 134 } // namespace media |
138 | 135 |
139 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 136 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
OLD | NEW |