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.
12 // tb_external_transport.h
15 #ifndef WEBRTC_VIDEO_ENGINE_TEST_AUTOTEST_INTERFACE_TB_EXTERNAL_TRANSPORT_H_
16 #define WEBRTC_VIDEO_ENGINE_TEST_AUTOTEST_INTERFACE_TB_EXTERNAL_TRANSPORT_H_
21 #include "webrtc/common_types.h"
25 class CriticalSectionWrapper;
31 enum RandomLossModel {
36 struct NetworkParameters {
38 int burst_length; // Only applicable for kGilbertElliotLoss.
39 int mean_one_way_delay;
40 int std_dev_one_way_delay;
41 RandomLossModel loss_model;
43 packet_loss_rate(0), burst_length(0), mean_one_way_delay(0),
44 std_dev_one_way_delay(0), loss_model(kNoLoss) {}
47 // Allows to subscribe for callback when a frame is started being sent.
48 class SendFrameCallback
51 // Called once per frame (when a new RTP timestamp is detected) when the
52 // first data packet of the frame is being sent using the
53 // TbExternalTransport.SendPacket method.
54 virtual void FrameSent(unsigned int rtp_timestamp) = 0;
56 SendFrameCallback() {}
57 virtual ~SendFrameCallback() {}
60 // Allows to subscribe for callback when the first packet of a frame is
62 class ReceiveFrameCallback
65 // Called once per frame (when a new RTP timestamp is detected)
66 // during the processing of the RTP packet queue in
67 // TbExternalTransport::ViEExternalTransportProcess.
68 virtual void FrameReceived(unsigned int rtp_timestamp) = 0;
70 ReceiveFrameCallback() {}
71 virtual ~ReceiveFrameCallback() {}
74 // External transport implementation for testing purposes.
75 // A packet loss probability must be set in order to drop packets from the data
76 // being sent to this class.
77 // Will never drop packets from the first frame of a video sequence.
78 class TbExternalTransport : public webrtc::Transport
81 typedef std::map<unsigned int, unsigned int> SsrcChannelMap;
83 TbExternalTransport(webrtc::ViENetwork& vieNetwork,
85 TbExternalTransport::SsrcChannelMap* receive_channels);
86 ~TbExternalTransport(void);
88 virtual int SendPacket(int channel, const void *data, int len) OVERRIDE;
89 virtual int SendRTCPPacket(int channel, const void *data, int len) OVERRIDE;
91 // Should only be called before/after traffic is being processed.
92 // Only one observer can be set (multiple calls will overwrite each other).
93 virtual void RegisterSendFrameCallback(SendFrameCallback* callback);
95 // Should only be called before/after traffic is being processed.
96 // Only one observer can be set (multiple calls will overwrite each other).
97 virtual void RegisterReceiveFrameCallback(ReceiveFrameCallback* callback);
99 // The network parameters of the link. Regarding packet losses, packets
100 // belonging to the first frame (same RTP timestamp) will never be dropped.
101 void SetNetworkParameters(const NetworkParameters& network_parameters);
102 void SetSSRCFilter(uint32_t SSRC);
105 // |packet_counters| is a map which counts the number of packets sent per
107 void GetStats(int32_t& numRtpPackets,
108 int32_t& numDroppedPackets,
109 int32_t& numRtcpPackets,
110 std::map<uint8_t, int>* packet_counters);
112 void SetTemporalToggle(unsigned char layers);
113 void EnableSSRCCheck();
114 unsigned int ReceivedSSRC();
116 void EnableSequenceNumberCheck();
117 unsigned short GetFirstSequenceNumber();
119 bool EmptyQueue() const;
122 static bool ViEExternalTransportRun(void* object);
123 bool ViEExternalTransportProcess();
125 // TODO(mikhal): Break these out to classes.
126 static int GaussianRandom(int mean_ms, int standard_deviation_ms);
127 bool UniformLoss(int loss_rate);
128 bool GilbertElliotLoss(int loss_rate, int burst_length);
133 KMaxPacketSize = 1650
141 int8_t packetBuffer[KMaxPacketSize];
148 SsrcChannelMap* receive_channels_;
149 webrtc::ViENetwork& _vieNetwork;
150 webrtc::ThreadWrapper& _thread;
151 webrtc::EventWrapper& _event;
152 webrtc::CriticalSectionWrapper& _crit;
153 webrtc::CriticalSectionWrapper& _statCrit;
155 NetworkParameters network_parameters_;
159 // |packet_counters| is a map which counts the number of packets sent per
161 std::map<uint8_t, int> packet_counters_;
163 std::list<VideoPacket*> _rtpPackets;
164 std::list<VideoPacket*> _rtcpPackets;
166 SendFrameCallback* _send_frame_callback;
167 ReceiveFrameCallback* _receive_frame_callback;
169 unsigned char _temporalLayers;
170 unsigned short _seqNum;
171 unsigned short _sendPID;
172 unsigned char _receivedPID;
174 unsigned char _currentRelayLayer;
175 unsigned int _lastTimeMs;
181 bool _checkSequenceNumber;
182 uint16_t _firstSequenceNumber;
184 // Keep track of the first RTP timestamp so we don't do packet loss on
186 uint32_t _firstRTPTimestamp;
187 // Track RTP timestamps so we invoke callbacks properly (if registered).
188 uint32_t _lastSendRTPTimestamp;
189 uint32_t _lastReceiveRTPTimestamp;
190 int64_t last_receive_time_;
194 #endif // WEBRTC_VIDEO_ENGINE_TEST_AUTOTEST_INTERFACE_TB_EXTERNAL_TRANSPORT_H_