Files
platform-external-webrtc/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h
stefan@webrtc.org 20ed36dada Break out RtpClock to system_wrappers and make it more generic.
The goal with this new clock interface is to have something which is used all
over WebRTC to make it easier to switch clock implementation depending on where
the components are used. This is a first step in that direction.

Next steps will be to, step by step, move all modules, video engine and voice
engine over to the new interface, effectively deprecating the old clock
interfaces. Long-term my vision is that we should be able to deprecate the clock
of WebRTC and rely on the user providing the implementation.

TEST=vie_auto_test, rtp_rtcp_unittests, trybots

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3381 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-01-17 14:01:20 +00:00

116 lines
3.0 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 "common_types.h"
#include "rtp_rtcp.h"
#include "rtp_rtcp_defines.h"
namespace webrtc {
class FakeRtpRtcpClock : public Clock {
public:
FakeRtpRtcpClock() {
time_in_ms_ = 123456;
}
// Return a timestamp in milliseconds relative to some arbitrary
// source; the source is fixed for this clock.
virtual WebRtc_Word64 TimeInMilliseconds() {
return time_in_ms_;
}
virtual int64_t TimeInMicroseconds() {
return time_in_ms_ * 1000;
}
// Retrieve an NTP absolute timestamp.
virtual void CurrentNtp(WebRtc_UWord32& secs, WebRtc_UWord32& frac) {
secs = time_in_ms_ / 1000;
frac = (time_in_ms_ % 1000) * 4294967;
}
void IncrementTime(WebRtc_UWord32 time_increment_ms) {
time_in_ms_ += time_increment_ms;
}
private:
WebRtc_Word64 time_in_ms_;
};
// 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;
}
}
if (_rtpRtcpModule->IncomingPacket((const WebRtc_UWord8*)data, len) == 0) {
return len;
}
return -1;
}
virtual int SendRTCPPacket(int channel, const void *data, int len) {
if (_rtpRtcpModule->IncomingPacket((const WebRtc_UWord8*)data, len) == 0) {
return len;
}
return -1;
}
private:
int _count;
int _packetLoss;
RtpRtcp* _rtpRtcpModule;
};
class RtpReceiver : public RtpData {
public:
enum { kMaxPayloadSize = 1500 };
virtual WebRtc_Word32 OnReceivedPayloadData(
const WebRtc_UWord8* payloadData,
const WebRtc_UWord16 payloadSize,
const webrtc::WebRtcRTPHeader* rtpHeader) {
EXPECT_LE(payloadSize, kMaxPayloadSize);
memcpy(_payloadData, payloadData, payloadSize);
memcpy(&_rtpHeader, rtpHeader, sizeof(_rtpHeader));
_payloadSize = payloadSize;
return 0;
}
const WebRtc_UWord8* payload_data() const {
return _payloadData;
}
WebRtc_UWord16 payload_size() const {
return _payloadSize;
}
webrtc::WebRtcRTPHeader rtp_header() const {
return _rtpHeader;
}
private:
WebRtc_UWord8 _payloadData[kMaxPayloadSize];
WebRtc_UWord16 _payloadSize;
webrtc::WebRtcRTPHeader _rtpHeader;
};
} // namespace webrtc