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) OVERRIDE {
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),
56 static_cast<size_t>(len),
60 PayloadUnion payload_specific;
61 if (!rtp_payload_registry_->GetPayloadSpecifics(
62 header.payloadType, &payload_specific)) {
65 receive_statistics_->IncomingPacket(header, len, false);
66 if (!rtp_receiver_->IncomingRtpPacket(header,
67 static_cast<const uint8_t*>(data),
68 len, payload_specific, true)) {
73 virtual int SendRTCPPacket(int channel, const void *data, int len) OVERRIDE {
74 if (_rtpRtcpModule->IncomingRtcpPacket((const uint8_t*)data, len) < 0) {
82 ReceiveStatistics* receive_statistics_;
83 RTPPayloadRegistry* rtp_payload_registry_;
84 RtpReceiver* rtp_receiver_;
85 RtpRtcp* _rtpRtcpModule;
88 class TestRtpReceiver : public NullRtpData {
91 virtual int32_t OnReceivedPayloadData(
92 const uint8_t* payloadData,
93 const uint16_t payloadSize,
94 const webrtc::WebRtcRTPHeader* rtpHeader) OVERRIDE {
95 EXPECT_LE(payloadSize, sizeof(_payloadData));
96 memcpy(_payloadData, payloadData, payloadSize);
97 memcpy(&_rtpHeader, rtpHeader, sizeof(_rtpHeader));
98 _payloadSize = payloadSize;
102 const uint8_t* payload_data() const {
106 uint16_t payload_size() const {
110 webrtc::WebRtcRTPHeader rtp_header() const {
115 uint8_t _payloadData[1500];
116 uint16_t _payloadSize;
117 webrtc::WebRtcRTPHeader _rtpHeader;
120 } // namespace webrtc