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