Unit test around ProcessThread usage
Bug: webrtc:11989 Change-Id: Ic631e80c4e5db6e3558ff714cc105e5a4874f744 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186421 Commit-Queue: Tim Na <natim@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32331}
This commit is contained in:
parent
43546869d6
commit
16e7b515ee
@ -19,6 +19,7 @@ if (rtc_include_tests) {
|
||||
"../../../api/task_queue:default_task_queue_factory",
|
||||
"../../../modules/audio_device:mock_audio_device",
|
||||
"../../../modules/audio_processing:mocks",
|
||||
"../../../modules/utility:mock_process_thread",
|
||||
"../../../test:audio_codec_mocks",
|
||||
"../../../test:mock_transport",
|
||||
"../../../test:test_support",
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "api/task_queue/default_task_queue_factory.h"
|
||||
#include "modules/audio_device/include/mock_audio_device.h"
|
||||
#include "modules/audio_processing/include/mock_audio_processing.h"
|
||||
#include "modules/utility/include/mock/mock_process_thread.h"
|
||||
#include "test/gtest.h"
|
||||
#include "test/mock_transport.h"
|
||||
|
||||
@ -40,15 +41,20 @@ class VoipCoreTest : public ::testing::Test {
|
||||
rtc::scoped_refptr<AudioProcessing> audio_processing =
|
||||
new rtc::RefCountedObject<test::MockAudioProcessing>();
|
||||
|
||||
auto process_thread = std::make_unique<NiceMock<MockProcessThread>>();
|
||||
// Hold the pointer to use for testing.
|
||||
process_thread_ = process_thread.get();
|
||||
|
||||
voip_core_ = std::make_unique<VoipCore>();
|
||||
voip_core_->Init(std::move(encoder_factory), std::move(decoder_factory),
|
||||
CreateDefaultTaskQueueFactory(), audio_device_,
|
||||
std::move(audio_processing));
|
||||
std::move(audio_processing), std::move(process_thread));
|
||||
}
|
||||
|
||||
std::unique_ptr<VoipCore> voip_core_;
|
||||
NiceMock<MockTransport> transport_;
|
||||
rtc::scoped_refptr<test::MockAudioDeviceModule> audio_device_;
|
||||
NiceMock<MockProcessThread>* process_thread_;
|
||||
};
|
||||
|
||||
// Validate expected API calls that involves with VoipCore. Some verification is
|
||||
@ -176,5 +182,34 @@ TEST_F(VoipCoreTest, StopSendAndPlayoutWithoutStarting) {
|
||||
voip_core_->ReleaseChannel(*channel);
|
||||
}
|
||||
|
||||
// This tests correctness on ProcessThread usage where we expect the first/last
|
||||
// channel creation/release triggers its Start/Stop method once only.
|
||||
TEST_F(VoipCoreTest, TestProcessThreadOperation) {
|
||||
EXPECT_CALL(*process_thread_, Start);
|
||||
EXPECT_CALL(*process_thread_, RegisterModule).Times(2);
|
||||
|
||||
auto channel_one = voip_core_->CreateChannel(&transport_, 0xdeadc0de);
|
||||
auto channel_two = voip_core_->CreateChannel(&transport_, 0xdeadbeef);
|
||||
EXPECT_TRUE(channel_one);
|
||||
EXPECT_TRUE(channel_two);
|
||||
|
||||
EXPECT_CALL(*process_thread_, Stop);
|
||||
EXPECT_CALL(*process_thread_, DeRegisterModule).Times(2);
|
||||
|
||||
voip_core_->ReleaseChannel(*channel_one);
|
||||
voip_core_->ReleaseChannel(*channel_two);
|
||||
|
||||
EXPECT_CALL(*process_thread_, Start);
|
||||
EXPECT_CALL(*process_thread_, RegisterModule);
|
||||
|
||||
auto channel_three = voip_core_->CreateChannel(&transport_, absl::nullopt);
|
||||
EXPECT_TRUE(channel_three);
|
||||
|
||||
EXPECT_CALL(*process_thread_, Stop);
|
||||
EXPECT_CALL(*process_thread_, DeRegisterModule);
|
||||
|
||||
voip_core_->ReleaseChannel(*channel_three);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
|
||||
@ -41,14 +41,18 @@ bool VoipCore::Init(rtc::scoped_refptr<AudioEncoderFactory> encoder_factory,
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
||||
std::unique_ptr<TaskQueueFactory> task_queue_factory,
|
||||
rtc::scoped_refptr<AudioDeviceModule> audio_device_module,
|
||||
rtc::scoped_refptr<AudioProcessing> audio_processing) {
|
||||
rtc::scoped_refptr<AudioProcessing> audio_processing,
|
||||
std::unique_ptr<ProcessThread> process_thread) {
|
||||
encoder_factory_ = std::move(encoder_factory);
|
||||
decoder_factory_ = std::move(decoder_factory);
|
||||
task_queue_factory_ = std::move(task_queue_factory);
|
||||
audio_device_module_ = std::move(audio_device_module);
|
||||
audio_processing_ = std::move(audio_processing);
|
||||
process_thread_ = std::move(process_thread);
|
||||
|
||||
process_thread_ = ProcessThread::Create("ModuleProcessThread");
|
||||
if (!process_thread_) {
|
||||
process_thread_ = ProcessThread::Create("ModuleProcessThread");
|
||||
}
|
||||
audio_mixer_ = AudioMixerImpl::Create();
|
||||
|
||||
// AudioTransportImpl depends on audio mixer and audio processing instances.
|
||||
|
||||
@ -54,12 +54,16 @@ class VoipCore : public VoipEngine,
|
||||
// Initialize VoipCore components with provided arguments.
|
||||
// Returns false only when |audio_device_module| fails to initialize which
|
||||
// would presumably render further processing useless.
|
||||
// ProcessThread implementation can be injected by |process_thread|
|
||||
// (mainly for testing purpose) and when set to nullptr, default
|
||||
// implementation will be used.
|
||||
// TODO(natim@webrtc.org): Need to report audio device errors to user layer.
|
||||
bool Init(rtc::scoped_refptr<AudioEncoderFactory> encoder_factory,
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
||||
std::unique_ptr<TaskQueueFactory> task_queue_factory,
|
||||
rtc::scoped_refptr<AudioDeviceModule> audio_device_module,
|
||||
rtc::scoped_refptr<AudioProcessing> audio_processing);
|
||||
rtc::scoped_refptr<AudioProcessing> audio_processing,
|
||||
std::unique_ptr<ProcessThread> process_thread = nullptr);
|
||||
|
||||
// Implements VoipEngine interfaces.
|
||||
VoipBase& Base() override { return *this; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user