Files
platform-external-webrtc/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h
stefan@webrtc.org a5cb98cbbd Breaking out RTP header parsing from the RTP module.
This is the first step in order to move bandwidth estimation closer to the network. The goal is to have RTP header parsing and bandwidth estimation before voice and video engine, and have a joint estimate for audio and video.

Moving bandwidth estimation before the RTP module is also required for RTX.

TEST=vie_auto_test, voe_auto_test, trybots.
BUG=1811
R=andresp@webrtc.org, henrika@webrtc.org, mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1545004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4129 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-05-29 12:12:51 +00:00

98 lines
2.7 KiB
C++

/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/common_types.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
namespace webrtc {
// This class sends all its packet straight to the provided RtpRtcp module.
// with optional packet loss.
class LoopBackTransport : public webrtc::Transport {
public:
LoopBackTransport()
: _count(0),
_packetLoss(0),
_rtpRtcpModule(NULL) {
}
void SetSendModule(RtpRtcp* rtpRtcpModule) {
_rtpRtcpModule = rtpRtcpModule;
}
void DropEveryNthPacket(int n) {
_packetLoss = n;
}
virtual int SendPacket(int channel, const void *data, int len) {
_count++;
if (_packetLoss > 0) {
if ((_count % _packetLoss) == 0) {
return len;
}
}
RTPHeader header;
scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
if (!parser->Parse(static_cast<const uint8_t*>(data), len, &header)) {
return -1;
}
if (_rtpRtcpModule->IncomingRtpPacket(static_cast<const uint8_t*>(data),
len, header) < 0) {
return -1;
}
return len;
}
virtual int SendRTCPPacket(int channel, const void *data, int len) {
if (_rtpRtcpModule->IncomingRtcpPacket((const uint8_t*)data, len) < 0) {
return -1;
}
return len;
}
private:
int _count;
int _packetLoss;
RtpRtcp* _rtpRtcpModule;
};
class RtpReceiver : public RtpData {
public:
virtual int32_t OnReceivedPayloadData(
const uint8_t* payloadData,
const uint16_t payloadSize,
const webrtc::WebRtcRTPHeader* rtpHeader) {
EXPECT_LE(payloadSize, sizeof(_payloadData));
memcpy(_payloadData, payloadData, payloadSize);
memcpy(&_rtpHeader, rtpHeader, sizeof(_rtpHeader));
_payloadSize = payloadSize;
return 0;
}
const uint8_t* payload_data() const {
return _payloadData;
}
uint16_t payload_size() const {
return _payloadSize;
}
webrtc::WebRtcRTPHeader rtp_header() const {
return _rtpHeader;
}
private:
uint8_t _payloadData[1500];
uint16_t _payloadSize;
webrtc::WebRtcRTPHeader _rtpHeader;
};
} // namespace webrtc