OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_ | 10 #ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_ |
11 #define WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_ | 11 #define WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_ |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/base/criticalsection.h" |
19 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 19 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
20 #include "webrtc/test/direct_transport.h" | 20 #include "webrtc/test/direct_transport.h" |
21 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" |
22 #include "webrtc/video_send_stream.h" | 22 #include "webrtc/video_send_stream.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 namespace test { | 25 namespace test { |
26 | 26 |
27 class PacketTransport; | |
28 | |
27 class RtpRtcpObserver { | 29 class RtpRtcpObserver { |
28 public: | 30 public: |
31 enum Action { | |
32 SEND_PACKET, | |
33 DROP_PACKET, | |
34 }; | |
35 | |
29 virtual ~RtpRtcpObserver() {} | 36 virtual ~RtpRtcpObserver() {} |
30 Transport* SendTransport() { | |
31 return &send_transport_; | |
32 } | |
33 | 37 |
34 Transport* ReceiveTransport() { | 38 virtual void SetTransports(PacketTransport* send_transport, |
pbos-webrtc
2015/10/27 14:06:30
if so remove here
stefan-webrtc
2015/10/27 14:33:16
Done.
| |
35 return &receive_transport_; | 39 PacketTransport* receive_transport) { |
36 } | 40 send_transport_ = send_transport; |
37 | 41 receive_transport_ = receive_transport; |
38 virtual void SetReceivers(PacketReceiver* send_transport_receiver, | |
39 PacketReceiver* receive_transport_receiver) { | |
40 send_transport_.SetReceiver(send_transport_receiver); | |
41 receive_transport_.SetReceiver(receive_transport_receiver); | |
42 } | |
43 | |
44 void StopSending() { | |
45 send_transport_.StopSending(); | |
46 receive_transport_.StopSending(); | |
47 } | 42 } |
48 | 43 |
49 virtual EventTypeWrapper Wait() { | 44 virtual EventTypeWrapper Wait() { |
50 EventTypeWrapper result = observation_complete_->Wait(timeout_ms_); | 45 EventTypeWrapper result = observation_complete_->Wait(timeout_ms_); |
51 return result; | 46 return result; |
52 } | 47 } |
53 | 48 |
49 virtual Action OnSendRtp(const uint8_t* packet, size_t length) { | |
50 return SEND_PACKET; | |
51 } | |
52 | |
53 virtual Action OnSendRtcp(const uint8_t* packet, size_t length) { | |
54 return SEND_PACKET; | |
55 } | |
56 | |
57 virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) { | |
58 return SEND_PACKET; | |
59 } | |
60 | |
61 virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) { | |
62 return SEND_PACKET; | |
63 } | |
64 | |
54 protected: | 65 protected: |
55 RtpRtcpObserver(unsigned int event_timeout_ms, | |
56 const FakeNetworkPipe::Config& configuration) | |
57 : observation_complete_(EventWrapper::Create()), | |
58 parser_(RtpHeaderParser::Create()), | |
59 send_transport_(&crit_, | |
60 this, | |
61 &RtpRtcpObserver::OnSendRtp, | |
62 &RtpRtcpObserver::OnSendRtcp, | |
63 configuration), | |
64 receive_transport_(&crit_, | |
65 this, | |
66 &RtpRtcpObserver::OnReceiveRtp, | |
67 &RtpRtcpObserver::OnReceiveRtcp, | |
68 configuration), | |
69 timeout_ms_(event_timeout_ms) {} | |
70 | |
71 explicit RtpRtcpObserver(unsigned int event_timeout_ms) | 66 explicit RtpRtcpObserver(unsigned int event_timeout_ms) |
72 : observation_complete_(EventWrapper::Create()), | 67 : observation_complete_(EventWrapper::Create()), |
73 parser_(RtpHeaderParser::Create()), | 68 parser_(RtpHeaderParser::Create()), |
74 send_transport_(&crit_, | 69 send_transport_(nullptr), |
75 this, | 70 receive_transport_(nullptr), |
76 &RtpRtcpObserver::OnSendRtp, | |
77 &RtpRtcpObserver::OnSendRtcp, | |
78 FakeNetworkPipe::Config()), | |
79 receive_transport_(&crit_, | |
80 this, | |
81 &RtpRtcpObserver::OnReceiveRtp, | |
82 &RtpRtcpObserver::OnReceiveRtcp, | |
83 FakeNetworkPipe::Config()), | |
84 timeout_ms_(event_timeout_ms) {} | 71 timeout_ms_(event_timeout_ms) {} |
85 | 72 |
86 enum Action { | |
87 SEND_PACKET, | |
88 DROP_PACKET, | |
89 }; | |
90 | |
91 virtual Action OnSendRtp(const uint8_t* packet, size_t length) | |
92 EXCLUSIVE_LOCKS_REQUIRED(crit_) { | |
93 return SEND_PACKET; | |
94 } | |
95 | |
96 virtual Action OnSendRtcp(const uint8_t* packet, size_t length) | |
97 EXCLUSIVE_LOCKS_REQUIRED(crit_) { | |
98 return SEND_PACKET; | |
99 } | |
100 | |
101 virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) | |
102 EXCLUSIVE_LOCKS_REQUIRED(crit_) { | |
103 return SEND_PACKET; | |
104 } | |
105 | |
106 virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) | |
107 EXCLUSIVE_LOCKS_REQUIRED(crit_) { | |
108 return SEND_PACKET; | |
109 } | |
110 | |
111 private: | |
112 class PacketTransport : public test::DirectTransport { | |
113 public: | |
114 typedef Action (RtpRtcpObserver::*PacketTransportAction)(const uint8_t*, | |
115 size_t); | |
116 | |
117 PacketTransport(rtc::CriticalSection* lock, | |
118 RtpRtcpObserver* observer, | |
119 PacketTransportAction on_rtp, | |
120 PacketTransportAction on_rtcp, | |
121 const FakeNetworkPipe::Config& configuration) | |
122 : test::DirectTransport(configuration), | |
123 crit_(lock), | |
124 observer_(observer), | |
125 on_rtp_(on_rtp), | |
126 on_rtcp_(on_rtcp) {} | |
127 | |
128 private: | |
129 bool SendRtp(const uint8_t* packet, | |
130 size_t length, | |
131 const PacketOptions& options) override { | |
132 EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length)); | |
133 Action action; | |
134 { | |
135 rtc::CritScope lock(crit_); | |
136 action = (observer_->*on_rtp_)(packet, length); | |
137 } | |
138 switch (action) { | |
139 case DROP_PACKET: | |
140 // Drop packet silently. | |
141 return true; | |
142 case SEND_PACKET: | |
143 return test::DirectTransport::SendRtp(packet, length, options); | |
144 } | |
145 return true; // Will never happen, makes compiler happy. | |
146 } | |
147 | |
148 bool SendRtcp(const uint8_t* packet, size_t length) override { | |
149 EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length)); | |
150 Action action; | |
151 { | |
152 rtc::CritScope lock(crit_); | |
153 action = (observer_->*on_rtcp_)(packet, length); | |
154 } | |
155 switch (action) { | |
156 case DROP_PACKET: | |
157 // Drop packet silently. | |
158 return true; | |
159 case SEND_PACKET: | |
160 return test::DirectTransport::SendRtcp(packet, length); | |
161 } | |
162 return true; // Will never happen, makes compiler happy. | |
163 } | |
164 | |
165 // Pointer to shared lock instance protecting on_rtp_/on_rtcp_ calls. | |
166 rtc::CriticalSection* const crit_; | |
167 | |
168 RtpRtcpObserver* const observer_; | |
169 const PacketTransportAction on_rtp_, on_rtcp_; | |
170 }; | |
171 | |
172 protected: | |
173 rtc::CriticalSection crit_; | |
174 const rtc::scoped_ptr<EventWrapper> observation_complete_; | 73 const rtc::scoped_ptr<EventWrapper> observation_complete_; |
175 const rtc::scoped_ptr<RtpHeaderParser> parser_; | 74 const rtc::scoped_ptr<RtpHeaderParser> parser_; |
176 PacketTransport send_transport_, receive_transport_; | 75 PacketTransport* send_transport_; |
pbos-webrtc
2015/10/27 14:06:30
dead code? if so remove
stefan-webrtc
2015/10/27 14:33:16
Done.
| |
76 PacketTransport* receive_transport_; | |
177 | 77 |
178 private: | 78 private: |
179 unsigned int timeout_ms_; | 79 unsigned int timeout_ms_; |
180 }; | 80 }; |
81 | |
82 class PacketTransport : public test::DirectTransport { | |
83 public: | |
84 enum TransportType { kReceiver, kSender }; | |
85 | |
86 PacketTransport(Call* send_call, | |
87 RtpRtcpObserver* observer, | |
88 TransportType transport_type, | |
89 const FakeNetworkPipe::Config& configuration) | |
90 : test::DirectTransport(configuration, send_call), | |
91 observer_(observer), | |
92 transport_type_(transport_type) {} | |
93 | |
94 private: | |
95 bool SendRtp(const uint8_t* packet, | |
96 size_t length, | |
97 const PacketOptions& options) override { | |
98 EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length)); | |
99 RtpRtcpObserver::Action action; | |
100 { | |
101 if (transport_type_ == kSender) { | |
102 action = observer_->OnSendRtp(packet, length); | |
103 } else { | |
104 action = observer_->OnReceiveRtp(packet, length); | |
105 } | |
106 } | |
107 switch (action) { | |
108 case RtpRtcpObserver::DROP_PACKET: | |
109 // Drop packet silently. | |
110 return true; | |
111 case RtpRtcpObserver::SEND_PACKET: | |
112 return test::DirectTransport::SendRtp(packet, length, options); | |
113 } | |
114 return true; // Will never happen, makes compiler happy. | |
115 } | |
116 | |
117 bool SendRtcp(const uint8_t* packet, size_t length) override { | |
118 EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length)); | |
119 RtpRtcpObserver::Action action; | |
120 { | |
121 if (transport_type_ == kSender) { | |
122 action = observer_->OnSendRtcp(packet, length); | |
123 } else { | |
124 action = observer_->OnReceiveRtcp(packet, length); | |
125 } | |
126 } | |
127 switch (action) { | |
128 case RtpRtcpObserver::DROP_PACKET: | |
129 // Drop packet silently. | |
130 return true; | |
131 case RtpRtcpObserver::SEND_PACKET: | |
132 return test::DirectTransport::SendRtcp(packet, length); | |
133 } | |
134 return true; // Will never happen, makes compiler happy. | |
135 } | |
136 | |
137 RtpRtcpObserver* const observer_; | |
138 TransportType transport_type_; | |
139 }; | |
181 } // namespace test | 140 } // namespace test |
182 } // namespace webrtc | 141 } // namespace webrtc |
183 | 142 |
184 #endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_ | 143 #endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_ |
OLD | NEW |