test_api.h revision 14b43beb7ce4440b30dcea31196de5b4a529cb6b
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
11#include "common_types.h"
12#include "rtp_rtcp.h"
13#include "rtp_rtcp_defines.h"
14
15namespace webrtc {
16
17class FakeRtpRtcpClock : public RtpRtcpClock {
18 public:
19  FakeRtpRtcpClock() {
20    time_in_ms_ = 123456;
21  }
22  // Return a timestamp in milliseconds relative to some arbitrary
23  // source; the source is fixed for this clock.
24  virtual WebRtc_Word64 GetTimeInMS() {
25    return time_in_ms_;
26  }
27  // Retrieve an NTP absolute timestamp.
28  virtual void CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac) {
29    secs = time_in_ms_ / 1000;
30    frac = (time_in_ms_ % 1000) * 4294967;
31  }
32  void IncrementTime(WebRtc_UWord32 time_increment_ms) {
33    time_in_ms_ += time_increment_ms;
34  }
35 private:
36  WebRtc_Word64 time_in_ms_;
37};
38
39// This class sends all its packet straight to the provided RtpRtcp module.
40// with optional packet loss.
41class LoopBackTransport : public webrtc::Transport {
42 public:
43  LoopBackTransport()
44    : _count(0),
45      _packetLoss(0),
46      _rtpRtcpModule(NULL) {
47  }
48  void SetSendModule(RtpRtcp* rtpRtcpModule) {
49    _rtpRtcpModule = rtpRtcpModule;
50  }
51  void DropEveryNthPacket(int n) {
52    _packetLoss = n;
53  }
54  virtual int SendPacket(int channel, const void *data, int len) {
55    _count++;
56    if (_packetLoss > 0) {
57      if ((_count % _packetLoss) == 0) {
58        return len;
59      }
60    }
61    if (_rtpRtcpModule->IncomingPacket((const WebRtc_UWord8*)data, len) == 0) {
62      return len;
63    }
64    return -1;
65  }
66  virtual int SendRTCPPacket(int channel, const void *data, int len) {
67    if (_rtpRtcpModule->IncomingPacket((const WebRtc_UWord8*)data, len) == 0) {
68      return len;
69    }
70    return -1;
71  }
72 private:
73  int _count;
74  int _packetLoss;
75  RtpRtcp* _rtpRtcpModule;
76};
77
78class RtpReceiver : public RtpData {
79 public:
80   virtual WebRtc_Word32 OnReceivedPayloadData(
81       const WebRtc_UWord8* payloadData,
82       const WebRtc_UWord16 payloadSize,
83       const webrtc::WebRtcRTPHeader* rtpHeader) {
84    return 0;
85  }
86};
87
88}  // namespace webrtc
89
90