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

@ -30,11 +30,15 @@ int32_t Channel::SendData(FrameType frameType,
rtpInfo.header.markerBit = false;
rtpInfo.header.ssrc = 0;
rtpInfo.header.sequenceNumber = (external_sequence_number_ < 0) ?
_seqNo++ : static_cast<uint16_t>(external_sequence_number_);
rtpInfo.header.sequenceNumber =
(external_sequence_number_ < 0)
? _seqNo++
: static_cast<uint16_t>(external_sequence_number_);
rtpInfo.header.payloadType = payloadType;
rtpInfo.header.timestamp = (external_send_timestamp_ < 0) ? timeStamp :
static_cast<uint32_t>(external_send_timestamp_);
rtpInfo.header.timestamp =
(external_send_timestamp_ < 0)
? timeStamp
: static_cast<uint32_t>(external_send_timestamp_);
if (frameType == kAudioFrameCN) {
rtpInfo.type.Audio.isCNG = true;
@ -57,7 +61,7 @@ int32_t Channel::SendData(FrameType frameType,
// only 0x80 if we have multiple blocks
_payloadData[0] = 0x80 + fragmentation->fragmentationPlType[1];
size_t REDheader = (fragmentation->fragmentationTimeDiff[1] << 10) +
fragmentation->fragmentationLength[1];
fragmentation->fragmentationLength[1];
_payloadData[1] = uint8_t((REDheader >> 16) & 0x000000FF);
_payloadData[2] = uint8_t((REDheader >> 8) & 0x000000FF);
_payloadData[3] = uint8_t(REDheader & 0x000000FF);
@ -96,7 +100,7 @@ int32_t Channel::SendData(FrameType frameType,
_channelCritSect.Enter();
if (_saveBitStream) {
//fwrite(payloadData, sizeof(uint8_t), payloadSize, _bitStreamFile);
// fwrite(payloadData, sizeof(uint8_t), payloadSize, _bitStreamFile);
}
if (!_isStereo) {
@ -128,8 +132,8 @@ int32_t Channel::SendData(FrameType frameType,
// TODO(turajs): rewite this method.
void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize) {
int n;
if ((rtpInfo.header.payloadType != _lastPayloadType)
&& (_lastPayloadType != -1)) {
if ((rtpInfo.header.payloadType != _lastPayloadType) &&
(_lastPayloadType != -1)) {
// payload-type is changed.
// we have to terminate the calculations on the previous payload type
// we ignore the last packet in that payload type just to make things
@ -156,14 +160,15 @@ void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize) {
if (!newPayload) {
if (!currentPayloadStr->newPacket) {
if (!_useLastFrameSize) {
_lastFrameSizeSample = (uint32_t) ((uint32_t) rtpInfo.header.timestamp -
(uint32_t) currentPayloadStr->lastTimestamp);
_lastFrameSizeSample =
(uint32_t)((uint32_t)rtpInfo.header.timestamp -
(uint32_t)currentPayloadStr->lastTimestamp);
}
assert(_lastFrameSizeSample > 0);
int k = 0;
for (; k < MAX_NUM_FRAMESIZES; ++k) {
if ((currentPayloadStr->frameSizeStats[k].frameSizeSample ==
_lastFrameSizeSample) ||
_lastFrameSizeSample) ||
(currentPayloadStr->frameSizeStats[k].frameSizeSample == 0)) {
break;
}
@ -174,9 +179,9 @@ void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize) {
_lastPayloadType, _lastFrameSizeSample);
return;
}
ACMTestFrameSizeStats* currentFrameSizeStats = &(currentPayloadStr
->frameSizeStats[k]);
currentFrameSizeStats->frameSizeSample = (int16_t) _lastFrameSizeSample;
ACMTestFrameSizeStats* currentFrameSizeStats =
&(currentPayloadStr->frameSizeStats[k]);
currentFrameSizeStats->frameSizeSample = (int16_t)_lastFrameSizeSample;
// increment the number of encoded samples.
currentFrameSizeStats->totalEncodedSamples += _lastFrameSizeSample;
@ -185,15 +190,15 @@ void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize) {
// increment the total number of bytes (this is based on
// the previous payload we don't know the frame-size of
// the current payload.
currentFrameSizeStats->totalPayloadLenByte += currentPayloadStr
->lastPayloadLenByte;
currentFrameSizeStats->totalPayloadLenByte +=
currentPayloadStr->lastPayloadLenByte;
// store the maximum payload-size (this is based on
// the previous payload we don't know the frame-size of
// the current payload.
if (currentFrameSizeStats->maxPayloadLen
< currentPayloadStr->lastPayloadLenByte) {
currentFrameSizeStats->maxPayloadLen = currentPayloadStr
->lastPayloadLenByte;
if (currentFrameSizeStats->maxPayloadLen <
currentPayloadStr->lastPayloadLenByte) {
currentFrameSizeStats->maxPayloadLen =
currentPayloadStr->lastPayloadLenByte;
}
// store the current values for the next time
currentPayloadStr->lastTimestamp = rtpInfo.header.timestamp;
@ -203,8 +208,8 @@ void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize) {
currentPayloadStr->lastPayloadLenByte = payloadSize;
currentPayloadStr->lastTimestamp = rtpInfo.header.timestamp;
currentPayloadStr->payloadType = rtpInfo.header.payloadType;
memset(currentPayloadStr->frameSizeStats, 0, MAX_NUM_FRAMESIZES *
sizeof(ACMTestFrameSizeStats));
memset(currentPayloadStr->frameSizeStats, 0,
MAX_NUM_FRAMESIZES * sizeof(ACMTestFrameSizeStats));
}
} else {
n = 0;
@ -216,8 +221,8 @@ void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize) {
_payloadStats[n].lastPayloadLenByte = payloadSize;
_payloadStats[n].lastTimestamp = rtpInfo.header.timestamp;
_payloadStats[n].payloadType = rtpInfo.header.payloadType;
memset(_payloadStats[n].frameSizeStats, 0, MAX_NUM_FRAMESIZES *
sizeof(ACMTestFrameSizeStats));
memset(_payloadStats[n].frameSizeStats, 0,
MAX_NUM_FRAMESIZES * sizeof(ACMTestFrameSizeStats));
}
}
@ -262,8 +267,7 @@ Channel::Channel(int16_t chID)
}
}
Channel::~Channel() {
}
Channel::~Channel() {}
void Channel::RegisterReceiverACM(AudioCodingModule* acm) {
_receiverACM = acm;
@ -311,13 +315,13 @@ int16_t Channel::Stats(CodecInst& codecInst,
_channelCritSect.Leave();
return 0;
}
payloadStats.frameSizeStats[n].usageLenSec = (double) payloadStats
.frameSizeStats[n].totalEncodedSamples / (double) codecInst.plfreq;
payloadStats.frameSizeStats[n].usageLenSec =
(double)payloadStats.frameSizeStats[n].totalEncodedSamples /
(double)codecInst.plfreq;
payloadStats.frameSizeStats[n].rateBitPerSec =
payloadStats.frameSizeStats[n].totalPayloadLenByte * 8
/ payloadStats.frameSizeStats[n].usageLenSec;
payloadStats.frameSizeStats[n].totalPayloadLenByte * 8 /
payloadStats.frameSizeStats[n].usageLenSec;
}
_channelCritSect.Leave();
return 0;
@ -353,14 +357,14 @@ void Channel::Stats(uint8_t* payloadType, uint32_t* payloadLenByte) {
if (_payloadStats[k].payloadType == -1) {
break;
}
payloadType[k] = (uint8_t) _payloadStats[k].payloadType;
payloadType[k] = (uint8_t)_payloadStats[k].payloadType;
payloadLenByte[k] = 0;
for (n = 0; n < MAX_NUM_FRAMESIZES; n++) {
if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) {
break;
}
payloadLenByte[k] += (uint16_t) _payloadStats[k].frameSizeStats[n]
.totalPayloadLenByte;
payloadLenByte[k] +=
(uint16_t)_payloadStats[k].frameSizeStats[n].totalPayloadLenByte;
}
}
@ -387,18 +391,15 @@ void Channel::PrintStats(CodecInst& codecInst) {
payloadStats.frameSizeStats[k].rateBitPerSec);
printf("Maximum Payload-Size.......... %" PRIuS " Bytes\n",
payloadStats.frameSizeStats[k].maxPayloadLen);
printf(
"Maximum Instantaneous Rate.... %.0f bits/sec\n",
((double) payloadStats.frameSizeStats[k].maxPayloadLen * 8.0
* (double) codecInst.plfreq)
/ (double) payloadStats.frameSizeStats[k].frameSizeSample);
printf("Maximum Instantaneous Rate.... %.0f bits/sec\n",
((double)payloadStats.frameSizeStats[k].maxPayloadLen * 8.0 *
(double)codecInst.plfreq) /
(double)payloadStats.frameSizeStats[k].frameSizeSample);
printf("Number of Packets............. %u\n",
(unsigned int) payloadStats.frameSizeStats[k].numPackets);
(unsigned int)payloadStats.frameSizeStats[k].numPackets);
printf("Duration...................... %0.3f sec\n\n",
payloadStats.frameSizeStats[k].usageLenSec);
}
}
uint32_t Channel::LastInTimestamp() {
@ -413,7 +414,7 @@ double Channel::BitRate() {
double rate;
uint64_t currTime = rtc::TimeMillis();
_channelCritSect.Enter();
rate = ((double) _totalBytes * 8.0) / (double) (currTime - _beginTime);
rate = ((double)_totalBytes * 8.0) / (double)(currTime - _beginTime);
_channelCritSect.Leave();
return rate;
}

View File

@ -20,8 +20,8 @@
namespace webrtc {
#define MAX_NUM_PAYLOADS 50
#define MAX_NUM_FRAMESIZES 6
#define MAX_NUM_PAYLOADS 50
#define MAX_NUM_FRAMESIZES 6
// TODO(turajs): Write constructor for this structure.
struct ACMTestFrameSizeStats {
@ -45,7 +45,6 @@ struct ACMTestPayloadStats {
class Channel : public AudioPacketizationCallback {
public:
Channel(int16_t chID = -1);
~Channel() override;
@ -56,7 +55,7 @@ class Channel : public AudioPacketizationCallback {
size_t payloadSize,
const RTPFragmentationHeader* fragmentation) override;
void RegisterReceiverACM(AudioCodingModule *acm);
void RegisterReceiverACM(AudioCodingModule* acm);
void ResetStats();
@ -68,9 +67,7 @@ class Channel : public AudioPacketizationCallback {
void PrintStats(CodecInst& codecInst);
void SetIsStereo(bool isStereo) {
_isStereo = isStereo;
}
void SetIsStereo(bool isStereo) { _isStereo = isStereo; }
uint32_t LastInTimestamp();

View File

@ -10,10 +10,10 @@
#include "modules/audio_coding/test/EncodeDecodeTest.h"
#include <memory>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <memory>
#include <sstream> // no-presubmit-check TODO(webrtc:8982)
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "common_types.h" // NOLINT(build/include)

View File

@ -30,8 +30,8 @@ PCMFile::PCMFile()
rewinded_(false),
read_stereo_(false),
save_stereo_(false) {
timestamp_ = (((uint32_t) rand() & 0x0000FFFF) << 16) |
((uint32_t) rand() & 0x0000FFFF);
timestamp_ =
(((uint32_t)rand() & 0x0000FFFF) << 16) | ((uint32_t)rand() & 0x0000FFFF);
}
PCMFile::PCMFile(uint32_t timestamp)
@ -52,7 +52,8 @@ PCMFile::~PCMFile() {
}
}
int16_t PCMFile::ChooseFile(std::string* file_name, int16_t max_len,
int16_t PCMFile::ChooseFile(std::string* file_name,
int16_t max_len,
uint16_t* frequency_hz) {
char tmp_name[MAX_FILE_NAME_LENGTH_BYTE];
@ -61,8 +62,8 @@ int16_t PCMFile::ChooseFile(std::string* file_name, int16_t max_len,
int16_t n = 0;
// Removing trailing spaces.
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0)
&& (n < MAX_FILE_NAME_LENGTH_BYTE)) {
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0) &&
(n < MAX_FILE_NAME_LENGTH_BYTE)) {
n++;
}
if (n > 0) {
@ -80,7 +81,7 @@ int16_t PCMFile::ChooseFile(std::string* file_name, int16_t max_len,
tmp_name[n + 1] = '\0';
}
int16_t len = (int16_t) strlen(tmp_name);
int16_t len = (int16_t)strlen(tmp_name);
if (len > max_len) {
return -1;
}
@ -91,15 +92,17 @@ int16_t PCMFile::ChooseFile(std::string* file_name, int16_t max_len,
printf("Enter the sampling frequency (in Hz) of the above file [%u]: ",
*frequency_hz);
EXPECT_TRUE(fgets(tmp_name, 10, stdin) != NULL);
uint16_t tmp_frequency = (uint16_t) atoi(tmp_name);
uint16_t tmp_frequency = (uint16_t)atoi(tmp_name);
if (tmp_frequency > 0) {
*frequency_hz = tmp_frequency;
}
return 0;
}
void PCMFile::Open(const std::string& file_name, uint16_t frequency,
const char* mode, bool auto_rewind) {
void PCMFile::Open(const std::string& file_name,
uint16_t frequency,
const char* mode,
bool auto_rewind) {
if ((pcm_file_ = fopen(file_name.c_str(), mode)) == NULL) {
printf("Cannot open file %s.\n", file_name.c_str());
ADD_FAILURE() << "Unable to read file";
@ -125,9 +128,9 @@ int32_t PCMFile::Read10MsData(AudioFrame& audio_frame) {
channels = 2;
}
int32_t payload_size = (int32_t) fread(audio_frame.mutable_data(),
sizeof(uint16_t),
samples_10ms_ * channels, pcm_file_);
int32_t payload_size =
(int32_t)fread(audio_frame.mutable_data(), sizeof(uint16_t),
samples_10ms_ * channels, pcm_file_);
if (payload_size < samples_10ms_ * channels) {
int16_t* frame_data = audio_frame.mutable_data();
for (int k = payload_size; k < samples_10ms_ * channels; k++) {

View File

@ -28,26 +28,27 @@ class PCMFile {
PCMFile(uint32_t timestamp);
~PCMFile();
void Open(const std::string& filename, uint16_t frequency, const char* mode,
void Open(const std::string& filename,
uint16_t frequency,
const char* mode,
bool auto_rewind = false);
int32_t Read10MsData(AudioFrame& audio_frame);
void Write10MsData(const int16_t *playout_buffer, size_t length_smpls);
void Write10MsData(const int16_t* playout_buffer, size_t length_smpls);
void Write10MsData(const AudioFrame& audio_frame);
uint16_t PayloadLength10Ms() const;
int32_t SamplingFrequency() const;
void Close();
bool EndOfFile() const {
return end_of_file_;
}
bool EndOfFile() const { return end_of_file_; }
// Moves forward the specified number of 10 ms blocks. If a limit has been set
// with SetNum10MsBlocksToRead, fast-forwarding does not count towards this
// limit.
void FastForward(int num_10ms_blocks);
void Rewind();
static int16_t ChooseFile(std::string* file_name, int16_t max_len,
static int16_t ChooseFile(std::string* file_name,
int16_t max_len,
uint16_t* frequency_hz);
bool Rewinded();
void SaveStereo(bool is_stereo = true);

View File

@ -23,11 +23,10 @@ ReceiverWithPacketLoss::ReceiverWithPacketLoss()
burst_length_(1),
packet_counter_(0),
lost_packet_counter_(0),
burst_lost_counter_(burst_length_) {
}
burst_lost_counter_(burst_length_) {}
void ReceiverWithPacketLoss::Setup(AudioCodingModule *acm,
RTPStream *rtpStream,
void ReceiverWithPacketLoss::Setup(AudioCodingModule* acm,
RTPStream* rtpStream,
std::string out_file_name,
int channels,
int loss_rate,
@ -84,13 +83,14 @@ bool ReceiverWithPacketLoss::PacketLost() {
return false;
}
SenderWithFEC::SenderWithFEC()
: expected_loss_rate_(0) {
}
SenderWithFEC::SenderWithFEC() : expected_loss_rate_(0) {}
void SenderWithFEC::Setup(AudioCodingModule *acm, RTPStream *rtpStream,
std::string in_file_name, int sample_rate,
int channels, int expected_loss_rate) {
void SenderWithFEC::Setup(AudioCodingModule* acm,
RTPStream* rtpStream,
std::string in_file_name,
int sample_rate,
int channels,
int expected_loss_rate) {
Sender::Setup(acm, rtpStream, in_file_name, sample_rate, channels);
EXPECT_TRUE(SetFEC(true));
EXPECT_TRUE(SetPacketLossRate(expected_loss_rate));
@ -111,18 +111,19 @@ bool SenderWithFEC::SetPacketLossRate(int expected_loss_rate) {
return false;
}
PacketLossTest::PacketLossTest(int channels, int expected_loss_rate,
int actual_loss_rate, int burst_length)
PacketLossTest::PacketLossTest(int channels,
int expected_loss_rate,
int actual_loss_rate,
int burst_length)
: channels_(channels),
in_file_name_(channels_ == 1 ? "audio_coding/testfile32kHz" :
"audio_coding/teststereo32kHz"),
in_file_name_(channels_ == 1 ? "audio_coding/testfile32kHz"
: "audio_coding/teststereo32kHz"),
sample_rate_hz_(32000),
sender_(new SenderWithFEC),
receiver_(new ReceiverWithPacketLoss),
expected_loss_rate_(expected_loss_rate),
actual_loss_rate_(actual_loss_rate),
burst_length_(burst_length) {
}
burst_length_(burst_length) {}
void PacketLossTest::Perform() {
#ifndef WEBRTC_CODEC_OPUS

View File

@ -20,8 +20,11 @@ namespace webrtc {
class ReceiverWithPacketLoss : public Receiver {
public:
ReceiverWithPacketLoss();
void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
std::string out_file_name, int channels, int loss_rate,
void Setup(AudioCodingModule* acm,
RTPStream* rtpStream,
std::string out_file_name,
int channels,
int loss_rate,
int burst_length);
bool IncomingPacket() override;
@ -37,20 +40,27 @@ class ReceiverWithPacketLoss : public Receiver {
class SenderWithFEC : public Sender {
public:
SenderWithFEC();
void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
std::string in_file_name, int sample_rate, int channels,
void Setup(AudioCodingModule* acm,
RTPStream* rtpStream,
std::string in_file_name,
int sample_rate,
int channels,
int expected_loss_rate);
bool SetPacketLossRate(int expected_loss_rate);
bool SetFEC(bool enable_fec);
protected:
int expected_loss_rate_;
};
class PacketLossTest : public ACMTest {
public:
PacketLossTest(int channels, int expected_loss_rate_, int actual_loss_rate,
PacketLossTest(int channels,
int expected_loss_rate_,
int actual_loss_rate,
int burst_length);
void Perform();
protected:
int channels_;
std::string in_file_name_;

View File

@ -14,9 +14,9 @@
#include <limits>
#ifdef WIN32
# include <Winsock2.h>
#include <Winsock2.h>
#else
# include <arpa/inet.h>
#include <arpa/inet.h>
#endif
#include "modules/include/module_common_types.h"
@ -29,18 +29,22 @@ namespace webrtc {
void RTPStream::ParseRTPHeader(WebRtcRTPHeader* rtpInfo,
const uint8_t* rtpHeader) {
rtpInfo->header.payloadType = rtpHeader[1];
rtpInfo->header.sequenceNumber = (static_cast<uint16_t>(rtpHeader[2]) << 8) |
rtpHeader[3];
rtpInfo->header.sequenceNumber =
(static_cast<uint16_t>(rtpHeader[2]) << 8) | rtpHeader[3];
rtpInfo->header.timestamp = (static_cast<uint32_t>(rtpHeader[4]) << 24) |
(static_cast<uint32_t>(rtpHeader[5]) << 16) |
(static_cast<uint32_t>(rtpHeader[6]) << 8) | rtpHeader[7];
(static_cast<uint32_t>(rtpHeader[5]) << 16) |
(static_cast<uint32_t>(rtpHeader[6]) << 8) |
rtpHeader[7];
rtpInfo->header.ssrc = (static_cast<uint32_t>(rtpHeader[8]) << 24) |
(static_cast<uint32_t>(rtpHeader[9]) << 16) |
(static_cast<uint32_t>(rtpHeader[10]) << 8) | rtpHeader[11];
(static_cast<uint32_t>(rtpHeader[9]) << 16) |
(static_cast<uint32_t>(rtpHeader[10]) << 8) |
rtpHeader[11];
}
void RTPStream::MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
int16_t seqNo, uint32_t timeStamp,
void RTPStream::MakeRTPheader(uint8_t* rtpHeader,
uint8_t payloadType,
int16_t seqNo,
uint32_t timeStamp,
uint32_t ssrc) {
rtpHeader[0] = 0x80;
rtpHeader[1] = payloadType;
@ -56,8 +60,11 @@ void RTPStream::MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
rtpHeader[11] = ssrc & 0xFF;
}
RTPPacket::RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
const uint8_t* payloadData, size_t payloadSize,
RTPPacket::RTPPacket(uint8_t payloadType,
uint32_t timeStamp,
int16_t seqNo,
const uint8_t* payloadData,
size_t payloadSize,
uint32_t frequency)
: payloadType(payloadType),
timeStamp(timeStamp),
@ -82,20 +89,25 @@ RTPBuffer::~RTPBuffer() {
delete _queueRWLock;
}
void RTPBuffer::Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const size_t payloadSize, uint32_t frequency) {
RTPPacket *packet = new RTPPacket(payloadType, timeStamp, seqNo, payloadData,
void RTPBuffer::Write(const uint8_t payloadType,
const uint32_t timeStamp,
const int16_t seqNo,
const uint8_t* payloadData,
const size_t payloadSize,
uint32_t frequency) {
RTPPacket* packet = new RTPPacket(payloadType, timeStamp, seqNo, payloadData,
payloadSize, frequency);
_queueRWLock->AcquireLockExclusive();
_rtpQueue.push(packet);
_queueRWLock->ReleaseLockExclusive();
}
size_t RTPBuffer::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
size_t payloadSize, uint32_t* offset) {
size_t RTPBuffer::Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
size_t payloadSize,
uint32_t* offset) {
_queueRWLock->AcquireLockShared();
RTPPacket *packet = _rtpQueue.front();
RTPPacket* packet = _rtpQueue.front();
_rtpQueue.pop();
_queueRWLock->ReleaseLockShared();
rtpInfo->header.markerBit = 1;
@ -120,7 +132,7 @@ bool RTPBuffer::EndOfFile() const {
return eof;
}
void RTPFile::Open(const char *filename, const char *mode) {
void RTPFile::Open(const char* filename, const char* mode) {
if ((_rtpFile = fopen(filename, mode)) == NULL) {
printf("Cannot write file %s.\n", filename);
ADD_FAILURE() << "Unable to write file";
@ -165,9 +177,12 @@ void RTPFile::ReadHeader() {
padding = ntohs(padding);
}
void RTPFile::Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const size_t payloadSize, uint32_t frequency) {
void RTPFile::Write(const uint8_t payloadType,
const uint32_t timeStamp,
const int16_t seqNo,
const uint8_t* payloadData,
const size_t payloadSize,
uint32_t frequency) {
/* write RTP packet to file */
uint8_t rtpHeader[12];
MakeRTPheader(rtpHeader, payloadType, seqNo, timeStamp, 0);
@ -185,8 +200,10 @@ void RTPFile::Write(const uint8_t payloadType, const uint32_t timeStamp,
EXPECT_EQ(payloadSize, fwrite(payloadData, 1, payloadSize, _rtpFile));
}
size_t RTPFile::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
size_t payloadSize, uint32_t* offset) {
size_t RTPFile::Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
size_t payloadSize,
uint32_t* offset) {
uint16_t lengthBytes;
uint16_t plen;
uint8_t rtpHeader[12];

View File

@ -22,30 +22,40 @@ namespace webrtc {
class RTPStream {
public:
virtual ~RTPStream() {
}
virtual ~RTPStream() {}
virtual void Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const size_t payloadSize, uint32_t frequency) = 0;
virtual void Write(const uint8_t payloadType,
const uint32_t timeStamp,
const int16_t seqNo,
const uint8_t* payloadData,
const size_t payloadSize,
uint32_t frequency) = 0;
// Returns the packet's payload size. Zero should be treated as an
// end-of-stream (in the case that EndOfFile() is true) or an error.
virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
size_t payloadSize, uint32_t* offset) = 0;
virtual size_t Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
size_t payloadSize,
uint32_t* offset) = 0;
virtual bool EndOfFile() const = 0;
protected:
void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, int16_t seqNo,
uint32_t timeStamp, uint32_t ssrc);
void MakeRTPheader(uint8_t* rtpHeader,
uint8_t payloadType,
int16_t seqNo,
uint32_t timeStamp,
uint32_t ssrc);
void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader);
};
class RTPPacket {
public:
RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
const uint8_t* payloadData, size_t payloadSize,
RTPPacket(uint8_t payloadType,
uint32_t timeStamp,
int16_t seqNo,
const uint8_t* payloadData,
size_t payloadSize,
uint32_t frequency);
~RTPPacket();
@ -80,20 +90,16 @@ class RTPBuffer : public RTPStream {
private:
RWLockWrapper* _queueRWLock;
std::queue<RTPPacket *> _rtpQueue;
std::queue<RTPPacket*> _rtpQueue;
};
class RTPFile : public RTPStream {
public:
~RTPFile() {
}
~RTPFile() {}
RTPFile()
: _rtpFile(NULL),
_rtpEOF(false) {
}
RTPFile() : _rtpFile(NULL), _rtpEOF(false) {}
void Open(const char *outFilename, const char *mode);
void Open(const char* outFilename, const char* mode);
void Close();

View File

@ -46,19 +46,19 @@ TestPack::TestPack()
timestamp_diff_(0),
last_in_timestamp_(0),
total_bytes_(0),
payload_size_(0) {
}
payload_size_(0) {}
TestPack::~TestPack() {
}
TestPack::~TestPack() {}
void TestPack::RegisterReceiverACM(AudioCodingModule* acm) {
receiver_acm_ = acm;
return;
}
int32_t TestPack::SendData(FrameType frame_type, uint8_t payload_type,
uint32_t timestamp, const uint8_t* payload_data,
int32_t TestPack::SendData(FrameType frame_type,
uint8_t payload_type,
uint32_t timestamp,
const uint8_t* payload_data,
size_t payload_size,
const RTPFragmentationHeader* fragmentation) {
WebRtcRTPHeader rtp_info;
@ -125,8 +125,8 @@ TestAllCodecs::~TestAllCodecs() {
}
void TestAllCodecs::Perform() {
const std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
const std::string file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
infile_a_.Open(file_name, 32000, "rb");
if (test_mode_ == 0) {
@ -306,17 +306,17 @@ void TestAllCodecs::Perform() {
char codec_opus[] = "OPUS";
RegisterSendCodec('A', codec_opus, 48000, 6000, 480, kVariableSize);
Run(channel_a_to_b_);
RegisterSendCodec('A', codec_opus, 48000, 20000, 480*2, kVariableSize);
RegisterSendCodec('A', codec_opus, 48000, 20000, 480 * 2, kVariableSize);
Run(channel_a_to_b_);
RegisterSendCodec('A', codec_opus, 48000, 32000, 480*4, kVariableSize);
RegisterSendCodec('A', codec_opus, 48000, 32000, 480 * 4, kVariableSize);
Run(channel_a_to_b_);
RegisterSendCodec('A', codec_opus, 48000, 48000, 480, kVariableSize);
Run(channel_a_to_b_);
RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, kVariableSize);
RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, kVariableSize);
Run(channel_a_to_b_);
RegisterSendCodec('A', codec_opus, 48000, 96000, 480*6, kVariableSize);
RegisterSendCodec('A', codec_opus, 48000, 96000, 480 * 6, kVariableSize);
Run(channel_a_to_b_);
RegisterSendCodec('A', codec_opus, 48000, 500000, 480*2, kVariableSize);
RegisterSendCodec('A', codec_opus, 48000, 500000, 480 * 2, kVariableSize);
Run(channel_a_to_b_);
outfile_b_.Close();
#endif
@ -351,9 +351,12 @@ void TestAllCodecs::Perform() {
// used when registering, can be an internal header
// set to kVariableSize if the codec is a variable
// rate codec
void TestAllCodecs::RegisterSendCodec(char side, char* codec_name,
int32_t sampling_freq_hz, int rate,
int packet_size, size_t extra_byte) {
void TestAllCodecs::RegisterSendCodec(char side,
char* codec_name,
int32_t sampling_freq_hz,
int rate,
int packet_size,
size_t extra_byte) {
if (test_mode_ != 0) {
// Print out codec and settings.
printf("codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
@ -377,9 +380,11 @@ void TestAllCodecs::RegisterSendCodec(char side, char* codec_name,
// packet. If variable rate codec (extra_byte == -1), set to -1.
if (extra_byte != kVariableSize) {
// Add 0.875 to always round up to a whole byte
packet_size_bytes_ = static_cast<size_t>(
static_cast<float>(packet_size * rate) /
static_cast<float>(sampling_freq_hz * 8) + 0.875) + extra_byte;
packet_size_bytes_ =
static_cast<size_t>(static_cast<float>(packet_size * rate) /
static_cast<float>(sampling_freq_hz * 8) +
0.875) +
extra_byte;
} else {
// Packets will have a variable size.
packet_size_bytes_ = kVariableSize;
@ -396,9 +401,7 @@ void TestAllCodecs::RegisterSendCodec(char side, char* codec_name,
my_acm = acm_b_.get();
break;
}
default: {
break;
}
default: { break; }
}
ASSERT_TRUE(my_acm != NULL);

View File

@ -60,8 +60,12 @@ class TestAllCodecs : public ACMTest {
// codec name, and a sampling frequency matching is not required.
// This is useful for codecs which support several sampling frequency.
// Note! Only mono mode is tested in this test.
void RegisterSendCodec(char side, char* codec_name, int32_t sampling_freq_hz,
int rate, int packet_size, size_t extra_byte);
void RegisterSendCodec(char side,
char* codec_name,
int32_t sampling_freq_hz,
int rate,
int packet_size,
size_t extra_byte);
void Run(TestPack* channel);
void OpenOutFile(int test_number);

View File

@ -26,11 +26,13 @@ class TestRedFec : public ACMTest {
~TestRedFec();
void Perform();
private:
// The default value of '-1' indicates that the registration is based only on
// codec name and a sampling frequency matching is not required. This is
// useful for codecs which support several sampling frequency.
int16_t RegisterSendCodec(char side, const char* codecName,
int16_t RegisterSendCodec(char side,
const char* codecName,
int32_t sampFreqHz = -1);
void Run();
void OpenOutFile(int16_t testNumber);

View File

@ -34,11 +34,9 @@ TestPackStereo::TestPackStereo()
total_bytes_(0),
payload_size_(0),
codec_mode_(kNotSet),
lost_packet_(false) {
}
lost_packet_(false) {}
TestPackStereo::~TestPackStereo() {
}
TestPackStereo::~TestPackStereo() {}
void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
receiver_acm_ = acm;
@ -72,8 +70,8 @@ int32_t TestPackStereo::SendData(const FrameType frame_type,
rtp_info.type.Audio.isCNG = true;
rtp_info.type.Audio.channel = static_cast<int>(kMono);
}
status = receiver_acm_->IncomingPacket(payload_data, payload_size,
rtp_info);
status =
receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_info);
if (frame_type != kAudioFrameCN) {
payload_size_ = static_cast<int>(payload_size);
@ -152,10 +150,10 @@ void TestStereo::Perform() {
ACMVADMode vad_mode;
// Open both mono and stereo test files in 32 kHz.
const std::string file_name_stereo = webrtc::test::ResourcePath(
"audio_coding/teststereo32kHz", "pcm");
const std::string file_name_mono = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
const std::string file_name_stereo =
webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
const std::string file_name_mono =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
frequency_hz = 32000;
in_file_stereo_ = new PCMFile();
in_file_mono_ = new PCMFile();
@ -230,22 +228,22 @@ void TestStereo::Perform() {
OpenOutFile(test_cntr_);
char codec_g722[] = "G722";
RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
g722_pltype_);
g722_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
g722_pltype_);
g722_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
g722_pltype_);
g722_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
g722_pltype_);
g722_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
g722_pltype_);
g722_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
g722_pltype_);
g722_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
@ -259,16 +257,16 @@ void TestStereo::Perform() {
OpenOutFile(test_cntr_);
char codec_l16[] = "L16";
RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
l16_8khz_pltype_);
l16_8khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
l16_8khz_pltype_);
l16_8khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
l16_8khz_pltype_);
l16_8khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
l16_8khz_pltype_);
l16_8khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
@ -280,16 +278,16 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
l16_16khz_pltype_);
l16_16khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
l16_16khz_pltype_);
l16_16khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
l16_16khz_pltype_);
l16_16khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
l16_16khz_pltype_);
l16_16khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
@ -301,10 +299,10 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
l16_32khz_pltype_);
l16_32khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
l16_32khz_pltype_);
l16_32khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
#ifdef PCMA_AND_PCMU
@ -392,26 +390,26 @@ void TestStereo::Perform() {
char codec_opus[] = "opus";
// Run Opus with 10 ms frame size.
RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
opus_pltype_);
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
// Run Opus with 20 ms frame size.
RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
opus_pltype_);
RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels,
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
// Run Opus with 40 ms frame size.
RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
opus_pltype_);
RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels,
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
// Run Opus with 60 ms frame size.
RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
opus_pltype_);
RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels,
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
// Run Opus with 20 ms frame size and different bitrates.
RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
opus_pltype_);
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
opus_pltype_);
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
#endif
@ -430,7 +428,7 @@ void TestStereo::Perform() {
channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
g722_pltype_);
g722_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
@ -443,7 +441,7 @@ void TestStereo::Perform() {
channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
l16_8khz_pltype_);
l16_8khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
if (test_mode_ != 0) {
@ -454,7 +452,7 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
l16_16khz_pltype_);
l16_16khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
if (test_mode_ != 0) {
@ -465,7 +463,7 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
l16_32khz_pltype_);
l16_32khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
#ifdef PCMA_AND_PCMU
@ -497,7 +495,7 @@ void TestStereo::Perform() {
channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
opus_pltype_);
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
// Encode in mono, decode in stereo mode.
@ -522,7 +520,7 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
g722_pltype_);
g722_pltype_);
// Make sure it is possible to set VAD/CNG, now that we are sending mono
// again.
@ -542,7 +540,7 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
l16_8khz_pltype_);
l16_8khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
if (test_mode_ != 0) {
@ -553,7 +551,7 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
l16_16khz_pltype_);
l16_16khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
if (test_mode_ != 0) {
@ -564,7 +562,7 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
l16_32khz_pltype_);
l16_32khz_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
#ifdef PCMA_AND_PCMU
@ -593,7 +591,7 @@ void TestStereo::Perform() {
OpenOutFile(test_cntr_);
// Encode and decode in mono.
RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
opus_pltype_);
opus_pltype_);
CodecInst opus_codec_param;
for (uint8_t n = 0; n < num_encoders; n++) {
EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
@ -620,8 +618,10 @@ void TestStereo::Perform() {
OpenOutFile(test_cntr_);
if (test_mode_ != 0) {
// Print out codec and settings
printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: mono\n", test_cntr_);
printf(
"Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: mono\n",
test_cntr_);
}
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
@ -630,8 +630,10 @@ void TestStereo::Perform() {
OpenOutFile(test_cntr_);
if (test_mode_ != 0) {
// Print out codec and settings
printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: stereo\n", test_cntr_);
printf(
"Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: stereo\n",
test_cntr_);
}
opus_codec_param.channels = 2;
EXPECT_EQ(true,
@ -644,8 +646,10 @@ void TestStereo::Perform() {
OpenOutFile(test_cntr_);
if (test_mode_ != 0) {
// Print out codec and settings
printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: mono\n", test_cntr_);
printf(
"Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: mono\n",
test_cntr_);
}
opus_codec_param.channels = 1;
EXPECT_EQ(true,
@ -665,9 +669,10 @@ void TestStereo::Perform() {
#ifdef WEBRTC_CODEC_OPUS
printf(" Opus\n");
#endif
printf("\nTo complete the test, listen to the %d number of output "
"files.\n",
test_cntr_);
printf(
"\nTo complete the test, listen to the %d number of output "
"files.\n",
test_cntr_);
}
// Delete the file pointers.
@ -684,9 +689,12 @@ void TestStereo::Perform() {
// pack_size - packet size in samples
// channels - number of channels; 1 for mono, 2 for stereo
// payload_type - payload type for the codec
void TestStereo::RegisterSendCodec(char side, char* codec_name,
int32_t sampling_freq_hz, int rate,
int pack_size, int channels,
void TestStereo::RegisterSendCodec(char side,
char* codec_name,
int32_t sampling_freq_hz,
int rate,
int pack_size,
int channels,
int payload_type) {
if (test_mode_ != 0) {
// Print out codec and settings
@ -722,7 +730,8 @@ void TestStereo::RegisterSendCodec(char side, char* codec_name,
CodecInst my_codec_param;
// Get all codec parameters before registering
EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
sampling_freq_hz, channels), -1);
sampling_freq_hz, channels),
-1);
my_codec_param.rate = rate;
my_codec_param.pacsize = pack_size;
EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
@ -730,7 +739,9 @@ void TestStereo::RegisterSendCodec(char side, char* codec_name,
send_codec_name_ = codec_name;
}
void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
void TestStereo::Run(TestPackStereo* channel,
int in_channels,
int out_channels,
int percent_loss) {
AudioFrame audio_frame;
@ -785,8 +796,8 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
variable_packets++;
} else {
// For fixed rate codecs, check that packet size is correct.
if ((rec_size != pack_size_bytes_ * out_channels)
&& (pack_size_bytes_ < 65535)) {
if ((rec_size != pack_size_bytes_ * out_channels) &&
(pack_size_bytes_ < 65535)) {
error_count++;
}
}
@ -831,7 +842,7 @@ void TestStereo::OpenOutFile(int16_t test_number) {
std::string file_name;
std::stringstream file_stream;
file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
<< ".pcm";
<< ".pcm";
file_name = file_stream.str();
out_file_.Open(file_name, 32000, "wb");
}

View File

@ -23,11 +23,7 @@
namespace webrtc {
enum StereoMonoMode {
kNotSet,
kMono,
kStereo
};
enum StereoMonoMode { kNotSet, kMono, kStereo };
class TestPackStereo : public AudioPacketizationCallback {
public:
@ -72,11 +68,17 @@ class TestStereo : public ACMTest {
// The default value of '-1' indicates that the registration is based only on
// codec name and a sampling frequncy matching is not required. This is useful
// for codecs which support several sampling frequency.
void RegisterSendCodec(char side, char* codec_name, int32_t samp_freq_hz,
int rate, int pack_size, int channels,
void RegisterSendCodec(char side,
char* codec_name,
int32_t samp_freq_hz,
int rate,
int pack_size,
int channels,
int payload_type);
void Run(TestPackStereo* channel, int in_channels, int out_channels,
void Run(TestPackStereo* channel,
int in_channels,
int out_channels,
int percent_loss = 0);
void OpenOutFile(int16_t test_number);
void DisplaySendReceiveCodec();

View File

@ -84,8 +84,11 @@ void TestVadDtx::RegisterCodec(CodecInst codec_param) {
// Encoding a file and see if the numbers that various packets occur follow
// the expectation.
void TestVadDtx::Run(std::string in_filename, int frequency, int channels,
std::string out_filename, bool append,
void TestVadDtx::Run(std::string in_filename,
int frequency,
int channels,
std::string out_filename,
bool append,
const int* expects) {
monitor_->ResetStatistics();
@ -146,13 +149,10 @@ void TestVadDtx::Run(std::string in_filename, int frequency, int channels,
// Following is the implementation of TestWebRtcVadDtx.
TestWebRtcVadDtx::TestWebRtcVadDtx()
: vad_enabled_(false),
dtx_enabled_(false),
output_file_num_(0) {
}
: vad_enabled_(false), dtx_enabled_(false), output_file_num_(0) {}
void TestWebRtcVadDtx::Perform() {
// Go through various test cases.
// Go through various test cases.
#ifdef WEBRTC_CODEC_ISAC
// Register iSAC WB as send codec
RegisterCodec(kIsacWb);
@ -206,15 +206,14 @@ void TestWebRtcVadDtx::Test(bool new_outfile) {
output_file_num_++;
}
std::stringstream out_filename;
out_filename << webrtc::test::OutputPath()
<< "testWebRtcVadDtx_outFile_"
<< output_file_num_
<< ".pcm";
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
32000, 1, out_filename.str(), !new_outfile, expects);
out_filename << webrtc::test::OutputPath() << "testWebRtcVadDtx_outFile_"
<< output_file_num_ << ".pcm";
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1,
out_filename.str(), !new_outfile, expects);
}
void TestWebRtcVadDtx::SetVAD(bool enable_dtx, bool enable_vad,
void TestWebRtcVadDtx::SetVAD(bool enable_dtx,
bool enable_vad,
ACMVADMode vad_mode) {
ACMVADMode mode;
EXPECT_EQ(0, acm_send_->SetVAD(enable_dtx, enable_vad, vad_mode));
@ -227,10 +226,10 @@ void TestWebRtcVadDtx::SetVAD(bool enable_dtx, bool enable_vad,
enable_dtx = enable_vad = false;
}
EXPECT_EQ(dtx_enabled_ , enable_dtx); // DTX should be set as expected.
EXPECT_EQ(dtx_enabled_, enable_dtx); // DTX should be set as expected.
if (dtx_enabled_) {
EXPECT_TRUE(vad_enabled_); // WebRTC DTX cannot run without WebRTC VAD.
EXPECT_TRUE(vad_enabled_); // WebRTC DTX cannot run without WebRTC VAD.
} else {
// Using no DTX should not affect setting of VAD.
EXPECT_EQ(enable_vad, vad_enabled_);
@ -250,19 +249,19 @@ void TestOpusDtx::Perform() {
int expects[] = {0, 1, 0, 0, 0};
// Register Opus as send codec
std::string out_filename = webrtc::test::OutputPath() +
"testOpusDtx_outFile_mono.pcm";
std::string out_filename =
webrtc::test::OutputPath() + "testOpusDtx_outFile_mono.pcm";
RegisterCodec(kOpus);
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
32000, 1, out_filename, false, expects);
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1,
out_filename, false, expects);
EXPECT_EQ(0, acm_send_->EnableOpusDtx());
expects[kEmptyFrame] = 1;
expects[kAudioFrameCN] = 1;
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
32000, 1, out_filename, true, expects);
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1,
out_filename, true, expects);
// Register stereo Opus as send codec
out_filename = webrtc::test::OutputPath() + "testOpusDtx_outFile_stereo.pcm";
@ -270,15 +269,15 @@ void TestOpusDtx::Perform() {
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
expects[kEmptyFrame] = 0;
expects[kAudioFrameCN] = 0;
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"),
32000, 2, out_filename, false, expects);
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000,
2, out_filename, false, expects);
EXPECT_EQ(0, acm_send_->EnableOpusDtx());
expects[kEmptyFrame] = 1;
expects[kAudioFrameCN] = 1;
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"),
32000, 2, out_filename, true, expects);
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000,
2, out_filename, true, expects);
#endif
}

View File

@ -28,6 +28,7 @@ class ActivityMonitor : public ACMVADCallback {
void PrintStatistics();
void ResetStatistics();
void GetStatistics(uint32_t* stats);
private:
// 0 - kEmptyFrame
// 1 - kAudioFrameSpeech
@ -37,7 +38,6 @@ class ActivityMonitor : public ACMVADCallback {
uint32_t counter_[5];
};
// TestVadDtx is to verify that VAD/DTX perform as they should. It runs through
// an audio file and check if the occurrence of various packet types follows
// expectation. TestVadDtx needs its derived class to implement the Perform()
@ -65,8 +65,12 @@ class TestVadDtx : public ACMTest {
// 2 - kAudioFrameCN
// 3 - kVideoFrameKey (not used by audio)
// 4 - kVideoFrameDelta (not used by audio)
void Run(std::string in_filename, int frequency, int channels,
std::string out_filename, bool append, const int* expects);
void Run(std::string in_filename,
int frequency,
int channels,
std::string out_filename,
bool append,
const int* expects);
std::unique_ptr<AudioCodingModule> acm_send_;
std::unique_ptr<AudioCodingModule> acm_receive_;

View File

@ -115,7 +115,7 @@ TEST(AudioCodingModuleTest, TestPacketLossBurst) {
#if defined(WEBRTC_IOS)
TEST(AudioCodingModuleTest, DISABLED_TestPacketLossStereo) {
#else
TEST(AudioCodingModuleTest, TestPacketLossStereo) {
TEST(AudioCodingModuleTest, TestPacketLossStereo) {
#endif
webrtc::PacketLossTest(2, 10, 10, 1).Perform();
}
@ -128,3 +128,11 @@ TEST(AudioCodingModuleTest, TestPacketLossStereoBurst) {
#endif
webrtc::PacketLossTest(2, 10, 10, 2).Perform();
}
// The full API test is too long to run automatically on bots, but can be used
// for offline testing. User interaction is needed.
#ifdef ACM_TEST_FULL_API
TEST(AudioCodingModuleTest, TestAPI) {
webrtc::APITest().Perform();
}
#endif

View File

@ -60,8 +60,7 @@ TwoWayCommunication::~TwoWayCommunication() {
_outFileRefB.Close();
}
void TwoWayCommunication::ChooseCodec(uint8_t* codecID_A,
uint8_t* codecID_B) {
void TwoWayCommunication::ChooseCodec(uint8_t* codecID_A, uint8_t* codecID_B) {
std::unique_ptr<AudioCodingModule> tmpACM(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory())));
uint8_t noCodec = tmpACM->NumberOfCodecs();
@ -75,11 +74,11 @@ void TwoWayCommunication::ChooseCodec(uint8_t* codecID_A,
printf("\nChoose a send codec for side A [0]: ");
char myStr[15] = "";
EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL);
*codecID_A = (uint8_t) atoi(myStr);
*codecID_A = (uint8_t)atoi(myStr);
printf("\nChoose a send codec for side B [0]: ");
EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL);
*codecID_B = (uint8_t) atoi(myStr);
*codecID_B = (uint8_t)atoi(myStr);
printf("\n");
}
@ -118,8 +117,8 @@ void TwoWayCommunication::SetUp() {
uint16_t frequencyHz;
//--- Input A
std::string in_file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
std::string in_file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
frequencyHz = 32000;
printf("Enter input file at side A [%s]: ", in_file_name.c_str());
PCMFile::ChooseFile(&in_file_name, 499, &frequencyHz);
@ -134,8 +133,8 @@ void TwoWayCommunication::SetUp() {
_outFileRefA.Open(ref_file_name, frequencyHz, "wb");
//--- Input B
in_file_name = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
"pcm");
in_file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
frequencyHz = 32000;
printf("\n\nEnter input file at side B [%s]: ", in_file_name.c_str());
PCMFile::ChooseFile(&in_file_name, 499, &frequencyHz);
@ -200,8 +199,8 @@ void TwoWayCommunication::SetUpAutotest() {
uint16_t frequencyHz;
//--- Input A and B
std::string in_file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
std::string in_file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
frequencyHz = 16000;
_inFileA.Open(in_file_name, frequencyHz, "rb");
_inFileB.Open(in_file_name, frequencyHz, "rb");
@ -210,16 +209,16 @@ void TwoWayCommunication::SetUpAutotest() {
std::string output_file_a = webrtc::test::OutputPath() + "outAutotestA.pcm";
frequencyHz = 16000;
_outFileA.Open(output_file_a, frequencyHz, "wb");
std::string output_ref_file_a = webrtc::test::OutputPath()
+ "ref_outAutotestA.pcm";
std::string output_ref_file_a =
webrtc::test::OutputPath() + "ref_outAutotestA.pcm";
_outFileRefA.Open(output_ref_file_a, frequencyHz, "wb");
//--- Output B
std::string output_file_b = webrtc::test::OutputPath() + "outAutotestB.pcm";
frequencyHz = 16000;
_outFileB.Open(output_file_b, frequencyHz, "wb");
std::string output_ref_file_b = webrtc::test::OutputPath()
+ "ref_outAutotestB.pcm";
std::string output_ref_file_b =
webrtc::test::OutputPath() + "ref_outAutotestB.pcm";
_outFileRefB.Open(output_ref_file_b, frequencyHz, "wb");
//--- Set A-to-B channel

View File

@ -27,6 +27,7 @@ class TwoWayCommunication : public ACMTest {
~TwoWayCommunication();
void Perform();
private:
void ChooseCodec(uint8_t* codecID_A, uint8_t* codecID_B);
void SetUp();

View File

@ -83,26 +83,25 @@ class DelayTest {
void Initialize() {
test_cntr_ = 0;
std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
std::string file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
if (strlen(FLAG_input_file) > 0)
file_name = FLAG_input_file;
in_file_a_.Open(file_name, 32000, "rb");
ASSERT_EQ(0, acm_a_->InitializeReceiver()) <<
"Couldn't initialize receiver.\n";
ASSERT_EQ(0, acm_b_->InitializeReceiver()) <<
"Couldn't initialize receiver.\n";
ASSERT_EQ(0, acm_a_->InitializeReceiver())
<< "Couldn't initialize receiver.\n";
ASSERT_EQ(0, acm_b_->InitializeReceiver())
<< "Couldn't initialize receiver.\n";
if (FLAG_delay > 0) {
ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAG_delay)) <<
"Failed to set minimum delay.\n";
ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAG_delay))
<< "Failed to set minimum delay.\n";
}
int num_encoders = acm_a_->NumberOfCodecs();
CodecInst my_codec_param;
for (int n = 0; n < num_encoders; n++) {
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)) <<
"Failed to get codec.";
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)) << "Failed to get codec.";
if (STR_CASE_CMP(my_codec_param.plname, "opus") == 0)
my_codec_param.channels = 1;
else if (my_codec_param.channels > 1)
@ -118,12 +117,14 @@ class DelayTest {
}
// Create and connect the channel
ASSERT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_)) <<
"Couldn't register Transport callback.\n";
ASSERT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_))
<< "Couldn't register Transport callback.\n";
channel_a2b_->RegisterReceiverACM(acm_b_.get());
}
void Perform(const TestSettings* config, size_t num_tests, int duration_sec,
void Perform(const TestSettings* config,
size_t num_tests,
int duration_sec,
const char* output_prefix) {
for (size_t n = 0; n < num_tests; ++n) {
ApplyConfig(config[n]);
@ -134,14 +135,15 @@ class DelayTest {
private:
void ApplyConfig(const TestSettings& config) {
printf("====================================\n");
printf("Test %d \n"
"Codec: %s, %d kHz, %d channel(s)\n"
"ACM: DTX %s, FEC %s\n"
"Channel: %s\n",
++test_cntr_, config.codec.name, config.codec.sample_rate_hz,
config.codec.num_channels, config.acm.dtx ? "on" : "off",
config.acm.fec ? "on" : "off",
config.packet_loss ? "with packet-loss" : "no packet-loss");
printf(
"Test %d \n"
"Codec: %s, %d kHz, %d channel(s)\n"
"ACM: DTX %s, FEC %s\n"
"Channel: %s\n",
++test_cntr_, config.codec.name, config.codec.sample_rate_hz,
config.codec.num_channels, config.acm.dtx ? "on" : "off",
config.acm.fec ? "on" : "off",
config.packet_loss ? "with packet-loss" : "no packet-loss");
SendCodec(config.codec);
ConfigAcm(config.acm);
ConfigChannel(config.packet_loss);
@ -149,20 +151,20 @@ class DelayTest {
void SendCodec(const CodecSettings& config) {
CodecInst my_codec_param;
ASSERT_EQ(0, AudioCodingModule::Codec(
config.name, &my_codec_param, config.sample_rate_hz,
config.num_channels)) << "Specified codec is not supported.\n";
ASSERT_EQ(
0, AudioCodingModule::Codec(config.name, &my_codec_param,
config.sample_rate_hz, config.num_channels))
<< "Specified codec is not supported.\n";
encoding_sample_rate_hz_ = my_codec_param.plfreq;
ASSERT_EQ(0, acm_a_->RegisterSendCodec(my_codec_param)) <<
"Failed to register send-codec.\n";
ASSERT_EQ(0, acm_a_->RegisterSendCodec(my_codec_param))
<< "Failed to register send-codec.\n";
}
void ConfigAcm(const AcmSettings& config) {
ASSERT_EQ(0, acm_a_->SetVAD(config.dtx, config.dtx, VADAggr)) <<
"Failed to set VAD.\n";
ASSERT_EQ(0, acm_a_->SetREDStatus(config.fec)) <<
"Failed to set RED.\n";
ASSERT_EQ(0, acm_a_->SetVAD(config.dtx, config.dtx, VADAggr))
<< "Failed to set VAD.\n";
ASSERT_EQ(0, acm_a_->SetREDStatus(config.fec)) << "Failed to set RED.\n";
}
void ConfigChannel(bool packet_loss) {
@ -172,7 +174,8 @@ class DelayTest {
void OpenOutFile(const char* output_id) {
std::stringstream file_stream;
file_stream << "delay_test_" << FLAG_codec << "_" << FLAG_sample_rate_hz
<< "Hz" << "_" << FLAG_delay << "ms.pcm";
<< "Hz"
<< "_" << FLAG_delay << "ms.pcm";
std::cout << "Output file: " << file_stream.str() << std::endl << std::endl;
std::string file_name = webrtc::test::OutputPath() + file_stream.str();
out_file_b_.Open(file_name.c_str(), 32000, "wb");
@ -197,14 +200,15 @@ class DelayTest {
if ((num_frames & 0x3F) == 0x3F) {
NetworkStatistics statistics;
acm_b_->GetNetworkStatistics(&statistics);
fprintf(stdout, "delay: min=%3d max=%3d mean=%3d median=%3d"
fprintf(stdout,
"delay: min=%3d max=%3d mean=%3d median=%3d"
" ts-based average = %6.3f, "
"curr buff-lev = %4u opt buff-lev = %4u \n",
statistics.minWaitingTimeMs, statistics.maxWaitingTimeMs,
statistics.meanWaitingTimeMs, statistics.medianWaitingTimeMs,
average_delay, statistics.currentBufferSize,
statistics.preferredBufferSize);
fflush (stdout);
fflush(stdout);
}
in_file_a_.Read10MsData(audio_frame);
@ -256,10 +260,8 @@ int main(int argc, char* argv[]) {
webrtc::TestSettings test_setting;
strcpy(test_setting.codec.name, FLAG_codec);
if (FLAG_sample_rate_hz != 8000 &&
FLAG_sample_rate_hz != 16000 &&
FLAG_sample_rate_hz != 32000 &&
FLAG_sample_rate_hz != 48000) {
if (FLAG_sample_rate_hz != 8000 && FLAG_sample_rate_hz != 16000 &&
FLAG_sample_rate_hz != 32000 && FLAG_sample_rate_hz != 48000) {
std::cout << "Invalid sampling rate.\n";
return 1;
}

View File

@ -41,11 +41,11 @@ void SetISACConfigDefault(ACMTestISACConfig& isacConfig) {
return;
}
int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm,
int16_t SetISAConfig(ACMTestISACConfig& isacConfig,
AudioCodingModule* acm,
int testMode) {
if ((isacConfig.currentRateBitPerSec != 0)
|| (isacConfig.currentFrameSizeMsec != 0)) {
if ((isacConfig.currentRateBitPerSec != 0) ||
(isacConfig.currentFrameSizeMsec != 0)) {
auto sendCodec = acm->SendCodec();
EXPECT_TRUE(sendCodec);
if (isacConfig.currentRateBitPerSec < 0) {
@ -57,8 +57,8 @@ int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm,
sendCodec->rate = isacConfig.currentRateBitPerSec;
}
if (isacConfig.currentFrameSizeMsec != 0) {
sendCodec->pacsize = isacConfig.currentFrameSizeMsec
* (sendCodec->plfreq / 1000);
sendCodec->pacsize =
isacConfig.currentFrameSizeMsec * (sendCodec->plfreq / 1000);
}
EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec));
}
@ -81,15 +81,15 @@ void ISACTest::Setup() {
CodecInst codecParam;
for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
codecCntr++) {
codecCntr++) {
EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam));
if (!STR_CASE_CMP(codecParam.plname, "ISAC")
&& codecParam.plfreq == 16000) {
if (!STR_CASE_CMP(codecParam.plname, "ISAC") &&
codecParam.plfreq == 16000) {
memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
_idISAC16kHz = codecCntr;
}
if (!STR_CASE_CMP(codecParam.plname, "ISAC")
&& codecParam.plfreq == 32000) {
if (!STR_CASE_CMP(codecParam.plname, "ISAC") &&
codecParam.plfreq == 32000) {
memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
_idISAC32kHz = codecCntr;
}
@ -115,8 +115,8 @@ void ISACTest::Setup() {
EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get()));
_channel_B2A->RegisterReceiverACM(_acmA.get());
file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
"pcm");
file_name_swb_ =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
@ -213,7 +213,8 @@ void ISACTest::Run10ms() {
_outFileB.Write10MsData(audioFrame);
}
void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
void ISACTest::EncodeDecode(int testNr,
ACMTestISACConfig& wbISACConfig,
ACMTestISACConfig& swbISACConfig) {
// Files in Side A and B
_inFileA.Open(file_name_swb_, 32000, "rb", true);
@ -241,8 +242,8 @@ void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
SetISAConfig(wbISACConfig, _acmB.get(), _testMode);
bool adaptiveMode = false;
if ((swbISACConfig.currentRateBitPerSec == -1)
|| (wbISACConfig.currentRateBitPerSec == -1)) {
if ((swbISACConfig.currentRateBitPerSec == -1) ||
(wbISACConfig.currentRateBitPerSec == -1)) {
adaptiveMode = true;
}
_myTimer.Reset();

View File

@ -23,7 +23,7 @@
#include "modules/audio_coding/test/utility.h"
#define MAX_FILE_NAME_LENGTH_BYTE 500
#define NO_OF_CLIENTS 15
#define NO_OF_CLIENTS 15
namespace webrtc {
@ -42,12 +42,14 @@ class ISACTest : public ACMTest {
~ISACTest();
void Perform();
private:
void Setup();
void Run10ms();
void EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
void EncodeDecode(int testNr,
ACMTestISACConfig& wbISACConfig,
ACMTestISACConfig& swbISACConfig);
void SwitchingSamplingRate(int testNr, int maxSampRateChange);

View File

@ -211,8 +211,11 @@ void OpusTest::Perform() {
#endif
}
void OpusTest::Run(TestPackStereo* channel, size_t channels, int bitrate,
size_t frame_length, int percent_loss) {
void OpusTest::Run(TestPackStereo* channel,
size_t channels,
int bitrate,
size_t frame_length,
int percent_loss) {
AudioFrame audio_frame;
int32_t out_freq_hz_b = out_file_.SamplingFrequency();
const size_t kBufferSizeSamples = 480 * 12 * 2; // 120 ms stereo audio.
@ -237,8 +240,8 @@ void OpusTest::Run(TestPackStereo* channel, size_t channels, int bitrate,
// default.
const int kOpusComplexity5 = 5;
EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_mono_encoder_, kOpusComplexity5));
EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_stereo_encoder_,
kOpusComplexity5));
EXPECT_EQ(0,
WebRtcOpus_SetComplexity(opus_stereo_encoder_, kOpusComplexity5));
#endif
// Fast-forward 1 second (100 blocks) since the files start with silence.
@ -263,19 +266,16 @@ void OpusTest::Run(TestPackStereo* channel, size_t channels, int bitrate,
}
// If input audio is sampled at 32 kHz, resampling to 48 kHz is required.
EXPECT_EQ(480,
resampler_.Resample10Msec(audio_frame.data(),
audio_frame.sample_rate_hz_,
48000,
channels,
kBufferSizeSamples - written_samples,
&audio[written_samples]));
EXPECT_EQ(480, resampler_.Resample10Msec(
audio_frame.data(), audio_frame.sample_rate_hz_, 48000,
channels, kBufferSizeSamples - written_samples,
&audio[written_samples]));
written_samples += 480 * channels;
// Sometimes we need to loop over the audio vector to produce the right
// number of packets.
size_t loop_encode = (written_samples - read_samples) /
(channels * frame_length);
size_t loop_encode =
(written_samples - read_samples) / (channels * frame_length);
if (loop_encode > 0) {
const size_t kMaxBytes = 1000; // Maximum number of bytes for one packet.
@ -319,9 +319,9 @@ void OpusTest::Run(TestPackStereo* channel, size_t channels, int bitrate,
opus_stereo_decoder_, bitstream, bitstream_len_byte,
&out_audio[decoded_samples * channels], &audio_type);
} else {
decoded_samples += WebRtcOpus_DecodePlc(
opus_stereo_decoder_, &out_audio[decoded_samples * channels],
1);
decoded_samples +=
WebRtcOpus_DecodePlc(opus_stereo_decoder_,
&out_audio[decoded_samples * channels], 1);
}
}
@ -377,14 +377,14 @@ void OpusTest::Run(TestPackStereo* channel, size_t channels, int bitrate,
void OpusTest::OpenOutFile(int test_number) {
std::string file_name;
std::stringstream file_stream;
file_stream << webrtc::test::OutputPath() << "opustest_out_"
<< test_number << ".pcm";
file_stream << webrtc::test::OutputPath() << "opustest_out_" << test_number
<< ".pcm";
file_name = file_stream.str();
out_file_.Open(file_name, 48000, "wb");
file_stream.str("");
file_name = file_stream.str();
file_stream << webrtc::test::OutputPath() << "opusstandalone_out_"
<< test_number << ".pcm";
<< test_number << ".pcm";
file_name = file_stream.str();
out_file_standalone_.Open(file_name, 48000, "wb");
}

View File

@ -15,8 +15,8 @@
#include <memory>
#include "modules/audio_coding/codecs/opus/opus_interface.h"
#include "modules/audio_coding/acm2/acm_resampler.h"
#include "modules/audio_coding/codecs/opus/opus_interface.h"
#include "modules/audio_coding/test/ACMTest.h"
#include "modules/audio_coding/test/Channel.h"
#include "modules/audio_coding/test/PCMFile.h"

View File

@ -73,8 +73,8 @@ class TargetDelayTest : public ::testing::Test {
void WithTargetDelayBufferNotChanging() {
// A target delay that is one packet larger than jitter.
const int kTargetDelayMs = (kInterarrivalJitterPacket + 1) *
kNum10msPerFrame * 10;
const int kTargetDelayMs =
(kInterarrivalJitterPacket + 1) * kNum10msPerFrame * 10;
ASSERT_EQ(0, SetMinimumDelay(kTargetDelayMs));
for (int n = 0; n < 30; ++n) // Run enough iterations to fill the buffer.
Run(true);
@ -91,8 +91,8 @@ class TargetDelayTest : public ::testing::Test {
int clean_optimal_delay = GetCurrentOptimalDelayMs();
// A relatively large delay.
const int kTargetDelayMs = (kInterarrivalJitterPacket + 10) *
kNum10msPerFrame * 10;
const int kTargetDelayMs =
(kInterarrivalJitterPacket + 10) * kNum10msPerFrame * 10;
ASSERT_EQ(0, SetMinimumDelay(kTargetDelayMs));
for (int n = 0; n < 300; ++n) // Run enough iterations to fill the buffer.
Run(true);
@ -146,8 +146,8 @@ class TargetDelayTest : public ::testing::Test {
void Push() {
rtp_info_.header.timestamp += kFrameSizeSamples;
rtp_info_.header.sequenceNumber++;
ASSERT_EQ(0, acm_->IncomingPacket(payload_, kFrameSizeSamples * 2,
rtp_info_));
ASSERT_EQ(0,
acm_->IncomingPacket(payload_, kFrameSizeSamples * 2, rtp_info_));
}
// Pull audio equivalent to the amount of audio in one RTP packet.
@ -195,9 +195,7 @@ class TargetDelayTest : public ::testing::Test {
return stats.preferredBufferSize;
}
int RequiredDelay() {
return acm_->LeastRequiredDelayMs();
}
int RequiredDelay() { return acm_->LeastRequiredDelayMs(); }
std::unique_ptr<AudioCodingModule> acm_;
WebRtcRTPHeader rtp_info_;

View File

@ -23,11 +23,7 @@
namespace webrtc {
ACMTestTimer::ACMTestTimer()
: _msec(0),
_sec(0),
_min(0),
_hour(0) {
ACMTestTimer::ACMTestTimer() : _msec(0), _sec(0), _min(0), _hour(0) {
return;
}
@ -68,12 +64,14 @@ void ACMTestTimer::Tick1sec() {
void ACMTestTimer::CurrentTimeHMS(char* currTime) {
sprintf(currTime, "%4lu:%02u:%06.3f", _hour, _min,
(double) _sec + (double) _msec / 1000.);
(double)_sec + (double)_msec / 1000.);
return;
}
void ACMTestTimer::CurrentTime(unsigned long& h, unsigned char& m,
unsigned char& s, unsigned short& ms) {
void ACMTestTimer::CurrentTime(unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms) {
h = _hour;
m = _min;
s = _sec;
@ -101,9 +99,8 @@ void ACMTestTimer::Adjust() {
}
int16_t ChooseCodec(CodecInst& codecInst) {
PrintCodecs();
//AudioCodingModule* tmpACM = AudioCodingModule::Create(0);
// AudioCodingModule* tmpACM = AudioCodingModule::Create(0);
uint8_t noCodec = AudioCodingModule::NumberOfCodecs();
int8_t codecID;
bool outOfRange = false;
@ -118,7 +115,7 @@ int16_t ChooseCodec(CodecInst& codecInst) {
}
} while (outOfRange);
CHECK_ERROR(AudioCodingModule::Codec((uint8_t )codecID, &codecInst));
CHECK_ERROR(AudioCodingModule::Codec((uint8_t)codecID, &codecInst));
return 0;
}
@ -132,7 +129,6 @@ void PrintCodecs() {
printf("%2d- %-18s %5d %6d\n", codecCntr, codecInst.plname,
codecInst.plfreq, codecInst.rate);
}
}
namespace test {
@ -192,7 +188,7 @@ void CircularBuffer::Update(const double newVal) {
if (_calcVar) {
// to calculate variance we have to update
// the sum of squares
_sumSqr += (double) (newVal - oldVal) * (double) (newVal + oldVal);
_sumSqr += (double)(newVal - oldVal) * (double)(newVal + oldVal);
}
}
@ -236,17 +232,15 @@ int16_t CircularBuffer::ArithMean(double& mean) {
assert(_buffLen > 0);
if (_buffIsFull) {
mean = _sum / (double) _buffLen;
mean = _sum / (double)_buffLen;
return 0;
} else {
if (_idx > 0) {
mean = _sum / (double) _idx;
mean = _sum / (double)_idx;
return 0;
} else {
return -1;
}
}
}
@ -254,11 +248,11 @@ int16_t CircularBuffer::Variance(double& var) {
assert(_buffLen > 0);
if (_buffIsFull) {
var = _sumSqr / (double) _buffLen;
var = _sumSqr / (double)_buffLen;
return 0;
} else {
if (_idx > 0) {
var = _sumSqr / (double) _idx;
var = _sumSqr / (double)_idx;
return 0;
} else {
return -1;
@ -269,9 +263,9 @@ int16_t CircularBuffer::Variance(double& var) {
} // namespace test
bool FixedPayloadTypeCodec(const char* payloadName) {
char fixPayloadTypeCodecs[NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE][32] = { "PCMU",
"PCMA", "GSM", "G723", "DVI4", "LPC", "PCMA", "G722", "QCELP", "CN",
"MPA", "G728", "G729" };
char fixPayloadTypeCodecs[NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE][32] = {
"PCMU", "PCMA", "GSM", "G723", "DVI4", "LPC", "PCMA",
"G722", "QCELP", "CN", "MPA", "G728", "G729"};
for (int n = 0; n < NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE; n++) {
if (!STR_CASE_CMP(payloadName, fixPayloadTypeCodecs[n])) {

View File

@ -17,48 +17,48 @@
namespace webrtc {
//-----------------------------
#define CHECK_ERROR(f) \
do { \
EXPECT_GE(f, 0) << "Error Calling API"; \
} while(0)
#define CHECK_ERROR(f) \
do { \
EXPECT_GE(f, 0) << "Error Calling API"; \
} while (0)
//-----------------------------
#define CHECK_PROTECTED(f) \
do { \
if (f >= 0) { \
ADD_FAILURE() << "Error Calling API"; \
} else { \
printf("An expected error is caught.\n"); \
} \
} while(0)
#define CHECK_PROTECTED(f) \
do { \
if (f >= 0) { \
ADD_FAILURE() << "Error Calling API"; \
} else { \
printf("An expected error is caught.\n"); \
} \
} while (0)
//----------------------------
#define CHECK_ERROR_MT(f) \
do { \
if (f < 0) { \
fprintf(stderr, "Error Calling API in file %s at line %d \n", \
__FILE__, __LINE__); \
} \
} while(0)
#define CHECK_ERROR_MT(f) \
do { \
if (f < 0) { \
fprintf(stderr, "Error Calling API in file %s at line %d \n", __FILE__, \
__LINE__); \
} \
} while (0)
//----------------------------
#define CHECK_PROTECTED_MT(f) \
do { \
if (f >= 0) { \
fprintf(stderr, "Error Calling API in file %s at line %d \n", \
__FILE__, __LINE__); \
} else { \
printf("An expected error is caught.\n"); \
} \
} while(0)
#define CHECK_PROTECTED_MT(f) \
do { \
if (f >= 0) { \
fprintf(stderr, "Error Calling API in file %s at line %d \n", __FILE__, \
__LINE__); \
} else { \
printf("An expected error is caught.\n"); \
} \
} while (0)
#define DELETE_POINTER(p) \
do { \
if (p != NULL) { \
delete p; \
p = NULL; \
} \
} while(0)
#define DELETE_POINTER(p) \
do { \
if (p != NULL) { \
delete p; \
p = NULL; \
} \
} while (0)
class ACMTestTimer {
public:
@ -71,7 +71,9 @@ class ACMTestTimer {
void Tick100ms();
void Tick1sec();
void CurrentTimeHMS(char* currTime);
void CurrentTime(unsigned long& h, unsigned char& m, unsigned char& s,
void CurrentTime(unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms);
private: