2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_H_
12 #define WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_H_
16 #include "webrtc/modules/interface/module.h"
17 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
20 // Forward declarations.
22 class ReceiveStatistics;
23 class RemoteBitrateEstimator;
27 class RtpRtcp : public Module {
29 struct Configuration {
32 /* id - Unique identifier of this RTP/RTCP module object
33 * audio - True for a audio version of the RTP/RTCP module
34 * object false will create a video version
35 * clock - The clock to use to read time. If NULL object
36 * will be using the system clock.
37 * incoming_data - Callback object that will receive the incoming
38 * data. May not be NULL; default callback will do
40 * incoming_messages - Callback object that will receive the incoming
41 * RTP messages. May not be NULL; default callback
43 * outgoing_transport - Transport object that will be called when packets
44 * are ready to be sent out on the network
45 * rtcp_feedback - Callback object that will receive the incoming
47 * intra_frame_callback - Called when the receiver request a intra frame.
48 * bandwidth_callback - Called when we receive a changed estimate from
49 * the receiver of out stream.
50 * audio_messages - Telehone events. May not be NULL; default callback
52 * remote_bitrate_estimator - Estimates the bandwidth available for a set of
53 * streams from the same client.
54 * paced_sender - Spread any bursts of packets into smaller
55 * bursts to minimize packet loss.
60 RtpRtcp* default_module;
61 ReceiveStatistics* receive_statistics;
62 Transport* outgoing_transport;
63 RtcpFeedback* rtcp_feedback;
64 RtcpIntraFrameObserver* intra_frame_callback;
65 RtcpBandwidthObserver* bandwidth_callback;
66 RtcpRttStats* rtt_stats;
67 RtpAudioFeedback* audio_messages;
68 RemoteBitrateEstimator* remote_bitrate_estimator;
69 PacedSender* paced_sender;
73 * Create a RTP/RTCP module object using the system clock.
75 * configuration - Configuration of the RTP/RTCP module.
77 static RtpRtcp* CreateRtpRtcp(const RtpRtcp::Configuration& configuration);
79 /**************************************************************************
83 ***************************************************************************/
85 virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet,
86 uint16_t incoming_packet_length) = 0;
88 virtual void SetRemoteSSRC(const uint32_t ssrc) = 0;
90 /**************************************************************************
94 ***************************************************************************/
99 * size - Max transfer unit in bytes, default is 1500
101 * return -1 on failure else 0
103 virtual int32_t SetMaxTransferUnit(const uint16_t size) = 0;
106 * set transtport overhead
107 * default is IPv4 and UDP with no encryption
109 * TCP - true for TCP false UDP
110 * IPv6 - true for IP version 6 false for version 4
111 * authenticationOverhead - number of bytes to leave for an
112 * authentication header
114 * return -1 on failure else 0
116 virtual int32_t SetTransportOverhead(
119 const uint8_t authenticationOverhead = 0) = 0;
122 * Get max payload length
124 * A combination of the configuration MaxTransferUnit and
126 * Does not account FEC/ULP/RED overhead if FEC is enabled.
127 * Does not account for RTP headers
129 virtual uint16_t MaxPayloadLength() const = 0;
132 * Get max data payload length
134 * A combination of the configuration MaxTransferUnit, headers and
136 * Takes into account FEC/ULP/RED overhead if FEC is enabled.
137 * Takes into account RTP headers
139 virtual uint16_t MaxDataPayloadLength() const = 0;
142 * set codec name and payload type
144 * return -1 on failure else 0
146 virtual int32_t RegisterSendPayload(
147 const CodecInst& voiceCodec) = 0;
150 * set codec name and payload type
152 * return -1 on failure else 0
154 virtual int32_t RegisterSendPayload(
155 const VideoCodec& videoCodec) = 0;
158 * Unregister a send payload
160 * payloadType - payload type of codec
162 * return -1 on failure else 0
164 virtual int32_t DeRegisterSendPayload(
165 const int8_t payloadType) = 0;
168 * (De)register RTP header extension type and id.
170 * return -1 on failure else 0
172 virtual int32_t RegisterSendRtpHeaderExtension(
173 const RTPExtensionType type,
174 const uint8_t id) = 0;
176 virtual int32_t DeregisterSendRtpHeaderExtension(
177 const RTPExtensionType type) = 0;
180 * get start timestamp
182 virtual uint32_t StartTimestamp() const = 0;
185 * configure start timestamp, default is a random number
187 * timestamp - start timestamp
189 * return -1 on failure else 0
191 virtual int32_t SetStartTimestamp(
192 const uint32_t timestamp) = 0;
197 virtual uint16_t SequenceNumber() const = 0;
200 * Set SequenceNumber, default is a random number
202 * return -1 on failure else 0
204 virtual int32_t SetSequenceNumber(const uint16_t seq) = 0;
209 virtual uint32_t SSRC() const = 0;
212 * configure SSRC, default is a random number
214 * return -1 on failure else 0
216 virtual int32_t SetSSRC(const uint32_t ssrc) = 0;
221 * arrOfCSRC - array of CSRCs
223 * return -1 on failure else number of valid entries in the array
225 virtual int32_t CSRCs(
226 uint32_t arrOfCSRC[kRtpCsrcSize]) const = 0;
231 * arrOfCSRC - array of CSRCs
232 * arrLength - number of valid entries in the array
234 * return -1 on failure else 0
236 virtual int32_t SetCSRCs(
237 const uint32_t arrOfCSRC[kRtpCsrcSize],
238 const uint8_t arrLength) = 0;
241 * includes CSRCs in RTP header if enabled
243 * include CSRC - on/off
247 * return -1 on failure else 0
249 virtual int32_t SetCSRCStatus(const bool include) = 0;
252 * Turn on/off sending RTX (RFC 4588) on a specific SSRC.
254 virtual int32_t SetRTXSendStatus(int modes, bool set_ssrc,
257 // Sets the payload type to use when sending RTX packets. Note that this
258 // doesn't enable RTX, only the payload type is set.
259 virtual void SetRtxSendPayloadType(int payload_type) = 0;
262 * Get status of sending RTX (RFC 4588) on a specific SSRC.
264 virtual int32_t RTXSendStatus(int* modes, uint32_t* ssrc,
265 int* payloadType) const = 0;
268 * sends kRtcpByeCode when going from true to false
272 * return -1 on failure else 0
274 virtual int32_t SetSendingStatus(const bool sending) = 0;
279 virtual bool Sending() const = 0;
282 * Starts/Stops media packets, on by default
286 * return -1 on failure else 0
288 virtual int32_t SetSendingMediaStatus(const bool sending) = 0;
293 virtual bool SendingMedia() const = 0;
296 * get sent bitrate in Kbit/s
298 virtual void BitrateSent(uint32_t* totalRate,
301 uint32_t* nackRate) const = 0;
304 * Called on any new send bitrate estimate.
306 virtual void RegisterVideoBitrateObserver(
307 BitrateStatisticsObserver* observer) = 0;
308 virtual BitrateStatisticsObserver* GetVideoBitrateObserver() const = 0;
311 * Used by the codec module to deliver a video or audio frame for
314 * frameType - type of frame to send
315 * payloadType - payload type of frame to send
316 * timestamp - timestamp of frame to send
317 * payloadData - payload buffer of frame to send
318 * payloadSize - size of payload buffer to send
319 * fragmentation - fragmentation offset data for fragmented frames such
322 * return -1 on failure else 0
324 virtual int32_t SendOutgoingData(
325 const FrameType frameType,
326 const int8_t payloadType,
327 const uint32_t timeStamp,
328 int64_t capture_time_ms,
329 const uint8_t* payloadData,
330 const uint32_t payloadSize,
331 const RTPFragmentationHeader* fragmentation = NULL,
332 const RTPVideoHeader* rtpVideoHdr = NULL) = 0;
334 virtual bool TimeToSendPacket(uint32_t ssrc,
335 uint16_t sequence_number,
336 int64_t capture_time_ms,
337 bool retransmission) = 0;
339 virtual int TimeToSendPadding(int bytes) = 0;
341 virtual void RegisterSendFrameCountObserver(
342 FrameCountObserver* observer) = 0;
343 virtual FrameCountObserver* GetSendFrameCountObserver() const = 0;
345 virtual bool GetSendSideDelay(int* avg_send_delay_ms,
346 int* max_send_delay_ms) const = 0;
348 // Called on generation of new statistics after an RTP send.
349 virtual void RegisterSendChannelRtpStatisticsCallback(
350 StreamDataCountersCallback* callback) = 0;
351 virtual StreamDataCountersCallback*
352 GetSendChannelRtpStatisticsCallback() const = 0;
354 /**************************************************************************
358 ***************************************************************************/
363 virtual RTCPMethod RTCP() const = 0;
366 * configure RTCP status i.e on(compound or non- compound)/off
368 * method - RTCP method to use
370 * return -1 on failure else 0
372 virtual int32_t SetRTCPStatus(const RTCPMethod method) = 0;
375 * Set RTCP CName (i.e unique identifier)
377 * return -1 on failure else 0
379 virtual int32_t SetCNAME(const char cName[RTCP_CNAME_SIZE]) = 0;
382 * Get RTCP CName (i.e unique identifier)
384 * return -1 on failure else 0
386 virtual int32_t CNAME(char cName[RTCP_CNAME_SIZE]) = 0;
391 * return -1 on failure else 0
393 virtual int32_t RemoteCNAME(
394 const uint32_t remoteSSRC,
395 char cName[RTCP_CNAME_SIZE]) const = 0;
400 * return -1 on failure else 0
402 virtual int32_t RemoteNTP(
403 uint32_t *ReceivedNTPsecs,
404 uint32_t *ReceivedNTPfrac,
405 uint32_t *RTCPArrivalTimeSecs,
406 uint32_t *RTCPArrivalTimeFrac,
407 uint32_t *rtcp_timestamp) const = 0;
412 * return -1 on failure else 0
414 virtual int32_t AddMixedCNAME(
416 const char cName[RTCP_CNAME_SIZE]) = 0;
421 * return -1 on failure else 0
423 virtual int32_t RemoveMixedCNAME(const uint32_t SSRC) = 0;
428 * return -1 on failure else 0
430 virtual int32_t RTT(const uint32_t remoteSSRC,
434 uint16_t* maxRTT) const = 0 ;
437 * Reset RoundTripTime statistics
439 * return -1 on failure else 0
441 virtual int32_t ResetRTT(const uint32_t remoteSSRC)= 0 ;
444 * Force a send of a RTCP packet
445 * normal SR and RR are triggered via the process function
447 * return -1 on failure else 0
449 virtual int32_t SendRTCP(
450 uint32_t rtcpPacketType = kRtcpReport) = 0;
453 * Good state of RTP receiver inform sender
455 virtual int32_t SendRTCPReferencePictureSelection(
456 const uint64_t pictureID) = 0;
459 * Send a RTCP Slice Loss Indication (SLI)
460 * 6 least significant bits of pictureID
462 virtual int32_t SendRTCPSliceLossIndication(
463 const uint8_t pictureID) = 0;
466 * Reset RTP data counters for the sending side
468 * return -1 on failure else 0
470 virtual int32_t ResetSendDataCountersRTP() = 0;
473 * statistics of the amount of data sent and received
475 * return -1 on failure else 0
477 virtual int32_t DataCountersRTP(
479 uint32_t* packetsSent) const = 0;
481 * Get received RTCP sender info
483 * return -1 on failure else 0
485 virtual int32_t RemoteRTCPStat(RTCPSenderInfo* senderInfo) = 0;
488 * Get received RTCP report block
490 * return -1 on failure else 0
492 virtual int32_t RemoteRTCPStat(
493 std::vector<RTCPReportBlock>* receiveBlocks) const = 0;
495 * Set received RTCP report block
497 * return -1 on failure else 0
499 virtual int32_t AddRTCPReportBlock(
501 const RTCPReportBlock* receiveBlock) = 0;
504 * RemoveRTCPReportBlock
506 * return -1 on failure else 0
508 virtual int32_t RemoveRTCPReportBlock(const uint32_t SSRC) = 0;
511 * (APP) Application specific data
513 * return -1 on failure else 0
515 virtual int32_t SetRTCPApplicationSpecificData(
516 const uint8_t subType,
519 const uint16_t length) = 0;
523 * return -1 on failure else 0
525 virtual int32_t SetRTCPVoIPMetrics(
526 const RTCPVoIPMetric* VoIPMetric) = 0;
529 * (XR) Receiver Reference Time Report
531 virtual void SetRtcpXrRrtrStatus(bool enable) = 0;
533 virtual bool RtcpXrRrtrStatus() const = 0;
536 * (REMB) Receiver Estimated Max Bitrate
538 virtual bool REMB() const = 0;
540 virtual int32_t SetREMBStatus(const bool enable) = 0;
542 virtual int32_t SetREMBData(const uint32_t bitrate,
543 const uint8_t numberOfSSRC,
544 const uint32_t* SSRC) = 0;
547 * (IJ) Extended jitter report.
549 virtual bool IJ() const = 0;
551 virtual int32_t SetIJStatus(const bool enable) = 0;
554 * (TMMBR) Temporary Max Media Bit Rate
556 virtual bool TMMBR() const = 0;
560 * return -1 on failure else 0
562 virtual int32_t SetTMMBRStatus(const bool enable) = 0;
569 * TODO(holmer): Propagate this API to VideoEngine.
570 * Returns the currently configured selective retransmission settings.
572 virtual int SelectiveRetransmissions() const = 0;
575 * TODO(holmer): Propagate this API to VideoEngine.
576 * Sets the selective retransmission settings, which will decide which
577 * packets will be retransmitted if NACKed. Settings are constructed by
578 * combining the constants in enum RetransmissionMode with bitwise OR.
579 * All packets are retransmitted if kRetransmitAllPackets is set, while no
580 * packets are retransmitted if kRetransmitOff is set.
581 * By default all packets except FEC packets are retransmitted. For VP8
582 * with temporal scalability only base layer packets are retransmitted.
584 * Returns -1 on failure, otherwise 0.
586 virtual int SetSelectiveRetransmissions(uint8_t settings) = 0;
589 * Send a Negative acknowledgement packet
591 * return -1 on failure else 0
593 virtual int32_t SendNACK(const uint16_t* nackList,
594 const uint16_t size) = 0;
597 * Store the sent packets, needed to answer to a Negative acknowledgement
600 * return -1 on failure else 0
602 virtual int32_t SetStorePacketsStatus(
604 const uint16_t numberToStore) = 0;
606 // Returns true if the module is configured to store packets.
607 virtual bool StorePackets() const = 0;
609 // Called on receipt of RTCP report block from remote side.
610 virtual void RegisterSendChannelRtcpStatisticsCallback(
611 RtcpStatisticsCallback* callback) = 0;
612 virtual RtcpStatisticsCallback*
613 GetSendChannelRtcpStatisticsCallback() = 0;
615 /**************************************************************************
619 ***************************************************************************/
622 * set audio packet size, used to determine when it's time to send a DTMF
623 * packet in silence (CNG)
625 * return -1 on failure else 0
627 virtual int32_t SetAudioPacketSize(
628 const uint16_t packetSizeSamples) = 0;
631 * SendTelephoneEventActive
633 * return true if we currently send a telephone event and 100 ms after an
634 * event is sent used to prevent the telephone event tone to be recorded
635 * by the microphone and send inband just after the tone has ended.
637 virtual bool SendTelephoneEventActive(
638 int8_t& telephoneEvent) const = 0;
641 * Send a TelephoneEvent tone using RFC 2833 (4733)
643 * return -1 on failure else 0
645 virtual int32_t SendTelephoneEventOutband(
647 const uint16_t time_ms,
648 const uint8_t level) = 0;
651 * Set payload type for Redundant Audio Data RFC 2198
653 * return -1 on failure else 0
655 virtual int32_t SetSendREDPayloadType(
656 const int8_t payloadType) = 0;
659 * Get payload type for Redundant Audio Data RFC 2198
661 * return -1 on failure else 0
663 virtual int32_t SendREDPayloadType(
664 int8_t& payloadType) const = 0;
667 * Set status and ID for header-extension-for-audio-level-indication.
668 * See http://tools.ietf.org/html/rfc6464 for more details.
670 * return -1 on failure else 0
672 virtual int32_t SetRTPAudioLevelIndicationStatus(
674 const uint8_t ID) = 0;
677 * Get status and ID for header-extension-for-audio-level-indication.
679 * return -1 on failure else 0
681 virtual int32_t GetRTPAudioLevelIndicationStatus(
683 uint8_t& ID) const = 0;
686 * Store the audio level in dBov for header-extension-for-audio-level-
688 * This API shall be called before transmision of an RTP packet to ensure
689 * that the |level| part of the extended RTP header is updated.
691 * return -1 on failure else 0.
693 virtual int32_t SetAudioLevel(const uint8_t level_dBov) = 0;
695 /**************************************************************************
699 ***************************************************************************/
702 * Set the estimated camera delay in MS
704 * return -1 on failure else 0
706 virtual int32_t SetCameraDelay(const int32_t delayMS) = 0;
709 * Set the target send bitrate
711 virtual void SetTargetSendBitrate(
712 const std::vector<uint32_t>& stream_bitrates) = 0;
715 * Turn on/off generic FEC
717 * return -1 on failure else 0
719 virtual int32_t SetGenericFECStatus(
721 const uint8_t payloadTypeRED,
722 const uint8_t payloadTypeFEC) = 0;
725 * Get generic FEC setting
727 * return -1 on failure else 0
729 virtual int32_t GenericFECStatus(bool& enable,
730 uint8_t& payloadTypeRED,
731 uint8_t& payloadTypeFEC) = 0;
734 virtual int32_t SetFecParameters(
735 const FecProtectionParams* delta_params,
736 const FecProtectionParams* key_params) = 0;
739 * Set method for requestion a new key frame
741 * return -1 on failure else 0
743 virtual int32_t SetKeyFrameRequestMethod(
744 const KeyFrameRequestMethod method) = 0;
747 * send a request for a keyframe
749 * return -1 on failure else 0
751 virtual int32_t RequestKeyFrame() = 0;
753 } // namespace webrtc
754 #endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_H_