2013-08-19 16:09:34 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-12-09 12:13:30 +01:00
|
|
|
#ifndef WEBRTC_TEST_RTP_RTCP_OBSERVER_H_
|
|
|
|
|
#define WEBRTC_TEST_RTP_RTCP_OBSERVER_H_
|
2013-08-19 16:09:34 +00:00
|
|
|
|
|
|
|
|
#include <map>
|
2016-05-01 14:53:46 -07:00
|
|
|
#include <memory>
|
2013-08-19 16:09:34 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2015-05-01 13:00:41 +02:00
|
|
|
#include "webrtc/base/criticalsection.h"
|
2015-12-10 13:02:50 +01:00
|
|
|
#include "webrtc/base/event.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
|
2017-02-21 05:20:28 -08:00
|
|
|
#include "webrtc/system_wrappers/include/field_trial.h"
|
2015-10-29 15:13:24 +01:00
|
|
|
#include "webrtc/test/constants.h"
|
2014-06-27 08:47:52 +00:00
|
|
|
#include "webrtc/test/direct_transport.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
2013-08-19 16:09:34 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2013-10-28 16:32:01 +00:00
|
|
|
#include "webrtc/video_send_stream.h"
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2017-02-21 05:20:28 -08:00
|
|
|
namespace {
|
|
|
|
|
const int kShortTimeoutMs = 500;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-19 16:09:34 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
class PacketTransport;
|
|
|
|
|
|
2013-08-19 16:09:34 +00:00
|
|
|
class RtpRtcpObserver {
|
|
|
|
|
public:
|
2015-10-27 08:29:42 -07:00
|
|
|
enum Action {
|
|
|
|
|
SEND_PACKET,
|
|
|
|
|
DROP_PACKET,
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-21 11:42:02 +00:00
|
|
|
virtual ~RtpRtcpObserver() {}
|
2015-10-27 08:29:42 -07:00
|
|
|
|
2017-02-21 05:20:28 -08:00
|
|
|
virtual bool Wait() {
|
|
|
|
|
if (field_trial::FindFullName("WebRTC-QuickPerfTest") == "Enabled") {
|
|
|
|
|
observation_complete_.Wait(kShortTimeoutMs);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return observation_complete_.Wait(timeout_ms_);
|
|
|
|
|
}
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnSendRtp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnSendRtcp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-11-15 12:32:15 +00:00
|
|
|
}
|
2013-09-19 14:22:12 +00:00
|
|
|
|
2013-08-19 16:09:34 +00:00
|
|
|
protected:
|
2015-12-10 13:02:50 +01:00
|
|
|
explicit RtpRtcpObserver(int event_timeout_ms)
|
|
|
|
|
: observation_complete_(false, false),
|
2013-11-18 11:58:24 +00:00
|
|
|
parser_(RtpHeaderParser::Create()),
|
2015-10-29 15:13:24 +01:00
|
|
|
timeout_ms_(event_timeout_ms) {
|
|
|
|
|
parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset,
|
|
|
|
|
kTOffsetExtensionId);
|
|
|
|
|
parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime,
|
|
|
|
|
kAbsSendTimeExtensionId);
|
|
|
|
|
parser_->RegisterRtpHeaderExtension(kRtpExtensionTransportSequenceNumber,
|
|
|
|
|
kTransportSequenceNumberExtensionId);
|
|
|
|
|
}
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-12-10 13:02:50 +01:00
|
|
|
rtc::Event observation_complete_;
|
2016-05-01 14:53:46 -07:00
|
|
|
const std::unique_ptr<RtpHeaderParser> parser_;
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
private:
|
2015-12-10 13:02:50 +01:00
|
|
|
const int timeout_ms_;
|
2015-10-27 08:29:42 -07:00
|
|
|
};
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
class PacketTransport : public test::DirectTransport {
|
|
|
|
|
public:
|
|
|
|
|
enum TransportType { kReceiver, kSender };
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
PacketTransport(Call* send_call,
|
|
|
|
|
RtpRtcpObserver* observer,
|
|
|
|
|
TransportType transport_type,
|
|
|
|
|
const FakeNetworkPipe::Config& configuration)
|
|
|
|
|
: test::DirectTransport(configuration, send_call),
|
|
|
|
|
observer_(observer),
|
|
|
|
|
transport_type_(transport_type) {}
|
2013-08-19 16:09:34 +00:00
|
|
|
|
|
|
|
|
private:
|
2015-10-27 08:29:42 -07:00
|
|
|
bool SendRtp(const uint8_t* packet,
|
|
|
|
|
size_t length,
|
|
|
|
|
const PacketOptions& options) override {
|
|
|
|
|
EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length));
|
|
|
|
|
RtpRtcpObserver::Action action;
|
|
|
|
|
{
|
|
|
|
|
if (transport_type_ == kSender) {
|
|
|
|
|
action = observer_->OnSendRtp(packet, length);
|
|
|
|
|
} else {
|
|
|
|
|
action = observer_->OnReceiveRtp(packet, length);
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-27 08:29:42 -07:00
|
|
|
switch (action) {
|
|
|
|
|
case RtpRtcpObserver::DROP_PACKET:
|
|
|
|
|
// Drop packet silently.
|
|
|
|
|
return true;
|
|
|
|
|
case RtpRtcpObserver::SEND_PACKET:
|
|
|
|
|
return test::DirectTransport::SendRtp(packet, length, options);
|
|
|
|
|
}
|
|
|
|
|
return true; // Will never happen, makes compiler happy.
|
|
|
|
|
}
|
2013-08-19 16:35:36 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
bool SendRtcp(const uint8_t* packet, size_t length) override {
|
|
|
|
|
EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length));
|
|
|
|
|
RtpRtcpObserver::Action action;
|
|
|
|
|
{
|
|
|
|
|
if (transport_type_ == kSender) {
|
|
|
|
|
action = observer_->OnSendRtcp(packet, length);
|
|
|
|
|
} else {
|
|
|
|
|
action = observer_->OnReceiveRtcp(packet, length);
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-27 08:29:42 -07:00
|
|
|
switch (action) {
|
|
|
|
|
case RtpRtcpObserver::DROP_PACKET:
|
|
|
|
|
// Drop packet silently.
|
|
|
|
|
return true;
|
|
|
|
|
case RtpRtcpObserver::SEND_PACKET:
|
|
|
|
|
return test::DirectTransport::SendRtcp(packet, length);
|
|
|
|
|
}
|
|
|
|
|
return true; // Will never happen, makes compiler happy.
|
|
|
|
|
}
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
RtpRtcpObserver* const observer_;
|
|
|
|
|
TransportType transport_type_;
|
2013-08-19 16:09:34 +00:00
|
|
|
};
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2015-12-09 12:13:30 +01:00
|
|
|
#endif // WEBRTC_TEST_RTP_RTCP_OBSERVER_H_
|