2011-09-09 08:01:16 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file includes unit tests for NetEQ.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h> // memset
|
|
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
#include <string>
|
2011-09-09 08:01:16 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
2011-11-07 16:05:19 +00:00
|
|
|
#include "modules/audio_coding/neteq/test/NETEQTEST_CodecClass.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/test/NETEQTEST_NetEQClass.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
|
2011-09-09 08:01:16 +00:00
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2011-11-07 16:05:19 +00:00
|
|
|
#include "modules/audio_coding/neteq/interface/webrtc_neteq.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
|
2011-11-25 13:43:42 +00:00
|
|
|
#include "testsupport/fileutils.h"
|
2011-09-09 08:01:16 +00:00
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
namespace webrtc {
|
2011-09-09 08:01:16 +00:00
|
|
|
|
|
|
|
|
class NetEqDecodingTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
NetEqDecodingTest();
|
|
|
|
|
virtual void SetUp();
|
|
|
|
|
virtual void TearDown();
|
|
|
|
|
void SelectDecoders(WebRtcNetEQDecoder* used_codec);
|
|
|
|
|
void LoadDecoders();
|
2011-11-25 13:43:42 +00:00
|
|
|
void DecodeAndCompare(const std::string &rtp_file,
|
|
|
|
|
const std::string &ref_file);
|
2011-09-09 08:01:16 +00:00
|
|
|
|
|
|
|
|
NETEQTEST_NetEQClass* neteq_inst_;
|
|
|
|
|
std::vector<NETEQTEST_Decoder*> dec_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NetEqDecodingTest::NetEqDecodingTest() : neteq_inst_(NULL) {}
|
|
|
|
|
|
|
|
|
|
void NetEqDecodingTest::SetUp() {
|
|
|
|
|
WebRtcNetEQDecoder usedCodec[kDecoderReservedEnd - 1];
|
|
|
|
|
|
|
|
|
|
SelectDecoders(usedCodec);
|
|
|
|
|
neteq_inst_ = new NETEQTEST_NetEQClass(usedCodec, dec_.size(), 8000,
|
|
|
|
|
kTCPLargeJitter);
|
|
|
|
|
ASSERT_TRUE(neteq_inst_);
|
|
|
|
|
LoadDecoders();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetEqDecodingTest::TearDown() {
|
|
|
|
|
if (neteq_inst_)
|
|
|
|
|
delete neteq_inst_;
|
|
|
|
|
for (size_t i = 0; i < dec_.size(); ++i) {
|
|
|
|
|
if (dec_[i])
|
|
|
|
|
delete dec_[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetEqDecodingTest::SelectDecoders(WebRtcNetEQDecoder* used_codec) {
|
|
|
|
|
*used_codec++ = kDecoderPCMu;
|
|
|
|
|
dec_.push_back(new decoder_PCMU(0));
|
|
|
|
|
*used_codec++ = kDecoderPCMa;
|
|
|
|
|
dec_.push_back(new decoder_PCMA(8));
|
|
|
|
|
*used_codec++ = kDecoderILBC;
|
|
|
|
|
dec_.push_back(new decoder_ILBC(102));
|
|
|
|
|
*used_codec++ = kDecoderISAC;
|
|
|
|
|
dec_.push_back(new decoder_iSAC(103));
|
|
|
|
|
*used_codec++ = kDecoderISACswb;
|
|
|
|
|
dec_.push_back(new decoder_iSACSWB(104));
|
|
|
|
|
*used_codec++ = kDecoderPCM16B;
|
|
|
|
|
dec_.push_back(new decoder_PCM16B_NB(93));
|
|
|
|
|
*used_codec++ = kDecoderPCM16Bwb;
|
|
|
|
|
dec_.push_back(new decoder_PCM16B_WB(94));
|
|
|
|
|
*used_codec++ = kDecoderPCM16Bswb32kHz;
|
|
|
|
|
dec_.push_back(new decoder_PCM16B_SWB32(95));
|
|
|
|
|
*used_codec++ = kDecoderCNG;
|
|
|
|
|
dec_.push_back(new decoder_CNG(13));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetEqDecodingTest::LoadDecoders() {
|
|
|
|
|
for (size_t i = 0; i < dec_.size(); ++i) {
|
|
|
|
|
ASSERT_EQ(0, dec_[i]->loadToNetEQ(*neteq_inst_));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
void NetEqDecodingTest::DecodeAndCompare(const std::string &rtp_file,
|
|
|
|
|
const std::string &ref_file) {
|
2011-09-09 08:01:16 +00:00
|
|
|
NETEQTEST_RTPpacket rtp;
|
2011-11-25 13:43:42 +00:00
|
|
|
FILE* rtp_fp = fopen(rtp_file.c_str(), "rb");
|
2011-09-09 08:01:16 +00:00
|
|
|
ASSERT_TRUE(rtp_fp != NULL);
|
|
|
|
|
ASSERT_EQ(0, NETEQTEST_RTPpacket::skipFileHeader(rtp_fp));
|
|
|
|
|
ASSERT_GT(rtp.readFromFile(rtp_fp), 0);
|
|
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
FILE* ref_fp = NULL;
|
|
|
|
|
FILE* out_fp = NULL;
|
|
|
|
|
if (!ref_file.empty()) {
|
|
|
|
|
ref_fp = fopen(ref_file.c_str(), "rb");
|
|
|
|
|
ASSERT_TRUE(ref_fp != NULL);
|
|
|
|
|
} else {
|
|
|
|
|
std::string out_file = webrtc::test::OutputPath() + "neteq_out.pcm";
|
|
|
|
|
out_fp = fopen(out_file.c_str(), "wb");
|
|
|
|
|
ASSERT_TRUE(out_fp != NULL);
|
|
|
|
|
}
|
2011-09-09 08:01:16 +00:00
|
|
|
|
|
|
|
|
unsigned int sim_clock = 0;
|
2011-11-25 13:43:42 +00:00
|
|
|
// NetEQ must be polled for data once every 10 ms. Thus, neither of the
|
|
|
|
|
// constants below can be changed.
|
|
|
|
|
const int kTimeStepMs = 10;
|
|
|
|
|
const int kBlockSize8kHz = kTimeStepMs * 8;
|
|
|
|
|
const int kBlockSize16kHz = kTimeStepMs * 16;
|
|
|
|
|
const int kBlockSize32kHz = kTimeStepMs * 32;
|
|
|
|
|
const int kMaxBlockSize = kBlockSize32kHz;
|
2011-09-09 08:01:16 +00:00
|
|
|
while (rtp.dataLen() >= 0) {
|
|
|
|
|
// Check if time to receive.
|
|
|
|
|
while ((sim_clock >= rtp.time()) &&
|
|
|
|
|
(rtp.dataLen() >= 0)) {
|
|
|
|
|
if (rtp.dataLen() > 0) {
|
|
|
|
|
ASSERT_EQ(0, neteq_inst_->recIn(rtp));
|
|
|
|
|
}
|
|
|
|
|
// Get next packet.
|
|
|
|
|
ASSERT_NE(-1, rtp.readFromFile(rtp_fp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RecOut
|
2011-11-25 13:43:42 +00:00
|
|
|
WebRtc_Word16 out_data[kMaxBlockSize];
|
2011-09-09 08:01:16 +00:00
|
|
|
WebRtc_Word16 out_len = neteq_inst_->recOut(out_data);
|
2011-11-25 13:43:42 +00:00
|
|
|
ASSERT_TRUE((out_len == kBlockSize8kHz) ||
|
|
|
|
|
(out_len == kBlockSize16kHz) ||
|
|
|
|
|
(out_len == kBlockSize32kHz));
|
|
|
|
|
|
|
|
|
|
if (ref_fp) {
|
|
|
|
|
// Read from ref file.
|
|
|
|
|
WebRtc_Word16 ref_data[kMaxBlockSize];
|
|
|
|
|
if (static_cast<size_t>(out_len) !=
|
|
|
|
|
fread(ref_data, sizeof(WebRtc_Word16), out_len, ref_fp)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-09-09 08:01:16 +00:00
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
// Compare
|
|
|
|
|
EXPECT_EQ(0, memcmp(out_data, ref_data, sizeof(WebRtc_Word16) * out_len));
|
2011-09-09 08:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
if (out_fp) {
|
|
|
|
|
// Write to output file (mainly for generating new output vectors).
|
|
|
|
|
ASSERT_EQ(static_cast<size_t>(out_len),
|
|
|
|
|
fwrite(out_data, sizeof(WebRtc_Word16), out_len, out_fp));
|
|
|
|
|
}
|
2011-09-09 08:01:16 +00:00
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
// Increase time.
|
|
|
|
|
sim_clock += kTimeStepMs;
|
2011-09-09 08:01:16 +00:00
|
|
|
}
|
|
|
|
|
fclose(rtp_fp);
|
2011-11-25 13:43:42 +00:00
|
|
|
if (ref_fp) {
|
|
|
|
|
ASSERT_NE(0, feof(ref_fp)); // Make sure that we reached the end.
|
|
|
|
|
fclose(ref_fp);
|
|
|
|
|
}
|
|
|
|
|
if (out_fp) fclose(out_fp);
|
2011-09-09 08:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-25 13:43:42 +00:00
|
|
|
#if defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_64_BITS)
|
2011-09-09 08:01:16 +00:00
|
|
|
TEST_F(NetEqDecodingTest, TestBitExactness) {
|
2011-11-25 13:43:42 +00:00
|
|
|
const std::string kInputRtpFile = webrtc::test::ProjectRootPath() +
|
|
|
|
|
"test/data/audio_coding/universal.rtp";
|
|
|
|
|
const std::string kInputRefFile = webrtc::test::ProjectRootPath() +
|
|
|
|
|
"test/data/audio_coding/universal_ref.pcm";
|
|
|
|
|
DecodeAndCompare(kInputRtpFile, kInputRefFile);
|
2011-09-09 08:01:16 +00:00
|
|
|
}
|
2011-11-25 13:43:42 +00:00
|
|
|
#endif // defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_64_BITS)
|
2011-09-09 08:01:16 +00:00
|
|
|
|
|
|
|
|
} // namespace
|