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