niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 0975d21 | 2012-03-06 20:59:13 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 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 | // 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.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 19 | // - Writing RTP and RTCP packets to binary files for off-line analysis of |
| 20 | // the call quality. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 21 | // |
| 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.org | 8a2fc88 | 2012-08-22 08:53:55 | [diff] [blame] | 42 | #include <vector> |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 | [diff] [blame] | 43 | #include "webrtc/common_types.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 44 | |
| 45 | namespace webrtc { |
| 46 | |
| 47 | class VoiceEngine; |
| 48 | |
| 49 | // VoERTPObserver |
| 50 | class WEBRTC_DLLEXPORT VoERTPObserver |
| 51 | { |
| 52 | public: |
| 53 | virtual void OnIncomingCSRCChanged( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 | [diff] [blame] | 54 | int channel, unsigned int CSRC, bool added) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 55 | |
| 56 | virtual void OnIncomingSSRCChanged( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 | [diff] [blame] | 57 | int channel, unsigned int SSRC) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 58 | |
| 59 | protected: |
| 60 | virtual ~VoERTPObserver() {} |
| 61 | }; |
| 62 | |
| 63 | // VoERTCPObserver |
| 64 | class WEBRTC_DLLEXPORT VoERTCPObserver |
| 65 | { |
| 66 | public: |
| 67 | virtual void OnApplicationDataReceived( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 | [diff] [blame] | 68 | int channel, unsigned char subType, |
| 69 | unsigned int name, const unsigned char* data, |
| 70 | unsigned short dataLengthInBytes) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 71 | |
| 72 | protected: |
| 73 | virtual ~VoERTCPObserver() {} |
| 74 | }; |
| 75 | |
| 76 | // CallStatistics |
| 77 | struct 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.org | 8a2fc88 | 2012-08-22 08:53:55 | [diff] [blame] | 90 | // See section 6.4.1 in http://www.ietf.org/rfc/rfc3550.txt for details. |
| 91 | struct 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. |
| 100 | struct 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.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 111 | // VoERTP_RTCP |
| 112 | class WEBRTC_DLLEXPORT VoERTP_RTCP |
| 113 | { |
| 114 | public: |
| 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|. |
| 155 | virtual int SetRTPAudioLevelIndicationStatus( |
| 156 | int channel, bool enable, unsigned char ID = 1) = 0; |
| 157 | |
| 158 | // Sets the status of rtp-audio-level-indication on a specific |channel|. |
| 159 | virtual int GetRTPAudioLevelIndicationStatus( |
| 160 | int channel, bool& enabled, unsigned char& ID) = 0; |
| 161 | |
| 162 | // Gets the CSRCs of the incoming RTP packets. |
| 163 | virtual int GetRemoteCSRCs(int channel, unsigned int arrCSRC[15]) = 0; |
| 164 | |
| 165 | // Sets the RTCP status on a specific |channel|. |
| 166 | virtual int SetRTCPStatus(int channel, bool enable) = 0; |
| 167 | |
| 168 | // Gets the RTCP status on a specific |channel|. |
| 169 | virtual int GetRTCPStatus(int channel, bool& enabled) = 0; |
| 170 | |
| 171 | // Sets the canonical name (CNAME) parameter for RTCP reports on a |
| 172 | // specific |channel|. |
| 173 | virtual int SetRTCP_CNAME(int channel, const char cName[256]) = 0; |
| 174 | |
| 175 | // Gets the canonical name (CNAME) parameter for RTCP reports on a |
| 176 | // specific |channel|. |
| 177 | virtual int GetRTCP_CNAME(int channel, char cName[256]) = 0; |
| 178 | |
| 179 | // Gets the canonical name (CNAME) parameter for incoming RTCP reports |
| 180 | // on a specific channel. |
| 181 | virtual int GetRemoteRTCP_CNAME(int channel, char cName[256]) = 0; |
| 182 | |
| 183 | // Gets RTCP data from incoming RTCP Sender Reports. |
| 184 | virtual int GetRemoteRTCPData( |
| 185 | int channel, unsigned int& NTPHigh, unsigned int& NTPLow, |
| 186 | unsigned int& timestamp, unsigned int& playoutTimestamp, |
| 187 | unsigned int* jitter = NULL, unsigned short* fractionLost = NULL) = 0; |
| 188 | |
| 189 | // Gets RTP statistics for a specific |channel|. |
| 190 | virtual int GetRTPStatistics( |
| 191 | int channel, unsigned int& averageJitterMs, unsigned int& maxJitterMs, |
| 192 | unsigned int& discardedPackets) = 0; |
| 193 | |
| 194 | // Gets RTCP statistics for a specific |channel|. |
| 195 | virtual int GetRTCPStatistics(int channel, CallStatistics& stats) = 0; |
| 196 | |
henrika@webrtc.org | 8a2fc88 | 2012-08-22 08:53:55 | [diff] [blame] | 197 | // Gets the sender info part of the last received RTCP Sender Report (SR) |
| 198 | // on a specified |channel|. |
| 199 | virtual int GetRemoteRTCPSenderInfo( |
| 200 | int channel, SenderInfo* sender_info) = 0; |
| 201 | |
| 202 | // Gets the report block parts of the last received RTCP Sender Report (SR), |
| 203 | // or RTCP Receiver Report (RR) on a specified |channel|. Each vector |
| 204 | // element also contains the SSRC of the sender in addition to a report |
| 205 | // block. |
| 206 | virtual int GetRemoteRTCPReportBlocks( |
| 207 | int channel, std::vector<ReportBlock>* receive_blocks) = 0; |
| 208 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 209 | // Sends an RTCP APP packet on a specific |channel|. |
| 210 | virtual int SendApplicationDefinedRTCPPacket( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 | [diff] [blame] | 211 | int channel, unsigned char subType, unsigned int name, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 212 | const char* data, unsigned short dataLengthInBytes) = 0; |
| 213 | |
| 214 | // Sets the Forward Error Correction (FEC) status on a specific |channel|. |
| 215 | virtual int SetFECStatus( |
| 216 | int channel, bool enable, int redPayloadtype = -1) = 0; |
| 217 | |
| 218 | // Gets the FEC status on a specific |channel|. |
| 219 | virtual int GetFECStatus( |
| 220 | int channel, bool& enabled, int& redPayloadtype) = 0; |
| 221 | |
niklas.enbom@webrtc.org | b35d2e3 | 2013-05-31 21:13:52 | [diff] [blame] | 222 | // This function enables Negative Acknowledgment (NACK) using RTCP, |
| 223 | // implemented based on RFC 4585. NACK retransmits RTP packets if lost on |
| 224 | // the network. This creates a lossless transport at the expense of delay. |
| 225 | // If using NACK, NACK should be enabled on both endpoints in a call. |
| 226 | virtual int SetNACKStatus(int channel, |
| 227 | bool enable, |
| 228 | int maxNoPackets) = 0; |
| 229 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 230 | // Enables capturing of RTP packets to a binary file on a specific |
| 231 | // |channel| and for a given |direction|. The file can later be replayed |
mflodman@webrtc.org | 3e820e5 | 2012-03-23 09:41:44 | [diff] [blame] | 232 | // using e.g. RTP Tools rtpplay since the binary file format is |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 233 | // compatible with the rtpdump format. |
| 234 | virtual int StartRTPDump( |
| 235 | int channel, const char fileNameUTF8[1024], |
| 236 | RTPDirections direction = kRtpIncoming) = 0; |
| 237 | |
| 238 | // Disables capturing of RTP packets to a binary file on a specific |
| 239 | // |channel| and for a given |direction|. |
| 240 | virtual int StopRTPDump( |
| 241 | int channel, RTPDirections direction = kRtpIncoming) = 0; |
| 242 | |
| 243 | // Gets the the current RTP capturing state for the specified |
| 244 | // |channel| and |direction|. |
| 245 | virtual int RTPDumpIsActive( |
| 246 | int channel, RTPDirections direction = kRtpIncoming) = 0; |
| 247 | |
roosa@google.com | 0870f02 | 2012-12-12 21:31:41 | [diff] [blame] | 248 | // Gets the timestamp of the last RTP packet received by |channel|. |
| 249 | virtual int GetLastRemoteTimeStamp(int channel, |
| 250 | uint32_t* lastRemoteTimeStamp) = 0; |
| 251 | |
henrika@webrtc.org | b7a91fa | 2014-02-19 08:58:08 | [diff] [blame] | 252 | // Don't use. To be removed. |
| 253 | virtual int InsertExtraRTPPacket( |
| 254 | int channel, unsigned char payloadType, bool markerBit, |
| 255 | const char* payloadData, unsigned short payloadSize) { return -1; }; |
| 256 | |
| 257 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 258 | protected: |
| 259 | VoERTP_RTCP() {} |
| 260 | virtual ~VoERTP_RTCP() {} |
| 261 | }; |
| 262 | |
| 263 | } // namespace webrtc |
| 264 | |
| 265 | #endif // #ifndef WEBRTC_VOICE_ENGINE_VOE_RTP_RTCP_H |