Change rtc::TimeNanos and rtc::TimeMicros return value from uint64_t to int64_t.

Also updated types close to call sites.

BUG=webrtc:6733

Review-Url: https://codereview.webrtc.org/2514553003
Cr-Commit-Position: refs/heads/master@{#15255}
This commit is contained in:
nisse
2016-11-28 01:54:54 -08:00
committed by Commit bot
parent 71b9b58a3a
commit deb95f32f4
13 changed files with 46 additions and 45 deletions

View File

@ -52,12 +52,12 @@ class RTCStatsReport : public rtc::RefCountInterface {
// TODO(hbos): Remove "= 0" once Chromium unittest has been updated to call // TODO(hbos): Remove "= 0" once Chromium unittest has been updated to call
// with a parameter. crbug.com/627816 // with a parameter. crbug.com/627816
static rtc::scoped_refptr<RTCStatsReport> Create(uint64_t timestamp_us = 0); static rtc::scoped_refptr<RTCStatsReport> Create(int64_t timestamp_us = 0);
explicit RTCStatsReport(uint64_t timestamp_us); explicit RTCStatsReport(int64_t timestamp_us);
RTCStatsReport(const RTCStatsReport& other) = delete; RTCStatsReport(const RTCStatsReport& other) = delete;
uint64_t timestamp_us() const { return timestamp_us_; } int64_t timestamp_us() const { return timestamp_us_; }
bool AddStats(std::unique_ptr<const RTCStats> stats); bool AddStats(std::unique_ptr<const RTCStats> stats);
const RTCStats* Get(const std::string& id) const; const RTCStats* Get(const std::string& id) const;
size_t size() const { return stats_.size(); } size_t size() const { return stats_.size(); }
@ -90,7 +90,7 @@ class RTCStatsReport : public rtc::RefCountInterface {
private: private:
~RTCStatsReport() override; ~RTCStatsReport() override;
uint64_t timestamp_us_; int64_t timestamp_us_;
StatsMap stats_; StatsMap stats_;
}; };

View File

@ -15,12 +15,12 @@
namespace rtc { namespace rtc {
uint64_t FakeClock::TimeNanos() const { int64_t FakeClock::TimeNanos() const {
CritScope cs(&lock_); CritScope cs(&lock_);
return time_; return time_;
} }
void FakeClock::SetTimeNanos(uint64_t nanos) { void FakeClock::SetTimeNanos(int64_t nanos) {
{ {
CritScope cs(&lock_); CritScope cs(&lock_);
RTC_DCHECK(nanos >= time_); RTC_DCHECK(nanos >= time_);

View File

@ -26,18 +26,18 @@ class FakeClock : public ClockInterface {
~FakeClock() override {} ~FakeClock() override {}
// ClockInterface implementation. // ClockInterface implementation.
uint64_t TimeNanos() const override; int64_t TimeNanos() const override;
// Methods that can be used by the test to control the time. // Methods that can be used by the test to control the time.
// Should only be used to set a time in the future. // Should only be used to set a time in the future.
void SetTimeNanos(uint64_t nanos); void SetTimeNanos(int64_t nanos);
void AdvanceTime(TimeDelta delta); void AdvanceTime(TimeDelta delta);
private: private:
CriticalSection lock_; CriticalSection lock_;
uint64_t time_ GUARDED_BY(lock_) = 0u; int64_t time_ GUARDED_BY(lock_) = 0;
}; };
// Helper class that sets itself as the global clock in its constructor and // Helper class that sets itself as the global clock in its constructor and

View File

@ -64,7 +64,7 @@ static SrtpCipherMapEntry SrtpCipherMap[] = {
#ifdef OPENSSL_IS_BORINGSSL #ifdef OPENSSL_IS_BORINGSSL
static void TimeCallback(const SSL* ssl, struct timeval* out_clock) { static void TimeCallback(const SSL* ssl, struct timeval* out_clock) {
uint64_t time = TimeNanos(); int64_t time = TimeNanos();
out_clock->tv_sec = time / kNumNanosecsPerSec; out_clock->tv_sec = time / kNumNanosecsPerSec;
out_clock->tv_usec = (time % kNumNanosecsPerSec) / kNumNanosecsPerMicrosec; out_clock->tv_usec = (time % kNumNanosecsPerSec) / kNumNanosecsPerMicrosec;
} }

View File

@ -1038,7 +1038,7 @@ void SocketTest::SocketRecvTimestamp(const IPAddress& loopback) {
EXPECT_EQ(0, socket->Bind(SocketAddress(loopback, 0))); EXPECT_EQ(0, socket->Bind(SocketAddress(loopback, 0)));
SocketAddress address = socket->GetLocalAddress(); SocketAddress address = socket->GetLocalAddress();
uint64_t send_time_1 = TimeMicros(); int64_t send_time_1 = TimeMicros();
socket->SendTo("foo", 3, address); socket->SendTo("foo", 3, address);
int64_t recv_timestamp_1; int64_t recv_timestamp_1;
char buffer[3]; char buffer[3];
@ -1048,7 +1048,7 @@ void SocketTest::SocketRecvTimestamp(const IPAddress& loopback) {
const int64_t kTimeBetweenPacketsMs = 100; const int64_t kTimeBetweenPacketsMs = 100;
Thread::SleepMs(kTimeBetweenPacketsMs); Thread::SleepMs(kTimeBetweenPacketsMs);
uint64_t send_time_2 = TimeMicros(); int64_t send_time_2 = TimeMicros();
socket->SendTo("bar", 3, address); socket->SendTo("bar", 3, address);
int64_t recv_timestamp_2; int64_t recv_timestamp_2;
socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_2); socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_2);

View File

@ -39,7 +39,7 @@ ClockInterface* SetClockForTesting(ClockInterface* clock) {
return prev; return prev;
} }
uint64_t SystemTimeNanos() { int64_t SystemTimeNanos() {
int64_t ticks; int64_t ticks;
#if defined(WEBRTC_MAC) #if defined(WEBRTC_MAC)
static mach_timebase_info_data_t timebase; static mach_timebase_info_data_t timebase;
@ -88,7 +88,7 @@ int64_t SystemTimeMillis() {
return static_cast<int64_t>(SystemTimeNanos() / kNumNanosecsPerMillisec); return static_cast<int64_t>(SystemTimeNanos() / kNumNanosecsPerMillisec);
} }
uint64_t TimeNanos() { int64_t TimeNanos() {
if (g_clock) { if (g_clock) {
return g_clock->TimeNanos(); return g_clock->TimeNanos();
} }
@ -100,11 +100,11 @@ uint32_t Time32() {
} }
int64_t TimeMillis() { int64_t TimeMillis() {
return static_cast<int64_t>(TimeNanos() / kNumNanosecsPerMillisec); return TimeNanos() / kNumNanosecsPerMillisec;
} }
uint64_t TimeMicros() { int64_t TimeMicros() {
return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec); return TimeNanos() / kNumNanosecsPerMicrosec;
} }
int64_t TimeAfter(int64_t elapsed) { int64_t TimeAfter(int64_t elapsed) {

View File

@ -34,7 +34,7 @@ static const int64_t kNumNanosecsPerMicrosec =
class ClockInterface { class ClockInterface {
public: public:
virtual ~ClockInterface() {} virtual ~ClockInterface() {}
virtual uint64_t TimeNanos() const = 0; virtual int64_t TimeNanos() const = 0;
}; };
// Sets the global source of time. This is useful mainly for unit tests. // Sets the global source of time. This is useful mainly for unit tests.
@ -55,7 +55,7 @@ ClockInterface* SetClockForTesting(ClockInterface* clock);
// Returns the actual system time, even if a clock is set for testing. // Returns the actual system time, even if a clock is set for testing.
// Useful for timeouts while using a test clock, or for logging. // Useful for timeouts while using a test clock, or for logging.
uint64_t SystemTimeNanos(); int64_t SystemTimeNanos();
int64_t SystemTimeMillis(); int64_t SystemTimeMillis();
// Returns the current time in milliseconds in 32 bits. // Returns the current time in milliseconds in 32 bits.
@ -69,10 +69,11 @@ inline int64_t Time() {
} }
// Returns the current time in microseconds. // Returns the current time in microseconds.
uint64_t TimeMicros(); int64_t TimeMicros();
// Returns the current time in nanoseconds. // Returns the current time in nanoseconds.
uint64_t TimeNanos(); int64_t TimeNanos();
// Returns a future timestamp, 'elapsed' milliseconds from now. // Returns a future timestamp, 'elapsed' milliseconds from now.
int64_t TimeAfter(int64_t elapsed); int64_t TimeAfter(int64_t elapsed);
@ -88,7 +89,7 @@ inline int64_t TimeSince(int64_t earlier) {
} }
// The number of milliseconds that will elapse between now and 'later'. // The number of milliseconds that will elapse between now and 'later'.
inline int64_t TimeUntil(uint64_t later) { inline int64_t TimeUntil(int64_t later) {
return later - TimeMillis(); return later - TimeMillis();
} }

View File

@ -303,11 +303,11 @@ TEST(FakeClock, TimeFunctionsUseFakeClock) {
FakeClock clock; FakeClock clock;
SetClockForTesting(&clock); SetClockForTesting(&clock);
clock.SetTimeNanos(987654321u); clock.SetTimeNanos(987654321);
EXPECT_EQ(987u, Time32()); EXPECT_EQ(987u, Time32());
EXPECT_EQ(987, TimeMillis()); EXPECT_EQ(987, TimeMillis());
EXPECT_EQ(987654u, TimeMicros()); EXPECT_EQ(987654, TimeMicros());
EXPECT_EQ(987654321u, TimeNanos()); EXPECT_EQ(987654321, TimeNanos());
EXPECT_EQ(1000u, TimeAfter(13)); EXPECT_EQ(1000u, TimeAfter(13));
SetClockForTesting(nullptr); SetClockForTesting(nullptr);
@ -317,27 +317,27 @@ TEST(FakeClock, TimeFunctionsUseFakeClock) {
TEST(FakeClock, InitialTime) { TEST(FakeClock, InitialTime) {
FakeClock clock; FakeClock clock;
EXPECT_EQ(0u, clock.TimeNanos()); EXPECT_EQ(0, clock.TimeNanos());
} }
TEST(FakeClock, SetTimeNanos) { TEST(FakeClock, SetTimeNanos) {
FakeClock clock; FakeClock clock;
clock.SetTimeNanos(123u); clock.SetTimeNanos(123);
EXPECT_EQ(123u, clock.TimeNanos()); EXPECT_EQ(123, clock.TimeNanos());
clock.SetTimeNanos(456u); clock.SetTimeNanos(456);
EXPECT_EQ(456u, clock.TimeNanos()); EXPECT_EQ(456, clock.TimeNanos());
} }
TEST(FakeClock, AdvanceTime) { TEST(FakeClock, AdvanceTime) {
FakeClock clock; FakeClock clock;
clock.AdvanceTime(TimeDelta::FromNanoseconds(1111u)); clock.AdvanceTime(TimeDelta::FromNanoseconds(1111u));
EXPECT_EQ(1111u, clock.TimeNanos()); EXPECT_EQ(1111, clock.TimeNanos());
clock.AdvanceTime(TimeDelta::FromMicroseconds(2222u)); clock.AdvanceTime(TimeDelta::FromMicroseconds(2222u));
EXPECT_EQ(2223111u, clock.TimeNanos()); EXPECT_EQ(2223111, clock.TimeNanos());
clock.AdvanceTime(TimeDelta::FromMilliseconds(3333u)); clock.AdvanceTime(TimeDelta::FromMilliseconds(3333u));
EXPECT_EQ(3335223111u, clock.TimeNanos()); EXPECT_EQ(3335223111, clock.TimeNanos());
clock.AdvanceTime(TimeDelta::FromSeconds(4444u)); clock.AdvanceTime(TimeDelta::FromSeconds(4444u));
EXPECT_EQ(4447335223111u, clock.TimeNanos()); EXPECT_EQ(4447335223111, clock.TimeNanos());
} }
// When the clock is advanced, threads that are waiting in a socket select // When the clock is advanced, threads that are waiting in a socket select

View File

@ -111,7 +111,7 @@ void AudioDeviceBuffer::StartPlayout() {
if (!recording_) { if (!recording_) {
StartPeriodicLogging(); StartPeriodicLogging();
} }
const uint64_t now_time = rtc::TimeMillis(); const int64_t now_time = rtc::TimeMillis();
// Clear members that are only touched on the main (creating) thread. // Clear members that are only touched on the main (creating) thread.
play_start_time_ = now_time; play_start_time_ = now_time;
playing_ = true; playing_ = true;

View File

@ -220,7 +220,7 @@ class AudioDeviceBuffer {
int16_t max_play_level_ ACCESS_ON(task_queue_); int16_t max_play_level_ ACCESS_ON(task_queue_);
// Time stamp of last timer task (drives logging). // Time stamp of last timer task (drives logging).
uint64_t last_timer_task_time_ ACCESS_ON(task_queue_); int64_t last_timer_task_time_ ACCESS_ON(task_queue_);
// Counts number of audio callbacks modulo 50 to create a signal when // Counts number of audio callbacks modulo 50 to create a signal when
// a new storage of audio stats shall be done. // a new storage of audio stats shall be done.
@ -228,8 +228,8 @@ class AudioDeviceBuffer {
int16_t play_stat_count_ ACCESS_ON(playout_thread_checker_); int16_t play_stat_count_ ACCESS_ON(playout_thread_checker_);
// Time stamps of when playout and recording starts. // Time stamps of when playout and recording starts.
uint64_t play_start_time_ ACCESS_ON(main_thread_checker_); int64_t play_start_time_ ACCESS_ON(main_thread_checker_);
uint64_t rec_start_time_ ACCESS_ON(main_thread_checker_); int64_t rec_start_time_ ACCESS_ON(main_thread_checker_);
// Set to true at construction and modified to false as soon as one audio- // Set to true at construction and modified to false as soon as one audio-
// level estimate larger than zero is detected. // level estimate larger than zero is detected.

View File

@ -472,8 +472,8 @@ TEST_F(VideoCaptureExternalTest, TestExternalCapture) {
#define MAYBE_FrameRate FrameRate #define MAYBE_FrameRate FrameRate
#endif #endif
TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) {
uint64_t testTime = 3 * rtc::kNumNanosecsPerSec; int64_t testTime = 3 * rtc::kNumNanosecsPerSec;
uint64_t startTime = rtc::TimeNanos(); int64_t startTime = rtc::TimeNanos();
while ((rtc::TimeNanos() - startTime) < testTime) { while ((rtc::TimeNanos() - startTime) < testTime) {
size_t length = webrtc::CalcBufferSize(webrtc::kI420, size_t length = webrtc::CalcBufferSize(webrtc::kI420,

View File

@ -385,9 +385,9 @@ void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start, int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start,
int64_t stop) { int64_t stop) {
uint64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec; int64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec;
RTC_DCHECK_LT(encode_time, RTC_DCHECK_GE(encode_time, std::numeric_limits<int>::min());
static_cast<unsigned int>(std::numeric_limits<int>::max())); RTC_DCHECK_LE(encode_time, std::numeric_limits<int>::max());
return static_cast<int>(encode_time); return static_cast<int>(encode_time);
} }

View File

@ -57,12 +57,12 @@ bool RTCStatsReport::ConstIterator::operator!=(
} }
rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create( rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create(
uint64_t timestamp_us) { int64_t timestamp_us) {
return rtc::scoped_refptr<RTCStatsReport>( return rtc::scoped_refptr<RTCStatsReport>(
new rtc::RefCountedObject<RTCStatsReport>(timestamp_us)); new rtc::RefCountedObject<RTCStatsReport>(timestamp_us));
} }
RTCStatsReport::RTCStatsReport(uint64_t timestamp_us) RTCStatsReport::RTCStatsReport(int64_t timestamp_us)
: timestamp_us_(timestamp_us) { : timestamp_us_(timestamp_us) {
} }