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