rtp_transport_test_util.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef PC_TEST_RTP_TRANSPORT_TEST_UTIL_H_
  11. #define PC_TEST_RTP_TRANSPORT_TEST_UTIL_H_
  12. #include "call/rtp_packet_sink_interface.h"
  13. #include "modules/rtp_rtcp/source/rtp_packet_received.h"
  14. #include "pc/rtp_transport_internal.h"
  15. #include "rtc_base/third_party/sigslot/sigslot.h"
  16. namespace webrtc {
  17. // Used to handle the signals when the RtpTransport receives an RTP/RTCP packet.
  18. // Used in Rtp/Srtp/DtlsTransport unit tests.
  19. class TransportObserver : public RtpPacketSinkInterface,
  20. public sigslot::has_slots<> {
  21. public:
  22. TransportObserver() {}
  23. explicit TransportObserver(RtpTransportInternal* rtp_transport) {
  24. rtp_transport->SignalRtcpPacketReceived.connect(
  25. this, &TransportObserver::OnRtcpPacketReceived);
  26. rtp_transport->SignalReadyToSend.connect(this,
  27. &TransportObserver::OnReadyToSend);
  28. }
  29. // RtpPacketInterface override.
  30. void OnRtpPacket(const RtpPacketReceived& packet) override {
  31. rtp_count_++;
  32. last_recv_rtp_packet_ = packet.Buffer();
  33. }
  34. void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet,
  35. int64_t packet_time_us) {
  36. rtcp_count_++;
  37. last_recv_rtcp_packet_ = *packet;
  38. }
  39. int rtp_count() const { return rtp_count_; }
  40. int rtcp_count() const { return rtcp_count_; }
  41. rtc::CopyOnWriteBuffer last_recv_rtp_packet() {
  42. return last_recv_rtp_packet_;
  43. }
  44. rtc::CopyOnWriteBuffer last_recv_rtcp_packet() {
  45. return last_recv_rtcp_packet_;
  46. }
  47. void OnReadyToSend(bool ready) {
  48. ready_to_send_signal_count_++;
  49. ready_to_send_ = ready;
  50. }
  51. bool ready_to_send() { return ready_to_send_; }
  52. int ready_to_send_signal_count() { return ready_to_send_signal_count_; }
  53. private:
  54. bool ready_to_send_ = false;
  55. int rtp_count_ = 0;
  56. int rtcp_count_ = 0;
  57. int ready_to_send_signal_count_ = 0;
  58. rtc::CopyOnWriteBuffer last_recv_rtp_packet_;
  59. rtc::CopyOnWriteBuffer last_recv_rtcp_packet_;
  60. };
  61. } // namespace webrtc
  62. #endif // PC_TEST_RTP_TRANSPORT_TEST_UTIL_H_