blob: df1fef7e4623bba55c0669280bc5596ffc65072a [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org0975d212012-03-06 20:59:13 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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// This sub-API supports the following functionalities:
12//
13// - Callbacks for RTP and RTCP events such as modified SSRC or CSRC.
14// - SSRC handling.
15// - Transmission of RTCP sender reports.
16// - Obtaining RTCP data from incoming RTCP sender reports.
17// - RTP and RTCP statistics (jitter, packet loss, RTT etc.).
18// - Forward Error Correction (FEC).
niklase@google.com470e71d2011-07-07 08:21:25 +000019// - Writing RTP and RTCP packets to binary files for off-line analysis of
20// the call quality.
21// - Inserting extra RTP packets into active audio stream.
22//
23// Usage example, omitting error checking:
24//
25// using namespace webrtc;
26// VoiceEngine* voe = VoiceEngine::Create();
27// VoEBase* base = VoEBase::GetInterface(voe);
28// VoERTP_RTCP* rtp_rtcp = VoERTP_RTCP::GetInterface(voe);
29// base->Init();
30// int ch = base->CreateChannel();
31// ...
32// rtp_rtcp->SetLocalSSRC(ch, 12345);
33// ...
34// base->DeleteChannel(ch);
35// base->Terminate();
36// base->Release();
37// rtp_rtcp->Release();
38// VoiceEngine::Delete(voe);
39//
40#ifndef WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H
41#define WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H
42
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000043#include <vector>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000044#include "webrtc/common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000045
46namespace webrtc {
47
48class VoiceEngine;
49
50// VoERTPObserver
51class WEBRTC_DLLEXPORT VoERTPObserver
52{
53public:
54 virtual void OnIncomingCSRCChanged(
pbos@webrtc.org92135212013-05-14 08:31:39 +000055 int channel, unsigned int CSRC, bool added) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
57 virtual void OnIncomingSSRCChanged(
pbos@webrtc.org92135212013-05-14 08:31:39 +000058 int channel, unsigned int SSRC) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
60protected:
61 virtual ~VoERTPObserver() {}
62};
63
64// VoERTCPObserver
65class WEBRTC_DLLEXPORT VoERTCPObserver
66{
67public:
68 virtual void OnApplicationDataReceived(
pbos@webrtc.org92135212013-05-14 08:31:39 +000069 int channel, unsigned char subType,
70 unsigned int name, const unsigned char* data,
71 unsigned short dataLengthInBytes) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
73protected:
74 virtual ~VoERTCPObserver() {}
75};
76
77// CallStatistics
78struct CallStatistics
79{
80 unsigned short fractionLost;
81 unsigned int cumulativeLost;
82 unsigned int extendedMax;
83 unsigned int jitterSamples;
84 int rttMs;
85 int bytesSent;
86 int packetsSent;
87 int bytesReceived;
88 int packetsReceived;
89};
90
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000091// See section 6.4.1 in http://www.ietf.org/rfc/rfc3550.txt for details.
92struct SenderInfo {
93 uint32_t NTP_timestamp_high;
94 uint32_t NTP_timestamp_low;
95 uint32_t RTP_timestamp;
96 uint32_t sender_packet_count;
97 uint32_t sender_octet_count;
98};
99
100// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
101struct ReportBlock {
102 uint32_t sender_SSRC; // SSRC of sender
103 uint32_t source_SSRC;
104 uint8_t fraction_lost;
105 uint32_t cumulative_num_packets_lost;
106 uint32_t extended_highest_sequence_number;
107 uint32_t interarrival_jitter;
108 uint32_t last_SR_timestamp;
109 uint32_t delay_since_last_SR;
110};
111
niklase@google.com470e71d2011-07-07 08:21:25 +0000112// VoERTP_RTCP
113class WEBRTC_DLLEXPORT VoERTP_RTCP
114{
115public:
116
117 // Factory for the VoERTP_RTCP sub-API. Increases an internal
118 // reference counter if successful. Returns NULL if the API is not
119 // supported or if construction fails.
120 static VoERTP_RTCP* GetInterface(VoiceEngine* voiceEngine);
121
122 // Releases the VoERTP_RTCP sub-API and decreases an internal
123 // reference counter. Returns the new reference count. This value should
124 // be zero for all sub-API:s before the VoiceEngine object can be safely
125 // deleted.
126 virtual int Release() = 0;
127
128 // Registers an instance of a VoERTPObserver derived class for a specified
129 // |channel|. It will allow the user to observe callbacks related to the
130 // RTP protocol such as changes in the incoming SSRC.
131 virtual int RegisterRTPObserver(int channel, VoERTPObserver& observer) = 0;
132
133 // Deregisters an instance of a VoERTPObserver derived class for a
134 // specified |channel|.
135 virtual int DeRegisterRTPObserver(int channel) = 0;
136
137 // Registers an instance of a VoERTCPObserver derived class for a specified
138 // |channel|.
139 virtual int RegisterRTCPObserver(
140 int channel, VoERTCPObserver& observer) = 0;
141
142 // Deregisters an instance of a VoERTCPObserver derived class for a
143 // specified |channel|.
144 virtual int DeRegisterRTCPObserver(int channel) = 0;
145
146 // Sets the local RTP synchronization source identifier (SSRC) explicitly.
147 virtual int SetLocalSSRC(int channel, unsigned int ssrc) = 0;
148
149 // Gets the local RTP SSRC of a specified |channel|.
150 virtual int GetLocalSSRC(int channel, unsigned int& ssrc) = 0;
151
152 // Gets the SSRC of the incoming RTP packets.
153 virtual int GetRemoteSSRC(int channel, unsigned int& ssrc) = 0;
154
155 // Sets the status of rtp-audio-level-indication on a specific |channel|.
156 virtual int SetRTPAudioLevelIndicationStatus(
157 int channel, bool enable, unsigned char ID = 1) = 0;
158
159 // Sets the status of rtp-audio-level-indication on a specific |channel|.
160 virtual int GetRTPAudioLevelIndicationStatus(
161 int channel, bool& enabled, unsigned char& ID) = 0;
162
163 // Gets the CSRCs of the incoming RTP packets.
164 virtual int GetRemoteCSRCs(int channel, unsigned int arrCSRC[15]) = 0;
165
166 // Sets the RTCP status on a specific |channel|.
167 virtual int SetRTCPStatus(int channel, bool enable) = 0;
168
169 // Gets the RTCP status on a specific |channel|.
170 virtual int GetRTCPStatus(int channel, bool& enabled) = 0;
171
172 // Sets the canonical name (CNAME) parameter for RTCP reports on a
173 // specific |channel|.
174 virtual int SetRTCP_CNAME(int channel, const char cName[256]) = 0;
175
176 // Gets the canonical name (CNAME) parameter for RTCP reports on a
177 // specific |channel|.
178 virtual int GetRTCP_CNAME(int channel, char cName[256]) = 0;
179
180 // Gets the canonical name (CNAME) parameter for incoming RTCP reports
181 // on a specific channel.
182 virtual int GetRemoteRTCP_CNAME(int channel, char cName[256]) = 0;
183
184 // Gets RTCP data from incoming RTCP Sender Reports.
185 virtual int GetRemoteRTCPData(
186 int channel, unsigned int& NTPHigh, unsigned int& NTPLow,
187 unsigned int& timestamp, unsigned int& playoutTimestamp,
188 unsigned int* jitter = NULL, unsigned short* fractionLost = NULL) = 0;
189
190 // Gets RTP statistics for a specific |channel|.
191 virtual int GetRTPStatistics(
192 int channel, unsigned int& averageJitterMs, unsigned int& maxJitterMs,
193 unsigned int& discardedPackets) = 0;
194
195 // Gets RTCP statistics for a specific |channel|.
196 virtual int GetRTCPStatistics(int channel, CallStatistics& stats) = 0;
197
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000198 // Gets the sender info part of the last received RTCP Sender Report (SR)
199 // on a specified |channel|.
200 virtual int GetRemoteRTCPSenderInfo(
201 int channel, SenderInfo* sender_info) = 0;
202
203 // Gets the report block parts of the last received RTCP Sender Report (SR),
204 // or RTCP Receiver Report (RR) on a specified |channel|. Each vector
205 // element also contains the SSRC of the sender in addition to a report
206 // block.
207 virtual int GetRemoteRTCPReportBlocks(
208 int channel, std::vector<ReportBlock>* receive_blocks) = 0;
209
niklase@google.com470e71d2011-07-07 08:21:25 +0000210 // Sends an RTCP APP packet on a specific |channel|.
211 virtual int SendApplicationDefinedRTCPPacket(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000212 int channel, unsigned char subType, unsigned int name,
niklase@google.com470e71d2011-07-07 08:21:25 +0000213 const char* data, unsigned short dataLengthInBytes) = 0;
214
215 // Sets the Forward Error Correction (FEC) status on a specific |channel|.
216 virtual int SetFECStatus(
217 int channel, bool enable, int redPayloadtype = -1) = 0;
218
219 // Gets the FEC status on a specific |channel|.
220 virtual int GetFECStatus(
221 int channel, bool& enabled, int& redPayloadtype) = 0;
222
niklase@google.com470e71d2011-07-07 08:21:25 +0000223 // Enables capturing of RTP packets to a binary file on a specific
224 // |channel| and for a given |direction|. The file can later be replayed
mflodman@webrtc.org3e820e52012-03-23 09:41:44 +0000225 // using e.g. RTP Tools rtpplay since the binary file format is
niklase@google.com470e71d2011-07-07 08:21:25 +0000226 // compatible with the rtpdump format.
227 virtual int StartRTPDump(
228 int channel, const char fileNameUTF8[1024],
229 RTPDirections direction = kRtpIncoming) = 0;
230
231 // Disables capturing of RTP packets to a binary file on a specific
232 // |channel| and for a given |direction|.
233 virtual int StopRTPDump(
234 int channel, RTPDirections direction = kRtpIncoming) = 0;
235
236 // Gets the the current RTP capturing state for the specified
237 // |channel| and |direction|.
238 virtual int RTPDumpIsActive(
239 int channel, RTPDirections direction = kRtpIncoming) = 0;
240
241 // Sends an extra RTP packet using an existing/active RTP session.
242 // It is possible to set the payload type, marker bit and payload
243 // of the extra RTP
244 virtual int InsertExtraRTPPacket(
245 int channel, unsigned char payloadType, bool markerBit,
246 const char* payloadData, unsigned short payloadSize) = 0;
247
roosa@google.com0870f022012-12-12 21:31:41 +0000248 // Gets the timestamp of the last RTP packet received by |channel|.
249 virtual int GetLastRemoteTimeStamp(int channel,
250 uint32_t* lastRemoteTimeStamp) = 0;
251
niklase@google.com470e71d2011-07-07 08:21:25 +0000252protected:
253 VoERTP_RTCP() {}
254 virtual ~VoERTP_RTCP() {}
255};
256
257} // namespace webrtc
258
259#endif // #ifndef WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H