Use int64_t more consistently for times, in particular for RTT values.

Existing code was inconsistent about whether to use uint16_t, int, unsigned int,
or uint32_t, and sometimes silently truncated one to another, or truncated
int64_t.  Because most core time-handling functions use int64_t, being
consistent about using int64_t unless otherwise necessary minimizes the number
of explicit or implicit casts.

BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, holmer@google.com, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/31349004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@8045 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pkasting@chromium.org
2015-01-12 21:51:21 +00:00
parent a7add19cf4
commit 16825b1a82
124 changed files with 422 additions and 417 deletions

View File

@ -106,7 +106,7 @@ VCMGenericEncoder::Encode(const I420VideoFrame& inputFrame,
}
int32_t
VCMGenericEncoder::SetChannelParameters(int32_t packetLoss, int rtt)
VCMGenericEncoder::SetChannelParameters(int32_t packetLoss, int64_t rtt)
{
return _encoder.SetChannelParameters(packetLoss, rtt);
}

View File

@ -103,7 +103,7 @@ public:
/**
* Set a new packet loss rate and a new round-trip time in milliseconds.
*/
int32_t SetChannelParameters(int32_t packetLoss, int rtt);
int32_t SetChannelParameters(int32_t packetLoss, int64_t rtt);
int32_t CodecConfigParameters(uint8_t* buffer, int32_t size);
/**
* Register a transport callback which will be called to deliver the encoded

View File

@ -31,7 +31,7 @@
namespace webrtc {
// Use this rtt if no value has been reported.
static const uint32_t kDefaultRtt = 200;
static const int64_t kDefaultRtt = 200;
typedef std::pair<uint32_t, VCMFrameBuffer*> FrameListPair;
@ -783,7 +783,7 @@ uint32_t VCMJitterBuffer::EstimatedJitterMs() {
// low_rtt_nackThresholdMs_ == -1 means no FEC.
double rtt_mult = 1.0f;
if (low_rtt_nack_threshold_ms_ >= 0 &&
static_cast<int>(rtt_ms_) >= low_rtt_nack_threshold_ms_) {
rtt_ms_ >= low_rtt_nack_threshold_ms_) {
// For RTTs above low_rtt_nack_threshold_ms_ we don't apply extra delay
// when waiting for retransmissions.
rtt_mult = 0.0f;
@ -791,15 +791,15 @@ uint32_t VCMJitterBuffer::EstimatedJitterMs() {
return jitter_estimate_.GetJitterEstimate(rtt_mult);
}
void VCMJitterBuffer::UpdateRtt(uint32_t rtt_ms) {
void VCMJitterBuffer::UpdateRtt(int64_t rtt_ms) {
CriticalSectionScoped cs(crit_sect_);
rtt_ms_ = rtt_ms;
jitter_estimate_.UpdateRtt(rtt_ms);
}
void VCMJitterBuffer::SetNackMode(VCMNackMode mode,
int low_rtt_nack_threshold_ms,
int high_rtt_nack_threshold_ms) {
int64_t low_rtt_nack_threshold_ms,
int64_t high_rtt_nack_threshold_ms) {
CriticalSectionScoped cs(crit_sect_);
nack_mode_ = mode;
if (mode == kNoNack) {
@ -1214,7 +1214,7 @@ bool VCMJitterBuffer::WaitForRetransmissions() {
// Evaluate if the RTT is higher than |high_rtt_nack_threshold_ms_|, and in
// that case we don't wait for retransmissions.
if (high_rtt_nack_threshold_ms_ >= 0 &&
rtt_ms_ >= static_cast<unsigned int>(high_rtt_nack_threshold_ms_)) {
rtt_ms_ >= high_rtt_nack_threshold_ms_) {
return false;
}
return true;

View File

@ -153,7 +153,7 @@ class VCMJitterBuffer {
uint32_t EstimatedJitterMs();
// Updates the round-trip time estimate.
void UpdateRtt(uint32_t rtt_ms);
void UpdateRtt(int64_t rtt_ms);
// Set the NACK mode. |highRttNackThreshold| is an RTT threshold in ms above
// which NACK will be disabled if the NACK mode is |kNackHybrid|, -1 meaning
@ -161,8 +161,8 @@ class VCMJitterBuffer {
// |lowRttNackThreshold| is an RTT threshold in ms below which we expect to
// rely on NACK only, and therefore are using larger buffers to have time to
// wait for retransmissions.
void SetNackMode(VCMNackMode mode, int low_rtt_nack_threshold_ms,
int high_rtt_nack_threshold_ms);
void SetNackMode(VCMNackMode mode, int64_t low_rtt_nack_threshold_ms,
int64_t high_rtt_nack_threshold_ms);
void SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack,
@ -331,12 +331,12 @@ class VCMJitterBuffer {
// Calculates network delays used for jitter calculations.
VCMInterFrameDelay inter_frame_delay_;
VCMJitterSample waiting_for_completion_;
uint32_t rtt_ms_;
int64_t rtt_ms_;
// NACK and retransmissions.
VCMNackMode nack_mode_;
int low_rtt_nack_threshold_ms_;
int high_rtt_nack_threshold_ms_;
int64_t low_rtt_nack_threshold_ms_;
int64_t high_rtt_nack_threshold_ms_;
// Holds the internal NACK list (the missing sequence numbers).
SequenceNumberSet missing_sequence_numbers_;
uint16_t latest_received_sequence_number_;

View File

@ -406,7 +406,7 @@ VCMJitterEstimator::PostProcessEstimate()
}
void
VCMJitterEstimator::UpdateRtt(uint32_t rttMs)
VCMJitterEstimator::UpdateRtt(int64_t rttMs)
{
_rttFilter.Update(rttMs);
}

View File

@ -59,7 +59,7 @@ public:
//
// Input:
// - rttMs : RTT in ms
void UpdateRtt(uint32_t rttMs);
void UpdateRtt(int64_t rttMs);
void UpdateMaxFrameSize(uint32_t frameSizeBytes);

View File

@ -53,8 +53,8 @@ VCMProtectionMethod::UpdateContentMetrics(const
_qmRobustness->UpdateContent(contentMetrics);
}
VCMNackFecMethod::VCMNackFecMethod(int lowRttNackThresholdMs,
int highRttNackThresholdMs)
VCMNackFecMethod::VCMNackFecMethod(int64_t lowRttNackThresholdMs,
int64_t highRttNackThresholdMs)
: VCMFecMethod(),
_lowRttNackMs(lowRttNackThresholdMs),
_highRttNackMs(highRttNackThresholdMs),
@ -159,6 +159,8 @@ bool VCMNackFecMethod::BitRateTooLowForFec(
}
// TODO (marpan): add condition based on maximum frames used for FEC,
// and expand condition based on frame size.
// Max round trip time threshold in ms.
const int64_t kMaxRttTurnOffFec = 200;
if (estimate_bytes_per_frame < max_bytes_per_frame &&
parameters->numLayers < 3 &&
parameters->rtt < kMaxRttTurnOffFec) {
@ -737,7 +739,7 @@ VCMLossProtectionLogic::RequiredBitRate() const
}
void
VCMLossProtectionLogic::UpdateRtt(uint32_t rtt)
VCMLossProtectionLogic::UpdateRtt(int64_t rtt)
{
_rtt = rtt;
}

View File

@ -41,10 +41,7 @@ enum FilterPacketLossMode {
// Thresholds for hybrid NACK/FEC
// common to media optimization and the jitter buffer.
enum HybridNackTH {
kHighRttNackMs = 100,
kLowRttNackMs = 20
};
const int64_t kLowRttNackMs = 20;
struct VCMProtectionParameters
{
@ -55,7 +52,7 @@ struct VCMProtectionParameters
numLayers(1)
{}
int rtt;
int64_t rtt;
float lossPr;
float bitRate;
float packetsPerFrame;
@ -211,16 +208,14 @@ protected:
enum { kMaxBytesPerFrameForFecLow = 400 };
// Max bytes/frame for frame size larger than VGA, ~200k at 25fps.
enum { kMaxBytesPerFrameForFecHigh = 1000 };
// Max round trip time threshold in ms.
enum { kMaxRttTurnOffFec = 200 };
};
class VCMNackFecMethod : public VCMFecMethod
{
public:
VCMNackFecMethod(int lowRttNackThresholdMs,
int highRttNackThresholdMs);
VCMNackFecMethod(int64_t lowRttNackThresholdMs,
int64_t highRttNackThresholdMs);
virtual ~VCMNackFecMethod();
virtual bool UpdateParameters(const VCMProtectionParameters* parameters);
// Get the effective packet loss for ER
@ -234,8 +229,8 @@ public:
private:
int ComputeMaxFramesFec(const VCMProtectionParameters* parameters);
int _lowRttNackMs;
int _highRttNackMs;
int64_t _lowRttNackMs;
int64_t _highRttNackMs;
int _maxFramesFec;
};
@ -267,7 +262,7 @@ public:
//
// Input:
// - rtt : Round-trip time in seconds.
void UpdateRtt(uint32_t rtt);
void UpdateRtt(int64_t rtt);
// Update residual packet loss
//
@ -369,7 +364,7 @@ private:
uint8_t MaxFilteredLossPr(int64_t nowMs) const;
VCMProtectionMethod* _selectedMethod;
VCMProtectionParameters _currentParameters;
uint32_t _rtt;
int64_t _rtt;
float _lossPr;
float _bitRate;
float _frameRate;

View File

@ -200,7 +200,7 @@ void MediaOptimization::SetEncodingDataInternal(VideoCodecType send_codec_type,
uint32_t MediaOptimization::SetTargetRates(
uint32_t target_bitrate,
uint8_t fraction_lost,
uint32_t round_trip_time_ms,
int64_t round_trip_time_ms,
VCMProtectionCallback* protection_callback,
VCMQMSettingsCallback* qmsettings_callback) {
CriticalSectionScoped lock(crit_sect_.get());

View File

@ -58,7 +58,7 @@ class MediaOptimization {
// an internal critical section.
uint32_t SetTargetRates(uint32_t target_bitrate,
uint8_t fraction_lost,
uint32_t round_trip_time_ms,
int64_t round_trip_time_ms,
VCMProtectionCallback* protection_callback,
VCMQMSettingsCallback* qmsettings_callback);

View File

@ -15,9 +15,8 @@ namespace webrtc
{
// Table for adjusting FEC rate for NACK/FEC protection method
// Table values are built as a sigmoid function, ranging from 0 to
// kHighRttNackMs (100), based on the HybridNackTH values defined in
// media_opt_util.h.
// Table values are built as a sigmoid function, ranging from 0 to 100, based on
// the HybridNackTH values defined in media_opt_util.h.
const uint16_t VCMNackFecTable[100] = {
0,
0,

View File

@ -925,7 +925,7 @@ void VCMQmRobustness::Reset() {
float VCMQmRobustness::AdjustFecFactor(uint8_t code_rate_delta,
float total_rate,
float framerate,
uint32_t rtt_time,
int64_t rtt_time,
uint8_t packet_loss) {
// Default: no adjustment
float adjust_fec = 1.0f;

View File

@ -353,7 +353,7 @@ class VCMQmRobustness : public VCMQmMethod {
float AdjustFecFactor(uint8_t code_rate_delta,
float total_rate,
float framerate,
uint32_t rtt_time,
int64_t rtt_time,
uint8_t packet_loss);
// Set the UEP protection on/off.
@ -365,7 +365,7 @@ class VCMQmRobustness : public VCMQmMethod {
private:
// Previous state of network parameters.
float prev_total_rate_;
uint32_t prev_rtt_time_;
int64_t prev_rtt_time_;
uint8_t prev_packet_loss_;
uint8_t prev_code_rate_delta_;
};

View File

@ -59,7 +59,7 @@ int32_t VCMReceiver::Initialize() {
return VCM_OK;
}
void VCMReceiver::UpdateRtt(uint32_t rtt) {
void VCMReceiver::UpdateRtt(int64_t rtt) {
jitter_buffer_.UpdateRtt(rtt);
}
@ -191,8 +191,8 @@ uint32_t VCMReceiver::DiscardedPackets() const {
}
void VCMReceiver::SetNackMode(VCMNackMode nackMode,
int low_rtt_nack_threshold_ms,
int high_rtt_nack_threshold_ms) {
int64_t low_rtt_nack_threshold_ms,
int64_t high_rtt_nack_threshold_ms) {
CriticalSectionScoped cs(crit_sect_);
// Default to always having NACK enabled in hybrid mode.
jitter_buffer_.SetNackMode(nackMode, low_rtt_nack_threshold_ms,

View File

@ -44,7 +44,7 @@ class VCMReceiver {
void Reset();
int32_t Initialize();
void UpdateRtt(uint32_t rtt);
void UpdateRtt(int64_t rtt);
int32_t InsertPacket(const VCMPacket& packet,
uint16_t frame_width,
uint16_t frame_height);
@ -57,8 +57,8 @@ class VCMReceiver {
// NACK.
void SetNackMode(VCMNackMode nackMode,
int low_rtt_nack_threshold_ms,
int high_rtt_nack_threshold_ms);
int64_t low_rtt_nack_threshold_ms,
int64_t high_rtt_nack_threshold_ms);
void SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack,
int max_incomplete_time_ms);

View File

@ -58,7 +58,7 @@ VCMRttFilter::Reset()
}
void
VCMRttFilter::Update(uint32_t rttMs)
VCMRttFilter::Update(int64_t rttMs)
{
if (!_gotNonZeroUpdate)
{
@ -103,7 +103,7 @@ VCMRttFilter::Update(uint32_t rttMs)
}
bool
VCMRttFilter::JumpDetection(uint32_t rttMs)
VCMRttFilter::JumpDetection(int64_t rttMs)
{
double diffFromAvg = _avgRtt - rttMs;
if (fabs(diffFromAvg) > _jumpStdDevs * sqrt(_varRtt))
@ -147,7 +147,7 @@ VCMRttFilter::JumpDetection(uint32_t rttMs)
}
bool
VCMRttFilter::DriftDetection(uint32_t rttMs)
VCMRttFilter::DriftDetection(int64_t rttMs)
{
if (_maxRtt - _avgRtt > _driftStdDevs * sqrt(_varRtt))
{
@ -174,7 +174,7 @@ VCMRttFilter::DriftDetection(uint32_t rttMs)
}
void
VCMRttFilter::ShortRttFilter(uint32_t* buf, uint32_t length)
VCMRttFilter::ShortRttFilter(int64_t* buf, uint32_t length)
{
if (length == 0)
{
@ -193,10 +193,10 @@ VCMRttFilter::ShortRttFilter(uint32_t* buf, uint32_t length)
_avgRtt = _avgRtt / static_cast<double>(length);
}
uint32_t
int64_t
VCMRttFilter::RttMs() const
{
return static_cast<uint32_t>(_maxRtt + 0.5);
return static_cast<int64_t>(_maxRtt + 0.5);
}
}

View File

@ -26,9 +26,9 @@ public:
// Resets the filter.
void Reset();
// Updates the filter with a new sample.
void Update(uint32_t rttMs);
void Update(int64_t rttMs);
// A getter function for the current RTT level in ms.
uint32_t RttMs() const;
int64_t RttMs() const;
private:
// The size of the drift and jump memory buffers
@ -39,19 +39,19 @@ private:
// samples and average to the standard deviation.
// Returns true if the long time statistics should be updated
// and false otherwise
bool JumpDetection(uint32_t rttMs);
bool JumpDetection(int64_t rttMs);
// Detects RTT drifts by comparing the difference between
// max and average to the standard deviation.
// Returns true if the long time statistics should be updated
// and false otherwise
bool DriftDetection(uint32_t rttMs);
bool DriftDetection(int64_t rttMs);
// Computes the short time average and maximum of the vector buf.
void ShortRttFilter(uint32_t* buf, uint32_t length);
void ShortRttFilter(int64_t* buf, uint32_t length);
bool _gotNonZeroUpdate;
double _avgRtt;
double _varRtt;
uint32_t _maxRtt;
int64_t _maxRtt;
uint32_t _filtFactCount;
const uint32_t _filtFactMax;
const double _jumpStdDevs;
@ -59,8 +59,8 @@ private:
int32_t _jumpCount;
int32_t _driftCount;
const int32_t _detectThreshold;
uint32_t _jumpBuf[kMaxDriftJumpCount];
uint32_t _driftBuf[kMaxDriftJumpCount];
int64_t _jumpBuf[kMaxDriftJumpCount];
int64_t _driftBuf[kMaxDriftJumpCount];
};
} // namespace webrtc

View File

@ -14,18 +14,13 @@
#include "webrtc/system_wrappers/interface/logging.h"
namespace webrtc {
namespace {
// Used in determining whether a frame is decodable.
enum {kRttThreshold = 100}; // Not decodable if Rtt is lower than this.
// Do not decode frames if the number of packets is between these two
// thresholds.
static const float kLowPacketPercentageThreshold = 0.2f;
static const float kHighPacketPercentageThreshold = 0.8f;
namespace {
uint16_t BufferToUWord16(const uint8_t* dataBuffer) {
return (dataBuffer[0] << 8) | dataBuffer[1];
}
} // namespace
VCMSessionInfo::VCMSessionInfo()
@ -233,6 +228,12 @@ void VCMSessionInfo::UpdateDecodableSession(const FrameData& frame_data) {
return;
// TODO(agalusza): Account for bursty loss.
// TODO(agalusza): Refine these values to better approximate optimal ones.
// Do not decode frames if the RTT is lower than this.
const int64_t kRttThreshold = 100;
// Do not decode frames if the number of packets is between these two
// thresholds.
const float kLowPacketPercentageThreshold = 0.2f;
const float kHighPacketPercentageThreshold = 0.8f;
if (frame_data.rtt_ms < kRttThreshold
|| frame_type_ == kVideoFrameKey
|| !HaveFirstPacket()

View File

@ -22,7 +22,7 @@ namespace webrtc {
// Used to pass data from jitter buffer to session info.
// This data is then used in determining whether a frame is decodable.
struct FrameData {
int rtt_ms;
int64_t rtt_ms;
float rolling_average_packets_per_frame;
};

View File

@ -142,7 +142,7 @@ class VideoCodingModuleImpl : public VideoCodingModule {
virtual int32_t SetChannelParameters(uint32_t target_bitrate, // bits/s.
uint8_t lossRate,
uint32_t rtt) OVERRIDE {
int64_t rtt) OVERRIDE {
return sender_->SetChannelParameters(target_bitrate, lossRate, rtt);
}
@ -332,7 +332,7 @@ class VideoCodingModuleImpl : public VideoCodingModule {
return receiver_->SetMinReceiverDelay(desired_delay_ms);
}
virtual int32_t SetReceiveChannelParameters(uint32_t rtt) OVERRIDE {
virtual int32_t SetReceiveChannelParameters(int64_t rtt) OVERRIDE {
return receiver_->SetReceiveChannelParameters(rtt);
}

View File

@ -79,7 +79,7 @@ class VideoSender {
int32_t SetChannelParameters(uint32_t target_bitrate, // bits/s.
uint8_t lossRate,
uint32_t rtt);
int64_t rtt);
int32_t RegisterTransportCallback(VCMPacketizationCallback* transport);
int32_t RegisterSendStatisticsCallback(VCMSendStatisticsCallback* sendStats);
@ -175,7 +175,7 @@ class VideoReceiver {
void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode);
int SetMinReceiverDelay(int desired_delay_ms);
int32_t SetReceiveChannelParameters(uint32_t rtt);
int32_t SetReceiveChannelParameters(int64_t rtt);
int32_t SetVideoProtection(VCMVideoProtection videoProtection, bool enable);
int64_t TimeUntilNextProcess();

View File

@ -168,7 +168,7 @@ int64_t VideoReceiver::TimeUntilNextProcess() {
return timeUntilNextProcess;
}
int32_t VideoReceiver::SetReceiveChannelParameters(uint32_t rtt) {
int32_t VideoReceiver::SetReceiveChannelParameters(int64_t rtt) {
CriticalSectionScoped receiveCs(_receiveCritSect);
_receiver.UpdateRtt(rtt);
return 0;

View File

@ -244,7 +244,7 @@ int VideoSender::FrameRate(unsigned int* framerate) const {
// Set channel parameters
int32_t VideoSender::SetChannelParameters(uint32_t target_bitrate,
uint8_t lossRate,
uint32_t rtt) {
int64_t rtt) {
int32_t ret = 0;
{
CriticalSectionScoped sendCs(_sendCritSect);