Formatting ACM tests

Pure formatting of all files located in /webrtc/modules/audio_coding/main/test/

Smaller manual modifications done after using Eclipse formatting tool, like wrapping long lines (mostly comments).

BUG=issue1024

Review URL: https://webrtc-codereview.appspot.com/1342004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3946 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tina.legrand@webrtc.org 2013-05-03 07:34:12 +00:00
parent 03efc89151
commit d5726a1286
34 changed files with 4385 additions and 5230 deletions

View File

@ -10,7 +10,5 @@
#include "ACMTest.h"
ACMTest::~ACMTest()
{
}
ACMTest::~ACMTest() {}

View File

@ -11,11 +11,10 @@
#ifndef ACMTEST_H
#define ACMTEST_H
class ACMTest
{
public:
virtual ~ACMTest() =0;
virtual void Perform() =0;
class ACMTest {
public:
virtual ~ACMTest() = 0;
virtual void Perform() = 0;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -19,155 +19,154 @@
namespace webrtc {
enum APITESTAction {TEST_CHANGE_CODEC_ONLY = 0, DTX_TEST = 1};
class APITest : public ACMTest
{
public:
APITest();
~APITest();
void Perform();
private:
int16_t SetUp();
static bool PushAudioThreadA(void* obj);
static bool PullAudioThreadA(void* obj);
static bool ProcessThreadA(void* obj);
static bool APIThreadA(void* obj);
static bool PushAudioThreadB(void* obj);
static bool PullAudioThreadB(void* obj);
static bool ProcessThreadB(void* obj);
static bool APIThreadB(void* obj);
void CheckVADStatus(char side);
// Set Min delay, get delay, playout timestamp
void TestDelay(char side);
// Unregister a codec & register again.
void TestRegisteration(char side);
// Playout Mode, background noise mode.
// Receiver Frequency, playout frequency.
void TestPlayout(char receiveSide);
// set/get receiver VAD status & mode.
void TestReceiverVAD(char side);
//
void TestSendVAD(char side);
void CurrentCodec(char side);
void ChangeCodec(char side);
void Wait(uint32_t waitLengthMs);
void LookForDTMF(char side);
void RunTest(char thread);
bool PushAudioRunA();
bool PullAudioRunA();
bool ProcessRunA();
bool APIRunA();
bool PullAudioRunB();
bool PushAudioRunB();
bool ProcessRunB();
bool APIRunB();
//--- ACMs
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
//--- Channels
Channel* _channel_A2B;
Channel* _channel_B2A;
//--- I/O files
// A
PCMFile _inFileA;
PCMFile _outFileA;
// B
PCMFile _outFileB;
PCMFile _inFileB;
//--- I/O params
// A
int32_t _outFreqHzA;
// B
int32_t _outFreqHzB;
// Should we write to file.
// we might skip writing to file if we
// run the test for a long time.
bool _writeToFile;
//--- Events
// A
EventWrapper* _pullEventA; // pulling data from ACM
EventWrapper* _pushEventA; // pushing data to ACM
EventWrapper* _processEventA; // process
EventWrapper* _apiEventA; // API calls
// B
EventWrapper* _pullEventB; // pulling data from ACM
EventWrapper* _pushEventB; // pushing data to ACM
EventWrapper* _processEventB; // process
EventWrapper* _apiEventB; // API calls
// keep track of the codec in either side.
uint8_t _codecCntrA;
uint8_t _codecCntrB;
// Is set to true if there is no encoder in either side
bool _thereIsEncoderA;
bool _thereIsEncoderB;
bool _thereIsDecoderA;
bool _thereIsDecoderB;
bool _sendVADA;
bool _sendDTXA;
ACMVADMode _sendVADModeA;
bool _sendVADB;
bool _sendDTXB;
ACMVADMode _sendVADModeB;
int32_t _minDelayA;
int32_t _minDelayB;
bool _payloadUsed[32];
AudioPlayoutMode _playoutModeA;
AudioPlayoutMode _playoutModeB;
ACMBackgroundNoiseMode _bgnModeA;
ACMBackgroundNoiseMode _bgnModeB;
int _receiveVADActivityA[3];
int _receiveVADActivityB[3];
bool _verbose;
int _dotPositionA;
int _dotMoveDirectionA;
int _dotPositionB;
int _dotMoveDirectionB;
char _movingDot[41];
DTMFDetector* _dtmfCallback;
VADCallback* _vadCallbackA;
VADCallback* _vadCallbackB;
RWLockWrapper& _apiTestRWLock;
bool _randomTest;
int _testNumA;
int _testNumB;
enum APITESTAction {
TEST_CHANGE_CODEC_ONLY = 0,
DTX_TEST = 1
};
} // namespace webrtc
class APITest : public ACMTest {
public:
APITest();
~APITest();
void Perform();
private:
int16_t SetUp();
static bool PushAudioThreadA(void* obj);
static bool PullAudioThreadA(void* obj);
static bool ProcessThreadA(void* obj);
static bool APIThreadA(void* obj);
static bool PushAudioThreadB(void* obj);
static bool PullAudioThreadB(void* obj);
static bool ProcessThreadB(void* obj);
static bool APIThreadB(void* obj);
void CheckVADStatus(char side);
// Set Min delay, get delay, playout timestamp
void TestDelay(char side);
// Unregister a codec & register again.
void TestRegisteration(char side);
// Playout Mode, background noise mode.
// Receiver Frequency, playout frequency.
void TestPlayout(char receiveSide);
// set/get receiver VAD status & mode.
void TestReceiverVAD(char side);
//
void TestSendVAD(char side);
void CurrentCodec(char side);
void ChangeCodec(char side);
void Wait(uint32_t waitLengthMs);
void LookForDTMF(char side);
void RunTest(char thread);
bool PushAudioRunA();
bool PullAudioRunA();
bool ProcessRunA();
bool APIRunA();
bool PullAudioRunB();
bool PushAudioRunB();
bool ProcessRunB();
bool APIRunB();
//--- ACMs
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
//--- Channels
Channel* _channel_A2B;
Channel* _channel_B2A;
//--- I/O files
// A
PCMFile _inFileA;
PCMFile _outFileA;
// B
PCMFile _outFileB;
PCMFile _inFileB;
//--- I/O params
// A
int32_t _outFreqHzA;
// B
int32_t _outFreqHzB;
// Should we write to file.
// we might skip writing to file if we
// run the test for a long time.
bool _writeToFile;
//--- Events
// A
EventWrapper* _pullEventA; // pulling data from ACM
EventWrapper* _pushEventA; // pushing data to ACM
EventWrapper* _processEventA; // process
EventWrapper* _apiEventA; // API calls
// B
EventWrapper* _pullEventB; // pulling data from ACM
EventWrapper* _pushEventB; // pushing data to ACM
EventWrapper* _processEventB; // process
EventWrapper* _apiEventB; // API calls
// keep track of the codec in either side.
uint8_t _codecCntrA;
uint8_t _codecCntrB;
// Is set to true if there is no encoder in either side
bool _thereIsEncoderA;
bool _thereIsEncoderB;
bool _thereIsDecoderA;
bool _thereIsDecoderB;
bool _sendVADA;
bool _sendDTXA;
ACMVADMode _sendVADModeA;
bool _sendVADB;
bool _sendDTXB;
ACMVADMode _sendVADModeB;
int32_t _minDelayA;
int32_t _minDelayB;
bool _payloadUsed[32];
AudioPlayoutMode _playoutModeA;
AudioPlayoutMode _playoutModeB;
ACMBackgroundNoiseMode _bgnModeA;
ACMBackgroundNoiseMode _bgnModeB;
int _receiveVADActivityA[3];
int _receiveVADActivityB[3];
bool _verbose;
int _dotPositionA;
int _dotMoveDirectionA;
int _dotPositionB;
int _dotMoveDirectionB;
char _movingDot[41];
DTMFDetector* _dtmfCallback;
VADCallback* _vadCallbackA;
VADCallback* _vadCallbackB;
RWLockWrapper& _apiTestRWLock;
bool _randomTest;
int _testNumA;
int _testNumB;
};
} // namespace webrtc
#endif

View File

@ -19,459 +19,374 @@
namespace webrtc {
int32_t
Channel::SendData(
const FrameType frameType,
const uint8_t payloadType,
const uint32_t timeStamp,
const uint8_t* payloadData,
const uint16_t payloadSize,
const RTPFragmentationHeader* fragmentation)
{
WebRtcRTPHeader rtpInfo;
int32_t status;
uint16_t payloadDataSize = payloadSize;
int32_t Channel::SendData(const FrameType frameType, const uint8_t payloadType,
const uint32_t timeStamp, const uint8_t* payloadData,
const uint16_t payloadSize,
const RTPFragmentationHeader* fragmentation) {
WebRtcRTPHeader rtpInfo;
int32_t status;
uint16_t payloadDataSize = payloadSize;
rtpInfo.header.markerBit = false;
rtpInfo.header.ssrc = 0;
rtpInfo.header.sequenceNumber = _seqNo++;
rtpInfo.header.payloadType = payloadType;
rtpInfo.header.timestamp = timeStamp;
if(frameType == kAudioFrameCN)
{
rtpInfo.type.Audio.isCNG = true;
}
else
{
rtpInfo.type.Audio.isCNG = false;
}
if(frameType == kFrameEmpty)
{
// Skip this frame
return 0;
}
rtpInfo.type.Audio.channel = 1;
// Treat fragmentation separately
if(fragmentation != NULL)
{
if((fragmentation->fragmentationTimeDiff[1] <= 0x3fff) && // silence for too long send only new data
(fragmentation->fragmentationVectorSize == 2))
{
// only 0x80 if we have multiple blocks
_payloadData[0] = 0x80 + fragmentation->fragmentationPlType[1];
uint32_t REDheader = (((uint32_t)fragmentation->fragmentationTimeDiff[1]) << 10) + fragmentation->fragmentationLength[1];
_payloadData[1] = uint8_t((REDheader >> 16) & 0x000000FF);
_payloadData[2] = uint8_t((REDheader >> 8) & 0x000000FF);
_payloadData[3] = uint8_t(REDheader & 0x000000FF);
_payloadData[4] = fragmentation->fragmentationPlType[0];
// copy the RED data
memcpy(_payloadData + 5,
payloadData + fragmentation->fragmentationOffset[1],
fragmentation->fragmentationLength[1]);
// copy the normal data
memcpy(_payloadData + 5 + fragmentation->fragmentationLength[1],
payloadData + fragmentation->fragmentationOffset[0],
fragmentation->fragmentationLength[0]);
payloadDataSize += 5;
} else
{
// single block (newest one)
memcpy(_payloadData,
payloadData + fragmentation->fragmentationOffset[0],
fragmentation->fragmentationLength[0]);
payloadDataSize = uint16_t(fragmentation->fragmentationLength[0]);
rtpInfo.header.payloadType = fragmentation->fragmentationPlType[0];
}
}
else
{
memcpy(_payloadData, payloadData, payloadDataSize);
if(_isStereo)
{
if(_leftChannel)
{
memcpy(&_rtpInfo, &rtpInfo, sizeof(WebRtcRTPHeader));
_leftChannel = false;
rtpInfo.type.Audio.channel = 1;
}
else
{
memcpy(&rtpInfo, &_rtpInfo, sizeof(WebRtcRTPHeader));
_leftChannel = true;
rtpInfo.type.Audio.channel = 2;
}
}
}
_channelCritSect->Enter();
if(_saveBitStream)
{
//fwrite(payloadData, sizeof(uint8_t), payloadSize, _bitStreamFile);
}
if(!_isStereo)
{
CalcStatistics(rtpInfo, payloadSize);
}
_lastInTimestamp = timeStamp;
_totalBytes += payloadDataSize;
_channelCritSect->Leave();
if(_useFECTestWithPacketLoss)
{
_packetLoss += 1;
if(_packetLoss == 3)
{
_packetLoss = 0;
return 0;
}
}
status = _receiverACM->IncomingPacket(_payloadData, payloadDataSize,
rtpInfo);
return status;
}
void
Channel::CalcStatistics(
WebRtcRTPHeader& rtpInfo,
uint16_t payloadSize)
{
int n;
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
// easier.
for(n = 0; n < MAX_NUM_PAYLOADS; n++)
{
if(_lastPayloadType == _payloadStats[n].payloadType)
{
_payloadStats[n].newPacket = true;
break;
}
}
}
_lastPayloadType = rtpInfo.header.payloadType;
bool newPayload = true;
ACMTestPayloadStats* currentPayloadStr = NULL;
for(n = 0; n < MAX_NUM_PAYLOADS; n++)
{
if(rtpInfo.header.payloadType == _payloadStats[n].payloadType)
{
newPayload = false;
currentPayloadStr = &_payloadStats[n];
break;
}
}
if(!newPayload)
{
if(!currentPayloadStr->newPacket)
{
uint32_t lastFrameSizeSample = (uint32_t)((uint32_t)rtpInfo.header.timestamp -
(uint32_t)currentPayloadStr->lastTimestamp);
assert(lastFrameSizeSample > 0);
int k = 0;
while((currentPayloadStr->frameSizeStats[k].frameSizeSample !=
lastFrameSizeSample) &&
(currentPayloadStr->frameSizeStats[k].frameSizeSample != 0))
{
k++;
}
ACMTestFrameSizeStats* currentFrameSizeStats =
&(currentPayloadStr->frameSizeStats[k]);
currentFrameSizeStats->frameSizeSample = (int16_t)lastFrameSizeSample;
// increment the number of encoded samples.
currentFrameSizeStats->totalEncodedSamples +=
lastFrameSizeSample;
// increment the number of recveived packets
currentFrameSizeStats->numPackets++;
// 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;
// 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;
}
// store the current values for the next time
currentPayloadStr->lastTimestamp = rtpInfo.header.timestamp;
currentPayloadStr->lastPayloadLenByte = payloadSize;
}
else
{
currentPayloadStr->newPacket = false;
currentPayloadStr->lastPayloadLenByte = payloadSize;
currentPayloadStr->lastTimestamp = rtpInfo.header.timestamp;
currentPayloadStr->payloadType = rtpInfo.header.payloadType;
}
}
else
{
n = 0;
while(_payloadStats[n].payloadType != -1)
{
n++;
}
// first packet
_payloadStats[n].newPacket = false;
_payloadStats[n].lastPayloadLenByte = payloadSize;
_payloadStats[n].lastTimestamp = rtpInfo.header.timestamp;
_payloadStats[n].payloadType = rtpInfo.header.payloadType;
}
}
Channel::Channel(int16_t chID) :
_receiverACM(NULL),
_seqNo(0),
_channelCritSect(CriticalSectionWrapper::CreateCriticalSection()),
_bitStreamFile(NULL),
_saveBitStream(false),
_lastPayloadType(-1),
_isStereo(false),
_leftChannel(true),
_lastInTimestamp(0),
_packetLoss(0),
_useFECTestWithPacketLoss(false),
_beginTime(TickTime::MillisecondTimestamp()),
_totalBytes(0)
{
int n;
int k;
for(n = 0; n < MAX_NUM_PAYLOADS; n++)
{
_payloadStats[n].payloadType = -1;
_payloadStats[n].newPacket = true;
for(k = 0; k < MAX_NUM_FRAMESIZES; k++)
{
_payloadStats[n].frameSizeStats[k].frameSizeSample = 0;
_payloadStats[n].frameSizeStats[k].maxPayloadLen = 0;
_payloadStats[n].frameSizeStats[k].numPackets = 0;
_payloadStats[n].frameSizeStats[k].totalPayloadLenByte = 0;
_payloadStats[n].frameSizeStats[k].totalEncodedSamples = 0;
}
}
if(chID >= 0)
{
_saveBitStream = true;
char bitStreamFileName[500];
sprintf(bitStreamFileName, "bitStream_%d.dat", chID);
_bitStreamFile = fopen(bitStreamFileName, "wb");
}
else
{
_saveBitStream = false;
}
}
Channel::~Channel()
{
delete _channelCritSect;
}
void
Channel::RegisterReceiverACM(AudioCodingModule* acm)
{
_receiverACM = acm;
return;
}
void
Channel::ResetStats()
{
int n;
int k;
_channelCritSect->Enter();
_lastPayloadType = -1;
for(n = 0; n < MAX_NUM_PAYLOADS; n++)
{
_payloadStats[n].payloadType = -1;
_payloadStats[n].newPacket = true;
for(k = 0; k < MAX_NUM_FRAMESIZES; k++)
{
_payloadStats[n].frameSizeStats[k].frameSizeSample = 0;
_payloadStats[n].frameSizeStats[k].maxPayloadLen = 0;
_payloadStats[n].frameSizeStats[k].numPackets = 0;
_payloadStats[n].frameSizeStats[k].totalPayloadLenByte = 0;
_payloadStats[n].frameSizeStats[k].totalEncodedSamples = 0;
}
}
_beginTime = TickTime::MillisecondTimestamp();
_totalBytes = 0;
_channelCritSect->Leave();
}
int16_t
Channel::Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats)
{
_channelCritSect->Enter();
int n;
payloadStats.payloadType = -1;
for(n = 0; n < MAX_NUM_PAYLOADS; n++)
{
if(_payloadStats[n].payloadType == codecInst.pltype)
{
memcpy(&payloadStats, &_payloadStats[n], sizeof(ACMTestPayloadStats));
break;
}
}
if(payloadStats.payloadType == -1)
{
_channelCritSect->Leave();
return -1;
}
for(n = 0; n < MAX_NUM_FRAMESIZES; n++)
{
if(payloadStats.frameSizeStats[n].frameSizeSample == 0)
{
_channelCritSect->Leave();
return 0;
}
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;
}
_channelCritSect->Leave();
rtpInfo.header.markerBit = false;
rtpInfo.header.ssrc = 0;
rtpInfo.header.sequenceNumber = _seqNo++;
rtpInfo.header.payloadType = payloadType;
rtpInfo.header.timestamp = timeStamp;
if (frameType == kAudioFrameCN) {
rtpInfo.type.Audio.isCNG = true;
} else {
rtpInfo.type.Audio.isCNG = false;
}
if (frameType == kFrameEmpty) {
// Skip this frame
return 0;
}
}
void
Channel::Stats(uint32_t* numPackets)
{
_channelCritSect->Enter();
int k;
int n;
memset(numPackets, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t));
for(k = 0; k < MAX_NUM_PAYLOADS; k++)
{
if(_payloadStats[k].payloadType == -1)
{
break;
}
numPackets[k] = 0;
for(n = 0; n < MAX_NUM_FRAMESIZES; n++)
{
if(_payloadStats[k].frameSizeStats[n].frameSizeSample == 0)
{
break;
}
numPackets[k] +=
_payloadStats[k].frameSizeStats[n].numPackets;
}
rtpInfo.type.Audio.channel = 1;
// Treat fragmentation separately
if (fragmentation != NULL) {
// If silence for too long, send only new data.
if ((fragmentation->fragmentationTimeDiff[1] <= 0x3fff) &&
(fragmentation->fragmentationVectorSize == 2)) {
// only 0x80 if we have multiple blocks
_payloadData[0] = 0x80 + fragmentation->fragmentationPlType[1];
uint32_t REDheader = (((uint32_t) fragmentation->fragmentationTimeDiff[1])
<< 10) + fragmentation->fragmentationLength[1];
_payloadData[1] = uint8_t((REDheader >> 16) & 0x000000FF);
_payloadData[2] = uint8_t((REDheader >> 8) & 0x000000FF);
_payloadData[3] = uint8_t(REDheader & 0x000000FF);
_payloadData[4] = fragmentation->fragmentationPlType[0];
// copy the RED data
memcpy(_payloadData + 5,
payloadData + fragmentation->fragmentationOffset[1],
fragmentation->fragmentationLength[1]);
// copy the normal data
memcpy(_payloadData + 5 + fragmentation->fragmentationLength[1],
payloadData + fragmentation->fragmentationOffset[0],
fragmentation->fragmentationLength[0]);
payloadDataSize += 5;
} else {
// single block (newest one)
memcpy(_payloadData, payloadData + fragmentation->fragmentationOffset[0],
fragmentation->fragmentationLength[0]);
payloadDataSize = uint16_t(fragmentation->fragmentationLength[0]);
rtpInfo.header.payloadType = fragmentation->fragmentationPlType[0];
}
_channelCritSect->Leave();
}
void
Channel::Stats(uint8_t* payloadType, uint32_t* payloadLenByte)
{
_channelCritSect->Enter();
int k;
int n;
memset(payloadLenByte, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t));
for(k = 0; k < MAX_NUM_PAYLOADS; k++)
{
if(_payloadStats[k].payloadType == -1)
{
break;
}
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;
}
} else {
memcpy(_payloadData, payloadData, payloadDataSize);
if (_isStereo) {
if (_leftChannel) {
memcpy(&_rtpInfo, &rtpInfo, sizeof(WebRtcRTPHeader));
_leftChannel = false;
rtpInfo.type.Audio.channel = 1;
} else {
memcpy(&rtpInfo, &_rtpInfo, sizeof(WebRtcRTPHeader));
_leftChannel = true;
rtpInfo.type.Audio.channel = 2;
}
}
}
_channelCritSect->Leave();
}
_channelCritSect->Enter();
if (_saveBitStream) {
//fwrite(payloadData, sizeof(uint8_t), payloadSize, _bitStreamFile);
}
if (!_isStereo) {
CalcStatistics(rtpInfo, payloadSize);
}
_lastInTimestamp = timeStamp;
_totalBytes += payloadDataSize;
_channelCritSect->Leave();
void
Channel::PrintStats(CodecInst& codecInst)
{
ACMTestPayloadStats payloadStats;
Stats(codecInst, payloadStats);
printf("%s %d kHz\n",
codecInst.plname,
codecInst.plfreq / 1000);
printf("=====================================================\n");
if(payloadStats.payloadType == -1)
{
printf("No Packets are sent with payload-type %d (%s)\n\n",
codecInst.pltype,
codecInst.plname);
return;
if (_useFECTestWithPacketLoss) {
_packetLoss += 1;
if (_packetLoss == 3) {
_packetLoss = 0;
return 0;
}
for(int k = 0; k < MAX_NUM_FRAMESIZES; k++)
{
if(payloadStats.frameSizeStats[k].frameSizeSample == 0)
{
break;
}
printf("Frame-size.................... %d samples\n",
payloadStats.frameSizeStats[k].frameSizeSample);
printf("Average Rate.................. %.0f bits/sec\n",
payloadStats.frameSizeStats[k].rateBitPerSec);
printf("Maximum Payload-Size.......... %d 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("Number of Packets............. %u\n",
(unsigned int)payloadStats.frameSizeStats[k].numPackets);
printf("Duration...................... %0.3f sec\n\n",
payloadStats.frameSizeStats[k].usageLenSec);
}
status = _receiverACM->IncomingPacket(_payloadData, payloadDataSize, rtpInfo);
return status;
}
void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize) {
int n;
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
// easier.
for (n = 0; n < MAX_NUM_PAYLOADS; n++) {
if (_lastPayloadType == _payloadStats[n].payloadType) {
_payloadStats[n].newPacket = true;
break;
}
}
}
_lastPayloadType = rtpInfo.header.payloadType;
bool newPayload = true;
ACMTestPayloadStats* currentPayloadStr = NULL;
for (n = 0; n < MAX_NUM_PAYLOADS; n++) {
if (rtpInfo.header.payloadType == _payloadStats[n].payloadType) {
newPayload = false;
currentPayloadStr = &_payloadStats[n];
break;
}
}
if (!newPayload) {
if (!currentPayloadStr->newPacket) {
uint32_t lastFrameSizeSample = (uint32_t)(
(uint32_t) rtpInfo.header.timestamp
- (uint32_t) currentPayloadStr->lastTimestamp);
assert(lastFrameSizeSample > 0);
int k = 0;
while ((currentPayloadStr->frameSizeStats[k].frameSizeSample
!= lastFrameSizeSample)
&& (currentPayloadStr->frameSizeStats[k].frameSizeSample != 0)) {
k++;
}
ACMTestFrameSizeStats* currentFrameSizeStats = &(currentPayloadStr
->frameSizeStats[k]);
currentFrameSizeStats->frameSizeSample = (int16_t) lastFrameSizeSample;
// increment the number of encoded samples.
currentFrameSizeStats->totalEncodedSamples += lastFrameSizeSample;
// increment the number of recveived packets
currentFrameSizeStats->numPackets++;
// 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;
// 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;
}
// store the current values for the next time
currentPayloadStr->lastTimestamp = rtpInfo.header.timestamp;
currentPayloadStr->lastPayloadLenByte = payloadSize;
} else {
currentPayloadStr->newPacket = false;
currentPayloadStr->lastPayloadLenByte = payloadSize;
currentPayloadStr->lastTimestamp = rtpInfo.header.timestamp;
currentPayloadStr->payloadType = rtpInfo.header.payloadType;
}
} else {
n = 0;
while (_payloadStats[n].payloadType != -1) {
n++;
}
// first packet
_payloadStats[n].newPacket = false;
_payloadStats[n].lastPayloadLenByte = payloadSize;
_payloadStats[n].lastTimestamp = rtpInfo.header.timestamp;
_payloadStats[n].payloadType = rtpInfo.header.payloadType;
}
}
uint32_t
Channel::LastInTimestamp()
{
uint32_t timestamp;
_channelCritSect->Enter();
timestamp = _lastInTimestamp;
Channel::Channel(int16_t chID)
: _receiverACM(NULL),
_seqNo(0),
_channelCritSect(CriticalSectionWrapper::CreateCriticalSection()),
_bitStreamFile(NULL),
_saveBitStream(false),
_lastPayloadType(-1),
_isStereo(false),
_leftChannel(true),
_lastInTimestamp(0),
_packetLoss(0),
_useFECTestWithPacketLoss(false),
_beginTime(TickTime::MillisecondTimestamp()),
_totalBytes(0) {
int n;
int k;
for (n = 0; n < MAX_NUM_PAYLOADS; n++) {
_payloadStats[n].payloadType = -1;
_payloadStats[n].newPacket = true;
for (k = 0; k < MAX_NUM_FRAMESIZES; k++) {
_payloadStats[n].frameSizeStats[k].frameSizeSample = 0;
_payloadStats[n].frameSizeStats[k].maxPayloadLen = 0;
_payloadStats[n].frameSizeStats[k].numPackets = 0;
_payloadStats[n].frameSizeStats[k].totalPayloadLenByte = 0;
_payloadStats[n].frameSizeStats[k].totalEncodedSamples = 0;
}
}
if (chID >= 0) {
_saveBitStream = true;
char bitStreamFileName[500];
sprintf(bitStreamFileName, "bitStream_%d.dat", chID);
_bitStreamFile = fopen(bitStreamFileName, "wb");
} else {
_saveBitStream = false;
}
}
Channel::~Channel() {
delete _channelCritSect;
}
void Channel::RegisterReceiverACM(AudioCodingModule* acm) {
_receiverACM = acm;
return;
}
void Channel::ResetStats() {
int n;
int k;
_channelCritSect->Enter();
_lastPayloadType = -1;
for (n = 0; n < MAX_NUM_PAYLOADS; n++) {
_payloadStats[n].payloadType = -1;
_payloadStats[n].newPacket = true;
for (k = 0; k < MAX_NUM_FRAMESIZES; k++) {
_payloadStats[n].frameSizeStats[k].frameSizeSample = 0;
_payloadStats[n].frameSizeStats[k].maxPayloadLen = 0;
_payloadStats[n].frameSizeStats[k].numPackets = 0;
_payloadStats[n].frameSizeStats[k].totalPayloadLenByte = 0;
_payloadStats[n].frameSizeStats[k].totalEncodedSamples = 0;
}
}
_beginTime = TickTime::MillisecondTimestamp();
_totalBytes = 0;
_channelCritSect->Leave();
}
int16_t Channel::Stats(CodecInst& codecInst,
ACMTestPayloadStats& payloadStats) {
_channelCritSect->Enter();
int n;
payloadStats.payloadType = -1;
for (n = 0; n < MAX_NUM_PAYLOADS; n++) {
if (_payloadStats[n].payloadType == codecInst.pltype) {
memcpy(&payloadStats, &_payloadStats[n], sizeof(ACMTestPayloadStats));
break;
}
}
if (payloadStats.payloadType == -1) {
_channelCritSect->Leave();
return timestamp;
return -1;
}
for (n = 0; n < MAX_NUM_FRAMESIZES; n++) {
if (payloadStats.frameSizeStats[n].frameSizeSample == 0) {
_channelCritSect->Leave();
return 0;
}
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;
}
_channelCritSect->Leave();
return 0;
}
double
Channel::BitRate()
{
double rate;
uint64_t currTime = TickTime::MillisecondTimestamp();
_channelCritSect->Enter();
rate = ((double)_totalBytes * 8.0)/ (double)(currTime - _beginTime);
_channelCritSect->Leave();
return rate;
void Channel::Stats(uint32_t* numPackets) {
_channelCritSect->Enter();
int k;
int n;
memset(numPackets, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t));
for (k = 0; k < MAX_NUM_PAYLOADS; k++) {
if (_payloadStats[k].payloadType == -1) {
break;
}
numPackets[k] = 0;
for (n = 0; n < MAX_NUM_FRAMESIZES; n++) {
if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) {
break;
}
numPackets[k] += _payloadStats[k].frameSizeStats[n].numPackets;
}
}
_channelCritSect->Leave();
}
} // namespace webrtc
void Channel::Stats(uint8_t* payloadType, uint32_t* payloadLenByte) {
_channelCritSect->Enter();
int k;
int n;
memset(payloadLenByte, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t));
for (k = 0; k < MAX_NUM_PAYLOADS; k++) {
if (_payloadStats[k].payloadType == -1) {
break;
}
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;
}
}
_channelCritSect->Leave();
}
void Channel::PrintStats(CodecInst& codecInst) {
ACMTestPayloadStats payloadStats;
Stats(codecInst, payloadStats);
printf("%s %d kHz\n", codecInst.plname, codecInst.plfreq / 1000);
printf("=====================================================\n");
if (payloadStats.payloadType == -1) {
printf("No Packets are sent with payload-type %d (%s)\n\n",
codecInst.pltype, codecInst.plname);
return;
}
for (int k = 0; k < MAX_NUM_FRAMESIZES; k++) {
if (payloadStats.frameSizeStats[k].frameSizeSample == 0) {
break;
}
printf("Frame-size.................... %d samples\n",
payloadStats.frameSizeStats[k].frameSizeSample);
printf("Average Rate.................. %.0f bits/sec\n",
payloadStats.frameSizeStats[k].rateBitPerSec);
printf("Maximum Payload-Size.......... %d 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("Number of Packets............. %u\n",
(unsigned int) payloadStats.frameSizeStats[k].numPackets);
printf("Duration...................... %0.3f sec\n\n",
payloadStats.frameSizeStats[k].usageLenSec);
}
}
uint32_t Channel::LastInTimestamp() {
uint32_t timestamp;
_channelCritSect->Enter();
timestamp = _lastInTimestamp;
_channelCritSect->Leave();
return timestamp;
}
double Channel::BitRate() {
double rate;
uint64_t currTime = TickTime::MillisecondTimestamp();
_channelCritSect->Enter();
rate = ((double) _totalBytes * 8.0) / (double) (currTime - _beginTime);
_channelCritSect->Leave();
return rate;
}
} // namespace webrtc

