Moving src/webrtc into src/.

In order to eliminate the WebRTC Subtree mirror in Chromium, 
WebRTC is moving the content of the src/webrtc directory up
to the src/ directory.

NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
TBR=tommi@webrtc.org

Bug: chromium:611808
Change-Id: Iac59c5b51b950f174119565bac87955a7994bc38
Reviewed-on: https://webrtc-review.googlesource.com/1560
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Henrik Kjellander <kjellander@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#19845}
This commit is contained in:
Mirko Bonadei
2017-09-15 06:15:48 +02:00
committed by Commit Bot
parent 6674846b4a
commit bb547203bf
4576 changed files with 1092 additions and 1196 deletions

View File

@ -0,0 +1,204 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "NETEQTEST_DummyRTPpacket.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <netinet/in.h> // for htons, htonl, etc
#endif
int NETEQTEST_DummyRTPpacket::readFromFile(FILE *fp)
{
if (!fp)
{
return -1;
}
uint16_t length, plen;
uint32_t offset;
int packetLen = 0;
bool readNextPacket = true;
while (readNextPacket) {
readNextPacket = false;
if (fread(&length, 2, 1, fp) == 0)
{
reset();
return -2;
}
length = ntohs(length);
if (fread(&plen, 2, 1, fp) == 0)
{
reset();
return -1;
}
packetLen = ntohs(plen);
if (fread(&offset, 4, 1, fp) == 0)
{
reset();
return -1;
}
// Store in local variable until we have passed the reset below.
uint32_t receiveTime = ntohl(offset);
// Use length here because a plen of 0 specifies rtcp.
length = (uint16_t) (length - _kRDHeaderLen);
// check buffer size
if (_datagram && _memSize < length + 1)
{
reset();
}
if (!_datagram)
{
// Add one extra byte, to be able to fake a dummy payload of 1 byte.
_datagram = new uint8_t[length + 1];
_memSize = length + 1;
}
memset(_datagram, 0, length + 1);
if (length == 0)
{
_datagramLen = 0;
_rtpParsed = false;
return packetLen;
}
// Read basic header
if (fread((unsigned short *) _datagram, 1, _kBasicHeaderLen, fp)
!= (size_t)_kBasicHeaderLen)
{
reset();
return -1;
}
_receiveTime = receiveTime;
_datagramLen = _kBasicHeaderLen;
// Parse the basic header
webrtc::WebRtcRTPHeader tempRTPinfo;
int P, X, CC;
parseBasicHeader(&tempRTPinfo, &P, &X, &CC);
// Check if we have to extend the header
if (X != 0 || CC != 0)
{
int newLen = _kBasicHeaderLen + CC * 4 + X * 4;
assert(_memSize >= newLen);
// Read extension from file
size_t readLen = newLen - _kBasicHeaderLen;
if (fread(&_datagram[_kBasicHeaderLen], 1, readLen, fp) != readLen)
{
reset();
return -1;
}
_datagramLen = newLen;
if (X != 0)
{
int totHdrLen = calcHeaderLength(X, CC);
assert(_memSize >= totHdrLen);
// Read extension from file
size_t readLen = totHdrLen - newLen;
if (fread(&_datagram[newLen], 1, readLen, fp) != readLen)
{
reset();
return -1;
}
_datagramLen = totHdrLen;
}
}
_datagramLen = length;
if (!_blockList.empty() && _blockList.count(payloadType()) > 0)
{
readNextPacket = true;
}
}
_rtpParsed = false;
assert(_memSize > _datagramLen);
_payloadLen = 1; // Set the length to 1 byte.
return packetLen;
}
int NETEQTEST_DummyRTPpacket::writeToFile(FILE *fp)
{
if (!fp)
{
return -1;
}
uint16_t length, plen;
uint32_t offset;
// length including RTPplay header
length = htons(_datagramLen + _kRDHeaderLen);
if (fwrite(&length, 2, 1, fp) != 1)
{
return -1;
}
// payload length
plen = htons(_datagramLen);
if (fwrite(&plen, 2, 1, fp) != 1)
{
return -1;
}
// offset (=receive time)
offset = htonl(_receiveTime);
if (fwrite(&offset, 4, 1, fp) != 1)
{
return -1;
}
// Figure out the length of the RTP header.
int headerLen;
if (_datagramLen == 0)
{
// No payload at all; we are done writing to file.
headerLen = 0;
}
else
{
parseHeader();
headerLen = _payloadPtr - _datagram;
assert(headerLen >= 0);
}
// write RTP header
if (fwrite((unsigned short *) _datagram, 1, headerLen, fp) !=
static_cast<size_t>(headerLen))
{
return -1;
}
return (headerLen + _kRDHeaderLen); // total number of bytes written
}
void NETEQTEST_DummyRTPpacket::parseHeader() {
NETEQTEST_RTPpacket::parseHeader();
// Change _payloadLen to 1 byte. The memory should always be big enough.
assert(_memSize > _datagramLen);
_payloadLen = 1;
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef NETEQTEST_DUMMYRTPPACKET_H
#define NETEQTEST_DUMMYRTPPACKET_H
#include "NETEQTEST_RTPpacket.h"
class NETEQTEST_DummyRTPpacket : public NETEQTEST_RTPpacket {
public:
int readFromFile(FILE* fp) override;
int writeToFile(FILE* fp) override;
void parseHeader() override;
};
#endif // NETEQTEST_DUMMYRTPPACKET_H

View File

@ -0,0 +1,851 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "NETEQTEST_RTPpacket.h"
#include <assert.h>
#include <stdlib.h> // rand
#include <string.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <netinet/in.h> // for htons, htonl, etc
#endif
const int NETEQTEST_RTPpacket::_kRDHeaderLen = 8;
const int NETEQTEST_RTPpacket::_kBasicHeaderLen = 12;
NETEQTEST_RTPpacket::NETEQTEST_RTPpacket()
:
_datagram(NULL),
_payloadPtr(NULL),
_memSize(0),
_datagramLen(-1),
_payloadLen(0),
_rtpParsed(false),
_receiveTime(0),
_lost(false)
{
memset(&_rtpInfo, 0, sizeof(_rtpInfo));
_blockList.clear();
}
NETEQTEST_RTPpacket::~NETEQTEST_RTPpacket()
{
if(_datagram)
{
delete [] _datagram;
}
}
void NETEQTEST_RTPpacket::reset()
{
if(_datagram) {
delete [] _datagram;
}
_datagram = NULL;
_memSize = 0;
_datagramLen = -1;
_payloadLen = 0;
_payloadPtr = NULL;
_receiveTime = 0;
memset(&_rtpInfo, 0, sizeof(_rtpInfo));
_rtpParsed = false;
}
int NETEQTEST_RTPpacket::skipFileHeader(FILE *fp)
{
if (!fp) {
return -1;
}
const int kFirstLineLength = 40;
char firstline[kFirstLineLength];
if (fgets(firstline, kFirstLineLength, fp) == NULL) {
return -1;
}
if (strncmp(firstline, "#!rtpplay", 9) == 0) {
if (strncmp(firstline, "#!rtpplay1.0", 12) != 0) {
return -1;
}
}
else if (strncmp(firstline, "#!RTPencode", 11) == 0) {
if (strncmp(firstline, "#!RTPencode1.0", 14) != 0) {
return -1;
}
}
else
{
return -1;
}
const int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
if (fseek(fp, kRtpDumpHeaderSize, SEEK_CUR) != 0)
{
return -1;
}
return 0;
}
int NETEQTEST_RTPpacket::readFromFile(FILE *fp)
{
if(!fp)
{
return(-1);
}
uint16_t length, plen;
uint32_t offset;
int packetLen = 0;
bool readNextPacket = true;
while (readNextPacket) {
readNextPacket = false;
if (fread(&length,2,1,fp)==0)
{
reset();
return(-2);
}
length = ntohs(length);
if (fread(&plen,2,1,fp)==0)
{
reset();
return(-1);
}
packetLen = ntohs(plen);
if (fread(&offset,4,1,fp)==0)
{
reset();
return(-1);
}
// store in local variable until we have passed the reset below
uint32_t receiveTime = ntohl(offset);
// Use length here because a plen of 0 specifies rtcp
length = (uint16_t) (length - _kRDHeaderLen);
// check buffer size
if (_datagram && _memSize < length)
{
reset();
}
if (!_datagram)
{
_datagram = new uint8_t[length];
_memSize = length;
}
if (fread((unsigned short *) _datagram,1,length,fp) != length)
{
reset();
return(-1);
}
_datagramLen = length;
_receiveTime = receiveTime;
if (!_blockList.empty() && _blockList.count(payloadType()) > 0)
{
readNextPacket = true;
}
}
_rtpParsed = false;
return(packetLen);
}
int NETEQTEST_RTPpacket::readFixedFromFile(FILE *fp, size_t length)
{
if (!fp)
{
return -1;
}
// check buffer size
if (_datagram && _memSize < static_cast<int>(length))
{
reset();
}
if (!_datagram)
{
_datagram = new uint8_t[length];
_memSize = length;
}
if (fread(_datagram, 1, length, fp) != length)
{
reset();
return -1;
}
_datagramLen = length;
_receiveTime = 0;
if (!_blockList.empty() && _blockList.count(payloadType()) > 0)
{
// discard this payload
return readFromFile(fp);
}
_rtpParsed = false;
return length;
}
int NETEQTEST_RTPpacket::writeToFile(FILE *fp)
{
if (!fp)
{
return -1;
}
uint16_t length, plen;
uint32_t offset;
// length including RTPplay header
length = htons(_datagramLen + _kRDHeaderLen);
if (fwrite(&length, 2, 1, fp) != 1)
{
return -1;
}
// payload length
plen = htons(_datagramLen);
if (fwrite(&plen, 2, 1, fp) != 1)
{
return -1;
}
// offset (=receive time)
offset = htonl(_receiveTime);
if (fwrite(&offset, 4, 1, fp) != 1)
{
return -1;
}
// write packet data
if (fwrite(_datagram, 1, _datagramLen, fp) !=
static_cast<size_t>(_datagramLen))
{
return -1;
}
return _datagramLen + _kRDHeaderLen; // total number of bytes written
}
void NETEQTEST_RTPpacket::blockPT(uint8_t pt)
{
_blockList[pt] = true;
}
void NETEQTEST_RTPpacket::parseHeader()
{
if (_rtpParsed)
{
// nothing to do
return;
}
if (_datagramLen < _kBasicHeaderLen)
{
// corrupt packet?
return;
}
_payloadLen = parseRTPheader(&_payloadPtr);
_rtpParsed = true;
return;
}
void NETEQTEST_RTPpacket::parseHeader(webrtc::WebRtcRTPHeader* rtp_header) {
if (!_rtpParsed) {
parseHeader();
}
if (rtp_header) {
rtp_header->header.markerBit = _rtpInfo.header.markerBit;
rtp_header->header.payloadType = _rtpInfo.header.payloadType;
rtp_header->header.sequenceNumber = _rtpInfo.header.sequenceNumber;
rtp_header->header.timestamp = _rtpInfo.header.timestamp;
rtp_header->header.ssrc = _rtpInfo.header.ssrc;
}
}
const webrtc::WebRtcRTPHeader* NETEQTEST_RTPpacket::RTPinfo() const
{
if (_rtpParsed)
{
return &_rtpInfo;
}
else
{
return NULL;
}
}
uint8_t * NETEQTEST_RTPpacket::datagram() const
{
if (_datagramLen > 0)
{
return _datagram;
}
else
{
return NULL;
}
}
uint8_t * NETEQTEST_RTPpacket::payload() const
{
if (_payloadLen > 0)
{
return _payloadPtr;
}
else
{
return NULL;
}
}
size_t NETEQTEST_RTPpacket::payloadLen()
{
parseHeader();
return _payloadLen;
}
int16_t NETEQTEST_RTPpacket::dataLen() const
{
return _datagramLen;
}
bool NETEQTEST_RTPpacket::isParsed() const
{
return _rtpParsed;
}
bool NETEQTEST_RTPpacket::isLost() const
{
return _lost;
}
uint8_t NETEQTEST_RTPpacket::payloadType() const
{
if(_datagram && _datagramLen >= _kBasicHeaderLen)
{
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.payloadType;
}
else
{
return 0;
}
}
uint16_t NETEQTEST_RTPpacket::sequenceNumber() const
{
if(_datagram && _datagramLen >= _kBasicHeaderLen)
{
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.sequenceNumber;
}
else
{
return 0;
}
}
uint32_t NETEQTEST_RTPpacket::timeStamp() const
{
if(_datagram && _datagramLen >= _kBasicHeaderLen)
{
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.timestamp;
}
else
{
return 0;
}
}
uint32_t NETEQTEST_RTPpacket::SSRC() const
{
if(_datagram && _datagramLen >= _kBasicHeaderLen)
{
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.ssrc;
}
else
{
return 0;
}
}
uint8_t NETEQTEST_RTPpacket::markerBit() const
{
if(_datagram && _datagramLen >= _kBasicHeaderLen)
{
webrtc::WebRtcRTPHeader tempRTPinfo;
parseRTPheader(&tempRTPinfo);
return tempRTPinfo.header.markerBit;
}
else
{
return 0;
}
}
int NETEQTEST_RTPpacket::setPayloadType(uint8_t pt)
{
if (_datagramLen < 12)
{
return -1;
}
if (!_rtpParsed)
{
_rtpInfo.header.payloadType = pt;
}
_datagram[1] = pt;
return 0;
}
int NETEQTEST_RTPpacket::setSequenceNumber(uint16_t sn)
{
if (_datagramLen < 12)
{
return -1;
}
if (!_rtpParsed)
{
_rtpInfo.header.sequenceNumber = sn;
}
_datagram[2]=(unsigned char)((sn>>8)&0xFF);
_datagram[3]=(unsigned char)((sn)&0xFF);
return 0;
}
int NETEQTEST_RTPpacket::setTimeStamp(uint32_t ts)
{
if (_datagramLen < 12)
{
return -1;
}
if (!_rtpParsed)
{
_rtpInfo.header.timestamp = ts;
}
_datagram[4]=(unsigned char)((ts>>24)&0xFF);
_datagram[5]=(unsigned char)((ts>>16)&0xFF);
_datagram[6]=(unsigned char)((ts>>8)&0xFF);
_datagram[7]=(unsigned char)(ts & 0xFF);
return 0;
}
int NETEQTEST_RTPpacket::setSSRC(uint32_t ssrc)
{
if (_datagramLen < 12)
{
return -1;
}
if (!_rtpParsed)
{
_rtpInfo.header.ssrc = ssrc;
}
_datagram[8]=(unsigned char)((ssrc>>24)&0xFF);
_datagram[9]=(unsigned char)((ssrc>>16)&0xFF);
_datagram[10]=(unsigned char)((ssrc>>8)&0xFF);
_datagram[11]=(unsigned char)(ssrc & 0xFF);
return 0;
}
int NETEQTEST_RTPpacket::setMarkerBit(uint8_t mb)
{
if (_datagramLen < 12)
{
return -1;
}
if (_rtpParsed)
{
_rtpInfo.header.markerBit = mb;
}
if (mb)
{
_datagram[0] |= 0x01;
}
else
{
_datagram[0] &= 0xFE;
}
return 0;
}
int NETEQTEST_RTPpacket::setRTPheader(const webrtc::WebRtcRTPHeader* RTPinfo)
{
if (_datagramLen < 12)
{
// this packet is not ok
return -1;
}
makeRTPheader(_datagram,
RTPinfo->header.payloadType,
RTPinfo->header.sequenceNumber,
RTPinfo->header.timestamp,
RTPinfo->header.ssrc,
RTPinfo->header.markerBit);
return 0;
}
int NETEQTEST_RTPpacket::splitStereo(NETEQTEST_RTPpacket* slaveRtp,
enum stereoModes mode)
{
// if mono, do nothing
if (mode == stereoModeMono)
{
return 0;
}
// check that the RTP header info is parsed
parseHeader();
// start by copying the main rtp packet
*slaveRtp = *this;
if(_payloadLen == 0)
{
// do no more
return 0;
}
if(_payloadLen%2 != 0)
{
// length must be a factor of 2
return -1;
}
switch(mode)
{
case stereoModeSample1:
{
// sample based codec with 1-byte samples
splitStereoSample(slaveRtp, 1 /* 1 byte/sample */);
break;
}
case stereoModeSample2:
{
// sample based codec with 2-byte samples
splitStereoSample(slaveRtp, 2 /* 2 bytes/sample */);
break;
}
case stereoModeFrame:
{
// frame based codec
splitStereoFrame(slaveRtp);
break;
}
case stereoModeDuplicate:
{
// frame based codec, send the whole packet to both master and slave
splitStereoDouble(slaveRtp);
break;
}
case stereoModeMono:
{
assert(false);
return -1;
}
}
return 0;
}
void NETEQTEST_RTPpacket::makeRTPheader(unsigned char* rtp_data,
uint8_t payloadType,
uint16_t seqNo,
uint32_t timestamp,
uint32_t ssrc,
uint8_t markerBit) const
{
rtp_data[0] = markerBit ? 0x81 : 0x80;
rtp_data[1] = payloadType;
rtp_data[2] = seqNo >> 8;
rtp_data[3] = seqNo & 0xFF;
rtp_data[4] = timestamp >> 24;
rtp_data[5] = (timestamp >> 16) & 0xFF;
rtp_data[6] = (timestamp >> 8) & 0xFF;
rtp_data[7] = timestamp & 0xFF;
rtp_data[8] = ssrc >> 24;
rtp_data[9] = (ssrc >> 16) & 0xFF;
rtp_data[10] = (ssrc >> 8) & 0xFF;
rtp_data[11] = ssrc & 0xFF;
}
uint16_t NETEQTEST_RTPpacket::parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo,
uint8_t **payloadPtr) const
{
uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram);
int i_P, i_X, i_CC;
assert(_datagramLen >= 12);
parseBasicHeader(RTPinfo, &i_P, &i_X, &i_CC);
int i_startPosition = calcHeaderLength(i_X, i_CC);
int i_padlength = calcPadLength(i_P);
if (payloadPtr)
{
*payloadPtr =
reinterpret_cast<uint8_t*>(&rtp_data[i_startPosition >> 1]);
}
return static_cast<uint16_t>(_datagramLen - i_startPosition - i_padlength);
}
void NETEQTEST_RTPpacket::parseBasicHeader(webrtc::WebRtcRTPHeader* RTPinfo,
int *i_P, int *i_X, int *i_CC) const
{
uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram);
if (_datagramLen < 12)
{
assert(false);
return;
}
*i_P = (rtp_data[0] >> 5) & 0x01;
*i_X = (rtp_data[0] >> 4) & 0x01;
*i_CC = rtp_data[0] & 0xF;
RTPinfo->header.markerBit = (rtp_data[0] >> 15) & 0x01;
RTPinfo->header.payloadType = (rtp_data[0] >> 8) & 0x7F;
RTPinfo->header.sequenceNumber =
(rtp_data[1] >> 8) | ((rtp_data[1] & 0xFF) << 8);
RTPinfo->header.timestamp =
((rtp_data[2] & 0xFF) << 24) | ((rtp_data[2] & 0xFF00) << 8) |
(rtp_data[3] >> 8) | ((rtp_data[3] & 0xFF) << 8);
RTPinfo->header.ssrc =
((rtp_data[4] & 0xFF) << 24) | ((rtp_data[4] & 0xFF00) << 8) |
(rtp_data[5] >> 8) | ((rtp_data[5] & 0xFF) << 8);
}
int NETEQTEST_RTPpacket::calcHeaderLength(int i_X, int i_CC) const
{
int i_extlength = 0;
uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram);
if (i_X == 1)
{
// Extension header exists.
// Find out how many int32_t it consists of.
int offset = 7 + 2 * i_CC;
assert(_datagramLen > 2 * offset);
if (_datagramLen > 2 * offset)
{
i_extlength = 1 +
(((rtp_data[offset]) >> 8) | ((rtp_data[offset] & 0xFF) << 8));
}
}
return 12 + 4 * i_extlength + 4 * i_CC;
}
int NETEQTEST_RTPpacket::calcPadLength(int i_P) const
{
uint16_t* rtp_data = reinterpret_cast<uint16_t*>(_datagram);
if (i_P == 1)
{
/* Padding exists. Find out how many bytes the padding consists of. */
if (_datagramLen & 0x1)
{
/* odd number of bytes => last byte in higher byte */
return rtp_data[_datagramLen >> 1] & 0xFF;
}
else
{
/* even number of bytes => last byte in lower byte */
return rtp_data[(_datagramLen >> 1) - 1] >> 8;
}
}
return 0;
}
void NETEQTEST_RTPpacket::splitStereoSample(NETEQTEST_RTPpacket* slaveRtp,
int stride)
{
if(!_payloadPtr || !slaveRtp || !slaveRtp->_payloadPtr
|| _payloadLen == 0 || slaveRtp->_memSize < _memSize)
{
return;
}
uint8_t *readDataPtr = _payloadPtr;
uint8_t *writeDataPtr = _payloadPtr;
uint8_t *slaveData = slaveRtp->_payloadPtr;
while (readDataPtr - _payloadPtr < static_cast<ptrdiff_t>(_payloadLen))
{
// master data
for (int ix = 0; ix < stride; ix++) {
*writeDataPtr = *readDataPtr;
writeDataPtr++;
readDataPtr++;
}
// slave data
for (int ix = 0; ix < stride; ix++) {
*slaveData = *readDataPtr;
slaveData++;
readDataPtr++;
}
}
_payloadLen /= 2;
slaveRtp->_payloadLen = _payloadLen;
}
void NETEQTEST_RTPpacket::splitStereoFrame(NETEQTEST_RTPpacket* slaveRtp)
{
if(!_payloadPtr || !slaveRtp || !slaveRtp->_payloadPtr
|| _payloadLen == 0 || slaveRtp->_memSize < _memSize)
{
return;
}
memmove(slaveRtp->_payloadPtr, _payloadPtr + _payloadLen/2, _payloadLen/2);
_payloadLen /= 2;
slaveRtp->_payloadLen = _payloadLen;
}
void NETEQTEST_RTPpacket::splitStereoDouble(NETEQTEST_RTPpacket* slaveRtp)
{
if(!_payloadPtr || !slaveRtp || !slaveRtp->_payloadPtr
|| _payloadLen == 0 || slaveRtp->_memSize < _memSize)
{
return;
}
memcpy(slaveRtp->_payloadPtr, _payloadPtr, _payloadLen);
slaveRtp->_payloadLen = _payloadLen;
}
// Get the RTP header for the RED payload indicated by argument index.
// The first RED payload is index = 0.
int NETEQTEST_RTPpacket::extractRED(int index, webrtc::WebRtcRTPHeader& red)
{
//
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |1| block PT | timestamp offset | block length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |1| ... |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |0| block PT |
// +-+-+-+-+-+-+-+-+
//
parseHeader();
uint8_t* ptr = payload();
uint8_t* payloadEndPtr = ptr + payloadLen();
int num_encodings = 0;
int total_len = 0;
while ((ptr < payloadEndPtr) && (*ptr & 0x80))
{
int len = ((ptr[2] & 0x03) << 8) + ptr[3];
if (num_encodings == index)
{
// Header found.
red.header.payloadType = ptr[0] & 0x7F;
uint32_t offset = (ptr[1] << 6) + (ptr[2] >> 2);
red.header.sequenceNumber = sequenceNumber();
red.header.timestamp = timeStamp() - offset;
red.header.markerBit = markerBit();
red.header.ssrc = SSRC();
return len;
}
++num_encodings;
total_len += len;
ptr += 4;
}
if ((ptr < payloadEndPtr) && (num_encodings == index))
{
// Last header.
red.header.payloadType = ptr[0] & 0x7F;
red.header.sequenceNumber = sequenceNumber();
red.header.timestamp = timeStamp();
red.header.markerBit = markerBit();
red.header.ssrc = SSRC();
++ptr;
return payloadLen() - (ptr - payload()) - total_len;
}
return -1;
}
// Randomize the payload, not the RTP header.
void NETEQTEST_RTPpacket::scramblePayload(void)
{
parseHeader();
for (size_t i = 0; i < _payloadLen; ++i)
{
_payloadPtr[i] = static_cast<uint8_t>(rand());
}
}

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef NETEQTEST_RTPPACKET_H
#define NETEQTEST_RTPPACKET_H
#include <map>
#include <stdio.h>
#include "webrtc/typedefs.h"
#include "webrtc/modules/include/module_common_types.h"
enum stereoModes {
stereoModeMono,
stereoModeSample1,
stereoModeSample2,
stereoModeFrame,
stereoModeDuplicate
};
class NETEQTEST_RTPpacket
{
public:
NETEQTEST_RTPpacket();
bool operator !() const { return (dataLen() < 0); };
virtual ~NETEQTEST_RTPpacket();
void reset();
static int skipFileHeader(FILE *fp);
virtual int readFromFile(FILE *fp);
int readFixedFromFile(FILE *fp, size_t len);
virtual int writeToFile(FILE *fp);
void blockPT(uint8_t pt);
virtual void parseHeader();
void parseHeader(webrtc::WebRtcRTPHeader* rtp_header);
const webrtc::WebRtcRTPHeader* RTPinfo() const;
uint8_t * datagram() const;
uint8_t * payload() const;
size_t payloadLen();
int16_t dataLen() const;
bool isParsed() const;
bool isLost() const;
uint32_t time() const { return _receiveTime; };
uint8_t payloadType() const;
uint16_t sequenceNumber() const;
uint32_t timeStamp() const;
uint32_t SSRC() const;
uint8_t markerBit() const;
int setPayloadType(uint8_t pt);
int setSequenceNumber(uint16_t sn);
int setTimeStamp(uint32_t ts);
int setSSRC(uint32_t ssrc);
int setMarkerBit(uint8_t mb);
void setTime(uint32_t receiveTime) { _receiveTime = receiveTime; };
int setRTPheader(const webrtc::WebRtcRTPHeader* RTPinfo);
int splitStereo(NETEQTEST_RTPpacket* slaveRtp, enum stereoModes mode);
int extractRED(int index, webrtc::WebRtcRTPHeader& red);
void scramblePayload(void);
uint8_t * _datagram;
uint8_t * _payloadPtr;
int _memSize;
int16_t _datagramLen;
size_t _payloadLen;
webrtc::WebRtcRTPHeader _rtpInfo;
bool _rtpParsed;
uint32_t _receiveTime;
bool _lost;
std::map<uint8_t, bool> _blockList;
protected:
static const int _kRDHeaderLen;
static const int _kBasicHeaderLen;
void parseBasicHeader(webrtc::WebRtcRTPHeader* RTPinfo, int *i_P, int *i_X,
int *i_CC) const;
int calcHeaderLength(int i_X, int i_CC) const;
private:
void makeRTPheader(unsigned char* rtp_data, uint8_t payloadType,
uint16_t seqNo, uint32_t timestamp,
uint32_t ssrc, uint8_t markerBit) const;
uint16_t parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo,
uint8_t **payloadPtr = NULL) const;
uint16_t parseRTPheader(uint8_t **payloadPtr = NULL)
{ return parseRTPheader(&_rtpInfo, payloadPtr);};
int calcPadLength(int i_P) const;
void splitStereoSample(NETEQTEST_RTPpacket* slaveRtp, int stride);
void splitStereoFrame(NETEQTEST_RTPpacket* slaveRtp);
void splitStereoDouble(NETEQTEST_RTPpacket* slaveRtp);
};
#endif //NETEQTEST_RTPPACKET_H

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
/* PayloadTypes.h */
/* Used by RTPencode application */
// TODO(henrik.lundin) Remove this once RTPencode is refactored.
/* RTP defined codepoints */
#define NETEQ_CODEC_PCMU_PT 0
#define NETEQ_CODEC_PCMA_PT 8
#define NETEQ_CODEC_G722_PT 9
#define NETEQ_CODEC_CN_PT 13
/* Dynamic RTP codepoints */
#define NETEQ_CODEC_ILBC_PT 102
#define NETEQ_CODEC_ISAC_PT 103
#define NETEQ_CODEC_ISACSWB_PT 104
#define NETEQ_CODEC_AVT_PT 106
#define NETEQ_CODEC_OPUS_PT 111
#define NETEQ_CODEC_RED_PT 117
#define NETEQ_CODEC_CN_WB_PT 105
#define NETEQ_CODEC_CN_SWB_PT 126
#define NETEQ_CODEC_PCM16B_PT 93
#define NETEQ_CODEC_PCM16B_WB_PT 94
#define NETEQ_CODEC_PCM16B_SWB32KHZ_PT 95
#define NETEQ_CODEC_PCM16B_SWB48KHZ_PT 96

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdio.h>
#include <algorithm>
#include <vector>
#include "webrtc/modules/audio_coding/neteq/test/NETEQTEST_DummyRTPpacket.h"
#include "webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
#define FIRSTLINELEN 40
//#define WEBRTC_DUMMY_RTP
static bool pktCmp(NETEQTEST_RTPpacket *a, NETEQTEST_RTPpacket *b) {
return (a->time() < b->time());
}
int main(int argc, char* argv[]) {
FILE* in_file = fopen(argv[1], "rb");
if (!in_file) {
printf("Cannot open input file %s\n", argv[1]);
return -1;
}
printf("Input RTP file: %s\n", argv[1]);
FILE* stat_file = fopen(argv[2], "rt");
if (!stat_file) {
printf("Cannot open timing file %s\n", argv[2]);
return -1;
}
printf("Timing file: %s\n", argv[2]);
FILE* out_file = fopen(argv[3], "wb");
if (!out_file) {
printf("Cannot open output file %s\n", argv[3]);
return -1;
}
printf("Output RTP file: %s\n\n", argv[3]);
// Read all statistics and insert into map.
// Read first line.
char temp_str[100];
if (fgets(temp_str, 100, stat_file) == NULL) {
printf("Failed to read timing file %s\n", argv[2]);
return -1;
}
// Define map.
std::map<std::pair<uint16_t, uint32_t>, uint32_t> packet_stats;
uint16_t seq_no;
uint32_t ts;
uint32_t send_time;
while (fscanf(stat_file,
"%hu %u %u %*i %*i\n", &seq_no, &ts, &send_time) == 3) {
std::pair<uint16_t, uint32_t>
temp_pair = std::pair<uint16_t, uint32_t>(seq_no, ts);
packet_stats[temp_pair] = send_time;
}
fclose(stat_file);
// Read file header and write directly to output file.
char first_line[FIRSTLINELEN];
if (fgets(first_line, FIRSTLINELEN, in_file) == NULL) {
printf("Failed to read first line of input file %s\n", argv[1]);
return -1;
}
fputs(first_line, out_file);
// start_sec + start_usec + source + port + padding
const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
if (fread(first_line, 1, kRtpDumpHeaderSize, in_file)
!= kRtpDumpHeaderSize) {
printf("Failed to read RTP dump header from input file %s\n", argv[1]);
return -1;
}
if (fwrite(first_line, 1, kRtpDumpHeaderSize, out_file)
!= kRtpDumpHeaderSize) {
printf("Failed to write RTP dump header to output file %s\n", argv[3]);
return -1;
}
std::vector<NETEQTEST_RTPpacket *> packet_vec;
while (1) {
// Insert in vector.
#ifdef WEBRTC_DUMMY_RTP
NETEQTEST_RTPpacket *new_packet = new NETEQTEST_DummyRTPpacket();
#else
NETEQTEST_RTPpacket *new_packet = new NETEQTEST_RTPpacket();
#endif
if (new_packet->readFromFile(in_file) < 0) {
// End of file.
break;
}
// Look for new send time in statistics vector.
std::pair<uint16_t, uint32_t> temp_pair =
std::pair<uint16_t, uint32_t>(new_packet->sequenceNumber(),
new_packet->timeStamp());
uint32_t new_send_time = packet_stats[temp_pair];
new_packet->setTime(new_send_time); // Set new send time.
packet_vec.push_back(new_packet); // Insert in vector.
}
// Sort the vector according to send times.
std::sort(packet_vec.begin(), packet_vec.end(), pktCmp);
std::vector<NETEQTEST_RTPpacket *>::iterator it;
for (it = packet_vec.begin(); it != packet_vec.end(); it++) {
// Write to out file.
if ((*it)->writeToFile(out_file) < 0) {
printf("Error writing to file\n");
return -1;
}
// Delete packet.
delete *it;
}
fclose(in_file);
fclose(out_file);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,229 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
//TODO(hlundin): Reformat file to meet style guide.
/* header includes */
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <winsock2.h>
#include <io.h>
#endif
#ifdef WEBRTC_LINUX
#include <netinet/in.h>
#endif
#include <assert.h>
#include "webrtc/test/gtest.h"
#include "webrtc/typedefs.h"
/*********************/
/* Misc. definitions */
/*********************/
#define FIRSTLINELEN 40
#define CHECK_NOT_NULL(a) if((a)==NULL){ \
fprintf(stderr,"\n %s \n line: %d \nerror at %s\n",__FILE__,__LINE__,#a ); \
return(-1);}
struct arr_time {
float time;
uint32_t ix;
};
int filelen(FILE *fid)
{
fpos_t cur_pos;
int len;
if (!fid || fgetpos(fid, &cur_pos)) {
return(-1);
}
fseek(fid, 0, SEEK_END);
len = ftell(fid);
fsetpos(fid, &cur_pos);
return (len);
}
int compare_arr_time(const void *x, const void *y);
int main(int argc, char* argv[])
{
unsigned int dat_len, rtp_len, Npack, k;
arr_time *time_vec;
char firstline[FIRSTLINELEN];
unsigned char* rtp_vec = NULL;
unsigned char** packet_ptr = NULL;
unsigned char* temp_packet = NULL;
const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
uint16_t len;
uint32_t *offset;
/* check number of parameters */
if (argc != 4) {
/* print help text and exit */
printf("Apply jitter on RTP stream.\n");
printf("Reads an RTP stream and packet timing from two files.\n");
printf("The RTP stream is modified to have the same jitter as described in "
"the timing files.\n");
printf("The format of the RTP stream file should be the same as for \n");
printf("rtpplay, and can be obtained e.g., from Ethereal by using\n");
printf("Statistics -> RTP -> Show All Streams -> [select a stream] -> "
"Save As\n\n");
printf("Usage:\n\n");
printf("%s RTP_infile dat_file RTP_outfile\n", argv[0]);
printf("where:\n");
printf("RTP_infile : RTP stream input file\n\n");
printf("dat_file : file with packet arrival times in ms\n\n");
printf("RTP_outfile : RTP stream output file\n\n");
return(0);
}
FILE* in_file=fopen(argv[1],"rb");
CHECK_NOT_NULL(in_file);
printf("Input file: %s\n",argv[1]);
FILE* dat_file=fopen(argv[2],"rb");
CHECK_NOT_NULL(dat_file);
printf("Dat-file: %s\n",argv[2]);
FILE* out_file=fopen(argv[3],"wb");
CHECK_NOT_NULL(out_file);
printf("Output file: %s\n\n",argv[3]);
// add 1000 bytes to avoid (rare) strange error.
time_vec = (arr_time *) malloc(sizeof(arr_time)
*(filelen(dat_file)/sizeof(float)) + 1000);
if (time_vec==NULL) {
fprintf(stderr, "Error: could not allocate memory for reading dat file\n");
goto closing;
}
dat_len=0;
while(fread(&(time_vec[dat_len].time),sizeof(float),1,dat_file)>0) {
time_vec[dat_len].ix=dat_len;
dat_len++;
}
if (dat_len == 0) {
fprintf(stderr, "Error: dat_file is empty, no arrival time is given.\n");
goto closing;
}
qsort(time_vec,dat_len,sizeof(arr_time),compare_arr_time);
rtp_vec = (unsigned char *) malloc(sizeof(unsigned char)*filelen(in_file));
if (rtp_vec==NULL) {
fprintf(stderr,"Error: could not allocate memory for reading rtp file\n");
goto closing;
}
// read file header and write directly to output file
EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, in_file) != NULL);
EXPECT_GT(fputs(firstline, out_file), 0);
EXPECT_EQ(kRtpDumpHeaderSize, fread(firstline, 1, kRtpDumpHeaderSize,
in_file));
EXPECT_EQ(kRtpDumpHeaderSize, fwrite(firstline, 1, kRtpDumpHeaderSize,
out_file));
// read all RTP packets into vector
rtp_len=0;
Npack=0;
// read length of first packet.
len=(uint16_t) fread(&rtp_vec[rtp_len], sizeof(unsigned char), 2, in_file);
while(len==2) {
len = ntohs(*((uint16_t *)(rtp_vec + rtp_len)));
rtp_len += 2;
if(fread(&rtp_vec[rtp_len], sizeof(unsigned char),
len-2, in_file)!=(unsigned) (len-2)) {
fprintf(stderr,"Error: currupt packet length\n");
goto closing;
}
rtp_len += len-2;
Npack++;
// read length of next packet.
len=(uint16_t) fread(&rtp_vec[rtp_len], sizeof(unsigned char), 2, in_file);
}
if (Npack == 0) {
fprintf(stderr, "Error: No RTP packet found.\n");
goto closing;
}
packet_ptr = (unsigned char **) malloc(Npack*sizeof(unsigned char*));
packet_ptr[0]=rtp_vec;
k=1;
while(k<Npack) {
len = ntohs(*((uint16_t *) packet_ptr[k-1]));
packet_ptr[k]=packet_ptr[k-1]+len;
k++;
}
for(k=0; k<dat_len && k<Npack; k++) {
if(time_vec[k].time < FLT_MAX && time_vec[k].ix < Npack){
temp_packet = packet_ptr[time_vec[k].ix];
offset = (uint32_t *) (temp_packet+4);
if ( time_vec[k].time >= 0 ) {
*offset = htonl((uint32_t) time_vec[k].time);
}
else {
*offset = htonl((uint32_t) 0);
fprintf(stderr, "Warning: negative receive time in dat file transformed"
" to 0.\n");
}
// write packet to file
if (fwrite(temp_packet, sizeof(unsigned char),
ntohs(*((uint16_t*) temp_packet)),
out_file) !=
ntohs(*((uint16_t*) temp_packet))) {
return -1;
}
}
}
closing:
free(time_vec);
free(rtp_vec);
if (packet_ptr != NULL) {
free(packet_ptr);
}
fclose(in_file);
fclose(dat_file);
fclose(out_file);
return(0);
}
int compare_arr_time(const void *xp, const void *yp) {
if(((arr_time *)xp)->time == ((arr_time *)yp)->time)
return(0);
else if(((arr_time *)xp)->time > ((arr_time *)yp)->time)
return(1);
return(-1);
}

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdio.h>
#include <algorithm>
#include <vector>
#include "webrtc/modules/audio_coding/neteq/test/NETEQTEST_RTPpacket.h"
#include "webrtc/test/gtest.h"
#define FIRSTLINELEN 40
int main(int argc, char* argv[]) {
if (argc < 4 || argc > 6) {
printf(
"Usage: RTPtimeshift in.rtp out.rtp newStartTS [newStartSN "
"[newStartArrTime]]\n");
exit(1);
}
FILE* inFile = fopen(argv[1], "rb");
if (!inFile) {
printf("Cannot open input file %s\n", argv[1]);
return (-1);
}
printf("Input RTP file: %s\n", argv[1]);
FILE* outFile = fopen(argv[2], "wb");
if (!outFile) {
printf("Cannot open output file %s\n", argv[2]);
return (-1);
}
printf("Output RTP file: %s\n\n", argv[2]);
// Read file header and write directly to output file.
const unsigned int kRtpDumpHeaderSize = 4 + 4 + 4 + 2 + 2;
char firstline[FIRSTLINELEN];
EXPECT_TRUE(fgets(firstline, FIRSTLINELEN, inFile) != NULL);
EXPECT_GT(fputs(firstline, outFile), 0);
EXPECT_EQ(kRtpDumpHeaderSize,
fread(firstline, 1, kRtpDumpHeaderSize, inFile));
EXPECT_EQ(kRtpDumpHeaderSize,
fwrite(firstline, 1, kRtpDumpHeaderSize, outFile));
NETEQTEST_RTPpacket packet;
int packLen = packet.readFromFile(inFile);
if (packLen < 0) {
exit(1);
}
// Get new start TS and start SeqNo from arguments.
uint32_t TSdiff = atoi(argv[3]) - packet.timeStamp();
uint16_t SNdiff = 0;
uint32_t ATdiff = 0;
if (argc > 4) {
int startSN = atoi(argv[4]);
if (startSN >= 0)
SNdiff = startSN - packet.sequenceNumber();
if (argc > 5) {
int startTS = atoi(argv[5]);
if (startTS >= 0)
ATdiff = startTS - packet.time();
}
}
while (packLen >= 0) {
packet.setTimeStamp(packet.timeStamp() + TSdiff);
packet.setSequenceNumber(packet.sequenceNumber() + SNdiff);
packet.setTime(packet.time() + ATdiff);
packet.writeToFile(outFile);
packLen = packet.readFromFile(inFile);
}
fclose(inFile);
fclose(outFile);
return 0;
}

