2013-05-22 20:39:43 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-14 20:40:57 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2018-04-12 22:44:09 +02:00
|
|
|
#include "api/audio/audio_frame.h"
|
2018-04-06 10:06:42 +02:00
|
|
|
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
2024-08-05 12:40:46 +02:00
|
|
|
#include "api/environment/environment_factory.h"
|
2019-09-23 10:31:16 +02:00
|
|
|
#include "api/rtp_headers.h"
|
2024-05-27 11:22:27 +02:00
|
|
|
#include "api/units/timestamp.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
|
|
|
|
#include "modules/audio_coding/include/audio_coding_module.h"
|
2024-09-13 13:46:56 +00:00
|
|
|
#include "modules/audio_coding/neteq/default_neteq_factory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gtest.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "test/testsupport/file_utils.h"
|
2013-05-22 20:39:43 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2014-04-17 08:29:10 +00:00
|
|
|
class TargetDelayTest : public ::testing::Test {
|
|
|
|
|
protected:
|
2018-04-06 10:06:42 +02:00
|
|
|
TargetDelayTest()
|
2024-09-13 13:46:56 +00:00
|
|
|
: neteq_(
|
|
|
|
|
DefaultNetEqFactory().Create(CreateEnvironment(),
|
|
|
|
|
NetEq::Config(),
|
|
|
|
|
CreateBuiltinAudioDecoderFactory())) {}
|
2013-10-02 21:44:33 +00:00
|
|
|
|
|
|
|
|
~TargetDelayTest() {}
|
2013-05-22 20:39:43 +00:00
|
|
|
|
|
|
|
|
void SetUp() {
|
2016-10-24 13:47:09 -07:00
|
|
|
constexpr int pltype = 108;
|
2018-12-05 10:30:25 +01:00
|
|
|
std::map<int, SdpAudioFormat> receive_codecs = {
|
|
|
|
|
{pltype, {"L16", kSampleRateHz, 1}}};
|
2024-09-13 13:46:56 +00:00
|
|
|
neteq_->SetCodecs(receive_codecs);
|
2013-05-22 20:39:43 +00:00
|
|
|
|
2019-02-15 15:21:47 +01:00
|
|
|
rtp_header_.payloadType = pltype;
|
|
|
|
|
rtp_header_.timestamp = 0;
|
|
|
|
|
rtp_header_.ssrc = 0x12345678;
|
|
|
|
|
rtp_header_.markerBit = false;
|
|
|
|
|
rtp_header_.sequenceNumber = 0;
|
2013-10-02 21:44:33 +00:00
|
|
|
|
|
|
|
|
int16_t audio[kFrameSizeSamples];
|
|
|
|
|
const int kRange = 0x7FF; // 2047, easy for masking.
|
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
|
|
|
for (size_t n = 0; n < kFrameSizeSamples; ++n)
|
2013-10-02 21:44:33 +00:00
|
|
|
audio[n] = (rand() & kRange) - kRange / 2;
|
|
|
|
|
WebRtcPcm16b_Encode(audio, kFrameSizeSamples, payload_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutOfRangeInput() {
|
2024-09-13 13:46:56 +00:00
|
|
|
EXPECT_FALSE(SetMinimumDelay(-1));
|
|
|
|
|
EXPECT_FALSE(SetMinimumDelay(10001));
|
2013-10-02 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TargetDelayBufferMinMax() {
|
|
|
|
|
const int kTargetMinDelayMs = kNum10msPerFrame * 10;
|
2024-09-13 13:46:56 +00:00
|
|
|
ASSERT_TRUE(SetMinimumDelay(kTargetMinDelayMs));
|
2013-10-02 21:44:33 +00:00
|
|
|
for (int m = 0; m < 30; ++m) // Run enough iterations to fill the buffer.
|
|
|
|
|
Run(true);
|
|
|
|
|
int clean_optimal_delay = GetCurrentOptimalDelayMs();
|
|
|
|
|
EXPECT_EQ(kTargetMinDelayMs, clean_optimal_delay);
|
|
|
|
|
|
|
|
|
|
const int kTargetMaxDelayMs = 2 * (kNum10msPerFrame * 10);
|
2024-09-13 13:46:56 +00:00
|
|
|
ASSERT_TRUE(SetMaximumDelay(kTargetMaxDelayMs));
|
2013-10-02 21:44:33 +00:00
|
|
|
for (int n = 0; n < 30; ++n) // Run enough iterations to fill the buffer.
|
|
|
|
|
Run(false);
|
|
|
|
|
|
|
|
|
|
int capped_optimal_delay = GetCurrentOptimalDelayMs();
|
|
|
|
|
EXPECT_EQ(kTargetMaxDelayMs, capped_optimal_delay);
|
2013-05-22 20:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-02 21:44:33 +00:00
|
|
|
private:
|
|
|
|
|
static const int kSampleRateHz = 16000;
|
|
|
|
|
static const int kNum10msPerFrame = 2;
|
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
|
|
|
static const size_t kFrameSizeSamples = 320; // 20 ms @ 16 kHz.
|
2013-10-02 21:44:33 +00:00
|
|
|
// payload-len = frame-samples * 2 bytes/sample.
|
|
|
|
|
static const int kPayloadLenBytes = 320 * 2;
|
|
|
|
|
// Inter-arrival time in number of packets in a jittery channel. One is no
|
|
|
|
|
// jitter.
|
|
|
|
|
static const int kInterarrivalJitterPacket = 2;
|
|
|
|
|
|
2013-05-22 20:39:43 +00:00
|
|
|
void Push() {
|
2019-02-15 15:21:47 +01:00
|
|
|
rtp_header_.timestamp += kFrameSizeSamples;
|
|
|
|
|
rtp_header_.sequenceNumber++;
|
2024-09-13 13:46:56 +00:00
|
|
|
ASSERT_EQ(0, neteq_->InsertPacket(rtp_header_,
|
|
|
|
|
rtc::ArrayView<const uint8_t>(
|
|
|
|
|
payload_, kFrameSizeSamples * 2),
|
|
|
|
|
Timestamp::MinusInfinity()));
|
2013-05-22 20:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pull audio equivalent to the amount of audio in one RTP packet.
|
|
|
|
|
void Pull() {
|
|
|
|
|
AudioFrame frame;
|
2016-05-17 12:21:55 -07:00
|
|
|
bool muted;
|
2013-05-22 20:39:43 +00:00
|
|
|
for (int k = 0; k < kNum10msPerFrame; ++k) { // Pull one frame.
|
2024-09-13 13:46:56 +00:00
|
|
|
ASSERT_EQ(NetEq::kOK, neteq_->GetAudio(&frame, &muted));
|
2016-05-17 12:21:55 -07:00
|
|
|
ASSERT_FALSE(muted);
|
2013-05-22 20:39:43 +00:00
|
|
|
// Had to use ASSERT_TRUE, ASSERT_EQ generated error.
|
|
|
|
|
ASSERT_TRUE(kSampleRateHz == frame.sample_rate_hz_);
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
ASSERT_EQ(1u, frame.num_channels_);
|
2013-05-22 20:39:43 +00:00
|
|
|
ASSERT_TRUE(kSampleRateHz / 100 == frame.samples_per_channel_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Run(bool clean) {
|
|
|
|
|
for (int n = 0; n < 10; ++n) {
|
|
|
|
|
for (int m = 0; m < 5; ++m) {
|
|
|
|
|
Push();
|
|
|
|
|
Pull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!clean) {
|
|
|
|
|
for (int m = 0; m < 10; ++m) { // Long enough to trigger delay change.
|
|
|
|
|
Push();
|
|
|
|
|
for (int n = 0; n < kInterarrivalJitterPacket; ++n)
|
|
|
|
|
Pull();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SetMinimumDelay(int delay_ms) {
|
2024-09-13 13:46:56 +00:00
|
|
|
return neteq_->SetMinimumDelay(delay_ms);
|
2013-05-22 20:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-06 21:01:36 +00:00
|
|
|
int SetMaximumDelay(int delay_ms) {
|
2024-09-13 13:46:56 +00:00
|
|
|
return neteq_->SetMaximumDelay(delay_ms);
|
2013-08-06 21:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-22 20:39:43 +00:00
|
|
|
int GetCurrentOptimalDelayMs() {
|
2024-09-13 13:46:56 +00:00
|
|
|
NetEqNetworkStatistics neteq_stats;
|
|
|
|
|
neteq_->NetworkStatistics(&neteq_stats);
|
|
|
|
|
return neteq_stats.preferred_buffer_size_ms;
|
2013-05-22 20:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-13 13:46:56 +00:00
|
|
|
std::unique_ptr<NetEq> neteq_;
|
2019-02-15 15:21:47 +01:00
|
|
|
RTPHeader rtp_header_;
|
2013-10-02 21:44:33 +00:00
|
|
|
uint8_t payload_[kPayloadLenBytes];
|
2013-05-22 20:39:43 +00:00
|
|
|
};
|
|
|
|
|
|
2017-02-26 22:10:14 -08:00
|
|
|
// Flaky on iOS: webrtc:7057.
|
|
|
|
|
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
|
2016-01-04 22:44:05 +01:00
|
|
|
#define MAYBE_OutOfRangeInput DISABLED_OutOfRangeInput
|
|
|
|
|
#else
|
|
|
|
|
#define MAYBE_OutOfRangeInput OutOfRangeInput
|
|
|
|
|
#endif
|
|
|
|
|
TEST_F(TargetDelayTest, MAYBE_OutOfRangeInput) {
|
2014-04-17 08:29:10 +00:00
|
|
|
OutOfRangeInput();
|
2013-10-02 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-26 22:10:14 -08:00
|
|
|
// Flaky on iOS: webrtc:7057.
|
|
|
|
|
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
|
2016-01-04 22:44:05 +01:00
|
|
|
#define MAYBE_TargetDelayBufferMinMax DISABLED_TargetDelayBufferMinMax
|
|
|
|
|
#else
|
|
|
|
|
#define MAYBE_TargetDelayBufferMinMax TargetDelayBufferMinMax
|
|
|
|
|
#endif
|
|
|
|
|
TEST_F(TargetDelayTest, MAYBE_TargetDelayBufferMinMax) {
|
2014-04-17 08:29:10 +00:00
|
|
|
TargetDelayBufferMinMax();
|
2013-08-06 21:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-02 21:44:33 +00:00
|
|
|
} // namespace webrtc
|