blob: 6c06ef0a6fa94f1e1e0470b71d0a96b8947f8b82 [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.
niklase@google.com470e71d2011-07-07 08:21:25 +000021//
22// Usage example, omitting error checking:
23//
24// using namespace webrtc;
25// VoiceEngine* voe = VoiceEngine::Create();
26// VoEBase* base = VoEBase::GetInterface(voe);
27// VoERTP_RTCP* rtp_rtcp = VoERTP_RTCP::GetInterface(voe);
28// base->Init();
29// int ch = base->CreateChannel();
30// ...
31// rtp_rtcp->SetLocalSSRC(ch, 12345);
32// ...
33// base->DeleteChannel(ch);
34// base->Terminate();
35// base->Release();
36// rtp_rtcp->Release();
37// VoiceEngine::Delete(voe);
38//
39#ifndef WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H
40#define WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H
41
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000042#include <vector>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000043#include "webrtc/common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45namespace webrtc {
46
47class VoiceEngine;
48
49// VoERTPObserver
50class WEBRTC_DLLEXPORT VoERTPObserver
51{
52public:
53 virtual void OnIncomingCSRCChanged(
pbos@webrtc.org92135212013-05-14 08:31:39 +000054 int channel, unsigned int CSRC, bool added) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
56 virtual void OnIncomingSSRCChanged(
pbos@webrtc.org92135212013-05-14 08:31:39 +000057 int channel, unsigned int SSRC) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59protected:
60 virtual ~VoERTPObserver() {}
61};
62
63// VoERTCPObserver
64class WEBRTC_DLLEXPORT VoERTCPObserver
65{
66public:
67 virtual void OnApplicationDataReceived(
pbos@webrtc.org92135212013-05-14 08:31:39 +000068 int channel, unsigned char subType,
69 unsigned int name, const unsigned char* data,
70 unsigned short dataLengthInBytes) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
72protected:
73 virtual ~VoERTCPObserver() {}
74};
75
76// CallStatistics
77struct CallStatistics
78{
79 unsigned short fractionLost;
80 unsigned int cumulativeLost;
81 unsigned int extendedMax;
82 unsigned int jitterSamples;
83 int rttMs;
84 int bytesSent;
85 int packetsSent;
86 int bytesReceived;
87 int packetsReceived;
88};
89
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000090// See section 6.4.1 in http://www.ietf.org/rfc/rfc3550.txt for details.
91struct SenderInfo {
92 uint32_t NTP_timestamp_high;
93 uint32_t NTP_timestamp_low;
94 uint32_t RTP_timestamp;
95 uint32_t sender_packet_count;
96 uint32_t sender_octet_count;
97};
98
99// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
100struct ReportBlock {
101 uint32_t sender_SSRC; // SSRC of sender
102 uint32_t source_SSRC;
103 uint8_t fraction_lost;
104 uint32_t cumulative_num_packets_lost;
105 uint32_t extended_highest_sequence_number;
106 uint32_t interarrival_jitter;
107 uint32_t last_SR_timestamp;
108 uint32_t delay_since_last_SR;
109};
110
niklase@google.com470e71d2011-07-07 08:21:25 +0000111// VoERTP_RTCP
112class WEBRTC_DLLEXPORT VoERTP_RTCP
113{
114public:
115
116 // Factory for the VoERTP_RTCP sub-API. Increases an internal
117 // reference counter if successful. Returns NULL if the API is not
118 // supported or if construction fails.
119 static VoERTP_RTCP* GetInterface(VoiceEngine* voiceEngine);
120
121 // Releases the VoERTP_RTCP sub-API and decreases an internal
122 // reference counter. Returns the new reference count. This value should
123 // be zero for all sub-API:s before the VoiceEngine object can be safely
124 // deleted.
125 virtual int Release() = 0;
126
127 // Registers an instance of a VoERTPObserver derived class for a specified
128 // |channel|. It will allow the user to observe callbacks related to the
129 // RTP protocol such as changes in the incoming SSRC.
130 virtual int RegisterRTPObserver(int channel, VoERTPObserver& observer) = 0;
131
132 // Deregisters an instance of a VoERTPObserver derived class for a
133 // specified |channel|.
134 virtual int DeRegisterRTPObserver(int channel) = 0;
135
136 // Registers an instance of a VoERTCPObserver derived class for a specified
137 // |channel|.
138 virtual int RegisterRTCPObserver(
139 int channel, VoERTCPObserver& observer) = 0;
140
141 // Deregisters an instance of a VoERTCPObserver derived class for a
142 // specified |channel|.
143 virtual int DeRegisterRTCPObserver(int channel) = 0;
144
145 // Sets the local RTP synchronization source identifier (SSRC) explicitly.
146 virtual int SetLocalSSRC(int channel, unsigned int ssrc) = 0;
147
148 // Gets the local RTP SSRC of a specified |channel|.
149 virtual int GetLocalSSRC(int channel, unsigned int& ssrc) = 0;
150
151 // Gets the SSRC of the incoming RTP packets.
152 virtual int GetRemoteSSRC(int channel, unsigned int& ssrc) = 0;
153
154 // Sets the status of rtp-audio-level-indication on a specific |channel|.
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000155 virtual int SetSendAudioLevelIndicationStatus(int channel,
156 bool enable,
157 unsigned char id = 1) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000159 // Sets the status of sending absolute sender time on a specific |channel|.
160 virtual int SetSendAbsoluteSenderTimeStatus(int channel,
161 bool enable,
162 unsigned char id) = 0;
163
164 // Sets status of receiving absolute sender time on a specific |channel|.
165 virtual int SetReceiveAbsoluteSenderTimeStatus(int channel,
166 bool enable,
167 unsigned char id) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
169 // Gets the CSRCs of the incoming RTP packets.
170 virtual int GetRemoteCSRCs(int channel, unsigned int arrCSRC[15]) = 0;
171
172 // Sets the RTCP status on a specific |channel|.
173 virtual int SetRTCPStatus(int channel, bool enable) = 0;
174
175 // Gets the RTCP status on a specific |channel|.
176 virtual int GetRTCPStatus(int channel, bool& enabled) = 0;
177
178 // Sets the canonical name (CNAME) parameter for RTCP reports on a
179 // specific |channel|.
180 virtual int SetRTCP_CNAME(int channel, const char cName[256]) = 0;
181
182 // Gets the canonical name (CNAME) parameter for RTCP reports on a
183 // specific |channel|.
184 virtual int GetRTCP_CNAME(int channel, char cName[256]) = 0;
185
186 // Gets the canonical name (CNAME) parameter for incoming RTCP reports
187 // on a specific channel.
188 virtual int GetRemoteRTCP_CNAME(int channel, char cName[256]) = 0;
189
190 // Gets RTCP data from incoming RTCP Sender Reports.
191 virtual int GetRemoteRTCPData(
192 int channel, unsigned int& NTPHigh, unsigned int& NTPLow,
193 unsigned int& timestamp, unsigned int& playoutTimestamp,
194 unsigned int* jitter = NULL, unsigned short* fractionLost = NULL) = 0;
195
196 // Gets RTP statistics for a specific |channel|.
197 virtual int GetRTPStatistics(
198 int channel, unsigned int& averageJitterMs, unsigned int& maxJitterMs,
199 unsigned int& discardedPackets) = 0;
200
201 // Gets RTCP statistics for a specific |channel|.
202 virtual int GetRTCPStatistics(int channel, CallStatistics& stats) = 0;
203
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000204 // Gets the sender info part of the last received RTCP Sender Report (SR)
205 // on a specified |channel|.
206 virtual int GetRemoteRTCPSenderInfo(
207 int channel, SenderInfo* sender_info) = 0;
208
209 // Gets the report block parts of the last received RTCP Sender Report (SR),
210 // or RTCP Receiver Report (RR) on a specified |channel|. Each vector
211 // element also contains the SSRC of the sender in addition to a report
212 // block.
213 virtual int GetRemoteRTCPReportBlocks(
214 int channel, std::vector<ReportBlock>* receive_blocks) = 0;
215
niklase@google.com470e71d2011-07-07 08:21:25 +0000216 // Sends an RTCP APP packet on a specific |channel|.
217 virtual int SendApplicationDefinedRTCPPacket(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000218 int channel, unsigned char subType, unsigned int name,
niklase@google.com470e71d2011-07-07 08:21:25 +0000219 const char* data, unsigned short dataLengthInBytes) = 0;
220
221 // Sets the Forward Error Correction (FEC) status on a specific |channel|.
222 virtual int SetFECStatus(
223 int channel, bool enable, int redPayloadtype = -1) = 0;
224
225 // Gets the FEC status on a specific |channel|.
226 virtual int GetFECStatus(
227 int channel, bool& enabled, int& redPayloadtype) = 0;
228
niklas.enbom@webrtc.orgb35d2e32013-05-31 21:13:52 +0000229 // This function enables Negative Acknowledgment (NACK) using RTCP,
230 // implemented based on RFC 4585. NACK retransmits RTP packets if lost on
231 // the network. This creates a lossless transport at the expense of delay.
232 // If using NACK, NACK should be enabled on both endpoints in a call.
233 virtual int SetNACKStatus(int channel,
234 bool enable,
235 int maxNoPackets) = 0;
236
niklase@google.com470e71d2011-07-07 08:21:25 +0000237 // Enables capturing of RTP packets to a binary file on a specific
238 // |channel| and for a given |direction|. The file can later be replayed
mflodman@webrtc.org3e820e52012-03-23 09:41:44 +0000239 // using e.g. RTP Tools rtpplay since the binary file format is
niklase@google.com470e71d2011-07-07 08:21:25 +0000240 // compatible with the rtpdump format.
241 virtual int StartRTPDump(
242 int channel, const char fileNameUTF8[1024],
243 RTPDirections direction = kRtpIncoming) = 0;
244
245 // Disables capturing of RTP packets to a binary file on a specific
246 // |channel| and for a given |direction|.
247 virtual int StopRTPDump(
248 int channel, RTPDirections direction = kRtpIncoming) = 0;
249
250 // Gets the the current RTP capturing state for the specified
251 // |channel| and |direction|.
252 virtual int RTPDumpIsActive(
253 int channel, RTPDirections direction = kRtpIncoming) = 0;
254
roosa@google.com0870f022012-12-12 21:31:41 +0000255 // Gets the timestamp of the last RTP packet received by |channel|.
256 virtual int GetLastRemoteTimeStamp(int channel,
257 uint32_t* lastRemoteTimeStamp) = 0;
258
henrika@webrtc.orgb7a91fa2014-02-19 08:58:08 +0000259 // Don't use. To be removed.
260 virtual int InsertExtraRTPPacket(
261 int channel, unsigned char payloadType, bool markerBit,
262 const char* payloadData, unsigned short payloadSize) { return -1; };
263
264
niklase@google.com470e71d2011-07-07 08:21:25 +0000265protected:
266 VoERTP_RTCP() {}
267 virtual ~VoERTP_RTCP() {}
268};
269
270} // namespace webrtc
271
272#endif // #ifndef WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H