|
38 | 38 |
|
39 | 39 | namespace jni |
40 | 40 | { |
41 | | - // A playout-only, "discard" AudioDeviceModule that drives the render pipeline |
42 | | - // by pulling 10 ms PCM chunks from AudioTransport and discarding them. |
43 | | - // - No capture implementation. |
44 | | - // - No real devices touched. |
| 41 | + // A headless AudioDeviceModule that drives the render pipeline by pulling |
| 42 | + // 10 ms PCM chunks from AudioTransport and discarding them, and simulates |
| 43 | + // a microphone by pulling 10 ms PCM chunks from the registered AudioTransport |
| 44 | + // and feeding them into the WebRTC capture pipeline. |
45 | 45 | class HeadlessAudioDeviceModule : public webrtc::AudioDeviceModule |
46 | 46 | { |
47 | 47 | public: |
48 | 48 | static webrtc::scoped_refptr<HeadlessAudioDeviceModule> Create( |
49 | 49 | const webrtc::Environment & env, |
50 | 50 | int sample_rate_hz = 48000, |
51 | | - size_t channels = 1, |
52 | | - int bits_per_sample = 16) |
| 51 | + size_t channels = 1) |
53 | 52 | { |
54 | 53 | return webrtc::make_ref_counted<HeadlessAudioDeviceModule>( |
55 | | - env, sample_rate_hz, channels, bits_per_sample); |
| 54 | + env, sample_rate_hz, channels); |
56 | 55 | } |
57 | 56 |
|
58 | | - HeadlessAudioDeviceModule(const webrtc::Environment & env, int sample_rate_hz, size_t channels, int bits_per_sample); |
| 57 | + HeadlessAudioDeviceModule(const webrtc::Environment & env, int sample_rate_hz, size_t channels); |
59 | 58 | ~HeadlessAudioDeviceModule() override; |
60 | 59 |
|
61 | 60 | // ----- AudioDeviceModule interface ----- |
@@ -149,25 +148,33 @@ namespace jni |
149 | 148 |
|
150 | 149 | private: |
151 | 150 | bool PlayThreadProcess(); |
| 151 | + bool CaptureThreadProcess(); |
152 | 152 |
|
153 | 153 | // State |
154 | 154 | bool initialized_ = false; |
155 | 155 | bool playout_initialized_ = false; |
| 156 | + bool recording_initialized_ = false; |
156 | 157 | bool playing_ = false; |
| 158 | + bool recording_ = false; |
157 | 159 |
|
158 | 160 | // Format |
159 | 161 | int sample_rate_hz_ = 48000; |
160 | 162 | size_t channels_ = 1; |
161 | 163 |
|
162 | 164 | webrtc::BufferT<int16_t> play_buffer_; |
| 165 | + webrtc::BufferT<int16_t> record_buffer_; |
163 | 166 |
|
164 | 167 | size_t playoutFramesIn10MS_; |
| 168 | + size_t recordingFramesIn10MS_; |
165 | 169 | int64_t lastCallPlayoutMillis_; |
| 170 | + int64_t lastCallRecordMillis_; |
166 | 171 |
|
167 | 172 | mutable webrtc::Mutex mutex_; |
168 | 173 | std::unique_ptr<webrtc::AudioDeviceBuffer> audio_device_buffer_ RTC_GUARDED_BY(mutex_); |
| 174 | + webrtc::AudioTransport * audio_callback_; |
169 | 175 |
|
170 | 176 | webrtc::PlatformThread render_thread_; |
| 177 | + webrtc::PlatformThread capture_thread_; |
171 | 178 | }; |
172 | 179 | } |
173 | 180 |
|
|
0 commit comments