Replace RegisterExternalDecoder with decoder factory in NetEqImplTest120ms
Change-Id: I86b5f748f556be186f020a97fcc1211f953fd219 Bug: webrtc:10080 Change-Id: I86b5f748f556be186f020a97fcc1211f953fd219 Reviewed-on: https://webrtc-review.googlesource.com/c/112600 Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25869}
This commit is contained in:
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "absl/memory/memory.h"
|
||||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||||
#include "common_types.h" // NOLINT(build/include)
|
#include "common_types.h" // NOLINT(build/include)
|
||||||
#include "modules/audio_coding/neteq/accelerate.h"
|
#include "modules/audio_coding/neteq/accelerate.h"
|
||||||
@ -28,6 +29,7 @@
|
|||||||
#include "modules/audio_coding/neteq/sync_buffer.h"
|
#include "modules/audio_coding/neteq/sync_buffer.h"
|
||||||
#include "modules/audio_coding/neteq/timestamp_scaler.h"
|
#include "modules/audio_coding/neteq/timestamp_scaler.h"
|
||||||
#include "rtc_base/numerics/safe_conversions.h"
|
#include "rtc_base/numerics/safe_conversions.h"
|
||||||
|
#include "test/function_audio_decoder_factory.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#include "test/mock_audio_decoder.h"
|
#include "test/mock_audio_decoder.h"
|
||||||
@ -59,8 +61,10 @@ class NetEqImplTest : public ::testing::Test {
|
|||||||
protected:
|
protected:
|
||||||
NetEqImplTest() { config_.sample_rate_hz = 8000; }
|
NetEqImplTest() { config_.sample_rate_hz = 8000; }
|
||||||
|
|
||||||
void CreateInstance() {
|
void CreateInstance(
|
||||||
NetEqImpl::Dependencies deps(config_, CreateBuiltinAudioDecoderFactory());
|
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
|
||||||
|
ASSERT_TRUE(decoder_factory);
|
||||||
|
NetEqImpl::Dependencies deps(config_, decoder_factory);
|
||||||
|
|
||||||
// Get a local pointer to NetEq's TickTimer object.
|
// Get a local pointer to NetEq's TickTimer object.
|
||||||
tick_timer_ = deps.tick_timer.get();
|
tick_timer_ = deps.tick_timer.get();
|
||||||
@ -137,6 +141,8 @@ class NetEqImplTest : public ::testing::Test {
|
|||||||
ASSERT_TRUE(neteq_ != NULL);
|
ASSERT_TRUE(neteq_ != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreateInstance() { CreateInstance(CreateBuiltinAudioDecoderFactory()); }
|
||||||
|
|
||||||
void UseNoMocks() {
|
void UseNoMocks() {
|
||||||
ASSERT_TRUE(neteq_ == NULL) << "Must call UseNoMocks before CreateInstance";
|
ASSERT_TRUE(neteq_ == NULL) << "Must call UseNoMocks before CreateInstance";
|
||||||
use_mock_buffer_level_filter_ = false;
|
use_mock_buffer_level_filter_ = false;
|
||||||
@ -1328,13 +1334,17 @@ class NetEqImplTest120ms : public NetEqImplTest {
|
|||||||
|
|
||||||
void CreateInstanceNoMocks() {
|
void CreateInstanceNoMocks() {
|
||||||
UseNoMocks();
|
UseNoMocks();
|
||||||
CreateInstance();
|
CreateInstance(decoder_factory_);
|
||||||
|
EXPECT_TRUE(neteq_->RegisterPayloadType(
|
||||||
|
kPayloadType, SdpAudioFormat("opus", 48000, 2, {{"stereo", "1"}})));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateInstanceWithDelayManagerMock() {
|
void CreateInstanceWithDelayManagerMock() {
|
||||||
UseNoMocks();
|
UseNoMocks();
|
||||||
use_mock_delay_manager_ = true;
|
use_mock_delay_manager_ = true;
|
||||||
CreateInstance();
|
CreateInstance(decoder_factory_);
|
||||||
|
EXPECT_TRUE(neteq_->RegisterPayloadType(
|
||||||
|
kPayloadType, SdpAudioFormat("opus", 48000, 2, {{"stereo", "1"}})));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t timestamp_diff_between_packets() const {
|
uint32_t timestamp_diff_between_packets() const {
|
||||||
@ -1364,14 +1374,18 @@ class NetEqImplTest120ms : public NetEqImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Register120msCodec(AudioDecoder::SpeechType speech_type) {
|
void Register120msCodec(AudioDecoder::SpeechType speech_type) {
|
||||||
decoder_.reset(new Decoder120ms(kSamplingFreq_, speech_type));
|
const uint32_t sampling_freq = kSamplingFreq_;
|
||||||
ASSERT_EQ(2u, decoder_->Channels());
|
decoder_factory_ =
|
||||||
EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder(
|
new rtc::RefCountedObject<test::FunctionAudioDecoderFactory>(
|
||||||
decoder_.get(), NetEqDecoder::kDecoderOpus_2ch,
|
[sampling_freq, speech_type]() {
|
||||||
"120ms codec", kPayloadType));
|
std::unique_ptr<AudioDecoder> decoder =
|
||||||
|
absl::make_unique<Decoder120ms>(sampling_freq, speech_type);
|
||||||
|
RTC_CHECK_EQ(2, decoder->Channels());
|
||||||
|
return decoder;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Decoder120ms> decoder_;
|
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
|
||||||
AudioFrame output_;
|
AudioFrame output_;
|
||||||
const uint32_t kPayloadType = 17;
|
const uint32_t kPayloadType = 17;
|
||||||
const uint32_t kSamplingFreq_ = 48000;
|
const uint32_t kSamplingFreq_ = 48000;
|
||||||
@ -1379,8 +1393,8 @@ class NetEqImplTest120ms : public NetEqImplTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(NetEqImplTest120ms, CodecInternalCng) {
|
TEST_F(NetEqImplTest120ms, CodecInternalCng) {
|
||||||
CreateInstanceNoMocks();
|
|
||||||
Register120msCodec(AudioDecoder::kComfortNoise);
|
Register120msCodec(AudioDecoder::kComfortNoise);
|
||||||
|
CreateInstanceNoMocks();
|
||||||
|
|
||||||
InsertPacket(first_timestamp());
|
InsertPacket(first_timestamp());
|
||||||
GetFirstPacket();
|
GetFirstPacket();
|
||||||
@ -1391,8 +1405,8 @@ TEST_F(NetEqImplTest120ms, CodecInternalCng) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NetEqImplTest120ms, Normal) {
|
TEST_F(NetEqImplTest120ms, Normal) {
|
||||||
CreateInstanceNoMocks();
|
|
||||||
Register120msCodec(AudioDecoder::kSpeech);
|
Register120msCodec(AudioDecoder::kSpeech);
|
||||||
|
CreateInstanceNoMocks();
|
||||||
|
|
||||||
InsertPacket(first_timestamp());
|
InsertPacket(first_timestamp());
|
||||||
GetFirstPacket();
|
GetFirstPacket();
|
||||||
@ -1401,9 +1415,9 @@ TEST_F(NetEqImplTest120ms, Normal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NetEqImplTest120ms, Merge) {
|
TEST_F(NetEqImplTest120ms, Merge) {
|
||||||
|
Register120msCodec(AudioDecoder::kSpeech);
|
||||||
CreateInstanceWithDelayManagerMock();
|
CreateInstanceWithDelayManagerMock();
|
||||||
|
|
||||||
Register120msCodec(AudioDecoder::kSpeech);
|
|
||||||
InsertPacket(first_timestamp());
|
InsertPacket(first_timestamp());
|
||||||
|
|
||||||
GetFirstPacket();
|
GetFirstPacket();
|
||||||
@ -1420,8 +1434,8 @@ TEST_F(NetEqImplTest120ms, Merge) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NetEqImplTest120ms, Expand) {
|
TEST_F(NetEqImplTest120ms, Expand) {
|
||||||
CreateInstanceNoMocks();
|
|
||||||
Register120msCodec(AudioDecoder::kSpeech);
|
Register120msCodec(AudioDecoder::kSpeech);
|
||||||
|
CreateInstanceNoMocks();
|
||||||
|
|
||||||
InsertPacket(first_timestamp());
|
InsertPacket(first_timestamp());
|
||||||
GetFirstPacket();
|
GetFirstPacket();
|
||||||
@ -1432,8 +1446,8 @@ TEST_F(NetEqImplTest120ms, Expand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NetEqImplTest120ms, FastAccelerate) {
|
TEST_F(NetEqImplTest120ms, FastAccelerate) {
|
||||||
CreateInstanceWithDelayManagerMock();
|
|
||||||
Register120msCodec(AudioDecoder::kSpeech);
|
Register120msCodec(AudioDecoder::kSpeech);
|
||||||
|
CreateInstanceWithDelayManagerMock();
|
||||||
|
|
||||||
InsertPacket(first_timestamp());
|
InsertPacket(first_timestamp());
|
||||||
GetFirstPacket();
|
GetFirstPacket();
|
||||||
@ -1450,8 +1464,8 @@ TEST_F(NetEqImplTest120ms, FastAccelerate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NetEqImplTest120ms, PreemptiveExpand) {
|
TEST_F(NetEqImplTest120ms, PreemptiveExpand) {
|
||||||
CreateInstanceWithDelayManagerMock();
|
|
||||||
Register120msCodec(AudioDecoder::kSpeech);
|
Register120msCodec(AudioDecoder::kSpeech);
|
||||||
|
CreateInstanceWithDelayManagerMock();
|
||||||
|
|
||||||
InsertPacket(first_timestamp());
|
InsertPacket(first_timestamp());
|
||||||
GetFirstPacket();
|
GetFirstPacket();
|
||||||
@ -1469,8 +1483,8 @@ TEST_F(NetEqImplTest120ms, PreemptiveExpand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NetEqImplTest120ms, Accelerate) {
|
TEST_F(NetEqImplTest120ms, Accelerate) {
|
||||||
CreateInstanceWithDelayManagerMock();
|
|
||||||
Register120msCodec(AudioDecoder::kSpeech);
|
Register120msCodec(AudioDecoder::kSpeech);
|
||||||
|
CreateInstanceWithDelayManagerMock();
|
||||||
|
|
||||||
InsertPacket(first_timestamp());
|
InsertPacket(first_timestamp());
|
||||||
GetFirstPacket();
|
GetFirstPacket();
|
||||||
|
@ -830,6 +830,7 @@ rtc_source_set("test_renderer_generic") {
|
|||||||
rtc_source_set("audio_codec_mocks") {
|
rtc_source_set("audio_codec_mocks") {
|
||||||
testonly = true
|
testonly = true
|
||||||
sources = [
|
sources = [
|
||||||
|
"function_audio_decoder_factory.h",
|
||||||
"mock_audio_decoder.cc",
|
"mock_audio_decoder.cc",
|
||||||
"mock_audio_decoder.h",
|
"mock_audio_decoder.h",
|
||||||
"mock_audio_decoder_factory.h",
|
"mock_audio_decoder_factory.h",
|
||||||
@ -843,7 +844,9 @@ rtc_source_set("audio_codec_mocks") {
|
|||||||
"../api:array_view",
|
"../api:array_view",
|
||||||
"../api/audio_codecs:audio_codecs_api",
|
"../api/audio_codecs:audio_codecs_api",
|
||||||
"../api/audio_codecs:builtin_audio_decoder_factory",
|
"../api/audio_codecs:builtin_audio_decoder_factory",
|
||||||
|
"../rtc_base:checks",
|
||||||
"../rtc_base:rtc_base_approved",
|
"../rtc_base:rtc_base_approved",
|
||||||
|
"//third_party/abseil-cpp/absl/memory",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
68
test/function_audio_decoder_factory.h
Normal file
68
test/function_audio_decoder_factory.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_
|
||||||
|
#define TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/memory/memory.h"
|
||||||
|
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||||
|
#include "api/audio_codecs/audio_format.h"
|
||||||
|
#include "rtc_base/checks.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
// A decoder factory producing decoders by calling a supplied create function.
|
||||||
|
class FunctionAudioDecoderFactory : public AudioDecoderFactory {
|
||||||
|
public:
|
||||||
|
explicit FunctionAudioDecoderFactory(
|
||||||
|
std::function<std::unique_ptr<AudioDecoder>()> create)
|
||||||
|
: create_([create](const SdpAudioFormat&,
|
||||||
|
absl::optional<AudioCodecPairId> codec_pair_id) {
|
||||||
|
return create();
|
||||||
|
}) {}
|
||||||
|
explicit FunctionAudioDecoderFactory(
|
||||||
|
std::function<std::unique_ptr<AudioDecoder>(
|
||||||
|
const SdpAudioFormat&,
|
||||||
|
absl::optional<AudioCodecPairId> codec_pair_id)> create)
|
||||||
|
: create_(std::move(create)) {}
|
||||||
|
|
||||||
|
// Unused by tests.
|
||||||
|
std::vector<AudioCodecSpec> GetSupportedDecoders() override {
|
||||||
|
RTC_NOTREACHED();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsSupportedDecoder(const SdpAudioFormat& format) override {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<AudioDecoder> MakeAudioDecoder(
|
||||||
|
const SdpAudioFormat& format,
|
||||||
|
absl::optional<AudioCodecPairId> codec_pair_id) override {
|
||||||
|
return create_(format, codec_pair_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::function<std::unique_ptr<AudioDecoder>(
|
||||||
|
const SdpAudioFormat&,
|
||||||
|
absl::optional<AudioCodecPairId> codec_pair_id)>
|
||||||
|
create_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // TEST_FUNCTION_AUDIO_DECODER_FACTORY_H_
|
Reference in New Issue
Block a user