2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/common_types.h"
13 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
14 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
15 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
16 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h"
17 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
18 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
19 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
23 // This class sends all its packet straight to the provided RtpRtcp module.
24 // with optional packet loss.
25 class LoopBackTransport : public webrtc::Transport {
30 rtp_payload_registry_(NULL),
32 _rtpRtcpModule(NULL) {
34 void SetSendModule(RtpRtcp* rtpRtcpModule,
35 RTPPayloadRegistry* payload_registry,
36 RtpReceiver* receiver,
37 ReceiveStatistics* receive_statistics) {
38 _rtpRtcpModule = rtpRtcpModule;
39 rtp_payload_registry_ = payload_registry;
40 rtp_receiver_ = receiver;
41 receive_statistics_ = receive_statistics;
43 void DropEveryNthPacket(int n) {
46 virtual int SendPacket(int channel, const void *data, int len) {
48 if (_packetLoss > 0) {
49 if ((_count % _packetLoss) == 0) {
54 scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
55 if (!parser->Parse(static_cast<const uint8_t*>(data), len, &header)) {
58 PayloadUnion payload_specific;
59 if (!rtp_payload_registry_->GetPayloadSpecifics(
60 header.payloadType, &payload_specific)) {
63 receive_statistics_->IncomingPacket(header, len, false);
64 if (!rtp_receiver_->IncomingRtpPacket(header,
65 static_cast<const uint8_t*>(data),
66 len, payload_specific, true)) {
71 virtual int SendRTCPPacket(int channel, const void *data, int len) {
72 if (_rtpRtcpModule->IncomingRtcpPacket((const uint8_t*)data, len) < 0) {
80 ReceiveStatistics* receive_statistics_;
81 RTPPayloadRegistry* rtp_payload_registry_;
82 RtpReceiver* rtp_receiver_;
83 RtpRtcp* _rtpRtcpModule;
86 class TestRtpReceiver : public NullRtpData {
89 virtual int32_t OnReceivedPayloadData(
90 const uint8_t* payloadData,
91 const uint16_t payloadSize,
92 const webrtc::WebRtcRTPHeader* rtpHeader) {
93 EXPECT_LE(payloadSize, sizeof(_payloadData));
94 memcpy(_payloadData, payloadData, payloadSize);
95 memcpy(&_rtpHeader, rtpHeader, sizeof(_rtpHeader));
96 _payloadSize = payloadSize;
100 const uint8_t* payload_data() const {
104 uint16_t payload_size() const {
108 webrtc::WebRtcRTPHeader rtp_header() const {
113 uint8_t _payloadData[1500];
114 uint16_t _payloadSize;
115 webrtc::WebRtcRTPHeader _rtpHeader;
118 } // namespace webrtc