2015-11-06 15:34:49 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-23 10:46:32 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
#include "webrtc/audio/audio_state.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
2015-11-06 15:34:49 -08:00
|
|
|
#include "webrtc/test/mock_voice_engine.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct ConfigHelper {
|
|
|
|
|
ConfigHelper() {
|
|
|
|
|
EXPECT_CALL(voice_engine_,
|
|
|
|
|
RegisterVoiceEngineObserver(testing::_)).WillOnce(testing::Return(0));
|
|
|
|
|
EXPECT_CALL(voice_engine_,
|
|
|
|
|
DeRegisterVoiceEngineObserver()).WillOnce(testing::Return(0));
|
2016-11-17 06:28:59 -08:00
|
|
|
EXPECT_CALL(voice_engine_, audio_device_module());
|
|
|
|
|
EXPECT_CALL(voice_engine_, audio_processing());
|
|
|
|
|
EXPECT_CALL(voice_engine_, audio_transport());
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
config_.voice_engine = &voice_engine_;
|
|
|
|
|
}
|
|
|
|
|
AudioState::Config& config() { return config_; }
|
|
|
|
|
MockVoiceEngine& voice_engine() { return voice_engine_; }
|
|
|
|
|
|
|
|
|
|
private:
|
2015-11-16 07:34:50 -08:00
|
|
|
testing::StrictMock<MockVoiceEngine> voice_engine_;
|
2015-11-06 15:34:49 -08:00
|
|
|
AudioState::Config config_;
|
|
|
|
|
};
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
TEST(AudioStateTest, Create) {
|
|
|
|
|
ConfigHelper helper;
|
|
|
|
|
rtc::scoped_refptr<AudioState> audio_state =
|
|
|
|
|
AudioState::Create(helper.config());
|
|
|
|
|
EXPECT_TRUE(audio_state.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AudioStateTest, ConstructDestruct) {
|
|
|
|
|
ConfigHelper helper;
|
2016-02-23 10:46:32 -08:00
|
|
|
std::unique_ptr<internal::AudioState> audio_state(
|
2015-11-06 15:34:49 -08:00
|
|
|
new internal::AudioState(helper.config()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AudioStateTest, GetVoiceEngine) {
|
|
|
|
|
ConfigHelper helper;
|
2016-02-23 10:46:32 -08:00
|
|
|
std::unique_ptr<internal::AudioState> audio_state(
|
2015-11-06 15:34:49 -08:00
|
|
|
new internal::AudioState(helper.config()));
|
|
|
|
|
EXPECT_EQ(audio_state->voice_engine(), &helper.voice_engine());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AudioStateTest, TypingNoiseDetected) {
|
|
|
|
|
ConfigHelper helper;
|
2016-02-23 10:46:32 -08:00
|
|
|
std::unique_ptr<internal::AudioState> audio_state(
|
2015-11-06 15:34:49 -08:00
|
|
|
new internal::AudioState(helper.config()));
|
|
|
|
|
VoiceEngineObserver* voe_observer =
|
|
|
|
|
static_cast<VoiceEngineObserver*>(audio_state.get());
|
|
|
|
|
EXPECT_FALSE(audio_state->typing_noise_detected());
|
|
|
|
|
|
|
|
|
|
voe_observer->CallbackOnError(-1, VE_NOT_INITED);
|
|
|
|
|
EXPECT_FALSE(audio_state->typing_noise_detected());
|
|
|
|
|
|
|
|
|
|
voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING);
|
|
|
|
|
EXPECT_TRUE(audio_state->typing_noise_detected());
|
|
|
|
|
voe_observer->CallbackOnError(-1, VE_NOT_INITED);
|
|
|
|
|
EXPECT_TRUE(audio_state->typing_noise_detected());
|
|
|
|
|
|
|
|
|
|
voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING);
|
|
|
|
|
EXPECT_FALSE(audio_state->typing_noise_detected());
|
|
|
|
|
voe_observer->CallbackOnError(-1, VE_NOT_INITED);
|
|
|
|
|
EXPECT_FALSE(audio_state->typing_noise_detected());
|
|
|
|
|
}
|
2016-11-17 06:28:59 -08:00
|
|
|
|
|
|
|
|
// Test that RecordedDataIsAvailable calls get to the original transport.
|
|
|
|
|
TEST(AudioStateTest, RecordedAudioArrivesAtOriginalTransport) {
|
|
|
|
|
using testing::_;
|
|
|
|
|
|
|
|
|
|
ConfigHelper helper;
|
|
|
|
|
auto& voice_engine = helper.voice_engine();
|
|
|
|
|
auto device =
|
|
|
|
|
static_cast<MockAudioDeviceModule*>(voice_engine.audio_device_module());
|
|
|
|
|
|
|
|
|
|
AudioTransport* audio_transport_proxy = nullptr;
|
|
|
|
|
ON_CALL(*device, RegisterAudioCallback(_))
|
|
|
|
|
.WillByDefault(
|
|
|
|
|
testing::Invoke([&audio_transport_proxy](AudioTransport* transport) {
|
|
|
|
|
audio_transport_proxy = transport;
|
|
|
|
|
return 0;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
MockAudioTransport original_audio_transport;
|
|
|
|
|
ON_CALL(voice_engine, audio_transport())
|
|
|
|
|
.WillByDefault(testing::Return(&original_audio_transport));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(voice_engine, audio_device_module());
|
|
|
|
|
std::unique_ptr<internal::AudioState> audio_state(
|
|
|
|
|
new internal::AudioState(helper.config()));
|
|
|
|
|
|
|
|
|
|
// Setup completed. Ensure call of old transport is forwarded to new.
|
|
|
|
|
uint32_t new_mic_level;
|
|
|
|
|
EXPECT_CALL(original_audio_transport,
|
|
|
|
|
RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, 0, false,
|
|
|
|
|
testing::Ref(new_mic_level)));
|
|
|
|
|
|
|
|
|
|
audio_transport_proxy->RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0,
|
|
|
|
|
0, false, new_mic_level);
|
|
|
|
|
}
|
2015-11-06 15:34:49 -08:00
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|