blob: 39aeba2f47ebae3e1659ad4d85cc5801e0347c3b [file] [log] [blame]
Henrik Kjellanderff761fb2015-11-04 08:31:52 +01001/*
2 * Copyright (c) 2012 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_INCLUDE_RTP_RTCP_H_
12#define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_H_
13
14#include <set>
15#include <vector>
16
17#include "webrtc/modules/include/module.h"
18#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19
20namespace webrtc {
21// Forward declarations.
22class ReceiveStatistics;
23class RemoteBitrateEstimator;
24class RtpReceiver;
25class Transport;
26namespace rtcp {
27class TransportFeedback;
28}
29
30class RtpRtcp : public Module {
31 public:
32 struct Configuration {
33 Configuration();
34
35 /* id - Unique identifier of this RTP/RTCP module object
36 * audio - True for a audio version of the RTP/RTCP module
37 * object false will create a video version
38 * clock - The clock to use to read time. If NULL object
39 * will be using the system clock.
40 * incoming_data - Callback object that will receive the incoming
41 * data. May not be NULL; default callback will do
42 * nothing.
43 * incoming_messages - Callback object that will receive the incoming
44 * RTP messages. May not be NULL; default callback
45 * will do nothing.
46 * outgoing_transport - Transport object that will be called when packets
47 * are ready to be sent out on the network
48 * intra_frame_callback - Called when the receiver request a intra frame.
49 * bandwidth_callback - Called when we receive a changed estimate from
50 * the receiver of out stream.
51 * audio_messages - Telephone events. May not be NULL; default
52 * callback will do nothing.
53 * remote_bitrate_estimator - Estimates the bandwidth available for a set of
54 * streams from the same client.
55 * paced_sender - Spread any bursts of packets into smaller
56 * bursts to minimize packet loss.
57 */
58 bool audio;
59 bool receiver_only;
60 Clock* clock;
61 ReceiveStatistics* receive_statistics;
62 Transport* outgoing_transport;
63 RtcpIntraFrameObserver* intra_frame_callback;
64 RtcpBandwidthObserver* bandwidth_callback;
65 TransportFeedbackObserver* transport_feedback_callback;
66 RtcpRttStats* rtt_stats;
67 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer;
68 RtpAudioFeedback* audio_messages;
69 RemoteBitrateEstimator* remote_bitrate_estimator;
70 RtpPacketSender* paced_sender;
71 TransportSequenceNumberAllocator* transport_sequence_number_allocator;
72 BitrateStatisticsObserver* send_bitrate_observer;
73 FrameCountObserver* send_frame_count_observer;
74 SendSideDelayObserver* send_side_delay_observer;
75 };
76
77 /*
78 * Create a RTP/RTCP module object using the system clock.
79 *
80 * configuration - Configuration of the RTP/RTCP module.
81 */
82 static RtpRtcp* CreateRtpRtcp(const RtpRtcp::Configuration& configuration);
83
84 /**************************************************************************
85 *
86 * Receiver functions
87 *
88 ***************************************************************************/
89
90 virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet,
91 size_t incoming_packet_length) = 0;
92
93 virtual void SetRemoteSSRC(uint32_t ssrc) = 0;
94
95 /**************************************************************************
96 *
97 * Sender
98 *
99 ***************************************************************************/
100
101 /*
102 * set MTU
103 *
104 * size - Max transfer unit in bytes, default is 1500
105 *
106 * return -1 on failure else 0
107 */
108 virtual int32_t SetMaxTransferUnit(uint16_t size) = 0;
109
110 /*
111 * set transtport overhead
112 * default is IPv4 and UDP with no encryption
113 *
114 * TCP - true for TCP false UDP
115 * IPv6 - true for IP version 6 false for version 4
116 * authenticationOverhead - number of bytes to leave for an
117 * authentication header
118 *
119 * return -1 on failure else 0
120 */
121 virtual int32_t SetTransportOverhead(
122 bool TCP,
123 bool IPV6,
124 uint8_t authenticationOverhead = 0) = 0;
125
126 /*
127 * Get max payload length
128 *
129 * A combination of the configuration MaxTransferUnit and
130 * TransportOverhead.
131 * Does not account FEC/ULP/RED overhead if FEC is enabled.
132 * Does not account for RTP headers
133 */
134 virtual uint16_t MaxPayloadLength() const = 0;
135
136 /*
137 * Get max data payload length
138 *
139 * A combination of the configuration MaxTransferUnit, headers and
140 * TransportOverhead.
141 * Takes into account FEC/ULP/RED overhead if FEC is enabled.
142 * Takes into account RTP headers
143 */
144 virtual uint16_t MaxDataPayloadLength() const = 0;
145
146 /*
147 * set codec name and payload type
148 *
149 * return -1 on failure else 0
150 */
151 virtual int32_t RegisterSendPayload(
152 const CodecInst& voiceCodec) = 0;
153
154 /*
155 * set codec name and payload type
156 *
157 * return -1 on failure else 0
158 */
159 virtual int32_t RegisterSendPayload(
160 const VideoCodec& videoCodec) = 0;
161
162 /*
163 * Unregister a send payload
164 *
165 * payloadType - payload type of codec
166 *
167 * return -1 on failure else 0
168 */
169 virtual int32_t DeRegisterSendPayload(int8_t payloadType) = 0;
170
171 /*
172 * (De)register RTP header extension type and id.
173 *
174 * return -1 on failure else 0
175 */
176 virtual int32_t RegisterSendRtpHeaderExtension(RTPExtensionType type,
177 uint8_t id) = 0;
178
179 virtual int32_t DeregisterSendRtpHeaderExtension(RTPExtensionType type) = 0;
180
181 /*
182 * get start timestamp
183 */
184 virtual uint32_t StartTimestamp() const = 0;
185
186 /*
187 * configure start timestamp, default is a random number
188 *
189 * timestamp - start timestamp
190 */
191 virtual void SetStartTimestamp(uint32_t timestamp) = 0;
192
193 /*
194 * Get SequenceNumber
195 */
196 virtual uint16_t SequenceNumber() const = 0;
197
198 /*
199 * Set SequenceNumber, default is a random number
200 */
201 virtual void SetSequenceNumber(uint16_t seq) = 0;
202
203 // Returns true if the ssrc matched this module, false otherwise.
204 virtual bool SetRtpStateForSsrc(uint32_t ssrc,
205 const RtpState& rtp_state) = 0;
206 virtual bool GetRtpStateForSsrc(uint32_t ssrc, RtpState* rtp_state) = 0;
207
208 /*
209 * Get SSRC
210 */
211 virtual uint32_t SSRC() const = 0;
212
213 /*
214 * configure SSRC, default is a random number
215 */
216 virtual void SetSSRC(uint32_t ssrc) = 0;
217
218 /*
219 * Set CSRC
220 *
221 * csrcs - vector of CSRCs
222 */
223 virtual void SetCsrcs(const std::vector<uint32_t>& csrcs) = 0;
224
225 /*
226 * Turn on/off sending RTX (RFC 4588). The modes can be set as a combination
227 * of values of the enumerator RtxMode.
228 */
229 virtual void SetRtxSendStatus(int modes) = 0;
230
231 /*
232 * Get status of sending RTX (RFC 4588). The returned value can be
233 * a combination of values of the enumerator RtxMode.
234 */
235 virtual int RtxSendStatus() const = 0;
236
237 // Sets the SSRC to use when sending RTX packets. This doesn't enable RTX,
238 // only the SSRC is set.
239 virtual void SetRtxSsrc(uint32_t ssrc) = 0;
240
241 // Sets the payload type to use when sending RTX packets. Note that this
242 // doesn't enable RTX, only the payload type is set.
243 virtual void SetRtxSendPayloadType(int payload_type,
244 int associated_payload_type) = 0;
245
246 // Gets the payload type pair of (RTX, associated) to use when sending RTX
247 // packets.
248 virtual std::pair<int, int> RtxSendPayloadType() const = 0;
249
250 /*
251 * sends kRtcpByeCode when going from true to false
252 *
253 * sending - on/off
254 *
255 * return -1 on failure else 0
256 */
257 virtual int32_t SetSendingStatus(bool sending) = 0;
258
259 /*
260 * get send status
261 */
262 virtual bool Sending() const = 0;
263
264 /*
265 * Starts/Stops media packets, on by default
266 *
267 * sending - on/off
268 */
269 virtual void SetSendingMediaStatus(bool sending) = 0;
270
271 /*
272 * get send status
273 */
274 virtual bool SendingMedia() const = 0;
275
276 /*
277 * get sent bitrate in Kbit/s
278 */
279 virtual void BitrateSent(uint32_t* totalRate,
280 uint32_t* videoRate,
281 uint32_t* fecRate,
282 uint32_t* nackRate) const = 0;
283
284 /*
285 * Used by the codec module to deliver a video or audio frame for
286 * packetization.
287 *
288 * frameType - type of frame to send
289 * payloadType - payload type of frame to send
290 * timestamp - timestamp of frame to send
291 * payloadData - payload buffer of frame to send
292 * payloadSize - size of payload buffer to send
293 * fragmentation - fragmentation offset data for fragmented frames such
294 * as layers or RED
295 *
296 * return -1 on failure else 0
297 */
298 virtual int32_t SendOutgoingData(
299 FrameType frameType,
300 int8_t payloadType,
301 uint32_t timeStamp,
302 int64_t capture_time_ms,
303 const uint8_t* payloadData,
304 size_t payloadSize,
305 const RTPFragmentationHeader* fragmentation = NULL,
306 const RTPVideoHeader* rtpVideoHdr = NULL) = 0;
307
308 virtual bool TimeToSendPacket(uint32_t ssrc,
309 uint16_t sequence_number,
310 int64_t capture_time_ms,
311 bool retransmission) = 0;
312
313 virtual size_t TimeToSendPadding(size_t bytes) = 0;
314
315 // Called on generation of new statistics after an RTP send.
316 virtual void RegisterSendChannelRtpStatisticsCallback(
317 StreamDataCountersCallback* callback) = 0;
318 virtual StreamDataCountersCallback*
319 GetSendChannelRtpStatisticsCallback() const = 0;
320
321 /**************************************************************************
322 *
323 * RTCP
324 *
325 ***************************************************************************/
326
327 /*
328 * Get RTCP status
329 */
330 virtual RtcpMode RTCP() const = 0;
331
332 /*
333 * configure RTCP status i.e on(compound or non- compound)/off
334 *
335 * method - RTCP method to use
336 */
337 virtual void SetRTCPStatus(RtcpMode method) = 0;
338
339 /*
340 * Set RTCP CName (i.e unique identifier)
341 *
342 * return -1 on failure else 0
343 */
344 virtual int32_t SetCNAME(const char* c_name) = 0;
345
346 /*
347 * Get remote CName
348 *
349 * return -1 on failure else 0
350 */
351 virtual int32_t RemoteCNAME(uint32_t remoteSSRC,
352 char cName[RTCP_CNAME_SIZE]) const = 0;
353
354 /*
355 * Get remote NTP
356 *
357 * return -1 on failure else 0
358 */
359 virtual int32_t RemoteNTP(
360 uint32_t *ReceivedNTPsecs,
361 uint32_t *ReceivedNTPfrac,
362 uint32_t *RTCPArrivalTimeSecs,
363 uint32_t *RTCPArrivalTimeFrac,
364 uint32_t *rtcp_timestamp) const = 0;
365
366 /*
367 * AddMixedCNAME
368 *
369 * return -1 on failure else 0
370 */
371 virtual int32_t AddMixedCNAME(uint32_t SSRC, const char* c_name) = 0;
372
373 /*
374 * RemoveMixedCNAME
375 *
376 * return -1 on failure else 0
377 */
378 virtual int32_t RemoveMixedCNAME(uint32_t SSRC) = 0;
379
380 /*
381 * Get RoundTripTime
382 *
383 * return -1 on failure else 0
384 */
385 virtual int32_t RTT(uint32_t remoteSSRC,
386 int64_t* RTT,
387 int64_t* avgRTT,
388 int64_t* minRTT,
389 int64_t* maxRTT) const = 0;
390
391 /*
392 * Force a send of a RTCP packet
393 * periodic SR and RR are triggered via the process function
394 *
395 * return -1 on failure else 0
396 */
397 virtual int32_t SendRTCP(RTCPPacketType rtcpPacketType) = 0;
398
399 /*
400 * Force a send of a RTCP packet with more than one packet type.
401 * periodic SR and RR are triggered via the process function
402 *
403 * return -1 on failure else 0
404 */
405 virtual int32_t SendCompoundRTCP(
406 const std::set<RTCPPacketType>& rtcpPacketTypes) = 0;
407
408 /*
409 * Good state of RTP receiver inform sender
410 */
411 virtual int32_t SendRTCPReferencePictureSelection(
412 const uint64_t pictureID) = 0;
413
414 /*
415 * Send a RTCP Slice Loss Indication (SLI)
416 * 6 least significant bits of pictureID
417 */
418 virtual int32_t SendRTCPSliceLossIndication(uint8_t pictureID) = 0;
419
420 /*
421 * Statistics of the amount of data sent
422 *
423 * return -1 on failure else 0
424 */
425 virtual int32_t DataCountersRTP(
426 size_t* bytesSent,
427 uint32_t* packetsSent) const = 0;
428
429 /*
430 * Get send statistics for the RTP and RTX stream.
431 */
432 virtual void GetSendStreamDataCounters(
433 StreamDataCounters* rtp_counters,
434 StreamDataCounters* rtx_counters) const = 0;
435
436 /*
437 * Get packet loss statistics for the RTP stream.
438 */
439 virtual void GetRtpPacketLossStats(
440 bool outgoing,
441 uint32_t ssrc,
442 struct RtpPacketLossStats* loss_stats) const = 0;
443
444 /*
445 * Get received RTCP sender info
446 *
447 * return -1 on failure else 0
448 */
449 virtual int32_t RemoteRTCPStat(RTCPSenderInfo* senderInfo) = 0;
450
451 /*
452 * Get received RTCP report block
453 *
454 * return -1 on failure else 0
455 */
456 virtual int32_t RemoteRTCPStat(
457 std::vector<RTCPReportBlock>* receiveBlocks) const = 0;
458
459 /*
460 * (APP) Application specific data
461 *
462 * return -1 on failure else 0
463 */
464 virtual int32_t SetRTCPApplicationSpecificData(uint8_t subType,
465 uint32_t name,
466 const uint8_t* data,
467 uint16_t length) = 0;
468 /*
469 * (XR) VOIP metric
470 *
471 * return -1 on failure else 0
472 */
473 virtual int32_t SetRTCPVoIPMetrics(
474 const RTCPVoIPMetric* VoIPMetric) = 0;
475
476 /*
477 * (XR) Receiver Reference Time Report
478 */
479 virtual void SetRtcpXrRrtrStatus(bool enable) = 0;
480
481 virtual bool RtcpXrRrtrStatus() const = 0;
482
483 /*
484 * (REMB) Receiver Estimated Max Bitrate
485 */
486 virtual bool REMB() const = 0;
487
488 virtual void SetREMBStatus(bool enable) = 0;
489
490 virtual void SetREMBData(uint32_t bitrate,
491 const std::vector<uint32_t>& ssrcs) = 0;
492
493 /*
494 * (TMMBR) Temporary Max Media Bit Rate
495 */
496 virtual bool TMMBR() const = 0;
497
498 virtual void SetTMMBRStatus(bool enable) = 0;
499
500 /*
501 * (NACK)
502 */
503
504 /*
505 * TODO(holmer): Propagate this API to VideoEngine.
506 * Returns the currently configured selective retransmission settings.
507 */
508 virtual int SelectiveRetransmissions() const = 0;
509
510 /*
511 * TODO(holmer): Propagate this API to VideoEngine.
512 * Sets the selective retransmission settings, which will decide which
513 * packets will be retransmitted if NACKed. Settings are constructed by
514 * combining the constants in enum RetransmissionMode with bitwise OR.
515 * All packets are retransmitted if kRetransmitAllPackets is set, while no
516 * packets are retransmitted if kRetransmitOff is set.
517 * By default all packets except FEC packets are retransmitted. For VP8
518 * with temporal scalability only base layer packets are retransmitted.
519 *
520 * Returns -1 on failure, otherwise 0.
521 */
522 virtual int SetSelectiveRetransmissions(uint8_t settings) = 0;
523
524 /*
525 * Send a Negative acknowledgement packet
526 *
527 * return -1 on failure else 0
528 */
529 virtual int32_t SendNACK(const uint16_t* nackList, uint16_t size) = 0;
530
531 /*
532 * Store the sent packets, needed to answer to a Negative acknowledgement
533 * requests
534 */
535 virtual void SetStorePacketsStatus(bool enable, uint16_t numberToStore) = 0;
536
537 // Returns true if the module is configured to store packets.
538 virtual bool StorePackets() const = 0;
539
540 // Called on receipt of RTCP report block from remote side.
541 virtual void RegisterRtcpStatisticsCallback(
542 RtcpStatisticsCallback* callback) = 0;
543 virtual RtcpStatisticsCallback*
544 GetRtcpStatisticsCallback() = 0;
545 // BWE feedback packets.
546 virtual bool SendFeedbackPacket(const rtcp::TransportFeedback& packet) = 0;
547
548 /**************************************************************************
549 *
550 * Audio
551 *
552 ***************************************************************************/
553
554 /*
555 * set audio packet size, used to determine when it's time to send a DTMF
556 * packet in silence (CNG)
557 *
558 * return -1 on failure else 0
559 */
560 virtual int32_t SetAudioPacketSize(uint16_t packetSizeSamples) = 0;
561
562 /*
563 * Send a TelephoneEvent tone using RFC 2833 (4733)
564 *
565 * return -1 on failure else 0
566 */
567 virtual int32_t SendTelephoneEventOutband(uint8_t key,
568 uint16_t time_ms,
569 uint8_t level) = 0;
570
571 /*
572 * Set payload type for Redundant Audio Data RFC 2198
573 *
574 * return -1 on failure else 0
575 */
576 virtual int32_t SetSendREDPayloadType(int8_t payloadType) = 0;
577
578 /*
579 * Get payload type for Redundant Audio Data RFC 2198
580 *
581 * return -1 on failure else 0
582 */
583 virtual int32_t SendREDPayloadType(
584 int8_t& payloadType) const = 0;
585
586 /*
587 * Store the audio level in dBov for header-extension-for-audio-level-
588 * indication.
589 * This API shall be called before transmision of an RTP packet to ensure
590 * that the |level| part of the extended RTP header is updated.
591 *
592 * return -1 on failure else 0.
593 */
594 virtual int32_t SetAudioLevel(uint8_t level_dBov) = 0;
595
596 /**************************************************************************
597 *
598 * Video
599 *
600 ***************************************************************************/
601
602 /*
603 * Set the target send bitrate
604 */
605 virtual void SetTargetSendBitrate(uint32_t bitrate_bps) = 0;
606
607 /*
608 * Turn on/off generic FEC
609 */
610 virtual void SetGenericFECStatus(bool enable,
611 uint8_t payload_type_red,
612 uint8_t payload_type_fec) = 0;
613
614 /*
615 * Get generic FEC setting
616 */
617 virtual void GenericFECStatus(bool& enable,
618 uint8_t& payloadTypeRED,
619 uint8_t& payloadTypeFEC) = 0;
620
621
622 virtual int32_t SetFecParameters(
623 const FecProtectionParams* delta_params,
624 const FecProtectionParams* key_params) = 0;
625
626 /*
627 * Set method for requestion a new key frame
628 *
629 * return -1 on failure else 0
630 */
631 virtual int32_t SetKeyFrameRequestMethod(KeyFrameRequestMethod method) = 0;
632
633 /*
634 * send a request for a keyframe
635 *
636 * return -1 on failure else 0
637 */
638 virtual int32_t RequestKeyFrame() = 0;
639};
640} // namespace webrtc
641#endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_H_