Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / rtp_rtcp / test / BWEStandAlone / TestSenderReceiver.h
1 /*
2  *  Copyright (c) 2011 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 #ifndef WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_
12 #define WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_
13
14 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
15 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
16 #include "webrtc/test/channel_transport/udp_transport.h"
17 #include "webrtc/typedefs.h"
18
19 class TestLoadGenerator;
20 namespace webrtc {
21 class CriticalSectionWrapper;
22 class EventWrapper;
23 class ThreadWrapper;
24 }
25
26 using namespace webrtc;
27
28 #define MAX_BITRATE_KBPS 50000
29
30
31 class SendRecCB
32 {
33 public:
34     virtual void OnOnNetworkChanged(const uint32_t bitrateTarget,
35         const uint8_t fractionLost,
36         const uint16_t roundTripTimeMs,
37         const uint16_t bwEstimateKbitMin,
38         const uint16_t bwEstimateKbitMax) = 0;
39
40     virtual ~SendRecCB() {};
41 };
42
43
44 class TestSenderReceiver : public RtpFeedback, public RtpData, public UdpTransportData, public RtpVideoFeedback
45 {
46
47 public:
48     TestSenderReceiver (void);
49
50     ~TestSenderReceiver (void);
51
52     void SetCallback (SendRecCB *cb) { _sendRecCB = cb; };
53
54     int32_t Start();
55
56     int32_t Stop();
57
58     bool ProcLoop();
59
60     /////////////////////////////////////////////
61     // Receiver methods
62
63     int32_t InitReceiver (const uint16_t rtpPort,
64                           const uint16_t rtcpPort = 0,
65                           const int8_t payloadType = 127);
66
67     int32_t ReceiveBitrateKbps ();
68
69     int32_t SetPacketTimeout(const uint32_t timeoutMS);
70
71     bool timeOutTriggered () { return (_timeOut); };
72
73     // Inherited from RtpFeedback
74     virtual int32_t OnInitializeDecoder(
75         const int32_t id,
76         const int8_t payloadType,
77         const int8_t payloadName[RTP_PAYLOAD_NAME_SIZE],
78         const uint32_t frequency,
79         const uint8_t channels,
80         const uint32_t rate) OVERRIDE {
81       return 0;
82     }
83
84     virtual void OnPacketTimeout(const int32_t id);
85
86     virtual void OnReceivedPacket(const int32_t id,
87                                   const RtpRtcpPacketType packetType);
88
89     virtual void OnPeriodicDeadOrAlive(const int32_t id,
90                                        const RTPAliveType alive) {};
91
92     virtual void OnIncomingSSRCChanged(const int32_t id,
93                                        const uint32_t SSRC) OVERRIDE {}
94
95     virtual void OnIncomingCSRCChanged(const int32_t id,
96                                        const uint32_t CSRC,
97                                        const bool added) OVERRIDE {}
98
99
100     // Inherited from RtpData
101     virtual int32_t OnReceivedPayloadData(
102         const uint8_t* payloadData,
103         const uint16_t payloadSize,
104         const webrtc::WebRtcRTPHeader* rtpHeader) OVERRIDE;
105
106
107     // Inherited from UdpTransportData
108     virtual void IncomingRTPPacket(const int8_t* incomingRtpPacket,
109                                    const int32_t rtpPacketLength,
110                                    const int8_t* fromIP,
111                                    const uint16_t fromPort) OVERRIDE;
112
113     virtual void IncomingRTCPPacket(const int8_t* incomingRtcpPacket,
114                                     const int32_t rtcpPacketLength,
115                                     const int8_t* fromIP,
116                                     const uint16_t fromPort) OVERRIDE;
117
118
119
120     /////////////////////////////////
121     // Sender methods
122
123     int32_t InitSender (const uint32_t startBitrateKbps,
124                         const int8_t* ipAddr,
125                         const uint16_t rtpPort,
126                         const uint16_t rtcpPort = 0,
127                         const int8_t payloadType = 127);
128
129     int32_t SendOutgoingData(const uint32_t timeStamp,
130         const uint8_t* payloadData,
131         const uint32_t payloadSize,
132         const webrtc::FrameType frameType = webrtc::kVideoFrameDelta);
133
134     int32_t SetLoadGenerator(TestLoadGenerator *generator);
135
136     uint32_t BitrateSent() { return (_rtp->BitrateSent()); };
137
138
139     // Inherited from RtpVideoFeedback
140     virtual void OnReceivedIntraFrameRequest(const int32_t id,
141         const uint8_t message = 0) {};
142
143     virtual void OnNetworkChanged(const int32_t id,
144                                   const uint32_t minBitrateBps,
145                                   const uint32_t maxBitrateBps,
146                                   const uint8_t fractionLost,
147                                   const uint16_t roundTripTimeMs,
148                                   const uint16_t bwEstimateKbitMin,
149                                   const uint16_t bwEstimateKbitMax);
150
151 private:
152     RtpRtcp* _rtp;
153     UdpTransport* _transport;
154     webrtc::CriticalSectionWrapper* _critSect;
155     webrtc::EventWrapper *_eventPtr;
156     webrtc::ThreadWrapper* _procThread;
157     bool _running;
158     int8_t _payloadType;
159     TestLoadGenerator* _loadGenerator;
160     bool _isSender;
161     bool _isReceiver;
162     bool _timeOut;
163     SendRecCB * _sendRecCB;
164     uint32_t _lastBytesReceived;
165     int64_t _lastTime;
166
167 };
168
169 #endif // WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_