blob: 50bb6a087843868000b17881a0517e132edd4504 [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"
21
22namespace webrtc {
23// Forward declarations.
24class ReceiveStatistics;
25class RemoteBitrateEstimator;
26class RtpReceiver;
27class Transport;
terelius429c3452016-01-21 05:42:04 -080028class RtcEventLog;
29
Peter Boström9c017252016-02-26 16:26:20 +010030RTPExtensionType StringToRtpExtensionType(const std::string& extension);
31
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010032namespace rtcp {
33class TransportFeedback;
34}
35
36class RtpRtcp : public Module {
37 public:
38 struct Configuration {
39 Configuration();
40
41 /* id - Unique identifier of this RTP/RTCP module object
42 * audio - True for a audio version of the RTP/RTCP module
43 * object false will create a video version
44 * clock - The clock to use to read time. If NULL object
45 * will be using the system clock.
46 * incoming_data - Callback object that will receive the incoming
47 * data. May not be NULL; default callback will do
48 * nothing.
49 * incoming_messages - Callback object that will receive the incoming
50 * RTP messages. May not be NULL; default callback
51 * will do nothing.
52 * outgoing_transport - Transport object that will be called when packets
53 * are ready to be sent out on the network
54 * intra_frame_callback - Called when the receiver request a intra frame.
55 * bandwidth_callback - Called when we receive a changed estimate from
56 * the receiver of out stream.
57 * audio_messages - Telephone events. May not be NULL; default
58 * callback will do nothing.
59 * 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;
74 RtpAudioFeedback* audio_messages;
75 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;
82
83 RTC_DISALLOW_COPY_AND_ASSIGN(Configuration);
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010084 };
85
86 /*
87 * Create a RTP/RTCP module object using the system clock.
88 *
89 * configuration - Configuration of the RTP/RTCP module.
90 */
91 static RtpRtcp* CreateRtpRtcp(const RtpRtcp::Configuration& configuration);
92
93 /**************************************************************************
94 *
95 * Receiver functions
96 *
97 ***************************************************************************/
98
99 virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet,
100 size_t incoming_packet_length) = 0;
101
102 virtual void SetRemoteSSRC(uint32_t ssrc) = 0;
103
104 /**************************************************************************
105 *
106 * Sender
107 *
108 ***************************************************************************/
109
110 /*
111 * set MTU
112 *
113 * size - Max transfer unit in bytes, default is 1500
114 *
115 * return -1 on failure else 0
116 */
117 virtual int32_t SetMaxTransferUnit(uint16_t size) = 0;
118
119 /*
120 * set transtport overhead
121 * default is IPv4 and UDP with no encryption
122 *
123 * TCP - true for TCP false UDP
124 * IPv6 - true for IP version 6 false for version 4
125 * authenticationOverhead - number of bytes to leave for an
126 * authentication header
127 *
128 * return -1 on failure else 0
129 */
130 virtual int32_t SetTransportOverhead(
131 bool TCP,
132 bool IPV6,
133 uint8_t authenticationOverhead = 0) = 0;
134
135 /*
136 * Get max payload length
137 *
138 * A combination of the configuration MaxTransferUnit and
139 * TransportOverhead.
140 * Does not account FEC/ULP/RED overhead if FEC is enabled.
141 * Does not account for RTP headers
142 */
143 virtual uint16_t MaxPayloadLength() const = 0;
144
145 /*
146 * Get max data payload length
147 *
148 * A combination of the configuration MaxTransferUnit, headers and
149 * TransportOverhead.
150 * Takes into account FEC/ULP/RED overhead if FEC is enabled.
151 * Takes into account RTP headers
152 */
153 virtual uint16_t MaxDataPayloadLength() const = 0;
154
155 /*
156 * set codec name and payload type
157 *
158 * return -1 on failure else 0
159 */
160 virtual int32_t RegisterSendPayload(
161 const CodecInst& voiceCodec) = 0;
162
163 /*
164 * set codec name and payload type
165 *
166 * return -1 on failure else 0
167 */
168 virtual int32_t RegisterSendPayload(
169 const VideoCodec& videoCodec) = 0;
170
Peter Boström8b79b072016-02-26 16:31:37 +0100171 virtual void RegisterVideoSendPayload(int payload_type,
172 const char* payload_name) = 0;
173
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100174 /*
175 * Unregister a send payload
176 *
177 * payloadType - payload type of codec
178 *
179 * return -1 on failure else 0
180 */
181 virtual int32_t DeRegisterSendPayload(int8_t payloadType) = 0;
182
183 /*
184 * (De)register RTP header extension type and id.
185 *
186 * return -1 on failure else 0
187 */
188 virtual int32_t RegisterSendRtpHeaderExtension(RTPExtensionType type,
189 uint8_t id) = 0;
190
191 virtual int32_t DeregisterSendRtpHeaderExtension(RTPExtensionType type) = 0;
192
193 /*
194 * get start timestamp
195 */
196 virtual uint32_t StartTimestamp() const = 0;
197
198 /*
199 * configure start timestamp, default is a random number
200 *
201 * timestamp - start timestamp
202 */
203 virtual void SetStartTimestamp(uint32_t timestamp) = 0;
204
205 /*
206 * Get SequenceNumber
207 */
208 virtual uint16_t SequenceNumber() const = 0;
209
210 /*
211 * Set SequenceNumber, default is a random number
212 */
213 virtual void SetSequenceNumber(uint16_t seq) = 0;
214
215 // Returns true if the ssrc matched this module, false otherwise.
216 virtual bool SetRtpStateForSsrc(uint32_t ssrc,
217 const RtpState& rtp_state) = 0;
218 virtual bool GetRtpStateForSsrc(uint32_t ssrc, RtpState* rtp_state) = 0;
219
220 /*
221 * Get SSRC
222 */
223 virtual uint32_t SSRC() const = 0;
224
225 /*
226 * configure SSRC, default is a random number
227 */
228 virtual void SetSSRC(uint32_t ssrc) = 0;
229
230 /*
231 * Set CSRC
232 *
233 * csrcs - vector of CSRCs
234 */
235 virtual void SetCsrcs(const std::vector<uint32_t>& csrcs) = 0;
236
237 /*
238 * Turn on/off sending RTX (RFC 4588). The modes can be set as a combination
239 * of values of the enumerator RtxMode.
240 */
241 virtual void SetRtxSendStatus(int modes) = 0;
242
243 /*
244 * Get status of sending RTX (RFC 4588). The returned value can be
245 * a combination of values of the enumerator RtxMode.
246 */
247 virtual int RtxSendStatus() const = 0;
248
249 // Sets the SSRC to use when sending RTX packets. This doesn't enable RTX,
250 // only the SSRC is set.
251 virtual void SetRtxSsrc(uint32_t ssrc) = 0;
252
253 // Sets the payload type to use when sending RTX packets. Note that this
254 // doesn't enable RTX, only the payload type is set.
255 virtual void SetRtxSendPayloadType(int payload_type,
256 int associated_payload_type) = 0;
257
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100258 /*
259 * sends kRtcpByeCode when going from true to false
260 *
261 * sending - on/off
262 *
263 * return -1 on failure else 0
264 */
265 virtual int32_t SetSendingStatus(bool sending) = 0;
266
267 /*
268 * get send status
269 */
270 virtual bool Sending() const = 0;
271
272 /*
273 * Starts/Stops media packets, on by default
274 *
275 * sending - on/off
276 */
277 virtual void SetSendingMediaStatus(bool sending) = 0;
278
279 /*
280 * get send status
281 */
282 virtual bool SendingMedia() const = 0;
283
284 /*
285 * get sent bitrate in Kbit/s
286 */
287 virtual void BitrateSent(uint32_t* totalRate,
288 uint32_t* videoRate,
289 uint32_t* fecRate,
290 uint32_t* nackRate) const = 0;
291
292 /*
293 * Used by the codec module to deliver a video or audio frame for
294 * packetization.
295 *
296 * frameType - type of frame to send
297 * payloadType - payload type of frame to send
298 * timestamp - timestamp of frame to send
299 * payloadData - payload buffer of frame to send
300 * payloadSize - size of payload buffer to send
301 * fragmentation - fragmentation offset data for fragmented frames such
302 * as layers or RED
303 *
304 * return -1 on failure else 0
305 */
306 virtual int32_t SendOutgoingData(
307 FrameType frameType,
308 int8_t payloadType,
309 uint32_t timeStamp,
310 int64_t capture_time_ms,
311 const uint8_t* payloadData,
312 size_t payloadSize,
313 const RTPFragmentationHeader* fragmentation = NULL,
314 const RTPVideoHeader* rtpVideoHdr = NULL) = 0;
315
316 virtual bool TimeToSendPacket(uint32_t ssrc,
317 uint16_t sequence_number,
318 int64_t capture_time_ms,
319 bool retransmission) = 0;
320
321 virtual size_t TimeToSendPadding(size_t bytes) = 0;
322
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 */
537 virtual int32_t SendNACK(const uint16_t* nackList, uint16_t size) = 0;
538
539 /*
540 * Store the sent packets, needed to answer to a Negative acknowledgement
541 * requests
542 */
543 virtual void SetStorePacketsStatus(bool enable, uint16_t numberToStore) = 0;
544
545 // Returns true if the module is configured to store packets.
546 virtual bool StorePackets() const = 0;
547
548 // Called on receipt of RTCP report block from remote side.
549 virtual void RegisterRtcpStatisticsCallback(
550 RtcpStatisticsCallback* callback) = 0;
551 virtual RtcpStatisticsCallback*
552 GetRtcpStatisticsCallback() = 0;
553 // BWE feedback packets.
554 virtual bool SendFeedbackPacket(const rtcp::TransportFeedback& packet) = 0;
555
556 /**************************************************************************
557 *
558 * Audio
559 *
560 ***************************************************************************/
561
562 /*
563 * set audio packet size, used to determine when it's time to send a DTMF
564 * packet in silence (CNG)
565 *
566 * return -1 on failure else 0
567 */
568 virtual int32_t SetAudioPacketSize(uint16_t packetSizeSamples) = 0;
569
570 /*
571 * Send a TelephoneEvent tone using RFC 2833 (4733)
572 *
573 * return -1 on failure else 0
574 */
575 virtual int32_t SendTelephoneEventOutband(uint8_t key,
576 uint16_t time_ms,
577 uint8_t level) = 0;
578
579 /*
580 * Set payload type for Redundant Audio Data RFC 2198
581 *
582 * return -1 on failure else 0
583 */
584 virtual int32_t SetSendREDPayloadType(int8_t payloadType) = 0;
585
586 /*
587 * Get payload type for Redundant Audio Data RFC 2198
588 *
589 * return -1 on failure else 0
590 */
danilchap5c1def82015-12-10 09:51:54 -0800591 // DEPRECATED. Use SendREDPayloadType below that takes output parameter
592 // by pointer instead of by reference.
593 // TODO(danilchap): Remove this when all callers have been updated.
594 int32_t SendREDPayloadType(int8_t& payloadType) const { // NOLINT
595 return SendREDPayloadType(&payloadType);
596 }
597 virtual int32_t SendREDPayloadType(int8_t* payload_type) const = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100598 /*
599 * Store the audio level in dBov for header-extension-for-audio-level-
600 * indication.
601 * This API shall be called before transmision of an RTP packet to ensure
602 * that the |level| part of the extended RTP header is updated.
603 *
604 * return -1 on failure else 0.
605 */
606 virtual int32_t SetAudioLevel(uint8_t level_dBov) = 0;
607
608 /**************************************************************************
609 *
610 * Video
611 *
612 ***************************************************************************/
613
614 /*
615 * Set the target send bitrate
616 */
617 virtual void SetTargetSendBitrate(uint32_t bitrate_bps) = 0;
618
619 /*
620 * Turn on/off generic FEC
621 */
622 virtual void SetGenericFECStatus(bool enable,
623 uint8_t payload_type_red,
624 uint8_t payload_type_fec) = 0;
625
626 /*
627 * Get generic FEC setting
628 */
danilchap5c1def82015-12-10 09:51:54 -0800629 // DEPRECATED. Use GenericFECStatus below that takes output parameters
630 // by pointers instead of by references.
631 // TODO(danilchap): Remove this when all callers have been updated.
632 void GenericFECStatus(bool& enable, // NOLINT
633 uint8_t& payloadTypeRED, // NOLINT
634 uint8_t& payloadTypeFEC) { // NOLINT
635 GenericFECStatus(&enable, &payloadTypeRED, &payloadTypeFEC);
636 }
637 virtual void GenericFECStatus(bool* enable,
638 uint8_t* payload_type_red,
639 uint8_t* payload_type_fec) = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +0100640
641 virtual int32_t SetFecParameters(
642 const FecProtectionParams* delta_params,
643 const FecProtectionParams* key_params) = 0;
644
645 /*
646 * Set method for requestion a new key frame
647 *
648 * return -1 on failure else 0
649 */
650 virtual int32_t SetKeyFrameRequestMethod(KeyFrameRequestMethod method) = 0;
651
652 /*
653 * send a request for a keyframe
654 *
655 * return -1 on failure else 0
656 */
657 virtual int32_t RequestKeyFrame() = 0;
658};
659} // namespace webrtc
danilchap5c1def82015-12-10 09:51:54 -0800660#endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_H_