2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Test to verify correct operation for externally created decoders.
|
|
|
|
|
|
2016-02-14 09:28:33 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2018-04-12 22:44:09 +02:00
|
|
|
#include "api/audio/audio_frame.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "common_types.h" // NOLINT(build/include)
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/mock/mock_external_decoder_pcm16b.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/tools/neteq_external_decoder_test.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/tools/rtp_generator.h"
|
2018-09-06 13:41:30 +02:00
|
|
|
#include "rtc_base/strings/string_builder.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gmock.h"
|
|
|
|
|
#include "test/testsupport/fileutils.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
using ::testing::_;
|
2014-09-22 08:30:07 +00:00
|
|
|
using ::testing::Return;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
class NetEqExternalDecoderUnitTest : public test::NetEqExternalDecoderTest {
|
2013-01-29 12:09:21 +00:00
|
|
|
protected:
|
2015-02-17 10:17:09 +00:00
|
|
|
static const int kFrameSizeMs = 10; // Frame size of Pcm16B.
|
|
|
|
|
|
|
|
|
|
NetEqExternalDecoderUnitTest(NetEqDecoder codec,
|
2016-05-31 06:28:03 -07:00
|
|
|
int sample_rate_hz,
|
2015-02-17 10:17:09 +00:00
|
|
|
MockExternalPcm16B* decoder)
|
2016-05-31 06:28:03 -07:00
|
|
|
: NetEqExternalDecoderTest(codec, sample_rate_hz, decoder),
|
2015-02-17 10:17:09 +00:00
|
|
|
external_decoder_(decoder),
|
2016-05-31 06:28:03 -07:00
|
|
|
samples_per_ms_(sample_rate_hz / 1000),
|
2015-02-17 10:17:09 +00:00
|
|
|
frame_size_samples_(kFrameSizeMs * samples_per_ms_),
|
2014-09-17 15:09:08 +00:00
|
|
|
rtp_generator_(new test::RtpGenerator(samples_per_ms_)),
|
2015-02-17 10:17:09 +00:00
|
|
|
input_(new int16_t[frame_size_samples_]),
|
|
|
|
|
// Payload should be no larger than input.
|
|
|
|
|
encoded_(new uint8_t[2 * frame_size_samples_]),
|
2013-01-29 12:09:21 +00:00
|
|
|
payload_size_bytes_(0),
|
|
|
|
|
last_send_time_(0),
|
|
|
|
|
last_arrival_time_(0) {
|
2015-02-17 10:17:09 +00:00
|
|
|
// NetEq is not allowed to delete the external decoder (hence Times(0)).
|
|
|
|
|
EXPECT_CALL(*external_decoder_, Die()).Times(0);
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
|
|
const std::string file_name =
|
|
|
|
|
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
|
|
|
|
|
input_file_.reset(new test::InputAudioFile(file_name));
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
virtual ~NetEqExternalDecoderUnitTest() {
|
2013-01-29 12:09:21 +00:00
|
|
|
delete[] input_;
|
|
|
|
|
delete[] encoded_;
|
2015-02-17 10:17:09 +00:00
|
|
|
// ~NetEqExternalDecoderTest() will delete |external_decoder_|, so expecting
|
|
|
|
|
// Die() to be called.
|
|
|
|
|
EXPECT_CALL(*external_decoder_, Die()).Times(1);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
// Method to draw kFrameSizeMs audio and verify the output.
|
|
|
|
|
// Use gTest methods. e.g. ASSERT_EQ() inside to trigger errors.
|
|
|
|
|
virtual void GetAndVerifyOutput() = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
// Method to get the number of calls to the Decode() method of the external
|
|
|
|
|
// decoder.
|
|
|
|
|
virtual int NumExpectedDecodeCalls(int num_loops) = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
// Method to generate packets and return the send time of the packet.
|
|
|
|
|
int GetNewPacket() {
|
2013-01-29 12:09:21 +00:00
|
|
|
if (!input_file_->Read(frame_size_samples_, input_)) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
payload_size_bytes_ =
|
|
|
|
|
WebRtcPcm16b_Encode(input_, frame_size_samples_, encoded_);
|
2015-02-17 10:17:09 +00:00
|
|
|
|
2014-09-17 15:09:08 +00:00
|
|
|
int next_send_time = rtp_generator_->GetRtpHeader(
|
|
|
|
|
kPayloadType, frame_size_samples_, &rtp_header_);
|
2013-01-29 12:09:21 +00:00
|
|
|
return next_send_time;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
// Method to decide packet losses.
|
|
|
|
|
virtual bool Lost() { return false; }
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
// Method to calculate packet arrival time.
|
|
|
|
|
int GetArrivalTime(int send_time) {
|
2013-01-29 12:09:21 +00:00
|
|
|
int arrival_time = last_arrival_time_ + (send_time - last_send_time_);
|
|
|
|
|
last_send_time_ = send_time;
|
|
|
|
|
last_arrival_time_ = arrival_time;
|
|
|
|
|
return arrival_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunTest(int num_loops) {
|
|
|
|
|
// Get next input packets (mono and multi-channel).
|
2015-02-17 10:17:09 +00:00
|
|
|
uint32_t next_send_time;
|
|
|
|
|
uint32_t next_arrival_time;
|
2013-01-29 12:09:21 +00:00
|
|
|
do {
|
2015-02-17 10:17:09 +00:00
|
|
|
next_send_time = GetNewPacket();
|
2013-01-29 12:09:21 +00:00
|
|
|
next_arrival_time = GetArrivalTime(next_send_time);
|
|
|
|
|
} while (Lost()); // If lost, immediately read the next packet.
|
|
|
|
|
|
2015-12-08 13:41:35 +01:00
|
|
|
EXPECT_CALL(
|
|
|
|
|
*external_decoder_,
|
|
|
|
|
DecodeInternal(_, payload_size_bytes_, 1000 * samples_per_ms_, _, _))
|
2014-09-22 08:30:07 +00:00
|
|
|
.Times(NumExpectedDecodeCalls(num_loops));
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
uint32_t time_now = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
for (int k = 0; k < num_loops; ++k) {
|
|
|
|
|
while (time_now >= next_arrival_time) {
|
2015-11-11 10:34:00 -08:00
|
|
|
InsertPacket(
|
|
|
|
|
rtp_header_,
|
|
|
|
|
rtc::ArrayView<const uint8_t>(encoded_, payload_size_bytes_),
|
2015-02-17 10:17:09 +00:00
|
|
|
next_arrival_time);
|
2013-01-29 12:09:21 +00:00
|
|
|
// Get next input packet.
|
|
|
|
|
do {
|
2015-02-17 10:17:09 +00:00
|
|
|
next_send_time = GetNewPacket();
|
2013-01-29 12:09:21 +00:00
|
|
|
next_arrival_time = GetArrivalTime(next_send_time);
|
|
|
|
|
} while (Lost()); // If lost, immediately read the next packet.
|
|
|
|
|
}
|
2014-09-17 15:09:08 +00:00
|
|
|
|
2018-09-06 13:41:30 +02:00
|
|
|
rtc::StringBuilder ss;
|
2013-01-29 12:09:21 +00:00
|
|
|
ss << "Lap number " << k << ".";
|
|
|
|
|
SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
|
|
|
|
|
// Compare mono and multi-channel.
|
2015-02-17 10:17:09 +00:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetAndVerifyOutput());
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
time_now += kOutputLengthMs;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 09:14:32 -07:00
|
|
|
void InsertPacket(RTPHeader rtp_header,
|
2015-11-11 10:34:00 -08:00
|
|
|
rtc::ArrayView<const uint8_t> payload,
|
2015-02-17 10:17:09 +00:00
|
|
|
uint32_t receive_timestamp) override {
|
2017-04-24 09:14:32 -07:00
|
|
|
EXPECT_CALL(*external_decoder_,
|
|
|
|
|
IncomingPacket(_, payload.size(), rtp_header.sequenceNumber,
|
|
|
|
|
rtp_header.timestamp, receive_timestamp));
|
2015-02-17 10:17:09 +00:00
|
|
|
NetEqExternalDecoderTest::InsertPacket(rtp_header, payload,
|
|
|
|
|
receive_timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MockExternalPcm16B* external_decoder() { return external_decoder_.get(); }
|
|
|
|
|
|
|
|
|
|
void ResetRtpGenerator(test::RtpGenerator* rtp_generator) {
|
|
|
|
|
rtp_generator_.reset(rtp_generator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int samples_per_ms() const { return samples_per_ms_; }
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
private:
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<MockExternalPcm16B> external_decoder_;
|
2014-09-22 08:30:07 +00:00
|
|
|
int samples_per_ms_;
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t frame_size_samples_;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<test::RtpGenerator> rtp_generator_;
|
2013-01-29 12:09:21 +00:00
|
|
|
int16_t* input_;
|
|
|
|
|
uint8_t* encoded_;
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t payload_size_bytes_;
|
2015-02-17 10:17:09 +00:00
|
|
|
uint32_t last_send_time_;
|
|
|
|
|
uint32_t last_arrival_time_;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<test::InputAudioFile> input_file_;
|
2017-04-24 09:14:32 -07:00
|
|
|
RTPHeader rtp_header_;
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
// This test encodes a few packets of PCM16b 32 kHz data and inserts it into two
|
|
|
|
|
// different NetEq instances. The first instance uses the internal version of
|
|
|
|
|
// the decoder object, while the second one uses an externally created decoder
|
|
|
|
|
// object (ExternalPcm16B wrapped in MockExternalPcm16B, both defined above).
|
|
|
|
|
// The test verifies that the output from both instances match.
|
|
|
|
|
class NetEqExternalVsInternalDecoderTest : public NetEqExternalDecoderUnitTest,
|
|
|
|
|
public ::testing::Test {
|
2014-09-22 08:30:07 +00:00
|
|
|
protected:
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
static const size_t kMaxBlockSize = 480; // 10 ms @ 48 kHz.
|
2014-09-22 08:30:07 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
NetEqExternalVsInternalDecoderTest()
|
2015-10-29 06:20:28 -07:00
|
|
|
: NetEqExternalDecoderUnitTest(NetEqDecoder::kDecoderPCM16Bswb32kHz,
|
2016-05-31 06:28:03 -07:00
|
|
|
32000,
|
2016-06-16 01:59:09 -07:00
|
|
|
new MockExternalPcm16B(32000)),
|
2016-05-31 06:28:03 -07:00
|
|
|
sample_rate_hz_(32000) {
|
2015-02-17 10:17:09 +00:00
|
|
|
NetEq::Config config;
|
2016-05-31 06:28:03 -07:00
|
|
|
config.sample_rate_hz = sample_rate_hz_;
|
2016-05-25 07:37:43 -07:00
|
|
|
neteq_internal_.reset(
|
|
|
|
|
NetEq::Create(config, CreateBuiltinAudioDecoderFactory()));
|
2014-09-22 08:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
void SetUp() override {
|
2016-10-04 09:33:27 -07:00
|
|
|
ASSERT_EQ(true, neteq_internal_->RegisterPayloadType(
|
|
|
|
|
kPayloadType, SdpAudioFormat("L16", 32000, 1)));
|
2014-09-22 08:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
void GetAndVerifyOutput() override {
|
|
|
|
|
// Get audio from internal decoder instance.
|
2016-05-12 13:51:28 -07:00
|
|
|
bool muted;
|
|
|
|
|
EXPECT_EQ(NetEq::kOK, neteq_internal_->GetAudio(&output_internal_, &muted));
|
|
|
|
|
ASSERT_FALSE(muted);
|
2016-03-04 10:34:21 -08:00
|
|
|
EXPECT_EQ(1u, output_internal_.num_channels_);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
EXPECT_EQ(static_cast<size_t>(kOutputLengthMs * sample_rate_hz_ / 1000),
|
2016-03-04 10:34:21 -08:00
|
|
|
output_internal_.samples_per_channel_);
|
2015-02-17 10:17:09 +00:00
|
|
|
|
|
|
|
|
// Get audio from external decoder instance.
|
2016-03-08 02:37:57 -08:00
|
|
|
GetOutputAudio(&output_);
|
2015-02-17 10:17:09 +00:00
|
|
|
|
2017-06-12 12:45:32 -07:00
|
|
|
const int16_t* output_data = output_.data();
|
|
|
|
|
const int16_t* output_internal_data = output_internal_.data();
|
2016-03-04 10:34:21 -08:00
|
|
|
for (size_t i = 0; i < output_.samples_per_channel_; ++i) {
|
2017-06-12 12:45:32 -07:00
|
|
|
ASSERT_EQ(output_data[i], output_internal_data[i])
|
2016-03-04 10:34:21 -08:00
|
|
|
<< "Diff in sample " << i << ".";
|
2015-02-17 10:17:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 09:14:32 -07:00
|
|
|
void InsertPacket(RTPHeader rtp_header,
|
2015-11-11 10:34:00 -08:00
|
|
|
rtc::ArrayView<const uint8_t> payload,
|
2015-02-17 10:17:09 +00:00
|
|
|
uint32_t receive_timestamp) override {
|
|
|
|
|
// Insert packet in internal decoder.
|
2017-04-24 09:14:32 -07:00
|
|
|
ASSERT_EQ(NetEq::kOK, neteq_internal_->InsertPacket(rtp_header, payload,
|
|
|
|
|
receive_timestamp));
|
2015-02-17 10:17:09 +00:00
|
|
|
|
|
|
|
|
// Insert packet in external decoder instance.
|
|
|
|
|
NetEqExternalDecoderUnitTest::InsertPacket(rtp_header, payload,
|
|
|
|
|
receive_timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NumExpectedDecodeCalls(int num_loops) override { return num_loops; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int sample_rate_hz_;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<NetEq> neteq_internal_;
|
2016-03-04 10:34:21 -08:00
|
|
|
AudioFrame output_internal_;
|
|
|
|
|
AudioFrame output_;
|
2015-02-17 10:17:09 +00:00
|
|
|
};
|
|
|
|
|
|
2015-06-16 10:04:20 +02:00
|
|
|
TEST_F(NetEqExternalVsInternalDecoderTest, RunTest) {
|
2015-02-17 10:17:09 +00:00
|
|
|
RunTest(100); // Run 100 laps @ 10 ms each in the test loop.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class LargeTimestampJumpTest : public NetEqExternalDecoderUnitTest,
|
|
|
|
|
public ::testing::Test {
|
|
|
|
|
protected:
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
static const size_t kMaxBlockSize = 480; // 10 ms @ 48 kHz.
|
2015-02-17 10:17:09 +00:00
|
|
|
|
|
|
|
|
enum TestStates {
|
|
|
|
|
kInitialPhase,
|
|
|
|
|
kNormalPhase,
|
|
|
|
|
kExpandPhase,
|
|
|
|
|
kFadedExpandPhase,
|
|
|
|
|
kRecovered
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LargeTimestampJumpTest()
|
2015-10-29 06:20:28 -07:00
|
|
|
: NetEqExternalDecoderUnitTest(NetEqDecoder::kDecoderPCM16B,
|
2016-05-31 06:28:03 -07:00
|
|
|
8000,
|
2016-06-16 01:59:09 -07:00
|
|
|
new MockExternalPcm16B(8000)),
|
2015-02-17 10:17:09 +00:00
|
|
|
test_state_(kInitialPhase) {
|
|
|
|
|
EXPECT_CALL(*external_decoder(), HasDecodePlc())
|
|
|
|
|
.WillRepeatedly(Return(false));
|
2014-09-22 08:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-08 02:37:57 -08:00
|
|
|
virtual void UpdateState(AudioFrame::SpeechType output_type) {
|
2014-09-22 08:30:07 +00:00
|
|
|
switch (test_state_) {
|
|
|
|
|
case kInitialPhase: {
|
2016-03-08 02:37:57 -08:00
|
|
|
if (output_type == AudioFrame::kNormalSpeech) {
|
2014-09-22 08:30:07 +00:00
|
|
|
test_state_ = kNormalPhase;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kNormalPhase: {
|
2016-03-08 02:37:57 -08:00
|
|
|
if (output_type == AudioFrame::kPLC) {
|
2014-09-22 08:30:07 +00:00
|
|
|
test_state_ = kExpandPhase;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kExpandPhase: {
|
2016-03-08 02:37:57 -08:00
|
|
|
if (output_type == AudioFrame::kPLCCNG) {
|
2014-09-22 08:30:07 +00:00
|
|
|
test_state_ = kFadedExpandPhase;
|
2016-03-08 02:37:57 -08:00
|
|
|
} else if (output_type == AudioFrame::kNormalSpeech) {
|
2014-11-04 14:03:58 +00:00
|
|
|
test_state_ = kRecovered;
|
2014-09-22 08:30:07 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kFadedExpandPhase: {
|
2016-03-08 02:37:57 -08:00
|
|
|
if (output_type == AudioFrame::kNormalSpeech) {
|
2014-09-22 08:30:07 +00:00
|
|
|
test_state_ = kRecovered;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kRecovered: {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
void GetAndVerifyOutput() override {
|
2016-03-04 10:34:21 -08:00
|
|
|
AudioFrame output;
|
2016-03-08 02:37:57 -08:00
|
|
|
GetOutputAudio(&output);
|
|
|
|
|
UpdateState(output.speech_type_);
|
2015-02-17 10:17:09 +00:00
|
|
|
|
2014-09-22 08:30:07 +00:00
|
|
|
if (test_state_ == kExpandPhase || test_state_ == kFadedExpandPhase) {
|
|
|
|
|
// Don't verify the output in this phase of the test.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-17 10:17:09 +00:00
|
|
|
|
2016-03-04 10:34:21 -08:00
|
|
|
ASSERT_EQ(1u, output.num_channels_);
|
2017-06-12 12:45:32 -07:00
|
|
|
const int16_t* output_data = output.data();
|
2016-03-04 10:34:21 -08:00
|
|
|
for (size_t i = 0; i < output.samples_per_channel_; ++i) {
|
2017-06-12 12:45:32 -07:00
|
|
|
if (output_data[i] != 0)
|
2014-09-22 08:30:07 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
EXPECT_TRUE(false)
|
|
|
|
|
<< "Expected at least one non-zero sample in each output block.";
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
int NumExpectedDecodeCalls(int num_loops) override {
|
2014-11-04 14:03:58 +00:00
|
|
|
// Some packets at the end of the stream won't be decoded. When the jump in
|
|
|
|
|
// timestamp happens, NetEq will do Expand during one GetAudio call. In the
|
|
|
|
|
// next call it will decode the packet after the jump, but the net result is
|
|
|
|
|
// that the delay increased by 1 packet. In another call, a Pre-emptive
|
|
|
|
|
// Expand operation is performed, leading to delay increase by 1 packet. In
|
|
|
|
|
// total, the test will end with a 2-packet delay, which results in the 2
|
|
|
|
|
// last packets not being decoded.
|
|
|
|
|
return num_loops - 2;
|
2014-09-22 08:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestStates test_state_;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-16 10:04:20 +02:00
|
|
|
TEST_F(LargeTimestampJumpTest, JumpLongerThanHalfRange) {
|
2014-09-22 08:30:07 +00:00
|
|
|
// Set the timestamp series to start at 2880, increase to 7200, then jump to
|
|
|
|
|
// 2869342376. The sequence numbers start at 42076 and increase by 1 for each
|
|
|
|
|
// packet, also when the timestamp jumps.
|
|
|
|
|
static const uint16_t kStartSeqeunceNumber = 42076;
|
|
|
|
|
static const uint32_t kStartTimestamp = 2880;
|
|
|
|
|
static const uint32_t kJumpFromTimestamp = 7200;
|
|
|
|
|
static const uint32_t kJumpToTimestamp = 2869342376;
|
2015-01-14 10:51:54 +00:00
|
|
|
static_assert(kJumpFromTimestamp < kJumpToTimestamp,
|
|
|
|
|
"timestamp jump should not result in wrap");
|
|
|
|
|
static_assert(
|
2014-09-22 08:30:07 +00:00
|
|
|
static_cast<uint32_t>(kJumpToTimestamp - kJumpFromTimestamp) > 0x7FFFFFFF,
|
2015-01-14 10:51:54 +00:00
|
|
|
"jump should be larger than half range");
|
2014-09-22 08:30:07 +00:00
|
|
|
// Replace the default RTP generator with one that jumps in timestamp.
|
2015-02-17 10:17:09 +00:00
|
|
|
ResetRtpGenerator(new test::TimestampJumpRtpGenerator(
|
|
|
|
|
samples_per_ms(), kStartSeqeunceNumber, kStartTimestamp,
|
|
|
|
|
kJumpFromTimestamp, kJumpToTimestamp));
|
2014-09-22 08:30:07 +00:00
|
|
|
|
|
|
|
|
RunTest(130); // Run 130 laps @ 10 ms each in the test loop.
|
|
|
|
|
EXPECT_EQ(kRecovered, test_state_);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 10:04:20 +02:00
|
|
|
TEST_F(LargeTimestampJumpTest, JumpLongerThanHalfRangeAndWrap) {
|
2014-09-22 08:30:07 +00:00
|
|
|
// Make a jump larger than half the 32-bit timestamp range. Set the start
|
|
|
|
|
// timestamp such that the jump will result in a wrap around.
|
|
|
|
|
static const uint16_t kStartSeqeunceNumber = 42076;
|
|
|
|
|
// Set the jump length slightly larger than 2^31.
|
|
|
|
|
static const uint32_t kStartTimestamp = 3221223116;
|
|
|
|
|
static const uint32_t kJumpFromTimestamp = 3221223216;
|
|
|
|
|
static const uint32_t kJumpToTimestamp = 1073744278;
|
2015-01-14 10:51:54 +00:00
|
|
|
static_assert(kJumpToTimestamp < kJumpFromTimestamp,
|
|
|
|
|
"timestamp jump should result in wrap");
|
|
|
|
|
static_assert(
|
2014-09-22 08:30:07 +00:00
|
|
|
static_cast<uint32_t>(kJumpToTimestamp - kJumpFromTimestamp) > 0x7FFFFFFF,
|
2015-01-14 10:51:54 +00:00
|
|
|
"jump should be larger than half range");
|
2014-09-22 08:30:07 +00:00
|
|
|
// Replace the default RTP generator with one that jumps in timestamp.
|
2015-02-17 10:17:09 +00:00
|
|
|
ResetRtpGenerator(new test::TimestampJumpRtpGenerator(
|
|
|
|
|
samples_per_ms(), kStartSeqeunceNumber, kStartTimestamp,
|
|
|
|
|
kJumpFromTimestamp, kJumpToTimestamp));
|
2014-09-22 08:30:07 +00:00
|
|
|
|
|
|
|
|
RunTest(130); // Run 130 laps @ 10 ms each in the test loop.
|
|
|
|
|
EXPECT_EQ(kRecovered, test_state_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ShortTimestampJumpTest : public LargeTimestampJumpTest {
|
|
|
|
|
protected:
|
2016-03-08 02:37:57 -08:00
|
|
|
void UpdateState(AudioFrame::SpeechType output_type) override {
|
2014-09-22 08:30:07 +00:00
|
|
|
switch (test_state_) {
|
|
|
|
|
case kInitialPhase: {
|
2016-03-08 02:37:57 -08:00
|
|
|
if (output_type == AudioFrame::kNormalSpeech) {
|
2014-09-22 08:30:07 +00:00
|
|
|
test_state_ = kNormalPhase;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kNormalPhase: {
|
2016-03-08 02:37:57 -08:00
|
|
|
if (output_type == AudioFrame::kPLC) {
|
2014-09-22 08:30:07 +00:00
|
|
|
test_state_ = kExpandPhase;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kExpandPhase: {
|
2016-03-08 02:37:57 -08:00
|
|
|
if (output_type == AudioFrame::kNormalSpeech) {
|
2014-09-22 08:30:07 +00:00
|
|
|
test_state_ = kRecovered;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kRecovered: {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: { FAIL(); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
int NumExpectedDecodeCalls(int num_loops) override {
|
2014-09-22 08:30:07 +00:00
|
|
|
// Some packets won't be decoded because of the timestamp jump.
|
|
|
|
|
return num_loops - 2;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-16 10:04:20 +02:00
|
|
|
TEST_F(ShortTimestampJumpTest, JumpShorterThanHalfRange) {
|
2014-09-22 08:30:07 +00:00
|
|
|
// Make a jump shorter than half the 32-bit timestamp range. Set the start
|
|
|
|
|
// timestamp such that the jump will not result in a wrap around.
|
|
|
|
|
static const uint16_t kStartSeqeunceNumber = 42076;
|
|
|
|
|
// Set the jump length slightly smaller than 2^31.
|
|
|
|
|
static const uint32_t kStartTimestamp = 4711;
|
|
|
|
|
static const uint32_t kJumpFromTimestamp = 4811;
|
|
|
|
|
static const uint32_t kJumpToTimestamp = 2147483747;
|
2015-01-14 10:51:54 +00:00
|
|
|
static_assert(kJumpFromTimestamp < kJumpToTimestamp,
|
|
|
|
|
"timestamp jump should not result in wrap");
|
|
|
|
|
static_assert(
|
2014-09-22 08:30:07 +00:00
|
|
|
static_cast<uint32_t>(kJumpToTimestamp - kJumpFromTimestamp) < 0x7FFFFFFF,
|
2015-01-14 10:51:54 +00:00
|
|
|
"jump should be smaller than half range");
|
2014-09-22 08:30:07 +00:00
|
|
|
// Replace the default RTP generator with one that jumps in timestamp.
|
2015-02-17 10:17:09 +00:00
|
|
|
ResetRtpGenerator(new test::TimestampJumpRtpGenerator(
|
|
|
|
|
samples_per_ms(), kStartSeqeunceNumber, kStartTimestamp,
|
|
|
|
|
kJumpFromTimestamp, kJumpToTimestamp));
|
2014-09-22 08:30:07 +00:00
|
|
|
|
|
|
|
|
RunTest(130); // Run 130 laps @ 10 ms each in the test loop.
|
|
|
|
|
EXPECT_EQ(kRecovered, test_state_);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 10:04:20 +02:00
|
|
|
TEST_F(ShortTimestampJumpTest, JumpShorterThanHalfRangeAndWrap) {
|
2014-09-22 08:30:07 +00:00
|
|
|
// Make a jump shorter than half the 32-bit timestamp range. Set the start
|
|
|
|
|
// timestamp such that the jump will result in a wrap around.
|
|
|
|
|
static const uint16_t kStartSeqeunceNumber = 42076;
|
|
|
|
|
// Set the jump length slightly smaller than 2^31.
|
|
|
|
|
static const uint32_t kStartTimestamp = 3221227827;
|
|
|
|
|
static const uint32_t kJumpFromTimestamp = 3221227927;
|
|
|
|
|
static const uint32_t kJumpToTimestamp = 1073739567;
|
2015-01-14 10:51:54 +00:00
|
|
|
static_assert(kJumpToTimestamp < kJumpFromTimestamp,
|
|
|
|
|
"timestamp jump should result in wrap");
|
|
|
|
|
static_assert(
|
2014-09-22 08:30:07 +00:00
|
|
|
static_cast<uint32_t>(kJumpToTimestamp - kJumpFromTimestamp) < 0x7FFFFFFF,
|
2015-01-14 10:51:54 +00:00
|
|
|
"jump should be smaller than half range");
|
2014-09-22 08:30:07 +00:00
|
|
|
// Replace the default RTP generator with one that jumps in timestamp.
|
2015-02-17 10:17:09 +00:00
|
|
|
ResetRtpGenerator(new test::TimestampJumpRtpGenerator(
|
|
|
|
|
samples_per_ms(), kStartSeqeunceNumber, kStartTimestamp,
|
|
|
|
|
kJumpFromTimestamp, kJumpToTimestamp));
|
2014-09-22 08:30:07 +00:00
|
|
|
|
|
|
|
|
RunTest(130); // Run 130 laps @ 10 ms each in the test loop.
|
|
|
|
|
EXPECT_EQ(kRecovered, test_state_);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
} // namespace webrtc
|