blob: 0dd3a89bd719186069978d5677fd7d653f263540 [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;
terelius429c3452016-01-21 05:42:04 -080030class RtcEventLog;
31
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 */
419 virtual int32_t SendRTCPReferencePictureSelection(
420 const uint64_t pictureID) = 0;
421
422 /*
423 * Send a RTCP Slice Loss Indication (SLI)
424 * 6 least significant bits of pictureID
425 */
426 virtual int32_t SendRTCPSliceLossIndication(uint8_t pictureID) = 0;
427
428 /*
429 * Statistics of the amount of data sent
430 *
431 * return -1 on failure else 0
432 */
433 virtual int32_t DataCountersRTP(
434 size_t* bytesSent,
435 uint32_t* packetsSent) const = 0;
436
437 /*
438 * Get send statistics for the RTP and RTX stream.
439 */
440 virtual void GetSendStreamDataCounters(
441 StreamDataCounters* rtp_counters,
442 StreamDataCounters* rtx_counters) const = 0;
443
444 /*
445 * Get packet loss statistics for the RTP stream.
446 */
447 virtual void GetRtpPacketLossStats(
448 bool outgoing,
449 uint32_t ssrc,
450 struct RtpPacketLossStats* loss_stats) const = 0;
451
452 /*
453 * Get received RTCP sender info
454 *
455 * return -1 on failure else 0
456 */
457 virtual int32_t RemoteRTCPStat(RTCPSenderInfo* senderInfo) = 0;
458
459 /*
460 * Get received RTCP report block
461 *
462 * return -1 on failure else 0
463 */
464 virtual int32_t RemoteRTCPStat(
465 std::vector<RTCPReportBlock>* receiveBlocks) const = 0;
466
467 /*
468 * (APP) Application specific data
469 *
470 * return -1 on failure else 0
471 */
472 virtual int32_t SetRTCPApplicationSpecificData(uint8_t subType,
473 uint32_t name,
474 const uint8_t* data,
475 uint16_t length) = 0;
476 /*
477 * (XR) VOIP metric
478 *
479 * return -1 on failure else 0
480 */
481 virtual int32_t SetRTCPVoIPMetrics(
482 const RTCPVoIPMetric* VoIPMetric) = 0;
483
484 /*
485 * (XR) Receiver Reference Time Report
486 */
487 virtual void SetRtcpXrRrtrStatus(bool enable) = 0;
488
489 virtual bool RtcpXrRrtrStatus() const = 0;
490
491 /*
492 * (REMB) Receiver Estimated Max Bitrate
493 */
494 virtual bool REMB() const = 0;
495
496 virtual void SetREMBStatus(bool enable) = 0;
497
498 virtual void SetREMBData(uint32_t bitrate,
499 const std::vector<uint32_t>& ssrcs) = 0;
500
501 /*
502 * (TMMBR) Temporary Max Media Bit Rate
503 */
504 virtual bool TMMBR() const = 0;
505
506 virtual void SetTMMBRStatus(bool enable) = 0;
507
508 /*
509 * (NACK)
510 */
511
512 /*
513 * TODO(holmer): Propagate this API to VideoEngine.
514 * Returns the currently configured selective retransmission settings.
515 */
516 virtual int SelectiveRetransmissions() const = 0;
517
518 /*
519 * TODO(holmer): Propagate this API to VideoEngine.
520 * Sets the selective retransmission settings, which will decide which
521 * packets will be retransmitted if NACKed. Settings are constructed by
522 * combining the constants in enum RetransmissionMode with bitwise OR.
523 * All packets are retransmitted if kRetransmitAllPackets is set, while no
524 * packets are retransmitted if kRetransmitOff is set.
525 * By default all packets except FEC packets are retransmitted. For VP8
526 * with temporal scalability only base layer packets are retransmitted.
527 *
528 * Returns -1 on failure, otherwise 0.
529 */
530 virtual int SetSelectiveRetransmissions(uint8_t settings) = 0;
531
532 /*
533 * Send a Negative acknowledgement packet
534 *
535 * return -1 on failure else 0
536 */
philipel83f831a2016-03-12 03:30:23 -0800537 // TODO(philipel): Deprecate this and start using SendNack instead,
538 // mostly because we want a function that actually send
539 // NACK for the specified packets.
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100540 virtual int32_t SendNACK(const uint16_t* nackList, uint16_t size) = 0;
541
542 /*
philipel83f831a2016-03-12 03:30:23 -0800543 * Send NACK for the packets specified.
mflodmandc7d0d22016-05-06 05:32:22 -0700544 *
545 * Note: This assumes the caller keeps track of timing and doesn't rely on
546 * the RTP module to do this.
philipel83f831a2016-03-12 03:30:23 -0800547 */
548 virtual void SendNack(const std::vector<uint16_t>& sequence_numbers) = 0;
549
550 /*
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100551 * Store the sent packets, needed to answer to a Negative acknowledgement
552 * requests
553 */
554 virtual void SetStorePacketsStatus(bool enable, uint16_t numberToStore) = 0;
555
556 // Returns true if the module is configured to store packets.
557 virtual bool StorePackets() const = 0;
558
559 // Called on receipt of RTCP report block from remote side.
560 virtual void RegisterRtcpStatisticsCallback(
561 RtcpStatisticsCallback* callback) = 0;
562 virtual RtcpStatisticsCallback*
563 GetRtcpStatisticsCallback() = 0;
564 // BWE feedback packets.
565 virtual bool SendFeedbackPacket(const rtcp::TransportFeedback& packet) = 0;
566
567 /**************************************************************************
568 *
569 * Audio
570 *
571 ***************************************************************************/
572
573 /*
574 * set audio packet size, used to determine when it's time to send a DTMF
575 * packet in silence (CNG)
576 *
577 * return -1 on failure else 0
578 */
579 virtual int32_t SetAudioPacketSize(uint16_t packetSizeSamples) = 0;
580
581 /*
582 * Send a TelephoneEvent tone using RFC 2833 (4733)
583 *
584 * return -1 on failure else 0
585 */
586 virtual int32_t SendTelephoneEventOutband(uint8_t key,
587 uint16_t time_ms,
588 uint8_t level) = 0;
589
590 /*
591 * Set payload type for Redundant Audio Data RFC 2198
592 *
593 * return -1 on failure else 0
594 */
595 virtual int32_t SetSendREDPayloadType(int8_t payloadType) = 0;
596
597 /*
598 * Get payload type for Redundant Audio Data RFC 2198
599 *
600 * return -1 on failure else 0
601 */
danilchap5c1def82015-12-10 09:51:54 -0800602 virtual int32_t SendREDPayloadType(int8_t* payload_type) const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100603 /*
604 * Store the audio level in dBov for header-extension-for-audio-level-
605 * indication.
606 * This API shall be called before transmision of an RTP packet to ensure
607 * that the |level| part of the extended RTP header is updated.
608 *
609 * return -1 on failure else 0.
610 */
611 virtual int32_t SetAudioLevel(uint8_t level_dBov) = 0;
612
613 /**************************************************************************
614 *
615 * Video
616 *
617 ***************************************************************************/
618
619 /*
620 * Set the target send bitrate
621 */
622 virtual void SetTargetSendBitrate(uint32_t bitrate_bps) = 0;
623
624 /*
625 * Turn on/off generic FEC
626 */
627 virtual void SetGenericFECStatus(bool enable,
628 uint8_t payload_type_red,
629 uint8_t payload_type_fec) = 0;
630
631 /*
632 * Get generic FEC setting
633 */
danilchap5c1def82015-12-10 09:51:54 -0800634 virtual void GenericFECStatus(bool* enable,
635 uint8_t* payload_type_red,
636 uint8_t* payload_type_fec) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100637
638 virtual int32_t SetFecParameters(
639 const FecProtectionParams* delta_params,
640 const FecProtectionParams* key_params) = 0;
641
642 /*
643 * Set method for requestion a new key frame
644 *
645 * return -1 on failure else 0
646 */
647 virtual int32_t SetKeyFrameRequestMethod(KeyFrameRequestMethod method) = 0;
648
649 /*
650 * send a request for a keyframe
651 *
652 * return -1 on failure else 0
653 */
654 virtual int32_t RequestKeyFrame() = 0;
655};
656} // namespace webrtc
danilchap5c1def82015-12-10 09:51:54 -0800657#endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_H_