View File

@ -23,103 +23,83 @@ namespace webrtc {
#define MAX_NUM_PAYLOADS 50
#define MAX_NUM_FRAMESIZES 6
struct ACMTestFrameSizeStats
{
uint16_t frameSizeSample;
int16_t maxPayloadLen;
uint32_t numPackets;
uint64_t totalPayloadLenByte;
uint64_t totalEncodedSamples;
double rateBitPerSec;
double usageLenSec;
struct ACMTestFrameSizeStats {
uint16_t frameSizeSample;
int16_t maxPayloadLen;
uint32_t numPackets;
uint64_t totalPayloadLenByte;
uint64_t totalEncodedSamples;
double rateBitPerSec;
double usageLenSec;
};
struct ACMTestPayloadStats
{
bool newPacket;
int16_t payloadType;
int16_t lastPayloadLenByte;
uint32_t lastTimestamp;
ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
struct ACMTestPayloadStats {
bool newPacket;
int16_t payloadType;
int16_t lastPayloadLenByte;
uint32_t lastTimestamp;
ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
};
class Channel: public AudioPacketizationCallback
{
public:
class Channel : public AudioPacketizationCallback {
public:
Channel(
int16_t chID = -1);
~Channel();
Channel(int16_t chID = -1);
~Channel();
int32_t SendData(
const FrameType frameType,
const uint8_t payloadType,
const uint32_t timeStamp,
const uint8_t* payloadData,
const uint16_t payloadSize,
const RTPFragmentationHeader* fragmentation);
int32_t SendData(const FrameType frameType, const uint8_t payloadType,
const uint32_t timeStamp, const uint8_t* payloadData,
const uint16_t payloadSize,
const RTPFragmentationHeader* fragmentation);
void RegisterReceiverACM(
AudioCodingModule *acm);
void RegisterReceiverACM(AudioCodingModule *acm);
void ResetStats();
void ResetStats();
int16_t Stats(
CodecInst& codecInst,
ACMTestPayloadStats& payloadStats);
int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
void Stats(
uint32_t* numPackets);
void Stats(uint32_t* numPackets);
void Stats(
uint8_t* payloadLenByte,
uint32_t* payloadType);
void Stats(uint8_t* payloadLenByte, uint32_t* payloadType);
void PrintStats(
CodecInst& codecInst);
void PrintStats(CodecInst& codecInst);
void SetIsStereo(bool isStereo)
{
_isStereo = isStereo;
}
void SetIsStereo(bool isStereo) {
_isStereo = isStereo;
}
uint32_t LastInTimestamp();
uint32_t LastInTimestamp();
void SetFECTestWithPacketLoss(bool usePacketLoss)
{
_useFECTestWithPacketLoss = usePacketLoss;
}
void SetFECTestWithPacketLoss(bool usePacketLoss) {
_useFECTestWithPacketLoss = usePacketLoss;
}
double BitRate();
double BitRate();
private:
void CalcStatistics(
WebRtcRTPHeader& rtpInfo,
uint16_t payloadSize);
private:
void CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize);
AudioCodingModule* _receiverACM;
uint16_t _seqNo;
// 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
uint8_t _payloadData[60 * 32 * 2 * 2];
AudioCodingModule* _receiverACM;
uint16_t _seqNo;
// 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
uint8_t _payloadData[60 * 32 * 2 * 2];
CriticalSectionWrapper* _channelCritSect;
FILE* _bitStreamFile;
bool _saveBitStream;
int16_t _lastPayloadType;
ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
bool _isStereo;
WebRtcRTPHeader _rtpInfo;
bool _leftChannel;
uint32_t _lastInTimestamp;
// FEC Test variables
int16_t _packetLoss;
bool _useFECTestWithPacketLoss;
uint64_t _beginTime;
uint64_t _totalBytes;
CriticalSectionWrapper* _channelCritSect;
FILE* _bitStreamFile;
bool _saveBitStream;
int16_t _lastPayloadType;
ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
bool _isStereo;
WebRtcRTPHeader _rtpInfo;
bool _leftChannel;
uint32_t _lastInTimestamp;
// FEC Test variables
int16_t _packetLoss;
bool _useFECTestWithPacketLoss;
uint64_t _beginTime;
uint64_t _totalBytes;
};
} // namespace webrtc
} // namespace webrtc
#endif

View File

@ -27,20 +27,18 @@
namespace webrtc {
TestPacketization::TestPacketization(RTPStream *rtpStream,
uint16_t frequency)
TestPacketization::TestPacketization(RTPStream *rtpStream, uint16_t frequency)
: _rtpStream(rtpStream),
_frequency(frequency),
_seqNo(0) {
}
TestPacketization::~TestPacketization() { }
TestPacketization::~TestPacketization() {
}
int32_t TestPacketization::SendData(
const FrameType /* frameType */,
const uint8_t payloadType,
const uint32_t timeStamp,
const uint8_t* payloadData,
const FrameType /* frameType */, const uint8_t payloadType,
const uint32_t timeStamp, const uint8_t* payloadData,
const uint16_t payloadSize,
const RTPFragmentationHeader* /* fragmentation */) {
_rtpStream->Write(payloadType, timeStamp, _seqNo++, payloadData, payloadSize,
@ -62,8 +60,8 @@ void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream) {
int codecNo;
// Open input file
const std::string file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
const std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
_pcmFile.Open(file_name, 32000, "rb");
// Set the codec for the current test.
@ -127,7 +125,7 @@ void Sender::Run() {
if (!Add10MsData()) {
break;
}
if (!Process()) { // This could be done in a processing thread
if (!Process()) { // This could be done in a processing thread
break;
}
}
@ -155,16 +153,16 @@ void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream) {
int playSampFreq;
std::string file_name;
std::stringstream file_stream;
file_stream << webrtc::test::OutputPath() << "encodeDecode_out" <<
static_cast<int>(codeId) << ".pcm";
file_stream << webrtc::test::OutputPath() << "encodeDecode_out"
<< static_cast<int>(codeId) << ".pcm";
file_name = file_stream.str();
_rtpStream = rtpStream;
if (testMode == 1) {
playSampFreq=recvCodec.plfreq;
playSampFreq = recvCodec.plfreq;
_pcmFile.Open(file_name, recvCodec.plfreq, "wb+");
} else if (testMode == 0) {
playSampFreq=32000;
playSampFreq = 32000;
_pcmFile.Open(file_name, 32000, "wb+");
} else {
printf("\nValid output frequencies:\n");
@ -172,7 +170,7 @@ void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream) {
printf("which means output frequency equal to received signal frequency");
printf("\n\nChoose output sampling frequency: ");
ASSERT_GT(scanf("%d", &playSampFreq), 0);
file_name = webrtc::test::OutputPath() + "encodeDecode_out.pcm";
file_name = webrtc::test::OutputPath() + "encodeDecode_out.pcm";
_pcmFile.Open(file_name, playSampFreq, "wb+");
}
@ -184,7 +182,7 @@ void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream) {
}
void Receiver::Teardown() {
delete [] _playoutBuffer;
delete[] _playoutBuffer;
_pcmFile.Close();
if (testMode > 1)
Trace::ReturnTrace();
@ -205,16 +203,16 @@ bool Receiver::IncomingPacket() {
return false;
}
}
}
}
int32_t ok = _acm->IncomingPacket(_incomingPayload,
_realPayloadSizeBytes, _rtpInfo);
if (ok != 0) {
printf("Error when inserting packet to ACM, for run: codecId: %d\n",
codeId);
}
_realPayloadSizeBytes = _rtpStream->Read(&_rtpInfo, _incomingPayload,
_payloadSizeBytes, &_nextTime);
int32_t ok = _acm->IncomingPacket(_incomingPayload, _realPayloadSizeBytes,
_rtpInfo);
if (ok != 0) {
printf("Error when inserting packet to ACM, for run: codecId: %d\n",
codeId);
}
_realPayloadSizeBytes = _rtpStream->Read(&_rtpInfo, _incomingPayload,
_payloadSizeBytes, &_nextTime);
if (_realPayloadSizeBytes == 0 && _rtpStream->EndOfFile()) {
_firstTime = true;
}
@ -233,8 +231,7 @@ bool Receiver::PlayoutData() {
if (_playoutLengthSmpls == 0) {
return false;
}
_pcmFile.Write10MsData(audioFrame.data_,
audioFrame.samples_per_channel_);
_pcmFile.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
return true;
}
@ -265,20 +262,20 @@ void Receiver::Run() {
EncodeDecodeTest::EncodeDecodeTest() {
_testMode = 2;
Trace::CreateTrace();
Trace::SetTraceFile((webrtc::test::OutputPath() +
"acm_encdec_trace.txt").c_str());
Trace::SetTraceFile(
(webrtc::test::OutputPath() + "acm_encdec_trace.txt").c_str());
}
EncodeDecodeTest::EncodeDecodeTest(int testMode) {
//testMode == 0 for autotest
//testMode == 1 for testing all codecs/parameters
//testMode > 1 for specific user-input test (as it was used before)
_testMode = testMode;
if(_testMode != 0) {
Trace::CreateTrace();
Trace::SetTraceFile((webrtc::test::OutputPath() +
"acm_encdec_trace.txt").c_str());
}
_testMode = testMode;
if (_testMode != 0) {
Trace::CreateTrace();
Trace::SetTraceFile(
(webrtc::test::OutputPath() + "acm_encdec_trace.txt").c_str());
}
}
void EncodeDecodeTest::Perform() {
@ -289,9 +286,9 @@ void EncodeDecodeTest::Perform() {
}
int numCodecs = 1;
int codePars[3]; // Frequency, packet size, rate.
int numPars[52]; // Number of codec parameters sets (freq, pacsize, rate)
// to test, for a given codec.
int codePars[3]; // Frequency, packet size, rate.
int numPars[52]; // Number of codec parameters sets (freq, pacsize, rate)
// to test, for a given codec.
codePars[0] = 0;
codePars[1] = 0;
@ -390,4 +387,4 @@ void EncodeDecodeTest::EncodeToFile(int fileType, int codeId, int* codePars,
AudioCodingModule::Destroy(acm);
}
} // namespace webrtc
} // namespace webrtc

View File

@ -24,21 +24,18 @@ namespace webrtc {
#define MAX_INCOMING_PAYLOAD 8096
// TestPacketization callback which writes the encoded payloads to file
class TestPacketization: public AudioPacketizationCallback {
class TestPacketization : public AudioPacketizationCallback {
public:
TestPacketization(RTPStream *rtpStream, uint16_t frequency);
~TestPacketization();
virtual int32_t SendData(const FrameType frameType,
const uint8_t payloadType,
const uint32_t timeStamp,
const uint8_t* payloadData,
virtual int32_t SendData(const FrameType frameType, const uint8_t payloadType,
const uint32_t timeStamp, const uint8_t* payloadData,
const uint16_t payloadSize,
const RTPFragmentationHeader* fragmentation);
private:
static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
int16_t seqNo, uint32_t timeStamp,
uint32_t ssrc);
int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
RTPStream* _rtpStream;
int32_t _frequency;
int16_t _seqNo;
@ -92,7 +89,7 @@ class Receiver {
uint32_t _nextTime;
};
class EncodeDecodeTest: public ACMTest {
class EncodeDecodeTest : public ACMTest {
public:
EncodeDecodeTest();
EncodeDecodeTest(int testMode);
@ -109,6 +106,6 @@ class EncodeDecodeTest: public ACMTest {
Receiver _receiver;
};
} // namespace webrtc
} // namespace webrtc
#endif

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)
@ -84,8 +84,7 @@ int16_t PCMFile::ChooseFile(std::string* file_name, int16_t max_len) {
return 0;
}
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];
@ -158,10 +157,8 @@ int32_t PCMFile::Read10MsData(AudioFrame& audio_frame) {
channels = 2;
}
int32_t payload_size = (int32_t) fread(audio_frame.data_,
sizeof(uint16_t),
samples_10ms_ * channels,
pcm_file_);
int32_t payload_size = (int32_t) fread(audio_frame.data_, sizeof(uint16_t),
samples_10ms_ * channels, pcm_file_);
if (payload_size < samples_10ms_ * channels) {
for (int k = payload_size; k < samples_10ms_ * channels; k++) {
audio_frame.data_[k] = 0;
@ -190,8 +187,7 @@ void PCMFile::Write10MsData(AudioFrame& audio_frame) {
return;
}
} else {
int16_t* stereo_audio =
new int16_t[2 * audio_frame.samples_per_channel_];
int16_t* stereo_audio = new int16_t[2 * audio_frame.samples_per_channel_];
int k;
for (k = 0; k < audio_frame.samples_per_channel_; k++) {
stereo_audio[k << 1] = audio_frame.data_[k];
@ -207,17 +203,17 @@ void PCMFile::Write10MsData(AudioFrame& audio_frame) {
} else {
if (fwrite(audio_frame.data_, sizeof(int16_t),
audio_frame.num_channels_ * audio_frame.samples_per_channel_,
pcm_file_) != static_cast<size_t>(
audio_frame.num_channels_ * audio_frame.samples_per_channel_)) {
pcm_file_) !=
static_cast<size_t>(audio_frame.num_channels_ *
audio_frame.samples_per_channel_)) {
return;
}
}
}
void PCMFile::Write10MsData(int16_t* playout_buffer,
uint16_t length_smpls) {
if (fwrite(playout_buffer, sizeof(uint16_t),
length_smpls, pcm_file_) != length_smpls) {
void PCMFile::Write10MsData(int16_t* playout_buffer, uint16_t length_smpls) {
if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) !=
length_smpls) {
return;
}
}

View File

@ -30,13 +30,12 @@ class PCMFile {
}
}
void Open(const std::string& filename, uint16_t frequency,
const char* mode, bool auto_rewind = false);
void Open(const std::string& filename, uint16_t frequency, const char* mode,
bool auto_rewind = false);
int32_t Read10MsData(AudioFrame& audio_frame);
void Write10MsData(int16_t *playout_buffer,
uint16_t length_smpls);
void Write10MsData(int16_t *playout_buffer, uint16_t length_smpls);
void Write10MsData(AudioFrame& audio_frame);
uint16_t PayloadLength10Ms() const;
@ -46,11 +45,9 @@ class PCMFile {
return end_of_file_;
}
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);
static int16_t ChooseFile(std::string* file_name,
int16_t max_len);
static int16_t ChooseFile(std::string* file_name, int16_t max_len);
bool Rewinded();
void SaveStereo(bool is_stereo = true);
void ReadStereo(bool is_stereo = true);

View File

@ -25,257 +25,223 @@
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.timestamp = (static_cast<uint32_t>(rtpHeader[4])<<24) |
(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];
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.timestamp = (static_cast<uint32_t>(rtpHeader[4]) << 24) |
(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];
}
void RTPStream::MakeRTPheader(uint8_t* rtpHeader,
uint8_t payloadType, int16_t seqNo,
uint32_t timeStamp, uint32_t ssrc)
{
rtpHeader[0]=(unsigned char)0x80;
rtpHeader[1]=(unsigned char)(payloadType & 0xFF);
rtpHeader[2]=(unsigned char)((seqNo>>8)&0xFF);
rtpHeader[3]=(unsigned char)((seqNo)&0xFF);
rtpHeader[4]=(unsigned char)((timeStamp>>24)&0xFF);
rtpHeader[5]=(unsigned char)((timeStamp>>16)&0xFF);
void RTPStream::MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
int16_t seqNo, uint32_t timeStamp,
uint32_t ssrc) {
rtpHeader[0] = (unsigned char) 0x80;
rtpHeader[1] = (unsigned char) (payloadType & 0xFF);
rtpHeader[2] = (unsigned char) ((seqNo >> 8) & 0xFF);
rtpHeader[3] = (unsigned char) ((seqNo) & 0xFF);
rtpHeader[4] = (unsigned char) ((timeStamp >> 24) & 0xFF);
rtpHeader[5] = (unsigned char) ((timeStamp >> 16) & 0xFF);
rtpHeader[6]=(unsigned char)((timeStamp>>8)&0xFF);
rtpHeader[7]=(unsigned char)(timeStamp & 0xFF);
rtpHeader[6] = (unsigned char) ((timeStamp >> 8) & 0xFF);
rtpHeader[7] = (unsigned char) (timeStamp & 0xFF);
rtpHeader[8]=(unsigned char)((ssrc>>24)&0xFF);
rtpHeader[9]=(unsigned char)((ssrc>>16)&0xFF);
rtpHeader[8] = (unsigned char) ((ssrc >> 24) & 0xFF);
rtpHeader[9] = (unsigned char) ((ssrc >> 16) & 0xFF);
rtpHeader[10]=(unsigned char)((ssrc>>8)&0xFF);
rtpHeader[11]=(unsigned char)(ssrc & 0xFF);
rtpHeader[10] = (unsigned char) ((ssrc >> 8) & 0xFF);
rtpHeader[11] = (unsigned char) (ssrc & 0xFF);
}
RTPPacket::RTPPacket(uint8_t payloadType, uint32_t timeStamp,
int16_t seqNo, const uint8_t* payloadData,
uint16_t payloadSize, uint32_t frequency)
:
payloadType(payloadType),
timeStamp(timeStamp),
seqNo(seqNo),
payloadSize(payloadSize),
frequency(frequency)
{
if (payloadSize > 0)
{
this->payloadData = new uint8_t[payloadSize];
memcpy(this->payloadData, payloadData, payloadSize);
}
RTPPacket::RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
const uint8_t* payloadData, uint16_t payloadSize,
uint32_t frequency)
: payloadType(payloadType),
timeStamp(timeStamp),
seqNo(seqNo),
payloadSize(payloadSize),
frequency(frequency) {
if (payloadSize > 0) {
this->payloadData = new uint8_t[payloadSize];
memcpy(this->payloadData, payloadData, payloadSize);
}
}
RTPPacket::~RTPPacket()
{
delete [] payloadData;
RTPPacket::~RTPPacket() {
delete[] payloadData;
}
RTPBuffer::RTPBuffer()
{
_queueRWLock = RWLockWrapper::CreateRWLock();
RTPBuffer::RTPBuffer() {
_queueRWLock = RWLockWrapper::CreateRWLock();
}
RTPBuffer::~RTPBuffer()
{
delete _queueRWLock;
RTPBuffer::~RTPBuffer() {
delete _queueRWLock;
}
void
RTPBuffer::Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_t payloadSize, uint32_t frequency)
{
RTPPacket *packet = new RTPPacket(payloadType, timeStamp, seqNo, payloadData, payloadSize, frequency);
_queueRWLock->AcquireLockExclusive();
_rtpQueue.push(packet);
_queueRWLock->ReleaseLockExclusive();
void RTPBuffer::Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_t payloadSize, uint32_t frequency) {
RTPPacket *packet = new RTPPacket(payloadType, timeStamp, seqNo, payloadData,
payloadSize, frequency);
_queueRWLock->AcquireLockExclusive();
_rtpQueue.push(packet);
_queueRWLock->ReleaseLockExclusive();
}
uint16_t
RTPBuffer::Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
uint16_t payloadSize,
uint32_t* offset)
{
_queueRWLock->AcquireLockShared();
RTPPacket *packet = _rtpQueue.front();
_rtpQueue.pop();
_queueRWLock->ReleaseLockShared();
rtpInfo->header.markerBit = 1;
rtpInfo->header.payloadType = packet->payloadType;
rtpInfo->header.sequenceNumber = packet->seqNo;
rtpInfo->header.ssrc = 0;
rtpInfo->header.timestamp = packet->timeStamp;
if (packet->payloadSize > 0 && payloadSize >= packet->payloadSize)
{
memcpy(payloadData, packet->payloadData, packet->payloadSize);
}
else
{
return 0;
}
*offset = (packet->timeStamp/(packet->frequency/1000));
uint16_t RTPBuffer::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
uint16_t payloadSize, uint32_t* offset) {
_queueRWLock->AcquireLockShared();
RTPPacket *packet = _rtpQueue.front();
_rtpQueue.pop();
_queueRWLock->ReleaseLockShared();
rtpInfo->header.markerBit = 1;
rtpInfo->header.payloadType = packet->payloadType;
rtpInfo->header.sequenceNumber = packet->seqNo;
rtpInfo->header.ssrc = 0;
rtpInfo->header.timestamp = packet->timeStamp;
if (packet->payloadSize > 0 && payloadSize >= packet->payloadSize) {
memcpy(payloadData, packet->payloadData, packet->payloadSize);
} else {
return 0;
}
*offset = (packet->timeStamp / (packet->frequency / 1000));
return packet->payloadSize;
return packet->payloadSize;
}
bool
RTPBuffer::EndOfFile() const
{
_queueRWLock->AcquireLockShared();
bool eof = _rtpQueue.empty();
_queueRWLock->ReleaseLockShared();
return eof;
bool RTPBuffer::EndOfFile() const {
_queueRWLock->AcquireLockShared();
bool eof = _rtpQueue.empty();
_queueRWLock->ReleaseLockShared();
return eof;
}
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";
exit(1);
}
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";
exit(1);
}
}
void RTPFile::Close()
{
if (_rtpFile != NULL)
{
fclose(_rtpFile);
_rtpFile = NULL;
}
void RTPFile::Close() {
if (_rtpFile != NULL) {
fclose(_rtpFile);
_rtpFile = NULL;
}
}
void RTPFile::WriteHeader()
{
// Write data in a format that NetEQ and RTP Play can parse
fprintf(_rtpFile, "#!RTPencode%s\n", "1.0");
uint32_t dummy_variable = 0;
// should be converted to network endian format, but does not matter when 0
if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 2, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 2, 1, _rtpFile) != 1) {
return;
}
fflush(_rtpFile);
void RTPFile::WriteHeader() {
// Write data in a format that NetEQ and RTP Play can parse
fprintf(_rtpFile, "#!RTPencode%s\n", "1.0");
uint32_t dummy_variable = 0;
// should be converted to network endian format, but does not matter when 0
if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 2, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&dummy_variable, 2, 1, _rtpFile) != 1) {
return;
}
fflush(_rtpFile);
}
void RTPFile::ReadHeader()
{
uint32_t start_sec, start_usec, source;
uint16_t port, padding;
char fileHeader[40];
EXPECT_TRUE(fgets(fileHeader, 40, _rtpFile) != 0);
EXPECT_EQ(1u, fread(&start_sec, 4, 1, _rtpFile));
start_sec=ntohl(start_sec);
EXPECT_EQ(1u, fread(&start_usec, 4, 1, _rtpFile));
start_usec=ntohl(start_usec);
EXPECT_EQ(1u, fread(&source, 4, 1, _rtpFile));
source=ntohl(source);
EXPECT_EQ(1u, fread(&port, 2, 1, _rtpFile));
port=ntohs(port);
EXPECT_EQ(1u, fread(&padding, 2, 1, _rtpFile));
padding=ntohs(padding);
void RTPFile::ReadHeader() {
uint32_t start_sec, start_usec, source;
uint16_t port, padding;
char fileHeader[40];
EXPECT_TRUE(fgets(fileHeader, 40, _rtpFile) != 0);
EXPECT_EQ(1u, fread(&start_sec, 4, 1, _rtpFile));
start_sec = ntohl(start_sec);
EXPECT_EQ(1u, fread(&start_usec, 4, 1, _rtpFile));
start_usec = ntohl(start_usec);
EXPECT_EQ(1u, fread(&source, 4, 1, _rtpFile));
source = ntohl(source);
EXPECT_EQ(1u, fread(&port, 2, 1, _rtpFile));
port = ntohs(port);
EXPECT_EQ(1u, fread(&padding, 2, 1, _rtpFile));
padding = ntohs(padding);
}
void RTPFile::Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_t payloadSize, uint32_t frequency)
{
/* write RTP packet to file */
uint8_t rtpHeader[12];
MakeRTPheader(rtpHeader, payloadType, seqNo, timeStamp, 0);
uint16_t lengthBytes = htons(12 + payloadSize + 8);
uint16_t plen = htons(12 + payloadSize);
uint32_t offsetMs;
const uint16_t payloadSize, uint32_t frequency) {
/* write RTP packet to file */
uint8_t rtpHeader[12];
MakeRTPheader(rtpHeader, payloadType, seqNo, timeStamp, 0);
uint16_t lengthBytes = htons(12 + payloadSize + 8);
uint16_t plen = htons(12 + payloadSize);
uint32_t offsetMs;
offsetMs = (timeStamp/(frequency/1000));
offsetMs = htonl(offsetMs);
if (fwrite(&lengthBytes, 2, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&plen, 2, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&offsetMs, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(rtpHeader, 12, 1, _rtpFile) != 1) {
return;
}
if (fwrite(payloadData, 1, payloadSize, _rtpFile) != payloadSize) {
return;
}
offsetMs = (timeStamp / (frequency / 1000));
offsetMs = htonl(offsetMs);
if (fwrite(&lengthBytes, 2, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&plen, 2, 1, _rtpFile) != 1) {
return;
}
if (fwrite(&offsetMs, 4, 1, _rtpFile) != 1) {
return;
}
if (fwrite(rtpHeader, 12, 1, _rtpFile) != 1) {
return;
}
if (fwrite(payloadData, 1, payloadSize, _rtpFile) != payloadSize) {
return;
}
}
uint16_t RTPFile::Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
uint16_t payloadSize,
uint32_t* offset)
{
uint16_t lengthBytes;
uint16_t plen;
uint8_t rtpHeader[12];
size_t read_len = fread(&lengthBytes, 2, 1, _rtpFile);
/* Check if we have reached end of file. */
if ((read_len == 0) && feof(_rtpFile))
{
_rtpEOF = true;
return 0;
}
EXPECT_EQ(1u, fread(&plen, 2, 1, _rtpFile));
EXPECT_EQ(1u, fread(offset, 4, 1, _rtpFile));
lengthBytes = ntohs(lengthBytes);
plen = ntohs(plen);
*offset = ntohl(*offset);
EXPECT_GT(plen, 11);
uint16_t RTPFile::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
uint16_t payloadSize, uint32_t* offset) {
uint16_t lengthBytes;
uint16_t plen;
uint8_t rtpHeader[12];
size_t read_len = fread(&lengthBytes, 2, 1, _rtpFile);
/* Check if we have reached end of file. */
if ((read_len == 0) && feof(_rtpFile)) {
_rtpEOF = true;
return 0;
}
EXPECT_EQ(1u, fread(&plen, 2, 1, _rtpFile));
EXPECT_EQ(1u, fread(offset, 4, 1, _rtpFile));
lengthBytes = ntohs(lengthBytes);
plen = ntohs(plen);
*offset = ntohl(*offset);
EXPECT_GT(plen, 11);
EXPECT_EQ(1u, fread(rtpHeader, 12, 1, _rtpFile));
ParseRTPHeader(rtpInfo, rtpHeader);
rtpInfo->type.Audio.isCNG = false;
rtpInfo->type.Audio.channel = 1;
EXPECT_EQ(lengthBytes, plen + 8);
EXPECT_EQ(1u, fread(rtpHeader, 12, 1, _rtpFile));
ParseRTPHeader(rtpInfo, rtpHeader);
rtpInfo->type.Audio.isCNG = false;
rtpInfo->type.Audio.channel = 1;
EXPECT_EQ(lengthBytes, plen + 8);
if (plen == 0)
{
return 0;
}
if (payloadSize < (lengthBytes - 20))
{
return -1;
}
if (lengthBytes < 20)
{
return -1;
}
lengthBytes -= 20;
EXPECT_EQ(lengthBytes, fread(payloadData, 1, lengthBytes, _rtpFile));
return lengthBytes;
if (plen == 0) {
return 0;
}
if (payloadSize < (lengthBytes - 20)) {
return -1;
}
if (lengthBytes < 20) {
return -1;
}
lengthBytes -= 20;
EXPECT_EQ(lengthBytes, fread(payloadData, 1, lengthBytes, _rtpFile));
return lengthBytes;
}
} // namespace webrtc
} // namespace webrtc

