Cleanup for Rtp Rtcp API test.

BUG=
R=pbos@webrtc.org, stefan@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@8098 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
changbin.shao@intel.com
2015-01-20 05:42:52 +00:00
parent 8e327c45d0
commit 9691b36995
2 changed files with 134 additions and 130 deletions

View File

@ -15,87 +15,145 @@
using namespace webrtc; using namespace webrtc;
namespace webrtc {
void LoopBackTransport::SetSendModule(RtpRtcp* rtp_rtcp_module,
RTPPayloadRegistry* payload_registry,
RtpReceiver* receiver,
ReceiveStatistics* receive_statistics) {
rtp_rtcp_module_ = rtp_rtcp_module;
rtp_payload_registry_ = payload_registry;
rtp_receiver_ = receiver;
receive_statistics_ = receive_statistics;
}
void LoopBackTransport::DropEveryNthPacket(int n) {
packet_loss_ = n;
}
int LoopBackTransport::SendPacket(int channel, const void* data, size_t len) {
count_++;
if (packet_loss_ > 0) {
if ((count_ % packet_loss_) == 0) {
return len;
}
}
RTPHeader header;
scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
if (!parser->Parse(static_cast<const uint8_t*>(data), len, &header)) {
return -1;
}
PayloadUnion payload_specific;
if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
&payload_specific)) {
return -1;
}
receive_statistics_->IncomingPacket(header, len, false);
if (!rtp_receiver_->IncomingRtpPacket(header,
static_cast<const uint8_t*>(data), len,
payload_specific, true)) {
return -1;
}
return len;
}
int LoopBackTransport::SendRTCPPacket(int channel,
const void* data,
size_t len) {
if (rtp_rtcp_module_->IncomingRtcpPacket((const uint8_t*)data, len) < 0) {
return -1;
}
return static_cast<int>(len);
}
int32_t TestRtpReceiver::OnReceivedPayloadData(
const uint8_t* payload_data,
const size_t payload_size,
const webrtc::WebRtcRTPHeader* rtp_header) {
EXPECT_LE(payload_size, sizeof(payload_data_));
memcpy(payload_data_, payload_data, payload_size);
memcpy(&rtp_header_, rtp_header, sizeof(rtp_header_));
payload_size_ = payload_size;
return 0;
}
} // namespace webrtc
class RtpRtcpAPITest : public ::testing::Test { class RtpRtcpAPITest : public ::testing::Test {
protected: protected:
RtpRtcpAPITest() : module(NULL), fake_clock(123456) { RtpRtcpAPITest() : fake_clock_(123456) {
test_csrcs.push_back(1234); test_csrcs_.push_back(1234);
test_csrcs.push_back(2345); test_csrcs_.push_back(2345);
test_id = 123; test_id = 123;
test_ssrc = 3456; test_ssrc_ = 3456;
test_timestamp = 4567; test_timestamp_ = 4567;
test_sequence_number = 2345; test_sequence_number_ = 2345;
} }
~RtpRtcpAPITest() {} ~RtpRtcpAPITest() {}
virtual void SetUp() { virtual void SetUp() OVERRIDE {
RtpRtcp::Configuration configuration; RtpRtcp::Configuration configuration;
configuration.id = test_id; configuration.id = test_id;
configuration.audio = true; configuration.audio = true;
configuration.clock = &fake_clock; configuration.clock = &fake_clock_;
module = RtpRtcp::CreateRtpRtcp(configuration); module_.reset(RtpRtcp::CreateRtpRtcp(configuration));
rtp_payload_registry_.reset(new RTPPayloadRegistry( rtp_payload_registry_.reset(new RTPPayloadRegistry(
RTPPayloadStrategy::CreateStrategy(true))); RTPPayloadStrategy::CreateStrategy(true)));
rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver( rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver(
test_id, &fake_clock, NULL, NULL, NULL, rtp_payload_registry_.get())); test_id, &fake_clock_, NULL, NULL, NULL, rtp_payload_registry_.get()));
}
virtual void TearDown() {
delete module;
} }
int test_id; int test_id;
scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
scoped_ptr<RtpReceiver> rtp_receiver_; scoped_ptr<RtpReceiver> rtp_receiver_;
RtpRtcp* module; scoped_ptr<RtpRtcp> module_;
uint32_t test_ssrc; uint32_t test_ssrc_;
uint32_t test_timestamp; uint32_t test_timestamp_;
uint16_t test_sequence_number; uint16_t test_sequence_number_;
std::vector<uint32_t> test_csrcs; std::vector<uint32_t> test_csrcs_;
SimulatedClock fake_clock; SimulatedClock fake_clock_;
}; };
TEST_F(RtpRtcpAPITest, Basic) { TEST_F(RtpRtcpAPITest, Basic) {
module->SetSequenceNumber(test_sequence_number); module_->SetSequenceNumber(test_sequence_number_);
EXPECT_EQ(test_sequence_number, module->SequenceNumber()); EXPECT_EQ(test_sequence_number_, module_->SequenceNumber());
module->SetStartTimestamp(test_timestamp); module_->SetStartTimestamp(test_timestamp_);
EXPECT_EQ(test_timestamp, module->StartTimestamp()); EXPECT_EQ(test_timestamp_, module_->StartTimestamp());
EXPECT_FALSE(module->Sending()); EXPECT_FALSE(module_->Sending());
EXPECT_EQ(0, module->SetSendingStatus(true)); EXPECT_EQ(0, module_->SetSendingStatus(true));
EXPECT_TRUE(module->Sending()); EXPECT_TRUE(module_->Sending());
} }
TEST_F(RtpRtcpAPITest, MTU) { TEST_F(RtpRtcpAPITest, MTU) {
EXPECT_EQ(-1, module->SetMaxTransferUnit(10)); EXPECT_EQ(-1, module_->SetMaxTransferUnit(10));
EXPECT_EQ(-1, module->SetMaxTransferUnit(IP_PACKET_SIZE + 1)); EXPECT_EQ(-1, module_->SetMaxTransferUnit(IP_PACKET_SIZE + 1));
EXPECT_EQ(0, module->SetMaxTransferUnit(1234)); EXPECT_EQ(0, module_->SetMaxTransferUnit(1234));
EXPECT_EQ(1234-20-8, module->MaxPayloadLength()); EXPECT_EQ(1234 - 20 - 8, module_->MaxPayloadLength());
EXPECT_EQ(0, module->SetTransportOverhead(true, true, 12)); EXPECT_EQ(0, module_->SetTransportOverhead(true, true, 12));
EXPECT_EQ(1234 - 20- 20 -20 - 12, module->MaxPayloadLength()); EXPECT_EQ(1234 - 20 - 20 - 20 - 12, module_->MaxPayloadLength());
EXPECT_EQ(0, module->SetTransportOverhead(false, false, 0)); EXPECT_EQ(0, module_->SetTransportOverhead(false, false, 0));
EXPECT_EQ(1234 - 20 - 8, module->MaxPayloadLength()); EXPECT_EQ(1234 - 20 - 8, module_->MaxPayloadLength());
} }
TEST_F(RtpRtcpAPITest, SSRC) { TEST_F(RtpRtcpAPITest, SSRC) {
module->SetSSRC(test_ssrc); module_->SetSSRC(test_ssrc_);
EXPECT_EQ(test_ssrc, module->SSRC()); EXPECT_EQ(test_ssrc_, module_->SSRC());
} }
TEST_F(RtpRtcpAPITest, RTCP) { TEST_F(RtpRtcpAPITest, RTCP) {
EXPECT_EQ(kRtcpOff, module->RTCP()); EXPECT_EQ(kRtcpOff, module_->RTCP());
module->SetRTCPStatus(kRtcpCompound); module_->SetRTCPStatus(kRtcpCompound);
EXPECT_EQ(kRtcpCompound, module->RTCP()); EXPECT_EQ(kRtcpCompound, module_->RTCP());
EXPECT_EQ(0, module->SetCNAME("john.doe@test.test")); EXPECT_EQ(0, module_->SetCNAME("john.doe@test.test"));
EXPECT_FALSE(module->TMMBR()); EXPECT_FALSE(module_->TMMBR());
module->SetTMMBRStatus(true); module_->SetTMMBRStatus(true);
EXPECT_TRUE(module->TMMBR()); EXPECT_TRUE(module_->TMMBR());
module->SetTMMBRStatus(false); module_->SetTMMBRStatus(false);
EXPECT_FALSE(module->TMMBR()); EXPECT_FALSE(module_->TMMBR());
EXPECT_EQ(kNackOff, rtp_receiver_->NACK()); EXPECT_EQ(kNackOff, rtp_receiver_->NACK());
rtp_receiver_->SetNACKStatus(kNackRtcp); rtp_receiver_->SetNACKStatus(kNackRtcp);
@ -103,17 +161,14 @@ TEST_F(RtpRtcpAPITest, RTCP) {
} }
TEST_F(RtpRtcpAPITest, RtxSender) { TEST_F(RtpRtcpAPITest, RtxSender) {
module->SetRtxSendStatus(kRtxRetransmitted); module_->SetRtxSendStatus(kRtxRetransmitted);
int rtx_mode = module->RtxSendStatus(); EXPECT_EQ(kRtxRetransmitted, module_->RtxSendStatus());
EXPECT_EQ(kRtxRetransmitted, rtx_mode);
module->SetRtxSendStatus(kRtxOff); module_->SetRtxSendStatus(kRtxOff);
rtx_mode = module->RtxSendStatus(); EXPECT_EQ(kRtxOff, module_->RtxSendStatus());
EXPECT_EQ(kRtxOff, rtx_mode);
module->SetRtxSendStatus(kRtxRetransmitted); module_->SetRtxSendStatus(kRtxRetransmitted);
rtx_mode = module->RtxSendStatus(); EXPECT_EQ(kRtxRetransmitted, module_->RtxSendStatus());
EXPECT_EQ(kRtxRetransmitted, rtx_mode);
} }
TEST_F(RtpRtcpAPITest, RtxReceiver) { TEST_F(RtpRtcpAPITest, RtxReceiver) {

View File

@ -25,96 +25,45 @@ namespace webrtc {
class LoopBackTransport : public webrtc::Transport { class LoopBackTransport : public webrtc::Transport {
public: public:
LoopBackTransport() LoopBackTransport()
: _count(0), : count_(0),
_packetLoss(0), packet_loss_(0),
rtp_payload_registry_(NULL), rtp_payload_registry_(NULL),
rtp_receiver_(NULL), rtp_receiver_(NULL),
_rtpRtcpModule(NULL) { rtp_rtcp_module_(NULL) {}
} void SetSendModule(RtpRtcp* rtp_rtcp_module,
void SetSendModule(RtpRtcp* rtpRtcpModule,
RTPPayloadRegistry* payload_registry, RTPPayloadRegistry* payload_registry,
RtpReceiver* receiver, RtpReceiver* receiver,
ReceiveStatistics* receive_statistics) { ReceiveStatistics* receive_statistics);
_rtpRtcpModule = rtpRtcpModule; void DropEveryNthPacket(int n);
rtp_payload_registry_ = payload_registry; virtual int SendPacket(int channel, const void* data, size_t len) OVERRIDE;
rtp_receiver_ = receiver;
receive_statistics_ = receive_statistics;
}
void DropEveryNthPacket(int n) {
_packetLoss = n;
}
virtual int SendPacket(int channel, const void *data, size_t len) OVERRIDE {
_count++;
if (_packetLoss > 0) {
if ((_count % _packetLoss) == 0) {
return len;
}
}
RTPHeader header;
scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
if (!parser->Parse(static_cast<const uint8_t*>(data), len, &header)) {
return -1;
}
PayloadUnion payload_specific;
if (!rtp_payload_registry_->GetPayloadSpecifics(
header.payloadType, &payload_specific)) {
return -1;
}
receive_statistics_->IncomingPacket(header, len, false);
if (!rtp_receiver_->IncomingRtpPacket(header,
static_cast<const uint8_t*>(data),
len, payload_specific, true)) {
return -1;
}
return len;
}
virtual int SendRTCPPacket(int channel, virtual int SendRTCPPacket(int channel,
const void *data, const void* data,
size_t len) OVERRIDE { size_t len) OVERRIDE;
if (_rtpRtcpModule->IncomingRtcpPacket((const uint8_t*)data, len) < 0) {
return -1;
}
return static_cast<int>(len);
}
private: private:
int _count; int count_;
int _packetLoss; int packet_loss_;
ReceiveStatistics* receive_statistics_; ReceiveStatistics* receive_statistics_;
RTPPayloadRegistry* rtp_payload_registry_; RTPPayloadRegistry* rtp_payload_registry_;
RtpReceiver* rtp_receiver_; RtpReceiver* rtp_receiver_;
RtpRtcp* _rtpRtcpModule; RtpRtcp* rtp_rtcp_module_;
}; };
class TestRtpReceiver : public NullRtpData { class TestRtpReceiver : public NullRtpData {
public: public:
virtual int32_t OnReceivedPayloadData( virtual int32_t OnReceivedPayloadData(
const uint8_t* payloadData, const uint8_t* payload_data,
const size_t payloadSize, const size_t payload_size,
const webrtc::WebRtcRTPHeader* rtpHeader) OVERRIDE { const webrtc::WebRtcRTPHeader* rtp_header) OVERRIDE;
EXPECT_LE(payloadSize, sizeof(_payloadData));
memcpy(_payloadData, payloadData, payloadSize);
memcpy(&_rtpHeader, rtpHeader, sizeof(_rtpHeader));
_payloadSize = payloadSize;
return 0;
}
const uint8_t* payload_data() const { const uint8_t* payload_data() const { return payload_data_; }
return _payloadData; size_t payload_size() const { return payload_size_; }
} webrtc::WebRtcRTPHeader rtp_header() const { return rtp_header_; }
size_t payload_size() const {
return _payloadSize;
}
webrtc::WebRtcRTPHeader rtp_header() const {
return _rtpHeader;
}
private: private:
uint8_t _payloadData[1500]; uint8_t payload_data_[1500];
size_t _payloadSize; size_t payload_size_;
webrtc::WebRtcRTPHeader _rtpHeader; webrtc::WebRtcRTPHeader rtp_header_;
}; };
} // namespace webrtc } // namespace webrtc