blob: eb337730d107f8c8d81a8d28a2aa04f32e602254 [file] [log] [blame]
zstein398c3fd2017-07-19 13:38:02 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_RTPTRANSPORTTESTUTIL_H_
12#define PC_RTPTRANSPORTTESTUTIL_H_
zstein398c3fd2017-07-19 13:38:02 -070013
Zhi Huang365381f2018-04-13 16:44:34 -070014#include "call/rtp_packet_sink_interface.h"
15#include "modules/rtp_rtcp/source/rtp_packet_received.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "pc/rtptransportinternal.h"
Artem Titove41c4332018-07-25 15:04:28 +020017#include "rtc_base/third_party/sigslot/sigslot.h"
zstein398c3fd2017-07-19 13:38:02 -070018
19namespace webrtc {
20
Zhi Huang365381f2018-04-13 16:44:34 -070021// Used to handle the signals when the RtpTransport receives an RTP/RTCP packet.
22// Used in Rtp/Srtp/DtlsTransport unit tests.
23class TransportObserver : public RtpPacketSinkInterface,
24 public sigslot::has_slots<> {
zstein398c3fd2017-07-19 13:38:02 -070025 public:
Zhi Huang365381f2018-04-13 16:44:34 -070026 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);
zstein398c3fd2017-07-19 13:38:02 -070033 }
Zhi Huang365381f2018-04-13 16:44:34 -070034
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 Huang95e7dbb2018-03-29 00:08:03 +000047 int rtp_count() const { return rtp_count_; }
Zhi Huang365381f2018-04-13 16:44:34 -070048 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_; }
zstein398c3fd2017-07-19 13:38:02 -070066
67 private:
Zhi Huang365381f2018-04-13 16:44:34 -070068 bool ready_to_send_ = false;
Zhi Huang95e7dbb2018-03-29 00:08:03 +000069 int rtp_count_ = 0;
Zhi Huang365381f2018-04-13 16:44:34 -070070 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_;
zstein398c3fd2017-07-19 13:38:02 -070074};
75
76} // namespace webrtc
77
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020078#endif // PC_RTPTRANSPORTTESTUTIL_H_