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