blob: ce6f849931331642e45635e84c78c69ce241e4fc [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.).
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +000018// - Redundant Coding (RED)
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
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000047class ViENetwork;
niklase@google.com470e71d2011-07-07 08:21:25 +000048class 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;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +000089 // The capture ntp time (in local timebase) of the first played out audio
90 // frame.
91 int64_t capture_start_ntp_time_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +000092};
93
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000094// See section 6.4.1 in http://www.ietf.org/rfc/rfc3550.txt for details.
95struct SenderInfo {
96 uint32_t NTP_timestamp_high;
97 uint32_t NTP_timestamp_low;
98 uint32_t RTP_timestamp;
99 uint32_t sender_packet_count;
100 uint32_t sender_octet_count;
101};
102
103// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
104struct ReportBlock {
105 uint32_t sender_SSRC; // SSRC of sender
106 uint32_t source_SSRC;
107 uint8_t fraction_lost;
108 uint32_t cumulative_num_packets_lost;
109 uint32_t extended_highest_sequence_number;
110 uint32_t interarrival_jitter;
111 uint32_t last_SR_timestamp;
112 uint32_t delay_since_last_SR;
113};
114
niklase@google.com470e71d2011-07-07 08:21:25 +0000115// VoERTP_RTCP
116class WEBRTC_DLLEXPORT VoERTP_RTCP
117{
118public:
119
120 // Factory for the VoERTP_RTCP sub-API. Increases an internal
121 // reference counter if successful. Returns NULL if the API is not
122 // supported or if construction fails.
123 static VoERTP_RTCP* GetInterface(VoiceEngine* voiceEngine);
124
125 // Releases the VoERTP_RTCP sub-API and decreases an internal
126 // reference counter. Returns the new reference count. This value should
127 // be zero for all sub-API:s before the VoiceEngine object can be safely
128 // deleted.
129 virtual int Release() = 0;
130
niklase@google.com470e71d2011-07-07 08:21:25 +0000131 // Sets the local RTP synchronization source identifier (SSRC) explicitly.
132 virtual int SetLocalSSRC(int channel, unsigned int ssrc) = 0;
133
134 // Gets the local RTP SSRC of a specified |channel|.
135 virtual int GetLocalSSRC(int channel, unsigned int& ssrc) = 0;
136
137 // Gets the SSRC of the incoming RTP packets.
138 virtual int GetRemoteSSRC(int channel, unsigned int& ssrc) = 0;
139
140 // Sets the status of rtp-audio-level-indication on a specific |channel|.
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000141 virtual int SetSendAudioLevelIndicationStatus(int channel,
142 bool enable,
143 unsigned char id = 1) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000145 // Sets the status of receiving rtp-audio-level-indication on a specific
146 // |channel|.
147 virtual int SetReceiveAudioLevelIndicationStatus(int channel,
148 bool enable,
149 unsigned char id = 1) {
150 // TODO(wu): Remove default implementation once talk is updated.
151 return 0;
152 }
153
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000154 // Sets the status of sending absolute sender time on a specific |channel|.
155 virtual int SetSendAbsoluteSenderTimeStatus(int channel,
156 bool enable,
157 unsigned char id) = 0;
158
159 // Sets status of receiving absolute sender time on a specific |channel|.
160 virtual int SetReceiveAbsoluteSenderTimeStatus(int channel,
161 bool enable,
162 unsigned char id) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000163
niklase@google.com470e71d2011-07-07 08:21:25 +0000164 // Sets the RTCP status on a specific |channel|.
165 virtual int SetRTCPStatus(int channel, bool enable) = 0;
166
167 // Gets the RTCP status on a specific |channel|.
168 virtual int GetRTCPStatus(int channel, bool& enabled) = 0;
169
170 // Sets the canonical name (CNAME) parameter for RTCP reports on a
171 // specific |channel|.
172 virtual int SetRTCP_CNAME(int channel, const char cName[256]) = 0;
173
174 // Gets the canonical name (CNAME) parameter for RTCP reports on a
175 // specific |channel|.
176 virtual int GetRTCP_CNAME(int channel, char cName[256]) = 0;
177
178 // Gets the canonical name (CNAME) parameter for incoming RTCP reports
179 // on a specific channel.
180 virtual int GetRemoteRTCP_CNAME(int channel, char cName[256]) = 0;
181
182 // Gets RTCP data from incoming RTCP Sender Reports.
183 virtual int GetRemoteRTCPData(
184 int channel, unsigned int& NTPHigh, unsigned int& NTPLow,
185 unsigned int& timestamp, unsigned int& playoutTimestamp,
186 unsigned int* jitter = NULL, unsigned short* fractionLost = NULL) = 0;
187
188 // Gets RTP statistics for a specific |channel|.
189 virtual int GetRTPStatistics(
190 int channel, unsigned int& averageJitterMs, unsigned int& maxJitterMs,
191 unsigned int& discardedPackets) = 0;
192
193 // Gets RTCP statistics for a specific |channel|.
194 virtual int GetRTCPStatistics(int channel, CallStatistics& stats) = 0;
195
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000196 // Gets the report block parts of the last received RTCP Sender Report (SR),
197 // or RTCP Receiver Report (RR) on a specified |channel|. Each vector
198 // element also contains the SSRC of the sender in addition to a report
199 // block.
200 virtual int GetRemoteRTCPReportBlocks(
201 int channel, std::vector<ReportBlock>* receive_blocks) = 0;
202
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000203 // Sets the Redundant Coding (RED) status on a specific |channel|.
204 // TODO(minyue): Make SetREDStatus() pure virtual when fakewebrtcvoiceengine
205 // in talk is ready.
206 virtual int SetREDStatus(
207 int channel, bool enable, int redPayloadtype = -1) { return -1; }
208
209 // Gets the RED status on a specific |channel|.
210 // TODO(minyue): Make GetREDStatus() pure virtual when fakewebrtcvoiceengine
211 // in talk is ready.
212 virtual int GetREDStatus(
213 int channel, bool& enabled, int& redPayloadtype) { return -1; }
214
niklase@google.com470e71d2011-07-07 08:21:25 +0000215 // Sets the Forward Error Correction (FEC) status on a specific |channel|.
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000216 // TODO(minyue): Remove SetFECStatus() when SetFECStatus() is replaced by
217 // SetREDStatus() in fakewebrtcvoiceengine.
niklase@google.com470e71d2011-07-07 08:21:25 +0000218 virtual int SetFECStatus(
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000219 int channel, bool enable, int redPayloadtype = -1) {
220 return SetREDStatus(channel, enable, redPayloadtype);
221 };
niklase@google.com470e71d2011-07-07 08:21:25 +0000222
223 // Gets the FEC status on a specific |channel|.
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000224 // TODO(minyue): Remove GetFECStatus() when GetFECStatus() is replaced by
225 // GetREDStatus() in fakewebrtcvoiceengine.
niklase@google.com470e71d2011-07-07 08:21:25 +0000226 virtual int GetFECStatus(
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000227 int channel, bool& enabled, int& redPayloadtype) {
228 return SetREDStatus(channel, enabled, redPayloadtype);
229 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
niklas.enbom@webrtc.orgb35d2e32013-05-31 21:13:52 +0000231 // This function enables Negative Acknowledgment (NACK) using RTCP,
232 // implemented based on RFC 4585. NACK retransmits RTP packets if lost on
233 // the network. This creates a lossless transport at the expense of delay.
234 // If using NACK, NACK should be enabled on both endpoints in a call.
235 virtual int SetNACKStatus(int channel,
236 bool enable,
237 int maxNoPackets) = 0;
238
niklase@google.com470e71d2011-07-07 08:21:25 +0000239 // Enables capturing of RTP packets to a binary file on a specific
240 // |channel| and for a given |direction|. The file can later be replayed
mflodman@webrtc.org3e820e52012-03-23 09:41:44 +0000241 // using e.g. RTP Tools rtpplay since the binary file format is
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 // compatible with the rtpdump format.
243 virtual int StartRTPDump(
244 int channel, const char fileNameUTF8[1024],
245 RTPDirections direction = kRtpIncoming) = 0;
246
247 // Disables capturing of RTP packets to a binary file on a specific
248 // |channel| and for a given |direction|.
249 virtual int StopRTPDump(
250 int channel, RTPDirections direction = kRtpIncoming) = 0;
251
252 // Gets the the current RTP capturing state for the specified
253 // |channel| and |direction|.
254 virtual int RTPDumpIsActive(
255 int channel, RTPDirections direction = kRtpIncoming) = 0;
256
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000257 // Sets video engine channel to receive incoming audio packets for
258 // aggregated bandwidth estimation. Takes ownership of the ViENetwork
259 // interface.
260 virtual int SetVideoEngineBWETarget(int channel, ViENetwork* vie_network,
261 int video_channel) {
262 return 0;
263 }
henrika@webrtc.orgb7a91fa2014-02-19 08:58:08 +0000264
henrika@webrtc.org66021e02014-05-12 08:53:27 +0000265 // Will be removed. Don't use.
266 virtual int RegisterRTPObserver(int channel,
267 VoERTPObserver& observer) { return -1; };
268 virtual int DeRegisterRTPObserver(int channel) { return -1; };
269 virtual int RegisterRTCPObserver(
270 int channel, VoERTCPObserver& observer) { return -1; };
271 virtual int DeRegisterRTCPObserver(int channel) { return -1; };
272 virtual int GetRemoteCSRCs(int channel,
273 unsigned int arrCSRC[15]) { return -1; };
274 virtual int InsertExtraRTPPacket(
275 int channel, unsigned char payloadType, bool markerBit,
276 const char* payloadData, unsigned short payloadSize) { return -1; };
277 virtual int GetRemoteRTCPSenderInfo(
278 int channel, SenderInfo* sender_info) { return -1; };
279 virtual int SendApplicationDefinedRTCPPacket(
280 int channel, unsigned char subType, unsigned int name,
281 const char* data, unsigned short dataLengthInBytes) { return -1; };
282 virtual int GetLastRemoteTimeStamp(int channel,
283 uint32_t* lastRemoteTimeStamp) { return -1; };
284
niklase@google.com470e71d2011-07-07 08:21:25 +0000285protected:
286 VoERTP_RTCP() {}
287 virtual ~VoERTP_RTCP() {}
288};
289
290} // namespace webrtc
291
292#endif // #ifndef WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H