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() { |
| 46 | if (field_trial::FindFullName("WebRTC-QuickPerfTest") == "Enabled") { |
| 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: |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 70 | explicit RtpRtcpObserver(int event_timeout_ms) |
| 71 | : observation_complete_(false, false), |
stefan@webrtc.org | 28bf50f | 2013-11-18 11:58:24 +0000 | [diff] [blame] | 72 | parser_(RtpHeaderParser::Create()), |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 73 | timeout_ms_(event_timeout_ms) { |
| 74 | parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, |
| 75 | kTOffsetExtensionId); |
| 76 | parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
| 77 | kAbsSendTimeExtensionId); |
| 78 | parser_->RegisterRtpHeaderExtension(kRtpExtensionTransportSequenceNumber, |
| 79 | kTransportSequenceNumberExtensionId); |
| 80 | } |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 81 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 82 | rtc::Event observation_complete_; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 83 | const std::unique_ptr<RtpHeaderParser> parser_; |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 84 | |
| 85 | private: |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 86 | const int timeout_ms_; |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 87 | }; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 88 | |
| 89 | class PacketTransport : public test::DirectTransport { |
| 90 | public: |
| 91 | enum TransportType { kReceiver, kSender }; |
| 92 | |
| 93 | PacketTransport(Call* send_call, |
| 94 | RtpRtcpObserver* observer, |
| 95 | TransportType transport_type, |
| 96 | const FakeNetworkPipe::Config& configuration) |
| 97 | : test::DirectTransport(configuration, send_call), |
| 98 | observer_(observer), |
| 99 | transport_type_(transport_type) {} |
| 100 | |
| 101 | private: |
| 102 | bool SendRtp(const uint8_t* packet, |
| 103 | size_t length, |
| 104 | const PacketOptions& options) override { |
| 105 | EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length)); |
| 106 | RtpRtcpObserver::Action action; |
| 107 | { |
| 108 | if (transport_type_ == kSender) { |
| 109 | action = observer_->OnSendRtp(packet, length); |
| 110 | } else { |
| 111 | action = observer_->OnReceiveRtp(packet, length); |
| 112 | } |
| 113 | } |
| 114 | switch (action) { |
| 115 | case RtpRtcpObserver::DROP_PACKET: |
| 116 | // Drop packet silently. |
| 117 | return true; |
| 118 | case RtpRtcpObserver::SEND_PACKET: |
| 119 | return test::DirectTransport::SendRtp(packet, length, options); |
| 120 | } |
| 121 | return true; // Will never happen, makes compiler happy. |
| 122 | } |
| 123 | |
| 124 | bool SendRtcp(const uint8_t* packet, size_t length) override { |
| 125 | EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length)); |
| 126 | RtpRtcpObserver::Action action; |
| 127 | { |
| 128 | if (transport_type_ == kSender) { |
| 129 | action = observer_->OnSendRtcp(packet, length); |
| 130 | } else { |
| 131 | action = observer_->OnReceiveRtcp(packet, length); |
| 132 | } |
| 133 | } |
| 134 | switch (action) { |
| 135 | case RtpRtcpObserver::DROP_PACKET: |
| 136 | // Drop packet silently. |
| 137 | return true; |
| 138 | case RtpRtcpObserver::SEND_PACKET: |
| 139 | return test::DirectTransport::SendRtcp(packet, length); |
| 140 | } |
| 141 | return true; // Will never happen, makes compiler happy. |
| 142 | } |
| 143 | |
| 144 | RtpRtcpObserver* const observer_; |
| 145 | TransportType transport_type_; |
| 146 | }; |
pbos@webrtc.org | e7f056e | 2013-08-19 16:09:34 +0000 | [diff] [blame] | 147 | } // namespace test |
| 148 | } // namespace webrtc |
| 149 | |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 150 | #endif // WEBRTC_TEST_RTP_RTCP_OBSERVER_H_ |