Skip to content

Commit f5b8880

Browse files
committed
feat: enhance HeadlessAudioDeviceModule with recording capabilities
1 parent 3395bb4 commit f5b8880

4 files changed

Lines changed: 194 additions & 54 deletions

File tree

.github/actions/prepare-linux/action.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@ runs:
3131
- name: Install required packages
3232
run: |
3333
sudo apt update
34-
sudo apt install -y binutils cmake git locales lsb-release ninja-build pkg-config python3 python3-setuptools rsync unzip wget xz-utils
34+
sudo apt install -y binutils cmake git locales lsb-release ninja-build pipewire pipewire-pulse pkg-config python3 python3-setuptools rsync unzip wget xz-utils
3535
3636
# Chromium Clang to be used with the clang toolchain file
3737
#curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python3 - --output-dir=/opt/clang
3838
# Use a more stable version of Clang
3939
sudo mkdir -p /opt/clang
4040
wget https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-llvmorg-20-init-9764-gb81d8e90-72.tar.xz
4141
sudo tar -xvf clang-llvmorg-20-init-9764-gb81d8e90-72.tar.xz -C /opt/clang
42-
43-
# Required for testing
44-
#pulseaudio --start
45-
sudo apt install -y pipewire pipewire-pulse gstreamer1.0-pipewire libspa-0.2-bluetooth libspa-0.2-jack pipewire-audio-client-libraries
46-
systemctl --user daemon-reload
47-
systemctl --user --now enable pipewire{,-pulse}.{socket,service}
4842
shell: bash
4943

5044
- name: Install required packages for x86-64

webrtc-jni/src/main/cpp/include/api/HeadlessAudioDeviceModule.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,23 @@
3838

3939
namespace jni
4040
{
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.
4545
class HeadlessAudioDeviceModule : public webrtc::AudioDeviceModule
4646
{
4747
public:
4848
static webrtc::scoped_refptr<HeadlessAudioDeviceModule> Create(
4949
const webrtc::Environment & env,
5050
int sample_rate_hz = 48000,
51-
size_t channels = 1,
52-
int bits_per_sample = 16)
51+
size_t channels = 1)
5352
{
5453
return webrtc::make_ref_counted<HeadlessAudioDeviceModule>(
55-
env, sample_rate_hz, channels, bits_per_sample);
54+
env, sample_rate_hz, channels);
5655
}
5756

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);
5958
~HeadlessAudioDeviceModule() override;
6059

6160
// ----- AudioDeviceModule interface -----
@@ -149,25 +148,33 @@ namespace jni
149148

150149
private:
151150
bool PlayThreadProcess();
151+
bool CaptureThreadProcess();
152152

153153
// State
154154
bool initialized_ = false;
155155
bool playout_initialized_ = false;
156+
bool recording_initialized_ = false;
156157
bool playing_ = false;
158+
bool recording_ = false;
157159

158160
// Format
159161
int sample_rate_hz_ = 48000;
160162
size_t channels_ = 1;
161163

162164
webrtc::BufferT<int16_t> play_buffer_;
165+
webrtc::BufferT<int16_t> record_buffer_;
163166

164167
size_t playoutFramesIn10MS_;
168+
size_t recordingFramesIn10MS_;
165169
int64_t lastCallPlayoutMillis_;
170+
int64_t lastCallRecordMillis_;
166171

167172
mutable webrtc::Mutex mutex_;
168173
std::unique_ptr<webrtc::AudioDeviceBuffer> audio_device_buffer_ RTC_GUARDED_BY(mutex_);
174+
webrtc::AudioTransport * audio_callback_;
169175

170176
webrtc::PlatformThread render_thread_;
177+
webrtc::PlatformThread capture_thread_;
171178
};
172179
}
173180

0 commit comments

Comments
 (0)