Reformat the WebRTC code base

Running clang-format with chromium's style guide.

The goal is n-fold:
 * providing consistency and readability (that's what code guidelines are for)
 * preventing noise with presubmit checks and git cl format
 * building on the previous point: making it easier to automatically fix format issues
 * you name it

Please consider using git-hyper-blame to ignore this commit.

Bug: webrtc:9340
Change-Id: I694567c4cdf8cee2860958cfe82bfaf25848bb87
Reviewed-on: https://webrtc-review.googlesource.com/81185
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23660}
This commit is contained in:
Yves Gerey
2018-06-19 15:03:05 +02:00
parent b602123a5a
commit 665174fdbb
1569 changed files with 30495 additions and 30309 deletions

View File

@ -21,16 +21,18 @@ bool AudioLoop::Init(const std::string file_name,
size_t max_loop_length_samples,
size_t block_length_samples) {
FILE* fp = fopen(file_name.c_str(), "rb");
if (!fp) return false;
if (!fp)
return false;
audio_array_.reset(new int16_t[max_loop_length_samples +
block_length_samples]);
size_t samples_read = fread(audio_array_.get(), sizeof(int16_t),
max_loop_length_samples, fp);
audio_array_.reset(
new int16_t[max_loop_length_samples + block_length_samples]);
size_t samples_read =
fread(audio_array_.get(), sizeof(int16_t), max_loop_length_samples, fp);
fclose(fp);
// Block length must be shorter than the loop length.
if (block_length_samples > samples_read) return false;
if (block_length_samples > samples_read)
return false;
// Add an extra block length of samples to the end of the array, starting
// over again from the beginning of the array. This is done to simplify
@ -54,6 +56,5 @@ rtc::ArrayView<const int16_t> AudioLoop::GetNextBlock() {
return rtc::ArrayView<const int16_t>(output_ptr, block_length_samples_);
}
} // namespace test
} // namespace webrtc

View File

