blob: 9489fa2bfeb3854437ff9e03aef369ce098fbad5 [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 Huang27f3bf52018-03-26 21:37:23 -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"
17#include "rtc_base/sigslot.h"
zstein398c3fd2017-07-19 13:38:02 -070018
19namespace webrtc {
20
Zhi Huang27f3bf52018-03-26 21:37:23 -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 Huang27f3bf52018-03-26 21:37:23 -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 Huang27f3bf52018-03-26 21:37:23 -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 RTC_LOG(LS_INFO) << "Received an RTCP packet.";
44 rtcp_count_++;
45 last_recv_rtcp_packet_ = *packet;
46 }
47
Zhi Huang97d5e5b2018-03-27 00:09:01 +000048 int rtp_count() const { return rtp_count_; }
Zhi Huang27f3bf52018-03-26 21:37:23 -070049 int rtcp_count() const { return rtcp_count_; }
50
51 rtc::CopyOnWriteBuffer last_recv_rtp_packet() {
52 return last_recv_rtp_packet_;
53 }
54
55 rtc::CopyOnWriteBuffer last_recv_rtcp_packet() {
56 return last_recv_rtcp_packet_;
57 }
58
59 void OnReadyToSend(bool ready) {
60 ready_to_send_signal_count_++;
61 ready_to_send_ = ready;
62 }
63
64 bool ready_to_send() { return ready_to_send_; }
65
66 int ready_to_send_signal_count() { return ready_to_send_signal_count_; }
zstein398c3fd2017-07-19 13:38:02 -070067
68 private:
Zhi Huang27f3bf52018-03-26 21:37:23 -070069 bool ready_to_send_ = false;
Zhi Huang97d5e5b2018-03-27 00:09:01 +000070 int rtp_count_ = 0;
Zhi Huang27f3bf52018-03-26 21:37:23 -070071 int rtcp_count_ = 0;
72 int ready_to_send_signal_count_ = 0;
73 rtc::CopyOnWriteBuffer last_recv_rtp_packet_;
74 rtc::CopyOnWriteBuffer last_recv_rtcp_packet_;
zstein398c3fd2017-07-19 13:38:02 -070075};
76
77} // namespace webrtc
78
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#endif // PC_RTPTRANSPORTTESTUTIL_H_