View File

@ -0,0 +1,201 @@
%
% Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
%
% Use of this source code is governed by a BSD-style license
% that can be found in the LICENSE file in the root of the source
% tree. An additional intellectual property rights grant can be found
% in the file PATENTS. All contributing project authors may
% be found in the AUTHORS file in the root of the source tree.
%
function outStruct = parse_delay_file(file)
fid = fopen(file, 'rb');
if fid == -1
error('Cannot open file %s', file);
end
textline = fgetl(fid);
if ~strncmp(textline, '#!NetEQ_Delay_Logging', 21)
error('Wrong file format');
end
ver = sscanf(textline, '#!NetEQ_Delay_Logging%d.%d');
if ~all(ver == [2; 0])
error('Wrong version of delay logging function')
end
start_pos = ftell(fid);
fseek(fid, -12, 'eof');
textline = fgetl(fid);
if ~strncmp(textline, 'End of file', 21)
error('File ending is not correct. Seems like the simulation ended abnormally.');
end
fseek(fid,-12-4, 'eof');
Npackets = fread(fid, 1, 'int32');
fseek(fid, start_pos, 'bof');
rtpts = zeros(Npackets, 1);
seqno = zeros(Npackets, 1);
pt = zeros(Npackets, 1);
plen = zeros(Npackets, 1);
recin_t = nan*ones(Npackets, 1);
decode_t = nan*ones(Npackets, 1);
playout_delay = zeros(Npackets, 1);
optbuf = zeros(Npackets, 1);
fs_ix = 1;
clock = 0;
ts_ix = 1;
ended = 0;
late_packets = 0;
fs_now = 8000;
last_decode_k = 0;
tot_expand = 0;
tot_accelerate = 0;
tot_preemptive = 0;
while not(ended)
signal = fread(fid, 1, '*int32');
switch signal
case 3 % NETEQ_DELAY_LOGGING_SIGNAL_CLOCK
clock = fread(fid, 1, '*float32');
% keep on reading batches of M until the signal is no longer "3"
% read int32 + float32 in one go
% this is to save execution time
temp = [3; 0];
M = 120;
while all(temp(1,:) == 3)
fp = ftell(fid);
temp = fread(fid, [2 M], '*int32');
end
% back up to last clock event
fseek(fid, fp - ftell(fid) + ...
(find(temp(1,:) ~= 3, 1 ) - 2) * 2 * 4 + 4, 'cof');
% read the last clock value
clock = fread(fid, 1, '*float32');
case 1 % NETEQ_DELAY_LOGGING_SIGNAL_RECIN
temp_ts = fread(fid, 1, 'uint32');
if late_packets > 0
temp_ix = ts_ix - 1;
while (temp_ix >= 1) && (rtpts(temp_ix) ~= temp_ts)
% TODO(hlundin): use matlab vector search instead?
temp_ix = temp_ix - 1;
end
if temp_ix >= 1
% the ts was found in the vector
late_packets = late_packets - 1;
else
temp_ix = ts_ix;
ts_ix = ts_ix + 1;
end
else
temp_ix = ts_ix;
ts_ix = ts_ix + 1;
end
rtpts(temp_ix) = temp_ts;
seqno(temp_ix) = fread(fid, 1, 'uint16');
pt(temp_ix) = fread(fid, 1, 'int32');
plen(temp_ix) = fread(fid, 1, 'int16');
recin_t(temp_ix) = clock;
case 2 % NETEQ_DELAY_LOGGING_SIGNAL_FLUSH
% do nothing
case 4 % NETEQ_DELAY_LOGGING_SIGNAL_EOF
ended = 1;
case 5 % NETEQ_DELAY_LOGGING_SIGNAL_DECODE
last_decode_ts = fread(fid, 1, 'uint32');
temp_delay = fread(fid, 1, 'uint16');
k = find(rtpts(1:(ts_ix - 1))==last_decode_ts,1,'last');
if ~isempty(k)
decode_t(k) = clock;
playout_delay(k) = temp_delay + ...
5 * fs_now / 8000; % add overlap length
last_decode_k = k;
end
case 6 % NETEQ_DELAY_LOGGING_SIGNAL_CHANGE_FS
fsvec(fs_ix) = fread(fid, 1, 'uint16');
fschange_ts(fs_ix) = last_decode_ts;
fs_now = fsvec(fs_ix);
fs_ix = fs_ix + 1;
case 7 % NETEQ_DELAY_LOGGING_SIGNAL_MERGE_INFO
playout_delay(last_decode_k) = playout_delay(last_decode_k) ...
+ fread(fid, 1, 'int32');
case 8 % NETEQ_DELAY_LOGGING_SIGNAL_EXPAND_INFO
temp = fread(fid, 1, 'int32');
if last_decode_k ~= 0
tot_expand = tot_expand + temp / (fs_now / 1000);
end
case 9 % NETEQ_DELAY_LOGGING_SIGNAL_ACCELERATE_INFO
temp = fread(fid, 1, 'int32');
if last_decode_k ~= 0
tot_accelerate = tot_accelerate + temp / (fs_now / 1000);
end
case 10 % NETEQ_DELAY_LOGGING_SIGNAL_PREEMPTIVE_INFO
temp = fread(fid, 1, 'int32');
if last_decode_k ~= 0
tot_preemptive = tot_preemptive + temp / (fs_now / 1000);
end
case 11 % NETEQ_DELAY_LOGGING_SIGNAL_OPTBUF
optbuf(last_decode_k) = fread(fid, 1, 'int32');
case 12 % NETEQ_DELAY_LOGGING_SIGNAL_DECODE_ONE_DESC
last_decode_ts = fread(fid, 1, 'uint32');
k = ts_ix - 1;
while (k >= 1) && (rtpts(k) ~= last_decode_ts)
% TODO(hlundin): use matlab vector search instead?
k = k - 1;
end
if k < 1
% packet not received yet
k = ts_ix;
rtpts(ts_ix) = last_decode_ts;
late_packets = late_packets + 1;
end
decode_t(k) = clock;
playout_delay(k) = fread(fid, 1, 'uint16') + ...
5 * fs_now / 8000; % add overlap length
last_decode_k = k;
end
end
fclose(fid);
outStruct = struct(...
'ts', rtpts, ...
'sn', seqno, ...
'pt', pt,...
'plen', plen,...
'arrival', recin_t,...
'decode', decode_t,...
'fs', fsvec(:),...
'fschange_ts', fschange_ts(:),...
'playout_delay', playout_delay,...
'tot_expand', tot_expand,...
'tot_accelerate', tot_accelerate,...
'tot_preemptive', tot_preemptive,...
'optbuf', optbuf);

