rtp_rtcp_impl.h revision aa4d96a134a03f998d52fb9699845d9c644eb24b
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_SOURCE_RTP_RTCP_IMPL_H_ 12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RTCP_IMPL_H_ 13 14#include <list> 15#include <vector> 16 17#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" 18#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" 19#include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" 20#include "webrtc/modules/rtp_rtcp/source/rtp_payload_registry.h" 21#include "webrtc/modules/rtp_rtcp/source/rtp_receiver.h" 22#include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" 23#include "webrtc/system_wrappers/interface/scoped_ptr.h" 24 25#ifdef MATLAB 26class MatlabPlot; 27#endif 28 29namespace webrtc { 30 31class ModuleRtpRtcpImpl : public RtpRtcp { 32 public: 33 explicit ModuleRtpRtcpImpl(const RtpRtcp::Configuration& configuration); 34 35 virtual ~ModuleRtpRtcpImpl(); 36 37 // Returns the number of milliseconds until the module want a worker thread to 38 // call Process. 39 virtual int32_t TimeUntilNextProcess(); 40 41 // Process any pending tasks such as timeouts. 42 virtual int32_t Process(); 43 44 // Receiver part. 45 46 // Configure a timeout value. 47 virtual int32_t SetPacketTimeout(const uint32_t rtp_timeout_ms, 48 const uint32_t rtcp_timeout_ms); 49 50 // Set periodic dead or alive notification. 51 virtual int32_t SetPeriodicDeadOrAliveStatus( 52 const bool enable, 53 const uint8_t sample_time_seconds); 54 55 // Get periodic dead or alive notification status. 56 virtual int32_t PeriodicDeadOrAliveStatus( 57 bool& enable, 58 uint8_t& sample_time_seconds); 59 60 virtual int32_t RegisterReceivePayload(const CodecInst& voice_codec); 61 62 virtual int32_t RegisterReceivePayload(const VideoCodec& video_codec); 63 64 virtual int32_t ReceivePayloadType(const CodecInst& voice_codec, 65 int8_t* pl_type); 66 67 virtual int32_t ReceivePayloadType(const VideoCodec& video_codec, 68 int8_t* pl_type); 69 70 virtual int32_t DeRegisterReceivePayload( 71 const int8_t payload_type); 72 73 // Get the currently configured SSRC filter. 74 virtual int32_t SSRCFilter(uint32_t& allowed_ssrc) const; 75 76 // Set a SSRC to be used as a filter for incoming RTP streams. 77 virtual int32_t SetSSRCFilter(const bool enable, 78 const uint32_t allowed_ssrc); 79 80 // Get last received remote timestamp. 81 virtual uint32_t RemoteTimestamp() const; 82 83 // Get the local time of the last received remote timestamp. 84 virtual int64_t LocalTimeOfRemoteTimeStamp() const; 85 86 // Get the current estimated remote timestamp. 87 virtual int32_t EstimatedRemoteTimeStamp( 88 uint32_t& timestamp) const; 89 90 virtual uint32_t RemoteSSRC() const; 91 92 virtual int32_t RemoteCSRCs( 93 uint32_t arr_of_csrc[kRtpCsrcSize]) const; 94 95 virtual int32_t SetRTXReceiveStatus(const bool enable, 96 const uint32_t ssrc); 97 98 virtual int32_t RTXReceiveStatus(bool* enable, uint32_t* ssrc, 99 int* payloadType) const; 100 101 virtual void SetRtxReceivePayloadType(int payload_type); 102 103 // Called when we receive an RTP packet. 104 virtual int32_t IncomingRtpPacket(const uint8_t* incoming_packet, 105 const uint16_t packet_length, 106 const RTPHeader& parsed_rtp_header); 107 108 // Called when we receive an RTCP packet. 109 virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet, 110 uint16_t incoming_packet_length); 111 112 // Sender part. 113 114 virtual int32_t RegisterSendPayload(const CodecInst& voice_codec); 115 116 virtual int32_t RegisterSendPayload(const VideoCodec& video_codec); 117 118 virtual int32_t DeRegisterSendPayload(const int8_t payload_type); 119 120 virtual int8_t SendPayloadType() const; 121 122 // Register RTP header extension. 123 virtual int32_t RegisterSendRtpHeaderExtension( 124 const RTPExtensionType type, 125 const uint8_t id); 126 127 virtual int32_t DeregisterSendRtpHeaderExtension( 128 const RTPExtensionType type); 129 130 // Get start timestamp. 131 virtual uint32_t StartTimestamp() const; 132 133 // Configure start timestamp, default is a random number. 134 virtual int32_t SetStartTimestamp(const uint32_t timestamp); 135 136 virtual uint16_t SequenceNumber() const; 137 138 // Set SequenceNumber, default is a random number. 139 virtual int32_t SetSequenceNumber(const uint16_t seq); 140 141 virtual uint32_t SSRC() const; 142 143 // Configure SSRC, default is a random number. 144 virtual int32_t SetSSRC(const uint32_t ssrc); 145 146 virtual int32_t CSRCs(uint32_t arr_of_csrc[kRtpCsrcSize]) const; 147 148 virtual int32_t SetCSRCs(const uint32_t arr_of_csrc[kRtpCsrcSize], 149 const uint8_t arr_length); 150 151 virtual int32_t SetCSRCStatus(const bool include); 152 153 virtual uint32_t PacketCountSent() const; 154 155 virtual int CurrentSendFrequencyHz() const; 156 157 virtual uint32_t ByteCountSent() const; 158 159 virtual int32_t SetRTXSendStatus(const RtxMode mode, 160 const bool set_ssrc, 161 const uint32_t ssrc); 162 163 virtual int32_t RTXSendStatus(RtxMode* mode, uint32_t* ssrc, 164 int* payloadType) const; 165 166 167 virtual void SetRtxSendPayloadType(int payload_type); 168 169 // Sends kRtcpByeCode when going from true to false. 170 virtual int32_t SetSendingStatus(const bool sending); 171 172 virtual bool Sending() const; 173 174 // Drops or relays media packets. 175 virtual int32_t SetSendingMediaStatus(const bool sending); 176 177 virtual bool SendingMedia() const; 178 179 // Used by the codec module to deliver a video or audio frame for 180 // packetization. 181 virtual int32_t SendOutgoingData( 182 const FrameType frame_type, 183 const int8_t payload_type, 184 const uint32_t time_stamp, 185 int64_t capture_time_ms, 186 const uint8_t* payload_data, 187 const uint32_t payload_size, 188 const RTPFragmentationHeader* fragmentation = NULL, 189 const RTPVideoHeader* rtp_video_hdr = NULL); 190 191 virtual bool TimeToSendPacket(uint32_t ssrc, uint16_t sequence_number, 192 int64_t capture_time_ms); 193 // Returns the number of padding bytes actually sent, which can be more or 194 // less than |bytes|. 195 virtual int TimeToSendPadding(int bytes); 196 // RTCP part. 197 198 // Get RTCP status. 199 virtual RTCPMethod RTCP() const; 200 201 // Configure RTCP status i.e on/off. 202 virtual int32_t SetRTCPStatus(const RTCPMethod method); 203 204 // Set RTCP CName. 205 virtual int32_t SetCNAME(const char c_name[RTCP_CNAME_SIZE]); 206 207 // Get RTCP CName. 208 virtual int32_t CNAME(char c_name[RTCP_CNAME_SIZE]); 209 210 // Get remote CName. 211 virtual int32_t RemoteCNAME(const uint32_t remote_ssrc, 212 char c_name[RTCP_CNAME_SIZE]) const; 213 214 // Get remote NTP. 215 virtual int32_t RemoteNTP(uint32_t* received_ntp_secs, 216 uint32_t* received_ntp_frac, 217 uint32_t* rtcp_arrival_time_secs, 218 uint32_t* rtcp_arrival_time_frac, 219 uint32_t* rtcp_timestamp) const; 220 221 virtual int32_t AddMixedCNAME(const uint32_t ssrc, 222 const char c_name[RTCP_CNAME_SIZE]); 223 224 virtual int32_t RemoveMixedCNAME(const uint32_t ssrc); 225 226 // Get RoundTripTime. 227 virtual int32_t RTT(const uint32_t remote_ssrc, 228 uint16_t* rtt, 229 uint16_t* avg_rtt, 230 uint16_t* min_rtt, 231 uint16_t* max_rtt) const; 232 233 // Reset RoundTripTime statistics. 234 virtual int32_t ResetRTT(const uint32_t remote_ssrc); 235 236 virtual void SetRtt(uint32_t rtt); 237 238 // Force a send of an RTCP packet. 239 // Normal SR and RR are triggered via the process function. 240 virtual int32_t SendRTCP(uint32_t rtcp_packet_type = kRtcpReport); 241 242 // Statistics of our locally created statistics of the received RTP stream. 243 virtual int32_t StatisticsRTP(uint8_t* fraction_lost, 244 uint32_t* cum_lost, 245 uint32_t* ext_max, 246 uint32_t* jitter, 247 uint32_t* max_jitter = NULL) const; 248 249 // Reset RTP statistics. 250 virtual int32_t ResetStatisticsRTP(); 251 252 virtual int32_t ResetReceiveDataCountersRTP(); 253 254 virtual int32_t ResetSendDataCountersRTP(); 255 256 // Statistics of the amount of data sent and received. 257 virtual int32_t DataCountersRTP(uint32_t* bytes_sent, 258 uint32_t* packets_sent, 259 uint32_t* bytes_received, 260 uint32_t* packets_received) const; 261 262 virtual int32_t ReportBlockStatistics( 263 uint8_t* fraction_lost, 264 uint32_t* cum_lost, 265 uint32_t* ext_max, 266 uint32_t* jitter, 267 uint32_t* jitter_transmission_time_offset); 268 269 // Get received RTCP report, sender info. 270 virtual int32_t RemoteRTCPStat(RTCPSenderInfo* sender_info); 271 272 // Get received RTCP report, report block. 273 virtual int32_t RemoteRTCPStat( 274 std::vector<RTCPReportBlock>* receive_blocks) const; 275 276 // Set received RTCP report block. 277 virtual int32_t AddRTCPReportBlock( 278 const uint32_t ssrc, const RTCPReportBlock* receive_block); 279 280 virtual int32_t RemoveRTCPReportBlock(const uint32_t ssrc); 281 282 // (REMB) Receiver Estimated Max Bitrate. 283 virtual bool REMB() const; 284 285 virtual int32_t SetREMBStatus(const bool enable); 286 287 virtual int32_t SetREMBData(const uint32_t bitrate, 288 const uint8_t number_of_ssrc, 289 const uint32_t* ssrc); 290 291 // (IJ) Extended jitter report. 292 virtual bool IJ() const; 293 294 virtual int32_t SetIJStatus(const bool enable); 295 296 // (TMMBR) Temporary Max Media Bit Rate. 297 virtual bool TMMBR() const; 298 299 virtual int32_t SetTMMBRStatus(const bool enable); 300 301 int32_t SetTMMBN(const TMMBRSet* bounding_set); 302 303 virtual uint16_t MaxPayloadLength() const; 304 305 virtual uint16_t MaxDataPayloadLength() const; 306 307 virtual int32_t SetMaxTransferUnit(const uint16_t size); 308 309 virtual int32_t SetTransportOverhead( 310 const bool tcp, 311 const bool ipv6, 312 const uint8_t authentication_overhead = 0); 313 314 // (NACK) Negative acknowledgment part. 315 316 // Is Negative acknowledgment requests on/off? 317 virtual NACKMethod NACK() const; 318 319 // Turn negative acknowledgment requests on/off. 320 virtual int32_t SetNACKStatus(const NACKMethod method, 321 int max_reordering_threshold); 322 323 virtual int SelectiveRetransmissions() const; 324 325 virtual int SetSelectiveRetransmissions(uint8_t settings); 326 327 // Send a Negative acknowledgment packet. 328 virtual int32_t SendNACK(const uint16_t* nack_list, const uint16_t size); 329 330 // Store the sent packets, needed to answer to a negative acknowledgment 331 // requests. 332 virtual int32_t SetStorePacketsStatus( 333 const bool enable, const uint16_t number_to_store); 334 335 // (APP) Application specific data. 336 virtual int32_t SetRTCPApplicationSpecificData( 337 const uint8_t sub_type, 338 const uint32_t name, 339 const uint8_t* data, 340 const uint16_t length); 341 342 // (XR) VOIP metric. 343 virtual int32_t SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric); 344 345 // Audio part. 346 347 // Set audio packet size, used to determine when it's time to send a DTMF 348 // packet in silence (CNG). 349 virtual int32_t SetAudioPacketSize( 350 const uint16_t packet_size_samples); 351 352 // Forward DTMFs to decoder for playout. 353 virtual int SetTelephoneEventForwardToDecoder(bool forward_to_decoder); 354 355 // Is forwarding of outband telephone events turned on/off? 356 virtual bool TelephoneEventForwardToDecoder() const; 357 358 virtual bool SendTelephoneEventActive(int8_t& telephone_event) const; 359 360 // Send a TelephoneEvent tone using RFC 2833 (4733). 361 virtual int32_t SendTelephoneEventOutband(const uint8_t key, 362 const uint16_t time_ms, 363 const uint8_t level); 364 365 // Set payload type for Redundant Audio Data RFC 2198. 366 virtual int32_t SetSendREDPayloadType(const int8_t payload_type); 367 368 // Get payload type for Redundant Audio Data RFC 2198. 369 virtual int32_t SendREDPayloadType(int8_t& payload_type) const; 370 371 // Set status and id for header-extension-for-audio-level-indication. 372 virtual int32_t SetRTPAudioLevelIndicationStatus( 373 const bool enable, const uint8_t id); 374 375 // Get status and id for header-extension-for-audio-level-indication. 376 virtual int32_t GetRTPAudioLevelIndicationStatus( 377 bool& enable, uint8_t& id) const; 378 379 // Store the audio level in d_bov for header-extension-for-audio-level- 380 // indication. 381 virtual int32_t SetAudioLevel(const uint8_t level_d_bov); 382 383 // Video part. 384 385 virtual RtpVideoCodecTypes ReceivedVideoCodec() const; 386 387 virtual RtpVideoCodecTypes SendVideoCodec() const; 388 389 virtual int32_t SendRTCPSliceLossIndication( 390 const uint8_t picture_id); 391 392 // Set method for requestion a new key frame. 393 virtual int32_t SetKeyFrameRequestMethod( 394 const KeyFrameRequestMethod method); 395 396 // Send a request for a keyframe. 397 virtual int32_t RequestKeyFrame(); 398 399 virtual int32_t SetCameraDelay(const int32_t delay_ms); 400 401 virtual void SetTargetSendBitrate(const uint32_t bitrate); 402 403 virtual int32_t SetGenericFECStatus( 404 const bool enable, 405 const uint8_t payload_type_red, 406 const uint8_t payload_type_fec); 407 408 virtual int32_t GenericFECStatus( 409 bool& enable, 410 uint8_t& payload_type_red, 411 uint8_t& payload_type_fec); 412 413 virtual int32_t SetFecParameters( 414 const FecProtectionParams* delta_params, 415 const FecProtectionParams* key_params); 416 417 virtual int32_t LastReceivedNTP(uint32_t& NTPsecs, 418 uint32_t& NTPfrac, 419 uint32_t& remote_sr); 420 421 virtual int32_t BoundingSet(bool& tmmbr_owner, TMMBRSet*& bounding_set_rec); 422 423 virtual void BitrateSent(uint32_t* total_rate, 424 uint32_t* video_rate, 425 uint32_t* fec_rate, 426 uint32_t* nackRate) const; 427 428 virtual void SetRemoteSSRC(const uint32_t ssrc); 429 430 virtual uint32_t SendTimeOfSendReport(const uint32_t send_report); 431 432 // Good state of RTP receiver inform sender. 433 virtual int32_t SendRTCPReferencePictureSelection( 434 const uint64_t picture_id); 435 436 void OnReceivedTMMBR(); 437 438 // Bad state of RTP receiver request a keyframe. 439 void OnRequestIntraFrame(); 440 441 // Received a request for a new SLI. 442 void OnReceivedSliceLossIndication(const uint8_t picture_id); 443 444 // Received a new reference frame. 445 void OnReceivedReferencePictureSelectionIndication( 446 const uint64_t picture_id); 447 448 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers); 449 450 void OnRequestSendReport(); 451 452 protected: 453 void RegisterChildModule(RtpRtcp* module); 454 455 void DeRegisterChildModule(RtpRtcp* module); 456 457 bool UpdateRTCPReceiveInformationTimers(); 458 459 void ProcessDeadOrAliveTimer(); 460 461 uint32_t BitrateReceivedNow() const; 462 463 // Get remote SequenceNumber. 464 uint16_t RemoteSequenceNumber() const; 465 466 // Only for internal testing. 467 uint32_t LastSendReport(uint32_t& last_rtcptime); 468 469 RTPPayloadRegistry rtp_payload_registry_; 470 471 RTPSender rtp_sender_; 472 scoped_ptr<RTPReceiver> rtp_receiver_; 473 474 RTCPSender rtcp_sender_; 475 RTCPReceiver rtcp_receiver_; 476 477 Clock* clock_; 478 479 private: 480 int64_t RtcpReportInterval(); 481 482 RTPReceiverAudio* rtp_telephone_event_handler_; 483 484 int32_t id_; 485 const bool audio_; 486 bool collision_detected_; 487 int64_t last_process_time_; 488 int64_t last_bitrate_process_time_; 489 int64_t last_packet_timeout_process_time_; 490 int64_t last_rtt_process_time_; 491 uint16_t packet_overhead_; 492 493 scoped_ptr<CriticalSectionWrapper> critical_section_module_ptrs_; 494 scoped_ptr<CriticalSectionWrapper> critical_section_module_ptrs_feedback_; 495 ModuleRtpRtcpImpl* default_module_; 496 std::list<ModuleRtpRtcpImpl*> child_modules_; 497 498 // Dead or alive. 499 bool dead_or_alive_active_; 500 uint32_t dead_or_alive_timeout_ms_; 501 int64_t dead_or_alive_last_timer_; 502 // Send side 503 NACKMethod nack_method_; 504 uint32_t nack_last_time_sent_full_; 505 uint16_t nack_last_seq_number_sent_; 506 507 bool simulcast_; 508 VideoCodec send_video_codec_; 509 KeyFrameRequestMethod key_frame_req_method_; 510 511 RemoteBitrateEstimator* remote_bitrate_; 512 513#ifdef MATLAB 514 MatlabPlot* plot1_; 515#endif 516 517 RtcpRttObserver* rtt_observer_; 518}; 519 520} // namespace webrtc 521 522#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RTCP_IMPL_H_ 523