pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 10 | #ifndef WEBRTC_TEST_RTP_RTCP_OBSERVER_H_ |
| 11 | #define WEBRTC_TEST_RTP_RTCP_OBSERVER_H_ |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 12 | |
| 13 | #include <map> |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 14 | #include <memory> |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 17 | #include "webrtc/base/criticalsection.h" |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 18 | #include "webrtc/base/event.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 19 | #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
ilnik | 5328b9e | 2017-02-21 05:20:28 -0800 | [diff] [blame] | 20 | #include "webrtc/system_wrappers/include/field_trial.h" |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 21 | #include "webrtc/test/constants.h" |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 22 | #include "webrtc/test/direct_transport.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 23 | #include "webrtc/test/gtest.h" |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 24 | #include "webrtc/typedefs.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 25 | #include "webrtc/video_send_stream.h" |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 26 | |
ilnik | 5328b9e | 2017-02-21 05:20:28 -0800 | [diff] [blame] | 27 | namespace { |
| 28 | const int kShortTimeoutMs = 500; |
| 29 | } |
| 30 | |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 31 | namespace webrtc { |
| 32 | namespace test { |
| 33 | |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 34 | class PacketTransport; |
| 35 | |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 36 | class RtpRtcpObserver { |
| 37 | public: |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 38 | enum Action { |
| 39 | SEND_PACKET, |
| 40 | DROP_PACKET, |
| 41 | }; |
| 42 | |
pbos@webrtc.org | b3cc78d | 2013-11-21 11:42:02 +0000 | [diff] [blame] | 43 | virtual ~RtpRtcpObserver() {} |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 44 | |
ilnik | 5328b9e | 2017-02-21 05:20:28 -0800 | [diff] [blame] | 45 | virtual bool Wait() { |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame] | 46 | if (field_trial::IsEnabled("WebRTC-QuickPerfTest")) { |
ilnik | 5328b9e | 2017-02-21 05:20:28 -0800 | [diff] [blame] | 47 | observation_complete_.Wait(kShortTimeoutMs); |
| 48 | return true; |
| 49 | } |
| 50 | return observation_complete_.Wait(timeout_ms_); |
| 51 | } |
pbos@webrtc.org | 6917e19 | 2013-09-19 14:22:12 +0000 | [diff] [blame] | 52 | |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 53 | virtual Action OnSendRtp(const uint8_t* packet, size_t length) { |
| 54 | return SEND_PACKET; |
| 55 | } |
stefan@webrtc.org | b082ade | 2013-11-18 11:45:11 +0000 | [diff] [blame] | 56 | |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 57 | virtual Action OnSendRtcp(const uint8_t* packet, size_t length) { |
| 58 | return SEND_PACKET; |
| 59 | } |
| 60 | |
| 61 | virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) { |
| 62 | return SEND_PACKET; |
| 63 | } |
| 64 | |
| 65 | virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) { |
| 66 | return SEND_PACKET; |
| 67 | } |
| 68 | |
| 69 | protected: |
philipel | e828c96 | 2017-03-21 03:24:27 -0700 | [diff] [blame^] | 70 | RtpRtcpObserver() : RtpRtcpObserver(0) {} |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 71 | explicit RtpRtcpObserver(int event_timeout_ms) |
| 72 | : observation_complete_(false, false), |
stefan@webrtc.org | 28bf50f | 2013-11-18 11:58:24 +0000 | [diff] [blame] | 73 | parser_(RtpHeaderParser::Create()), |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 74 | timeout_ms_(event_timeout_ms) { |
| 75 | parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, |
| 76 | kTOffsetExtensionId); |
| 77 | parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
| 78 | kAbsSendTimeExtensionId); |
| 79 | parser_->RegisterRtpHeaderExtension(kRtpExtensionTransportSequenceNumber, |
| 80 | kTransportSequenceNumberExtensionId); |
| 81 | } |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 82 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 83 | rtc::Event observation_complete_; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 84 | const std::unique_ptr<RtpHeaderParser> parser_; |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 85 | |
| 86 | private: |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 87 | const int timeout_ms_; |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 88 | }; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 89 | |
| 90 | class PacketTransport : public test::DirectTransport { |
| 91 | public: |
| 92 | enum TransportType { kReceiver, kSender }; |
| 93 | |
| 94 | PacketTransport(Call* send_call, |
| 95 | RtpRtcpObserver* observer, |
| 96 | TransportType transport_type, |
| 97 | const FakeNetworkPipe::Config& configuration) |
| 98 | : test::DirectTransport(configuration, send_call), |
| 99 | observer_(observer), |
| 100 | transport_type_(transport_type) {} |
| 101 | |
| 102 | private: |
| 103 | bool SendRtp(const uint8_t* packet, |
| 104 | size_t length, |
| 105 | const PacketOptions& options) override { |
| 106 | EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length)); |
| 107 | RtpRtcpObserver::Action action; |
| 108 | { |
| 109 | if (transport_type_ == kSender) { |
| 110 | action = observer_->OnSendRtp(packet, length); |
| 111 | } else { |
| 112 | action = observer_->OnReceiveRtp(packet, length); |
| 113 | } |
| 114 | } |
| 115 | switch (action) { |
| 116 | case RtpRtcpObserver::DROP_PACKET: |
| 117 | // Drop packet silently. |
| 118 | return true; |
| 119 | case RtpRtcpObserver::SEND_PACKET: |
| 120 | return test::DirectTransport::SendRtp(packet, length, options); |
| 121 | } |
| 122 | return true; // Will never happen, makes compiler happy. |
| 123 | } |
| 124 | |
| 125 | bool SendRtcp(const uint8_t* packet, size_t length) override { |
| 126 | EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length)); |
| 127 | RtpRtcpObserver::Action action; |
| 128 | { |
| 129 | if (transport_type_ == kSender) { |
| 130 | action = observer_->OnSendRtcp(packet, length); |
| 131 | } else { |
| 132 | action = observer_->OnReceiveRtcp(packet, length); |
| 133 | } |
| 134 | } |
| 135 | switch (action) { |
| 136 | case RtpRtcpObserver::DROP_PACKET: |
| 137 | // Drop packet silently. |
| 138 | return true; |
| 139 | case RtpRtcpObserver::SEND_PACKET: |
| 140 | return test::DirectTransport::SendRtcp(packet, length); |
| 141 | } |
| 142 | return true; // Will never happen, makes compiler happy. |
| 143 | } |
| 144 | |
| 145 | RtpRtcpObserver* const observer_; |
| 146 | TransportType transport_type_; |
| 147 | }; |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 148 | } // namespace test |
| 149 | } // namespace webrtc |
| 150 | |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 151 | #endif // WEBRTC_TEST_RTP_RTCP_OBSERVER_H_ |