1 /* 2 * Copyright (c) 2012 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 WEBRTC_MODULES_RTP_RTCP_TEST_TESTAPI_TEST_API_H_ 11 #define WEBRTC_MODULES_RTP_RTCP_TEST_TESTAPI_TEST_API_H_ 12 13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "webrtc/base/scoped_ptr.h" 15 #include "webrtc/common_types.h" 16 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" 18 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" 19 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 22 #include "webrtc/transport.h" 23 24 namespace webrtc { 25 26 // This class sends all its packet straight to the provided RtpRtcp module. 27 // with optional packet loss. 28 class LoopBackTransport : public Transport { 29 public: LoopBackTransport()30 LoopBackTransport() 31 : count_(0), 32 packet_loss_(0), 33 rtp_payload_registry_(NULL), 34 rtp_receiver_(NULL), 35 rtp_rtcp_module_(NULL) {} 36 void SetSendModule(RtpRtcp* rtp_rtcp_module, 37 RTPPayloadRegistry* payload_registry, 38 RtpReceiver* receiver, 39 ReceiveStatistics* receive_statistics); 40 void DropEveryNthPacket(int n); 41 bool SendRtp(const uint8_t* data, 42 size_t len, 43 const PacketOptions& options) override; 44 bool SendRtcp(const uint8_t* data, size_t len) override; 45 46 private: 47 int count_; 48 int packet_loss_; 49 ReceiveStatistics* receive_statistics_; 50 RTPPayloadRegistry* rtp_payload_registry_; 51 RtpReceiver* rtp_receiver_; 52 RtpRtcp* rtp_rtcp_module_; 53 }; 54 55 class TestRtpReceiver : public NullRtpData { 56 public: 57 int32_t OnReceivedPayloadData( 58 const uint8_t* payload_data, 59 const size_t payload_size, 60 const webrtc::WebRtcRTPHeader* rtp_header) override; 61 payload_data()62 const uint8_t* payload_data() const { return payload_data_; } payload_size()63 size_t payload_size() const { return payload_size_; } rtp_header()64 webrtc::WebRtcRTPHeader rtp_header() const { return rtp_header_; } 65 66 private: 67 uint8_t payload_data_[1500]; 68 size_t payload_size_; 69 webrtc::WebRtcRTPHeader rtp_header_; 70 }; 71 72 } // namespace webrtc 73 #endif // WEBRTC_MODULES_RTP_RTCP_TEST_TESTAPI_TEST_API_H_ 74