Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information. This CL was reviewed and approved in pieces in the following CLs: https://webrtc-codereview.appspot.com/24209004/ https://webrtc-codereview.appspot.com/24229004/ https://webrtc-codereview.appspot.com/24259004/ https://webrtc-codereview.appspot.com/25109004/ https://webrtc-codereview.appspot.com/26099004/ https://webrtc-codereview.appspot.com/27069004/ https://webrtc-codereview.appspot.com/27969004/ https://webrtc-codereview.appspot.com/27989004/ https://webrtc-codereview.appspot.com/29009004/ https://webrtc-codereview.appspot.com/30929004/ https://webrtc-codereview.appspot.com/30939004/ https://webrtc-codereview.appspot.com/31999004/ Committing as TBR to the original reviewers. BUG=chromium:81439 TEST=none TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom Review URL: https://webrtc-codereview.appspot.com/23129004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -13,18 +13,21 @@
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "webrtc/base/format_macros.h"
|
||||
#include "webrtc/system_wrappers/interface/tick_util.h"
|
||||
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
||||
|
||||
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,
|
||||
int32_t Channel::SendData(FrameType frameType,
|
||||
uint8_t payloadType,
|
||||
uint32_t timeStamp,
|
||||
const uint8_t* payloadData,
|
||||
size_t payloadSize,
|
||||
const RTPFragmentationHeader* fragmentation) {
|
||||
WebRtcRTPHeader rtpInfo;
|
||||
int32_t status;
|
||||
uint16_t payloadDataSize = payloadSize;
|
||||
size_t payloadDataSize = payloadSize;
|
||||
|
||||
rtpInfo.header.markerBit = false;
|
||||
rtpInfo.header.ssrc = 0;
|
||||
@ -52,8 +55,8 @@ int32_t Channel::SendData(const FrameType frameType, const uint8_t payloadType,
|
||||
(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];
|
||||
size_t REDheader = (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);
|
||||
@ -72,7 +75,7 @@ int32_t Channel::SendData(const FrameType frameType, const uint8_t payloadType,
|
||||
// single block (newest one)
|
||||
memcpy(_payloadData, payloadData + fragmentation->fragmentationOffset[0],
|
||||
fragmentation->fragmentationLength[0]);
|
||||
payloadDataSize = uint16_t(fragmentation->fragmentationLength[0]);
|
||||
payloadDataSize = fragmentation->fragmentationLength[0];
|
||||
rtpInfo.header.payloadType = fragmentation->fragmentationPlType[0];
|
||||
}
|
||||
} else {
|
||||
@ -121,7 +124,7 @@ int32_t Channel::SendData(const FrameType frameType, const uint8_t payloadType,
|
||||
}
|
||||
|
||||
// TODO(turajs): rewite this method.
|
||||
void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize) {
|
||||
void Channel::CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize) {
|
||||
int n;
|
||||
if ((rtpInfo.header.payloadType != _lastPayloadType)
|
||||
&& (_lastPayloadType != -1)) {
|
||||
@ -371,7 +374,7 @@ void Channel::PrintStats(CodecInst& codecInst) {
|
||||
payloadStats.frameSizeStats[k].frameSizeSample);
|
||||
printf("Average Rate.................. %.0f bits/sec\n",
|
||||
payloadStats.frameSizeStats[k].rateBitPerSec);
|
||||
printf("Maximum Payload-Size.......... %d Bytes\n",
|
||||
printf("Maximum Payload-Size.......... %" PRIuS " Bytes\n",
|
||||
payloadStats.frameSizeStats[k].maxPayloadLen);
|
||||
printf(
|
||||
"Maximum Instantaneous Rate.... %.0f bits/sec\n",
|
||||
|
||||
@ -27,7 +27,7 @@ class CriticalSectionWrapper;
|
||||
// TODO(turajs): Write constructor for this structure.
|
||||
struct ACMTestFrameSizeStats {
|
||||
uint16_t frameSizeSample;
|
||||
int16_t maxPayloadLen;
|
||||
size_t maxPayloadLen;
|
||||
uint32_t numPackets;
|
||||
uint64_t totalPayloadLenByte;
|
||||
uint64_t totalEncodedSamples;
|
||||
@ -39,7 +39,7 @@ struct ACMTestFrameSizeStats {
|
||||
struct ACMTestPayloadStats {
|
||||
bool newPacket;
|
||||
int16_t payloadType;
|
||||
int16_t lastPayloadLenByte;
|
||||
size_t lastPayloadLenByte;
|
||||
uint32_t lastTimestamp;
|
||||
ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
|
||||
};
|
||||
@ -51,9 +51,11 @@ class Channel : public AudioPacketizationCallback {
|
||||
~Channel();
|
||||
|
||||
virtual int32_t SendData(
|
||||
const FrameType frameType, const uint8_t payloadType,
|
||||
const uint32_t timeStamp, const uint8_t* payloadData,
|
||||
const uint16_t payloadSize,
|
||||
FrameType frameType,
|
||||
uint8_t payloadType,
|
||||
uint32_t timeStamp,
|
||||
const uint8_t* payloadData,
|
||||
size_t payloadSize,
|
||||
const RTPFragmentationHeader* fragmentation) OVERRIDE;
|
||||
|
||||
void RegisterReceiverACM(AudioCodingModule *acm);
|
||||
@ -93,7 +95,7 @@ class Channel : public AudioPacketizationCallback {
|
||||
}
|
||||
|
||||
private:
|
||||
void CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize);
|
||||
void CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize);
|
||||
|
||||
AudioCodingModule* _receiverACM;
|
||||
uint16_t _seqNo;
|
||||
|
||||
@ -37,7 +37,7 @@ TestPacketization::~TestPacketization() {
|
||||
int32_t TestPacketization::SendData(
|
||||
const FrameType /* frameType */, const uint8_t payloadType,
|
||||
const uint32_t timeStamp, const uint8_t* payloadData,
|
||||
const uint16_t payloadSize,
|
||||
const size_t payloadSize,
|
||||
const RTPFragmentationHeader* /* fragmentation */) {
|
||||
_rtpStream->Write(payloadType, timeStamp, _seqNo++, payloadData, payloadSize,
|
||||
_frequency);
|
||||
|
||||
@ -30,9 +30,11 @@ class TestPacketization : public AudioPacketizationCallback {
|
||||
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,
|
||||
const uint16_t payloadSize,
|
||||
const FrameType frameType,
|
||||
const uint8_t payloadType,
|
||||
const uint32_t timeStamp,
|
||||
const uint8_t* payloadData,
|
||||
const size_t payloadSize,
|
||||
const RTPFragmentationHeader* fragmentation) OVERRIDE;
|
||||
|
||||
private:
|
||||
@ -92,8 +94,8 @@ class Receiver {
|
||||
uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
|
||||
RTPStream* _rtpStream;
|
||||
WebRtcRTPHeader _rtpInfo;
|
||||
uint16_t _realPayloadSizeBytes;
|
||||
uint16_t _payloadSizeBytes;
|
||||
size_t _realPayloadSizeBytes;
|
||||
size_t _payloadSizeBytes;
|
||||
uint32_t _nextTime;
|
||||
};
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "RTPFile.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits>
|
||||
|
||||
#ifdef WIN32
|
||||
# include <Winsock2.h>
|
||||
@ -60,7 +61,7 @@ void RTPStream::MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
|
||||
}
|
||||
|
||||
RTPPacket::RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
|
||||
const uint8_t* payloadData, uint16_t payloadSize,
|
||||
const uint8_t* payloadData, size_t payloadSize,
|
||||
uint32_t frequency)
|
||||
: payloadType(payloadType),
|
||||
timeStamp(timeStamp),
|
||||
@ -87,7 +88,7 @@ RTPBuffer::~RTPBuffer() {
|
||||
|
||||
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) {
|
||||
const size_t payloadSize, uint32_t frequency) {
|
||||
RTPPacket *packet = new RTPPacket(payloadType, timeStamp, seqNo, payloadData,
|
||||
payloadSize, frequency);
|
||||
_queueRWLock->AcquireLockExclusive();
|
||||
@ -95,8 +96,8 @@ void RTPBuffer::Write(const uint8_t payloadType, const uint32_t timeStamp,
|
||||
_queueRWLock->ReleaseLockExclusive();
|
||||
}
|
||||
|
||||
uint16_t RTPBuffer::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
uint16_t payloadSize, uint32_t* offset) {
|
||||
size_t RTPBuffer::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
size_t payloadSize, uint32_t* offset) {
|
||||
_queueRWLock->AcquireLockShared();
|
||||
RTPPacket *packet = _rtpQueue.front();
|
||||
_rtpQueue.pop();
|
||||
@ -143,21 +144,11 @@ void RTPFile::WriteHeader() {
|
||||
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;
|
||||
}
|
||||
EXPECT_EQ(1u, fwrite(&dummy_variable, 4, 1, _rtpFile));
|
||||
EXPECT_EQ(1u, fwrite(&dummy_variable, 4, 1, _rtpFile));
|
||||
EXPECT_EQ(1u, fwrite(&dummy_variable, 4, 1, _rtpFile));
|
||||
EXPECT_EQ(1u, fwrite(&dummy_variable, 2, 1, _rtpFile));
|
||||
EXPECT_EQ(1u, fwrite(&dummy_variable, 2, 1, _rtpFile));
|
||||
fflush(_rtpFile);
|
||||
}
|
||||
|
||||
@ -180,35 +171,26 @@ void RTPFile::ReadHeader() {
|
||||
|
||||
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) {
|
||||
const size_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);
|
||||
ASSERT_LE(12 + payloadSize + 8, std::numeric_limits<u_short>::max());
|
||||
uint16_t lengthBytes = htons(static_cast<u_short>(12 + payloadSize + 8));
|
||||
uint16_t plen = htons(static_cast<u_short>(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;
|
||||
}
|
||||
EXPECT_EQ(1u, fwrite(&lengthBytes, 2, 1, _rtpFile));
|
||||
EXPECT_EQ(1u, fwrite(&plen, 2, 1, _rtpFile));
|
||||
EXPECT_EQ(1u, fwrite(&offsetMs, 4, 1, _rtpFile));
|
||||
EXPECT_EQ(1u, fwrite(&rtpHeader, 12, 1, _rtpFile));
|
||||
EXPECT_EQ(payloadSize, fwrite(payloadData, 1, payloadSize, _rtpFile));
|
||||
}
|
||||
|
||||
uint16_t RTPFile::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
uint16_t payloadSize, uint32_t* offset) {
|
||||
size_t RTPFile::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
size_t payloadSize, uint32_t* offset) {
|
||||
uint16_t lengthBytes;
|
||||
uint16_t plen;
|
||||
uint8_t rtpHeader[12];
|
||||
@ -237,7 +219,7 @@ uint16_t RTPFile::Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
if (lengthBytes < 20) {
|
||||
return 0;
|
||||
}
|
||||
if (payloadSize < (lengthBytes - 20)) {
|
||||
if (payloadSize < static_cast<size_t>((lengthBytes - 20))) {
|
||||
return 0;
|
||||
}
|
||||
lengthBytes -= 20;
|
||||
|
||||
@ -28,12 +28,12 @@ class 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;
|
||||
const size_t payloadSize, uint32_t frequency) = 0;
|
||||
|
||||
// Returns the packet's payload size. Zero should be treated as an
|
||||
// end-of-stream (in the case that EndOfFile() is true) or an error.
|
||||
virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
uint16_t payloadSize, uint32_t* offset) = 0;
|
||||
virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
size_t payloadSize, uint32_t* offset) = 0;
|
||||
virtual bool EndOfFile() const = 0;
|
||||
|
||||
protected:
|
||||
@ -46,7 +46,7 @@ class RTPStream {
|
||||
class RTPPacket {
|
||||
public:
|
||||
RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
|
||||
const uint8_t* payloadData, uint16_t payloadSize,
|
||||
const uint8_t* payloadData, size_t payloadSize,
|
||||
uint32_t frequency);
|
||||
|
||||
~RTPPacket();
|
||||
@ -55,7 +55,7 @@ class RTPPacket {
|
||||
uint32_t timeStamp;
|
||||
int16_t seqNo;
|
||||
uint8_t* payloadData;
|
||||
uint16_t payloadSize;
|
||||
size_t payloadSize;
|
||||
uint32_t frequency;
|
||||
};
|
||||
|
||||
@ -67,10 +67,10 @@ class RTPBuffer : public 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) OVERRIDE;
|
||||
const size_t payloadSize, uint32_t frequency) OVERRIDE;
|
||||
|
||||
virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
uint16_t payloadSize, uint32_t* offset) OVERRIDE;
|
||||
virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
size_t payloadSize, uint32_t* offset) OVERRIDE;
|
||||
|
||||
virtual bool EndOfFile() const OVERRIDE;
|
||||
|
||||
@ -99,10 +99,10 @@ class RTPFile : public 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) OVERRIDE;
|
||||
const size_t payloadSize, uint32_t frequency) OVERRIDE;
|
||||
|
||||
virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
uint16_t payloadSize, uint32_t* offset) OVERRIDE;
|
||||
virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
|
||||
size_t payloadSize, uint32_t* offset) OVERRIDE;
|
||||
|
||||
virtual bool EndOfFile() const OVERRIDE {
|
||||
return _rtpEOF;
|
||||
|
||||
@ -10,7 +10,8 @@
|
||||
|
||||
#include "webrtc/modules/audio_coding/main/test/TestAllCodecs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -32,6 +33,10 @@
|
||||
// The test loops through all available mono codecs, encode at "a" sends over
|
||||
// the channel, and decodes at "b".
|
||||
|
||||
namespace {
|
||||
const size_t kVariableSize = std::numeric_limits<size_t>::max();
|
||||
}
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Class for simulating packet handling.
|
||||
@ -54,7 +59,7 @@ void TestPack::RegisterReceiverACM(AudioCodingModule* acm) {
|
||||
|
||||
int32_t TestPack::SendData(FrameType frame_type, uint8_t payload_type,
|
||||
uint32_t timestamp, const uint8_t* payload_data,
|
||||
uint16_t payload_size,
|
||||
size_t payload_size,
|
||||
const RTPFragmentationHeader* fragmentation) {
|
||||
WebRtcRTPHeader rtp_info;
|
||||
int32_t status;
|
||||
@ -87,7 +92,7 @@ int32_t TestPack::SendData(FrameType frame_type, uint8_t payload_type,
|
||||
return status;
|
||||
}
|
||||
|
||||
uint16_t TestPack::payload_size() {
|
||||
size_t TestPack::payload_size() {
|
||||
return payload_size_;
|
||||
}
|
||||
|
||||
@ -459,13 +464,13 @@ void TestAllCodecs::Perform() {
|
||||
test_count_++;
|
||||
OpenOutFile(test_count_);
|
||||
char codec_isac[] = "ISAC";
|
||||
RegisterSendCodec('A', codec_isac, 16000, -1, 480, -1);
|
||||
RegisterSendCodec('A', codec_isac, 16000, -1, 480, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_isac, 16000, -1, 960, -1);
|
||||
RegisterSendCodec('A', codec_isac, 16000, -1, 960, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_isac, 16000, 15000, 480, -1);
|
||||
RegisterSendCodec('A', codec_isac, 16000, 15000, 480, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_isac, 16000, 32000, 960, -1);
|
||||
RegisterSendCodec('A', codec_isac, 16000, 32000, 960, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
outfile_b_.Close();
|
||||
#endif
|
||||
@ -475,13 +480,13 @@ void TestAllCodecs::Perform() {
|
||||
}
|
||||
test_count_++;
|
||||
OpenOutFile(test_count_);
|
||||
RegisterSendCodec('A', codec_isac, 32000, -1, 960, -1);
|
||||
RegisterSendCodec('A', codec_isac, 32000, -1, 960, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_isac, 32000, 56000, 960, -1);
|
||||
RegisterSendCodec('A', codec_isac, 32000, 56000, 960, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_isac, 32000, 37000, 960, -1);
|
||||
RegisterSendCodec('A', codec_isac, 32000, 37000, 960, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_isac, 32000, 32000, 960, -1);
|
||||
RegisterSendCodec('A', codec_isac, 32000, 32000, 960, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
outfile_b_.Close();
|
||||
#endif
|
||||
@ -611,19 +616,19 @@ void TestAllCodecs::Perform() {
|
||||
test_count_++;
|
||||
OpenOutFile(test_count_);
|
||||
char codec_opus[] = "OPUS";
|
||||
RegisterSendCodec('A', codec_opus, 48000, 6000, 480, -1);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 6000, 480, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 20000, 480*2, -1);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 20000, 480*2, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 32000, 480*4, -1);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 32000, 480*4, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 48000, 480, -1);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 48000, 480, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, -1);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 96000, 480*6, -1);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 96000, 480*6, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 500000, 480*2, -1);
|
||||
RegisterSendCodec('A', codec_opus, 48000, 500000, 480*2, kVariableSize);
|
||||
Run(channel_a_to_b_);
|
||||
outfile_b_.Close();
|
||||
#endif
|
||||
@ -686,10 +691,11 @@ void TestAllCodecs::Perform() {
|
||||
// packet_size - packet size in samples
|
||||
// extra_byte - if extra bytes needed compared to the bitrate
|
||||
// used when registering, can be an internal header
|
||||
// set to -1 if the codec is a variable rate codec
|
||||
// set to kVariableSize if the codec is a variable
|
||||
// rate codec
|
||||
void TestAllCodecs::RegisterSendCodec(char side, char* codec_name,
|
||||
int32_t sampling_freq_hz, int rate,
|
||||
int packet_size, int extra_byte) {
|
||||
int packet_size, size_t extra_byte) {
|
||||
if (test_mode_ != 0) {
|
||||
// Print out codec and settings.
|
||||
printf("codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
|
||||
@ -711,14 +717,14 @@ void TestAllCodecs::RegisterSendCodec(char side, char* codec_name,
|
||||
|
||||
// Store the expected packet size in bytes, used to validate the received
|
||||
// packet. If variable rate codec (extra_byte == -1), set to -1.
|
||||
if (extra_byte != -1) {
|
||||
if (extra_byte != kVariableSize) {
|
||||
// Add 0.875 to always round up to a whole byte
|
||||
packet_size_bytes_ = static_cast<int>(static_cast<float>(packet_size
|
||||
* rate) / static_cast<float>(sampling_freq_hz * 8) + 0.875)
|
||||
+ extra_byte;
|
||||
packet_size_bytes_ = static_cast<size_t>(
|
||||
static_cast<float>(packet_size * rate) /
|
||||
static_cast<float>(sampling_freq_hz * 8) + 0.875) + extra_byte;
|
||||
} else {
|
||||
// Packets will have a variable size.
|
||||
packet_size_bytes_ = -1;
|
||||
packet_size_bytes_ = kVariableSize;
|
||||
}
|
||||
|
||||
// Set pointer to the ACM where to register the codec.
|
||||
@ -751,7 +757,7 @@ void TestAllCodecs::Run(TestPack* channel) {
|
||||
AudioFrame audio_frame;
|
||||
|
||||
int32_t out_freq_hz = outfile_b_.SamplingFrequency();
|
||||
uint16_t receive_size;
|
||||
size_t receive_size;
|
||||
uint32_t timestamp_diff;
|
||||
channel->reset_payload_size();
|
||||
int error_count = 0;
|
||||
@ -768,8 +774,8 @@ void TestAllCodecs::Run(TestPack* channel) {
|
||||
// Verify that the received packet size matches the settings.
|
||||
receive_size = channel->payload_size();
|
||||
if (receive_size) {
|
||||
if ((static_cast<int>(receive_size) != packet_size_bytes_) &&
|
||||
(packet_size_bytes_ > -1)) {
|
||||
if ((receive_size != packet_size_bytes_) &&
|
||||
(packet_size_bytes_ != kVariableSize)) {
|
||||
error_count++;
|
||||
}
|
||||
|
||||
|
||||
@ -29,12 +29,14 @@ class TestPack : public AudioPacketizationCallback {
|
||||
void RegisterReceiverACM(AudioCodingModule* acm);
|
||||
|
||||
virtual int32_t SendData(
|
||||
FrameType frame_type, uint8_t payload_type,
|
||||
uint32_t timestamp, const uint8_t* payload_data,
|
||||
uint16_t payload_size,
|
||||
FrameType frame_type,
|
||||
uint8_t payload_type,
|
||||
uint32_t timestamp,
|
||||
const uint8_t* payload_data,
|
||||
size_t payload_size,
|
||||
const RTPFragmentationHeader* fragmentation) OVERRIDE;
|
||||
|
||||
uint16_t payload_size();
|
||||
size_t payload_size();
|
||||
uint32_t timestamp_diff();
|
||||
void reset_payload_size();
|
||||
|
||||
@ -45,7 +47,7 @@ class TestPack : public AudioPacketizationCallback {
|
||||
uint32_t timestamp_diff_;
|
||||
uint32_t last_in_timestamp_;
|
||||
uint64_t total_bytes_;
|
||||
uint16_t payload_size_;
|
||||
size_t payload_size_;
|
||||
};
|
||||
|
||||
class TestAllCodecs : public ACMTest {
|
||||
@ -61,7 +63,7 @@ class TestAllCodecs : public ACMTest {
|
||||
// This is useful for codecs which support several sampling frequency.
|
||||
// Note! Only mono mode is tested in this test.
|
||||
void RegisterSendCodec(char side, char* codec_name, int32_t sampling_freq_hz,
|
||||
int rate, int packet_size, int extra_byte);
|
||||
int rate, int packet_size, size_t extra_byte);
|
||||
|
||||
void Run(TestPack* channel);
|
||||
void OpenOutFile(int test_number);
|
||||
@ -75,7 +77,7 @@ class TestAllCodecs : public ACMTest {
|
||||
PCMFile outfile_b_;
|
||||
int test_count_;
|
||||
int packet_size_samples_;
|
||||
int packet_size_bytes_;
|
||||
size_t packet_size_bytes_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -48,7 +48,7 @@ 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 size_t payload_size,
|
||||
const RTPFragmentationHeader* fragmentation) {
|
||||
WebRtcRTPHeader rtp_info;
|
||||
int32_t status = 0;
|
||||
@ -114,18 +114,26 @@ TestStereo::TestStereo(int test_mode)
|
||||
test_cntr_(0),
|
||||
pack_size_samp_(0),
|
||||
pack_size_bytes_(0),
|
||||
counter_(0),
|
||||
g722_pltype_(0),
|
||||
l16_8khz_pltype_(-1),
|
||||
l16_16khz_pltype_(-1),
|
||||
l16_32khz_pltype_(-1),
|
||||
pcma_pltype_(-1),
|
||||
pcmu_pltype_(-1),
|
||||
celt_pltype_(-1),
|
||||
opus_pltype_(-1),
|
||||
cn_8khz_pltype_(-1),
|
||||
cn_16khz_pltype_(-1),
|
||||
cn_32khz_pltype_(-1) {
|
||||
counter_(0)
|
||||
#ifdef WEBRTC_CODEC_G722
|
||||
, g722_pltype_(0)
|
||||
#endif
|
||||
#ifdef WEBRTC_CODEC_PCM16
|
||||
, l16_8khz_pltype_(-1)
|
||||
, l16_16khz_pltype_(-1)
|
||||
, l16_32khz_pltype_(-1)
|
||||
#endif
|
||||
#ifdef PCMA_AND_PCMU
|
||||
, pcma_pltype_(-1)
|
||||
, pcmu_pltype_(-1)
|
||||
#endif
|
||||
#ifdef WEBRTC_CODEC_CELT
|
||||
, celt_pltype_(-1)
|
||||
#endif
|
||||
#ifdef WEBRTC_CODEC_OPUS
|
||||
, opus_pltype_(-1)
|
||||
#endif
|
||||
{
|
||||
// test_mode = 0 for silent test (auto test)
|
||||
test_mode_ = test_mode;
|
||||
}
|
||||
@ -302,7 +310,6 @@ void TestStereo::Perform() {
|
||||
Run(channel_a2b_, audio_channels, codec_channels);
|
||||
out_file_.Close();
|
||||
#endif
|
||||
#define PCMA_AND_PCMU
|
||||
#ifdef PCMA_AND_PCMU
|
||||
if (test_mode_ != 0) {
|
||||
printf("===========================================================\n");
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
#include "webrtc/modules/audio_coding/main/test/Channel.h"
|
||||
#include "webrtc/modules/audio_coding/main/test/PCMFile.h"
|
||||
|
||||
#define PCMA_AND_PCMU
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
enum StereoMonoMode {
|
||||
@ -38,7 +40,7 @@ class TestPackStereo : public AudioPacketizationCallback {
|
||||
const uint8_t payload_type,
|
||||
const uint32_t timestamp,
|
||||
const uint8_t* payload_data,
|
||||
const uint16_t payload_size,
|
||||
const size_t payload_size,
|
||||
const RTPFragmentationHeader* fragmentation) OVERRIDE;
|
||||
|
||||
uint16_t payload_size();
|
||||
@ -78,11 +80,6 @@ class TestStereo : public ACMTest {
|
||||
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,
|
||||
const uint16_t payload_size,
|
||||
const RTPFragmentationHeader* fragmentation);
|
||||
|
||||
int test_mode_;
|
||||
|
||||
scoped_ptr<AudioCodingModule> acm_a_;
|
||||
@ -100,17 +97,24 @@ class TestStereo : public ACMTest {
|
||||
char* send_codec_name_;
|
||||
|
||||
// Payload types for stereo codecs and CNG
|
||||
#ifdef WEBRTC_CODEC_G722
|
||||
int g722_pltype_;
|
||||
#endif
|
||||
#ifdef WEBRTC_CODEC_PCM16
|
||||
int l16_8khz_pltype_;
|
||||
int l16_16khz_pltype_;
|
||||
int l16_32khz_pltype_;
|
||||
#endif
|
||||
#ifdef PCMA_AND_PCMU
|
||||
int pcma_pltype_;
|
||||
int pcmu_pltype_;
|
||||
#endif
|
||||
#ifdef WEBRTC_CODEC_CELT
|
||||
int celt_pltype_;
|
||||
#endif
|
||||
#ifdef WEBRTC_CODEC_OPUS
|
||||
int opus_pltype_;
|
||||
int cn_8khz_pltype_;
|
||||
int cn_16khz_pltype_;
|
||||
int cn_32khz_pltype_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -36,9 +36,11 @@ class DualStreamTest : public AudioPacketizationCallback,
|
||||
void ApiTest();
|
||||
|
||||
virtual int32_t SendData(
|
||||
FrameType frameType, uint8_t payload_type,
|
||||
uint32_t timestamp, const uint8_t* payload_data,
|
||||
uint16_t payload_size,
|
||||
FrameType frameType,
|
||||
uint8_t payload_type,
|
||||
uint32_t timestamp,
|
||||
const uint8_t* payload_data,
|
||||
size_t payload_size,
|
||||
const RTPFragmentationHeader* fragmentation) OVERRIDE;
|
||||
|
||||
void Perform(bool start_in_sync, int num_channels_input);
|
||||
@ -49,9 +51,9 @@ class DualStreamTest : public AudioPacketizationCallback,
|
||||
void PopulateCodecInstances(int frame_size_primary_ms,
|
||||
int num_channels_primary, int sampling_rate);
|
||||
|
||||
void Validate(bool start_in_sync, int tolerance);
|
||||
void Validate(bool start_in_sync, size_t tolerance);
|
||||
bool EqualTimestamp(int stream, int position);
|
||||
int EqualPayloadLength(int stream, int position);
|
||||
size_t EqualPayloadLength(int stream, int position);
|
||||
bool EqualPayloadData(int stream, int position);
|
||||
|
||||
static const int kMaxNumStoredPayloads = 2;
|
||||
@ -77,8 +79,8 @@ class DualStreamTest : public AudioPacketizationCallback,
|
||||
uint32_t timestamp_ref_[kMaxNumStreams][kMaxNumStoredPayloads];
|
||||
uint32_t timestamp_dual_[kMaxNumStreams][kMaxNumStoredPayloads];
|
||||
|
||||
int payload_len_ref_[kMaxNumStreams][kMaxNumStoredPayloads];
|
||||
int payload_len_dual_[kMaxNumStreams][kMaxNumStoredPayloads];
|
||||
size_t payload_len_ref_[kMaxNumStreams][kMaxNumStoredPayloads];
|
||||
size_t payload_len_dual_[kMaxNumStreams][kMaxNumStoredPayloads];
|
||||
|
||||
uint8_t payload_data_ref_[kMaxNumStreams][MAX_PAYLOAD_SIZE_BYTE
|
||||
* kMaxNumStoredPayloads];
|
||||
@ -174,7 +176,7 @@ void DualStreamTest::Perform(bool start_in_sync, int num_channels_input) {
|
||||
pcm_file.ReadStereo(num_channels_input == 2);
|
||||
AudioFrame audio_frame;
|
||||
|
||||
int tolerance = 0;
|
||||
size_t tolerance = 0;
|
||||
if (num_channels_input == 2 && primary_encoder_.channels == 2
|
||||
&& secondary_encoder_.channels == 1) {
|
||||
tolerance = 12;
|
||||
@ -253,10 +255,10 @@ bool DualStreamTest::EqualTimestamp(int stream_index, int position) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int DualStreamTest::EqualPayloadLength(int stream_index, int position) {
|
||||
return abs(
|
||||
payload_len_dual_[stream_index][position]
|
||||
- payload_len_ref_[stream_index][position]);
|
||||
size_t DualStreamTest::EqualPayloadLength(int stream_index, int position) {
|
||||
size_t dual = payload_len_dual_[stream_index][position];
|
||||
size_t ref = payload_len_ref_[stream_index][position];
|
||||
return (dual > ref) ? (dual - ref) : (ref - dual);
|
||||
}
|
||||
|
||||
bool DualStreamTest::EqualPayloadData(int stream_index, int position) {
|
||||
@ -264,7 +266,7 @@ bool DualStreamTest::EqualPayloadData(int stream_index, int position) {
|
||||
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++) {
|
||||
for (size_t 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]) {
|
||||
return false;
|
||||
@ -273,9 +275,9 @@ bool DualStreamTest::EqualPayloadData(int stream_index, int position) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void DualStreamTest::Validate(bool start_in_sync, int tolerance) {
|
||||
void DualStreamTest::Validate(bool start_in_sync, size_t tolerance) {
|
||||
for (int stream_index = 0; stream_index < kMaxNumStreams; stream_index++) {
|
||||
int my_tolerance = stream_index == kPrimary ? 0 : tolerance;
|
||||
size_t 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) {
|
||||
@ -296,7 +298,7 @@ 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,
|
||||
size_t payload_size,
|
||||
const RTPFragmentationHeader* fragmentation) {
|
||||
int position;
|
||||
int stream_index;
|
||||
|
||||
@ -46,7 +46,7 @@ class TargetDelayTest : public ::testing::Test {
|
||||
|
||||
int16_t audio[kFrameSizeSamples];
|
||||
const int kRange = 0x7FF; // 2047, easy for masking.
|
||||
for (int n = 0; n < kFrameSizeSamples; ++n)
|
||||
for (size_t n = 0; n < kFrameSizeSamples; ++n)
|
||||
audio[n] = (rand() & kRange) - kRange / 2;
|
||||
WebRtcPcm16b_Encode(audio, kFrameSizeSamples, payload_);
|
||||
}
|
||||
@ -133,7 +133,7 @@ class TargetDelayTest : public ::testing::Test {
|
||||
private:
|
||||
static const int kSampleRateHz = 16000;
|
||||
static const int kNum10msPerFrame = 2;
|
||||
static const int kFrameSizeSamples = 320; // 20 ms @ 16 kHz.
|
||||
static const size_t kFrameSizeSamples = 320; // 20 ms @ 16 kHz.
|
||||
// payload-len = frame-samples * 2 bytes/sample.
|
||||
static const int kPayloadLenBytes = 320 * 2;
|
||||
// Inter-arrival time in number of packets in a jittery channel. One is no
|
||||
|
||||
Reference in New Issue
Block a user