• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef PC_TEST_RTP_TRANSPORT_TEST_UTIL_H_
12 #define PC_TEST_RTP_TRANSPORT_TEST_UTIL_H_
13 
14 #include "call/rtp_packet_sink_interface.h"
15 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
16 #include "pc/rtp_transport_internal.h"
17 #include "rtc_base/third_party/sigslot/sigslot.h"
18 
19 namespace webrtc {
20 
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<> {
25  public:
TransportObserver()26   TransportObserver() {}
27 
TransportObserver(RtpTransportInternal * rtp_transport)28   explicit TransportObserver(RtpTransportInternal* rtp_transport) {
29     rtp_transport->SignalRtcpPacketReceived.connect(
30         this, &TransportObserver::OnRtcpPacketReceived);
31     rtp_transport->SignalReadyToSend.connect(this,
32                                              &TransportObserver::OnReadyToSend);
33   }
34 
35   // RtpPacketInterface override.
OnRtpPacket(const RtpPacketReceived & packet)36   void OnRtpPacket(const RtpPacketReceived& packet) override {
37     rtp_count_++;
38     last_recv_rtp_packet_ = packet.Buffer();
39   }
40 
OnRtcpPacketReceived(rtc::CopyOnWriteBuffer * packet,int64_t packet_time_us)41   void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet,
42                             int64_t packet_time_us) {
43     rtcp_count_++;
44     last_recv_rtcp_packet_ = *packet;
45   }
46 
rtp_count()47   int rtp_count() const { return rtp_count_; }
rtcp_count()48   int rtcp_count() const { return rtcp_count_; }
49 
last_recv_rtp_packet()50   rtc::CopyOnWriteBuffer last_recv_rtp_packet() {
51     return last_recv_rtp_packet_;
52   }
53 
last_recv_rtcp_packet()54   rtc::CopyOnWriteBuffer last_recv_rtcp_packet() {
55     return last_recv_rtcp_packet_;
56   }
57 
OnReadyToSend(bool ready)58   void OnReadyToSend(bool ready) {
59     ready_to_send_signal_count_++;
60     ready_to_send_ = ready;
61   }
62 
ready_to_send()63   bool ready_to_send() { return ready_to_send_; }
64 
ready_to_send_signal_count()65   int ready_to_send_signal_count() { return ready_to_send_signal_count_; }
66 
67  private:
68   bool ready_to_send_ = false;
69   int rtp_count_ = 0;
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_;
74 };
75 
76 }  // namespace webrtc
77 
78 #endif  // PC_TEST_RTP_TRANSPORT_TEST_UTIL_H_
79