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