@ -26,10 +26,7 @@ namespace test {
class AudioLoop {
public:
AudioLoop()
: next_index_(0),
loop_length_samples_(0),
block_length_samples_(0) {
}
: next_index_(0), loop_length_samples_(0), block_length_samples_(0) {}
virtual ~AudioLoop() {}
@ -38,7 +35,8 @@ class AudioLoop {
// greater. Otherwise, the loop length is the same as the file length.
// The audio will be delivered in blocks of |block_length_samples|.
// Returns false if the initialization failed, otherwise true.
bool Init(const std::string file_name, size_t max_loop_length_samples,
bool Init(const std::string file_name,
size_t max_loop_length_samples,
size_t block_length_samples);
// Returns a (pointer,size) pair for the next block of audio. The size is

View File

@ -32,9 +32,8 @@ class AudioSink {
// Writes |audio_frame| to the AudioSink. Returns true if successful,
// otherwise false.
bool WriteAudioFrame(const AudioFrame& audio_frame) {
return WriteArray(
audio_frame.data(),
audio_frame.samples_per_channel_ * audio_frame.num_channels_);
return WriteArray(audio_frame.data(), audio_frame.samples_per_channel_ *
audio_frame.num_channels_);
}
private:

View File

@ -20,7 +20,9 @@ InputAudioFile::InputAudioFile(const std::string file_name, bool loop_at_end)
fp_ = fopen(file_name.c_str(), "rb");
}
InputAudioFile::~InputAudioFile() { fclose(fp_); }
InputAudioFile::~InputAudioFile() {
fclose(fp_);
}
bool InputAudioFile::Read(size_t samples, int16_t* destination) {
if (!fp_) {
@ -73,7 +75,8 @@ bool InputAudioFile::Seek(int samples) {
return true;
}
void InputAudioFile::DuplicateInterleaved(const int16_t* source, size_t samples,
void InputAudioFile::DuplicateInterleaved(const int16_t* source,
size_t samples,
size_t channels,
int16_t* destination) {
// Start from the end of |source| and |destination|, and work towards the

View File

@ -45,8 +45,10 @@ class InputAudioFile {
// channels are identical. The output |destination| must have the capacity to
// hold samples * channels elements. Note that |source| and |destination| can
// be the same array (i.e., point to the same address).
static void DuplicateInterleaved(const int16_t* source, size_t samples,
size_t channels, int16_t* destination);
static void DuplicateInterleaved(const int16_t* source,
size_t samples,
size_t channels,
int16_t* destination);
private:
FILE* fp_;

View File

@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_coding/neteq/tools/neteq_external_decoder_test.h"
#include "api/audio/audio_frame.h"
@ -32,9 +31,8 @@ NetEqExternalDecoderTest::NetEqExternalDecoderTest(NetEqDecoder codec,
}
void NetEqExternalDecoderTest::Init() {
ASSERT_EQ(NetEq::kOK,
neteq_->RegisterExternalDecoder(decoder_, codec_, name_,
kPayloadType));
ASSERT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder(decoder_, codec_, name_,
kPayloadType));
}
void NetEqExternalDecoderTest::InsertPacket(

View File

@ -31,7 +31,7 @@ class NetEqExternalDecoderTest {
int sample_rate_hz,
AudioDecoder* decoder);
virtual ~NetEqExternalDecoderTest() { }
virtual ~NetEqExternalDecoderTest() {}
// In Init(), we register the external decoder.
void Init();

View File

@ -95,9 +95,8 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
}
// Get next packet.
packet_input_time_ms = rtp_gen.GetRtpHeader(kPayloadType,
kInputBlockSizeSamples,
&rtp_header);
packet_input_time_ms = rtp_gen.GetRtpHeader(
kPayloadType, kInputBlockSizeSamples, &rtp_header);
input_samples = audio_loop.GetNextBlock();
if (input_samples.empty())
return -1;

View File

@ -47,7 +47,9 @@ static bool ValidateFilename(const std::string& value, bool write) {
return true;
}
DEFINE_string(in_filename, DefaultInFilename().c_str(),
DEFINE_string(
in_filename,
DefaultInFilename().c_str(),
"Filename for input audio (specify sample rate with --input_sample_rate, "
"and channels with --channels).");
@ -55,8 +57,9 @@ DEFINE_int(input_sample_rate, 16000, "Sample rate of input file in Hz.");
DEFINE_int(channels, 1, "Number of channels in input audio.");
DEFINE_string(out_filename, DefaultOutFilename().c_str(),
"Name of output audio file.");
DEFINE_string(out_filename,
DefaultOutFilename().c_str(),
"Name of output audio file.");
DEFINE_int(runtime_ms, 10000, "Simulated runtime (milliseconds).");
@ -67,8 +70,9 @@ DEFINE_int(random_loss_mode,
"Random loss mode: 0--no loss, 1--uniform loss, 2--Gilbert Elliot "
"loss, 3--fixed loss.");
DEFINE_int(burst_length, 30,
"Burst length in milliseconds, only valid for Gilbert Elliot loss.");
DEFINE_int(burst_length,
30,
"Burst length in milliseconds, only valid for Gilbert Elliot loss.");
DEFINE_float(drift_factor, 0.0, "Time drift factor.");
@ -85,21 +89,22 @@ DEFINE_string(loss_events,
// to achieve the target packet loss rate |loss_rate|, when a packet is not
// lost only if all |units| drawings within the duration of the packet result in
// no-loss.
static double ProbTrans00Solver(int units, double loss_rate,
static double ProbTrans00Solver(int units,
double loss_rate,
double prob_trans_10) {
if (units == 1)
return prob_trans_10 / (1.0f - loss_rate) - prob_trans_10;
// 0 == prob_trans_00 ^ (units - 1) + (1 - loss_rate) / prob_trans_10 *
// prob_trans_00 - (1 - loss_rate) * (1 + 1 / prob_trans_10).
// There is a unique solution between 0.0 and 1.0, due to the monotonicity and
// an opposite sign at 0.0 and 1.0.
// For simplicity, we reformulate the equation as
// f(x) = x ^ (units - 1) + a x + b.
// Its derivative is
// f'(x) = (units - 1) x ^ (units - 2) + a.
// The derivative is strictly greater than 0 when x is between 0 and 1.
// We use Newton's method to solve the equation, iteration is
// x(k+1) = x(k) - f(x) / f'(x);
// 0 == prob_trans_00 ^ (units - 1) + (1 - loss_rate) / prob_trans_10 *
// prob_trans_00 - (1 - loss_rate) * (1 + 1 / prob_trans_10).
// There is a unique solution between 0.0 and 1.0, due to the monotonicity and
// an opposite sign at 0.0 and 1.0.
// For simplicity, we reformulate the equation as
// f(x) = x ^ (units - 1) + a x + b.
// Its derivative is
// f'(x) = (units - 1) x ^ (units - 2) + a.
// The derivative is strictly greater than 0 when x is between 0 and 1.
// We use Newton's method to solve the equation, iteration is
// x(k+1) = x(k) - f(x) / f'(x);
const double kPrecision = 0.001f;
const int kIterations = 100;
const double a = (1.0f - loss_rate) / prob_trans_10;
@ -117,7 +122,7 @@ static double ProbTrans00Solver(int units, double loss_rate,
x = 0.0f;
}
f = pow(x, units - 1) + a * x + b;
iter ++;
iter++;
}
return x;
}
@ -210,9 +215,7 @@ bool NoLoss::Lost(int now_ms) {
return false;
}
UniformLoss::UniformLoss(double loss_rate)
: loss_rate_(loss_rate) {
}
UniformLoss::UniformLoss(double loss_rate) : loss_rate_(loss_rate) {}
bool UniformLoss::Lost(int now_ms) {
int drop_this = rand();
@ -223,8 +226,7 @@ GilbertElliotLoss::GilbertElliotLoss(double prob_trans_11, double prob_trans_01)
: prob_trans_11_(prob_trans_11),
prob_trans_01_(prob_trans_01),
lost_last_(false),
uniform_loss_model_(new UniformLoss(0)) {
}
uniform_loss_model_(new UniformLoss(0)) {}
GilbertElliotLoss::~GilbertElliotLoss() {}
@ -277,8 +279,8 @@ void NetEqQualityTest::SetUp() {
// a full packet duration is drawn with a loss, |unit_loss_rate| fulfills
// (1 - unit_loss_rate) ^ (block_duration_ms_ / kPacketLossTimeUnitMs) ==
// 1 - packet_loss_rate.
double unit_loss_rate = (1.0f - pow(1.0f - 0.01f * packet_loss_rate_,
1.0f / units));
double unit_loss_rate =
(1.0f - pow(1.0f - 0.01f * packet_loss_rate_, 1.0f / units));
loss_model_.reset(new UniformLoss(unit_loss_rate));
break;
}
@ -304,8 +306,8 @@ void NetEqQualityTest::SetUp() {
double loss_rate = 0.01f * packet_loss_rate_;
double prob_trans_10 = 1.0f * kPacketLossTimeUnitMs / FLAG_burst_length;
double prob_trans_00 = ProbTrans00Solver(units, loss_rate, prob_trans_10);
loss_model_.reset(new GilbertElliotLoss(1.0f - prob_trans_10,
1.0f - prob_trans_00));
loss_model_.reset(
new GilbertElliotLoss(1.0f - prob_trans_10, 1.0f - prob_trans_00));
break;
}
case kFixedLoss: {
@ -347,7 +349,7 @@ bool NetEqQualityTest::PacketLost() {
// The loop is to make sure that codecs with different block lengths share the
// same packet loss profile.
bool lost = false;
for (int idx = 0; idx < cycles; idx ++) {
for (int idx = 0; idx < cycles; idx++) {
if (loss_model_->Lost(decoded_time_ms_)) {
// The packet will be lost if any of the drawings indicates a loss, but
// the loop has to go on to make sure that codecs with different block
@ -359,14 +361,10 @@ bool NetEqQualityTest::PacketLost() {
}
int NetEqQualityTest::Transmit() {
int packet_input_time_ms =
rtp_generator_->GetRtpHeader(kPayloadType, in_size_samples_,
&rtp_header_);
Log() << "Packet of size "
<< payload_size_bytes_
<< " bytes, for frame at "
<< packet_input_time_ms
<< " ms ";
int packet_input_time_ms = rtp_generator_->GetRtpHeader(
kPayloadType, in_size_samples_, &rtp_header_);
Log() << "Packet of size " << payload_size_bytes_ << " bytes, for frame at "
<< packet_input_time_ms << " ms ";
if (payload_size_bytes_ > 0) {
if (!PacketLost()) {
int ret = neteq_->InsertPacket(
@ -411,9 +409,8 @@ void NetEqQualityTest::Simulate() {
decoded_time_ms_) {
ASSERT_TRUE(in_file_->Read(in_size_samples_ * channels_, &in_data_[0]));
payload_.Clear();
payload_size_bytes_ = EncodeBlock(&in_data_[0],
in_size_samples_, &payload_,
max_payload_bytes_);
payload_size_bytes_ = EncodeBlock(&in_data_[0], in_size_samples_,
&payload_, max_payload_bytes_);
total_payload_size_bytes_ += payload_size_bytes_;
decodable_time_ms_ = Transmit() + block_duration_ms_;
}
@ -423,8 +420,7 @@ void NetEqQualityTest::Simulate() {
}
}
Log() << "Average bit rate was "
<< 8.0f * total_payload_size_bytes_ / FLAG_runtime_ms
<< " kbps"
<< 8.0f * total_payload_size_bytes_ / FLAG_runtime_ms << " kbps"
<< std::endl;
}

View File

@ -36,7 +36,7 @@ enum LossModes {
class LossModel {
public:
virtual ~LossModel() {};
virtual ~LossModel(){};
virtual bool Lost(int now_ms) = 0;
};
@ -110,8 +110,10 @@ class NetEqQualityTest : public ::testing::Test {
// |block_size_samples| (samples per channel),
// 2. save the bit stream to |payload| of |max_bytes| bytes in size,
// 3. returns the length of the payload (in bytes),
virtual int EncodeBlock(int16_t* in_data, size_t block_size_samples,
rtc::Buffer* payload, size_t max_bytes) = 0;
virtual int EncodeBlock(int16_t* in_data,
size_t block_size_samples,
rtc::Buffer* payload,
size_t max_bytes) = 0;
// PacketLost(...) determines weather a packet sent at an indicated time gets
// lost or not.

View File

@ -42,7 +42,7 @@ class NetEqReplacementInput : public NetEqInput {
const uint8_t replacement_payload_type_;
const std::set<uint8_t> comfort_noise_types_;
const std::set<uint8_t> forbidden_types_;
std::unique_ptr<PacketData> packet_; // The next packet to deliver.
std::unique_ptr<PacketData> packet_; // The next packet to deliver.
uint32_t last_frame_size_timestamps_ = 960; // Initial guess: 20 ms @ 48 kHz.
};

View File

@ -10,20 +10,20 @@
#include <errno.h>
#include <inttypes.h>
#include <iostream>
#include <limits.h> // For ULONG_MAX returned by strtoul.
#include <memory>
#include <stdio.h>
#include <stdlib.h> // For strtoul.
#include <iostream>
#include <memory>
#include <string>
#include "modules/audio_coding/neteq/include/neteq.h"
#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
#include "modules/audio_coding/neteq/tools/neteq_stats_getter.h"
#include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h"
#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
#include "modules/audio_coding/neteq/tools/neteq_stats_getter.h"
#include "modules/audio_coding/neteq/tools/neteq_test.h"
#include "modules/audio_coding/neteq/tools/output_audio_file.h"
#include "modules/audio_coding/neteq/tools/output_wav_file.h"
@ -71,7 +71,7 @@ bool ValidatePayloadType(int value) {
bool ValidateSsrcValue(const std::string& str) {
uint32_t dummy_ssrc;
if (ParseSsrc(str, &dummy_ssrc)) // Value is ok.
if (ParseSsrc(str, &dummy_ssrc)) // Value is ok.
return true;
printf("Invalid SSRC: %s\n", str.c_str());
return false;
@ -106,10 +106,15 @@ DEFINE_int(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)");
DEFINE_int(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)");
DEFINE_int(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)");
DEFINE_int(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)");
DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and "
"codec");
DEFINE_string(replacement_audio_file, "",
"A PCM file that will be used to populate ""dummy"" RTP packets");
DEFINE_bool(codec_map,
false,
"Prints the mapping between RTP payload type and "
"codec");
DEFINE_string(replacement_audio_file,
"",
"A PCM file that will be used to populate "
"dummy"
" RTP packets");
DEFINE_string(ssrc,
"",
"Only use packets with this SSRC (decimal or hex, the latter "
@ -240,8 +245,8 @@ class SsrcSwitchDetector : public NetEqPostInsertPacket {
NetEq* neteq) override {
if (last_ssrc_ && packet.header.ssrc != *last_ssrc_) {
std::cout << "Changing streams from 0x" << std::hex << *last_ssrc_
<< " to 0x" << std::hex << packet.header.ssrc
<< std::dec << " (payload type "
<< " to 0x" << std::hex << packet.header.ssrc << std::dec
<< " (payload type "
<< static_cast<int>(packet.header.payloadType) << ")"
<< std::endl;
}
@ -258,10 +263,13 @@ class SsrcSwitchDetector : public NetEqPostInsertPacket {
int RunTest(int argc, char* argv[]) {
std::string program_name = argv[0];
std::string usage = "Tool for decoding an RTP dump file using NetEq.\n"
"Run " + program_name + " --help for usage.\n"
"Example usage:\n" + program_name +
" input.rtp output.{pcm, wav}\n";
std::string usage =
"Tool for decoding an RTP dump file using NetEq.\n"
"Run " +
program_name +
" --help for usage.\n"
"Example usage:\n" +
program_name + " input.rtp output.{pcm, wav}\n";
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
return 1;
}
@ -406,10 +414,8 @@ int RunTest(int argc, char* argv[]) {
{FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")},
{FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")},
{FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")},
{FLAG_avt_32,
std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")},
{FLAG_avt_48,
std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")},
{FLAG_avt_32, std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")},
{FLAG_avt_48, std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")},
{FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")},
{FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")},
{FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")},
@ -440,9 +446,8 @@ int RunTest(int argc, char* argv[]) {
std::set<uint8_t> cn_types = std_set_int32_to_uint8(
{FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48});
std::set<uint8_t> forbidden_types =
std_set_int32_to_uint8({FLAG_g722, FLAG_red, FLAG_avt,
FLAG_avt_16, FLAG_avt_32, FLAG_avt_48});
std::set<uint8_t> forbidden_types = std_set_int32_to_uint8(
{FLAG_g722, FLAG_red, FLAG_avt, FLAG_avt_16, FLAG_avt_32, FLAG_avt_48});
input.reset(new NetEqReplacementInput(std::move(input), replacement_pt,
cn_types, forbidden_types));

View File

@ -26,8 +26,7 @@ std::string NetEqStatsGetter::ConcealmentEvent::ToString() const {
rtc::SimpleStringBuilder ss(ss_buf);
ss << "ConcealmentEvent duration_ms:" << duration_ms
<< " event_number:" << concealment_event_number
<< " time_from_previous_event_end_ms:"
<< time_from_previous_event_end_ms;
<< " time_from_previous_event_end_ms:" << time_from_previous_event_end_ms;
return ss.str();
}
@ -115,12 +114,10 @@ NetEqStatsGetter::Stats NetEqStatsGetter::AverageStats() const {
a.added_zero_samples += b.added_zero_samples;
a.mean_waiting_time_ms += b.mean_waiting_time_ms;
a.median_waiting_time_ms += b.median_waiting_time_ms;
a.min_waiting_time_ms =
std::min(a.min_waiting_time_ms,
static_cast<double>(b.min_waiting_time_ms));
a.max_waiting_time_ms =
std::max(a.max_waiting_time_ms,
static_cast<double>(b.max_waiting_time_ms));
a.min_waiting_time_ms = std::min(
a.min_waiting_time_ms, static_cast<double>(b.min_waiting_time_ms));
a.max_waiting_time_ms = std::max(
a.max_waiting_time_ms, static_cast<double>(b.max_waiting_time_ms));
return a;
});

View File

@ -69,9 +69,7 @@ class NetEqStatsGetter : public NetEqGetAudioCallback {
double AverageSpeechExpandRate() const;
NetEqDelayAnalyzer* delay_analyzer() const {
return delay_analyzer_.get();
}
NetEqDelayAnalyzer* delay_analyzer() const { return delay_analyzer_.get(); }
const std::vector<ConcealmentEvent>& concealment_events() const {
// Do not account for the last concealment event to avoid potential end

View File

@ -158,11 +158,10 @@ void Packet::CopyToHeader(RTPHeader* destination) const {
destination->paddingLength = header_.paddingLength;
destination->headerLength = header_.headerLength;
destination->payload_type_frequency = header_.payload_type_frequency;
memcpy(&destination->arrOfCSRCs,
&header_.arrOfCSRCs,
memcpy(&destination->arrOfCSRCs, &header_.arrOfCSRCs,
sizeof(header_.arrOfCSRCs));
memcpy(
&destination->extension, &header_.extension, sizeof(header_.extension));
memcpy(&destination->extension, &header_.extension,
sizeof(header_.extension));
}
} // namespace test

View File

@ -15,7 +15,7 @@
#include <memory>
#include "api/rtp_headers.h" // NOLINT(build/include)
#include "common_types.h" // NOLINT(build/include)
#include "common_types.h" // NOLINT(build/include)
#include "rtc_base/constructormagic.h"
#include "typedefs.h" // NOLINT(build/include)

View File

@ -28,7 +28,7 @@ void MakeRtpHeader(int payload_type,
rtp_data[0] = 0x80;
rtp_data[1] = static_cast<uint8_t>(payload_type);
rtp_data[2] = (seq_number >> 8) & 0xFF;
rtp_data[3] = (seq_number) & 0xFF;
rtp_data[3] = (seq_number)&0xFF;
rtp_data[4] = timestamp >> 24;
rtp_data[5] = (timestamp >> 16) & 0xFF;
rtp_data[6] = (timestamp >> 8) & 0xFF;
@ -47,8 +47,8 @@ TEST(TestPacket, RegularPacket) {
const uint16_t kSequenceNumber = 4711;
const uint32_t kTimestamp = 47114711;
const uint32_t kSsrc = 0x12345678;
MakeRtpHeader(
kPayloadType, kSequenceNumber, kTimestamp, kSsrc, packet_memory);
MakeRtpHeader(kPayloadType, kSequenceNumber, kTimestamp, kSsrc,
packet_memory);
const double kPacketTime = 1.0;
// Hand over ownership of |packet_memory| to |packet|.
Packet packet(packet_memory, kPacketLengthBytes, kPacketTime);
@ -75,13 +75,11 @@ TEST(TestPacket, DummyPacket) {
const uint16_t kSequenceNumber = 4711;
const uint32_t kTimestamp = 47114711;
const uint32_t kSsrc = 0x12345678;
MakeRtpHeader(
kPayloadType, kSequenceNumber, kTimestamp, kSsrc, packet_memory);
MakeRtpHeader(kPayloadType, kSequenceNumber, kTimestamp, kSsrc,
packet_memory);
const double kPacketTime = 1.0;
// Hand over ownership of |packet_memory| to |packet|.
Packet packet(packet_memory,
kPacketLengthBytes,
kVirtualPacketLengthBytes,
Packet packet(packet_memory, kPacketLengthBytes, kVirtualPacketLengthBytes,
kPacketTime);
ASSERT_TRUE(packet.valid_header());
EXPECT_EQ(kPayloadType, packet.header().payloadType);
@ -140,8 +138,8 @@ TEST(TestPacket, RED) {
const uint16_t kSequenceNumber = 4711;
const uint32_t kTimestamp = 47114711;
const uint32_t kSsrc = 0x12345678;
MakeRtpHeader(
kRedPayloadType, kSequenceNumber, kTimestamp, kSsrc, packet_memory);
MakeRtpHeader(kRedPayloadType, kSequenceNumber, kTimestamp, kSsrc,
packet_memory);
// Create four RED headers.
// Payload types are just the same as the block index the offset is 100 times
// the block index.
@ -154,8 +152,8 @@ TEST(TestPacket, RED) {
uint32_t timestamp_offset = 100 * i;
int block_length = 10 * i;
bool last_block = (i == kRedBlocks - 1) ? true : false;
payload_ptr += MakeRedHeader(
payload_type, timestamp_offset, block_length, last_block, payload_ptr);
payload_ptr += MakeRedHeader(payload_type, timestamp_offset, block_length,
last_block, payload_ptr);
}
const double kPacketTime = 1.0;
// Hand over ownership of |packet_memory| to |packet|.
@ -178,8 +176,7 @@ TEST(TestPacket, RED) {
EXPECT_EQ(kRedBlocks, static_cast<int>(red_headers.size()));
int block_index = 0;
for (std::list<RTPHeader*>::reverse_iterator it = red_headers.rbegin();
it != red_headers.rend();
++it) {
it != red_headers.rend(); ++it) {
// Reading list from the back, since the extraction puts the main payload
// (which is the last one on wire) first.
RTPHeader* red_block = *it;

View File

@ -20,10 +20,14 @@
// Define command line flags.
DEFINE_int(red, 117, "RTP payload type for RED");
DEFINE_int(audio_level, -1, "Extension ID for audio level (RFC 6464); "
"-1 not to print audio level");
DEFINE_int(abs_send_time, -1, "Extension ID for absolute sender time; "
"-1 not to print absolute send time");
DEFINE_int(audio_level,
-1,
"Extension ID for audio level (RFC 6464); "
"-1 not to print audio level");
DEFINE_int(abs_send_time,
-1,
"Extension ID for absolute sender time; "
"-1 not to print absolute send time");
DEFINE_bool(help, false, "Print this message");
int main(int argc, char* argv[]) {
@ -37,8 +41,8 @@ int main(int argc, char* argv[]) {
program_name + " input.rtp output.txt\n\n" +
"Output is sent to stdout if no output file is given. " +
"Note that this tool can read files with or without payloads.\n";
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) ||
FLAG_help || (argc != 2 && argc != 3)) {
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
(argc != 2 && argc != 3)) {
printf("%s", usage.c_str());
if (FLAG_help) {
rtc::FlagList::Print(nullptr, false);
@ -47,10 +51,11 @@ int main(int argc, char* argv[]) {
return 1;
}
RTC_CHECK(FLAG_red >= 0 && FLAG_red <= 127); // Payload type
RTC_CHECK(FLAG_audio_level == -1 || // Default
(FLAG_audio_level > 0 && FLAG_audio_level <= 255)); // Extension ID
RTC_CHECK(FLAG_abs_send_time == -1 || // Default
RTC_CHECK(FLAG_red >= 0 && FLAG_red <= 127); // Payload type
RTC_CHECK(FLAG_audio_level == -1 || // Default
(FLAG_audio_level > 0 && FLAG_audio_level <= 255)); // Extension ID
RTC_CHECK(
FLAG_abs_send_time == -1 || // Default
(FLAG_abs_send_time > 0 && FLAG_abs_send_time <= 255)); // Extension ID
printf("Input file: %s\n", argv[1]);
@ -104,19 +109,14 @@ int main(int argc, char* argv[]) {
}
// Write packet data to file. Use virtual_packet_length_bytes so that the
// correct packet sizes are printed also for RTP header-only dumps.
fprintf(out_file,
"%5u %10u %10u %5i %5i %2i %#08X",
packet->header().sequenceNumber,
packet->header().timestamp,
fprintf(out_file, "%5u %10u %10u %5i %5i %2i %#08X",
packet->header().sequenceNumber, packet->header().timestamp,
static_cast<unsigned int>(packet->time_ms()),
static_cast<int>(packet->virtual_packet_length_bytes()),
packet->header().payloadType,
packet->header().markerBit,
packet->header().payloadType, packet->header().markerBit,
packet->header().ssrc);
if (print_audio_level && packet->header().extension.hasAudioLevel) {
fprintf(out_file,
" %5u (%1i)",
packet->header().extension.audioLevel,
fprintf(out_file, " %5u (%1i)", packet->header().extension.audioLevel,
packet->header().extension.voiceActivity);
}
if (print_abs_send_time && packet->header().extension.hasAbsoluteSendTime) {
@ -156,11 +156,8 @@ int main(int argc, char* argv[]) {
while (!red_headers.empty()) {
webrtc::RTPHeader* red = red_headers.front();
assert(red);
fprintf(out_file,
"* %5u %10u %10u %5i\n",
red->sequenceNumber,
red->timestamp,
static_cast<unsigned int>(packet->time_ms()),
fprintf(out_file, "* %5u %10u %10u %5i\n", red->sequenceNumber,
red->timestamp, static_cast<unsigned int>(packet->time_ms()),
red->payloadType);
red_headers.pop_front();
delete red;

View File

@ -247,11 +247,16 @@ AudioEncoderCng::Config GetCngConfig(int sample_rate_hz) {
AudioEncoderCng::Config cng_config;
const auto default_payload_type = [&] {
switch (sample_rate_hz) {
case 8000: return 13;
case 16000: return 98;
case 32000: return 99;
case 48000: return 100;
default: RTC_NOTREACHED();
case 8000:
return 13;
case 16000:
return 98;
case 32000:
return 99;
case 48000:
return 100;
default:
RTC_NOTREACHED();
}
return 0;
};

View File

@ -44,8 +44,7 @@ bool RtpFileSource::ValidPcap(const std::string& file_name) {
return !!temp_file;
}
RtpFileSource::~RtpFileSource() {
}
RtpFileSource::~RtpFileSource() {}
bool RtpFileSource::RegisterRtpHeaderExtension(RTPExtensionType type,
uint8_t id) {
@ -82,8 +81,7 @@ std::unique_ptr<Packet> RtpFileSource::NextPacket() {
}
RtpFileSource::RtpFileSource()
: PacketSource(),
parser_(RtpHeaderParser::Create()) {}
: PacketSource(), parser_(RtpHeaderParser::Create()) {}
bool RtpFileSource::OpenFile(const std::string& file_name) {
rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kRtpDump, file_name));

View File

@ -32,8 +32,8 @@ uint32_t RtpGenerator::GetRtpHeader(uint8_t payload_type,
uint32_t this_send_time = next_send_time_ms_;
assert(samples_per_ms_ > 0);
next_send_time_ms_ += ((1.0 + drift_factor_) * payload_length_samples) /
samples_per_ms_;
next_send_time_ms_ +=
((1.0 + drift_factor_) * payload_length_samples) / samples_per_ms_;
return this_send_time;
}
@ -46,8 +46,8 @@ void RtpGenerator::set_drift_factor(double factor) {
uint32_t TimestampJumpRtpGenerator::GetRtpHeader(uint8_t payload_type,
size_t payload_length_samples,
RTPHeader* rtp_header) {
uint32_t ret = RtpGenerator::GetRtpHeader(
payload_type, payload_length_samples, rtp_header);
uint32_t ret = RtpGenerator::GetRtpHeader(payload_type,
payload_length_samples, rtp_header);
if (timestamp_ - static_cast<uint32_t>(payload_length_samples) <=
jump_from_timestamp_ &&
timestamp_ > jump_from_timestamp_) {

View File

@ -32,8 +32,7 @@ class RtpGenerator {
next_send_time_ms_(start_send_time_ms),
ssrc_(ssrc),
samples_per_ms_(samples_per_ms),
drift_factor_(0.0) {
}
drift_factor_(0.0) {}
virtual ~RtpGenerator() {}