View File

@ -20,84 +20,97 @@
namespace webrtc {
class RTPStream
{
public:
virtual ~RTPStream(){}
class RTPStream {
public:
virtual ~RTPStream() {
}
virtual void Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_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 uint16_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 uint16_t Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
uint16_t payloadSize,
uint32_t* offset) = 0;
virtual bool EndOfFile() const = 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 uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
uint16_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 ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader);
protected:
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,
uint16_t payloadSize, uint32_t frequency);
~RTPPacket();
uint8_t payloadType;
uint32_t timeStamp;
int16_t seqNo;
uint8_t* payloadData;
uint16_t payloadSize;
uint32_t frequency;
class RTPPacket {
public:
RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
const uint8_t* payloadData, uint16_t payloadSize,
uint32_t frequency);
~RTPPacket();
uint8_t payloadType;
uint32_t timeStamp;
int16_t seqNo;
uint8_t* payloadData;
uint16_t payloadSize;
uint32_t frequency;
};
class RTPBuffer : public RTPStream
{
public:
RTPBuffer();
~RTPBuffer();
void Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_t payloadSize, uint32_t frequency);
uint16_t Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
uint16_t payloadSize,
uint32_t* offset);
virtual bool EndOfFile() const;
private:
RWLockWrapper* _queueRWLock;
std::queue<RTPPacket *> _rtpQueue;
class RTPBuffer : public RTPStream {
public:
RTPBuffer();
~RTPBuffer();
void Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_t payloadSize, uint32_t frequency);
uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
uint16_t payloadSize, uint32_t* offset);
virtual bool EndOfFile() const;
private:
RWLockWrapper* _queueRWLock;
std::queue<RTPPacket *> _rtpQueue;
};
class RTPFile : public RTPStream
{
public:
~RTPFile(){}
RTPFile() : _rtpFile(NULL),_rtpEOF(false) {}
void Open(const char *outFilename, const char *mode);
void Close();
void WriteHeader();
void ReadHeader();
void Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_t payloadSize, uint32_t frequency);
uint16_t Read(WebRtcRTPHeader* rtpInfo,
uint8_t* payloadData,
uint16_t payloadSize,
uint32_t* offset);
bool EndOfFile() const { return _rtpEOF; }
private:
FILE* _rtpFile;
bool _rtpEOF;
class RTPFile : public RTPStream {
public:
~RTPFile() {
}
RTPFile()
: _rtpFile(NULL),
_rtpEOF(false) {
}
void Open(const char *outFilename, const char *mode);
void Close();
void WriteHeader();
void ReadHeader();
void Write(const uint8_t payloadType, const uint32_t timeStamp,
const int16_t seqNo, const uint8_t* payloadData,
const uint16_t payloadSize, uint32_t frequency);
uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
uint16_t payloadSize, uint32_t* offset);
bool EndOfFile() const {
return _rtpEOF;
}
private:
FILE* _rtpFile;
bool _rtpEOF;
};
} // namespace webrtc
} // namespace webrtc
#endif

View File

