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