Use int64_t for milliseconds more often, primarily for TimeUntilNextProcess.

This fixes a variety of MSVC warnings about value truncations when implicitly
storing the 64-bit values we get back from e.g. TimeTicks in 32-bit objects, and
removes the need for a number of explicit casts.

This also moves a number of constants so they're declared right where they're used, which is easier to read and maintain, and makes some of them of integral type rather than using the "enum hack".

BUG=chromium:81439
TEST=none
R=tommi@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7905 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pkasting@chromium.org 2014-12-15 22:09:40 +00:00
parent 96a626262a
commit 0b1534c52e
68 changed files with 160 additions and 173 deletions

View File

@ -94,7 +94,7 @@ int FakeAudioCaptureModule::frames_received() const {
return frames_received_;
}
int32_t FakeAudioCaptureModule::TimeUntilNextProcess() {
int64_t FakeAudioCaptureModule::TimeUntilNextProcess() {
const uint32 current_time = rtc::Time();
if (current_time < last_process_time_ms_) {
// TODO: wraparound could be handled more gracefully.

View File

@ -76,7 +76,7 @@ class FakeAudioCaptureModule
// Only functions called by PeerConnection are implemented, the rest do
// nothing and return success. If a function is not expected to be called by
// PeerConnection an assertion is triggered if it is in fact called.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;

View File

@ -44,7 +44,7 @@ class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule {
running_(false),
delay_(0) {
}
virtual int32_t TimeUntilNextProcess() OVERRIDE {
virtual int64_t TimeUntilNextProcess() OVERRIDE {
return 0;
}
virtual int32_t Process() OVERRIDE {

View File

@ -45,7 +45,7 @@ class WebRtcPassthroughRender : public webrtc::VideoRender {
return 0;
}
virtual int32_t TimeUntilNextProcess() OVERRIDE { return 0; }
virtual int64_t TimeUntilNextProcess() OVERRIDE { return 0; }
virtual int32_t Process() OVERRIDE { return 0; }

View File

@ -262,7 +262,7 @@ int32_t AudioCodingModuleImpl::ChangeUniqueId(const int32_t id) {
// Returns the number of milliseconds until the module want a
// worker thread to call Process.
int32_t AudioCodingModuleImpl::TimeUntilNextProcess() {
int64_t AudioCodingModuleImpl::TimeUntilNextProcess() {
CriticalSectionScoped lock(acm_crit_sect_);
if (!HaveValidEncoder("TimeUntilNextProcess")) {

View File

@ -40,7 +40,7 @@ class AudioCodingModuleImpl : public AudioCodingModule {
// Returns the number of milliseconds until the module want a worker thread
// to call Process.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
// Process any pending tasks such as timeouts.
virtual int32_t Process() OVERRIDE;

View File

@ -41,7 +41,7 @@ public:
// Module functions
virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE = 0;
virtual int32_t TimeUntilNextProcess() OVERRIDE = 0;
virtual int64_t TimeUntilNextProcess() OVERRIDE = 0;
virtual int32_t Process() OVERRIDE = 0;
// Register/unregister a callback class for receiving the mixed audio.

View File

@ -197,8 +197,8 @@ int32_t AudioConferenceMixerImpl::ChangeUniqueId(const int32_t id) {
}
// Process should be called every kProcessPeriodicityInMs ms
int32_t AudioConferenceMixerImpl::TimeUntilNextProcess() {
int32_t timeUntilNextProcess = 0;
int64_t AudioConferenceMixerImpl::TimeUntilNextProcess() {
int64_t timeUntilNextProcess = 0;
CriticalSectionScoped cs(_crit.get());
if(_timeScheduler.TimeToNextUpdate(timeUntilNextProcess) != 0) {
WEBRTC_TRACE(kTraceError, kTraceAudioMixerServer, _id,

View File

@ -65,7 +65,7 @@ public:
// Module functions
virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
// AudioConferenceMixer functions

View File

@ -12,7 +12,7 @@
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
namespace webrtc {
TimeScheduler::TimeScheduler(const uint32_t periodicityInMs)
TimeScheduler::TimeScheduler(const int64_t periodicityInMs)
: _crit(CriticalSectionWrapper::CreateCriticalSection()),
_isStarted(false),
_lastPeriodMark(),
@ -50,8 +50,7 @@ int32_t TimeScheduler::UpdateScheduler()
int64_t amassedMs = amassedTicks.Milliseconds();
// Calculate the number of periods the time that has passed correspond to.
int32_t periodsToClaim = static_cast<int32_t>(amassedMs /
static_cast<int32_t>(_periodicityInMs));
int64_t periodsToClaim = amassedMs / _periodicityInMs;
// One period will be worked off by this call. Make sure that the number of
// pending periods don't end up being negative (e.g. if this function is
@ -65,7 +64,7 @@ int32_t TimeScheduler::UpdateScheduler()
// Note that if this fuunction is called to often _lastPeriodMark can
// refer to a time in the future which in turn will yield TimeToNextUpdate
// that is greater than the periodicity
for(int32_t i = 0; i < periodsToClaim; i++)
for(int64_t i = 0; i < periodsToClaim; i++)
{
_lastPeriodMark += _periodicityInTicks;
}
@ -77,7 +76,7 @@ int32_t TimeScheduler::UpdateScheduler()
}
int32_t TimeScheduler::TimeToNextUpdate(
int32_t& updateTimeInMS) const
int64_t& updateTimeInMS) const
{
CriticalSectionScoped cs(_crit);
// Missed periods means that the next UpdateScheduler() should happen
@ -92,8 +91,8 @@ int32_t TimeScheduler::TimeToNextUpdate(
// UpdateScheduler()
TickTime tickNow = TickTime::Now();
TickInterval ticksSinceLastUpdate = tickNow - _lastPeriodMark;
const int32_t millisecondsSinceLastUpdate =
static_cast<int32_t>(ticksSinceLastUpdate.Milliseconds());
const int64_t millisecondsSinceLastUpdate =
ticksSinceLastUpdate.Milliseconds();
updateTimeInMS = _periodicityInMs - millisecondsSinceLastUpdate;
updateTimeInMS = (updateTimeInMS < 0) ? 0 : updateTimeInMS;

View File

@ -22,7 +22,7 @@ class CriticalSectionWrapper;
class TimeScheduler
{
public:
TimeScheduler(const uint32_t periodicityInMs);
TimeScheduler(const int64_t periodicityInMs);
~TimeScheduler();
// Signal that a periodic event has been triggered.
@ -30,7 +30,7 @@ public:
// Set updateTimeInMs to the amount of time until UpdateScheduler() should
// be called. This time will never be negative.
int32_t TimeToNextUpdate(int32_t& updateTimeInMS) const;
int32_t TimeToNextUpdate(int64_t& updateTimeInMS) const;
private:
CriticalSectionWrapper* _crit;
@ -38,8 +38,8 @@ private:
bool _isStarted;
TickTime _lastPeriodMark;
uint32_t _periodicityInMs;
int64_t _periodicityInTicks;
int64_t _periodicityInMs;
int64_t _periodicityInTicks;
uint32_t _missedPeriods;
};
} // namespace webrtc

View File

@ -480,7 +480,7 @@ int32_t AudioDeviceModuleImpl::ChangeUniqueId(const int32_t id)
// to call Process().
// ----------------------------------------------------------------------------
int32_t AudioDeviceModuleImpl::TimeUntilNextProcess()
int64_t AudioDeviceModuleImpl::TimeUntilNextProcess()
{
uint32_t now = AudioDeviceUtility::GetTimeInMS();
int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);

View File

@ -44,7 +44,7 @@ public:
public: // RefCountedModule
virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
public:

View File

@ -36,7 +36,7 @@ class FakeAudioDeviceModule : public AudioDeviceModule {
virtual int32_t SetStereoRecording(bool enable) { return 0; }
virtual int32_t SetAGC(bool enable) { return 0; }
virtual int32_t StopRecording() { return 0; }
virtual int32_t TimeUntilNextProcess() { return 0; }
virtual int64_t TimeUntilNextProcess() { return 0; }
virtual int32_t Process() { return 0; }
virtual int32_t Terminate() { return 0; }

View File

@ -223,12 +223,13 @@ void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) {
MaybeTriggerOnNetworkChanged();
}
int32_t BitrateControllerImpl::TimeUntilNextProcess() {
enum { kBitrateControllerUpdateIntervalMs = 25 };
int64_t BitrateControllerImpl::TimeUntilNextProcess() {
const int64_t kBitrateControllerUpdateIntervalMs = 25;
CriticalSectionScoped cs(critsect_);
int time_since_update_ms =
int64_t time_since_update_ms =
clock_->TimeInMilliseconds() - last_bitrate_update_ms_;
return std::max(0, kBitrateControllerUpdateIntervalMs - time_since_update_ms);
return std::max<int64_t>(
kBitrateControllerUpdateIntervalMs - time_since_update_ms, 0);
}
int32_t BitrateControllerImpl::Process() {

View File

@ -46,7 +46,7 @@ class BitrateControllerImpl : public BitrateController {
virtual void EnforceMinBitrate(bool enforce_min_bitrate) OVERRIDE;
virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
private:

View File

@ -25,7 +25,7 @@ class Module {
// Returns the number of milliseconds until the module want a worker
// thread to call Process.
virtual int32_t TimeUntilNextProcess() = 0;
virtual int64_t TimeUntilNextProcess() = 0;
// Process any pending tasks such as timeouts.
virtual int32_t Process() = 0;

View File

@ -91,7 +91,7 @@ int32_t MediaFileImpl::ChangeUniqueId(const int32_t id)
return 0;
}
int32_t MediaFileImpl::TimeUntilNextProcess()
int64_t MediaFileImpl::TimeUntilNextProcess()
{
WEBRTC_TRACE(
kTraceWarning,

View File

@ -28,7 +28,7 @@ public:
virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
virtual int32_t Process() OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
// MediaFile functions
virtual int32_t PlayoutAudioData(int8_t* audioBuffer,

View File

@ -29,7 +29,7 @@ class MockPacedSender : public PacedSender {
int64_t capture_time_ms,
size_t bytes,
bool retransmission));
MOCK_CONST_METHOD0(QueueInMs, int());
MOCK_CONST_METHOD0(QueueInMs, int64_t());
MOCK_CONST_METHOD0(QueueInPackets, int());
};

View File

@ -106,7 +106,7 @@ class PacedSender : public Module {
bool retransmission);
// Returns the time since the oldest queued packet was enqueued.
virtual int QueueInMs() const;
virtual int64_t QueueInMs() const;
virtual size_t QueueSizePackets() const;
@ -116,7 +116,7 @@ class PacedSender : public Module {
// Returns the number of milliseconds until the module want a worker thread
// to call Process.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
// Process any pending packets in the queue(s).
virtual int32_t Process() OVERRIDE;
@ -126,7 +126,7 @@ class PacedSender : public Module {
private:
// Updates the number of bytes that can be sent for the next time interval.
void UpdateBytesPerInterval(uint32_t delta_time_in_ms)
void UpdateBytesPerInterval(int64_t delta_time_in_ms)
EXCLUSIVE_LOCKS_REQUIRED(critsect_);
bool SendPacket(const paced_sender::Packet& packet)

View File

@ -26,11 +26,11 @@
namespace {
// Time limit in milliseconds between packet bursts.
const int kMinPacketLimitMs = 5;
const int64_t kMinPacketLimitMs = 5;
// Upper cap on process interval, in case process has not been called in a long
// time.
const int kMaxIntervalTimeMs = 30;
const int64_t kMaxIntervalTimeMs = 30;
} // namespace
@ -178,8 +178,8 @@ class IntervalBudget {
target_rate_kbps_ = target_rate_kbps;
}
void IncreaseBudget(int delta_time_ms) {
int bytes = target_rate_kbps_ * delta_time_ms / 8;
void IncreaseBudget(int64_t delta_time_ms) {
int64_t bytes = target_rate_kbps_ * delta_time_ms / 8;
if (bytes_remaining_ < 0) {
// We overused last interval, compensate this interval.
bytes_remaining_ = bytes_remaining_ + bytes;
@ -293,7 +293,7 @@ size_t PacedSender::QueueSizePackets() const {
return packets_->SizeInPackets();
}
int PacedSender::QueueInMs() const {
int64_t PacedSender::QueueInMs() const {
CriticalSectionScoped cs(critsect_.get());
int64_t oldest_packet = packets_->OldestEnqueueTime();
@ -303,31 +303,27 @@ int PacedSender::QueueInMs() const {
return clock_->TimeInMilliseconds() - oldest_packet;
}
int32_t PacedSender::TimeUntilNextProcess() {
int64_t PacedSender::TimeUntilNextProcess() {
CriticalSectionScoped cs(critsect_.get());
int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_;
int elapsed_time_ms = static_cast<int>((elapsed_time_us + 500) / 1000);
if (prober_->IsProbing()) {
int next_probe = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds());
return next_probe;
return prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds());
}
if (elapsed_time_ms >= kMinPacketLimitMs) {
return 0;
}
return kMinPacketLimitMs - elapsed_time_ms;
int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_;
int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000;
return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0);
}
int32_t PacedSender::Process() {
int64_t now_us = clock_->TimeInMicroseconds();
CriticalSectionScoped cs(critsect_.get());
int elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000;
int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000;
time_last_update_us_ = now_us;
if (!enabled_) {
return 0;
}
if (!paused_) {
if (elapsed_time_ms > 0) {
uint32_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms);
int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms);
UpdateBytesPerInterval(delta_time_ms);
}
@ -387,7 +383,7 @@ void PacedSender::SendPadding(size_t padding_needed) {
padding_budget_->UseBudget(bytes_sent);
}
void PacedSender::UpdateBytesPerInterval(uint32_t delta_time_ms) {
void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) {
media_budget_->IncreaseBudget(delta_time_ms);
padding_budget_->IncreaseBudget(delta_time_ms);
}

View File

@ -20,7 +20,6 @@ namespace webrtc {
static const uint32_t kDefaultRttMs = 200;
static const int64_t kLogIntervalMs = 1000;
static const int kMinFeedbackIntervalMs = 200;
static const double kWithinIncomingBitrateHysteresis = 1.05;
AimdRateControl::AimdRateControl(uint32_t min_bitrate_bps)
@ -54,17 +53,15 @@ bool AimdRateControl::ValidEstimate() const {
return bitrate_is_initialized_;
}
int AimdRateControl::GetFeedbackInterval() const {
int64_t AimdRateControl::GetFeedbackInterval() const {
// Estimate how often we can send RTCP if we allocate up to 5% of bandwidth
// to feedback.
static const int kRtcpSize = 80.0;
int interval = kRtcpSize * 8.0 * 1000.0 / (0.05 * current_bitrate_bps_) + 0.5;
if (interval > kMaxFeedbackIntervalMs)
interval = kMaxFeedbackIntervalMs;
else if (interval < kMinFeedbackIntervalMs) {
interval = kMinFeedbackIntervalMs;
}
return interval;
static const int kRtcpSize = 80;
int64_t interval = static_cast<int64_t>(
kRtcpSize * 8.0 * 1000.0 / (0.05 * current_bitrate_bps_) + 0.5);
const int64_t kMinFeedbackIntervalMs = 200;
return std::min(std::max(interval, kMinFeedbackIntervalMs),
kMaxFeedbackIntervalMs);
}
bool AimdRateControl::TimeToReduceFurther(int64_t time_now,

View File

@ -30,7 +30,7 @@ class AimdRateControl : public RemoteRateControl {
virtual bool ValidEstimate() const OVERRIDE;
virtual RateControlType GetControlType() const OVERRIDE;
virtual uint32_t GetMinBitrate() const OVERRIDE;
virtual int GetFeedbackInterval() const OVERRIDE;
virtual int64_t GetFeedbackInterval() const OVERRIDE;
// Returns true if the bitrate estimate hasn't been changed for more than
// an RTT, or if the incoming_bitrate is more than 5% above the current
// estimate. Should be used to decide if we should reduce the rate further

View File

@ -89,8 +89,8 @@ class RemoteBitrateEstimator : public CallStatsObserver, public Module {
virtual bool GetStats(ReceiveBandwidthEstimatorStats* output) const = 0;
protected:
static const int kProcessIntervalMs = 1000;
static const int kStreamTimeOutMs = 2000;
static const int64_t kProcessIntervalMs = 1000;
static const int64_t kStreamTimeOutMs = 2000;
};
struct RemoteBitrateEstimatorFactory {

View File

@ -55,7 +55,7 @@ bool MimdRateControl::ValidEstimate() const {
return initialized_bit_rate_;
}
int MimdRateControl::GetFeedbackInterval() const {
int64_t MimdRateControl::GetFeedbackInterval() const {
return kMaxFeedbackIntervalMs;
}

View File

@ -28,7 +28,7 @@ class MimdRateControl : public RemoteRateControl {
virtual RateControlType GetControlType() const OVERRIDE;
virtual uint32_t GetMinBitrate() const OVERRIDE;
virtual bool ValidEstimate() const OVERRIDE;
virtual int GetFeedbackInterval() const OVERRIDE;
virtual int64_t GetFeedbackInterval() const OVERRIDE;
virtual bool TimeToReduceFurther(
int64_t time_now, uint32_t incoming_bitrate_bps) const OVERRIDE;
virtual uint32_t LatestEstimate() const OVERRIDE;

View File

@ -83,7 +83,7 @@ class RemoteBitrateEstimatorAbsSendTimeImpl : public RemoteBitrateEstimator {
// shouldn't be detached from the ProcessThread except if it's about to be
// deleted.
virtual int32_t Process() OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual void OnRttUpdate(uint32_t rtt) OVERRIDE;
virtual void RemoveStream(unsigned int ssrc) OVERRIDE;
virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs,
@ -168,7 +168,7 @@ class RemoteBitrateEstimatorAbsSendTimeImpl : public RemoteBitrateEstimator {
int64_t last_process_time_;
std::vector<int> recent_propagation_delta_ms_ GUARDED_BY(crit_sect_.get());
std::vector<int64_t> recent_update_time_ms_ GUARDED_BY(crit_sect_.get());
int process_interval_ms_ GUARDED_BY(crit_sect_.get());
int64_t process_interval_ms_ GUARDED_BY(crit_sect_.get());
int total_propagation_delta_ms_ GUARDED_BY(crit_sect_.get());
std::list<Probe> probes_;
@ -376,7 +376,7 @@ int32_t RemoteBitrateEstimatorAbsSendTimeImpl::Process() {
return 0;
}
int32_t RemoteBitrateEstimatorAbsSendTimeImpl::TimeUntilNextProcess() {
int64_t RemoteBitrateEstimatorAbsSendTimeImpl::TimeUntilNextProcess() {
if (last_process_time_ < 0) {
return 0;
}

View File

@ -97,8 +97,8 @@ TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestLongTimeoutAndWrap) {
TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProcessAfterTimeout) {
// This time constant must be equal to the ones defined for the
// RemoteBitrateEstimator.
const int kStreamTimeOutMs = 2000;
const int kProcessIntervalMs = 1000;
const int64_t kStreamTimeOutMs = 2000;
const int64_t kProcessIntervalMs = 1000;
IncomingPacket(0, 1000, clock_.TimeInMilliseconds(), 0, 0);
clock_.AdvanceTimeMilliseconds(kStreamTimeOutMs + 1);
// Trigger timeout.

View File

@ -40,7 +40,7 @@ class RemoteBitrateEstimatorImpl : public RemoteBitrateEstimator {
size_t payload_size,
const RTPHeader& header) OVERRIDE;
virtual int32_t Process() OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual void OnRttUpdate(uint32_t rtt) OVERRIDE;
virtual void RemoveStream(unsigned int ssrc) OVERRIDE;
virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs,
@ -79,7 +79,7 @@ class RemoteBitrateEstimatorImpl : public RemoteBitrateEstimator {
RemoteBitrateObserver* observer_ GUARDED_BY(crit_sect_.get());
scoped_ptr<CriticalSectionWrapper> crit_sect_;
int64_t last_process_time_;
int process_interval_ms_ GUARDED_BY(crit_sect_.get());
int64_t process_interval_ms_ GUARDED_BY(crit_sect_.get());
DISALLOW_IMPLICIT_CONSTRUCTORS(RemoteBitrateEstimatorImpl);
};
@ -172,7 +172,7 @@ int32_t RemoteBitrateEstimatorImpl::Process() {
return 0;
}
int32_t RemoteBitrateEstimatorImpl::TimeUntilNextProcess() {
int64_t RemoteBitrateEstimatorImpl::TimeUntilNextProcess() {
if (last_process_time_ < 0) {
return 0;
}

View File

@ -14,6 +14,10 @@
#include "webrtc/modules/remote_bitrate_estimator/mimd_rate_control.h"
namespace webrtc {
// static
const int64_t RemoteRateControl::kMaxFeedbackIntervalMs = 1000;
RemoteRateControl* RemoteRateControl::Create(RateControlType control_type,
uint32_t min_bitrate_bps) {
if (control_type == kAimdControl) {
@ -22,4 +26,5 @@ RemoteRateControl* RemoteRateControl::Create(RateControlType control_type,
return new MimdRateControl(min_bitrate_bps);
}
}
} // namespace webrtc

View File

@ -28,7 +28,7 @@ class RemoteRateControl {
virtual bool ValidEstimate() const = 0;
virtual RateControlType GetControlType() const = 0;
virtual uint32_t GetMinBitrate() const = 0;
virtual int GetFeedbackInterval() const = 0;
virtual int64_t GetFeedbackInterval() const = 0;
// Returns true if the bitrate estimate hasn't been changed for more than
// an RTT, or if the incoming_bitrate is more than 5% above the current
@ -44,7 +44,7 @@ class RemoteRateControl {
virtual void SetEstimate(int bitrate_bps, int64_t time_now_ms) = 0;
protected:
static const int kMaxFeedbackIntervalMs = 1000;
static const int64_t kMaxFeedbackIntervalMs;
};
} // namespace webrtc

View File

@ -76,11 +76,11 @@ class TestedEstimator : public RemoteBitrateObserver {
}
}
int64_t step_ms = std::max(estimator_->TimeUntilNextProcess(), 0);
int64_t step_ms = std::max<int64_t>(estimator_->TimeUntilNextProcess(), 0);
while ((clock_.TimeInMilliseconds() + step_ms) < packet_time_ms) {
clock_.AdvanceTimeMilliseconds(step_ms);
estimator_->Process();
step_ms = std::max(estimator_->TimeUntilNextProcess(), 0);
step_ms = std::max<int64_t>(estimator_->TimeUntilNextProcess(), 0);
}
estimator_->IncomingPacket(packet_time_ms, packet.payload_size(),
packet.header());

View File

@ -700,7 +700,7 @@ void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
int64_t end_time_ms = clock_.TimeInMilliseconds() + time_ms;
Packets::iterator it = generated_packets.begin();
while (clock_.TimeInMilliseconds() <= end_time_ms) {
int time_until_process_ms = pacer_.TimeUntilNextProcess();
int64_t time_until_process_ms = pacer_.TimeUntilNextProcess();
if (time_until_process_ms < 0)
time_until_process_ms = 0;
int time_until_packet_ms = time_ms;

View File

@ -10,6 +10,7 @@
#include <stdio.h>
#include "webrtc/base/format_macros.h"
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
@ -98,18 +99,17 @@ int main(int argc, char** argv) {
packet.time_ms = packet.time_ms - first_rtp_time_ms;
next_rtp_time_ms = packet.time_ms;
}
int time_until_process_ms = rbe->TimeUntilNextProcess();
int64_t time_until_process_ms = rbe->TimeUntilNextProcess();
if (time_until_process_ms <= 0) {
rbe->Process();
}
int time_until_next_event =
int64_t time_until_next_event =
std::min(rbe->TimeUntilNextProcess(),
static_cast<int>(next_rtp_time_ms -
clock.TimeInMilliseconds()));
clock.AdvanceTimeMilliseconds(std::max(time_until_next_event, 0));
next_rtp_time_ms - clock.TimeInMilliseconds());
clock.AdvanceTimeMilliseconds(std::max<int64_t>(time_until_next_event, 0));
}
printf("Parsed %d packets\nTime passed: %u ms\n", packet_counter,
static_cast<uint32_t>(clock.TimeInMilliseconds()));
printf("Parsed %d packets\nTime passed: %" PRId64 " ms\n", packet_counter,
clock.TimeInMilliseconds());
printf("Estimator used: %s\n", estimator_used.c_str());
printf("Packets with absolute send time: %d\n",
abs_send_time_count);

View File

@ -90,7 +90,7 @@ class NullReceiveStatistics : public ReceiveStatistics {
virtual void FecPacketReceived(uint32_t ssrc) OVERRIDE;
virtual StatisticianMap GetActiveStatisticians() const OVERRIDE;
virtual StreamStatistician* GetStatistician(uint32_t ssrc) const OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
virtual void SetMaxReorderingThreshold(int max_reordering_threshold) OVERRIDE;
virtual void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback)

View File

@ -261,7 +261,7 @@ class MockRtpRtcp : public RtpRtcp {
MOCK_CONST_METHOD3(Version,
int32_t(char* version, uint32_t& remaining_buffer_in_bytes, uint32_t& position));
MOCK_METHOD0(TimeUntilNextProcess,
int32_t());
int64_t());
MOCK_METHOD0(Process,
int32_t());
MOCK_METHOD1(RegisterSendFrameCountObserver,

View File

@ -20,7 +20,7 @@
namespace webrtc {
const int64_t kStatisticsTimeoutMs = 8000;
const int kStatisticsProcessIntervalMs = 1000;
const int64_t kStatisticsProcessIntervalMs = 1000;
StreamStatistician::~StreamStatistician() {}
@ -491,11 +491,12 @@ int32_t ReceiveStatisticsImpl::Process() {
return 0;
}
int32_t ReceiveStatisticsImpl::TimeUntilNextProcess() {
int64_t ReceiveStatisticsImpl::TimeUntilNextProcess() {
CriticalSectionScoped cs(receive_statistics_lock_.get());
int time_since_last_update = clock_->TimeInMilliseconds() -
int64_t time_since_last_update = clock_->TimeInMilliseconds() -
last_rate_update_ms_;
return std::max(kStatisticsProcessIntervalMs - time_since_last_update, 0);
return std::max<int64_t>(
kStatisticsProcessIntervalMs - time_since_last_update, 0);
}
void ReceiveStatisticsImpl::RegisterRtcpStatisticsCallback(
@ -548,7 +549,7 @@ StreamStatistician* NullReceiveStatistics::GetStatistician(
void NullReceiveStatistics::SetMaxReorderingThreshold(
int max_reordering_threshold) {}
int32_t NullReceiveStatistics::TimeUntilNextProcess() { return 0; }
int64_t NullReceiveStatistics::TimeUntilNextProcess() { return 0; }
int32_t NullReceiveStatistics::Process() { return 0; }

View File

@ -117,7 +117,7 @@ class ReceiveStatisticsImpl : public ReceiveStatistics,
// Implement Module.
virtual int32_t Process() OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback)
OVERRIDE;

View File

@ -13,11 +13,6 @@
// Configuration file for RTP utilities (RTPSender, RTPReceiver ...)
namespace webrtc {
enum { kRtpRtcpMaxIdleTimeProcess = 5,
kRtpRtcpBitrateProcessTimeMs = 10,
kRtpRtcpPacketTimeoutProcessTimeMs = 100,
kRtpRtcpRttProcessTimeMs = 1000 };
enum { NACK_BYTECOUNT_SIZE = 60}; // size of our NACK history
// A sanity for the NACK list parsing at the send-side.
enum { kSendSideNackListSizeSanity = 20000 };

View File

@ -154,9 +154,10 @@ void ModuleRtpRtcpImpl::DeRegisterChildModule(RtpRtcp* remove_module) {
// Returns the number of milliseconds until the module want a worker thread
// to call Process.
int32_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
const int64_t now = clock_->TimeInMilliseconds();
return kRtpRtcpMaxIdleTimeProcess - (now - last_process_time_);
int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
const int64_t now = clock_->TimeInMilliseconds();
const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5;
return kRtpRtcpMaxIdleTimeProcessMs - (now - last_process_time_);
}
// Process any pending tasks such as timeouts (non time critical events).
@ -164,12 +165,14 @@ int32_t ModuleRtpRtcpImpl::Process() {
const int64_t now = clock_->TimeInMilliseconds();
last_process_time_ = now;
const int64_t kRtpRtcpBitrateProcessTimeMs = 10;
if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
rtp_sender_.ProcessBitrate();
last_bitrate_process_time_ = now;
}
if (!IsDefaultModule()) {
const int64_t kRtpRtcpRttProcessTimeMs = 1000;
bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
if (rtcp_sender_.Sending()) {
// Process RTT if we have received a receiver report and we haven't

View File

@ -31,7 +31,7 @@ class ModuleRtpRtcpImpl : public RtpRtcp {
// Returns the number of milliseconds until the module want a worker thread to
// call Process.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
// Process any pending tasks such as timeouts.
virtual int32_t Process() OVERRIDE;

View File

@ -130,12 +130,12 @@ bool ProcessThreadImpl::Process()
{
// Wait for the module that should be called next, but don't block thread
// longer than 100 ms.
int32_t minTimeToNext = 100;
int64_t minTimeToNext = 100;
{
CriticalSectionScoped lock(_critSectModules);
for (ModuleList::iterator iter = _modules.begin();
iter != _modules.end(); ++iter) {
int32_t timeToNext = (*iter)->TimeUntilNextProcess();
int64_t timeToNext = (*iter)->TimeUntilNextProcess();
if(minTimeToNext > timeToNext)
{
minTimeToNext = timeToNext;
@ -145,7 +145,8 @@ bool ProcessThreadImpl::Process()
if(minTimeToNext > 0)
{
if(kEventError == _timeEvent.Wait(minTimeToNext))
if(kEventError ==
_timeEvent.Wait(static_cast<unsigned long>(minTimeToNext)))
{
return true;
}
@ -159,7 +160,7 @@ bool ProcessThreadImpl::Process()
CriticalSectionScoped lock(_critSectModules);
for (ModuleList::iterator iter = _modules.begin();
iter != _modules.end(); ++iter) {
int32_t timeToNext = (*iter)->TimeUntilNextProcess();
int64_t timeToNext = (*iter)->TimeUntilNextProcess();
if(timeToNext < 1)
{
(*iter)->Process();

View File

@ -18,7 +18,7 @@ namespace webrtc {
class MockVideoCaptureModule : public VideoCaptureModule {
public:
// from Module
MOCK_METHOD0(TimeUntilNextProcess, int32_t());
MOCK_METHOD0(TimeUntilNextProcess, int64_t());
MOCK_METHOD0(Process, int32_t());
// from RefCountedModule

View File

@ -24,7 +24,6 @@ enum {kMaxFrameRate =60}; // Max allowed frame rate of the start image
enum {kDefaultCaptureDelay = 120};
enum {kMaxCaptureDelay = 270}; // Max capture delay allowed in the precompiled capture delay values.
enum {kProcessInterval = 300};
enum {kFrameRateCallbackInterval = 1000};
enum {kFrameRateCountHistorySize = 90};
enum {kFrameRateHistoryWindowMs = 2000};

View File

@ -89,14 +89,12 @@ int32_t VideoCaptureImpl::ChangeUniqueId(const int32_t id)
}
// returns the number of milliseconds until the module want a worker thread to call Process
int32_t VideoCaptureImpl::TimeUntilNextProcess()
int64_t VideoCaptureImpl::TimeUntilNextProcess()
{
CriticalSectionScoped cs(&_callBackCs);
int32_t timeToNormalProcess = kProcessInterval
- (int32_t)((TickTime::Now() - _lastProcessTime).Milliseconds());
return timeToNormalProcess;
const int64_t kProcessIntervalMs = 300;
return kProcessIntervalMs -
(TickTime::Now() - _lastProcessTime).Milliseconds();
}
// Process any pending tasks such as timeouts

View File

@ -78,7 +78,7 @@ public:
virtual const char* CurrentDeviceName() const;
// Module handling
virtual int32_t TimeUntilNextProcess();
virtual int64_t TimeUntilNextProcess();
virtual int32_t Process();
// Implement VideoCaptureExternal

View File

@ -21,20 +21,16 @@
namespace webrtc {
namespace vcm {
uint32_t
int64_t
VCMProcessTimer::Period() const {
return _periodMs;
}
uint32_t
int64_t
VCMProcessTimer::TimeUntilProcess() const {
const int64_t time_since_process = _clock->TimeInMilliseconds() -
static_cast<int64_t>(_latestMs);
const int64_t time_until_process = static_cast<int64_t>(_periodMs) -
time_since_process;
if (time_until_process < 0)
return 0;
return time_until_process;
const int64_t time_since_process = _clock->TimeInMilliseconds() - _latestMs;
const int64_t time_until_process = _periodMs - time_since_process;
return std::max<int64_t>(time_until_process, 0);
}
void
@ -90,9 +86,9 @@ class VideoCodingModuleImpl : public VideoCodingModule {
own_event_factory_.reset();
}
virtual int32_t TimeUntilNextProcess() OVERRIDE {
int32_t sender_time = sender_->TimeUntilNextProcess();
int32_t receiver_time = receiver_->TimeUntilNextProcess();
virtual int64_t TimeUntilNextProcess() OVERRIDE {
int64_t sender_time = sender_->TimeUntilNextProcess();
int64_t receiver_time = receiver_->TimeUntilNextProcess();
assert(sender_time >= 0);
assert(receiver_time >= 0);
return VCM_MIN(sender_time, receiver_time);

View File

@ -37,17 +37,17 @@ class DebugRecorder;
class VCMProcessTimer {
public:
VCMProcessTimer(uint32_t periodMs, Clock* clock)
VCMProcessTimer(int64_t periodMs, Clock* clock)
: _clock(clock),
_periodMs(periodMs),
_latestMs(_clock->TimeInMilliseconds()) {}
uint32_t Period() const;
uint32_t TimeUntilProcess() const;
int64_t Period() const;
int64_t TimeUntilProcess() const;
void Processed();
private:
Clock* _clock;
uint32_t _periodMs;
int64_t _periodMs;
int64_t _latestMs;
};
@ -105,7 +105,7 @@ class VideoSender {
void SuspendBelowMinBitrate();
bool VideoSuspended() const;
int32_t TimeUntilNextProcess();
int64_t TimeUntilNextProcess();
int32_t Process();
private:
@ -179,7 +179,7 @@ class VideoReceiver {
int32_t SetReceiveChannelParameters(uint32_t rtt);
int32_t SetVideoProtection(VCMVideoProtection videoProtection, bool enable);
int32_t TimeUntilNextProcess();
int64_t TimeUntilNextProcess();
int32_t Process();
void RegisterPreDecodeImageCallback(EncodedImageCallback* observer);

View File

@ -154,8 +154,8 @@ int32_t VideoReceiver::Process() {
return returnValue;
}
int32_t VideoReceiver::TimeUntilNextProcess() {
uint32_t timeUntilNextProcess = _receiveStatsTimer.TimeUntilProcess();
int64_t VideoReceiver::TimeUntilNextProcess() {
int64_t timeUntilNextProcess = _receiveStatsTimer.TimeUntilProcess();
if (_receiver.NackMode() != kNoNack) {
// We need a Process call more often if we are relying on
// retransmissions

View File

@ -110,7 +110,7 @@ int32_t VideoSender::InitializeSender() {
return VCM_OK;
}
int32_t VideoSender::TimeUntilNextProcess() {
int64_t VideoSender::TimeUntilNextProcess() {
return _sendStatsTimer.TimeUntilProcess();
}

View File

@ -89,7 +89,7 @@ class VideoProcessingModule : public Module {
/**
Not supported.
*/
virtual int32_t TimeUntilNextProcess() OVERRIDE { return -1; }
virtual int64_t TimeUntilNextProcess() OVERRIDE { return -1; }
/**
Not supported.

View File

@ -59,7 +59,7 @@ public:
*/
virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE = 0;
virtual int32_t TimeUntilNextProcess() OVERRIDE = 0;
virtual int64_t TimeUntilNextProcess() OVERRIDE = 0;
virtual int32_t Process() OVERRIDE = 0;
/**************************************************************************

View File

@ -129,7 +129,7 @@ int32_t ModuleVideoRenderImpl::ChangeUniqueId(const int32_t id)
return 0;
}
int32_t ModuleVideoRenderImpl::TimeUntilNextProcess()
int64_t ModuleVideoRenderImpl::TimeUntilNextProcess()
{
// Not used
return 50;

View File

@ -39,7 +39,7 @@ public:
*/
virtual int32_t ChangeUniqueId(const int32_t id);
virtual int32_t TimeUntilNextProcess();
virtual int64_t TimeUntilNextProcess();
virtual int32_t Process();
/*

View File

@ -309,7 +309,7 @@ int32_t ModuleVideoRenderImpl::ChangeUniqueId(const int32_t id)
return 0;
}
int32_t ModuleVideoRenderImpl::TimeUntilNextProcess()
int64_t ModuleVideoRenderImpl::TimeUntilNextProcess()
{
// Not used
return 50;

View File

@ -78,9 +78,9 @@ bool DirectTransport::NetworkProcess(void* transport) {
bool DirectTransport::SendPackets() {
fake_network_.Process();
int wait_time_ms = fake_network_.TimeUntilNextProcess();
int64_t wait_time_ms = fake_network_.TimeUntilNextProcess();
if (wait_time_ms > 0) {
switch (packet_event_->Wait(wait_time_ms)) {
switch (packet_event_->Wait(static_cast<unsigned long>(wait_time_ms))) {
case kEventSignaled:
packet_event_->Reset();
break;

View File

@ -22,7 +22,6 @@
namespace webrtc {
const double kPi = 3.14159265;
const int kDefaultProcessIntervalMs = 30;
static int GaussianRandom(int mean_delay_ms, int standard_deviation_ms) {
// Creating a Normal distribution variable from two independent uniform
@ -208,12 +207,13 @@ void FakeNetworkPipe::Process() {
}
}
int FakeNetworkPipe::TimeUntilNextProcess() const {
int64_t FakeNetworkPipe::TimeUntilNextProcess() const {
CriticalSectionScoped crit(lock_.get());
const int64_t kDefaultProcessIntervalMs = 30;
if (capacity_link_.size() == 0 || delay_link_.size() == 0)
return kDefaultProcessIntervalMs;
return std::max(static_cast<int>(next_process_time_ -
TickTime::MillisecondTimestamp()), 0);
return std::max<int64_t>(
next_process_time_ - TickTime::MillisecondTimestamp(), 0);
}
} // namespace webrtc

View File

@ -66,7 +66,7 @@ class FakeNetworkPipe {
// Processes the network queues and trigger PacketReceiver::IncomingPacket for
// packets ready to be delivered.
void Process();
int TimeUntilNextProcess() const;
int64_t TimeUntilNextProcess() const;
// Get statistics.
float PercentageLoss();

View File

@ -18,14 +18,14 @@
namespace webrtc {
namespace {
// A rtt report is considered valid for this long.
const int kRttTimeoutMs = 1500;
// Time interval for updating the observers.
const int kUpdateIntervalMs = 1000;
const int64_t kUpdateIntervalMs = 1000;
// Weight factor to apply to the average rtt.
const float kWeightFactor = 0.3f;
void RemoveOldReports(int64_t now, std::list<CallStats::RttTime>* reports) {
// A rtt report is considered valid for this long.
const int64_t kRttTimeoutMs = 1500;
while (!reports->empty() &&
(now - reports->front().time) > kRttTimeoutMs) {
reports->pop_front();
@ -101,7 +101,7 @@ CallStats::~CallStats() {
assert(observers_.empty());
}
int32_t CallStats::TimeUntilNextProcess() {
int64_t CallStats::TimeUntilNextProcess() {
return last_process_time_ + kUpdateIntervalMs -
TickTime::MillisecondTimestamp();
}

View File

@ -32,7 +32,7 @@ class CallStats : public Module {
~CallStats();
// Implements Module, to use the process thread.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
// Returns a RtcpRttStats to register at a statistics provider. The object

View File

@ -384,7 +384,7 @@ void OveruseFrameDetector::GetCpuOveruseMetrics(
metrics->capture_queue_delay_ms_per_s = capture_queue_delay_->Value();
}
int32_t OveruseFrameDetector::TimeUntilNextProcess() {
int64_t OveruseFrameDetector::TimeUntilNextProcess() {
CriticalSectionScoped cs(crit_.get());
return next_process_time_ - clock_->TimeInMilliseconds();
}

View File

@ -99,7 +99,7 @@ class OveruseFrameDetector : public Module {
int FramesInQueue() const;
// Implements Module.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
private:

View File

@ -65,7 +65,7 @@ class WrappingBitrateEstimator : public RemoteBitrateEstimator {
return rbe_->Process();
}
virtual int32_t TimeUntilNextProcess() OVERRIDE {
virtual int64_t TimeUntilNextProcess() OVERRIDE {
CriticalSectionScoped cs(crit_sect_.get());
return rbe_->TimeUntilNextProcess();
}

View File

@ -22,8 +22,6 @@
namespace webrtc {
enum { kSyncInterval = 1000};
int UpdateMeasurements(StreamSynchronization::Measurements* stream,
const RtpRtcp& rtp_rtcp, const RtpReceiver& receiver) {
if (!receiver.Timestamp(&stream->latest_timestamp))
@ -93,9 +91,9 @@ int ViESyncModule::VoiceChannel() {
return voe_channel_id_;
}
int32_t ViESyncModule::TimeUntilNextProcess() {
return static_cast<int32_t>(kSyncInterval -
(TickTime::Now() - last_sync_time_).Milliseconds());
int64_t ViESyncModule::TimeUntilNextProcess() {
const int64_t kSyncIntervalMs = 1000;
return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds();
}
int32_t ViESyncModule::Process() {

View File

@ -45,7 +45,7 @@ class ViESyncModule : public Module {
int SetTargetBufferingDelay(int target_delay_ms);
// Implements Module.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
private:

View File

@ -58,13 +58,12 @@ MonitorModule::ChangeUniqueId(int32_t id)
return 0;
}
int32_t
int64_t
MonitorModule::TimeUntilNextProcess()
{
uint32_t now = TickTime::MillisecondTimestamp();
int32_t timeToNext =
kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
return (timeToNext);
int64_t now = TickTime::MillisecondTimestamp();
const int64_t kAverageProcessUpdateTimeMs = 1000;
return kAverageProcessUpdateTimeMs - (now - _lastProcessTime);
}
int32_t

View File

@ -42,14 +42,13 @@ public:
public: // module
virtual int32_t ChangeUniqueId(int32_t id) OVERRIDE;
virtual int32_t TimeUntilNextProcess() OVERRIDE;
virtual int64_t TimeUntilNextProcess() OVERRIDE;
virtual int32_t Process() OVERRIDE;
private:
enum { kAverageProcessUpdateTimeMs = 1000 };
MonitorObserver* _observerPtr;
CriticalSectionWrapper& _callbackCritSect;
int32_t _lastProcessTime;
int64_t _lastProcessTime;
};
} // namespace voe