@ -23,210 +23,183 @@ namespace webrtc {
#define NUM_PANN_COEFFS 10
SpatialAudio::SpatialAudio(int testMode)
{
_testMode = testMode;
SpatialAudio::SpatialAudio(int testMode) {
_testMode = testMode;
}
SpatialAudio::~SpatialAudio()
{
AudioCodingModule::Destroy(_acmLeft);
AudioCodingModule::Destroy(_acmRight);
AudioCodingModule::Destroy(_acmReceiver);
delete _channel;
_inFile.Close();
_outFile.Close();
SpatialAudio::~SpatialAudio() {
AudioCodingModule::Destroy(_acmLeft);
AudioCodingModule::Destroy(_acmRight);
AudioCodingModule::Destroy(_acmReceiver);
delete _channel;
_inFile.Close();
_outFile.Close();
}
int16_t
SpatialAudio::Setup()
{
// Create ACMs and the Channel;
_acmLeft = AudioCodingModule::Create(1);
_acmRight = AudioCodingModule::Create(2);
_acmReceiver = AudioCodingModule::Create(3);
_channel = new Channel;
int16_t SpatialAudio::Setup() {
// Create ACMs and the Channel;
_acmLeft = AudioCodingModule::Create(1);
_acmRight = AudioCodingModule::Create(2);
_acmReceiver = AudioCodingModule::Create(3);
_channel = new Channel;
// Register callback for the sender side.
CHECK_ERROR(_acmLeft->RegisterTransportCallback(_channel));
CHECK_ERROR(_acmRight->RegisterTransportCallback(_channel));
// Register the receiver ACM in channel
_channel->RegisterReceiverACM(_acmReceiver);
// Register callback for the sender side.
CHECK_ERROR(_acmLeft->RegisterTransportCallback(_channel));
CHECK_ERROR(_acmRight->RegisterTransportCallback(_channel));
// Register the receiver ACM in channel
_channel->RegisterReceiverACM(_acmReceiver);
uint16_t sampFreqHz = 32000;
uint16_t sampFreqHz = 32000;
const std::string file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
_inFile.Open(file_name, sampFreqHz, "rb", false);
const std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
_inFile.Open(file_name, sampFreqHz, "rb", false);
std::string output_file = webrtc::test::OutputPath() +
"out_spatial_autotest.pcm";
if(_testMode == 1)
{
output_file = webrtc::test::OutputPath() + "testspatial_out.pcm";
printf("\n");
printf("Enter the output file [%s]: ", output_file.c_str());
PCMFile::ChooseFile(&output_file, MAX_FILE_NAME_LENGTH_BYTE,
&sampFreqHz);
std::string output_file = webrtc::test::OutputPath()
+ "out_spatial_autotest.pcm";
if (_testMode == 1) {
output_file = webrtc::test::OutputPath() + "testspatial_out.pcm";
printf("\n");
printf("Enter the output file [%s]: ", output_file.c_str());
PCMFile::ChooseFile(&output_file, MAX_FILE_NAME_LENGTH_BYTE, &sampFreqHz);
} else {
output_file = webrtc::test::OutputPath() + "testspatial_out.pcm";
}
_outFile.Open(output_file, sampFreqHz, "wb", false);
_outFile.SaveStereo(true);
// Register all available codes as receiving codecs.
CodecInst codecInst;
int status;
uint8_t num_encoders = _acmReceiver->NumberOfCodecs();
// Register all available codes as receiving codecs once more.
for (uint8_t n = 0; n < num_encoders; n++) {
status = _acmReceiver->Codec(n, &codecInst);
if (status < 0) {
printf("Error in Codec(), no matching codec found");
}
else
{
output_file = webrtc::test::OutputPath() + "testspatial_out.pcm";
status = _acmReceiver->RegisterReceiveCodec(codecInst);
if (status < 0) {
printf("Error in RegisterReceiveCodec() for payload type %d",
codecInst.pltype);
}
_outFile.Open(output_file, sampFreqHz, "wb", false);
_outFile.SaveStereo(true);
}
// Register all available codes as receiving codecs.
CodecInst codecInst;
int status;
uint8_t num_encoders = _acmReceiver->NumberOfCodecs();
// Register all available codes as receiving codecs once more.
for (uint8_t n = 0; n < num_encoders; n++) {
status = _acmReceiver->Codec(n, &codecInst);
if (status < 0) {
printf("Error in Codec(), no matching codec found");
}
status = _acmReceiver->RegisterReceiveCodec(codecInst);
if (status < 0) {
printf("Error in RegisterReceiveCodec() for payload type %d",
codecInst.pltype);
}
}
return 0;
return 0;
}
void
SpatialAudio::Perform()
{
if(_testMode == 0)
{
printf("Running SpatialAudio Test");
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1,
"---------- SpatialAudio ----------");
}
void SpatialAudio::Perform() {
if (_testMode == 0) {
printf("Running SpatialAudio Test");
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1,
"---------- SpatialAudio ----------");
}
Setup();
Setup();
CodecInst codecInst;
_acmLeft->Codec((uint8_t)1, &codecInst);
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
EncodeDecode();
CodecInst codecInst;
_acmLeft->Codec((uint8_t) 1, &codecInst);
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
EncodeDecode();
int16_t pannCntr = 0;
int16_t pannCntr = 0;
double leftPanning[NUM_PANN_COEFFS] =
{1.00, 0.95, 0.90, 0.85, 0.80, 0.75, 0.70, 0.60, 0.55, 0.50};
double rightPanning[NUM_PANN_COEFFS] =
{0.50, 0.55, 0.60, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95, 1.00};
double leftPanning[NUM_PANN_COEFFS] = { 1.00, 0.95, 0.90, 0.85, 0.80, 0.75,
0.70, 0.60, 0.55, 0.50 };
double rightPanning[NUM_PANN_COEFFS] = { 0.50, 0.55, 0.60, 0.70, 0.75, 0.80,
0.85, 0.90, 0.95, 1.00 };
while((pannCntr + 1) < NUM_PANN_COEFFS)
{
_acmLeft->Codec((uint8_t)0, &codecInst);
codecInst.pacsize = 480;
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
CHECK_ERROR(_acmRight->RegisterSendCodec(codecInst));
EncodeDecode(leftPanning[pannCntr], rightPanning[pannCntr]);
pannCntr++;
// Change codec
_acmLeft->Codec((uint8_t)3, &codecInst);
codecInst.pacsize = 320;
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
CHECK_ERROR(_acmRight->RegisterSendCodec(codecInst));
EncodeDecode(leftPanning[pannCntr], rightPanning[pannCntr]);
pannCntr++;
if(_testMode == 0)
{
printf(".");
}
}
_acmLeft->Codec((uint8_t)4, &codecInst);
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
EncodeDecode();
_acmLeft->Codec((uint8_t)0, &codecInst);
while ((pannCntr + 1) < NUM_PANN_COEFFS) {
_acmLeft->Codec((uint8_t) 0, &codecInst);
codecInst.pacsize = 480;
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
CHECK_ERROR(_acmRight->RegisterSendCodec(codecInst));
pannCntr = NUM_PANN_COEFFS -1;
while(pannCntr >= 0)
{
EncodeDecode(leftPanning[pannCntr], rightPanning[pannCntr]);
pannCntr--;
if(_testMode == 0)
{
printf(".");
}
EncodeDecode(leftPanning[pannCntr], rightPanning[pannCntr]);
pannCntr++;
// Change codec
_acmLeft->Codec((uint8_t) 3, &codecInst);
codecInst.pacsize = 320;
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
CHECK_ERROR(_acmRight->RegisterSendCodec(codecInst));
EncodeDecode(leftPanning[pannCntr], rightPanning[pannCntr]);
pannCntr++;
if (_testMode == 0) {
printf(".");
}
if(_testMode == 0)
{
printf("Done!\n");
}
_acmLeft->Codec((uint8_t) 4, &codecInst);
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
EncodeDecode();
_acmLeft->Codec((uint8_t) 0, &codecInst);
codecInst.pacsize = 480;
CHECK_ERROR(_acmLeft->RegisterSendCodec(codecInst));
CHECK_ERROR(_acmRight->RegisterSendCodec(codecInst));
pannCntr = NUM_PANN_COEFFS - 1;
while (pannCntr >= 0) {
EncodeDecode(leftPanning[pannCntr], rightPanning[pannCntr]);
pannCntr--;
if (_testMode == 0) {
printf(".");
}
}
if (_testMode == 0) {
printf("Done!\n");
}
}
void
SpatialAudio::EncodeDecode(
const double leftPanning,
const double rightPanning)
{
AudioFrame audioFrame;
int32_t outFileSampFreq = _outFile.SamplingFrequency();
void SpatialAudio::EncodeDecode(const double leftPanning,
const double rightPanning) {
AudioFrame audioFrame;
int32_t outFileSampFreq = _outFile.SamplingFrequency();
const double rightToLeftRatio = rightPanning / leftPanning;
const double rightToLeftRatio = rightPanning / leftPanning;
_channel->SetIsStereo(true);
_channel->SetIsStereo(true);
while(!_inFile.EndOfFile())
{
_inFile.Read10MsData(audioFrame);
for(int n = 0; n < audioFrame.samples_per_channel_; n++)
{
audioFrame.data_[n] = (int16_t)floor(
audioFrame.data_[n] * leftPanning + 0.5);
}
CHECK_ERROR(_acmLeft->Add10MsData(audioFrame));
for(int n = 0; n < audioFrame.samples_per_channel_; n++)
{
audioFrame.data_[n] = (int16_t)floor(
audioFrame.data_[n] * rightToLeftRatio + 0.5);
}
CHECK_ERROR(_acmRight->Add10MsData(audioFrame));
CHECK_ERROR(_acmLeft->Process());
CHECK_ERROR(_acmRight->Process());
CHECK_ERROR(_acmReceiver->PlayoutData10Ms(outFileSampFreq,
&audioFrame));
_outFile.Write10MsData(audioFrame);
while (!_inFile.EndOfFile()) {
_inFile.Read10MsData(audioFrame);
for (int n = 0; n < audioFrame.samples_per_channel_; n++) {
audioFrame.data_[n] = (int16_t) floor(
audioFrame.data_[n] * leftPanning + 0.5);
}
_inFile.Rewind();
CHECK_ERROR(_acmLeft->Add10MsData(audioFrame));
for (int n = 0; n < audioFrame.samples_per_channel_; n++) {
audioFrame.data_[n] = (int16_t) floor(
audioFrame.data_[n] * rightToLeftRatio + 0.5);
}
CHECK_ERROR(_acmRight->Add10MsData(audioFrame));
CHECK_ERROR(_acmLeft->Process());
CHECK_ERROR(_acmRight->Process());
CHECK_ERROR(_acmReceiver->PlayoutData10Ms(outFileSampFreq, &audioFrame));
_outFile.Write10MsData(audioFrame);
}
_inFile.Rewind();
}
void
SpatialAudio::EncodeDecode()
{
AudioFrame audioFrame;
int32_t outFileSampFreq = _outFile.SamplingFrequency();
void SpatialAudio::EncodeDecode() {
AudioFrame audioFrame;
int32_t outFileSampFreq = _outFile.SamplingFrequency();
_channel->SetIsStereo(false);
_channel->SetIsStereo(false);
while(!_inFile.EndOfFile())
{
_inFile.Read10MsData(audioFrame);
CHECK_ERROR(_acmLeft->Add10MsData(audioFrame));
while (!_inFile.EndOfFile()) {
_inFile.Read10MsData(audioFrame);
CHECK_ERROR(_acmLeft->Add10MsData(audioFrame));
CHECK_ERROR(_acmLeft->Process());
CHECK_ERROR(_acmLeft->Process());
CHECK_ERROR(_acmReceiver->PlayoutData10Ms(outFileSampFreq,
&audioFrame));
_outFile.Write10MsData(audioFrame);
}
_inFile.Rewind();
CHECK_ERROR(_acmReceiver->PlayoutData10Ms(outFileSampFreq, &audioFrame));
_outFile.Write10MsData(audioFrame);
}
_inFile.Rewind();
}
} // namespace webrtc
} // namespace webrtc

View File

@ -21,27 +21,26 @@
namespace webrtc {
class SpatialAudio : public ACMTest
{
public:
SpatialAudio(int testMode);
~SpatialAudio();
class SpatialAudio : public ACMTest {
public:
SpatialAudio(int testMode);
~SpatialAudio();
void Perform();
private:
int16_t Setup();
void EncodeDecode(double leftPanning, double rightPanning);
void EncodeDecode();
void Perform();
private:
int16_t Setup();
void EncodeDecode(double leftPanning, double rightPanning);
void EncodeDecode();
AudioCodingModule* _acmLeft;
AudioCodingModule* _acmRight;
AudioCodingModule* _acmReceiver;
Channel* _channel;
PCMFile _inFile;
PCMFile _outFile;
int _testMode;
AudioCodingModule* _acmLeft;
AudioCodingModule* _acmRight;
AudioCodingModule* _acmReceiver;
Channel* _channel;
PCMFile _inFile;
PCMFile _outFile;
int _testMode;
};
} // namespace webrtc
} // namespace webrtc
#endif

View File

@ -78,8 +78,7 @@ int32_t TestPack::SendData(FrameType frame_type, uint8_t payload_type,
rtp_info.type.Audio.channel = 1;
memcpy(payload_data_, payload_data, payload_size);
status = receiver_acm_->IncomingPacket(payload_data_, payload_size,
rtp_info);
status = receiver_acm_->IncomingPacket(payload_data_, payload_size, rtp_info);
payload_size_ = payload_size;
timestamp_diff_ = timestamp - last_in_timestamp_;
@ -127,8 +126,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) {
@ -725,9 +724,9 @@ void TestAllCodecs::RegisterSendCodec(char side, char* codec_name,
// packet. If variable rate codec (extra_byte == -1), set to -1 (65535).
if (extra_byte != -1) {
// Add 0.875 to always round up to a whole byte
packet_size_bytes_ =
static_cast<uint16_t>(static_cast<float>(packet_size * rate) /
static_cast<float>(sampling_freq_hz * 8) + 0.875) + extra_byte;
packet_size_bytes_ = static_cast<uint16_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_ = -1;

View File

@ -35,7 +35,7 @@ class TestPack : public AudioPacketizationCallback {
void reset_payload_size();
private:
AudioCodingModule* receiver_acm_;
AudioCodingModule* receiver_acm_;
uint16_t sequence_number_;
uint8_t payload_data_[60 * 32 * 2 * 2];
uint32_t timestamp_diff_;

View File

@ -22,581 +22,453 @@
namespace webrtc {
TestFEC::TestFEC(int testMode):
_acmA(NULL),
_acmB(NULL),
_channelA2B(NULL),
_testCntr(0)
{
_testMode = testMode;
TestFEC::TestFEC(int testMode)
: _acmA(NULL),
_acmB(NULL),
_channelA2B(NULL),
_testCntr(0) {
_testMode = testMode;
}
TestFEC::~TestFEC()
{
if(_acmA != NULL)
{
AudioCodingModule::Destroy(_acmA);
_acmA = NULL;
}
if(_acmB != NULL)
{
AudioCodingModule::Destroy(_acmB);
_acmB = NULL;
}
if(_channelA2B != NULL)
{
delete _channelA2B;
_channelA2B = NULL;
}
TestFEC::~TestFEC() {
if (_acmA != NULL) {
AudioCodingModule::Destroy(_acmA);
_acmA = NULL;
}
if (_acmB != NULL) {
AudioCodingModule::Destroy(_acmB);
_acmB = NULL;
}
if (_channelA2B != NULL) {
delete _channelA2B;
_channelA2B = NULL;
}
}
void TestFEC::Perform()
{
void TestFEC::Perform() {
if(_testMode == 0)
{
printf("Running FEC Test");
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- TestFEC ----------");
if (_testMode == 0) {
printf("Running FEC Test");
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- TestFEC ----------");
}
const std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
_inFileA.Open(file_name, 32000, "rb");
bool fecEnabled;
_acmA = AudioCodingModule::Create(0);
_acmB = AudioCodingModule::Create(1);
_acmA->InitializeReceiver();
_acmB->InitializeReceiver();
uint8_t numEncoders = _acmA->NumberOfCodecs();
CodecInst myCodecParam;
if (_testMode != 0) {
printf("Registering codecs at receiver... \n");
}
for (uint8_t n = 0; n < numEncoders; n++) {
_acmB->Codec(n, &myCodecParam);
if (_testMode != 0) {
printf("%s\n", myCodecParam.plname);
}
const std::string file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
_inFileA.Open(file_name, 32000, "rb");
_acmB->RegisterReceiveCodec(myCodecParam);
}
bool fecEnabled;
// Create and connect the channel
_channelA2B = new Channel;
_acmA->RegisterTransportCallback(_channelA2B);
_channelA2B->RegisterReceiverACM(_acmB);
_acmA = AudioCodingModule::Create(0);
_acmB = AudioCodingModule::Create(1);
_acmA->InitializeReceiver();
_acmB->InitializeReceiver();
uint8_t numEncoders = _acmA->NumberOfCodecs();
CodecInst myCodecParam;
if(_testMode != 0)
{
printf("Registering codecs at receiver... \n");
}
for(uint8_t n = 0; n < numEncoders; n++)
{
_acmB->Codec(n, &myCodecParam);
if(_testMode != 0)
{
printf("%s\n", myCodecParam.plname);
}
_acmB->RegisterReceiveCodec(myCodecParam);
}
// Create and connect the channel
_channelA2B = new Channel;
_acmA->RegisterTransportCallback(_channelA2B);
_channelA2B->RegisterReceiverACM(_acmB);
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
#ifndef WEBRTC_CODEC_G722
printf("G722 needs to be activated to run this test\n");
exit(-1);
printf("G722 needs to be activated to run this test\n");
exit(-1);
#endif
char nameG722[] = "G722";
RegisterSendCodec('A', nameG722, 16000);
char nameCN[] = "CN";
RegisterSendCodec('A', nameCN, 16000);
char nameRED[] = "RED";
RegisterSendCodec('A', nameRED);
OpenOutFile(_testCntr);
SetVAD(true, true, VADAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
char nameG722[] = "G722";
RegisterSendCodec('A', nameG722, 16000);
char nameCN[] = "CN";
RegisterSendCodec('A', nameCN, 16000);
char nameRED[] = "RED";
RegisterSendCodec('A', nameRED);
OpenOutFile(_testCntr);
SetVAD(true, true, VADAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
char nameISAC[] = "iSAC";
RegisterSendCodec('A', nameISAC, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
char nameISAC[] = "iSAC";
RegisterSendCodec('A',nameISAC, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(false, false, VADNormal);
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
_channelA2B->SetFECTestWithPacketLoss(true);
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
RegisterSendCodec('A', nameG722);
RegisterSendCodec('A', nameCN, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(false, false, VADNormal);
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(false, false, VADNormal);
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 32000);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 32000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
_channelA2B->SetFECTestWithPacketLoss(true);
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
RegisterSendCodec('A',nameG722);
RegisterSendCodec('A', nameCN, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
RegisterSendCodec('A', nameISAC, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if(_testMode != 0)
{
printf("=======================================================================\n");
printf("%d ",_testCntr++);
}
else
{
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(false, false, VADNormal);
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 32000);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if(_testMode != 0)
{
printf("FEC currently %s\n",(fecEnabled?"ON":"OFF"));
DisplaySendReceiveCodec();
}
Run();
_outFileB.Close();
if(_testMode == 0)
{
printf("Done!\n");
}
if (_testMode == 0) {
printf("Done!\n");
}
}
int32_t TestFEC::SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode)
{
if(_testMode != 0)
{
printf("DTX %s; VAD %s; VAD-Mode %d\n",
enableDTX? "ON":"OFF",
enableVAD? "ON":"OFF",
(int16_t)vadMode);
}
return _acmA->SetVAD(enableDTX, enableVAD, vadMode);
int32_t TestFEC::SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode) {
if (_testMode != 0) {
printf("DTX %s; VAD %s; VAD-Mode %d\n", enableDTX ? "ON" : "OFF",
enableVAD ? "ON" : "OFF", (int16_t) vadMode);
}
return _acmA->SetVAD(enableDTX, enableVAD, vadMode);
}
int16_t TestFEC::RegisterSendCodec(char side, char* codecName, int32_t samplingFreqHz)
{
if(_testMode != 0)
{
if(samplingFreqHz > 0)
{
printf("Registering %s-%d for side %c\n", codecName, samplingFreqHz, side);
}
else
{
printf("Registering %s for side %c\n", codecName, side);
}
int16_t TestFEC::RegisterSendCodec(char side, char* codecName,
int32_t samplingFreqHz) {
if (_testMode != 0) {
if (samplingFreqHz > 0) {
printf("Registering %s-%d for side %c\n", codecName, samplingFreqHz,
side);
} else {
printf("Registering %s for side %c\n", codecName, side);
}
}
std::cout << std::flush;
AudioCodingModule* myACM;
switch (side) {
case 'A': {
myACM = _acmA;
break;
}
case 'B': {
myACM = _acmB;
break;
}
std::cout << std::flush;
AudioCodingModule* myACM;
switch(side)
{
case 'A':
{
myACM = _acmA;
break;
}
case 'B':
{
myACM = _acmB;
break;
}
default:
return -1;
}
return -1;
}
if(myACM == NULL)
{
assert(false);
return -1;
}
CodecInst myCodecParam;
if (myACM == NULL) {
assert(false);
return -1;
}
CodecInst myCodecParam;
CHECK_ERROR(AudioCodingModule::Codec(codecName, &myCodecParam,
samplingFreqHz, 1));
CHECK_ERROR(
AudioCodingModule::Codec(codecName, &myCodecParam, samplingFreqHz, 1));
CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam));
CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam));
// initialization was succesful
return 0;
// initialization was succesful
return 0;
}
void TestFEC::Run()
{
AudioFrame audioFrame;
void TestFEC::Run() {
AudioFrame audioFrame;
uint16_t msecPassed = 0;
uint32_t secPassed = 0;
int32_t outFreqHzB = _outFileB.SamplingFrequency();
uint16_t msecPassed = 0;
uint32_t secPassed = 0;
int32_t outFreqHzB = _outFileB.SamplingFrequency();
while(!_inFileA.EndOfFile())
{
_inFileA.Read10MsData(audioFrame);
CHECK_ERROR(_acmA->Add10MsData(audioFrame));
CHECK_ERROR(_acmA->Process());
CHECK_ERROR(_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
_outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
msecPassed += 10;
if(msecPassed >= 1000)
{
msecPassed = 0;
secPassed++;
}
if(((secPassed%5) == 4) && (msecPassed == 0) && (_testCntr > 14))
{
printf("%3u:%3u ", secPassed, msecPassed);
_acmA->SetFECStatus(false);
printf("FEC currently %s\n",(_acmA->FECStatus()?"ON":"OFF"));
}
if(((secPassed%5) == 4) && (msecPassed >= 990) && (_testCntr > 14))
{
printf("%3u:%3u ", secPassed, msecPassed);
_acmA->SetFECStatus(true);
printf("FEC currently %s\n",(_acmA->FECStatus()?"ON":"OFF"));
}
while (!_inFileA.EndOfFile()) {
_inFileA.Read10MsData(audioFrame);
CHECK_ERROR(_acmA->Add10MsData(audioFrame));
CHECK_ERROR(_acmA->Process());
CHECK_ERROR(_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
_outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
msecPassed += 10;
if (msecPassed >= 1000) {
msecPassed = 0;
secPassed++;
}
_inFileA.Rewind();
if (((secPassed % 5) == 4) && (msecPassed == 0) && (_testCntr > 14)) {
printf("%3u:%3u ", secPassed, msecPassed);
_acmA->SetFECStatus(false);
printf("FEC currently %s\n", (_acmA->FECStatus() ? "ON" : "OFF"));
}
if (((secPassed % 5) == 4) && (msecPassed >= 990) && (_testCntr > 14)) {
printf("%3u:%3u ", secPassed, msecPassed);
_acmA->SetFECStatus(true);
printf("FEC currently %s\n", (_acmA->FECStatus() ? "ON" : "OFF"));
}
}
_inFileA.Rewind();
}
void TestFEC::OpenOutFile(int16_t test_number) {
@ -613,13 +485,12 @@ void TestFEC::OpenOutFile(int16_t test_number) {
_outFileB.Open(file_name, 16000, "wb");
}
void TestFEC::DisplaySendReceiveCodec()
{
CodecInst myCodecParam;
_acmA->SendCodec(&myCodecParam);
printf("%s -> ", myCodecParam.plname);
_acmB->ReceiveCodec(&myCodecParam);
printf("%s\n", myCodecParam.plname);
void TestFEC::DisplaySendReceiveCodec() {
CodecInst myCodecParam;
_acmA->SendCodec(&myCodecParam);
printf("%s -> ", myCodecParam.plname);
_acmB->ReceiveCodec(&myCodecParam);
printf("%s\n", myCodecParam.plname);
}
} // namespace webrtc
} // namespace webrtc

View File

@ -17,33 +17,33 @@
namespace webrtc {
class TestFEC : public ACMTest
{
public:
TestFEC(int testMode);
~TestFEC();
class TestFEC : public ACMTest {
public:
TestFEC(int testMode);
~TestFEC();
void Perform();
private:
// 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.
int16_t RegisterSendCodec(char side, char* codecName, int32_t sampFreqHz = -1);
void Run();
void OpenOutFile(int16_t testNumber);
void DisplaySendReceiveCodec();
int32_t SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode);
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
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, char* codecName,
int32_t sampFreqHz = -1);
void Run();
void OpenOutFile(int16_t testNumber);
void DisplaySendReceiveCodec();
int32_t SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode);
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
Channel* _channelA2B;
Channel* _channelA2B;
PCMFile _inFileA;
PCMFile _outFileB;
int16_t _testCntr;
int _testMode;
PCMFile _inFileA;
PCMFile _outFileB;
int16_t _testCntr;
int _testMode;
};
} // namespace webrtc
} // namespace webrtc
#endif

View File

@ -33,22 +33,23 @@ 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;
return;
}
int32_t TestPackStereo::SendData(
const FrameType frame_type,
const uint8_t payload_type,
const uint32_t timestamp,
const uint8_t* payload_data,
const uint16_t payload_size,
const RTPFragmentationHeader* fragmentation) {
int32_t TestPackStereo::SendData(const FrameType frame_type,
const uint8_t payload_type,
const uint32_t timestamp,
const uint8_t* payload_data,
const uint16_t payload_size,
const RTPFragmentationHeader* fragmentation) {
WebRtcRTPHeader rtp_info;
int32_t status = 0;
@ -159,10 +160,10 @@ void TestStereo::Perform() {
}
// 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();
@ -449,26 +450,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_);
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_);
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_);
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
@ -488,7 +489,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();
#endif
@ -502,7 +503,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) {
@ -513,7 +514,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) {
@ -524,7 +525,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();
#endif
@ -555,7 +556,7 @@ void TestStereo::Perform() {
channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
celt_pltype_);
celt_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
#endif
@ -571,7 +572,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.
@ -597,8 +598,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.
@ -619,7 +619,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) {
@ -630,18 +630,18 @@ 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) {
printf("==============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
printf("==============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
}
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();
#endif
@ -670,7 +670,7 @@ void TestStereo::Perform() {
test_cntr_++;
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
celt_pltype_);
celt_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
#endif
@ -684,7 +684,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));
@ -795,12 +795,11 @@ void TestStereo::RegisterSendCodec(char side, char* codec_name,
if (!strcmp(codec_name, "CELT")) {
pack_size_bytes_ = (uint16_t)(
static_cast<float>(pack_size * rate) /
static_cast<float>(sampling_freq_hz * 8) + 0.875)
/ channels;
static_cast<float>(sampling_freq_hz * 8) + 0.875) / channels;
} else {
pack_size_bytes_ = (uint16_t)(
static_cast<float>(pack_size * rate) /
static_cast<float>(sampling_freq_hz * 8) + 0.875);
static_cast<float>(sampling_freq_hz * 8) + 0.875);
}
// Set pointer to the ACM where to register the codec
@ -911,8 +910,8 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
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";
file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
<< ".pcm";
file_name = file_stream.str();
out_file_.Open(file_name, 32000, "wb");
}

View File

@ -67,19 +67,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, int payload_type);
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,
int percent_loss = 0);
void OpenOutFile(int16_t test_number);
void DisplaySendReceiveCodec();
int32_t SendData(const FrameType frame_type,
const uint8_t payload_type,
const uint32_t timestamp,
const uint8_t* payload_data,
int32_t SendData(const FrameType frame_type, const uint8_t payload_type,
const uint32_t timestamp, const uint8_t* payload_data,
const uint16_t payload_size,
const RTPFragmentationHeader* fragmentation);

View File

@ -22,360 +22,324 @@
namespace webrtc {
TestVADDTX::TestVADDTX(int testMode):
_acmA(NULL),
_acmB(NULL),
_channelA2B(NULL),
_testResults(0)
{
//testMode == 1 for more extensive testing
//testMode == 0 for quick test (autotest)
_testMode = testMode;
TestVADDTX::TestVADDTX(int testMode)
: _acmA(NULL),
_acmB(NULL),
_channelA2B(NULL),
_testResults(0) {
//testMode == 1 for more extensive testing
//testMode == 0 for quick test (autotest)
_testMode = testMode;
}
TestVADDTX::~TestVADDTX()
{
if(_acmA != NULL)
{
AudioCodingModule::Destroy(_acmA);
_acmA = NULL;
}
if(_acmB != NULL)
{
AudioCodingModule::Destroy(_acmB);
_acmB = NULL;
}
if(_channelA2B != NULL)
{
delete _channelA2B;
_channelA2B = NULL;
}
TestVADDTX::~TestVADDTX() {
if (_acmA != NULL) {
AudioCodingModule::Destroy(_acmA);
_acmA = NULL;
}
if (_acmB != NULL) {
AudioCodingModule::Destroy(_acmB);
_acmB = NULL;
}
if (_channelA2B != NULL) {
delete _channelA2B;
_channelA2B = NULL;
}
}
void TestVADDTX::Perform()
{
if(_testMode == 0)
{
printf("Running VAD/DTX Test");
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1,
"---------- TestVADDTX ----------");
void TestVADDTX::Perform() {
if (_testMode == 0) {
printf("Running VAD/DTX Test");
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1,
"---------- TestVADDTX ----------");
}
const std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
_inFileA.Open(file_name, 32000, "rb");
_acmA = AudioCodingModule::Create(0);
_acmB = AudioCodingModule::Create(1);
_acmA->InitializeReceiver();
_acmB->InitializeReceiver();
uint8_t numEncoders = _acmA->NumberOfCodecs();
CodecInst myCodecParam;
if (_testMode != 0) {
printf("Registering codecs at receiver... \n");
}
for (uint8_t n = 0; n < numEncoders; n++) {
_acmB->Codec(n, &myCodecParam);
if (_testMode != 0) {
printf("%s\n", myCodecParam.plname);
}
const std::string file_name =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
_inFileA.Open(file_name, 32000, "rb");
_acmA = AudioCodingModule::Create(0);
_acmB = AudioCodingModule::Create(1);
_acmA->InitializeReceiver();
_acmB->InitializeReceiver();
uint8_t numEncoders = _acmA->NumberOfCodecs();
CodecInst myCodecParam;
if(_testMode != 0)
{
printf("Registering codecs at receiver... \n");
}
for(uint8_t n = 0; n < numEncoders; n++)
{
_acmB->Codec(n, &myCodecParam);
if(_testMode != 0)
{
printf("%s\n", myCodecParam.plname);
}
if (!strcmp(myCodecParam.plname, "opus")) {
// Use mono decoding for Opus in the VAD/DTX test.
myCodecParam.channels = 1;
}
_acmB->RegisterReceiveCodec(myCodecParam);
if (!strcmp(myCodecParam.plname, "opus")) {
// Use mono decoding for Opus in the VAD/DTX test.
myCodecParam.channels = 1;
}
_acmB->RegisterReceiveCodec(myCodecParam);
}
// Create and connect the channel
_channelA2B = new Channel;
_acmA->RegisterTransportCallback(_channelA2B);
_channelA2B->RegisterReceiverACM(_acmB);
// Create and connect the channel
_channelA2B = new Channel;
_acmA->RegisterTransportCallback(_channelA2B);
_channelA2B->RegisterReceiverACM(_acmB);
_acmA->RegisterVADCallback(&_monitor);
_acmA->RegisterVADCallback(&_monitor);
int16_t testCntr = 1;
int16_t testResults = 0;
int16_t testCntr = 1;
int16_t testResults = 0;
#ifdef WEBRTC_CODEC_ISAC
// Open outputfile
OpenOutFile(testCntr++);
// Open outputfile
OpenOutFile(testCntr++);
// Register iSAC WB as send codec
char nameISAC[] = "ISAC";
RegisterSendCodec('A', nameISAC, 16000);
// Register iSAC WB as send codec
char nameISAC[] = "ISAC";
RegisterSendCodec('A', nameISAC, 16000);
// Run the five test cased
runTestCases();
// Run the five test cased
runTestCases();
// Close file
_outFileB.Close();
// Close file
_outFileB.Close();
// Open outputfile
OpenOutFile(testCntr++);
// Open outputfile
OpenOutFile(testCntr++);
// Register iSAC SWB as send codec
RegisterSendCodec('A', nameISAC, 32000);
// Register iSAC SWB as send codec
RegisterSendCodec('A', nameISAC, 32000);
// Run the five test cased
runTestCases();
// Run the five test cased
runTestCases();
// Close file
_outFileB.Close();
// Close file
_outFileB.Close();
#endif
#ifdef WEBRTC_CODEC_ILBC
// Open outputfile
OpenOutFile(testCntr++);
// Open outputfile
OpenOutFile(testCntr++);
// Register iLBC as send codec
char nameILBC[] = "ilbc";
RegisterSendCodec('A', nameILBC);
// Register iLBC as send codec
char nameILBC[] = "ilbc";
RegisterSendCodec('A', nameILBC);
// Run the five test cased
runTestCases();
// Run the five test cased
runTestCases();
// Close file
_outFileB.Close();
// Close file
_outFileB.Close();
#endif
#ifdef WEBRTC_CODEC_OPUS
// Open outputfile
OpenOutFile(testCntr++);
// Open outputfile
OpenOutFile(testCntr++);
// Register Opus as send codec
char nameOPUS[] = "opus";
RegisterSendCodec('A', nameOPUS);
// Register Opus as send codec
char nameOPUS[] = "opus";
RegisterSendCodec('A', nameOPUS);
// Run the five test cased
runTestCases();
// Run the five test cased
runTestCases();
// Close file
_outFileB.Close();
// Close file
_outFileB.Close();
#endif
if(_testMode) {
printf("Done!\n");
}
if (_testMode) {
printf("Done!\n");
}
printf("VAD/DTX test completed with %d subtests failed\n", testResults);
if (testResults > 0)
{
printf("Press return\n\n");
getchar();
}
printf("VAD/DTX test completed with %d subtests failed\n", testResults);
if (testResults > 0) {
printf("Press return\n\n");
getchar();
}
}
void TestVADDTX::runTestCases()
{
if(_testMode != 0)
{
CodecInst myCodecParam;
_acmA->SendCodec(&myCodecParam);
printf("%s\n", myCodecParam.plname);
}
else
{
printf(".");
}
// #1 DTX = OFF, VAD = ON, VADNormal
if(_testMode != 0)
printf("Test #1 ");
SetVAD(false, true, VADNormal);
Run();
_testResults += VerifyTest();
// #2 DTX = OFF, VAD = ON, VADAggr
if(_testMode != 0)
printf("Test #2 ");
SetVAD(false, true, VADAggr);
Run();
_testResults += VerifyTest();
// #3 DTX = ON, VAD = ON, VADLowBitrate
if(_testMode != 0)
printf("Test #3 ");
SetVAD(true, true, VADLowBitrate);
Run();
_testResults += VerifyTest();
// #4 DTX = ON, VAD = ON, VADVeryAggr
if(_testMode != 0)
printf("Test #4 ");
SetVAD(true, true, VADVeryAggr);
Run();
_testResults += VerifyTest();
// #5 DTX = ON, VAD = OFF, VADNormal
if(_testMode != 0)
printf("Test #5 ");
SetVAD(true, false, VADNormal);
Run();
_testResults += VerifyTest();
}
void TestVADDTX::runTestInternalDTX()
{
// #6 DTX = ON, VAD = ON, VADNormal
if(_testMode != 0)
printf("Test #6 ");
SetVAD(true, true, VADNormal);
if(_acmA->ReplaceInternalDTXWithWebRtc(true) < 0) {
printf("Was not able to replace DTX since CN was not registered\n");
}
Run();
_testResults += VerifyTest();
}
void TestVADDTX::SetVAD(bool statusDTX, bool statusVAD, int16_t vadMode)
{
bool dtxEnabled, vadEnabled;
ACMVADMode vadModeSet;
if (_acmA->SetVAD(statusDTX, statusVAD, (ACMVADMode) vadMode) < 0) {
assert(false);
}
if (_acmA->VAD(&dtxEnabled, &vadEnabled, &vadModeSet) < 0) {
assert(false);
}
if(_testMode != 0)
{
if(statusDTX != dtxEnabled)
{
printf("DTX: %s not the same as requested: %s\n",
dtxEnabled? "ON":"OFF", dtxEnabled? "OFF":"ON");
}
if(((statusVAD == true) && (vadEnabled == false)) ||
((statusVAD == false) && (vadEnabled == false) &&
(statusDTX == true)))
{
printf("VAD: %s not the same as requested: %s\n",
vadEnabled? "ON":"OFF", vadEnabled? "OFF":"ON");
}
if(vadModeSet != vadMode)
{
printf("VAD mode: %d not the same as requested: %d\n",
(int16_t)vadModeSet, (int16_t)vadMode);
}
}
// Requested VAD/DTX settings
_setStruct.statusDTX = statusDTX;
_setStruct.statusVAD = statusVAD;
_setStruct.vadMode = (ACMVADMode) vadMode;
// VAD settings after setting VAD in ACM
_getStruct.statusDTX = dtxEnabled;
_getStruct.statusVAD = vadEnabled;
_getStruct.vadMode = vadModeSet;
}
VADDTXstruct TestVADDTX::GetVAD()
{
VADDTXstruct retStruct;
bool dtxEnabled, vadEnabled;
ACMVADMode vadModeSet;
if (_acmA->VAD(&dtxEnabled, &vadEnabled, &vadModeSet) < 0) {
assert(false);
}
retStruct.statusDTX = dtxEnabled;
retStruct.statusVAD = vadEnabled;
retStruct.vadMode = vadModeSet;
return retStruct;
}
int16_t TestVADDTX::RegisterSendCodec(char side,
char* codecName,
int32_t samplingFreqHz,
int32_t rateKbps)
{
if(_testMode != 0)
{
printf("Registering %s for side %c\n", codecName, side);
}
std::cout << std::flush;
AudioCodingModule* myACM;
switch(side)
{
case 'A':
{
myACM = _acmA;
break;
}
case 'B':
{
myACM = _acmB;
break;
}
default:
return -1;
}
if(myACM == NULL)
{
return -1;
}
void TestVADDTX::runTestCases() {
if (_testMode != 0) {
CodecInst myCodecParam;
for(int16_t codecCntr = 0; codecCntr < myACM->NumberOfCodecs();
codecCntr++)
{
CHECK_ERROR(myACM->Codec((uint8_t)codecCntr, &myCodecParam));
if(!STR_CASE_CMP(myCodecParam.plname, codecName))
{
if((samplingFreqHz == -1) || (myCodecParam.plfreq == samplingFreqHz))
{
if((rateKbps == -1) || (myCodecParam.rate == rateKbps))
{
break;
}
}
}
}
_acmA->SendCodec(&myCodecParam);
printf("%s\n", myCodecParam.plname);
} else {
printf(".");
}
// #1 DTX = OFF, VAD = ON, VADNormal
if (_testMode != 0)
printf("Test #1 ");
SetVAD(false, true, VADNormal);
Run();
_testResults += VerifyTest();
// We only allow VAD/DTX when sending mono.
myCodecParam.channels = 1;
CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam));
// #2 DTX = OFF, VAD = ON, VADAggr
if (_testMode != 0)
printf("Test #2 ");
SetVAD(false, true, VADAggr);
Run();
_testResults += VerifyTest();
// initialization was succesful
return 0;
// #3 DTX = ON, VAD = ON, VADLowBitrate
if (_testMode != 0)
printf("Test #3 ");
SetVAD(true, true, VADLowBitrate);
Run();
_testResults += VerifyTest();
// #4 DTX = ON, VAD = ON, VADVeryAggr
if (_testMode != 0)
printf("Test #4 ");
SetVAD(true, true, VADVeryAggr);
Run();
_testResults += VerifyTest();
// #5 DTX = ON, VAD = OFF, VADNormal
if (_testMode != 0)
printf("Test #5 ");
SetVAD(true, false, VADNormal);
Run();
_testResults += VerifyTest();
}
void TestVADDTX::runTestInternalDTX() {
// #6 DTX = ON, VAD = ON, VADNormal
if (_testMode != 0)
printf("Test #6 ");
SetVAD(true, true, VADNormal);
if (_acmA->ReplaceInternalDTXWithWebRtc(true) < 0) {
printf("Was not able to replace DTX since CN was not registered\n");
}
Run();
_testResults += VerifyTest();
}
void TestVADDTX::Run()
{
AudioFrame audioFrame;
void TestVADDTX::SetVAD(bool statusDTX, bool statusVAD, int16_t vadMode) {
bool dtxEnabled, vadEnabled;
ACMVADMode vadModeSet;
uint16_t SamplesIn10MsecA = _inFileA.PayloadLength10Ms();
uint32_t timestampA = 1;
int32_t outFreqHzB = _outFileB.SamplingFrequency();
if (_acmA->SetVAD(statusDTX, statusVAD, (ACMVADMode) vadMode) < 0) {
assert(false);
}
if (_acmA->VAD(&dtxEnabled, &vadEnabled, &vadModeSet) < 0) {
assert(false);
}
while(!_inFileA.EndOfFile())
{
_inFileA.Read10MsData(audioFrame);
audioFrame.timestamp_ = timestampA;
timestampA += SamplesIn10MsecA;
CHECK_ERROR(_acmA->Add10MsData(audioFrame));
CHECK_ERROR(_acmA->Process());
CHECK_ERROR(_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
_outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
if (_testMode != 0) {
if (statusDTX != dtxEnabled) {
printf("DTX: %s not the same as requested: %s\n",
dtxEnabled ? "ON" : "OFF", dtxEnabled ? "OFF" : "ON");
}
if (((statusVAD == true) && (vadEnabled == false)) ||
((statusVAD == false) && (vadEnabled == false) &&
(statusDTX == true))) {
printf("VAD: %s not the same as requested: %s\n",
vadEnabled ? "ON" : "OFF", vadEnabled ? "OFF" : "ON");
}
if (vadModeSet != vadMode) {
printf("VAD mode: %d not the same as requested: %d\n",
(int16_t) vadModeSet, (int16_t) vadMode);
}
}
// Requested VAD/DTX settings
_setStruct.statusDTX = statusDTX;
_setStruct.statusVAD = statusVAD;
_setStruct.vadMode = (ACMVADMode) vadMode;
// VAD settings after setting VAD in ACM
_getStruct.statusDTX = dtxEnabled;
_getStruct.statusVAD = vadEnabled;
_getStruct.vadMode = vadModeSet;
}
VADDTXstruct TestVADDTX::GetVAD() {
VADDTXstruct retStruct;
bool dtxEnabled, vadEnabled;
ACMVADMode vadModeSet;
if (_acmA->VAD(&dtxEnabled, &vadEnabled, &vadModeSet) < 0) {
assert(false);
}
retStruct.statusDTX = dtxEnabled;
retStruct.statusVAD = vadEnabled;
retStruct.vadMode = vadModeSet;
return retStruct;
}
int16_t TestVADDTX::RegisterSendCodec(char side, char* codecName,
int32_t samplingFreqHz,
int32_t rateKbps) {
if (_testMode != 0) {
printf("Registering %s for side %c\n", codecName, side);
}
std::cout << std::flush;
AudioCodingModule* myACM;
switch (side) {
case 'A': {
myACM = _acmA;
break;
}
case 'B': {
myACM = _acmB;
break;
}
default:
return -1;
}
if (myACM == NULL) {
return -1;
}
CodecInst myCodecParam;
for (int16_t codecCntr = 0; codecCntr < myACM->NumberOfCodecs();
codecCntr++) {
CHECK_ERROR(myACM->Codec((uint8_t) codecCntr, &myCodecParam));
if (!STR_CASE_CMP(myCodecParam.plname, codecName)) {
if ((samplingFreqHz == -1) || (myCodecParam.plfreq == samplingFreqHz)) {
if ((rateKbps == -1) || (myCodecParam.rate == rateKbps)) {
break;
}
}
}
}
// We only allow VAD/DTX when sending mono.
myCodecParam.channels = 1;
CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam));
// initialization was succesful
return 0;
}
void TestVADDTX::Run() {
AudioFrame audioFrame;
uint16_t SamplesIn10MsecA = _inFileA.PayloadLength10Ms();
uint32_t timestampA = 1;
int32_t outFreqHzB = _outFileB.SamplingFrequency();
while (!_inFileA.EndOfFile()) {
_inFileA.Read10MsData(audioFrame);
audioFrame.timestamp_ = timestampA;
timestampA += SamplesIn10MsecA;
CHECK_ERROR(_acmA->Add10MsData(audioFrame));
CHECK_ERROR(_acmA->Process());
CHECK_ERROR(_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
_outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
}
#ifdef PRINT_STAT
_monitor.PrintStatistics(_testMode);
_monitor.PrintStatistics(_testMode);
#endif
_inFileA.Rewind();
_monitor.GetStatistics(_statCounter);
_monitor.ResetStatistics();
_inFileA.Rewind();
_monitor.GetStatistics(_statCounter);
_monitor.ResetStatistics();
}
void TestVADDTX::OpenOutFile(int16_t test_number) {
@ -392,142 +356,133 @@ void TestVADDTX::OpenOutFile(int16_t test_number) {
_outFileB.Open(file_name, 16000, "wb");
}
int16_t TestVADDTX::VerifyTest()
{
// Verify empty frame result
uint8_t statusEF = 0;
uint8_t vadPattern = 0;
uint8_t emptyFramePattern[6];
CodecInst myCodecParam;
_acmA->SendCodec(&myCodecParam);
bool dtxInUse = true;
bool isReplaced = false;
if ((STR_CASE_CMP(myCodecParam.plname,"G729") == 0) ||
(STR_CASE_CMP(myCodecParam.plname,"G723") == 0) ||
(STR_CASE_CMP(myCodecParam.plname,"AMR") == 0) ||
(STR_CASE_CMP(myCodecParam.plname,"AMR-wb") == 0) ||
(STR_CASE_CMP(myCodecParam.plname,"speex") == 0))
{
_acmA->IsInternalDTXReplacedWithWebRtc(&isReplaced);
if (!isReplaced)
{
dtxInUse = false;
}
int16_t TestVADDTX::VerifyTest() {
// Verify empty frame result
uint8_t statusEF = 0;
uint8_t vadPattern = 0;
uint8_t emptyFramePattern[6];
CodecInst myCodecParam;
_acmA->SendCodec(&myCodecParam);
bool dtxInUse = true;
bool isReplaced = false;
if ((STR_CASE_CMP(myCodecParam.plname, "G729") == 0)
|| (STR_CASE_CMP(myCodecParam.plname, "G723") == 0)
|| (STR_CASE_CMP(myCodecParam.plname, "AMR") == 0)
|| (STR_CASE_CMP(myCodecParam.plname, "AMR-wb") == 0)
|| (STR_CASE_CMP(myCodecParam.plname, "speex") == 0)) {
_acmA->IsInternalDTXReplacedWithWebRtc(&isReplaced);
if (!isReplaced) {
dtxInUse = false;
}
}
// Check for error in VAD/DTX settings
if (_getStruct.statusDTX != _setStruct.statusDTX){
// DTX status doesn't match expected
vadPattern |= 4;
// Check for error in VAD/DTX settings
if (_getStruct.statusDTX != _setStruct.statusDTX) {
// DTX status doesn't match expected
vadPattern |= 4;
}
if (_getStruct.statusDTX) {
if ((!_getStruct.statusVAD && dtxInUse)
|| (!dtxInUse && (_getStruct.statusVAD != _setStruct.statusVAD))) {
// Missmatch in VAD setting
vadPattern |= 2;
}
if (_getStruct.statusDTX){
if ((!_getStruct.statusVAD && dtxInUse) || (!dtxInUse && (_getStruct.statusVAD !=_setStruct.statusVAD)))
{
// Missmatch in VAD setting
vadPattern |= 2;
}
} else {
if (_getStruct.statusVAD != _setStruct.statusVAD) {
// VAD status doesn't match expected
vadPattern |= 2;
}
}
if (_getStruct.vadMode != _setStruct.vadMode) {
// VAD Mode doesn't match expected
vadPattern |= 1;
}
// Set expected empty frame pattern
int ii;
for (ii = 0; ii < 6; ii++) {
emptyFramePattern[ii] = 0;
}
// 0 - "kNoEncoding", not important to check.
// Codecs with packetsize != 80 samples will get this output.
// 1 - "kActiveNormalEncoded", expect to receive some frames with this label .
// 2 - "kPassiveNormalEncoded".
// 3 - "kPassiveDTXNB".
// 4 - "kPassiveDTXWB".
// 5 - "kPassiveDTXSWB".
emptyFramePattern[0] = 1;
emptyFramePattern[1] = 1;
emptyFramePattern[2] = (((!_getStruct.statusDTX && _getStruct.statusVAD)
|| (!dtxInUse && _getStruct.statusDTX)));
emptyFramePattern[3] = ((_getStruct.statusDTX && dtxInUse
&& (_acmA->SendFrequency() == 8000)));
emptyFramePattern[4] = ((_getStruct.statusDTX && dtxInUse
&& (_acmA->SendFrequency() == 16000)));
emptyFramePattern[5] = ((_getStruct.statusDTX && dtxInUse
&& (_acmA->SendFrequency() == 32000)));
// Check pattern 1-5 (skip 0)
for (int ii = 1; ii < 6; ii++) {
if (emptyFramePattern[ii]) {
statusEF |= (_statCounter[ii] == 0);
} else {
if (_getStruct.statusVAD != _setStruct.statusVAD){
// VAD status doesn't match expected
vadPattern |= 2;
}
statusEF |= (_statCounter[ii] > 0);
}
if (_getStruct.vadMode != _setStruct.vadMode){
// VAD Mode doesn't match expected
vadPattern |= 1;
}
if ((statusEF == 0) && (vadPattern == 0)) {
if (_testMode != 0) {
printf(" Test OK!\n");
}
// Set expected empty frame pattern
int ii;
for (ii = 0; ii < 6; ii++) {
emptyFramePattern[ii] = 0;
}
emptyFramePattern[0] = 1; // "kNoEncoding", not important to check. Codecs with packetsize != 80 samples will get this output.
emptyFramePattern[1] = 1; // Expect to always receive some frames labeled "kActiveNormalEncoded"
emptyFramePattern[2] = (((!_getStruct.statusDTX && _getStruct.statusVAD) || (!dtxInUse && _getStruct.statusDTX))); // "kPassiveNormalEncoded"
emptyFramePattern[3] = ((_getStruct.statusDTX && dtxInUse && (_acmA->SendFrequency() == 8000))); // "kPassiveDTXNB"
emptyFramePattern[4] = ((_getStruct.statusDTX && dtxInUse && (_acmA->SendFrequency() == 16000))); // "kPassiveDTXWB"
emptyFramePattern[5] = ((_getStruct.statusDTX && dtxInUse && (_acmA->SendFrequency() == 32000))); // "kPassiveDTXSWB"
// Check pattern 1-5 (skip 0)
for (int ii = 1; ii < 6; ii++)
{
if (emptyFramePattern[ii])
{
statusEF |= (_statCounter[ii] == 0);
}
else
{
statusEF |= (_statCounter[ii] > 0);
}
}
if ((statusEF == 0) && (vadPattern == 0))
{
if(_testMode != 0)
{
printf(" Test OK!\n");
}
return 0;
}
else
{
if (statusEF)
{
printf("\t\t\tUnexpected empty frame result!\n");
}
if (vadPattern)
{
printf("\t\t\tUnexpected SetVAD() result!\tDTX: %d\tVAD: %d\tMode: %d\n", (vadPattern >> 2) & 1, (vadPattern >> 1) & 1, vadPattern & 1);
}
return 1;
}
}
ActivityMonitor::ActivityMonitor()
{
_counter[0] = _counter[1] = _counter[2] = _counter[3] = _counter[4] = _counter[5] = 0;
}
ActivityMonitor::~ActivityMonitor()
{
}
int32_t ActivityMonitor::InFrameType(int16_t frameType)
{
_counter[frameType]++;
return 0;
}
void ActivityMonitor::PrintStatistics(int testMode)
{
if(testMode != 0)
{
printf("\n");
printf("kActiveNormalEncoded kPassiveNormalEncoded kPassiveDTXWB kPassiveDTXNB kPassiveDTXSWB kFrameEmpty\n");
printf("%19u", _counter[1]);
printf("%22u", _counter[2]);
printf("%14u", _counter[3]);
printf("%14u", _counter[4]);
printf("%14u", _counter[5]);
printf("%11u", _counter[0]);
printf("\n\n");
} else {
if (statusEF) {
printf("\t\t\tUnexpected empty frame result!\n");
}
}
void ActivityMonitor::ResetStatistics()
{
_counter[0] = _counter[1] = _counter[2] = _counter[3] = _counter[4] = _counter[5] = 0;
}
void ActivityMonitor::GetStatistics(uint32_t* getCounter)
{
for (int ii = 0; ii < 6; ii++)
{
getCounter[ii] = _counter[ii];
if (vadPattern) {
printf("\t\t\tUnexpected SetVAD() result!\tDTX: %d\tVAD: %d\tMode: %d\n",
(vadPattern >> 2) & 1, (vadPattern >> 1) & 1, vadPattern & 1);
}
return 1;
}
}
} // namespace webrtc
ActivityMonitor::ActivityMonitor() {
_counter[0] = _counter[1] = _counter[2] = _counter[3] = _counter[4] =
_counter[5] = 0;
}
ActivityMonitor::~ActivityMonitor() {
}
int32_t ActivityMonitor::InFrameType(int16_t frameType) {
_counter[frameType]++;
return 0;
}
void ActivityMonitor::PrintStatistics(int testMode) {
if (testMode != 0) {
printf("\n");
printf("kActiveNormalEncoded kPassiveNormalEncoded kPassiveDTXWB ");
printf("kPassiveDTXNB kPassiveDTXSWB kFrameEmpty\n");
printf("%19u", _counter[1]);
printf("%22u", _counter[2]);
printf("%14u", _counter[3]);
printf("%14u", _counter[4]);
printf("%14u", _counter[5]);
printf("%11u", _counter[0]);
printf("\n\n");
}
}
void ActivityMonitor::ResetStatistics() {
_counter[0] = _counter[1] = _counter[2] = _counter[3] = _counter[4] =
_counter[5] = 0;
}
void ActivityMonitor::GetStatistics(uint32_t* getCounter) {
for (int ii = 0; ii < 6; ii++) {
getCounter[ii] = _counter[ii];
}
}
} // namespace webrtc

View File

@ -17,74 +17,70 @@
namespace webrtc {
typedef struct
{
bool statusDTX;
bool statusVAD;
ACMVADMode vadMode;
typedef struct {
bool statusDTX;
bool statusVAD;
ACMVADMode vadMode;
} VADDTXstruct;
class ActivityMonitor : public ACMVADCallback
{
public:
ActivityMonitor();
~ActivityMonitor();
int32_t InFrameType(int16_t frameType);
void PrintStatistics(int testMode);
void ResetStatistics();
void GetStatistics(uint32_t* getCounter);
private:
// counting according to
/*enum WebRtcACMEncodingType
{
kNoEncoding,
kActiveNormalEncoded,
kPassiveNormalEncoded,
kPassiveDTXNB,
kPassiveDTXWB,
kPassiveDTXSWB
};*/
uint32_t _counter[6];
class ActivityMonitor : public ACMVADCallback {
public:
ActivityMonitor();
~ActivityMonitor();
int32_t InFrameType(int16_t frameType);
void PrintStatistics(int testMode);
void ResetStatistics();
void GetStatistics(uint32_t* getCounter);
private:
// Counting according to
// enum WebRtcACMEncodingType {
// kNoEncoding,
// kActiveNormalEncoded,
// kPassiveNormalEncoded,
// kPassiveDTXNB,
// kPassiveDTXWB,
// kPassiveDTXSWB
// };
uint32_t _counter[6];
};
class TestVADDTX : public ACMTest
{
public:
TestVADDTX(int testMode);
~TestVADDTX();
class TestVADDTX : public ACMTest {
public:
TestVADDTX(int testMode);
~TestVADDTX();
void Perform();
private:
// Registration can be based on codec name only, codec name and sampling frequency, or
// codec name, sampling frequency and rate.
int16_t RegisterSendCodec(char side,
char* codecName,
int32_t samplingFreqHz = -1,
int32_t rateKhz = -1);
void Run();
void OpenOutFile(int16_t testNumber);
void runTestCases();
void runTestInternalDTX();
void SetVAD(bool statusDTX, bool statusVAD, int16_t vadMode);
VADDTXstruct GetVAD();
int16_t VerifyTest();//VADDTXstruct setDTX, VADDTXstruct getDTX);
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
void Perform();
private:
// Registration can be based on codec name only, codec name and sampling
// frequency, or codec name, sampling frequency and rate.
int16_t RegisterSendCodec(char side,
char* codecName,
int32_t samplingFreqHz = -1,
int32_t rateKhz = -1);
void Run();
void OpenOutFile(int16_t testNumber);
void runTestCases();
void runTestInternalDTX();
void SetVAD(bool statusDTX, bool statusVAD, int16_t vadMode);
VADDTXstruct GetVAD();
int16_t VerifyTest();
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
Channel* _channelA2B;
Channel* _channelA2B;
PCMFile _inFileA;
PCMFile _outFileB;
PCMFile _inFileA;
PCMFile _outFileB;
ActivityMonitor _monitor;
uint32_t _statCounter[6];
ActivityMonitor _monitor;
uint32_t _statCounter[6];
int _testMode;
int _testResults;
VADDTXstruct _setStruct;
VADDTXstruct _getStruct;
int _testMode;
int _testResults;
VADDTXstruct _setStruct;
VADDTXstruct _getStruct;
};
} // namespace webrtc
} // namespace webrtc
#endif

View File

@ -122,7 +122,7 @@ void PopulateTests(std::vector<ACMTest*>* tests) {
TEST(AudioCodingModuleTest, TestAllCodecs) {
Trace::CreateTrace();
Trace::SetTraceFile((webrtc::test::OutputPath() +
"acm_allcodecs_trace.txt").c_str());
"acm_allcodecs_trace.txt").c_str());
webrtc::TestAllCodecs(ACM_TEST_MODE).Perform();
Trace::ReturnTrace();
}
@ -131,7 +131,7 @@ TEST(AudioCodingModuleTest, TestAllCodecs) {
TEST(AudioCodingModuleTest, TestOpus) {
Trace::CreateTrace();
Trace::SetTraceFile((webrtc::test::OutputPath() +
"acm_opus_trace.txt").c_str());
"acm_opus_trace.txt").c_str());
webrtc::OpusTest().Perform();
Trace::ReturnTrace();
}

View File

@ -12,66 +12,47 @@
#include <math.h>
double TimedTrace::_timeEllapsedSec = 0;
FILE* TimedTrace::_timedTraceFile = NULL;
FILE* TimedTrace::_timedTraceFile = NULL;
TimedTrace::TimedTrace()
{
TimedTrace::TimedTrace() {
}
TimedTrace::~TimedTrace()
{
if(_timedTraceFile != NULL)
{
fclose(_timedTraceFile);
}
_timedTraceFile = NULL;
TimedTrace::~TimedTrace() {
if (_timedTraceFile != NULL) {
fclose(_timedTraceFile);
}
_timedTraceFile = NULL;
}
int16_t
TimedTrace::SetUp(char* fileName)
{
if(_timedTraceFile == NULL)
{
_timedTraceFile = fopen(fileName, "w");
}
if(_timedTraceFile == NULL)
{
return -1;
}
return 0;
int16_t TimedTrace::SetUp(char* fileName) {
if (_timedTraceFile == NULL) {
_timedTraceFile = fopen(fileName, "w");
}
if (_timedTraceFile == NULL) {
return -1;
}
return 0;
}
void
TimedTrace::SetTimeEllapsed(double timeEllapsedSec)
{
_timeEllapsedSec = timeEllapsedSec;
void TimedTrace::SetTimeEllapsed(double timeEllapsedSec) {
_timeEllapsedSec = timeEllapsedSec;
}
double
TimedTrace::TimeEllapsed()
{
return _timeEllapsedSec;
double TimedTrace::TimeEllapsed() {
return _timeEllapsedSec;
}
void
TimedTrace::Tick10Msec()
{
_timeEllapsedSec += 0.010;
void TimedTrace::Tick10Msec() {
_timeEllapsedSec += 0.010;
}
void
TimedTrace::TimedLogg(char* message)
{
unsigned int minutes = (uint32_t)floor(_timeEllapsedSec / 60.0);
double seconds = _timeEllapsedSec - minutes * 60;
//char myFormat[100] = "%8.2f, %3u:%05.2f: %s\n";
if(_timedTraceFile != NULL)
{
fprintf(_timedTraceFile, "%8.2f, %3u:%05.2f: %s\n",
_timeEllapsedSec,
minutes,
seconds,
message);
}
void TimedTrace::TimedLogg(char* message) {
unsigned int minutes = (uint32_t) floor(_timeEllapsedSec / 60.0);
double seconds = _timeEllapsedSec - minutes * 60;
//char myFormat[100] = "%8.2f, %3u:%05.2f: %s\n";
if (_timedTraceFile != NULL) {
fprintf(_timedTraceFile, "%8.2f, %3u:%05.2f: %s\n", _timeEllapsedSec,
minutes, seconds, message);
}
}

View File

@ -16,22 +16,20 @@
#include <cstdio>
#include <cstdlib>
class TimedTrace {
public:
TimedTrace();
~TimedTrace();
class TimedTrace
{
public:
TimedTrace();
~TimedTrace();
void SetTimeEllapsed(double myTime);
double TimeEllapsed();
void Tick10Msec();
int16_t SetUp(char* fileName);
void TimedLogg(char* message);
void SetTimeEllapsed(double myTime);
double TimeEllapsed();
void Tick10Msec();
int16_t SetUp(char* fileName);
void TimedLogg(char* message);
private:
static double _timeEllapsedSec;
static FILE* _timedTraceFile;
private:
static double _timeEllapsedSec;
static FILE* _timedTraceFile;
};

View File

@ -30,423 +30,386 @@ namespace webrtc {
#define MAX_FILE_NAME_LENGTH_BYTE 500
TwoWayCommunication::TwoWayCommunication(int testMode)
{
_testMode = testMode;
TwoWayCommunication::TwoWayCommunication(int testMode) {
_testMode = testMode;
}
TwoWayCommunication::~TwoWayCommunication()
{
AudioCodingModule::Destroy(_acmA);
AudioCodingModule::Destroy(_acmB);
TwoWayCommunication::~TwoWayCommunication() {
AudioCodingModule::Destroy(_acmA);
AudioCodingModule::Destroy(_acmB);
AudioCodingModule::Destroy(_acmRefA);
AudioCodingModule::Destroy(_acmRefB);
AudioCodingModule::Destroy(_acmRefA);
AudioCodingModule::Destroy(_acmRefB);
delete _channel_A2B;
delete _channel_B2A;
delete _channel_A2B;
delete _channel_B2A;
delete _channelRef_A2B;
delete _channelRef_B2A;
delete _channelRef_A2B;
delete _channelRef_B2A;
#ifdef WEBRTC_DTMF_DETECTION
if(_dtmfDetectorA != NULL)
{
delete _dtmfDetectorA;
}
if(_dtmfDetectorB != NULL)
{
delete _dtmfDetectorB;
}
if(_dtmfDetectorA != NULL)
{
delete _dtmfDetectorA;
}
if(_dtmfDetectorB != NULL)
{
delete _dtmfDetectorB;
}
#endif
_inFileA.Close();
_inFileB.Close();
_outFileA.Close();
_outFileB.Close();
_outFileRefA.Close();
_outFileRefB.Close();
_inFileA.Close();
_inFileB.Close();
_outFileA.Close();
_outFileB.Close();
_outFileRefA.Close();
_outFileRefB.Close();
}
uint8_t TwoWayCommunication::ChooseCodec(uint8_t* codecID_A,
uint8_t* codecID_B) {
AudioCodingModule* tmpACM = AudioCodingModule::Create(0);
uint8_t noCodec = tmpACM->NumberOfCodecs();
CodecInst codecInst;
printf("List of Supported Codecs\n");
printf("========================\n");
for (uint8_t codecCntr = 0; codecCntr < noCodec; codecCntr++) {
tmpACM->Codec(codecCntr, &codecInst);
printf("%d- %s\n", codecCntr, codecInst.plname);
}
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);
uint8_t
TwoWayCommunication::ChooseCodec(uint8_t* codecID_A,
uint8_t* codecID_B)
{
AudioCodingModule* tmpACM = AudioCodingModule::Create(0);
uint8_t noCodec = tmpACM->NumberOfCodecs();
CodecInst codecInst;
printf("List of Supported Codecs\n");
printf("========================\n");
for(uint8_t codecCntr = 0; codecCntr < noCodec; codecCntr++)
{
tmpACM->Codec(codecCntr, &codecInst);
printf("%d- %s\n", codecCntr, codecInst.plname);
}
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);
printf("\nChoose a send codec for side B [0]: ");
EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL);
*codecID_B = (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);
AudioCodingModule::Destroy(tmpACM);
printf("\n");
return 0;
}
AudioCodingModule::Destroy(tmpACM);
int16_t TwoWayCommunication::SetUp() {
_acmA = AudioCodingModule::Create(1);
_acmB = AudioCodingModule::Create(2);
_acmRefA = AudioCodingModule::Create(3);
_acmRefB = AudioCodingModule::Create(4);
uint8_t codecID_A;
uint8_t codecID_B;
ChooseCodec(&codecID_A, &codecID_B);
CodecInst codecInst_A;
CodecInst codecInst_B;
CodecInst dummyCodec;
_acmA->Codec(codecID_A, &codecInst_A);
_acmB->Codec(codecID_B, &codecInst_B);
_acmA->Codec(6, &dummyCodec);
//--- Set A codecs
CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorA = new(DTMFDetector);
CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA,
ACMUSA));
#endif
//--- Set ref-A codecs
CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B));
//--- Set B codecs
CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorB = new(DTMFDetector);
CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB,
ACMUSA));
#endif
//--- Set ref-B codecs
CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A));
uint16_t frequencyHz;
//--- Input A
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);
_inFileA.Open(in_file_name, frequencyHz, "rb");
//--- Output A
std::string out_file_a = webrtc::test::OutputPath() + "outA.pcm";
printf("Output file at side A: %s\n", out_file_a.c_str());
printf("Sampling frequency (in Hz) of the above file: %u\n", frequencyHz);
_outFileA.Open(out_file_a, frequencyHz, "wb");
std::string ref_file_name = webrtc::test::OutputPath() + "ref_outA.pcm";
_outFileRefA.Open(ref_file_name, frequencyHz, "wb");
//--- Input B
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);
_inFileB.Open(in_file_name, frequencyHz, "rb");
//--- Output B
std::string out_file_b = webrtc::test::OutputPath() + "outB.pcm";
printf("Output file at side B: %s\n", out_file_b.c_str());
printf("Sampling frequency (in Hz) of the above file: %u\n", frequencyHz);
_outFileB.Open(out_file_b, frequencyHz, "wb");
ref_file_name = webrtc::test::OutputPath() + "ref_outB.pcm";
_outFileRefB.Open(ref_file_name, frequencyHz, "wb");
//--- Set A-to-B channel
_channel_A2B = new Channel;
_acmA->RegisterTransportCallback(_channel_A2B);
_channel_A2B->RegisterReceiverACM(_acmB);
//--- Do the same for the reference
_channelRef_A2B = new Channel;
_acmRefA->RegisterTransportCallback(_channelRef_A2B);
_channelRef_A2B->RegisterReceiverACM(_acmRefB);
//--- Set B-to-A channel
_channel_B2A = new Channel;
_acmB->RegisterTransportCallback(_channel_B2A);
_channel_B2A->RegisterReceiverACM(_acmA);
//--- Do the same for reference
_channelRef_B2A = new Channel;
_acmRefB->RegisterTransportCallback(_channelRef_B2A);
_channelRef_B2A->RegisterReceiverACM(_acmRefA);
// The clicks will be more obvious when we
// are in FAX mode.
_acmB->SetPlayoutMode(fax);
_acmRefB->SetPlayoutMode(fax);
return 0;
}
int16_t TwoWayCommunication::SetUpAutotest() {
_acmA = AudioCodingModule::Create(1);
_acmB = AudioCodingModule::Create(2);
_acmRefA = AudioCodingModule::Create(3);
_acmRefB = AudioCodingModule::Create(4);
CodecInst codecInst_A;
CodecInst codecInst_B;
CodecInst dummyCodec;
_acmA->Codec("ISAC", &codecInst_A, 16000, 1);
_acmB->Codec("L16", &codecInst_B, 8000, 1);
_acmA->Codec(6, &dummyCodec);
//--- Set A codecs
CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorA = new(DTMFDetector);
CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA,
ACMUSA));
#endif
//--- Set ref-A codecs
CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B));
//--- Set B codecs
CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorB = new(DTMFDetector);
CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB,
ACMUSA));
#endif
//--- Set ref-B codecs
CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A));
uint16_t frequencyHz;
//--- Input A and B
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");
//--- Output A
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";
_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";
_outFileRefB.Open(output_ref_file_b, frequencyHz, "wb");
//--- Set A-to-B channel
_channel_A2B = new Channel;
_acmA->RegisterTransportCallback(_channel_A2B);
_channel_A2B->RegisterReceiverACM(_acmB);
//--- Do the same for the reference
_channelRef_A2B = new Channel;
_acmRefA->RegisterTransportCallback(_channelRef_A2B);
_channelRef_A2B->RegisterReceiverACM(_acmRefB);
//--- Set B-to-A channel
_channel_B2A = new Channel;
_acmB->RegisterTransportCallback(_channel_B2A);
_channel_B2A->RegisterReceiverACM(_acmA);
//--- Do the same for reference
_channelRef_B2A = new Channel;
_acmRefB->RegisterTransportCallback(_channelRef_B2A);
_channelRef_B2A->RegisterReceiverACM(_acmRefA);
// The clicks will be more obvious when we
// are in FAX mode.
_acmB->SetPlayoutMode(fax);
_acmRefB->SetPlayoutMode(fax);
return 0;
}
void TwoWayCommunication::Perform() {
if (_testMode == 0) {
printf("Running TwoWayCommunication Test");
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- TwoWayCommunication ----------");
SetUpAutotest();
} else {
SetUp();
}
unsigned int msecPassed = 0;
unsigned int secPassed = 0;
int32_t outFreqHzA = _outFileA.SamplingFrequency();
int32_t outFreqHzB = _outFileB.SamplingFrequency();
AudioFrame audioFrame;
CodecInst codecInst_B;
CodecInst dummy;
_acmB->SendCodec(&codecInst_B);
if (_testMode != 0) {
printf("\n");
return 0;
}
printf("sec:msec A B\n");
printf("-------- ----- -----\n");
}
int16_t TwoWayCommunication::SetUp()
{
_acmA = AudioCodingModule::Create(1);
_acmB = AudioCodingModule::Create(2);
while (!_inFileA.EndOfFile() && !_inFileB.EndOfFile()) {
_inFileA.Read10MsData(audioFrame);
_acmA->Add10MsData(audioFrame);
_acmRefA->Add10MsData(audioFrame);
_acmRefA = AudioCodingModule::Create(3);
_acmRefB = AudioCodingModule::Create(4);
_inFileB.Read10MsData(audioFrame);
_acmB->Add10MsData(audioFrame);
_acmRefB->Add10MsData(audioFrame);
uint8_t codecID_A;
uint8_t codecID_B;
_acmA->Process();
_acmB->Process();
_acmRefA->Process();
_acmRefB->Process();
ChooseCodec(&codecID_A, &codecID_B);
CodecInst codecInst_A;
CodecInst codecInst_B;
CodecInst dummyCodec;
_acmA->Codec(codecID_A, &codecInst_A);
_acmB->Codec(codecID_B, &codecInst_B);
_acmA->PlayoutData10Ms(outFreqHzA, &audioFrame);
_outFileA.Write10MsData(audioFrame);
_acmA->Codec(6, &dummyCodec);
_acmRefA->PlayoutData10Ms(outFreqHzA, &audioFrame);
_outFileRefA.Write10MsData(audioFrame);
//--- Set A codecs
CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorA = new(DTMFDetector);
CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA,
ACMUSA));
#endif
//--- Set ref-A codecs
CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B));
_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame);
_outFileB.Write10MsData(audioFrame);
//--- Set B codecs
CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorB = new(DTMFDetector);
CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB,
ACMUSA));
#endif
_acmRefB->PlayoutData10Ms(outFreqHzB, &audioFrame);
_outFileRefB.Write10MsData(audioFrame);
//--- Set ref-B codecs
CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A));
uint16_t frequencyHz;
//--- Input A
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);
_inFileA.Open(in_file_name, frequencyHz, "rb");
//--- Output A
std::string out_file_a = webrtc::test::OutputPath() + "outA.pcm";
printf("Output file at side A: %s\n", out_file_a.c_str());
printf("Sampling frequency (in Hz) of the above file: %u\n",
frequencyHz);
_outFileA.Open(out_file_a, frequencyHz, "wb");
std::string ref_file_name = webrtc::test::OutputPath() + "ref_outA.pcm";
_outFileRefA.Open(ref_file_name, frequencyHz, "wb");
//--- Input B
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);
_inFileB.Open(in_file_name, frequencyHz, "rb");
//--- Output B
std::string out_file_b = webrtc::test::OutputPath() + "outB.pcm";
printf("Output file at side B: %s\n", out_file_b.c_str());
printf("Sampling frequency (in Hz) of the above file: %u\n",
frequencyHz);
_outFileB.Open(out_file_b, frequencyHz, "wb");
ref_file_name = webrtc::test::OutputPath() + "ref_outB.pcm";
_outFileRefB.Open(ref_file_name, frequencyHz, "wb");
//--- Set A-to-B channel
_channel_A2B = new Channel;
_acmA->RegisterTransportCallback(_channel_A2B);
_channel_A2B->RegisterReceiverACM(_acmB);
//--- Do the same for the reference
_channelRef_A2B = new Channel;
_acmRefA->RegisterTransportCallback(_channelRef_A2B);
_channelRef_A2B->RegisterReceiverACM(_acmRefB);
//--- Set B-to-A channel
_channel_B2A = new Channel;
_acmB->RegisterTransportCallback(_channel_B2A);
_channel_B2A->RegisterReceiverACM(_acmA);
//--- Do the same for reference
_channelRef_B2A = new Channel;
_acmRefB->RegisterTransportCallback(_channelRef_B2A);
_channelRef_B2A->RegisterReceiverACM(_acmRefA);
// The clicks will be more obvious when we
// are in FAX mode.
_acmB->SetPlayoutMode(fax);
_acmRefB->SetPlayoutMode(fax);
return 0;
}
int16_t TwoWayCommunication::SetUpAutotest()
{
_acmA = AudioCodingModule::Create(1);
_acmB = AudioCodingModule::Create(2);
_acmRefA = AudioCodingModule::Create(3);
_acmRefB = AudioCodingModule::Create(4);
CodecInst codecInst_A;
CodecInst codecInst_B;
CodecInst dummyCodec;
_acmA->Codec("ISAC", &codecInst_A, 16000, 1);
_acmB->Codec("L16", &codecInst_B, 8000, 1);
_acmA->Codec(6, &dummyCodec);
//--- Set A codecs
CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorA = new(DTMFDetector);
CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA,
ACMUSA));
#endif
//--- Set ref-A codecs
CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A));
CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B));
//--- Set B codecs
CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A));
#ifdef WEBRTC_DTMF_DETECTION
_dtmfDetectorB = new(DTMFDetector);
CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB,
ACMUSA));
#endif
//--- Set ref-B codecs
CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A));
uint16_t frequencyHz;
//--- Input A and B
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");
//--- Output A
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";
_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";
_outFileRefB.Open(output_ref_file_b, frequencyHz, "wb");
//--- Set A-to-B channel
_channel_A2B = new Channel;
_acmA->RegisterTransportCallback(_channel_A2B);
_channel_A2B->RegisterReceiverACM(_acmB);
//--- Do the same for the reference
_channelRef_A2B = new Channel;
_acmRefA->RegisterTransportCallback(_channelRef_A2B);
_channelRef_A2B->RegisterReceiverACM(_acmRefB);
//--- Set B-to-A channel
_channel_B2A = new Channel;
_acmB->RegisterTransportCallback(_channel_B2A);
_channel_B2A->RegisterReceiverACM(_acmA);
//--- Do the same for reference
_channelRef_B2A = new Channel;
_acmRefB->RegisterTransportCallback(_channelRef_B2A);
_channelRef_B2A->RegisterReceiverACM(_acmRefA);
// The clicks will be more obvious when we
// are in FAX mode.
_acmB->SetPlayoutMode(fax);
_acmRefB->SetPlayoutMode(fax);
return 0;
}
void
TwoWayCommunication::Perform()
{
if(_testMode == 0)
{
printf("Running TwoWayCommunication Test");
msecPassed += 10;
if (msecPassed >= 1000) {
msecPassed = 0;
secPassed++;
}
if (((secPassed % 5) == 4) && (msecPassed == 0)) {
if (_testMode != 0) {
printf("%3u:%3u ", secPassed, msecPassed);
}
_acmA->ResetEncoder();
if (_testMode == 0) {
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- TwoWayCommunication ----------");
SetUpAutotest();
"---------- Errors expected");
printf(".");
} else {
printf("Reset Encoder (click in side B) ");
printf("Initialize Sender (no audio in side A)\n");
}
CHECK_ERROR(_acmB->InitializeSender());
}
else
{
SetUp();
if (((secPassed % 5) == 4) && (msecPassed >= 990)) {
if (_testMode == 0) {
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"----- END: Errors expected");
printf(".");
} else {
printf("%3u:%3u ", secPassed, msecPassed);
printf(" ");
printf("Register Send Codec (audio back in side A)\n");
}
CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmB->SendCodec(&dummy));
}
unsigned int msecPassed = 0;
unsigned int secPassed = 0;
int32_t outFreqHzA = _outFileA.SamplingFrequency();
int32_t outFreqHzB = _outFileB.SamplingFrequency();
AudioFrame audioFrame;
CodecInst codecInst_B;
CodecInst dummy;
_acmB->SendCodec(&codecInst_B);
if(_testMode != 0)
{
printf("\n");
printf("sec:msec A B\n");
printf("-------- ----- -----\n");
if (((secPassed % 7) == 6) && (msecPassed == 0)) {
CHECK_ERROR(_acmB->ResetDecoder());
if (_testMode == 0) {
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- Errors expected");
printf(".");
} else {
printf("%3u:%3u ", secPassed, msecPassed);
printf("Initialize Receiver (no audio in side A) ");
printf("Reset Decoder\n");
}
CHECK_ERROR(_acmA->InitializeReceiver());
}
while(!_inFileA.EndOfFile() && !_inFileB.EndOfFile())
{
_inFileA.Read10MsData(audioFrame);
_acmA->Add10MsData(audioFrame);
_acmRefA->Add10MsData(audioFrame);
_inFileB.Read10MsData(audioFrame);
_acmB->Add10MsData(audioFrame);
_acmRefB->Add10MsData(audioFrame);
_acmA->Process();
_acmB->Process();
_acmRefA->Process();
_acmRefB->Process();
_acmA->PlayoutData10Ms(outFreqHzA, &audioFrame);
_outFileA.Write10MsData(audioFrame);
_acmRefA->PlayoutData10Ms(outFreqHzA, &audioFrame);
_outFileRefA.Write10MsData(audioFrame);
_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame);
_outFileB.Write10MsData(audioFrame);
_acmRefB->PlayoutData10Ms(outFreqHzB, &audioFrame);
_outFileRefB.Write10MsData(audioFrame);
msecPassed += 10;
if(msecPassed >= 1000)
{
msecPassed = 0;
secPassed++;
}
if(((secPassed%5) == 4) && (msecPassed == 0))
{
if(_testMode != 0)
{
printf("%3u:%3u ", secPassed, msecPassed);
}
_acmA->ResetEncoder();
if(_testMode == 0)
{
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- Errors expected");
printf(".");
}
else
{
printf("Reset Encoder (click in side B) ");
printf("Initialize Sender (no audio in side A)\n");
}
CHECK_ERROR(_acmB->InitializeSender());
}
if(((secPassed%5) == 4) && (msecPassed >= 990))
{
if(_testMode == 0)
{
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"----- END: Errors expected");
printf(".");
}
else
{
printf("%3u:%3u ", secPassed, msecPassed);
printf(" ");
printf("Register Send Codec (audio back in side A)\n");
}
CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B));
CHECK_ERROR(_acmB->SendCodec(&dummy));
}
if(((secPassed%7) == 6) && (msecPassed == 0))
{
CHECK_ERROR(_acmB->ResetDecoder());
if(_testMode == 0)
{
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- Errors expected");
printf(".");
}
else
{
printf("%3u:%3u ", secPassed, msecPassed);
printf("Initialize Receiver (no audio in side A) ");
printf("Reset Decoder\n");
}
CHECK_ERROR(_acmA->InitializeReceiver());
}
if(((secPassed%7) == 6) && (msecPassed >= 990))
{
if(_testMode == 0)
{
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"----- END: Errors expected");
printf(".");
}
else
{
printf("%3u:%3u ", secPassed, msecPassed);
printf("Register Receive Coded (audio back in side A)\n");
}
CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B));
}
//Sleep(9);
}
if(_testMode == 0)
{
printf("Done!\n");
if (((secPassed % 7) == 6) && (msecPassed >= 990)) {
if (_testMode == 0) {
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"----- END: Errors expected");
printf(".");
} else {
printf("%3u:%3u ", secPassed, msecPassed);
printf("Register Receive Coded (audio back in side A)\n");
}
CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B));
}
//Sleep(9);
}
if (_testMode == 0) {
printf("Done!\n");
}
#ifdef WEBRTC_DTMF_DETECTION
printf("\nDTMF at Side A\n");
_dtmfDetectorA->PrintDetectedDigits();
printf("\nDTMF at Side A\n");
_dtmfDetectorA->PrintDetectedDigits();
printf("\nDTMF at Side B\n");
_dtmfDetectorB->PrintDetectedDigits();
printf("\nDTMF at Side B\n");
_dtmfDetectorB->PrintDetectedDigits();
#endif
}
} // namespace webrtc
} // namespace webrtc

