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