zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_RTPTRANSPORTTESTUTIL_H_ |
| 12 | #define PC_RTPTRANSPORTTESTUTIL_H_ |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 13 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 14 | #include "call/rtp_packet_sink_interface.h" |
| 15 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "pc/rtptransportinternal.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame^] | 17 | #include "rtc_base/third_party/sigslot/sigslot.h" |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 21 | // Used to handle the signals when the RtpTransport receives an RTP/RTCP packet. |
| 22 | // Used in Rtp/Srtp/DtlsTransport unit tests. |
| 23 | class TransportObserver : public RtpPacketSinkInterface, |
| 24 | public sigslot::has_slots<> { |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 25 | public: |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 26 | TransportObserver() {} |
| 27 | |
| 28 | explicit TransportObserver(RtpTransportInternal* rtp_transport) { |
| 29 | rtp_transport->SignalRtcpPacketReceived.connect( |
| 30 | this, &TransportObserver::OnRtcpPacketReceived); |
| 31 | rtp_transport->SignalReadyToSend.connect(this, |
| 32 | &TransportObserver::OnReadyToSend); |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 33 | } |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 34 | |
| 35 | // RtpPacketInterface override. |
| 36 | void OnRtpPacket(const RtpPacketReceived& packet) override { |
| 37 | rtp_count_++; |
| 38 | last_recv_rtp_packet_ = packet.Buffer(); |
| 39 | } |
| 40 | |
| 41 | void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet, |
| 42 | const rtc::PacketTime& packet_time) { |
| 43 | rtcp_count_++; |
| 44 | last_recv_rtcp_packet_ = *packet; |
| 45 | } |
| 46 | |
Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 +0000 | [diff] [blame] | 47 | int rtp_count() const { return rtp_count_; } |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 48 | int rtcp_count() const { return rtcp_count_; } |
| 49 | |
| 50 | rtc::CopyOnWriteBuffer last_recv_rtp_packet() { |
| 51 | return last_recv_rtp_packet_; |
| 52 | } |
| 53 | |
| 54 | rtc::CopyOnWriteBuffer last_recv_rtcp_packet() { |
| 55 | return last_recv_rtcp_packet_; |
| 56 | } |
| 57 | |
| 58 | void OnReadyToSend(bool ready) { |
| 59 | ready_to_send_signal_count_++; |
| 60 | ready_to_send_ = ready; |
| 61 | } |
| 62 | |
| 63 | bool ready_to_send() { return ready_to_send_; } |
| 64 | |
| 65 | int ready_to_send_signal_count() { return ready_to_send_signal_count_; } |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 66 | |
| 67 | private: |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 68 | bool ready_to_send_ = false; |
Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 +0000 | [diff] [blame] | 69 | int rtp_count_ = 0; |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 70 | int rtcp_count_ = 0; |
| 71 | int ready_to_send_signal_count_ = 0; |
| 72 | rtc::CopyOnWriteBuffer last_recv_rtp_packet_; |
| 73 | rtc::CopyOnWriteBuffer last_recv_rtcp_packet_; |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace webrtc |
| 77 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 78 | #endif // PC_RTPTRANSPORTTESTUTIL_H_ |