View File

@ -19,42 +19,41 @@
namespace webrtc {
class TwoWayCommunication : public ACMTest
{
public:
TwoWayCommunication(int testMode = 1);
~TwoWayCommunication();
class TwoWayCommunication : public ACMTest {
public:
TwoWayCommunication(int testMode = 1);
~TwoWayCommunication();
void Perform();
private:
uint8_t ChooseCodec(uint8_t* codecID_A, uint8_t* codecID_B);
int16_t SetUp();
int16_t SetUpAutotest();
void Perform();
private:
uint8_t ChooseCodec(uint8_t* codecID_A, uint8_t* codecID_B);
int16_t SetUp();
int16_t SetUpAutotest();
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
AudioCodingModule* _acmRefA;
AudioCodingModule* _acmRefB;
AudioCodingModule* _acmRefA;
AudioCodingModule* _acmRefB;
Channel* _channel_A2B;
Channel* _channel_B2A;
Channel* _channel_A2B;
Channel* _channel_B2A;
Channel* _channelRef_A2B;
Channel* _channelRef_B2A;
Channel* _channelRef_A2B;
Channel* _channelRef_B2A;
PCMFile _inFileA;
PCMFile _inFileB;
PCMFile _inFileA;
PCMFile _inFileB;
PCMFile _outFileA;
PCMFile _outFileB;
PCMFile _outFileA;
PCMFile _outFileB;
PCMFile _outFileRefA;
PCMFile _outFileRefB;
PCMFile _outFileRefA;
PCMFile _outFileRefB;
int _testMode;
int _testMode;
};
} // namespace webrtc
} // namespace webrtc
#endif