View File

@ -0,0 +1,197 @@
%
% Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
%
% Use of this source code is governed by a BSD-style license
% that can be found in the LICENSE file in the root of the source
% tree. An additional intellectual property rights grant can be found
% in the file PATENTS. All contributing project authors may
% be found in the AUTHORS file in the root of the source tree.
%
function [delay_struct, delayvalues] = plot_neteq_delay(delayfile, varargin)
% InfoStruct = plot_neteq_delay(delayfile)
% InfoStruct = plot_neteq_delay(delayfile, 'skipdelay', skip_seconds)
%
% Henrik Lundin, 2006-11-17
% Henrik Lundin, 2011-05-17
%
try
s = parse_delay_file(delayfile);
catch
error(lasterr);
end
delayskip=0;
noplot=0;
arg_ptr=1;
delaypoints=[];
s.sn=unwrap_seqno(s.sn);
while arg_ptr+1 <= nargin
switch lower(varargin{arg_ptr})
case {'skipdelay', 'delayskip'}
% skip a number of seconds in the beginning when calculating delays
delayskip = varargin{arg_ptr+1};
arg_ptr = arg_ptr + 2;
case 'noplot'
noplot=1;
arg_ptr = arg_ptr + 1;
case {'get_delay', 'getdelay'}
% return a vector of delay values for the points in the given vector
delaypoints = varargin{arg_ptr+1};
arg_ptr = arg_ptr + 2;
otherwise
warning('Unknown switch %s\n', varargin{arg_ptr});
arg_ptr = arg_ptr + 1;
end
end
% find lost frames that were covered by one-descriptor decoding
one_desc_ix=find(isnan(s.arrival));
for k=1:length(one_desc_ix)
ix=find(s.ts==max(s.ts(s.ts(one_desc_ix(k))>s.ts)));
s.sn(one_desc_ix(k))=s.sn(ix)+1;
s.pt(one_desc_ix(k))=s.pt(ix);
s.arrival(one_desc_ix(k))=s.arrival(ix)+s.decode(one_desc_ix(k))-s.decode(ix);
end
% remove duplicate received frames that were never decoded (RED codec)
if length(unique(s.ts(isfinite(s.ts)))) < length(s.ts(isfinite(s.ts)))
ix=find(isfinite(s.decode));
s.sn=s.sn(ix);
s.ts=s.ts(ix);
s.arrival=s.arrival(ix);
s.playout_delay=s.playout_delay(ix);
s.pt=s.pt(ix);
s.optbuf=s.optbuf(ix);
plen=plen(ix);
s.decode=s.decode(ix);
end
% find non-unique sequence numbers
[~,un_ix]=unique(s.sn);
nonun_ix=setdiff(1:length(s.sn),un_ix);
if ~isempty(nonun_ix)
warning('RTP sequence numbers are in error');
end
% sort vectors
[s.sn,sort_ix]=sort(s.sn);
s.ts=s.ts(sort_ix);
s.arrival=s.arrival(sort_ix);
s.decode=s.decode(sort_ix);
s.playout_delay=s.playout_delay(sort_ix);
s.pt=s.pt(sort_ix);
send_t=s.ts-s.ts(1);
if length(s.fs)<1
warning('No info about sample rate found in file. Using default 8000.');
s.fs(1)=8000;
s.fschange_ts(1)=min(s.ts);
elseif s.fschange_ts(1)>min(s.ts)
s.fschange_ts(1)=min(s.ts);
end
end_ix=length(send_t);
for k=length(s.fs):-1:1
start_ix=find(s.ts==s.fschange_ts(k));
send_t(start_ix:end_ix)=send_t(start_ix:end_ix)/s.fs(k)*1000;
s.playout_delay(start_ix:end_ix)=s.playout_delay(start_ix:end_ix)/s.fs(k)*1000;
s.optbuf(start_ix:end_ix)=s.optbuf(start_ix:end_ix)/s.fs(k)*1000;
end_ix=start_ix-1;
end
tot_time=max(send_t)-min(send_t);
seq_ix=s.sn-min(s.sn)+1;
send_t=send_t+max(min(s.arrival-send_t),0);
plot_send_t=nan*ones(max(seq_ix),1);
plot_send_t(seq_ix)=send_t;
plot_nw_delay=nan*ones(max(seq_ix),1);
plot_nw_delay(seq_ix)=s.arrival-send_t;
cng_ix=find(s.pt~=13); % find those packets that are not CNG/SID
if noplot==0
h=plot(plot_send_t/1000,plot_nw_delay);
set(h,'color',0.75*[1 1 1]);
hold on
if any(s.optbuf~=0)
peak_ix=find(s.optbuf(cng_ix)<0); % peak mode is labeled with negative values
no_peak_ix=find(s.optbuf(cng_ix)>0); %setdiff(1:length(cng_ix),peak_ix);
h1=plot(send_t(cng_ix(peak_ix))/1000,...
s.arrival(cng_ix(peak_ix))+abs(s.optbuf(cng_ix(peak_ix)))-send_t(cng_ix(peak_ix)),...
'r.');
h2=plot(send_t(cng_ix(no_peak_ix))/1000,...
s.arrival(cng_ix(no_peak_ix))+abs(s.optbuf(cng_ix(no_peak_ix)))-send_t(cng_ix(no_peak_ix)),...
'g.');
set([h1, h2],'markersize',1)
end
%h=plot(send_t(seq_ix)/1000,s.decode+s.playout_delay-send_t(seq_ix));
h=plot(send_t(cng_ix)/1000,s.decode(cng_ix)+s.playout_delay(cng_ix)-send_t(cng_ix));
set(h,'linew',1.5);
hold off
ax1=axis;
axis tight
ax2=axis;
axis([ax2(1:3) ax1(4)])
end
% calculate delays and other parameters
delayskip_ix = find(send_t-send_t(1)>=delayskip*1000, 1 );
use_ix = intersect(cng_ix,... % use those that are not CNG/SID frames...
intersect(find(isfinite(s.decode)),... % ... that did arrive ...
(delayskip_ix:length(s.decode))')); % ... and are sent after delayskip seconds
mean_delay = mean(s.decode(use_ix)+s.playout_delay(use_ix)-send_t(use_ix));
neteq_delay = mean(s.decode(use_ix)+s.playout_delay(use_ix)-s.arrival(use_ix));
Npack=max(s.sn(delayskip_ix:end))-min(s.sn(delayskip_ix:end))+1;
nw_lossrate=(Npack-length(s.sn(delayskip_ix:end)))/Npack;
neteq_lossrate=(length(s.sn(delayskip_ix:end))-length(use_ix))/Npack;
delay_struct=struct('mean_delay',mean_delay,'neteq_delay',neteq_delay,...
'nw_lossrate',nw_lossrate,'neteq_lossrate',neteq_lossrate,...
'tot_expand',round(s.tot_expand),'tot_accelerate',round(s.tot_accelerate),...
'tot_preemptive',round(s.tot_preemptive),'tot_time',tot_time,...
'filename',delayfile,'units','ms','fs',unique(s.fs));
if not(isempty(delaypoints))
delayvalues=interp1(send_t(cng_ix),...
s.decode(cng_ix)+s.playout_delay(cng_ix)-send_t(cng_ix),...
delaypoints,'nearest',NaN);
else
delayvalues=[];
end
% SUBFUNCTIONS %
function y=unwrap_seqno(x)
jumps=find(abs((diff(x)-1))>65000);
while ~isempty(jumps)
n=jumps(1);
if x(n+1)-x(n) < 0
% negative jump
x(n+1:end)=x(n+1:end)+65536;
else
% positive jump
x(n+1:end)=x(n+1:end)-65536;
end
jumps=find(abs((diff(x(n+1:end))-1))>65000);
end
y=x;
return;

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <memory>
#include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h"
#include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "webrtc/rtc_base/checks.h"
#include "webrtc/rtc_base/flags.h"
#include "webrtc/rtc_base/safe_conversions.h"
#include "webrtc/test/testsupport/fileutils.h"
using testing::InitGoogleTest;
namespace webrtc {
namespace test {
namespace {
static const int kInputSampleRateKhz = 8;
static const int kOutputSampleRateKhz = 8;
DEFINE_int(frame_size_ms, 20, "Codec frame size (milliseconds).");
} // namespace
class NetEqIlbcQualityTest : public NetEqQualityTest {
protected:
NetEqIlbcQualityTest()
: NetEqQualityTest(FLAG_frame_size_ms,
kInputSampleRateKhz,
kOutputSampleRateKhz,
NetEqDecoder::kDecoderILBC) {
// Flag validation
RTC_CHECK(FLAG_frame_size_ms == 20 || FLAG_frame_size_ms == 30 ||
FLAG_frame_size_ms == 40 || FLAG_frame_size_ms == 60)
<< "Invalid frame size, should be 20, 30, 40, or 60 ms.";
}
void SetUp() override {
ASSERT_EQ(1u, channels_) << "iLBC supports only mono audio.";
AudioEncoderIlbcConfig config;
config.frame_size_ms = FLAG_frame_size_ms;
encoder_.reset(new AudioEncoderIlbcImpl(config, 102));
NetEqQualityTest::SetUp();
}
int EncodeBlock(int16_t* in_data,
size_t block_size_samples,
rtc::Buffer* payload, size_t max_bytes) override {
const size_t kFrameSizeSamples = 80; // Samples per 10 ms.
size_t encoded_samples = 0;
uint32_t dummy_timestamp = 0;
AudioEncoder::EncodedInfo info;
do {
info = encoder_->Encode(dummy_timestamp,
rtc::ArrayView<const int16_t>(
in_data + encoded_samples, kFrameSizeSamples),
payload);
encoded_samples += kFrameSizeSamples;
} while (info.encoded_bytes == 0);
return rtc::checked_cast<int>(info.encoded_bytes);
}
private:
std::unique_ptr<AudioEncoderIlbcImpl> encoder_;
};
TEST_F(NetEqIlbcQualityTest, Test) {
Simulate();
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_coding/codecs/isac/fix/include/isacfix.h"
#include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "webrtc/rtc_base/flags.h"
using testing::InitGoogleTest;
namespace webrtc {
namespace test {
namespace {
static const int kIsacBlockDurationMs = 30;
static const int kIsacInputSamplingKhz = 16;
static const int kIsacOutputSamplingKhz = 16;
DEFINE_int(bit_rate_kbps, 32, "Target bit rate (kbps).");
} // namespace
class NetEqIsacQualityTest : public NetEqQualityTest {
protected:
NetEqIsacQualityTest();
void SetUp() override;
void TearDown() override;
int EncodeBlock(int16_t* in_data, size_t block_size_samples,
rtc::Buffer* payload, size_t max_bytes) override;
private:
ISACFIX_MainStruct* isac_encoder_;
int bit_rate_kbps_;
};
NetEqIsacQualityTest::NetEqIsacQualityTest()
: NetEqQualityTest(kIsacBlockDurationMs,
kIsacInputSamplingKhz,
kIsacOutputSamplingKhz,
NetEqDecoder::kDecoderISAC),
isac_encoder_(NULL),
bit_rate_kbps_(FLAG_bit_rate_kbps) {
// Flag validation
RTC_CHECK(FLAG_bit_rate_kbps >= 10 && FLAG_bit_rate_kbps <= 32)
<< "Invalid bit rate, should be between 10 and 32 kbps.";
}
void NetEqIsacQualityTest::SetUp() {
ASSERT_EQ(1u, channels_) << "iSAC supports only mono audio.";
// Create encoder memory.
WebRtcIsacfix_Create(&isac_encoder_);
ASSERT_TRUE(isac_encoder_ != NULL);
EXPECT_EQ(0, WebRtcIsacfix_EncoderInit(isac_encoder_, 1));
// Set bitrate and block length.
EXPECT_EQ(0, WebRtcIsacfix_Control(isac_encoder_, bit_rate_kbps_ * 1000,
kIsacBlockDurationMs));
NetEqQualityTest::SetUp();
}
void NetEqIsacQualityTest::TearDown() {
// Free memory.
EXPECT_EQ(0, WebRtcIsacfix_Free(isac_encoder_));
NetEqQualityTest::TearDown();
}
int NetEqIsacQualityTest::EncodeBlock(int16_t* in_data,
size_t block_size_samples,
rtc::Buffer* payload, size_t max_bytes) {
// ISAC takes 10 ms for every call.
const int subblocks = kIsacBlockDurationMs / 10;
const int subblock_length = 10 * kIsacInputSamplingKhz;
int value = 0;
int pointer = 0;
for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) {
// The Isac encoder does not perform encoding (and returns 0) until it
// receives a sequence of sub-blocks that amount to the frame duration.
EXPECT_EQ(0, value);
payload->AppendData(max_bytes, [&] (rtc::ArrayView<uint8_t> payload) {
value = WebRtcIsacfix_Encode(isac_encoder_, &in_data[pointer],
payload.data());
return (value >= 0) ? static_cast<size_t>(value) : 0;
});
}
EXPECT_GT(value, 0);
return value;
}
TEST_F(NetEqIsacQualityTest, Test) {
Simulate();
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,174 @@
/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
#include "webrtc/modules/audio_coding/codecs/opus/opus_inst.h"
#include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "webrtc/rtc_base/flags.h"
using testing::InitGoogleTest;
namespace webrtc {
namespace test {
namespace {
static const int kOpusBlockDurationMs = 20;
static const int kOpusSamplingKhz = 48;
DEFINE_int(bit_rate_kbps, 32, "Target bit rate (kbps).");
DEFINE_int(complexity, 10, "Complexity: 0 ~ 10 -- defined as in Opus"
"specification.");
DEFINE_int(maxplaybackrate, 48000, "Maximum playback rate (Hz).");
DEFINE_int(application, 0, "Application mode: 0 -- VOIP, 1 -- Audio.");
DEFINE_int(reported_loss_rate, 10, "Reported percentile of packet loss.");
DEFINE_bool(fec, false, "Enable FEC for encoding (-nofec to disable).");
DEFINE_bool(dtx, false, "Enable DTX for encoding (-nodtx to disable).");
DEFINE_int(sub_packets, 1, "Number of sub packets to repacketize.");
} // namespace
class NetEqOpusQualityTest : public NetEqQualityTest {
protected:
NetEqOpusQualityTest();
void SetUp() override;
void TearDown() override;
int EncodeBlock(int16_t* in_data, size_t block_size_samples,
rtc::Buffer* payload, size_t max_bytes) override;
private:
WebRtcOpusEncInst* opus_encoder_;
OpusRepacketizer* repacketizer_;
size_t sub_block_size_samples_;
int bit_rate_kbps_;
bool fec_;
bool dtx_;
int complexity_;
int maxplaybackrate_;
int target_loss_rate_;
int sub_packets_;
int application_;
};
NetEqOpusQualityTest::NetEqOpusQualityTest()
: NetEqQualityTest(kOpusBlockDurationMs * FLAG_sub_packets,
kOpusSamplingKhz,
kOpusSamplingKhz,
NetEqDecoder::kDecoderOpus),
opus_encoder_(NULL),
repacketizer_(NULL),
sub_block_size_samples_(
static_cast<size_t>(kOpusBlockDurationMs * kOpusSamplingKhz)),
bit_rate_kbps_(FLAG_bit_rate_kbps),
fec_(FLAG_fec),
dtx_(FLAG_dtx),
complexity_(FLAG_complexity),
maxplaybackrate_(FLAG_maxplaybackrate),
target_loss_rate_(FLAG_reported_loss_rate),
sub_packets_(FLAG_sub_packets) {
// Flag validation
RTC_CHECK(FLAG_bit_rate_kbps >= 6 && FLAG_bit_rate_kbps <= 510)
<< "Invalid bit rate, should be between 6 and 510 kbps.";
RTC_CHECK(FLAG_complexity >= -1 && FLAG_complexity <= 10)
<< "Invalid complexity setting, should be between 0 and 10.";
RTC_CHECK(FLAG_application == 0 || FLAG_application == 1)
<< "Invalid application mode, should be 0 or 1.";
RTC_CHECK(FLAG_reported_loss_rate >= 0 && FLAG_reported_loss_rate <= 100)
<< "Invalid packet loss percentile, should be between 0 and 100.";
RTC_CHECK(FLAG_sub_packets >= 1 && FLAG_sub_packets <= 3)
<< "Invalid number of sub packets, should be between 1 and 3.";
// Redefine decoder type if input is stereo.
if (channels_ > 1) {
decoder_type_ = NetEqDecoder::kDecoderOpus_2ch;
}
application_ = FLAG_application;
}
void NetEqOpusQualityTest::SetUp() {
// Create encoder memory.
WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, application_);
ASSERT_TRUE(opus_encoder_);
// Create repacketizer.
repacketizer_ = opus_repacketizer_create();
ASSERT_TRUE(repacketizer_);
// Set bitrate.
EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, bit_rate_kbps_ * 1000));
if (fec_) {
EXPECT_EQ(0, WebRtcOpus_EnableFec(opus_encoder_));
}
if (dtx_) {
EXPECT_EQ(0, WebRtcOpus_EnableDtx(opus_encoder_));
}
EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_encoder_, complexity_));
EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, maxplaybackrate_));
EXPECT_EQ(0, WebRtcOpus_SetPacketLossRate(opus_encoder_,
target_loss_rate_));
NetEqQualityTest::SetUp();
}
void NetEqOpusQualityTest::TearDown() {
// Free memory.
EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
opus_repacketizer_destroy(repacketizer_);
NetEqQualityTest::TearDown();
}
int NetEqOpusQualityTest::EncodeBlock(int16_t* in_data,
size_t block_size_samples,
rtc::Buffer* payload, size_t max_bytes) {
EXPECT_EQ(block_size_samples, sub_block_size_samples_ * sub_packets_);
int16_t* pointer = in_data;
int value;
opus_repacketizer_init(repacketizer_);
for (int idx = 0; idx < sub_packets_; idx++) {
payload->AppendData(max_bytes, [&] (rtc::ArrayView<uint8_t> payload) {
value = WebRtcOpus_Encode(opus_encoder_,
pointer, sub_block_size_samples_,
max_bytes, payload.data());
Log() << "Encoded a frame with Opus mode "
<< (value == 0 ? 0 : payload[0] >> 3)
<< std::endl;
return (value >= 0) ? static_cast<size_t>(value) : 0;
});
if (OPUS_OK != opus_repacketizer_cat(repacketizer_,
payload->data(), value)) {
opus_repacketizer_init(repacketizer_);
// If the repacketization fails, we discard this frame.
return 0;
}
pointer += sub_block_size_samples_ * channels_;
}
value = opus_repacketizer_out(repacketizer_, payload->data(),
static_cast<opus_int32>(max_bytes));
EXPECT_GE(value, 0);
return value;
}
TEST_F(NetEqOpusQualityTest, Test) {
Simulate();
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <memory>
#include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h"
#include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "webrtc/rtc_base/checks.h"
#include "webrtc/rtc_base/flags.h"
#include "webrtc/rtc_base/safe_conversions.h"
#include "webrtc/test/testsupport/fileutils.h"
using testing::InitGoogleTest;
namespace webrtc {
namespace test {
namespace {
static const int kInputSampleRateKhz = 8;
static const int kOutputSampleRateKhz = 8;
DEFINE_int(frame_size_ms, 20, "Codec frame size (milliseconds).");
} // namespace
class NetEqPcmuQualityTest : public NetEqQualityTest {
protected:
NetEqPcmuQualityTest()
: NetEqQualityTest(FLAG_frame_size_ms,
kInputSampleRateKhz,
kOutputSampleRateKhz,
NetEqDecoder::kDecoderPCMu) {
// Flag validation
RTC_CHECK(FLAG_frame_size_ms >= 10 && FLAG_frame_size_ms <= 60 &&
(FLAG_frame_size_ms % 10) == 0)
<< "Invalid frame size, should be 10, 20, ..., 60 ms.";
}
void SetUp() override {
ASSERT_EQ(1u, channels_) << "PCMu supports only mono audio.";
AudioEncoderPcmU::Config config;
config.frame_size_ms = FLAG_frame_size_ms;
encoder_.reset(new AudioEncoderPcmU(config));
NetEqQualityTest::SetUp();
}
int EncodeBlock(int16_t* in_data,
size_t block_size_samples,
rtc::Buffer* payload, size_t max_bytes) override {
const size_t kFrameSizeSamples = 80; // Samples per 10 ms.
size_t encoded_samples = 0;
uint32_t dummy_timestamp = 0;
AudioEncoder::EncodedInfo info;
do {
info = encoder_->Encode(dummy_timestamp,
rtc::ArrayView<const int16_t>(
in_data + encoded_samples, kFrameSizeSamples),
payload);
encoded_samples += kFrameSizeSamples;
} while (info.encoded_bytes == 0);
return rtc::checked_cast<int>(info.encoded_bytes);
}
private:
std::unique_ptr<AudioEncoderPcmU> encoder_;
};
TEST_F(NetEqPcmuQualityTest, Test) {
Simulate();
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.h"
#include "webrtc/test/gtest.h"
#include "webrtc/test/testsupport/perf_test.h"
#include "webrtc/typedefs.h"
#include "webrtc/system_wrappers/include/field_trial.h"
// Runs a test with 10% packet losses and 10% clock drift, to exercise
// both loss concealment and time-stretching code.
TEST(NetEqPerformanceTest, Run) {
const int kSimulationTimeMs = 10000000;
const int kQuickSimulationTimeMs = 100000;
const int kLossPeriod = 10; // Drop every 10th packet.
const double kDriftFactor = 0.1;
int64_t runtime = webrtc::test::NetEqPerformanceTest::Run(
webrtc::field_trial::IsEnabled("WebRTC-QuickPerfTest")
? kQuickSimulationTimeMs
: kSimulationTimeMs,
kLossPeriod, kDriftFactor);
ASSERT_GT(runtime, 0);
webrtc::test::PrintResult(
"neteq_performance", "", "10_pl_10_drift", runtime, "ms", true);
}
// Runs a test with neither packet losses nor clock drift, to put
// emphasis on the "good-weather" code path, which is presumably much
// more lightweight.
TEST(NetEqPerformanceTest, RunClean) {
const int kSimulationTimeMs = 10000000;
const int kQuickSimulationTimeMs = 100000;
const int kLossPeriod = 0; // No losses.
const double kDriftFactor = 0.0; // No clock drift.
int64_t runtime = webrtc::test::NetEqPerformanceTest::Run(
webrtc::field_trial::IsEnabled("WebRTC-QuickPerfTest")
? kQuickSimulationTimeMs
: kSimulationTimeMs,
kLossPeriod, kDriftFactor);
ASSERT_GT(runtime, 0);
webrtc::test::PrintResult(
"neteq_performance", "", "0_pl_0_drift", runtime, "ms", true);
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdio.h>
#include <iostream>
#include "webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.h"
#include "webrtc/rtc_base/flags.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/typedefs.h"
// Define command line flags.
DEFINE_int(runtime_ms, 10000, "Simulated runtime in ms.");
DEFINE_int(lossrate, 10,
"Packet lossrate; drop every N packets.");
DEFINE_float(drift, 0.1f,
"Clockdrift factor.");
DEFINE_bool(help, false, "Print this message.");
int main(int argc, char* argv[]) {
std::string program_name = argv[0];
std::string usage = "Tool for measuring the speed of NetEq.\n"
"Usage: " + program_name + " [options]\n\n"
" --runtime_ms=N runtime in ms; default is 10000 ms\n"
" --lossrate=N drop every N packets; default is 10\n"
" --drift=F clockdrift factor between 0.0 and 1.0; "
"default is 0.1\n";
webrtc::test::SetExecutablePath(argv[0]);
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) ||
FLAG_help || argc != 1) {
printf("%s", usage.c_str());
if (FLAG_help) {
rtc::FlagList::Print(nullptr, false);
return 0;
}
return 1;
}
RTC_CHECK_GT(FLAG_runtime_ms, 0);
RTC_CHECK_GE(FLAG_lossrate, 0);
RTC_CHECK(FLAG_drift >= 0.0 && FLAG_drift < 1.0);
int64_t result =
webrtc::test::NetEqPerformanceTest::Run(FLAG_runtime_ms, FLAG_lossrate,
FLAG_drift);
if (result <= 0) {
std::cout << "There was an error" << std::endl;
return -1;
}
std::cout << "Simulation done" << std::endl;
std::cout << "Runtime = " << result << " ms" << std::endl;
return 0;
}