rtp_rtcp_impl.h revision 71f055fb41336316324942f828e022e2f7d93ec7
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_sender.h" 21#include "webrtc/system_wrappers/interface/scoped_ptr.h" 22#include "webrtc/test/testsupport/gtest_prod_util.h" 23 24#ifdef MATLAB 25class MatlabPlot; 26#endif 27 28namespace webrtc { 29 30class ModuleRtpRtcpImpl : public RtpRtcp { 31 public: 32 explicit ModuleRtpRtcpImpl(const RtpRtcp::Configuration& configuration); 33 34 virtual ~ModuleRtpRtcpImpl(); 35 36 // Returns the number of milliseconds until the module want a worker thread to 37 // call Process. 38 virtual int32_t TimeUntilNextProcess() OVERRIDE; 39 40 // Process any pending tasks such as timeouts. 41 virtual int32_t Process() OVERRIDE; 42 43 // Receiver part. 44 45 // Called when we receive an RTCP packet. 46 virtual int32_t IncomingRtcpPacket(const uint8_t* incoming_packet, 47 uint16_t incoming_packet_length) OVERRIDE; 48 49 virtual void SetRemoteSSRC(const uint32_t ssrc); 50 51 // Sender part. 52 53 virtual int32_t RegisterSendPayload(const CodecInst& voice_codec) OVERRIDE; 54 55 virtual int32_t RegisterSendPayload(const VideoCodec& video_codec) OVERRIDE; 56 57 virtual int32_t DeRegisterSendPayload(const int8_t payload_type) OVERRIDE; 58 59 virtual int8_t SendPayloadType() const; 60 61 // Register RTP header extension. 62 virtual int32_t RegisterSendRtpHeaderExtension( 63 const RTPExtensionType type, 64 const uint8_t id) OVERRIDE; 65 66 virtual int32_t DeregisterSendRtpHeaderExtension( 67 const RTPExtensionType type) OVERRIDE; 68 69 // Get start timestamp. 70 virtual uint32_t StartTimestamp() const OVERRIDE; 71 72 // Configure start timestamp, default is a random number. 73 virtual int32_t SetStartTimestamp(const uint32_t timestamp) OVERRIDE; 74 75 virtual uint16_t SequenceNumber() const OVERRIDE; 76 77 // Set SequenceNumber, default is a random number. 78 virtual int32_t SetSequenceNumber(const uint16_t seq) OVERRIDE; 79 80 virtual uint32_t SSRC() const OVERRIDE; 81 82 // Configure SSRC, default is a random number. 83 virtual int32_t SetSSRC(const uint32_t ssrc) OVERRIDE; 84 85 virtual int32_t CSRCs(uint32_t arr_of_csrc[kRtpCsrcSize]) const OVERRIDE; 86 87 virtual int32_t SetCSRCs(const uint32_t arr_of_csrc[kRtpCsrcSize], 88 const uint8_t arr_length) OVERRIDE; 89 90 virtual int32_t SetCSRCStatus(const bool include) OVERRIDE; 91 92 virtual uint32_t PacketCountSent() const; 93 94 virtual int CurrentSendFrequencyHz() const; 95 96 virtual uint32_t ByteCountSent() const; 97 98 virtual int32_t SetRTXSendStatus(const int mode, 99 const bool set_ssrc, 100 const uint32_t ssrc) OVERRIDE; 101 102 virtual int32_t RTXSendStatus(int* mode, uint32_t* ssrc, 103 int* payloadType) const OVERRIDE; 104 105 106 virtual void SetRtxSendPayloadType(int payload_type) OVERRIDE; 107 108 // Sends kRtcpByeCode when going from true to false. 109 virtual int32_t SetSendingStatus(const bool sending) OVERRIDE; 110 111 virtual bool Sending() const OVERRIDE; 112 113 // Drops or relays media packets. 114 virtual int32_t SetSendingMediaStatus(const bool sending) OVERRIDE; 115 116 virtual bool SendingMedia() const OVERRIDE; 117 118 // Used by the codec module to deliver a video or audio frame for 119 // packetization. 120 virtual int32_t SendOutgoingData( 121 const FrameType frame_type, 122 const int8_t payload_type, 123 const uint32_t time_stamp, 124 int64_t capture_time_ms, 125 const uint8_t* payload_data, 126 const uint32_t payload_size, 127 const RTPFragmentationHeader* fragmentation = NULL, 128 const RTPVideoHeader* rtp_video_hdr = NULL) OVERRIDE; 129 130 virtual bool TimeToSendPacket(uint32_t ssrc, 131 uint16_t sequence_number, 132 int64_t capture_time_ms, 133 bool retransmission) OVERRIDE; 134 // Returns the number of padding bytes actually sent, which can be more or 135 // less than |bytes|. 136 virtual int TimeToSendPadding(int bytes) OVERRIDE; 137 // RTCP part. 138 139 // Get RTCP status. 140 virtual RTCPMethod RTCP() const OVERRIDE; 141 142 // Configure RTCP status i.e on/off. 143 virtual int32_t SetRTCPStatus(const RTCPMethod method) OVERRIDE; 144 145 // Set RTCP CName. 146 virtual int32_t SetCNAME(const char c_name[RTCP_CNAME_SIZE]) OVERRIDE; 147 148 // Get RTCP CName. 149 virtual int32_t CNAME(char c_name[RTCP_CNAME_SIZE]) OVERRIDE; 150 151 // Get remote CName. 152 virtual int32_t RemoteCNAME(const uint32_t remote_ssrc, 153 char c_name[RTCP_CNAME_SIZE]) const OVERRIDE; 154 155 // Get remote NTP. 156 virtual int32_t RemoteNTP(uint32_t* received_ntp_secs, 157 uint32_t* received_ntp_frac, 158 uint32_t* rtcp_arrival_time_secs, 159 uint32_t* rtcp_arrival_time_frac, 160 uint32_t* rtcp_timestamp) const OVERRIDE; 161 162 virtual int32_t AddMixedCNAME(const uint32_t ssrc, 163 const char c_name[RTCP_CNAME_SIZE]) OVERRIDE; 164 165 virtual int32_t RemoveMixedCNAME(const uint32_t ssrc) OVERRIDE; 166 167 // Get RoundTripTime. 168 virtual int32_t RTT(const uint32_t remote_ssrc, 169 uint16_t* rtt, 170 uint16_t* avg_rtt, 171 uint16_t* min_rtt, 172 uint16_t* max_rtt) const OVERRIDE; 173 174 // Reset RoundTripTime statistics. 175 virtual int32_t ResetRTT(const uint32_t remote_ssrc) OVERRIDE; 176 177 // Force a send of an RTCP packet. 178 // Normal SR and RR are triggered via the process function. 179 virtual int32_t SendRTCP(uint32_t rtcp_packet_type = kRtcpReport) OVERRIDE; 180 181 virtual int32_t ResetSendDataCountersRTP() OVERRIDE; 182 183 // Statistics of the amount of data sent and received. 184 virtual int32_t DataCountersRTP(uint32_t* bytes_sent, 185 uint32_t* packets_sent) const OVERRIDE; 186 187 // Get received RTCP report, sender info. 188 virtual int32_t RemoteRTCPStat(RTCPSenderInfo* sender_info) OVERRIDE; 189 190 // Get received RTCP report, report block. 191 virtual int32_t RemoteRTCPStat( 192 std::vector<RTCPReportBlock>* receive_blocks) const OVERRIDE; 193 194 // Set received RTCP report block. 195 virtual int32_t AddRTCPReportBlock( 196 const uint32_t ssrc, const RTCPReportBlock* receive_block) OVERRIDE; 197 198 virtual int32_t RemoveRTCPReportBlock(const uint32_t ssrc) OVERRIDE; 199 200 // (REMB) Receiver Estimated Max Bitrate. 201 virtual bool REMB() const OVERRIDE; 202 203 virtual int32_t SetREMBStatus(const bool enable) OVERRIDE; 204 205 virtual int32_t SetREMBData(const uint32_t bitrate, 206 const uint8_t number_of_ssrc, 207 const uint32_t* ssrc) OVERRIDE; 208 209 // (IJ) Extended jitter report. 210 virtual bool IJ() const OVERRIDE; 211 212 virtual int32_t SetIJStatus(const bool enable) OVERRIDE; 213 214 // (TMMBR) Temporary Max Media Bit Rate. 215 virtual bool TMMBR() const OVERRIDE; 216 217 virtual int32_t SetTMMBRStatus(const bool enable) OVERRIDE; 218 219 int32_t SetTMMBN(const TMMBRSet* bounding_set); 220 221 virtual uint16_t MaxPayloadLength() const OVERRIDE; 222 223 virtual uint16_t MaxDataPayloadLength() const OVERRIDE; 224 225 virtual int32_t SetMaxTransferUnit(const uint16_t size) OVERRIDE; 226 227 virtual int32_t SetTransportOverhead( 228 const bool tcp, 229 const bool ipv6, 230 const uint8_t authentication_overhead = 0) OVERRIDE; 231 232 // (NACK) Negative acknowledgment part. 233 234 virtual int SelectiveRetransmissions() const OVERRIDE; 235 236 virtual int SetSelectiveRetransmissions(uint8_t settings) OVERRIDE; 237 238 // Send a Negative acknowledgment packet. 239 virtual int32_t SendNACK(const uint16_t* nack_list, 240 const uint16_t size) OVERRIDE; 241 242 // Store the sent packets, needed to answer to a negative acknowledgment 243 // requests. 244 virtual int32_t SetStorePacketsStatus( 245 const bool enable, const uint16_t number_to_store) OVERRIDE; 246 247 virtual bool StorePackets() const OVERRIDE; 248 249 // (APP) Application specific data. 250 virtual int32_t SetRTCPApplicationSpecificData( 251 const uint8_t sub_type, 252 const uint32_t name, 253 const uint8_t* data, 254 const uint16_t length) OVERRIDE; 255 256 // (XR) VOIP metric. 257 virtual int32_t SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric) OVERRIDE; 258 259 // (XR) Receiver reference time report. 260 virtual void SetRtcpXrRrtrStatus(bool enable) OVERRIDE; 261 262 virtual bool RtcpXrRrtrStatus() const OVERRIDE; 263 264 // Audio part. 265 266 // Set audio packet size, used to determine when it's time to send a DTMF 267 // packet in silence (CNG). 268 virtual int32_t SetAudioPacketSize( 269 const uint16_t packet_size_samples) OVERRIDE; 270 271 virtual bool SendTelephoneEventActive(int8_t& telephone_event) const OVERRIDE; 272 273 // Send a TelephoneEvent tone using RFC 2833 (4733). 274 virtual int32_t SendTelephoneEventOutband(const uint8_t key, 275 const uint16_t time_ms, 276 const uint8_t level) OVERRIDE; 277 278 // Set payload type for Redundant Audio Data RFC 2198. 279 virtual int32_t SetSendREDPayloadType(const int8_t payload_type) OVERRIDE; 280 281 // Get payload type for Redundant Audio Data RFC 2198. 282 virtual int32_t SendREDPayloadType(int8_t& payload_type) const OVERRIDE; 283 284 // Set status and id for header-extension-for-audio-level-indication. 285 virtual int32_t SetRTPAudioLevelIndicationStatus( 286 const bool enable, const uint8_t id) OVERRIDE; 287 288 // Get status and id for header-extension-for-audio-level-indication. 289 virtual int32_t GetRTPAudioLevelIndicationStatus( 290 bool& enable, uint8_t& id) const OVERRIDE; 291 292 // Store the audio level in d_bov for header-extension-for-audio-level- 293 // indication. 294 virtual int32_t SetAudioLevel(const uint8_t level_d_bov) OVERRIDE; 295 296 // Video part. 297 298 virtual RtpVideoCodecTypes SendVideoCodec() const; 299 300 virtual int32_t SendRTCPSliceLossIndication( 301 const uint8_t picture_id) OVERRIDE; 302 303 // Set method for requestion a new key frame. 304 virtual int32_t SetKeyFrameRequestMethod( 305 const KeyFrameRequestMethod method) OVERRIDE; 306 307 // Send a request for a keyframe. 308 virtual int32_t RequestKeyFrame() OVERRIDE; 309 310 virtual int32_t SetCameraDelay(const int32_t delay_ms) OVERRIDE; 311 312 virtual void SetTargetSendBitrate( 313 const std::vector<uint32_t>& stream_bitrates) OVERRIDE; 314 315 virtual int32_t SetGenericFECStatus( 316 const bool enable, 317 const uint8_t payload_type_red, 318 const uint8_t payload_type_fec) OVERRIDE; 319 320 virtual int32_t GenericFECStatus( 321 bool& enable, 322 uint8_t& payload_type_red, 323 uint8_t& payload_type_fec) OVERRIDE; 324 325 virtual int32_t SetFecParameters( 326 const FecProtectionParams* delta_params, 327 const FecProtectionParams* key_params) OVERRIDE; 328 329 virtual int32_t LastReceivedNTP(uint32_t& NTPsecs, 330 uint32_t& NTPfrac, 331 uint32_t& remote_sr); 332 333 virtual bool LastReceivedXrReferenceTimeInfo(RtcpReceiveTimeInfo* info) const; 334 335 virtual int32_t BoundingSet(bool& tmmbr_owner, TMMBRSet*& bounding_set_rec); 336 337 virtual void BitrateSent(uint32_t* total_rate, 338 uint32_t* video_rate, 339 uint32_t* fec_rate, 340 uint32_t* nackRate) const OVERRIDE; 341 342 virtual uint32_t SendTimeOfSendReport(const uint32_t send_report); 343 344 virtual bool SendTimeOfXrRrReport(uint32_t mid_ntp, int64_t* time_ms) const; 345 346 // Good state of RTP receiver inform sender. 347 virtual int32_t SendRTCPReferencePictureSelection( 348 const uint64_t picture_id) OVERRIDE; 349 350 void OnReceivedTMMBR(); 351 352 // Bad state of RTP receiver request a keyframe. 353 void OnRequestIntraFrame(); 354 355 // Received a request for a new SLI. 356 void OnReceivedSliceLossIndication(const uint8_t picture_id); 357 358 // Received a new reference frame. 359 void OnReceivedReferencePictureSelectionIndication( 360 const uint64_t picture_id); 361 362 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers); 363 364 void OnRequestSendReport(); 365 366 virtual void RegisterSendFrameCountObserver( 367 FrameCountObserver* observer) OVERRIDE; 368 virtual FrameCountObserver* GetSendFrameCountObserver() const OVERRIDE; 369 370 protected: 371 void RegisterChildModule(RtpRtcp* module); 372 373 void DeRegisterChildModule(RtpRtcp* module); 374 375 bool UpdateRTCPReceiveInformationTimers(); 376 377 uint32_t BitrateReceivedNow() const; 378 379 // Get remote SequenceNumber. 380 uint16_t RemoteSequenceNumber() const; 381 382 // Only for internal testing. 383 uint32_t LastSendReport(uint32_t& last_rtcptime); 384 385 RTPSender rtp_sender_; 386 387 RTCPSender rtcp_sender_; 388 RTCPReceiver rtcp_receiver_; 389 390 Clock* clock_; 391 392 private: 393 FRIEND_TEST_ALL_PREFIXES(RtpRtcpImplTest, RttForReceiverOnly); 394 int64_t RtcpReportInterval(); 395 void SetRtcpReceiverSsrcs(uint32_t main_ssrc); 396 397 void set_rtt_ms(uint32_t rtt_ms); 398 uint32_t rtt_ms() const; 399 400 int32_t id_; 401 const bool audio_; 402 bool collision_detected_; 403 int64_t last_process_time_; 404 int64_t last_bitrate_process_time_; 405 int64_t last_rtt_process_time_; 406 uint16_t packet_overhead_; 407 408 scoped_ptr<CriticalSectionWrapper> critical_section_module_ptrs_; 409 scoped_ptr<CriticalSectionWrapper> critical_section_module_ptrs_feedback_; 410 ModuleRtpRtcpImpl* default_module_; 411 std::list<ModuleRtpRtcpImpl*> child_modules_; 412 413 // Send side 414 NACKMethod nack_method_; 415 uint32_t nack_last_time_sent_full_; 416 uint16_t nack_last_seq_number_sent_; 417 418 bool simulcast_; 419 VideoCodec send_video_codec_; 420 KeyFrameRequestMethod key_frame_req_method_; 421 422 RemoteBitrateEstimator* remote_bitrate_; 423 424#ifdef MATLAB 425 MatlabPlot* plot1_; 426#endif 427 428 RtcpRttStats* rtt_stats_; 429 430 // The processed RTT from RtcpRttStats. 431 scoped_ptr<CriticalSectionWrapper> critical_section_rtt_; 432 uint32_t rtt_ms_; 433}; 434 435} // namespace webrtc 436 437#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RTCP_IMPL_H_ 438