View File

@ -63,25 +63,24 @@ class DelayTest {
public:
DelayTest()
: acm_a_(NULL),
acm_b_(NULL),
channel_a2b_(NULL),
test_cntr_(0),
encoding_sample_rate_hz_(8000) {
}
: acm_a_(NULL),
acm_b_(NULL),
channel_a2b_(NULL),
test_cntr_(0),
encoding_sample_rate_hz_(8000) {}
~DelayTest() {}
void TearDown() {
if(acm_a_ != NULL) {
if (acm_a_ != NULL) {
AudioCodingModule::Destroy(acm_a_);
acm_a_ = NULL;
}
if(acm_b_ != NULL) {
if (acm_b_ != NULL) {
AudioCodingModule::Destroy(acm_b_);
acm_b_ = NULL;
}
if(channel_a2b_ != NULL) {
if (channel_a2b_ != NULL) {
delete channel_a2b_;
channel_a2b_ = NULL;
}
@ -89,8 +88,8 @@ class DelayTest {
void SetUp() {
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 (FLAGS_input_file.size() > 0)
file_name = FLAGS_input_file;
in_file_a_.Open(file_name, 32000, "rb");
@ -108,15 +107,15 @@ class DelayTest {
uint8_t num_encoders = acm_a_->NumberOfCodecs();
CodecInst my_codec_param;
for(int n = 0; n < num_encoders; n++) {
for (int n = 0; n < num_encoders; n++) {
acm_b_->Codec(n, &my_codec_param);
if (STR_CASE_CMP(my_codec_param.plname, "opus") == 0)
my_codec_param.channels = 1;
else if (my_codec_param.channels > 1)
else if (my_codec_param.channels > 1)
continue;
if (STR_CASE_CMP(my_codec_param.plname, "CN") == 0 &&
my_codec_param.plfreq == 48000)
continue;
continue;
if (STR_CASE_CMP(my_codec_param.plname, "telephone-event") == 0)
continue;
acm_b_->RegisterReceiveCodec(my_codec_param);
@ -141,14 +140,13 @@ class DelayTest {
void ApplyConfig(const Config& 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");
"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);
@ -156,9 +154,10 @@ class DelayTest {
void SendCodec(const CodecConfig& config) {
CodecInst my_codec_param;
ASSERT_EQ(0, AudioCodingModule::Codec(config.name, &my_codec_param,
config.sample_rate_hz,
config.num_channels));
ASSERT_EQ(
0,
AudioCodingModule::Codec(config.name, &my_codec_param,
config.sample_rate_hz, config.num_channels));
encoding_sample_rate_hz_ = my_codec_param.plfreq;
ASSERT_EQ(0, acm_a_->RegisterSendCodec(my_codec_param));
}
@ -174,11 +173,9 @@ class DelayTest {
void OpenOutFile(const char* output_id) {
std::stringstream file_stream;
file_stream << "delay_test_" << FLAGS_codec << "_"
<< FLAGS_sample_rate_hz << "Hz" << "_"
<< FLAGS_init_delay << "ms_"
<< FLAGS_delay << "ms.pcm";
std::cout << "Output file: " << file_stream.str() << std::endl <<std::endl;
file_stream << "delay_test_" << FLAGS_codec << "_" << FLAGS_sample_rate_hz
<< "Hz" << "_" << FLAGS_init_delay << "ms_" << FLAGS_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");
}
@ -194,7 +191,7 @@ class DelayTest {
uint32_t received_ts;
double average_delay = 0;
double inst_delay_sec = 0;
while(num_frames < (duration_sec * 100)) {
while (num_frames < (duration_sec * 100)) {
if (in_file_a_.EndOfFile()) {
in_file_a_.Rewind();
}
@ -206,27 +203,24 @@ class DelayTest {
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.minWaitingTimeMs, statistics.maxWaitingTimeMs,
statistics.meanWaitingTimeMs, statistics.medianWaitingTimeMs,
average_delay, statistics.currentBufferSize,
statistics.preferredBufferSize);
fflush(stdout);
fflush (stdout);
}
in_file_a_.Read10MsData(audio_frame);
ASSERT_EQ(0, acm_a_->Add10MsData(audio_frame));
ASSERT_LE(0, acm_a_->Process());
ASSERT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
out_file_b_.Write10MsData(audio_frame.data_,
audio_frame.samples_per_channel_ *
audio_frame.num_channels_);
out_file_b_.Write10MsData(
audio_frame.data_,
audio_frame.samples_per_channel_ * audio_frame.num_channels_);
acm_b_->PlayoutTimestamp(&playout_ts);
received_ts = channel_a2b_->LastInTimestamp();
inst_delay_sec = static_cast<uint32_t>(received_ts - playout_ts) /
static_cast<double>(encoding_sample_rate_hz_);
inst_delay_sec = static_cast<uint32_t>(received_ts - playout_ts)
/ static_cast<double>(encoding_sample_rate_hz_);
if (num_frames > 10)
average_delay = 0.95 * average_delay + 0.05 * inst_delay_sec;
@ -248,7 +242,7 @@ class DelayTest {
int encoding_sample_rate_hz_;
};
} // namespace webrtc
} // namespace webrtc
int main(int argc, char* argv[]) {

View File

@ -17,30 +17,27 @@
#include "testsupport/fileutils.h"
#include "typedefs.h"
namespace webrtc {
class DualStreamTest : public AudioPacketizationCallback,
public ::testing::Test {
class DualStreamTest :
public AudioPacketizationCallback,
public ::testing::Test {
protected:
DualStreamTest();
~DualStreamTest();
int32_t SendData(FrameType frameType, uint8_t payload_type,
uint32_t timestamp,
const uint8_t* payload_data,
uint32_t timestamp, const uint8_t* payload_data,
uint16_t payload_size,
const RTPFragmentationHeader* fragmentation);
void Perform(bool start_in_sync, int num_channels_input);
void InitializeSender(int frame_size_primary_samples,
int num_channels_primary,
int sampling_rate);
int num_channels_primary, int sampling_rate);
void PopulateCodecInstances(int frame_size_primary_ms,
int num_channels_primary,
int sampling_rate);
int num_channels_primary, int sampling_rate);
void Validate(bool start_in_sync, int tolerance);
bool EqualTimestamp(int stream, int position);
@ -49,7 +46,11 @@ public ::testing::Test {
static const int kMaxNumStoredPayloads = 2;
enum {kPrimary = 0, kSecondary, kMaxNumStreams};
enum {
kPrimary = 0,
kSecondary,
kMaxNumStreams
};
AudioCodingModule* acm_dual_stream_;
AudioCodingModule* acm_ref_primary_;
@ -69,10 +70,10 @@ public ::testing::Test {
int payload_len_ref_[kMaxNumStreams][kMaxNumStoredPayloads];
int payload_len_dual_[kMaxNumStreams][kMaxNumStoredPayloads];
uint8_t payload_data_ref_[kMaxNumStreams]
[MAX_PAYLOAD_SIZE_BYTE * kMaxNumStoredPayloads];
uint8_t payload_data_dual_[kMaxNumStreams]
[MAX_PAYLOAD_SIZE_BYTE * kMaxNumStoredPayloads];
uint8_t payload_data_ref_[kMaxNumStreams][MAX_PAYLOAD_SIZE_BYTE
* kMaxNumStoredPayloads];
uint8_t payload_data_dual_[kMaxNumStreams][MAX_PAYLOAD_SIZE_BYTE
* kMaxNumStoredPayloads];
int num_received_payloads_dual_[kMaxNumStreams];
int num_received_payloads_ref_[kMaxNumStreams];
@ -92,7 +93,8 @@ DualStreamTest::DualStreamTest()
num_received_payloads_ref_(),
num_compared_payloads_(),
last_timestamp_(),
received_payload_() {}
received_payload_() {
}
DualStreamTest::~DualStreamTest() {
AudioCodingModule::Destroy(acm_dual_stream_);
@ -112,17 +114,17 @@ void DualStreamTest::PopulateCodecInstances(int frame_size_primary_ms,
for (int n = 0; n < AudioCodingModule::NumberOfCodecs(); n++) {
AudioCodingModule::Codec(n, &my_codec);
if (strcmp(my_codec.plname, "ISAC") == 0 &&
my_codec.plfreq == sampling_rate) {
if (strcmp(my_codec.plname, "ISAC") == 0
&& my_codec.plfreq == sampling_rate) {
my_codec.rate = 32000;
my_codec.pacsize = 30 * sampling_rate / 1000;
memcpy(&secondary_encoder_, &my_codec, sizeof(my_codec));
} else if (strcmp(my_codec.plname, "L16") == 0 &&
my_codec.channels == num_channels_primary &&
my_codec.plfreq == sampling_rate) {
} else if (strcmp(my_codec.plname, "L16") == 0
&& my_codec.channels == num_channels_primary
&& my_codec.plfreq == sampling_rate) {
my_codec.pacsize = frame_size_primary_ms * sampling_rate / 1000;
memcpy(&primary_encoder_, &my_codec, sizeof(my_codec));
} else if (strcmp(my_codec.plname, "red") == 0) {
} else if (strcmp(my_codec.plname, "red") == 0) {
memcpy(&red_encoder_, &my_codec, sizeof(my_codec));
}
}
@ -160,15 +162,16 @@ void DualStreamTest::InitializeSender(int frame_size_primary_samples,
void DualStreamTest::Perform(bool start_in_sync, int num_channels_input) {
PCMFile pcm_file;
std::string file_name = test::ResourcePath(
(num_channels_input == 1) ? "audio_coding/testfile32kHz" :
"audio_coding/teststereo32kHz", "pcm");
(num_channels_input == 1) ?
"audio_coding/testfile32kHz" : "audio_coding/teststereo32kHz",
"pcm");
pcm_file.Open(file_name, 32000, "rb");
pcm_file.ReadStereo(num_channels_input == 2);
AudioFrame audio_frame;
int tolerance = 0;
if (num_channels_input == 2 && primary_encoder_.channels == 2 &&
secondary_encoder_.channels == 1) {
if (num_channels_input == 2 && primary_encoder_.channels == 2
&& secondary_encoder_.channels == 1) {
tolerance = 12;
}
@ -215,10 +218,11 @@ void DualStreamTest::Perform(bool start_in_sync, int num_channels_input) {
// later and the input file may end before the "next" payload .
EXPECT_EQ(num_received_payloads_ref_[kPrimary],
num_received_payloads_dual_[kPrimary]);
EXPECT_TRUE(num_received_payloads_ref_[kSecondary] ==
num_received_payloads_dual_[kSecondary] ||
num_received_payloads_ref_[kSecondary] ==
(num_received_payloads_dual_[kSecondary] + 1));
EXPECT_TRUE(
num_received_payloads_ref_[kSecondary]
== num_received_payloads_dual_[kSecondary]
|| num_received_payloads_ref_[kSecondary]
== (num_received_payloads_dual_[kSecondary] + 1));
// Make sure all received payloads are compared.
if (start_in_sync) {
@ -237,25 +241,27 @@ void DualStreamTest::Perform(bool start_in_sync, int num_channels_input) {
}
bool DualStreamTest::EqualTimestamp(int stream_index, int position) {
if (timestamp_dual_[stream_index][position] !=
timestamp_ref_[stream_index][position]) {
if (timestamp_dual_[stream_index][position]
!= timestamp_ref_[stream_index][position]) {
return false;
}
return true;
}
int DualStreamTest::EqualPayloadLength(int stream_index, int position) {
return abs(payload_len_dual_[stream_index][position] -
payload_len_ref_[stream_index][position]);
return abs(
payload_len_dual_[stream_index][position]
- payload_len_ref_[stream_index][position]);
}
bool DualStreamTest::EqualPayloadData(int stream_index, int position) {
assert(payload_len_dual_[stream_index][position] ==
payload_len_ref_[stream_index][position]);
assert(
payload_len_dual_[stream_index][position]
== payload_len_ref_[stream_index][position]);
int offset = position * MAX_PAYLOAD_SIZE_BYTE;
for (int n = 0; n < payload_len_dual_[stream_index][position]; n++) {
if (payload_data_dual_[stream_index][offset + n] !=
payload_data_ref_[stream_index][offset + n]) {
if (payload_data_dual_[stream_index][offset + n]
!= payload_data_ref_[stream_index][offset + n]) {
return false;
}
}
@ -266,10 +272,10 @@ void DualStreamTest::Validate(bool start_in_sync, int tolerance) {
for (int stream_index = 0; stream_index < kMaxNumStreams; stream_index++) {
int my_tolerance = stream_index == kPrimary ? 0 : tolerance;
for (int position = 0; position < kMaxNumStoredPayloads; position++) {
if (payload_ref_is_stored_[stream_index][position] == 1 &&
payload_dual_is_stored_[stream_index][position] == 1) {
if (payload_ref_is_stored_[stream_index][position] == 1
&& payload_dual_is_stored_[stream_index][position] == 1) {
// Check timestamps only if codecs started in sync or it is primary.
if (start_in_sync || stream_index == 0)
if (start_in_sync || stream_index == 0)
EXPECT_TRUE(EqualTimestamp(stream_index, position));
EXPECT_LE(EqualPayloadLength(stream_index, position), my_tolerance);
if (my_tolerance == 0)
@ -282,10 +288,11 @@ void DualStreamTest::Validate(bool start_in_sync, int tolerance) {
}
}
int32_t DualStreamTest::SendData(
FrameType frameType, uint8_t payload_type, uint32_t timestamp,
const uint8_t* payload_data, uint16_t payload_size,
const RTPFragmentationHeader* fragmentation) {
int32_t DualStreamTest::SendData(FrameType frameType, uint8_t payload_type,
uint32_t timestamp,
const uint8_t* payload_data,
uint16_t payload_size,
const RTPFragmentationHeader* fragmentation) {
int position;
int stream_index;
@ -297,12 +304,12 @@ int32_t DualStreamTest::SendData(
// As the oldest payloads are in the higher indices of fragmentation,
// to be able to check the increment of timestamps are correct we loop
// backward.
for (int n = fragmentation->fragmentationVectorSize - 1; n >= 0 ; --n) {
for (int n = fragmentation->fragmentationVectorSize - 1; n >= 0; --n) {
if (fragmentation->fragmentationPlType[n] == primary_encoder_.pltype) {
// Received primary payload from dual stream.
stream_index = kPrimary;
} else if (fragmentation->fragmentationPlType[n] ==
secondary_encoder_.pltype) {
} else if (fragmentation->fragmentationPlType[n]
== secondary_encoder_.pltype) {
// Received secondary payload from dual stream.
stream_index = kSecondary;
} else {
@ -318,10 +325,10 @@ int32_t DualStreamTest::SendData(
assert(false);
return -1;
}
timestamp_dual_[stream_index][position] = timestamp -
fragmentation->fragmentationTimeDiff[n];
payload_len_dual_[stream_index][position] =
fragmentation->fragmentationLength[n];
timestamp_dual_[stream_index][position] = timestamp
- fragmentation->fragmentationTimeDiff[n];
payload_len_dual_[stream_index][position] = fragmentation
->fragmentationLength[n];
memcpy(
&payload_data_dual_[stream_index][position * MAX_PAYLOAD_SIZE_BYTE],
&payload_data[fragmentation->fragmentationOffset[n]],
@ -329,8 +336,8 @@ int32_t DualStreamTest::SendData(
payload_dual_is_stored_[stream_index][position] = 1;
// Check if timestamps are incremented correctly.
if (received_payload_[stream_index]) {
int t = timestamp_dual_[stream_index][position] -
last_timestamp_[stream_index];
int t = timestamp_dual_[stream_index][position]
- last_timestamp_[stream_index];
if ((stream_index == kPrimary) && (t != primary_encoder_.pacsize)) {
assert(false);
return -1;
@ -460,7 +467,6 @@ TEST_F(DualStreamTest, BitExactAsyncMonoInputMonoPrimaryWb40Ms) {
Perform(false, 1);
}
TEST_F(DualStreamTest, Api) {
PopulateCodecInstances(20, 1, 16000);
CodecInst my_codec;
@ -469,7 +475,7 @@ TEST_F(DualStreamTest, Api) {
// Not allowed to register secondary codec if primary is not registered yet.
ASSERT_EQ(-1,
acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));
acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));
ASSERT_EQ(-1, acm_dual_stream_->SecondarySendCodec(&my_codec));
ASSERT_EQ(0, acm_dual_stream_->RegisterSendCodec(primary_encoder_));
@ -486,7 +492,7 @@ TEST_F(DualStreamTest, Api) {
EXPECT_EQ(VADNormal, vad_mode);
ASSERT_EQ(0,
acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));
acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));
ASSERT_EQ(0, acm_dual_stream_->SecondarySendCodec(&my_codec));
ASSERT_EQ(0, memcmp(&my_codec, &secondary_encoder_, sizeof(my_codec)));
@ -512,4 +518,5 @@ TEST_F(DualStreamTest, Api) {
EXPECT_EQ(VADVeryAggr, vad_mode);
}
} // namespace webrtc
}
// namespace webrtc

View File

@ -32,536 +32,466 @@
namespace webrtc {
void SetISACConfigDefault(
ACMTestISACConfig& isacConfig)
{
isacConfig.currentRateBitPerSec = 0;
isacConfig.currentFrameSizeMsec = 0;
isacConfig.maxRateBitPerSec = 0;
isacConfig.maxPayloadSizeByte = 0;
isacConfig.encodingMode = -1;
isacConfig.initRateBitPerSec = 0;
isacConfig.initFrameSizeInMsec = 0;
isacConfig.enforceFrameSize = false;
return;
void SetISACConfigDefault(ACMTestISACConfig& isacConfig) {
isacConfig.currentRateBitPerSec = 0;
isacConfig.currentFrameSizeMsec = 0;
isacConfig.maxRateBitPerSec = 0;
isacConfig.maxPayloadSizeByte = 0;
isacConfig.encodingMode = -1;
isacConfig.initRateBitPerSec = 0;
isacConfig.initFrameSizeInMsec = 0;
isacConfig.enforceFrameSize = false;
return;
}
int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm,
int testMode) {
int16_t SetISAConfig(
ACMTestISACConfig& isacConfig,
AudioCodingModule* acm,
int testMode)
{
if ((isacConfig.currentRateBitPerSec != 0)
|| (isacConfig.currentFrameSizeMsec != 0)) {
CodecInst sendCodec;
acm->SendCodec(&sendCodec);
if (isacConfig.currentRateBitPerSec < 0) {
sendCodec.rate = -1;
CHECK_ERROR(acm->RegisterSendCodec(sendCodec));
if (testMode != 0) {
printf("ISAC-%s Registered in adaptive (channel-dependent) mode.\n",
(sendCodec.plfreq == 32000) ? "swb" : "wb");
}
} else {
if((isacConfig.currentRateBitPerSec != 0) ||
(isacConfig.currentFrameSizeMsec != 0))
{
CodecInst sendCodec;
acm->SendCodec(&sendCodec);
if(isacConfig.currentRateBitPerSec < 0)
{
sendCodec.rate = -1;
CHECK_ERROR(acm->RegisterSendCodec(sendCodec));
if(testMode != 0)
{
printf("ISAC-%s Registered in adaptive (channel-dependent) mode.\n",
(sendCodec.plfreq == 32000)? "swb":"wb");
}
}
else
{
if(isacConfig.currentRateBitPerSec != 0)
{
sendCodec.rate = isacConfig.currentRateBitPerSec;
}
if(isacConfig.currentFrameSizeMsec != 0)
{
sendCodec.pacsize = isacConfig.currentFrameSizeMsec *
(sendCodec.plfreq / 1000);
}
CHECK_ERROR(acm->RegisterSendCodec(sendCodec));
if(testMode != 0)
{
printf("Target rate is set to %d bit/sec with frame-size %d ms \n",
(int)isacConfig.currentRateBitPerSec,
(int)sendCodec.pacsize / (sendCodec.plfreq / 1000));
}
}
if (isacConfig.currentRateBitPerSec != 0) {
sendCodec.rate = isacConfig.currentRateBitPerSec;
}
if (isacConfig.currentFrameSizeMsec != 0) {
sendCodec.pacsize = isacConfig.currentFrameSizeMsec
* (sendCodec.plfreq / 1000);
}
CHECK_ERROR(acm->RegisterSendCodec(sendCodec));
if (testMode != 0) {
printf("Target rate is set to %d bit/sec with frame-size %d ms \n",
(int) isacConfig.currentRateBitPerSec,
(int) sendCodec.pacsize / (sendCodec.plfreq / 1000));
}
}
}
if(isacConfig.maxRateBitPerSec > 0)
{
CHECK_ERROR(acm->SetISACMaxRate(isacConfig.maxRateBitPerSec));
if(testMode != 0)
{
printf("Max rate is set to %u bit/sec\n",
isacConfig.maxRateBitPerSec);
}
if (isacConfig.maxRateBitPerSec > 0) {
CHECK_ERROR(acm->SetISACMaxRate(isacConfig.maxRateBitPerSec));
if (testMode != 0) {
printf("Max rate is set to %u bit/sec\n", isacConfig.maxRateBitPerSec);
}
if(isacConfig.maxPayloadSizeByte > 0)
{
CHECK_ERROR(acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte));
if(testMode != 0)
{
printf("Max payload-size is set to %u bit/sec\n",
isacConfig.maxPayloadSizeByte);
}
}
if (isacConfig.maxPayloadSizeByte > 0) {
CHECK_ERROR(acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte));
if (testMode != 0) {
printf("Max payload-size is set to %u bit/sec\n",
isacConfig.maxPayloadSizeByte);
}
if((isacConfig.initFrameSizeInMsec != 0) ||
(isacConfig.initRateBitPerSec != 0))
{
CHECK_ERROR(acm->ConfigISACBandwidthEstimator(
(uint8_t)isacConfig.initFrameSizeInMsec,
(uint16_t)isacConfig.initRateBitPerSec,
}
if ((isacConfig.initFrameSizeInMsec != 0)
|| (isacConfig.initRateBitPerSec != 0)) {
CHECK_ERROR(
acm->ConfigISACBandwidthEstimator(
(uint8_t) isacConfig.initFrameSizeInMsec,
(uint16_t) isacConfig.initRateBitPerSec,
isacConfig.enforceFrameSize));
if((isacConfig.initFrameSizeInMsec != 0) && (testMode != 0))
{
printf("Initialize BWE to %d msec frame-size\n",
isacConfig.initFrameSizeInMsec);
}
if((isacConfig.initRateBitPerSec != 0) && (testMode != 0))
{
printf("Initialize BWE to %u bit/sec send-bandwidth\n",
isacConfig.initRateBitPerSec);
}
if ((isacConfig.initFrameSizeInMsec != 0) && (testMode != 0)) {
printf("Initialize BWE to %d msec frame-size\n",
isacConfig.initFrameSizeInMsec);
}
if ((isacConfig.initRateBitPerSec != 0) && (testMode != 0)) {
printf("Initialize BWE to %u bit/sec send-bandwidth\n",
isacConfig.initRateBitPerSec);
}
}
return 0;
return 0;
}
ISACTest::ISACTest(int testMode)
{
_testMode = testMode;
ISACTest::ISACTest(int testMode) {
_testMode = testMode;
}
ISACTest::~ISACTest()
{
AudioCodingModule::Destroy(_acmA);
AudioCodingModule::Destroy(_acmB);
ISACTest::~ISACTest() {
AudioCodingModule::Destroy(_acmA);
AudioCodingModule::Destroy(_acmB);
delete _channel_A2B;
delete _channel_B2A;
delete _channel_A2B;
delete _channel_B2A;
}
int16_t ISACTest::Setup() {
int codecCntr;
CodecInst codecParam;
int16_t
ISACTest::Setup()
{
int codecCntr;
CodecInst codecParam;
_acmA = AudioCodingModule::Create(1);
_acmB = AudioCodingModule::Create(2);
_acmA = AudioCodingModule::Create(1);
_acmB = AudioCodingModule::Create(2);
for(codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs(); codecCntr++)
{
AudioCodingModule::Codec(codecCntr, &codecParam);
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)
{
memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
_idISAC32kHz = codecCntr;
}
for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
codecCntr++) {
AudioCodingModule::Codec(codecCntr, &codecParam);
if (!STR_CASE_CMP(codecParam.plname, "ISAC")
&& codecParam.plfreq == 16000) {
memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
_idISAC16kHz = codecCntr;
}
// register both iSAC-wb & iSAC-swb in both sides as receiver codecs
CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC16kHz));
CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC16kHz));
CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC32kHz));
//--- Set A-to-B channel
_channel_A2B = new Channel;
CHECK_ERROR(_acmA->RegisterTransportCallback(_channel_A2B));
_channel_A2B->RegisterReceiverACM(_acmB);
//--- Set B-to-A channel
_channel_B2A = new Channel;
CHECK_ERROR(_acmB->RegisterTransportCallback(_channel_B2A));
_channel_B2A->RegisterReceiverACM(_acmA);
file_name_swb_ =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
_acmB->RegisterSendCodec(_paramISAC16kHz);
_acmA->RegisterSendCodec(_paramISAC32kHz);
if(_testMode != 0)
{
printf("Side A Send Codec\n");
printf("%s %d\n", _paramISAC32kHz.plname, _paramISAC32kHz.plfreq);
printf("Side B Send Codec\n");
printf("%s %d\n", _paramISAC16kHz.plname, _paramISAC16kHz.plfreq);
if (!STR_CASE_CMP(codecParam.plname, "ISAC")
&& codecParam.plfreq == 32000) {
memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
_idISAC32kHz = codecCntr;
}
}
_inFileA.Open(file_name_swb_, 32000, "rb");
std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
_outFileA.Open(fileNameA, 32000, "wb");
_outFileB.Open(fileNameB, 32000, "wb");
// register both iSAC-wb & iSAC-swb in both sides as receiver codecs
CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC16kHz));
CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC16kHz));
CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC32kHz));
while(!_inFileA.EndOfFile())
{
Run10ms();
}
CodecInst receiveCodec;
CHECK_ERROR(_acmA->ReceiveCodec(&receiveCodec));
if(_testMode != 0)
{
printf("Side A Receive Codec\n");
printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq);
}
//--- Set A-to-B channel
_channel_A2B = new Channel;
CHECK_ERROR(_acmA->RegisterTransportCallback(_channel_A2B));
_channel_A2B->RegisterReceiverACM(_acmB);
CHECK_ERROR(_acmB->ReceiveCodec(&receiveCodec));
if(_testMode != 0)
{
printf("Side B Receive Codec\n");
printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq);
}
//--- Set B-to-A channel
_channel_B2A = new Channel;
CHECK_ERROR(_acmB->RegisterTransportCallback(_channel_B2A));
_channel_B2A->RegisterReceiverACM(_acmA);
_inFileA.Close();
_outFileA.Close();
_outFileB.Close();
file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
"pcm");
return 0;
_acmB->RegisterSendCodec(_paramISAC16kHz);
_acmA->RegisterSendCodec(_paramISAC32kHz);
if (_testMode != 0) {
printf("Side A Send Codec\n");
printf("%s %d\n", _paramISAC32kHz.plname, _paramISAC32kHz.plfreq);
printf("Side B Send Codec\n");
printf("%s %d\n", _paramISAC16kHz.plname, _paramISAC16kHz.plfreq);
}
_inFileA.Open(file_name_swb_, 32000, "rb");
std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
_outFileA.Open(fileNameA, 32000, "wb");
_outFileB.Open(fileNameB, 32000, "wb");
while (!_inFileA.EndOfFile()) {
Run10ms();
}
CodecInst receiveCodec;
CHECK_ERROR(_acmA->ReceiveCodec(&receiveCodec));
if (_testMode != 0) {
printf("Side A Receive Codec\n");
printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq);
}
CHECK_ERROR(_acmB->ReceiveCodec(&receiveCodec));
if (_testMode != 0) {
printf("Side B Receive Codec\n");
printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq);
}
_inFileA.Close();
_outFileA.Close();
_outFileB.Close();
return 0;
}
void ISACTest::Perform() {
if (_testMode == 0) {
printf("Running iSAC Test");
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1,
"---------- iSACTest ----------");
}
void
ISACTest::Perform()
{
if(_testMode == 0)
{
printf("Running iSAC Test");
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1, "---------- iSACTest ----------");
}
Setup();
Setup();
int16_t testNr = 0;
ACMTestISACConfig wbISACConfig;
ACMTestISACConfig swbISACConfig;
int16_t testNr = 0;
ACMTestISACConfig wbISACConfig;
ACMTestISACConfig swbISACConfig;
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
wbISACConfig.currentRateBitPerSec = -1;
swbISACConfig.currentRateBitPerSec = -1;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
if (_testMode != 0) {
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
wbISACConfig.currentRateBitPerSec = -1;
swbISACConfig.currentRateBitPerSec = -1;
wbISACConfig.initRateBitPerSec = 13000;
wbISACConfig.initFrameSizeInMsec = 60;
swbISACConfig.initRateBitPerSec = 20000;
swbISACConfig.initFrameSizeInMsec = 30;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
if (_testMode != 0)
{
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
wbISACConfig.currentRateBitPerSec = -1;
swbISACConfig.currentRateBitPerSec = -1;
wbISACConfig.initRateBitPerSec = 13000;
wbISACConfig.initFrameSizeInMsec = 60;
swbISACConfig.initRateBitPerSec = 20000;
swbISACConfig.initFrameSizeInMsec = 30;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
wbISACConfig.currentRateBitPerSec = 20000;
swbISACConfig.currentRateBitPerSec = 48000;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
wbISACConfig.currentRateBitPerSec = 16000;
swbISACConfig.currentRateBitPerSec = 30000;
wbISACConfig.currentFrameSizeMsec = 60;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
}
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
wbISACConfig.currentRateBitPerSec = 20000;
swbISACConfig.currentRateBitPerSec = 48000;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
int user_input;
if((_testMode == 0) || (_testMode == 1))
{
swbISACConfig.maxPayloadSizeByte = (uint16_t)200;
wbISACConfig.maxPayloadSizeByte = (uint16_t)200;
}
else
{
printf("Enter the max payload-size for side A: ");
CHECK_ERROR(scanf("%d", &user_input));
swbISACConfig.maxPayloadSizeByte = (uint16_t)user_input;
printf("Enter the max payload-size for side B: ");
CHECK_ERROR(scanf("%d", &user_input));
wbISACConfig.maxPayloadSizeByte = (uint16_t)user_input;
}
wbISACConfig.currentRateBitPerSec = 16000;
swbISACConfig.currentRateBitPerSec = 30000;
wbISACConfig.currentFrameSizeMsec = 60;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
}
_acmA->ResetEncoder();
_acmB->ResetEncoder();
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
if((_testMode == 0) || (_testMode == 1))
{
swbISACConfig.maxRateBitPerSec = (uint32_t)48000;
wbISACConfig.maxRateBitPerSec = (uint32_t)48000;
}
else
{
printf("Enter the max rate for side A: ");
CHECK_ERROR(scanf("%d", &user_input));
swbISACConfig.maxRateBitPerSec = (uint32_t)user_input;
printf("Enter the max rate for side B: ");
CHECK_ERROR(scanf("%d", &user_input));
wbISACConfig.maxRateBitPerSec = (uint32_t)user_input;
}
int user_input;
if ((_testMode == 0) || (_testMode == 1)) {
swbISACConfig.maxPayloadSizeByte = (uint16_t) 200;
wbISACConfig.maxPayloadSizeByte = (uint16_t) 200;
} else {
printf("Enter the max payload-size for side A: ");
CHECK_ERROR(scanf("%d", &user_input));
swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
printf("Enter the max payload-size for side B: ");
CHECK_ERROR(scanf("%d", &user_input));
wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
}
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
_acmA->ResetEncoder();
_acmB->ResetEncoder();
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
if ((_testMode == 0) || (_testMode == 1)) {
swbISACConfig.maxRateBitPerSec = (uint32_t) 48000;
wbISACConfig.maxRateBitPerSec = (uint32_t) 48000;
} else {
printf("Enter the max rate for side A: ");
CHECK_ERROR(scanf("%d", &user_input));
swbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
printf("Enter the max rate for side B: ");
CHECK_ERROR(scanf("%d", &user_input));
wbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
}
testNr++;
if(_testMode == 0)
{
SwitchingSamplingRate(testNr, 4);
printf("Done!\n");
}
else
{
SwitchingSamplingRate(testNr, 80);
}
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
testNr++;
if (_testMode == 0) {
SwitchingSamplingRate(testNr, 4);
printf("Done!\n");
} else {
SwitchingSamplingRate(testNr, 80);
}
}
void ISACTest::Run10ms() {
AudioFrame audioFrame;
void
ISACTest::Run10ms()
{
AudioFrame audioFrame;
_inFileA.Read10MsData(audioFrame);
CHECK_ERROR(_acmA->Add10MsData(audioFrame));
_inFileA.Read10MsData(audioFrame);
CHECK_ERROR(_acmA->Add10MsData(audioFrame));
CHECK_ERROR(_acmB->Add10MsData(audioFrame));
CHECK_ERROR(_acmB->Add10MsData(audioFrame));
CHECK_ERROR(_acmA->Process());
CHECK_ERROR(_acmB->Process());
CHECK_ERROR(_acmA->Process());
CHECK_ERROR(_acmB->Process());
CHECK_ERROR(_acmA->PlayoutData10Ms(32000, &audioFrame));
_outFileA.Write10MsData(audioFrame);
CHECK_ERROR(_acmA->PlayoutData10Ms(32000, &audioFrame));
_outFileA.Write10MsData(audioFrame);
CHECK_ERROR(_acmB->PlayoutData10Ms(32000, &audioFrame));
_outFileB.Write10MsData(audioFrame);
CHECK_ERROR(_acmB->PlayoutData10Ms(32000, &audioFrame));
_outFileB.Write10MsData(audioFrame);
}
void
ISACTest::EncodeDecode(
int testNr,
ACMTestISACConfig& wbISACConfig,
ACMTestISACConfig& swbISACConfig)
{
if(_testMode == 0)
{
printf(".");
}
else
{
printf("\nTest %d:\n\n", testNr);
void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
ACMTestISACConfig& swbISACConfig) {
if (_testMode == 0) {
printf(".");
} else {
printf("\nTest %d:\n\n", testNr);
}
// Files in Side A and B
_inFileA.Open(file_name_swb_, 32000, "rb", true);
_inFileB.Open(file_name_swb_, 32000, "rb", true);
std::string file_name_out;
std::stringstream file_stream_a;
std::stringstream file_stream_b;
file_stream_a << webrtc::test::OutputPath();
file_stream_b << webrtc::test::OutputPath();
if (_testMode == 0) {
file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
} else {
file_stream_a << "outA_" << testNr << ".pcm";
file_stream_b << "outB_" << testNr << ".pcm";
}
file_name_out = file_stream_a.str();
_outFileA.Open(file_name_out, 32000, "wb");
file_name_out = file_stream_b.str();
_outFileB.Open(file_name_out, 32000, "wb");
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz));
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
if (_testMode != 0) {
printf("Side A Sending Super-Wideband \n");
printf("Side B Sending Wideband\n\n");
}
SetISAConfig(swbISACConfig, _acmA, _testMode);
SetISAConfig(wbISACConfig, _acmB, _testMode);
bool adaptiveMode = false;
if ((swbISACConfig.currentRateBitPerSec == -1)
|| (wbISACConfig.currentRateBitPerSec == -1)) {
adaptiveMode = true;
}
_myTimer.Reset();
_channel_A2B->ResetStats();
_channel_B2A->ResetStats();
char currentTime[500];
if (_testMode == 2)
printf("\n");
CodecInst sendCodec;
EventWrapper* myEvent = EventWrapper::Create();
myEvent->StartTimer(true, 10);
while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
Run10ms();
_myTimer.Tick10ms();
_myTimer.CurrentTimeHMS(currentTime);
if (_testMode == 2)
printf("\r%s ", currentTime);
if ((adaptiveMode) && (_testMode != 0)) {
myEvent->Wait(5000);
_acmA->SendCodec(&sendCodec);
if (_testMode == 2)
printf("[%d] ", sendCodec.rate);
_acmB->SendCodec(&sendCodec);
if (_testMode == 2)
printf("[%d] ", sendCodec.rate);
}
}
// Files in Side A and B
_inFileA.Open(file_name_swb_, 32000, "rb", true);
_inFileB.Open(file_name_swb_, 32000, "rb", true);
if (_testMode != 0) {
printf("\n\nSide A statistics\n\n");
_channel_A2B->PrintStats(_paramISAC32kHz);
std::string file_name_out;
std::stringstream file_stream_a;
std::stringstream file_stream_b;
file_stream_a << webrtc::test::OutputPath();
file_stream_b << webrtc::test::OutputPath();
if(_testMode == 0)
{
file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
printf("\n\nSide B statistics\n\n");
_channel_B2A->PrintStats(_paramISAC16kHz);
}
}
else
{
file_stream_a << "outA_" << testNr << ".pcm";
file_stream_b << "outB_" << testNr << ".pcm";
}
file_name_out = file_stream_a.str();
_outFileA.Open(file_name_out, 32000, "wb");
file_name_out = file_stream_b.str();
_outFileB.Open(file_name_out, 32000, "wb");
_channel_A2B->ResetStats();
_channel_B2A->ResetStats();
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz));
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
if(_testMode != 0)
{
printf("Side A Sending Super-Wideband \n");
printf("Side B Sending Wideband\n\n");
}
SetISAConfig(swbISACConfig, _acmA, _testMode);
SetISAConfig(wbISACConfig, _acmB, _testMode);
bool adaptiveMode = false;
if((swbISACConfig.currentRateBitPerSec == -1) ||
(wbISACConfig.currentRateBitPerSec == -1))
{
adaptiveMode = true;
}
_myTimer.Reset();
_channel_A2B->ResetStats();
_channel_B2A->ResetStats();
char currentTime[500];
if(_testMode == 2) printf("\n");
CodecInst sendCodec;
EventWrapper* myEvent = EventWrapper::Create();
myEvent->StartTimer(true, 10);
while(!(_inFileA.EndOfFile() || _inFileA.Rewinded()))
{
Run10ms();
_myTimer.Tick10ms();
_myTimer.CurrentTimeHMS(currentTime);
if(_testMode == 2) printf("\r%s ", currentTime);
if((adaptiveMode) && (_testMode != 0))
{
myEvent->Wait(5000);
_acmA->SendCodec(&sendCodec);
if(_testMode == 2) printf("[%d] ", sendCodec.rate);
_acmB->SendCodec(&sendCodec);
if(_testMode == 2) printf("[%d] ", sendCodec.rate);
}
}
if(_testMode != 0)
{
printf("\n\nSide A statistics\n\n");
_channel_A2B->PrintStats(_paramISAC32kHz);
printf("\n\nSide B statistics\n\n");
_channel_B2A->PrintStats(_paramISAC16kHz);
}
_channel_A2B->ResetStats();
_channel_B2A->ResetStats();
if(_testMode != 0) printf("\n");
_outFileA.Close();
_outFileB.Close();
_inFileA.Close();
_inFileB.Close();
if (_testMode != 0)
printf("\n");
_outFileA.Close();
_outFileB.Close();
_inFileA.Close();
_inFileB.Close();
}
void
ISACTest::SwitchingSamplingRate(
int testNr,
int maxSampRateChange)
{
// Files in Side A
_inFileA.Open(file_name_swb_, 32000, "rb");
_inFileB.Open(file_name_swb_, 32000, "rb");
void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
// Files in Side A
_inFileA.Open(file_name_swb_, 32000, "rb");
_inFileB.Open(file_name_swb_, 32000, "rb");
std::string file_name_out;
std::stringstream file_stream_a;
std::stringstream file_stream_b;
file_stream_a << webrtc::test::OutputPath();
file_stream_b << webrtc::test::OutputPath();
if(_testMode == 0)
{
file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
}
else
{
printf("\nTest %d", testNr);
printf(" Alternate between WB and SWB at the sender Side\n\n");
file_stream_a << "outA_" << testNr << ".pcm";
file_stream_b << "outB_" << testNr << ".pcm";
}
file_name_out = file_stream_a.str();
_outFileA.Open(file_name_out, 32000, "wb");
file_name_out = file_stream_b.str();
_outFileB.Open(file_name_out, 32000, "wb");
std::string file_name_out;
std::stringstream file_stream_a;
std::stringstream file_stream_b;
file_stream_a << webrtc::test::OutputPath();
file_stream_b << webrtc::test::OutputPath();
if (_testMode == 0) {
file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
} else {
printf("\nTest %d", testNr);
printf(" Alternate between WB and SWB at the sender Side\n\n");
file_stream_a << "outA_" << testNr << ".pcm";
file_stream_b << "outB_" << testNr << ".pcm";
}
file_name_out = file_stream_a.str();
_outFileA.Open(file_name_out, 32000, "wb");
file_name_out = file_stream_b.str();
_outFileB.Open(file_name_out, 32000, "wb");
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
if(_testMode != 0)
{
printf("Side A Sending Super-Wideband \n");
printf("Side B Sending Wideband\n");
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
if (_testMode != 0) {
printf("Side A Sending Super-Wideband \n");
printf("Side B Sending Wideband\n");
}
int numSendCodecChanged = 0;
_myTimer.Reset();
char currentTime[50];
while (numSendCodecChanged < (maxSampRateChange << 1)) {
Run10ms();
_myTimer.Tick10ms();
_myTimer.CurrentTimeHMS(currentTime);
if (_testMode == 2)
printf("\r%s", currentTime);
if (_inFileA.EndOfFile()) {
if (_inFileA.SamplingFrequency() == 16000) {
if (_testMode != 0)
printf("\nSide A switched to Send Super-Wideband\n");
_inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
} else {
if (_testMode != 0)
printf("\nSide A switched to Send Wideband\n");
_inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz));
}
numSendCodecChanged++;
}
int numSendCodecChanged = 0;
_myTimer.Reset();
char currentTime[50];
while(numSendCodecChanged < (maxSampRateChange<<1))
{
Run10ms();
_myTimer.Tick10ms();
_myTimer.CurrentTimeHMS(currentTime);
if(_testMode == 2) printf("\r%s", currentTime);
if(_inFileA.EndOfFile())
{
if(_inFileA.SamplingFrequency() == 16000)
{
if(_testMode != 0) printf("\nSide A switched to Send Super-Wideband\n");
_inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
}
else
{
if(_testMode != 0) printf("\nSide A switched to Send Wideband\n");
_inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz));
}
numSendCodecChanged++;
}
if(_inFileB.EndOfFile())
{
if(_inFileB.SamplingFrequency() == 16000)
{
if(_testMode != 0) printf("\nSide B switched to Send Super-Wideband\n");
_inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz));
}
else
{
if(_testMode != 0) printf("\nSide B switched to Send Wideband\n");
_inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
}
numSendCodecChanged++;
}
if (_inFileB.EndOfFile()) {
if (_inFileB.SamplingFrequency() == 16000) {
if (_testMode != 0)
printf("\nSide B switched to Send Super-Wideband\n");
_inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz));
} else {
if (_testMode != 0)
printf("\nSide B switched to Send Wideband\n");
_inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb");
CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
}
numSendCodecChanged++;
}
_outFileA.Close();
_outFileB.Close();
_inFileA.Close();
_inFileB.Close();
}
_outFileA.Close();
_outFileB.Close();
_inFileA.Close();
_inFileB.Close();
}
} // namespace webrtc
} // namespace webrtc

View File

@ -25,80 +25,70 @@
namespace webrtc {
struct ACMTestISACConfig
{
int32_t currentRateBitPerSec;
int16_t currentFrameSizeMsec;
uint32_t maxRateBitPerSec;
int16_t maxPayloadSizeByte;
int16_t encodingMode;
uint32_t initRateBitPerSec;
int16_t initFrameSizeInMsec;
bool enforceFrameSize;
struct ACMTestISACConfig {
int32_t currentRateBitPerSec;
int16_t currentFrameSizeMsec;
uint32_t maxRateBitPerSec;
int16_t maxPayloadSizeByte;
int16_t encodingMode;
uint32_t initRateBitPerSec;
int16_t initFrameSizeInMsec;
bool enforceFrameSize;
};
class ISACTest : public ACMTest {
public:
ISACTest(int testMode);
~ISACTest();
void Perform();
private:
int16_t Setup();
int16_t SetupConference();
int16_t RunConference();
class ISACTest : public ACMTest
{
public:
ISACTest(int testMode);
~ISACTest();
void Run10ms();
void Perform();
private:
int16_t Setup();
int16_t SetupConference();
int16_t RunConference();
void EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
ACMTestISACConfig& swbISACConfig);
void TestBWE(int testNr);
void Run10ms();
void SwitchingSamplingRate(int testNr, int maxSampRateChange);
void EncodeDecode(
int testNr,
ACMTestISACConfig& wbISACConfig,
ACMTestISACConfig& swbISACConfig);
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
void TestBWE(
int testNr);
Channel* _channel_A2B;
Channel* _channel_B2A;
void SwitchingSamplingRate(
int testNr,
int maxSampRateChange);
PCMFile _inFileA;
PCMFile _inFileB;
AudioCodingModule* _acmA;
AudioCodingModule* _acmB;
PCMFile _outFileA;
PCMFile _outFileB;
Channel* _channel_A2B;
Channel* _channel_B2A;
uint8_t _idISAC16kHz;
uint8_t _idISAC32kHz;
CodecInst _paramISAC16kHz;
CodecInst _paramISAC32kHz;
PCMFile _inFileA;
PCMFile _inFileB;
std::string file_name_swb_;
PCMFile _outFileA;
PCMFile _outFileB;
ACMTestTimer _myTimer;
int _testMode;
uint8_t _idISAC16kHz;
uint8_t _idISAC32kHz;
CodecInst _paramISAC16kHz;
CodecInst _paramISAC32kHz;
AudioCodingModule* _defaultACM32;
AudioCodingModule* _defaultACM16;
std::string file_name_swb_;
AudioCodingModule* _confACM[NO_OF_CLIENTS];
AudioCodingModule* _clientACM[NO_OF_CLIENTS];
Channel* _conf2Client[NO_OF_CLIENTS];
Channel* _client2Conf[NO_OF_CLIENTS];
ACMTestTimer _myTimer;
int _testMode;
AudioCodingModule* _defaultACM32;
AudioCodingModule* _defaultACM16;
AudioCodingModule* _confACM[NO_OF_CLIENTS];
AudioCodingModule* _clientACM[NO_OF_CLIENTS];
Channel* _conf2Client[NO_OF_CLIENTS];
Channel* _client2Conf[NO_OF_CLIENTS];
PCMFile _clientOutFile[NO_OF_CLIENTS];
PCMFile _clientOutFile[NO_OF_CLIENTS];
};
} // namespace webrtc
} // namespace webrtc
#endif

View File

@ -41,27 +41,28 @@ double FrameRms(AudioFrame& frame) {
}
class InitialPlayoutDelayTest : public ::testing::Test {
class InitialPlayoutDelayTest : public ::testing::Test {
protected:
InitialPlayoutDelayTest()
: acm_a_(NULL),
acm_b_(NULL),
channel_a2b_(NULL) {
: acm_a_(NULL),
acm_b_(NULL),
channel_a2b_(NULL) {
}
~InitialPlayoutDelayTest() {}
~InitialPlayoutDelayTest() {
}
void TearDown() {
if(acm_a_ != NULL) {
if (acm_a_ != NULL) {
AudioCodingModule::Destroy(acm_a_);
acm_a_ = NULL;
}
if(acm_b_ != NULL) {
if (acm_b_ != NULL) {
AudioCodingModule::Destroy(acm_b_);
acm_b_ = NULL;
}
if(channel_a2b_ != NULL) {
if (channel_a2b_ != NULL) {
delete channel_a2b_;
channel_a2b_ = NULL;
}
@ -76,8 +77,8 @@ class InitialPlayoutDelayTest : public ::testing::Test {
// Register all L16 codecs in receiver.
CodecInst codec;
const int kFsHz[3] = {8000, 16000, 32000};
const int kChannels[2] = {1, 2};
const int kFsHz[3] = { 8000, 16000, 32000 };
const int kChannels[2] = { 1, 2 };
for (int n = 0; n < 3; ++n) {
for (int k = 0; k < 2; ++k) {
AudioCodingModule::Codec("L16", &codec, kFsHz[n], kChannels[k]);
@ -109,7 +110,7 @@ class InitialPlayoutDelayTest : public ::testing::Test {
double rms = 0;
acm_a_->RegisterSendCodec(codec);
acm_b_->SetInitialPlayoutDelay(initial_delay_ms);
while(rms < kAmp / 2) {
while (rms < kAmp / 2) {
in_audio_frame.timestamp_ = timestamp;
timestamp += in_audio_frame.samples_per_channel_;
ASSERT_EQ(0, acm_a_->Add10MsData(in_audio_frame));
@ -128,7 +129,6 @@ class InitialPlayoutDelayTest : public ::testing::Test {
Channel* channel_a2b_;
};
TEST_F( InitialPlayoutDelayTest, NbMono) {
CodecInst codec;
AudioCodingModule::Codec("L16", &codec, 8000, 1);
@ -167,4 +167,5 @@ TEST_F( InitialPlayoutDelayTest, SwbStereo) {
// PCM16 super-wideband.
}
} // namespace webrtc
}
// namespace webrtc

View File

@ -23,413 +23,310 @@
namespace webrtc {
ACMTestTimer::ACMTestTimer() :
_msec(0),
_sec(0),
_min(0),
_hour(0)
{
return;
ACMTestTimer::ACMTestTimer()
: _msec(0),
_sec(0),
_min(0),
_hour(0) {
return;
}
ACMTestTimer::~ACMTestTimer()
{
return;
ACMTestTimer::~ACMTestTimer() {
return;
}
void ACMTestTimer::Reset()
{
_msec = 0;
_sec = 0;
_min = 0;
_hour = 0;
return;
void ACMTestTimer::Reset() {
_msec = 0;
_sec = 0;
_min = 0;
_hour = 0;
return;
}
void ACMTestTimer::Tick10ms()
{
_msec += 10;
Adjust();
return;
void ACMTestTimer::Tick10ms() {
_msec += 10;
Adjust();
return;
}
void ACMTestTimer::Tick1ms()
{
_msec++;
Adjust();
return;
void ACMTestTimer::Tick1ms() {
_msec++;
Adjust();
return;
}
void ACMTestTimer::Tick100ms()
{
_msec += 100;
Adjust();
return;
void ACMTestTimer::Tick100ms() {
_msec += 100;
Adjust();
return;
}
void ACMTestTimer::Tick1sec()
{
_sec++;
Adjust();
return;
void ACMTestTimer::Tick1sec() {
_sec++;
Adjust();
return;
}
void ACMTestTimer::CurrentTimeHMS(char* currTime)
{
sprintf(currTime, "%4lu:%02u:%06.3f", _hour, _min, (double)_sec + (double)_msec / 1000.);
return;
void ACMTestTimer::CurrentTimeHMS(char* currTime) {
sprintf(currTime, "%4lu:%02u:%06.3f", _hour, _min,
(double) _sec + (double) _msec / 1000.);
return;
}
void ACMTestTimer::CurrentTime(
unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms)
{
h = _hour;
m = _min;
s = _sec;
ms = _msec;
return;
void ACMTestTimer::CurrentTime(unsigned long& h, unsigned char& m,
unsigned char& s, unsigned short& ms) {
h = _hour;
m = _min;
s = _sec;
ms = _msec;
return;
}
void ACMTestTimer::Adjust()
{
unsigned int n;
if(_msec >= 1000)
{
n = _msec / 1000;
_msec -= (1000 * n);
_sec += n;
}
if(_sec >= 60)
{
n = _sec / 60;
_sec -= (n * 60);
_min += n;
}
if(_min >= 60)
{
n = _min / 60;
_min -= (n * 60);
_hour += n;
void ACMTestTimer::Adjust() {
unsigned int n;
if (_msec >= 1000) {
n = _msec / 1000;
_msec -= (1000 * n);
_sec += n;
}
if (_sec >= 60) {
n = _sec / 60;
_sec -= (n * 60);
_min += n;
}
if (_min >= 60) {
n = _min / 60;
_min -= (n * 60);
_hour += n;
}
}
int16_t ChooseCodec(CodecInst& codecInst) {
PrintCodecs();
//AudioCodingModule* tmpACM = AudioCodingModule::Create(0);
uint8_t noCodec = AudioCodingModule::NumberOfCodecs();
int8_t codecID;
bool outOfRange = false;
char myStr[15] = "";
do {
printf("\nChoose a codec [0]: ");
EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL);
codecID = atoi(myStr);
if ((codecID < 0) || (codecID >= noCodec)) {
printf("\nOut of range.\n");
outOfRange = true;
}
} while (outOfRange);
CHECK_ERROR(AudioCodingModule::Codec((uint8_t )codecID, &codecInst));
return 0;
}
void PrintCodecs() {
uint8_t noCodec = AudioCodingModule::NumberOfCodecs();
int16_t
ChooseCodec(
CodecInst& codecInst)
{
CodecInst codecInst;
printf("No Name [Hz] [bps]\n");
for (uint8_t codecCntr = 0; codecCntr < noCodec; codecCntr++) {
AudioCodingModule::Codec(codecCntr, &codecInst);
printf("%2d- %-18s %5d %6d\n", codecCntr, codecInst.plname,
codecInst.plfreq, codecInst.rate);
}
PrintCodecs();
//AudioCodingModule* tmpACM = AudioCodingModule::Create(0);
uint8_t noCodec = AudioCodingModule::NumberOfCodecs();
int8_t codecID;
bool outOfRange = false;
char myStr[15] = "";
do
{
printf("\nChoose a codec [0]: ");
EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL);
codecID = atoi(myStr);
if((codecID < 0) || (codecID >= noCodec))
{
printf("\nOut of range.\n");
outOfRange = true;
}
} while(outOfRange);
}
CHECK_ERROR(AudioCodingModule::Codec((uint8_t)codecID, &codecInst));
CircularBuffer::CircularBuffer(uint32_t len)
: _buff(NULL),
_idx(0),
_buffIsFull(false),
_calcAvg(false),
_calcVar(false),
_sum(0),
_sumSqr(0) {
_buff = new double[len];
if (_buff == NULL) {
_buffLen = 0;
} else {
for (uint32_t n = 0; n < len; n++) {
_buff[n] = 0;
}
_buffLen = len;
}
}
CircularBuffer::~CircularBuffer() {
if (_buff != NULL) {
delete[] _buff;
_buff = NULL;
}
}
void CircularBuffer::Update(const double newVal) {
assert(_buffLen > 0);
// store the value that is going to be overwritten
double oldVal = _buff[_idx];
// record the new value
_buff[_idx] = newVal;
// increment the index, to point to where we would
// write next
_idx++;
// it is a circular buffer, if we are at the end
// we have to cycle to the beginning
if (_idx >= _buffLen) {
// flag that the buffer is filled up.
_buffIsFull = true;
_idx = 0;
}
// Update
if (_calcAvg) {
// for the average we have to update
// the sum
_sum += (newVal - oldVal);
}
if (_calcVar) {
// to calculate variance we have to update
// the sum of squares
_sumSqr += (double) (newVal - oldVal) * (double) (newVal + oldVal);
}
}
void CircularBuffer::SetArithMean(bool enable) {
assert(_buffLen > 0);
if (enable && !_calcAvg) {
uint32_t lim;
if (_buffIsFull) {
lim = _buffLen;
} else {
lim = _idx;
}
_sum = 0;
for (uint32_t n = 0; n < lim; n++) {
_sum += _buff[n];
}
}
_calcAvg = enable;
}
void CircularBuffer::SetVariance(bool enable) {
assert(_buffLen > 0);
if (enable && !_calcVar) {
uint32_t lim;
if (_buffIsFull) {
lim = _buffLen;
} else {
lim = _idx;
}
_sumSqr = 0;
for (uint32_t n = 0; n < lim; n++) {
_sumSqr += _buff[n] * _buff[n];
}
}
_calcAvg = enable;
}
int16_t CircularBuffer::ArithMean(double& mean) {
assert(_buffLen > 0);
if (_buffIsFull) {
mean = _sum / (double) _buffLen;
return 0;
} else {
if (_idx > 0) {
mean = _sum / (double) _idx;
return 0;
} else {
return -1;
}
}
}
void
PrintCodecs()
{
uint8_t noCodec = AudioCodingModule::NumberOfCodecs();
int16_t CircularBuffer::Variance(double& var) {
assert(_buffLen > 0);
CodecInst codecInst;
printf("No Name [Hz] [bps]\n");
for(uint8_t codecCntr = 0; codecCntr < noCodec; codecCntr++)
{
AudioCodingModule::Codec(codecCntr, &codecInst);
printf("%2d- %-18s %5d %6d\n",
codecCntr, codecInst.plname, codecInst.plfreq, codecInst.rate);
}
}
CircularBuffer::CircularBuffer(uint32_t len):
_buff(NULL),
_idx(0),
_buffIsFull(false),
_calcAvg(false),
_calcVar(false),
_sum(0),
_sumSqr(0)
{
_buff = new double[len];
if(_buff == NULL)
{
_buffLen = 0;
}
else
{
for(uint32_t n = 0; n < len; n++)
{
_buff[n] = 0;
}
_buffLen = len;
}
}
CircularBuffer::~CircularBuffer()
{
if(_buff != NULL)
{
delete [] _buff;
_buff = NULL;
}
}
void
CircularBuffer::Update(
const double newVal)
{
assert(_buffLen > 0);
// store the value that is going to be overwritten
double oldVal = _buff[_idx];
// record the new value
_buff[_idx] = newVal;
// increment the index, to point to where we would
// write next
_idx++;
// it is a circular buffer, if we are at the end
// we have to cycle to the beginning
if(_idx >= _buffLen)
{
// flag that the buffer is filled up.
_buffIsFull = true;
_idx = 0;
}
// Update
if(_calcAvg)
{
// for the average we have to update
// the sum
_sum += (newVal - oldVal);
}
if(_calcVar)
{
// to calculate variance we have to update
// the sum of squares
_sumSqr += (double)(newVal - oldVal) * (double)(newVal + oldVal);
}
}
void
CircularBuffer::SetArithMean(
bool enable)
{
assert(_buffLen > 0);
if(enable && !_calcAvg)
{
uint32_t lim;
if(_buffIsFull)
{
lim = _buffLen;
}
else
{
lim = _idx;
}
_sum = 0;
for(uint32_t n = 0; n < lim; n++)
{
_sum += _buff[n];
}
}
_calcAvg = enable;
}
void
CircularBuffer::SetVariance(
bool enable)
{
assert(_buffLen > 0);
if(enable && !_calcVar)
{
uint32_t lim;
if(_buffIsFull)
{
lim = _buffLen;
}
else
{
lim = _idx;
}
_sumSqr = 0;
for(uint32_t n = 0; n < lim; n++)
{
_sumSqr += _buff[n] * _buff[n];
}
}
_calcAvg = enable;
}
int16_t
CircularBuffer::ArithMean(double& mean)
{
assert(_buffLen > 0);
if(_buffIsFull)
{
mean = _sum / (double)_buffLen;
return 0;
}
else
{
if(_idx > 0)
{
mean = _sum / (double)_idx;
return 0;
}
else
{
return -1;
}
}
}
int16_t
CircularBuffer::Variance(double& var)
{
assert(_buffLen > 0);
if(_buffIsFull)
{
var = _sumSqr / (double)_buffLen;
return 0;
}
else
{
if(_idx > 0)
{
var = _sumSqr / (double)_idx;
return 0;
}
else
{
return -1;
}
}
}
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"
};
for(int n = 0; n < NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE; n++)
{
if(!STR_CASE_CMP(payloadName, fixPayloadTypeCodecs[n]))
{
return true;
}
}
return false;
}
DTMFDetector::DTMFDetector()
{
for(int16_t n = 0; n < 1000; n++)
{
_toneCntr[n] = 0;
}
}
DTMFDetector::~DTMFDetector()
{
}
int32_t DTMFDetector::IncomingDtmf(const uint8_t digitDtmf, const bool /* toneEnded */)
{
fprintf(stdout, "%d-",digitDtmf);
_toneCntr[digitDtmf]++;
if (_buffIsFull) {
var = _sumSqr / (double) _buffLen;
return 0;
}
void DTMFDetector::PrintDetectedDigits()
{
for(int16_t n = 0; n < 1000; n++)
{
if(_toneCntr[n] > 0)
{
fprintf(stdout, "%d %u msec, \n", n, _toneCntr[n]*10);
}
} else {
if (_idx > 0) {
var = _sumSqr / (double) _idx;
return 0;
} else {
return -1;
}
fprintf(stdout, "\n");
return;
}
}
void
VADCallback::Reset()
{
for(int n = 0; n < 6; n++)
{
_numFrameTypes[n] = 0;
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" };
for (int n = 0; n < NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE; n++) {
if (!STR_CASE_CMP(payloadName, fixPayloadTypeCodecs[n])) {
return true;
}
}
return false;
}
VADCallback::VADCallback()
{
for(int n = 0; n < 6; n++)
{
_numFrameTypes[n] = 0;
DTMFDetector::DTMFDetector() {
for (int16_t n = 0; n < 1000; n++) {
_toneCntr[n] = 0;
}
}
DTMFDetector::~DTMFDetector() {
}
int32_t DTMFDetector::IncomingDtmf(const uint8_t digitDtmf,
const bool /* toneEnded */) {
fprintf(stdout, "%d-", digitDtmf);
_toneCntr[digitDtmf]++;
return 0;
}
void DTMFDetector::PrintDetectedDigits() {
for (int16_t n = 0; n < 1000; n++) {
if (_toneCntr[n] > 0) {
fprintf(stdout, "%d %u msec, \n", n, _toneCntr[n] * 10);
}
}
fprintf(stdout, "\n");
return;
}
void
VADCallback::PrintFrameTypes()
{
fprintf(stdout, "No encoding.................. %d\n", _numFrameTypes[0]);
fprintf(stdout, "Active normal encoded........ %d\n", _numFrameTypes[1]);
fprintf(stdout, "Passive normal encoded....... %d\n", _numFrameTypes[2]);
fprintf(stdout, "Passive DTX wideband......... %d\n", _numFrameTypes[3]);
fprintf(stdout, "Passive DTX narrowband....... %d\n", _numFrameTypes[4]);
fprintf(stdout, "Passive DTX super-wideband... %d\n", _numFrameTypes[5]);
void VADCallback::Reset() {
for (int n = 0; n < 6; n++) {
_numFrameTypes[n] = 0;
}
}
int32_t
VADCallback::InFrameType(
int16_t frameType)
{
_numFrameTypes[frameType]++;
return 0;
VADCallback::VADCallback() {
for (int n = 0; n < 6; n++) {
_numFrameTypes[n] = 0;
}
}
} // namespace webrtc
void VADCallback::PrintFrameTypes() {
fprintf(stdout, "No encoding.................. %d\n", _numFrameTypes[0]);
fprintf(stdout, "Active normal encoded........ %d\n", _numFrameTypes[1]);
fprintf(stdout, "Passive normal encoded....... %d\n", _numFrameTypes[2]);
fprintf(stdout, "Passive DTX wideband......... %d\n", _numFrameTypes[3]);
fprintf(stdout, "Passive DTX narrowband....... %d\n", _numFrameTypes[4]);
fprintf(stdout, "Passive DTX super-wideband... %d\n", _numFrameTypes[5]);
}
int32_t VADCallback::InFrameType(int16_t frameType) {
_numFrameTypes[frameType]++;
return 0;
}
} // namespace webrtc

View File

@ -17,166 +17,138 @@
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 DESTROY_ACM(acm) \
do { \
if (acm != NULL) { \
AudioCodingModule::Destroy(acm); \
acm = NULL; \
} \
} while(0)
#define DESTROY_ACM(acm) \
do { \
if(acm != NULL) { \
AudioCodingModule::Destroy(acm); \
acm = NULL; \
} \
} while(0)
#define DELETE_POINTER(p) \
do { \
if (p != NULL) { \
delete p; \
p = NULL; \
} \
} while(0)
class ACMTestTimer {
public:
ACMTestTimer();
~ACMTestTimer();
#define DELETE_POINTER(p) \
do { \
if(p != NULL) { \
delete p; \
p = NULL; \
} \
} while(0)
void Reset();
void Tick10ms();
void Tick1ms();
void Tick100ms();
void Tick1sec();
void CurrentTimeHMS(char* currTime);
void CurrentTime(unsigned long& h, unsigned char& m, unsigned char& s,
unsigned short& ms);
class ACMTestTimer
{
public:
ACMTestTimer();
~ACMTestTimer();
private:
void Adjust();
void Reset();
void Tick10ms();
void Tick1ms();
void Tick100ms();
void Tick1sec();
void CurrentTimeHMS(
char* currTime);
void CurrentTime(
unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms);
private:
void Adjust();
unsigned short _msec;
unsigned char _sec;
unsigned char _min;
unsigned long _hour;
unsigned short _msec;
unsigned char _sec;
unsigned char _min;
unsigned long _hour;
};
class CircularBuffer {
public:
CircularBuffer(uint32_t len);
~CircularBuffer();
void SetArithMean(bool enable);
void SetVariance(bool enable);
class CircularBuffer
{
public:
CircularBuffer(uint32_t len);
~CircularBuffer();
void Update(const double newVal);
void IsBufferFull();
void SetArithMean(
bool enable);
void SetVariance(
bool enable);
int16_t Variance(double& var);
int16_t ArithMean(double& mean);
void Update(
const double newVal);
void IsBufferFull();
protected:
double* _buff;
uint32_t _idx;
uint32_t _buffLen;
int16_t Variance(double& var);
int16_t ArithMean(double& mean);
protected:
double* _buff;
uint32_t _idx;
uint32_t _buffLen;
bool _buffIsFull;
bool _calcAvg;
bool _calcVar;
double _sum;
double _sumSqr;
bool _buffIsFull;
bool _calcAvg;
bool _calcVar;
double _sum;
double _sumSqr;
};
int16_t ChooseCodec(
CodecInst& codecInst);
int16_t ChooseCodec(CodecInst& codecInst);
void PrintCodecs();
bool FixedPayloadTypeCodec(const char* payloadName);
class DTMFDetector : public AudioCodingFeedback {
public:
DTMFDetector();
~DTMFDetector();
// used for inband DTMF detection
int32_t IncomingDtmf(const uint8_t digitDtmf, const bool toneEnded);
void PrintDetectedDigits();
class DTMFDetector: public AudioCodingFeedback
{
public:
DTMFDetector();
~DTMFDetector();
// used for inband DTMF detection
int32_t IncomingDtmf(const uint8_t digitDtmf, const bool toneEnded);
void PrintDetectedDigits();
private:
uint32_t _toneCntr[1000];
private:
uint32_t _toneCntr[1000];
};
class VADCallback : public ACMVADCallback {
public:
VADCallback();
~VADCallback() {
}
int32_t InFrameType(int16_t frameType);
void PrintFrameTypes();
void Reset();
class VADCallback : public ACMVADCallback
{
public:
VADCallback();
~VADCallback(){}
int32_t InFrameType(
int16_t frameType);
void PrintFrameTypes();
void Reset();
private:
uint32_t _numFrameTypes[6];
private:
uint32_t _numFrameTypes[6];
};
} // namespace webrtc