1 /* 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_INTERFACE_RTP_RTCP_H_ 12 #define WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_H_ 13 14 #include <vector> 15 16 #include "webrtc/modules/interface/module.h" 17 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" 18 19 namespace webrtc { 20 // Forward declarations. 21 class PacedSender; 22 class ReceiveStatistics; 23 class RemoteBitrateEstimator; 24 class RtpReceiver; 25 class Transport; 26 27 class RtpRtcp : public Module { 28 public: 29 struct Configuration { 30 Configuration(); 31 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 39 * nothing. 40 * incoming_messages - Callback object that will receive the incoming 41 * RTP messages. May not be NULL; default callback 42 * will do nothing. 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 46 * RTCP messages. 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 - Telephone events. May not be NULL; default 51 * callback will do nothing. 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. 56 */ 57 int32_t id; 58 bool audio; 59 Clock* clock; 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; 70 BitrateStatisticsObserver* send_bitrate_observer; 71 FrameCountObserver* send_frame_count_observer; 72 SendSideDelayObserver* send_side_delay_observer; 73 }; 74 75 /* 76 * Create a RTP/RTCP module object using the system clock. 77 * 78 * configuration - Configuration of the RTP/RTCP module. 79 */ 80 static RtpRtcp* CreateRtpRtcp(const RtpRtcp::Configuration& configuration); 81 82 /************************************************************************** 83 * 84 * Receiver functions 85 * 86 ***************************************************************************/ 87 88 virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet, 89 uint16_t incoming_packet_length) = 0; 90 91 virtual void SetRemoteSSRC(const uint32_t ssrc) = 0; 92 93 /************************************************************************** 94 * 95 * Sender 96 * 97 ***************************************************************************/ 98 99 /* 100 * set MTU 101 * 102 * size - Max transfer unit in bytes, default is 1500 103 * 104 * return -1 on failure else 0 105 */ 106 virtual int32_t SetMaxTransferUnit(const uint16_t size) = 0; 107 108 /* 109 * set transtport overhead 110 * default is IPv4 and UDP with no encryption 111 * 112 * TCP - true for TCP false UDP 113 * IPv6 - true for IP version 6 false for version 4 114 * authenticationOverhead - number of bytes to leave for an 115 * authentication header 116 * 117 * return -1 on failure else 0 118 */ 119 virtual int32_t SetTransportOverhead( 120 const bool TCP, 121 const bool IPV6, 122 const uint8_t authenticationOverhead = 0) = 0; 123 124 /* 125 * Get max payload length 126 * 127 * A combination of the configuration MaxTransferUnit and 128 * TransportOverhead. 129 * Does not account FEC/ULP/RED overhead if FEC is enabled. 130 * Does not account for RTP headers 131 */ 132 virtual uint16_t MaxPayloadLength() const = 0; 133 134 /* 135 * Get max data payload length 136 * 137 * A combination of the configuration MaxTransferUnit, headers and 138 * TransportOverhead. 139 * Takes into account FEC/ULP/RED overhead if FEC is enabled. 140 * Takes into account RTP headers 141 */ 142 virtual uint16_t MaxDataPayloadLength() const = 0; 143 144 /* 145 * set codec name and payload type 146 * 147 * return -1 on failure else 0 148 */ 149 virtual int32_t RegisterSendPayload( 150 const CodecInst& voiceCodec) = 0; 151 152 /* 153 * set codec name and payload type 154 * 155 * return -1 on failure else 0 156 */ 157 virtual int32_t RegisterSendPayload( 158 const VideoCodec& videoCodec) = 0; 159 160 /* 161 * Unregister a send payload 162 * 163 * payloadType - payload type of codec 164 * 165 * return -1 on failure else 0 166 */ 167 virtual int32_t DeRegisterSendPayload( 168 const int8_t payloadType) = 0; 169 170 /* 171 * (De)register RTP header extension type and id. 172 * 173 * return -1 on failure else 0 174 */ 175 virtual int32_t RegisterSendRtpHeaderExtension( 176 const RTPExtensionType type, 177 const uint8_t id) = 0; 178 179 virtual int32_t DeregisterSendRtpHeaderExtension( 180 const RTPExtensionType type) = 0; 181 182 /* 183 * get start timestamp 184 */ 185 virtual uint32_t StartTimestamp() const = 0; 186 187 /* 188 * configure start timestamp, default is a random number 189 * 190 * timestamp - start timestamp 191 * 192 * return -1 on failure else 0 193 */ 194 virtual int32_t SetStartTimestamp( 195 const uint32_t timestamp) = 0; 196 197 /* 198 * Get SequenceNumber 199 */ 200 virtual uint16_t SequenceNumber() const = 0; 201 202 /* 203 * Set SequenceNumber, default is a random number 204 * 205 * return -1 on failure else 0 206 */ 207 virtual int32_t SetSequenceNumber(const uint16_t seq) = 0; 208 209 virtual void SetRtpStateForSsrc(uint32_t ssrc, 210 const RtpState& rtp_state) = 0; 211 virtual bool GetRtpStateForSsrc(uint32_t ssrc, RtpState* rtp_state) = 0; 212 213 /* 214 * Get SSRC 215 */ 216 virtual uint32_t SSRC() const = 0; 217 218 /* 219 * configure SSRC, default is a random number 220 * 221 * return -1 on failure else 0 222 */ 223 virtual void SetSSRC(const uint32_t ssrc) = 0; 224 225 /* 226 * Get CSRC 227 * 228 * arrOfCSRC - array of CSRCs 229 * 230 * return -1 on failure else number of valid entries in the array 231 */ 232 virtual int32_t CSRCs( 233 uint32_t arrOfCSRC[kRtpCsrcSize]) const = 0; 234 235 /* 236 * Set CSRC 237 * 238 * arrOfCSRC - array of CSRCs 239 * arrLength - number of valid entries in the array 240 * 241 * return -1 on failure else 0 242 */ 243 virtual int32_t SetCSRCs( 244 const uint32_t arrOfCSRC[kRtpCsrcSize], 245 const uint8_t arrLength) = 0; 246 247 /* 248 * includes CSRCs in RTP header if enabled 249 * 250 * include CSRC - on/off 251 * 252 * default:on 253 * 254 * return -1 on failure else 0 255 */ 256 virtual int32_t SetCSRCStatus(const bool include) = 0; 257 258 /* 259 * Turn on/off sending RTX (RFC 4588). The modes can be set as a combination 260 * of values of the enumerator RtxMode. 261 */ 262 virtual void SetRTXSendStatus(int modes) = 0; 263 264 // Sets the SSRC to use when sending RTX packets. This doesn't enable RTX, 265 // only the SSRC is set. 266 virtual void SetRtxSsrc(uint32_t ssrc) = 0; 267 268 // Sets the payload type to use when sending RTX packets. Note that this 269 // doesn't enable RTX, only the payload type is set. 270 virtual void SetRtxSendPayloadType(int payload_type) = 0; 271 272 /* 273 * Get status of sending RTX (RFC 4588) on a specific SSRC. 274 */ 275 virtual void RTXSendStatus(int* modes, uint32_t* ssrc, 276 int* payloadType) const = 0; 277 278 /* 279 * sends kRtcpByeCode when going from true to false 280 * 281 * sending - on/off 282 * 283 * return -1 on failure else 0 284 */ 285 virtual int32_t SetSendingStatus(const bool sending) = 0; 286 287 /* 288 * get send status 289 */ 290 virtual bool Sending() const = 0; 291 292 /* 293 * Starts/Stops media packets, on by default 294 * 295 * sending - on/off 296 * 297 * return -1 on failure else 0 298 */ 299 virtual int32_t SetSendingMediaStatus(const bool sending) = 0; 300 301 /* 302 * get send status 303 */ 304 virtual bool SendingMedia() const = 0; 305 306 /* 307 * get sent bitrate in Kbit/s 308 */ 309 virtual void BitrateSent(uint32_t* totalRate, 310 uint32_t* videoRate, 311 uint32_t* fecRate, 312 uint32_t* nackRate) const = 0; 313 314 /* 315 * Used by the codec module to deliver a video or audio frame for 316 * packetization. 317 * 318 * frameType - type of frame to send 319 * payloadType - payload type of frame to send 320 * timestamp - timestamp of frame to send 321 * payloadData - payload buffer of frame to send 322 * payloadSize - size of payload buffer to send 323 * fragmentation - fragmentation offset data for fragmented frames such 324 * as layers or RED 325 * 326 * return -1 on failure else 0 327 */ 328 virtual int32_t SendOutgoingData( 329 const FrameType frameType, 330 const int8_t payloadType, 331 const uint32_t timeStamp, 332 int64_t capture_time_ms, 333 const uint8_t* payloadData, 334 const uint32_t payloadSize, 335 const RTPFragmentationHeader* fragmentation = NULL, 336 const RTPVideoHeader* rtpVideoHdr = NULL) = 0; 337 338 virtual bool TimeToSendPacket(uint32_t ssrc, 339 uint16_t sequence_number, 340 int64_t capture_time_ms, 341 bool retransmission) = 0; 342 343 virtual int TimeToSendPadding(int bytes) = 0; 344 345 virtual bool GetSendSideDelay(int* avg_send_delay_ms, 346 int* max_send_delay_ms) const = 0; 347 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; 353 354 /************************************************************************** 355 * 356 * RTCP 357 * 358 ***************************************************************************/ 359 360 /* 361 * Get RTCP status 362 */ 363 virtual RTCPMethod RTCP() const = 0; 364 365 /* 366 * configure RTCP status i.e on(compound or non- compound)/off 367 * 368 * method - RTCP method to use 369 * 370 * return -1 on failure else 0 371 */ 372 virtual int32_t SetRTCPStatus(const RTCPMethod method) = 0; 373 374 /* 375 * Set RTCP CName (i.e unique identifier) 376 * 377 * return -1 on failure else 0 378 */ 379 virtual int32_t SetCNAME(const char cName[RTCP_CNAME_SIZE]) = 0; 380 381 /* 382 * Get remote CName 383 * 384 * return -1 on failure else 0 385 */ 386 virtual int32_t RemoteCNAME( 387 const uint32_t remoteSSRC, 388 char cName[RTCP_CNAME_SIZE]) const = 0; 389 390 /* 391 * Get remote NTP 392 * 393 * return -1 on failure else 0 394 */ 395 virtual int32_t RemoteNTP( 396 uint32_t *ReceivedNTPsecs, 397 uint32_t *ReceivedNTPfrac, 398 uint32_t *RTCPArrivalTimeSecs, 399 uint32_t *RTCPArrivalTimeFrac, 400 uint32_t *rtcp_timestamp) const = 0; 401 402 /* 403 * AddMixedCNAME 404 * 405 * return -1 on failure else 0 406 */ 407 virtual int32_t AddMixedCNAME( 408 const uint32_t SSRC, 409 const char cName[RTCP_CNAME_SIZE]) = 0; 410 411 /* 412 * RemoveMixedCNAME 413 * 414 * return -1 on failure else 0 415 */ 416 virtual int32_t RemoveMixedCNAME(const uint32_t SSRC) = 0; 417 418 /* 419 * Get RoundTripTime 420 * 421 * return -1 on failure else 0 422 */ 423 virtual int32_t RTT(const uint32_t remoteSSRC, 424 uint16_t* RTT, 425 uint16_t* avgRTT, 426 uint16_t* minRTT, 427 uint16_t* maxRTT) const = 0 ; 428 429 /* 430 * Reset RoundTripTime statistics 431 * 432 * return -1 on failure else 0 433 */ 434 virtual int32_t ResetRTT(const uint32_t remoteSSRC)= 0 ; 435 436 /* 437 * Force a send of a RTCP packet 438 * normal SR and RR are triggered via the process function 439 * 440 * return -1 on failure else 0 441 */ 442 virtual int32_t SendRTCP( 443 uint32_t rtcpPacketType = kRtcpReport) = 0; 444 445 /* 446 * Good state of RTP receiver inform sender 447 */ 448 virtual int32_t SendRTCPReferencePictureSelection( 449 const uint64_t pictureID) = 0; 450 451 /* 452 * Send a RTCP Slice Loss Indication (SLI) 453 * 6 least significant bits of pictureID 454 */ 455 virtual int32_t SendRTCPSliceLossIndication( 456 const uint8_t pictureID) = 0; 457 458 /* 459 * Reset RTP data counters for the sending side 460 * 461 * return -1 on failure else 0 462 */ 463 virtual int32_t ResetSendDataCountersRTP() = 0; 464 465 /* 466 * statistics of the amount of data sent and received 467 * 468 * return -1 on failure else 0 469 */ 470 virtual int32_t DataCountersRTP( 471 uint32_t* bytesSent, 472 uint32_t* packetsSent) const = 0; 473 /* 474 * Get received RTCP sender info 475 * 476 * return -1 on failure else 0 477 */ 478 virtual int32_t RemoteRTCPStat(RTCPSenderInfo* senderInfo) = 0; 479 480 /* 481 * Get received RTCP report block 482 * 483 * return -1 on failure else 0 484 */ 485 virtual int32_t RemoteRTCPStat( 486 std::vector<RTCPReportBlock>* receiveBlocks) const = 0; 487 /* 488 * Set received RTCP report block 489 * 490 * return -1 on failure else 0 491 */ 492 virtual int32_t AddRTCPReportBlock( 493 const uint32_t SSRC, 494 const RTCPReportBlock* receiveBlock) = 0; 495 496 /* 497 * RemoveRTCPReportBlock 498 * 499 * return -1 on failure else 0 500 */ 501 virtual int32_t RemoveRTCPReportBlock(const uint32_t SSRC) = 0; 502 503 /* 504 * Get number of sent and received RTCP packet types. 505 */ 506 virtual void GetRtcpPacketTypeCounters( 507 RtcpPacketTypeCounter* packets_sent, 508 RtcpPacketTypeCounter* packets_received) const = 0; 509 510 /* 511 * (APP) Application specific data 512 * 513 * return -1 on failure else 0 514 */ 515 virtual int32_t SetRTCPApplicationSpecificData( 516 const uint8_t subType, 517 const uint32_t name, 518 const uint8_t* data, 519 const uint16_t length) = 0; 520 /* 521 * (XR) VOIP metric 522 * 523 * return -1 on failure else 0 524 */ 525 virtual int32_t SetRTCPVoIPMetrics( 526 const RTCPVoIPMetric* VoIPMetric) = 0; 527 528 /* 529 * (XR) Receiver Reference Time Report 530 */ 531 virtual void SetRtcpXrRrtrStatus(bool enable) = 0; 532 533 virtual bool RtcpXrRrtrStatus() const = 0; 534 535 /* 536 * (REMB) Receiver Estimated Max Bitrate 537 */ 538 virtual bool REMB() const = 0; 539 540 virtual int32_t SetREMBStatus(const bool enable) = 0; 541 542 virtual int32_t SetREMBData(const uint32_t bitrate, 543 const uint8_t numberOfSSRC, 544 const uint32_t* SSRC) = 0; 545 546 /* 547 * (IJ) Extended jitter report. 548 */ 549 virtual bool IJ() const = 0; 550 551 virtual int32_t SetIJStatus(const bool enable) = 0; 552 553 /* 554 * (TMMBR) Temporary Max Media Bit Rate 555 */ 556 virtual bool TMMBR() const = 0; 557 558 /* 559 * 560 * return -1 on failure else 0 561 */ 562 virtual int32_t SetTMMBRStatus(const bool enable) = 0; 563 564 /* 565 * (NACK) 566 */ 567 568 /* 569 * TODO(holmer): Propagate this API to VideoEngine. 570 * Returns the currently configured selective retransmission settings. 571 */ 572 virtual int SelectiveRetransmissions() const = 0; 573 574 /* 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. 583 * 584 * Returns -1 on failure, otherwise 0. 585 */ 586 virtual int SetSelectiveRetransmissions(uint8_t settings) = 0; 587 588 /* 589 * Send a Negative acknowledgement packet 590 * 591 * return -1 on failure else 0 592 */ 593 virtual int32_t SendNACK(const uint16_t* nackList, 594 const uint16_t size) = 0; 595 596 /* 597 * Store the sent packets, needed to answer to a Negative acknowledgement 598 * requests 599 * 600 * return -1 on failure else 0 601 */ 602 virtual int32_t SetStorePacketsStatus( 603 const bool enable, 604 const uint16_t numberToStore) = 0; 605 606 // Returns true if the module is configured to store packets. 607 virtual bool StorePackets() const = 0; 608 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; 614 615 /************************************************************************** 616 * 617 * Audio 618 * 619 ***************************************************************************/ 620 621 /* 622 * set audio packet size, used to determine when it's time to send a DTMF 623 * packet in silence (CNG) 624 * 625 * return -1 on failure else 0 626 */ 627 virtual int32_t SetAudioPacketSize( 628 const uint16_t packetSizeSamples) = 0; 629 630 /* 631 * SendTelephoneEventActive 632 * 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. 636 */ 637 virtual bool SendTelephoneEventActive( 638 int8_t& telephoneEvent) const = 0; 639 640 /* 641 * Send a TelephoneEvent tone using RFC 2833 (4733) 642 * 643 * return -1 on failure else 0 644 */ 645 virtual int32_t SendTelephoneEventOutband( 646 const uint8_t key, 647 const uint16_t time_ms, 648 const uint8_t level) = 0; 649 650 /* 651 * Set payload type for Redundant Audio Data RFC 2198 652 * 653 * return -1 on failure else 0 654 */ 655 virtual int32_t SetSendREDPayloadType( 656 const int8_t payloadType) = 0; 657 658 /* 659 * Get payload type for Redundant Audio Data RFC 2198 660 * 661 * return -1 on failure else 0 662 */ 663 virtual int32_t SendREDPayloadType( 664 int8_t& payloadType) const = 0; 665 666 /* 667 * Store the audio level in dBov for header-extension-for-audio-level- 668 * indication. 669 * This API shall be called before transmision of an RTP packet to ensure 670 * that the |level| part of the extended RTP header is updated. 671 * 672 * return -1 on failure else 0. 673 */ 674 virtual int32_t SetAudioLevel(const uint8_t level_dBov) = 0; 675 676 /************************************************************************** 677 * 678 * Video 679 * 680 ***************************************************************************/ 681 682 /* 683 * Set the estimated camera delay in MS 684 * 685 * return -1 on failure else 0 686 */ 687 virtual int32_t SetCameraDelay(const int32_t delayMS) = 0; 688 689 /* 690 * Set the target send bitrate 691 */ 692 virtual void SetTargetSendBitrate( 693 const std::vector<uint32_t>& stream_bitrates) = 0; 694 695 /* 696 * Turn on/off generic FEC 697 * 698 * return -1 on failure else 0 699 */ 700 virtual int32_t SetGenericFECStatus( 701 const bool enable, 702 const uint8_t payloadTypeRED, 703 const uint8_t payloadTypeFEC) = 0; 704 705 /* 706 * Get generic FEC setting 707 * 708 * return -1 on failure else 0 709 */ 710 virtual int32_t GenericFECStatus(bool& enable, 711 uint8_t& payloadTypeRED, 712 uint8_t& payloadTypeFEC) = 0; 713 714 715 virtual int32_t SetFecParameters( 716 const FecProtectionParams* delta_params, 717 const FecProtectionParams* key_params) = 0; 718 719 /* 720 * Set method for requestion a new key frame 721 * 722 * return -1 on failure else 0 723 */ 724 virtual int32_t SetKeyFrameRequestMethod( 725 const KeyFrameRequestMethod method) = 0; 726 727 /* 728 * send a request for a keyframe 729 * 730 * return -1 on failure else 0 731 */ 732 virtual int32_t RequestKeyFrame() = 0; 733 }; 734 } // namespace webrtc 735 #endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_H_ 736