Skip to content

Commit

Permalink
go back to ZeroCapturer
Browse files Browse the repository at this point in the history
  • Loading branch information
duvallj committed Apr 24, 2024
1 parent e1e0d4d commit 5d8f59e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ PeerConnectionFactory::PeerConnectionFactory(const Napi::CallbackInfo &info)
})
.Or([]() {
return TestAudioDeviceModule::CreateTestAudioDeviceModule(
webrtc::TestAudioDeviceModule::CreatePulsedNoiseCapturer(
0, 48000),
TestAudioDeviceModule::CreateZeroCapturer(48000, 1),
webrtc::TestAudioDeviceModule::CreateDiscardRenderer(
48000));
});
Expand Down
35 changes: 35 additions & 0 deletions src/webrtc/test_audio_device_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <algorithm>
#include <cstdlib>
#include <iosfwd>
#include <memory>
#include <type_traits>
#include <vector>

Expand Down Expand Up @@ -270,6 +271,32 @@ class
bool stop_thread_ RTC_GUARDED_BY(lock_) = false;
};

class ZeroCapturerImpl final : public webrtc::TestAudioDeviceModule::Capturer {
public:
ZeroCapturerImpl(int sampling_frequency_in_hz, int num_channels)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
num_channels_(num_channels) {}

int SamplingFrequency() const override { return sampling_frequency_in_hz_; }

int NumChannels() const override { return num_channels_; }

bool Capture(rtc::BufferT<int16_t> *buffer) override {
buffer->SetData(
TestAudioDeviceModule::SamplesPerFrame(sampling_frequency_in_hz_) *
num_channels_,
[&](rtc::ArrayView<int16_t> data) {
std::fill(data.begin(), data.end(), 0);
return data.size();
});
return true;
}

private:
int sampling_frequency_in_hz_;
const int num_channels_;
};

} // namespace

size_t TestAudioDeviceModule::SamplesPerFrame(int sampling_frequency_in_hz) {
Expand All @@ -285,4 +312,12 @@ TestAudioDeviceModule::CreateTestAudioDeviceModule(
std::move(capturer), std::move(renderer), speed);
}

std::unique_ptr<webrtc::TestAudioDeviceModule::Capturer>
TestAudioDeviceModule::CreateZeroCapturer(

int sampling_frequency_in_hz, int num_channels) {
return std::make_unique<ZeroCapturerImpl>(sampling_frequency_in_hz,
num_channels);
}

} // namespace node_webrtc
3 changes: 3 additions & 0 deletions src/webrtc/test_audio_device_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class TestAudioDeviceModule
std::unique_ptr<webrtc::TestAudioDeviceModule::Renderer> renderer,
float speed = 1);

static std::unique_ptr<webrtc::TestAudioDeviceModule::Capturer>
CreateZeroCapturer(int sampling_frequency_in_hz, int num_channels);

int32_t Init() override = 0;

int32_t RegisterAudioCallback(webrtc::AudioTransport *callback) override = 0;
Expand Down

0 comments on commit 5d8f59e

Please sign in to comment.