Relanding "Setting up an RTP input fuzzer for NetEq"

The original CL (https://codereview.webrtc.org/2315633002) was
reverted since the fuzzer depended on gflags and files in the
resources folder; neither of this is allowed for a fuzzer test in
Chromium. This new version streamlines the dependencies, and changes
the test to generate a sinusoid input audio signal instead of reading
from a file.

Original commit message:
This CL introduces a new fuzzer target neteq_rtp_fuzzer that
manipulates the RTP header fields before inserting the packets into
NetEq. A few helper classes are also introduced.

BUG=webrtc:5447
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.win:win_chromium_rel_ng;master.tryserver.chromium.android:android_compile_dbg,linux_android_rel_ng;master.tryserver.chromium.linux:linux_chromium_rel_ng;master.tryserver.chromium.mac:mac_chromium_rel_ng,ios-device

Review-Url: https://codereview.webrtc.org/2384423002
Cr-Commit-Position: refs/heads/master@{#14523}
This commit is contained in:
henrik.lundin
2016-10-05 02:27:42 -07:00
committed by Commit bot
parent d020f3fea0
commit 58466f6d97
6 changed files with 359 additions and 3 deletions

View File

@ -868,6 +868,25 @@ rtc_static_library("neteq") {
}
}
# Although providing only test support, this target must be outside of the
# rtc_include_tests conditional. The reason is that it supports fuzzer tests
# that ultimately are built and run as a part of the Chromium ecosystem, which
# does not set the rtc_include_tests flag.
rtc_source_set("neteq_test_minimal") {
testonly = true
sources = [
"neteq/tools/encode_neteq_input.cc",
"neteq/tools/encode_neteq_input.h",
"neteq/tools/neteq_test.cc",
"neteq/tools/neteq_test.h",
]
if (is_clang) {
# Suppress warnings from the Chromium Clang plugins (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}
if (rtc_include_tests) {
rtc_source_set("acm_receive_test") {
testonly = true
@ -1156,8 +1175,6 @@ if (rtc_include_tests) {
"neteq/tools/neteq_packet_source_input.h",
"neteq/tools/neteq_replacement_input.cc",
"neteq/tools/neteq_replacement_input.h",
"neteq/tools/neteq_test.cc",
"neteq/tools/neteq_test.h",
"neteq/tools/output_audio_file.h",
"neteq/tools/output_wav_file.h",
"neteq/tools/packet.cc",
@ -1180,6 +1197,7 @@ if (rtc_include_tests) {
}
deps = [
":neteq_test_minimal",
"../../common_audio",
"../../test:rtp_test_utils",
"../rtp_rtcp",

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2016 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.
*/
#include "webrtc/modules/audio_coding/neteq/tools/encode_neteq_input.h"
#include <utility>
#include "webrtc/base/checks.h"
#include "webrtc/base/safe_conversions.h"
namespace webrtc {
namespace test {
EncodeNetEqInput::EncodeNetEqInput(std::unique_ptr<Generator> generator,
std::unique_ptr<AudioEncoder> encoder,
int64_t input_duration_ms)
: generator_(std::move(generator)),
encoder_(std::move(encoder)),
input_duration_ms_(input_duration_ms) {
CreatePacket();
}
rtc::Optional<int64_t> EncodeNetEqInput::NextPacketTime() const {
RTC_DCHECK(packet_data_);
return rtc::Optional<int64_t>(static_cast<int64_t>(packet_data_->time_ms));
}
rtc::Optional<int64_t> EncodeNetEqInput::NextOutputEventTime() const {
return rtc::Optional<int64_t>(next_output_event_ms_);
}
std::unique_ptr<NetEqInput::PacketData> EncodeNetEqInput::PopPacket() {
RTC_DCHECK(packet_data_);
// Grab the packet to return...
std::unique_ptr<PacketData> packet_to_return = std::move(packet_data_);
// ... and line up the next packet for future use.
CreatePacket();
return packet_to_return;
}
void EncodeNetEqInput::AdvanceOutputEvent() {
next_output_event_ms_ += kOutputPeriodMs;
}
rtc::Optional<RTPHeader> EncodeNetEqInput::NextHeader() const {
RTC_DCHECK(packet_data_);
return rtc::Optional<RTPHeader>(packet_data_->header.header);
}
void EncodeNetEqInput::CreatePacket() {
// Create a new PacketData object.
RTC_DCHECK(!packet_data_);
packet_data_.reset(new NetEqInput::PacketData);
RTC_DCHECK_EQ(packet_data_->payload.size(), 0u);
// Loop until we get a packet.
AudioEncoder::EncodedInfo info;
RTC_DCHECK(!info.send_even_if_empty);
int num_blocks = 0;
while (packet_data_->payload.size() == 0 && !info.send_even_if_empty) {
const size_t num_samples = rtc::CheckedDivExact(
static_cast<int>(encoder_->SampleRateHz() * kOutputPeriodMs), 1000);
info = encoder_->Encode(rtp_timestamp_, generator_->Generate(num_samples),
&packet_data_->payload);
rtp_timestamp_ += rtc::checked_cast<uint32_t>(
num_samples * encoder_->RtpTimestampRateHz() /
encoder_->SampleRateHz());
++num_blocks;
}
packet_data_->header.header.timestamp = info.encoded_timestamp;
packet_data_->header.header.payloadType = info.payload_type;
packet_data_->header.header.sequenceNumber = sequence_number_++;
packet_data_->time_ms = next_packet_time_ms_;
next_packet_time_ms_ += num_blocks * kOutputPeriodMs;
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 2016 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 WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_ENCODE_NETEQ_INPUT_H_
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_ENCODE_NETEQ_INPUT_H_
#include <memory>
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
#include "webrtc/modules/audio_coding/neteq/tools/neteq_input.h"
#include "webrtc/modules/include/module_common_types.h"
namespace webrtc {
namespace test {
// This class provides a NetEqInput that takes audio from a generator object and
// encodes it using a given audio encoder.
class EncodeNetEqInput : public NetEqInput {
public:
// Generator class, to be provided to the EncodeNetEqInput constructor.
class Generator {
public:
virtual ~Generator() = default;
// Returns the next num_samples values from the signal generator.
virtual rtc::ArrayView<const int16_t> Generate(size_t num_samples) = 0;
};
// The source will end after the given input duration.
EncodeNetEqInput(std::unique_ptr<Generator> generator,
std::unique_ptr<AudioEncoder> encoder,
int64_t input_duration_ms);
rtc::Optional<int64_t> NextPacketTime() const override;
rtc::Optional<int64_t> NextOutputEventTime() const override;
std::unique_ptr<PacketData> PopPacket() override;
void AdvanceOutputEvent() override;
bool ended() const override {
return next_output_event_ms_ <= input_duration_ms_;
}
rtc::Optional<RTPHeader> NextHeader() const override;
private:
static constexpr int64_t kOutputPeriodMs = 10;
void CreatePacket();
std::unique_ptr<Generator> generator_;
std::unique_ptr<AudioEncoder> encoder_;
std::unique_ptr<PacketData> packet_data_;
uint32_t rtp_timestamp_ = 0;
int16_t sequence_number_ = 0;
int64_t next_packet_time_ms_ = 0;
int64_t next_output_event_ms_ = 0;
const int64_t input_duration_ms_;
};
} // namespace test
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_ENCODE_NETEQ_INPUT_H_

View File

@ -65,7 +65,9 @@ class NetEqInput {
// time).
virtual void AdvanceOutputEvent() = 0;
// Returns true if the source has come to an end.
// Returns true if the source has come to an end. An implementation must
// eventually return true from this method, or the test will end up in an
// infinite loop.
virtual bool ended() const = 0;
// Returns the RTP header for the next packet, i.e., the packet that will be