[rtp_rtcp] lint errors about rand() usage fixed.
rand() usage replaced with new Random class, which also makes it clearer what interval random number is in. BUG=webrtc:5277 R=mflodman Review URL: https://codereview.webrtc.org/1519503002 Cr-Commit-Position: refs/heads/master@{#11019}
This commit is contained in:
@ -11,7 +11,6 @@
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h"
|
||||
|
||||
#include <assert.h> // assert
|
||||
#include <stdlib.h> // rand
|
||||
#include <string.h> // memcpy
|
||||
|
||||
#include <algorithm> // min
|
||||
@ -141,6 +140,7 @@ RTCPSender::RTCPSender(
|
||||
Transport* outgoing_transport)
|
||||
: audio_(audio),
|
||||
clock_(clock),
|
||||
random_(clock_->TimeInMicroseconds()),
|
||||
method_(RtcpMode::kOff),
|
||||
transport_(outgoing_transport),
|
||||
|
||||
@ -914,15 +914,9 @@ void RTCPSender::PrepareReport(const std::set<RTCPPacketType>& packetTypes,
|
||||
SetFlag(kRtcpXrDlrrReportBlock, true);
|
||||
|
||||
// generate next time to send an RTCP report
|
||||
// seeded from RTP constructor
|
||||
int32_t random = rand() % 1000;
|
||||
int32_t timeToNext = RTCP_INTERVAL_AUDIO_MS;
|
||||
uint32_t minIntervalMs = RTCP_INTERVAL_AUDIO_MS;
|
||||
|
||||
if (audio_) {
|
||||
timeToNext = (RTCP_INTERVAL_AUDIO_MS / 2) +
|
||||
(RTCP_INTERVAL_AUDIO_MS * random / 1000);
|
||||
} else {
|
||||
uint32_t minIntervalMs = RTCP_INTERVAL_AUDIO_MS;
|
||||
if (!audio_) {
|
||||
if (sending_) {
|
||||
// Calculate bandwidth for video; 360 / send bandwidth in kbit/s.
|
||||
uint32_t send_bitrate_kbit = feedback_state.send_bitrate / 1000;
|
||||
@ -931,8 +925,11 @@ void RTCPSender::PrepareReport(const std::set<RTCPPacketType>& packetTypes,
|
||||
}
|
||||
if (minIntervalMs > RTCP_INTERVAL_VIDEO_MS)
|
||||
minIntervalMs = RTCP_INTERVAL_VIDEO_MS;
|
||||
timeToNext = (minIntervalMs / 2) + (minIntervalMs * random / 1000);
|
||||
}
|
||||
// The interval between RTCP packets is varied randomly over the
|
||||
// range [1/2,3/2] times the calculated interval.
|
||||
uint32_t timeToNext =
|
||||
random_.Rand(minIntervalMs * 1 / 2, minIntervalMs * 3 / 2);
|
||||
next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + timeToNext;
|
||||
|
||||
StatisticianMap statisticians =
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/random.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/base/thread_annotations.h"
|
||||
#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
|
||||
@ -202,6 +203,7 @@ class RTCPSender {
|
||||
private:
|
||||
const bool audio_;
|
||||
Clock* const clock_;
|
||||
Random random_ GUARDED_BY(critical_section_rtcp_sender_);
|
||||
RtcpMode method_ GUARDED_BY(critical_section_rtcp_sender_);
|
||||
|
||||
Transport* const transport_;
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <list>
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "webrtc/base/random.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
|
||||
|
||||
@ -41,8 +42,12 @@ template <typename T> void ClearList(std::list<T*>* my_list) {
|
||||
class RtpFecTest : public ::testing::Test {
|
||||
protected:
|
||||
RtpFecTest()
|
||||
: fec_(new ForwardErrorCorrection()), ssrc_(rand()), fec_seq_num_(0) {}
|
||||
: random_(0xfec133700742),
|
||||
fec_(new ForwardErrorCorrection()),
|
||||
ssrc_(random_.Rand<uint32_t>()),
|
||||
fec_seq_num_(0) {}
|
||||
|
||||
webrtc::Random random_;
|
||||
ForwardErrorCorrection* fec_;
|
||||
int ssrc_;
|
||||
uint16_t fec_seq_num_;
|
||||
@ -891,22 +896,20 @@ int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets,
|
||||
assert(num_media_packets > 0);
|
||||
ForwardErrorCorrection::Packet* media_packet = NULL;
|
||||
int sequence_number = start_seq_num;
|
||||
int time_stamp = rand();
|
||||
int time_stamp = random_.Rand<int>();
|
||||
|
||||
for (int i = 0; i < num_media_packets; ++i) {
|
||||
media_packet = new ForwardErrorCorrection::Packet;
|
||||
media_packet_list_.push_back(media_packet);
|
||||
media_packet->length = static_cast<size_t>(
|
||||
(static_cast<float>(rand()) / RAND_MAX) *
|
||||
(IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead -
|
||||
ForwardErrorCorrection::PacketOverhead()));
|
||||
const uint32_t kMinPacketSize = kRtpHeaderSize;
|
||||
const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize -
|
||||
kTransportOverhead -
|
||||
ForwardErrorCorrection::PacketOverhead();
|
||||
media_packet->length = random_.Rand(kMinPacketSize, kMaxPacketSize);
|
||||
|
||||
if (media_packet->length < kRtpHeaderSize) {
|
||||
media_packet->length = kRtpHeaderSize;
|
||||
}
|
||||
// Generate random values for the first 2 bytes
|
||||
media_packet->data[0] = static_cast<uint8_t>(rand() % 256);
|
||||
media_packet->data[1] = static_cast<uint8_t>(rand() % 256);
|
||||
media_packet->data[0] = random_.Rand<uint8_t>();
|
||||
media_packet->data[1] = random_.Rand<uint8_t>();
|
||||
|
||||
// The first two bits are assumed to be 10 by the FEC encoder.
|
||||
// In fact the FEC decoder will set the two first bits to 10 regardless of
|
||||
@ -929,7 +932,7 @@ int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets,
|
||||
|
||||
// Generate random values for payload.
|
||||
for (size_t j = 12; j < media_packet->length; ++j) {
|
||||
media_packet->data[j] = static_cast<uint8_t>(rand() % 256);
|
||||
media_packet->data[j] = random_.Rand<uint8_t>();
|
||||
}
|
||||
sequence_number++;
|
||||
}
|
||||
@ -940,5 +943,5 @@ int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets,
|
||||
}
|
||||
|
||||
int RtpFecTest::ConstructMediaPackets(int num_media_packets) {
|
||||
return ConstructMediaPacketsSeqNum(num_media_packets, rand());
|
||||
return ConstructMediaPacketsSeqNum(num_media_packets, random_.Rand<int>());
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ static const uint32_t kAbsSendTimeFraction = 18;
|
||||
namespace {
|
||||
|
||||
const size_t kRtpHeaderLength = 12;
|
||||
const uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1.
|
||||
|
||||
const char* FrameTypeToString(FrameType frame_type) {
|
||||
switch (frame_type) {
|
||||
@ -126,6 +127,7 @@ RTPSender::RTPSender(
|
||||
// TickTime.
|
||||
clock_delta_ms_(clock_->TimeInMilliseconds() -
|
||||
TickTime::MillisecondTimestamp()),
|
||||
random_(clock_->TimeInMicroseconds()),
|
||||
bitrates_(new BitrateAggregator(bitrate_callback)),
|
||||
total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()),
|
||||
audio_configured_(audio),
|
||||
@ -183,8 +185,8 @@ RTPSender::RTPSender(
|
||||
ssrc_rtx_ = ssrc_db_.CreateSSRC(); // Can't be 0.
|
||||
bitrates_->set_ssrc(ssrc_);
|
||||
// Random start, 16 bits. Can't be 0.
|
||||
sequence_number_rtx_ = static_cast<uint16_t>(rand() + 1) & 0x7FFF;
|
||||
sequence_number_ = static_cast<uint16_t>(rand() + 1) & 0x7FFF;
|
||||
sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
||||
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
||||
}
|
||||
|
||||
RTPSender::~RTPSender() {
|
||||
@ -1656,8 +1658,7 @@ void RTPSender::SetSendingStatus(bool enabled) {
|
||||
// Don't initialize seq number if SSRC passed externally.
|
||||
if (!sequence_number_forced_ && !ssrc_forced_) {
|
||||
// Generate a new sequence number.
|
||||
sequence_number_ =
|
||||
rand() / (RAND_MAX / MAX_INIT_RTP_SEQ_NUMBER); // NOLINT
|
||||
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1719,8 +1720,7 @@ void RTPSender::SetSSRC(uint32_t ssrc) {
|
||||
ssrc_ = ssrc;
|
||||
bitrates_->set_ssrc(ssrc_);
|
||||
if (!sequence_number_forced_) {
|
||||
sequence_number_ =
|
||||
rand() / (RAND_MAX / MAX_INIT_RTP_SEQ_NUMBER); // NOLINT
|
||||
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/random.h"
|
||||
#include "webrtc/base/thread_annotations.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
@ -27,8 +28,6 @@
|
||||
#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
|
||||
#include "webrtc/transport.h"
|
||||
|
||||
#define MAX_INIT_RTP_SEQ_NUMBER 32767 // 2^15 -1.
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class BitrateAggregator;
|
||||
@ -387,6 +386,7 @@ class RTPSender : public RTPSenderInterface {
|
||||
|
||||
Clock* clock_;
|
||||
int64_t clock_delta_ms_;
|
||||
Random random_ GUARDED_BY(send_critsect_);
|
||||
|
||||
rtc::scoped_ptr<BitrateAggregator> bitrates_;
|
||||
Bitrate total_bitrate_sent_;
|
||||
|
||||
Reference in New Issue
Block a user