2012-01-10 14:09:18 +00:00
|
|
|
/*
|
2012-02-29 16:09:51 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2012-01-10 14:09:18 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-03-15 23:21:52 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h"
|
|
|
|
|
|
2012-01-10 14:09:18 +00:00
|
|
|
#include <algorithm>
|
2016-04-27 01:19:58 -07:00
|
|
|
#include <memory>
|
2012-01-10 14:09:18 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2016-10-05 07:51:44 -07:00
|
|
|
#include "webrtc/base/checks.h"
|
2016-07-29 12:59:36 +02:00
|
|
|
#include "webrtc/base/rate_limiter.h"
|
2015-12-10 05:05:27 -08:00
|
|
|
#include "webrtc/test/null_transport.h"
|
|
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
namespace webrtc {
|
2015-12-10 12:39:08 -08:00
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 03:39:33 -07:00
|
|
|
bool LoopBackTransport::SendRtp(const uint8_t* data,
|
|
|
|
|
size_t len,
|
|
|
|
|
const PacketOptions& options) {
|
2015-01-20 05:42:52 +00:00
|
|
|
count_++;
|
|
|
|
|
if (packet_loss_ > 0) {
|
|
|
|
|
if ((count_ % packet_loss_) == 0) {
|
2015-09-28 09:59:31 -07:00
|
|
|
return true;
|
2015-01-20 05:42:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RTPHeader header;
|
2016-04-27 01:19:58 -07:00
|
|
|
std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
|
2016-10-05 07:51:44 -07:00
|
|
|
if (!parser->Parse(data, len, &header)) {
|
2015-09-28 09:59:31 -07:00
|
|
|
return false;
|
2015-01-20 05:42:52 +00:00
|
|
|
}
|
|
|
|
|
PayloadUnion payload_specific;
|
|
|
|
|
if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
|
|
|
|
|
&payload_specific)) {
|
2015-09-28 09:59:31 -07:00
|
|
|
return false;
|
2015-01-20 05:42:52 +00:00
|
|
|
}
|
2016-10-05 07:51:44 -07:00
|
|
|
const uint8_t* payload = data + header.headerLength;
|
|
|
|
|
RTC_CHECK_GE(len, header.headerLength);
|
|
|
|
|
const size_t payload_length = len - header.headerLength;
|
2015-01-20 05:42:52 +00:00
|
|
|
receive_statistics_->IncomingPacket(header, len, false);
|
2016-10-05 07:51:44 -07:00
|
|
|
if (!rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
|
2015-01-20 05:42:52 +00:00
|
|
|
payload_specific, true)) {
|
2015-09-28 09:59:31 -07:00
|
|
|
return false;
|
2015-01-20 05:42:52 +00:00
|
|
|
}
|
2015-09-28 09:59:31 -07:00
|
|
|
return true;
|
2015-01-20 05:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-28 09:59:31 -07:00
|
|
|
bool LoopBackTransport::SendRtcp(const uint8_t* data, size_t len) {
|
2015-01-20 05:42:52 +00:00
|
|
|
if (rtp_rtcp_module_->IncomingRtcpPacket((const uint8_t*)data, len) < 0) {
|
2015-09-28 09:59:31 -07:00
|
|
|
return false;
|
2015-01-20 05:42:52 +00:00
|
|
|
}
|
2015-09-28 09:59:31 -07:00
|
|
|
return true;
|
2015-01-20 05:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t TestRtpReceiver::OnReceivedPayloadData(
|
|
|
|
|
const uint8_t* payload_data,
|
2016-06-14 12:52:54 +02:00
|
|
|
size_t payload_size,
|
2015-01-20 05:42:52 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-10 14:09:18 +00:00
|
|
|
class RtpRtcpAPITest : public ::testing::Test {
|
|
|
|
|
protected:
|
2016-07-29 12:59:36 +02:00
|
|
|
RtpRtcpAPITest()
|
|
|
|
|
: fake_clock_(123456), retransmission_rate_limiter_(&fake_clock_, 1000) {
|
2015-01-20 05:42:52 +00:00
|
|
|
test_csrcs_.push_back(1234);
|
|
|
|
|
test_csrcs_.push_back(2345);
|
|
|
|
|
test_ssrc_ = 3456;
|
|
|
|
|
test_timestamp_ = 4567;
|
|
|
|
|
test_sequence_number_ = 2345;
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
|
|
|
|
~RtpRtcpAPITest() {}
|
|
|
|
|
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
const uint32_t initial_ssrc = 8888;
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
void SetUp() override {
|
2012-05-11 11:08:54 +00:00
|
|
|
RtpRtcp::Configuration configuration;
|
|
|
|
|
configuration.audio = true;
|
2015-01-20 05:42:52 +00:00
|
|
|
configuration.clock = &fake_clock_;
|
2015-09-29 04:45:43 -07:00
|
|
|
configuration.outgoing_transport = &null_transport_;
|
2016-07-29 12:59:36 +02:00
|
|
|
configuration.retransmission_rate_limiter = &retransmission_rate_limiter_;
|
2015-01-20 05:42:52 +00:00
|
|
|
module_.reset(RtpRtcp::CreateRtpRtcp(configuration));
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
module_->SetSSRC(initial_ssrc);
|
2016-11-25 06:40:25 -08:00
|
|
|
rtp_payload_registry_.reset(new RTPPayloadRegistry());
|
2013-08-15 23:38:54 +00:00
|
|
|
rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver(
|
2016-03-30 02:42:32 -07:00
|
|
|
&fake_clock_, NULL, NULL, rtp_payload_registry_.get()));
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-27 01:19:58 -07:00
|
|
|
std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
|
|
|
|
|
std::unique_ptr<RtpReceiver> rtp_receiver_;
|
|
|
|
|
std::unique_ptr<RtpRtcp> module_;
|
2015-01-20 05:42:52 +00:00
|
|
|
uint32_t test_ssrc_;
|
|
|
|
|
uint32_t test_timestamp_;
|
|
|
|
|
uint16_t test_sequence_number_;
|
|
|
|
|
std::vector<uint32_t> test_csrcs_;
|
|
|
|
|
SimulatedClock fake_clock_;
|
2015-09-29 04:45:43 -07:00
|
|
|
test::NullTransport null_transport_;
|
2016-07-29 12:59:36 +02:00
|
|
|
RateLimiter retransmission_rate_limiter_;
|
2012-01-10 14:09:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpRtcpAPITest, Basic) {
|
2015-01-20 05:42:52 +00:00
|
|
|
module_->SetSequenceNumber(test_sequence_number_);
|
|
|
|
|
EXPECT_EQ(test_sequence_number_, module_->SequenceNumber());
|
2012-01-10 14:09:18 +00:00
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
module_->SetStartTimestamp(test_timestamp_);
|
|
|
|
|
EXPECT_EQ(test_timestamp_, module_->StartTimestamp());
|
2012-01-10 14:09:18 +00:00
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
EXPECT_FALSE(module_->Sending());
|
|
|
|
|
EXPECT_EQ(0, module_->SetSendingStatus(true));
|
|
|
|
|
EXPECT_TRUE(module_->Sending());
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
TEST_F(RtpRtcpAPITest, PacketSize) {
|
|
|
|
|
module_->SetMaxRtpPacketSize(1234);
|
|
|
|
|
EXPECT_EQ(1234u, module_->MaxRtpPacketSize());
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpRtcpAPITest, SSRC) {
|
2015-01-20 05:42:52 +00:00
|
|
|
module_->SetSSRC(test_ssrc_);
|
|
|
|
|
EXPECT_EQ(test_ssrc_, module_->SSRC());
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpRtcpAPITest, RTCP) {
|
2015-10-02 02:36:56 -07:00
|
|
|
EXPECT_EQ(RtcpMode::kOff, module_->RTCP());
|
|
|
|
|
module_->SetRTCPStatus(RtcpMode::kCompound);
|
|
|
|
|
EXPECT_EQ(RtcpMode::kCompound, module_->RTCP());
|
2012-01-10 14:09:18 +00:00
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
EXPECT_EQ(0, module_->SetCNAME("john.doe@test.test"));
|
2012-01-10 14:09:18 +00:00
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
EXPECT_FALSE(module_->TMMBR());
|
|
|
|
|
module_->SetTMMBRStatus(true);
|
|
|
|
|
EXPECT_TRUE(module_->TMMBR());
|
|
|
|
|
module_->SetTMMBRStatus(false);
|
|
|
|
|
EXPECT_FALSE(module_->TMMBR());
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
2013-03-15 23:21:52 +00:00
|
|
|
|
2013-09-06 13:40:11 +00:00
|
|
|
TEST_F(RtpRtcpAPITest, RtxSender) {
|
2015-01-20 05:42:52 +00:00
|
|
|
module_->SetRtxSendStatus(kRtxRetransmitted);
|
|
|
|
|
EXPECT_EQ(kRtxRetransmitted, module_->RtxSendStatus());
|
2015-01-13 14:15:15 +00:00
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
module_->SetRtxSendStatus(kRtxOff);
|
|
|
|
|
EXPECT_EQ(kRtxOff, module_->RtxSendStatus());
|
2015-01-13 14:15:15 +00:00
|
|
|
|
2015-01-20 05:42:52 +00:00
|
|
|
module_->SetRtxSendStatus(kRtxRetransmitted);
|
|
|
|
|
EXPECT_EQ(kRtxRetransmitted, module_->RtxSendStatus());
|
2013-03-15 23:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-06 13:40:11 +00:00
|
|
|
TEST_F(RtpRtcpAPITest, RtxReceiver) {
|
|
|
|
|
const uint32_t kRtxSsrc = 1;
|
2013-04-12 14:55:46 +00:00
|
|
|
const int kRtxPayloadType = 119;
|
2015-04-21 20:24:50 +08:00
|
|
|
const int kPayloadType = 100;
|
2014-06-05 08:25:29 +00:00
|
|
|
EXPECT_FALSE(rtp_payload_registry_->RtxEnabled());
|
|
|
|
|
rtp_payload_registry_->SetRtxSsrc(kRtxSsrc);
|
2015-04-21 20:24:50 +08:00
|
|
|
rtp_payload_registry_->SetRtxPayloadType(kRtxPayloadType, kPayloadType);
|
2013-09-06 13:40:11 +00:00
|
|
|
EXPECT_TRUE(rtp_payload_registry_->RtxEnabled());
|
|
|
|
|
RTPHeader rtx_header;
|
|
|
|
|
rtx_header.ssrc = kRtxSsrc;
|
|
|
|
|
rtx_header.payloadType = kRtxPayloadType;
|
|
|
|
|
EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header));
|
|
|
|
|
rtx_header.ssrc = 0;
|
|
|
|
|
EXPECT_FALSE(rtp_payload_registry_->IsRtx(rtx_header));
|
|
|
|
|
rtx_header.ssrc = kRtxSsrc;
|
2014-06-05 08:25:29 +00:00
|
|
|
rtx_header.payloadType = 0;
|
|
|
|
|
EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header));
|
2013-03-15 23:21:52 +00:00
|
|
|
}
|
2015-12-10 12:39:08 -08:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|