You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2013 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 TEST_RTP_RTCP_OBSERVER_H_
  11. #define TEST_RTP_RTCP_OBSERVER_H_
  12. #include <map>
  13. #include <memory>
  14. #include <utility>
  15. #include <vector>
  16. #include "api/test/simulated_network.h"
  17. #include "call/simulated_packet_receiver.h"
  18. #include "call/video_send_stream.h"
  19. #include "rtc_base/critical_section.h"
  20. #include "rtc_base/event.h"
  21. #include "system_wrappers/include/field_trial.h"
  22. #include "test/direct_transport.h"
  23. #include "test/gtest.h"
  24. #include "test/rtp_header_parser.h"
  25. namespace {
  26. const int kShortTimeoutMs = 500;
  27. }
  28. namespace webrtc {
  29. namespace test {
  30. class PacketTransport;
  31. class RtpRtcpObserver {
  32. public:
  33. enum Action {
  34. SEND_PACKET,
  35. DROP_PACKET,
  36. };
  37. virtual ~RtpRtcpObserver() {}
  38. virtual bool Wait() {
  39. if (field_trial::IsEnabled("WebRTC-QuickPerfTest")) {
  40. observation_complete_.Wait(kShortTimeoutMs);
  41. return true;
  42. }
  43. return observation_complete_.Wait(timeout_ms_);
  44. }
  45. virtual Action OnSendRtp(const uint8_t* packet, size_t length) {
  46. return SEND_PACKET;
  47. }
  48. virtual Action OnSendRtcp(const uint8_t* packet, size_t length) {
  49. return SEND_PACKET;
  50. }
  51. virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) {
  52. return SEND_PACKET;
  53. }
  54. virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) {
  55. return SEND_PACKET;
  56. }
  57. protected:
  58. RtpRtcpObserver() : RtpRtcpObserver(0) {}
  59. explicit RtpRtcpObserver(int event_timeout_ms)
  60. : parser_(RtpHeaderParser::CreateForTest()),
  61. timeout_ms_(event_timeout_ms) {}
  62. rtc::Event observation_complete_;
  63. const std::unique_ptr<RtpHeaderParser> parser_;
  64. private:
  65. const int timeout_ms_;
  66. };
  67. class PacketTransport : public test::DirectTransport {
  68. public:
  69. enum TransportType { kReceiver, kSender };
  70. PacketTransport(TaskQueueBase* task_queue,
  71. Call* send_call,
  72. RtpRtcpObserver* observer,
  73. TransportType transport_type,
  74. const std::map<uint8_t, MediaType>& payload_type_map,
  75. std::unique_ptr<SimulatedPacketReceiverInterface> nw_pipe)
  76. : test::DirectTransport(task_queue,
  77. std::move(nw_pipe),
  78. send_call,
  79. payload_type_map),
  80. observer_(observer),
  81. transport_type_(transport_type) {}
  82. private:
  83. bool SendRtp(const uint8_t* packet,
  84. size_t length,
  85. const PacketOptions& options) override {
  86. EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length));
  87. RtpRtcpObserver::Action action;
  88. {
  89. if (transport_type_ == kSender) {
  90. action = observer_->OnSendRtp(packet, length);
  91. } else {
  92. action = observer_->OnReceiveRtp(packet, length);
  93. }
  94. }
  95. switch (action) {
  96. case RtpRtcpObserver::DROP_PACKET:
  97. // Drop packet silently.
  98. return true;
  99. case RtpRtcpObserver::SEND_PACKET:
  100. return test::DirectTransport::SendRtp(packet, length, options);
  101. }
  102. return true; // Will never happen, makes compiler happy.
  103. }
  104. bool SendRtcp(const uint8_t* packet, size_t length) override {
  105. EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length));
  106. RtpRtcpObserver::Action action;
  107. {
  108. if (transport_type_ == kSender) {
  109. action = observer_->OnSendRtcp(packet, length);
  110. } else {
  111. action = observer_->OnReceiveRtcp(packet, length);
  112. }
  113. }
  114. switch (action) {
  115. case RtpRtcpObserver::DROP_PACKET:
  116. // Drop packet silently.
  117. return true;
  118. case RtpRtcpObserver::SEND_PACKET:
  119. return test::DirectTransport::SendRtcp(packet, length);
  120. }
  121. return true; // Will never happen, makes compiler happy.
  122. }
  123. RtpRtcpObserver* const observer_;
  124. TransportType transport_type_;
  125. };
  126. } // namespace test
  127. } // namespace webrtc
  128. #endif // TEST_RTP_RTCP_OBSERVER_H_