diff --git a/webrtc/api/java/jni/androidmediacodeccommon.h b/webrtc/api/java/jni/androidmediacodeccommon.h index 2f9e05d1f5..db7260ade5 100644 --- a/webrtc/api/java/jni/androidmediacodeccommon.h +++ b/webrtc/api/java/jni/androidmediacodeccommon.h @@ -19,7 +19,6 @@ #include "webrtc/api/java/jni/jni_helpers.h" #include "webrtc/base/logging.h" #include "webrtc/base/thread.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc_jni { @@ -59,10 +58,6 @@ enum { kMaxDecodedLogFrames = 10 }; // Maximum amount of encoded frames for which per-frame logging is enabled. enum { kMaxEncodedLogFrames = 10 }; -static inline int64_t GetCurrentTimeMs() { - return webrtc::TickTime::Now().Ticks() / 1000000LL; -} - static inline void AllowBlockingCalls() { rtc::Thread* current_thread = rtc::Thread::Current(); if (current_thread != NULL) diff --git a/webrtc/api/java/jni/androidmediadecoder_jni.cc b/webrtc/api/java/jni/androidmediadecoder_jni.cc index 11c8d66f20..b3c2ffc241 100644 --- a/webrtc/api/java/jni/androidmediadecoder_jni.cc +++ b/webrtc/api/java/jni/androidmediadecoder_jni.cc @@ -32,7 +32,6 @@ #include "webrtc/common_video/include/i420_buffer_pool.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" #include "webrtc/system_wrappers/include/logcat_trace_context.h" -#include "webrtc/system_wrappers/include/tick_util.h" using rtc::Bind; using rtc::Thread; @@ -43,7 +42,6 @@ using webrtc::DecodedImageCallback; using webrtc::EncodedImage; using webrtc::VideoFrame; using webrtc::RTPFragmentationHeader; -using webrtc::TickTime; using webrtc::VideoCodec; using webrtc::VideoCodecType; using webrtc::kVideoCodecH264; @@ -319,7 +317,7 @@ void MediaCodecVideoDecoder::ResetVariables() { frames_received_ = 0; frames_decoded_ = 0; frames_decoded_logged_ = kMaxDecodedLogFrames; - start_time_ms_ = GetCurrentTimeMs(); + start_time_ms_ = rtc::TimeMillis(); current_frames_ = 0; current_bytes_ = 0; current_decoding_time_ms_ = 0; @@ -589,9 +587,9 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread( frames_received_ << ". Decoded: " << frames_decoded_; EnableFrameLogOnWarning(); } - const int64 drain_start = GetCurrentTimeMs(); + const int64 drain_start = rtc::TimeMillis(); while ((frames_received_ > frames_decoded_ + max_pending_frames_) && - (GetCurrentTimeMs() - drain_start) < kMediaCodecTimeoutMs) { + (rtc::TimeMillis() - drain_start) < kMediaCodecTimeoutMs) { if (!DeliverPendingOutputs(jni, kMediaCodecPollMs)) { ALOGE << "DeliverPendingOutputs error. Frames received: " << frames_received_ << ". Frames decoded: " << frames_decoded_; @@ -844,7 +842,7 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs( current_frames_++; current_decoding_time_ms_ += decode_time_ms; current_delay_time_ms_ += frame_delayed_ms; - int statistic_time_ms = GetCurrentTimeMs() - start_time_ms_; + int statistic_time_ms = rtc::TimeMillis() - start_time_ms_; if (statistic_time_ms >= kMediaCodecStatisticsIntervalMs && current_frames_ > 0) { int current_bitrate = current_bytes_ * 8 / statistic_time_ms; @@ -857,7 +855,7 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs( ". DecTime: " << (current_decoding_time_ms_ / current_frames_) << ". DelayTime: " << (current_delay_time_ms_ / current_frames_) << " for last " << statistic_time_ms << " ms."; - start_time_ms_ = GetCurrentTimeMs(); + start_time_ms_ = rtc::TimeMillis(); current_frames_ = 0; current_bytes_ = 0; current_decoding_time_ms_ = 0; @@ -993,4 +991,3 @@ const char* MediaCodecVideoDecoder::ImplementationName() const { } } // namespace webrtc_jni - diff --git a/webrtc/api/java/jni/androidmediaencoder_jni.cc b/webrtc/api/java/jni/androidmediaencoder_jni.cc index 7a13270b13..5a817b6e84 100644 --- a/webrtc/api/java/jni/androidmediaencoder_jni.cc +++ b/webrtc/api/java/jni/androidmediaencoder_jni.cc @@ -27,6 +27,7 @@ #include "webrtc/base/logging.h" #include "webrtc/base/thread.h" #include "webrtc/base/thread_checker.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_types.h" #include "webrtc/modules/rtp_rtcp/source/h264_bitstream_parser.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" @@ -524,7 +525,7 @@ int32_t MediaCodecVideoEncoder::InitEncodeOnCodecThread( frames_dropped_media_encoder_ = 0; consecutive_full_queue_frame_drops_ = 0; current_timestamp_us_ = 0; - stat_start_time_ms_ = GetCurrentTimeMs(); + stat_start_time_ms_ = rtc::TimeMillis(); current_frames_ = 0; current_bytes_ = 0; current_acc_qp_ = 0; @@ -612,7 +613,7 @@ int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( bool send_key_frame = false; if (codec_mode_ == webrtc::kRealtimeVideo) { ++frames_received_since_last_key_; - int64_t now_ms = GetCurrentTimeMs(); + int64_t now_ms = rtc::TimeMillis(); if (last_frame_received_ms_ != -1 && (now_ms - last_frame_received_ms_) > kFrameDiffThresholdMs) { // Add limit to prevent triggering a key for every frame for very low @@ -698,7 +699,7 @@ int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( return WEBRTC_VIDEO_CODEC_ERROR; } - const int64_t time_before_calling_encode = GetCurrentTimeMs(); + const int64_t time_before_calling_encode = rtc::TimeMillis(); const bool key_frame = frame_types->front() != webrtc::kVideoFrameDelta || send_key_frame; bool encode_status = true; @@ -950,7 +951,7 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { output_render_time_ms_ = frame_info.frame_render_time_ms; output_rotation_ = frame_info.rotation; frame_encoding_time_ms = - GetCurrentTimeMs() - frame_info.encode_start_time; + rtc::TimeMillis() - frame_info.encode_start_time; input_frame_infos_.pop_front(); } @@ -1113,7 +1114,7 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { } void MediaCodecVideoEncoder::LogStatistics(bool force_log) { - int statistic_time_ms = GetCurrentTimeMs() - stat_start_time_ms_; + int statistic_time_ms = rtc::TimeMillis() - stat_start_time_ms_; if ((statistic_time_ms >= kMediaCodecStatisticsIntervalMs || force_log) && current_frames_ > 0 && statistic_time_ms > 0) { int current_bitrate = current_bytes_ * 8 / statistic_time_ms; @@ -1126,7 +1127,7 @@ void MediaCodecVideoEncoder::LogStatistics(bool force_log) { ", encTime: " << (current_encoding_time_ms_ / current_frames_) << ". QP: " << (current_acc_qp_ / current_frames_) << " for last " << statistic_time_ms << " ms."; - stat_start_time_ms_ = GetCurrentTimeMs(); + stat_start_time_ms_ = rtc::TimeMillis(); current_frames_ = 0; current_bytes_ = 0; current_acc_qp_ = 0; diff --git a/webrtc/audio/audio_receive_stream.cc b/webrtc/audio/audio_receive_stream.cc index f984c7fb20..fb17fccefc 100644 --- a/webrtc/audio/audio_receive_stream.cc +++ b/webrtc/audio/audio_receive_stream.cc @@ -18,9 +18,9 @@ #include "webrtc/audio/conversion.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/congestion_controller/include/congestion_controller.h" #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/voice_engine/channel_proxy.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/include/voe_codec.h" @@ -230,7 +230,7 @@ bool AudioReceiveStream::DeliverRtp(const uint8_t* packet, // video and shouldn't be mixed. if (remote_bitrate_estimator_ && header.extension.hasTransportSequenceNumber) { - int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); + int64_t arrival_time_ms = rtc::TimeMillis(); if (packet_time.timestamp >= 0) arrival_time_ms = (packet_time.timestamp + 500) / 1000; size_t payload_size = length - header.headerLength; diff --git a/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc b/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc index afb0963c3f..aca73b2d4b 100644 --- a/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc +++ b/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc @@ -14,10 +14,10 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/common_audio/resampler/push_sinc_resampler.h" #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -86,16 +86,17 @@ void PushSincResamplerTest::ResampleBenchmarkTest(bool int_format) { const double io_ratio = input_rate_ / static_cast(output_rate_); SincResampler sinc_resampler(io_ratio, SincResampler::kDefaultRequestSize, &resampler_source); - TickTime start = TickTime::Now(); + int64_t start = rtc::TimeNanos(); for (int i = 0; i < kResampleIterations; ++i) { sinc_resampler.Resample(output_samples, resampled_destination.get()); } - double total_time_sinc_us = (TickTime::Now() - start).Microseconds(); + double total_time_sinc_us = + (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; printf("SincResampler took %.2f us per frame.\n", total_time_sinc_us / kResampleIterations); PushSincResampler resampler(input_samples, output_samples); - start = TickTime::Now(); + start = rtc::TimeNanos(); if (int_format) { for (int i = 0; i < kResampleIterations; ++i) { EXPECT_EQ(output_samples, @@ -113,7 +114,8 @@ void PushSincResamplerTest::ResampleBenchmarkTest(bool int_format) { output_samples)); } } - double total_time_us = (TickTime::Now() - start).Microseconds(); + double total_time_us = + (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; printf("PushSincResampler took %.2f us per frame; which is a %.1f%% overhead " "on SincResampler.\n\n", total_time_us / kResampleIterations, (total_time_us - total_time_sinc_us) / total_time_sinc_us * 100); diff --git a/webrtc/common_audio/resampler/sinc_resampler_unittest.cc b/webrtc/common_audio/resampler/sinc_resampler_unittest.cc index 42172ebdda..d3b0dcd428 100644 --- a/webrtc/common_audio/resampler/sinc_resampler_unittest.cc +++ b/webrtc/common_audio/resampler/sinc_resampler_unittest.cc @@ -20,11 +20,11 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_audio/resampler/sinc_resampler.h" #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" #include "webrtc/system_wrappers/include/stringize_macros.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/test_suite.h" using testing::_; @@ -107,10 +107,11 @@ TEST(SincResamplerTest, DISABLED_SetRatioBench) { SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, &mock_source); - TickTime start = TickTime::Now(); + int64_t start = rtc::TimeNanos(); for (int i = 1; i < 10000; ++i) resampler.SetRatio(1.0 / i); - double total_time_c_us = (TickTime::Now() - start).Microseconds(); + double total_time_c_us = + (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; printf("SetRatio() took %.2fms.\n", total_time_c_us / 1000); } @@ -179,13 +180,14 @@ TEST(SincResamplerTest, ConvolveBenchmark) { printf("Benchmarking %d iterations:\n", kConvolveIterations); // Benchmark Convolve_C(). - TickTime start = TickTime::Now(); + int64_t start = rtc::TimeNanos(); for (int i = 0; i < kConvolveIterations; ++i) { resampler.Convolve_C( resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), kKernelInterpolationFactor); } - double total_time_c_us = (TickTime::Now() - start).Microseconds(); + double total_time_c_us = + (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; printf("Convolve_C took %.2fms.\n", total_time_c_us / 1000); #if defined(CONVOLVE_FUNC) @@ -196,27 +198,27 @@ TEST(SincResamplerTest, ConvolveBenchmark) { #endif // Benchmark with unaligned input pointer. - start = TickTime::Now(); + start = rtc::TimeNanos(); for (int j = 0; j < kConvolveIterations; ++j) { resampler.CONVOLVE_FUNC( resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), kKernelInterpolationFactor); } double total_time_optimized_unaligned_us = - (TickTime::Now() - start).Microseconds(); + (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; printf(STRINGIZE(CONVOLVE_FUNC) "(unaligned) took %.2fms; which is %.2fx " "faster than Convolve_C.\n", total_time_optimized_unaligned_us / 1000, total_time_c_us / total_time_optimized_unaligned_us); // Benchmark with aligned input pointer. - start = TickTime::Now(); + start = rtc::TimeNanos(); for (int j = 0; j < kConvolveIterations; ++j) { resampler.CONVOLVE_FUNC( resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), kKernelInterpolationFactor); } double total_time_optimized_aligned_us = - (TickTime::Now() - start).Microseconds(); + (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; printf(STRINGIZE(CONVOLVE_FUNC) " (aligned) took %.2fms; which is %.2fx " "faster than Convolve_C and %.2fx faster than " STRINGIZE(CONVOLVE_FUNC) " (unaligned).\n", diff --git a/webrtc/common_video/incoming_video_stream.cc b/webrtc/common_video/incoming_video_stream.cc index 01da4a6b5b..5fc8eae0bd 100644 --- a/webrtc/common_video/incoming_video_stream.cc +++ b/webrtc/common_video/incoming_video_stream.cc @@ -22,11 +22,11 @@ #endif #include "webrtc/base/platform_thread.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/common_video/video_render_frames.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { @@ -56,7 +56,7 @@ void IncomingVideoStream::OnFrame(const VideoFrame& video_frame) { // Rate statistics. num_frames_since_last_calculation_++; - int64_t now_ms = TickTime::MillisecondTimestamp(); + int64_t now_ms = rtc::TimeMillis(); if (now_ms >= last_rate_calculation_time_ms_ + kFrameRatePeriodMs) { incoming_rate_ = static_cast(1000 * num_frames_since_last_calculation_ / diff --git a/webrtc/common_video/libyuv/libyuv_unittest.cc b/webrtc/common_video/libyuv/libyuv_unittest.cc index 9f92b8bb15..99ad725597 100644 --- a/webrtc/common_video/libyuv/libyuv_unittest.cc +++ b/webrtc/common_video/libyuv/libyuv_unittest.cc @@ -15,7 +15,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/video_frame.h" diff --git a/webrtc/common_video/libyuv/scaler_unittest.cc b/webrtc/common_video/libyuv/scaler_unittest.cc index 9ba1b9d94f..29a0a7403d 100644 --- a/webrtc/common_video/libyuv/scaler_unittest.cc +++ b/webrtc/common_video/libyuv/scaler_unittest.cc @@ -14,8 +14,8 @@ #include #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_video/libyuv/include/scaler.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" namespace webrtc { @@ -378,9 +378,9 @@ void TestScaler::ScaleSequence(ScaleMethod method, (src_width + 1) / 2, kVideoRotation_0); - start_clock = TickTime::MillisecondTimestamp(); + start_clock = rtc::TimeMillis(); EXPECT_EQ(0, test_scaler_.Scale(input_frame, &output_frame)); - total_clock += TickTime::MillisecondTimestamp() - start_clock; + total_clock += rtc::TimeMillis() - start_clock; if (PrintVideoFrame(output_frame, output_file) < 0) { return; } diff --git a/webrtc/common_video/video_render_frames.cc b/webrtc/common_video/video_render_frames.cc index 8b447cb10f..3e5dfe9d10 100644 --- a/webrtc/common_video/video_render_frames.cc +++ b/webrtc/common_video/video_render_frames.cc @@ -12,8 +12,8 @@ #include +#include "webrtc/base/timeutils.h" #include "webrtc/modules/include/module_common_types.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { @@ -27,7 +27,7 @@ VideoRenderFrames::VideoRenderFrames() } int32_t VideoRenderFrames::AddFrame(const VideoFrame& new_frame) { - const int64_t time_now = TickTime::MillisecondTimestamp(); + const int64_t time_now = rtc::TimeMillis(); // Drop old frames only when there are other frames in the queue, otherwise, a // really slow system never renders any frames. @@ -74,7 +74,7 @@ uint32_t VideoRenderFrames::TimeToNextFrameRelease() { } const int64_t time_to_release = incoming_frames_.front().render_time_ms() - render_delay_ms_ - - TickTime::MillisecondTimestamp(); + rtc::TimeMillis(); return time_to_release < 0 ? 0u : static_cast(time_to_release); } diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/acm2/acm_receiver.cc index f8bacf8dc7..7c96c28968 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receiver.cc +++ b/webrtc/modules/audio_coding/acm2/acm_receiver.cc @@ -26,7 +26,6 @@ #include "webrtc/modules/audio_coding/acm2/call_statistics.h" #include "webrtc/modules/audio_coding/neteq/include/neteq.h" #include "webrtc/system_wrappers/include/clock.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { diff --git a/webrtc/modules/audio_coding/test/APITest.cc b/webrtc/modules/audio_coding/test/APITest.cc index a2506ba011..25bacfd60b 100644 --- a/webrtc/modules/audio_coding/test/APITest.cc +++ b/webrtc/modules/audio_coding/test/APITest.cc @@ -21,13 +21,13 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/platform_thread.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common.h" #include "webrtc/common_types.h" #include "webrtc/engine_configurations.h" #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/test/testsupport/fileutils.h" @@ -560,7 +560,7 @@ void APITest::Perform() { // Keep main thread waiting for sender/receiver // threads to complete EventWrapper* completeEvent = EventWrapper::Create(); - uint64_t startTime = TickTime::MillisecondTimestamp(); + uint64_t startTime = rtc::TimeMillis(); uint64_t currentTime; // Run test in 2 minutes (120000 ms). do { @@ -570,7 +570,7 @@ void APITest::Perform() { } //fflush(stderr); completeEvent->Wait(50); - currentTime = TickTime::MillisecondTimestamp(); + currentTime = rtc::TimeMillis(); } while ((currentTime - startTime) < 120000); //completeEvent->Wait(0xFFFFFFFF); diff --git a/webrtc/modules/audio_coding/test/Channel.cc b/webrtc/modules/audio_coding/test/Channel.cc index 0507691fb4..46c398b1b7 100644 --- a/webrtc/modules/audio_coding/test/Channel.cc +++ b/webrtc/modules/audio_coding/test/Channel.cc @@ -14,7 +14,7 @@ #include #include "webrtc/base/format_macros.h" -#include "webrtc/system_wrappers/include/tick_util.h" +#include "webrtc/base/timeutils.h" namespace webrtc { @@ -234,7 +234,7 @@ Channel::Channel(int16_t chID) _lastFrameSizeSample(0), _packetLoss(0), _useFECTestWithPacketLoss(false), - _beginTime(TickTime::MillisecondTimestamp()), + _beginTime(rtc::TimeMillis()), _totalBytes(0), external_send_timestamp_(-1), external_sequence_number_(-1), @@ -286,7 +286,7 @@ void Channel::ResetStats() { _payloadStats[n].frameSizeStats[k].totalEncodedSamples = 0; } } - _beginTime = TickTime::MillisecondTimestamp(); + _beginTime = rtc::TimeMillis(); _totalBytes = 0; _channelCritSect.Leave(); } @@ -411,7 +411,7 @@ uint32_t Channel::LastInTimestamp() { double Channel::BitRate() { double rate; - uint64_t currTime = TickTime::MillisecondTimestamp(); + uint64_t currTime = rtc::TimeMillis(); _channelCritSect.Enter(); rate = ((double) _totalBytes * 8.0) / (double) (currTime - _beginTime); _channelCritSect.Leave(); diff --git a/webrtc/modules/audio_coding/test/iSACTest.cc b/webrtc/modules/audio_coding/test/iSACTest.cc index 9f223fb81f..abc84b2073 100644 --- a/webrtc/modules/audio_coding/test/iSACTest.cc +++ b/webrtc/modules/audio_coding/test/iSACTest.cc @@ -26,7 +26,6 @@ #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/test/testsupport/fileutils.h" diff --git a/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc b/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc index 19f5bd8848..30b2933b61 100644 --- a/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc +++ b/webrtc/modules/audio_conference_mixer/source/time_scheduler.cc @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/base/timeutils.h" #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" @@ -17,7 +18,7 @@ TimeScheduler::TimeScheduler(const int64_t periodicityInMs) _isStarted(false), _lastPeriodMark(), _periodicityInMs(periodicityInMs), - _periodicityInTicks(TickTime::MillisecondsToTicks(periodicityInMs)), + _periodicityInTicks(periodicityInMs * rtc::kNumNanosecsPerMillisec), _missedPeriods(0) { } @@ -33,7 +34,7 @@ int32_t TimeScheduler::UpdateScheduler() if(!_isStarted) { _isStarted = true; - _lastPeriodMark = TickTime::Now(); + _lastPeriodMark = rtc::TimeNanos(); return 0; } // Don't perform any calculations until the debt of pending periods have @@ -45,9 +46,9 @@ int32_t TimeScheduler::UpdateScheduler() } // Calculate the time that has past since previous call to this function. - TickTime tickNow = TickTime::Now(); - TickInterval amassedTicks = tickNow - _lastPeriodMark; - int64_t amassedMs = amassedTicks.Milliseconds(); + int64_t tickNow = rtc::TimeNanos(); + int64_t amassedTicks = tickNow - _lastPeriodMark; + int64_t amassedMs = amassedTicks / rtc::kNumNanosecsPerMillisec; // Calculate the number of periods the time that has passed correspond to. int64_t periodsToClaim = amassedMs / _periodicityInMs; @@ -89,10 +90,10 @@ int32_t TimeScheduler::TimeToNextUpdate( // Calculate the time (in ms) that has past since last call to // UpdateScheduler() - TickTime tickNow = TickTime::Now(); - TickInterval ticksSinceLastUpdate = tickNow - _lastPeriodMark; + int64_t tickNow = rtc::TimeNanos(); + int64_t ticksSinceLastUpdate = tickNow - _lastPeriodMark; const int64_t millisecondsSinceLastUpdate = - ticksSinceLastUpdate.Milliseconds(); + ticksSinceLastUpdate / rtc::kNumNanosecsPerMillisec; updateTimeInMS = _periodicityInMs - millisecondsSinceLastUpdate; updateTimeInMS = (updateTimeInMS < 0) ? 0 : updateTimeInMS; diff --git a/webrtc/modules/audio_conference_mixer/source/time_scheduler.h b/webrtc/modules/audio_conference_mixer/source/time_scheduler.h index 09d0caa66a..d1897fa100 100644 --- a/webrtc/modules/audio_conference_mixer/source/time_scheduler.h +++ b/webrtc/modules/audio_conference_mixer/source/time_scheduler.h @@ -15,8 +15,6 @@ #ifndef WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_TIME_SCHEDULER_H_ #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_TIME_SCHEDULER_H_ -#include "webrtc/system_wrappers/include/tick_util.h" - namespace webrtc { class CriticalSectionWrapper; class TimeScheduler @@ -36,7 +34,7 @@ private: CriticalSectionWrapper* _crit; bool _isStarted; - TickTime _lastPeriodMark; + int64_t _lastPeriodMark; // In ns int64_t _periodicityInMs; int64_t _periodicityInTicks; diff --git a/webrtc/modules/audio_device/audio_device_impl.cc b/webrtc/modules/audio_device/audio_device_impl.cc index 23ac1e4650..7abc94d5f7 100644 --- a/webrtc/modules/audio_device/audio_device_impl.cc +++ b/webrtc/modules/audio_device/audio_device_impl.cc @@ -9,11 +9,11 @@ */ #include "webrtc/base/refcount.h" +#include "webrtc/base/timeutils.h" #include "webrtc/base/trace_event.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_device/audio_device_config.h" #include "webrtc/modules/audio_device/audio_device_impl.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include #include @@ -123,7 +123,7 @@ AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer _ptrAudioDevice(NULL), _id(id), _platformAudioLayer(audioLayer), - _lastProcessTime(TickTime::MillisecondTimestamp()), + _lastProcessTime(rtc::TimeMillis()), _platformType(kPlatformNotSupported), _initialized(false), _lastError(kAdmErrNone) @@ -407,7 +407,7 @@ AudioDeviceModuleImpl::~AudioDeviceModuleImpl() int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() { - int64_t now = TickTime::MillisecondTimestamp(); + int64_t now = rtc::TimeMillis(); int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime); return deltaProcess; } @@ -422,7 +422,7 @@ int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() void AudioDeviceModuleImpl::Process() { - _lastProcessTime = TickTime::MillisecondTimestamp(); + _lastProcessTime = rtc::TimeMillis(); // kPlayoutWarning if (_ptrAudioDevice->PlayoutWarning()) diff --git a/webrtc/modules/audio_device/win/audio_device_wave_win.cc b/webrtc/modules/audio_device/win/audio_device_wave_win.cc index 8079051184..c149708992 100644 --- a/webrtc/modules/audio_device/win/audio_device_wave_win.cc +++ b/webrtc/modules/audio_device/win/audio_device_wave_win.cc @@ -8,11 +8,11 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/base/timeutils.h" #include "webrtc/modules/audio_device/audio_device_config.h" #include "webrtc/modules/audio_device/win/audio_device_wave_win.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" #include @@ -206,7 +206,7 @@ int32_t AudioDeviceWindowsWave::Init() return 0; } - const uint32_t nowTime(TickTime::MillisecondTimestamp()); + const uint32_t nowTime(rtc::TimeMillis()); _recordedBytes = 0; _prevRecByteCheckTime = nowTime; @@ -3038,7 +3038,7 @@ bool AudioDeviceWindowsWave::ThreadProcess() return true; } - time = TickTime::MillisecondTimestamp(); + time = rtc::TimeMillis(); if (_startPlay) { diff --git a/webrtc/modules/audio_processing/test/audio_file_processor.h b/webrtc/modules/audio_processing/test/audio_file_processor.h index f7cde59821..76d5e0edb8 100644 --- a/webrtc/modules/audio_processing/test/audio_file_processor.h +++ b/webrtc/modules/audio_processing/test/audio_file_processor.h @@ -16,11 +16,11 @@ #include #include +#include "webrtc/base/timeutils.h" #include "webrtc/common_audio/channel_buffer.h" #include "webrtc/common_audio/wav_file.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/test/test_utils.h" -#include "webrtc/system_wrappers/include/tick_util.h" #ifdef WEBRTC_ANDROID_PLATFORM_BUILD #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" @@ -33,9 +33,9 @@ namespace webrtc { // Holds a few statistics about a series of TickIntervals. struct TickIntervalStats { TickIntervalStats() : min(std::numeric_limits::max()) {} - TickInterval sum; - TickInterval max; - TickInterval min; + int64_t sum; + int64_t max; + int64_t min; }; // Interface for processing an input file with an AudioProcessing instance and @@ -60,10 +60,10 @@ class AudioFileProcessor { class ScopedTimer { public: explicit ScopedTimer(TickIntervalStats* proc_time) - : proc_time_(proc_time), start_time_(TickTime::Now()) {} + : proc_time_(proc_time), start_time_(rtc::TimeNanos()) {} ~ScopedTimer() { - TickInterval interval = TickTime::Now() - start_time_; + int64_t interval = rtc::TimeNanos() - start_time_; proc_time_->sum += interval; proc_time_->max = std::max(proc_time_->max, interval); proc_time_->min = std::min(proc_time_->min, interval); @@ -71,7 +71,7 @@ class AudioFileProcessor { private: TickIntervalStats* const proc_time_; - TickTime start_time_; + int64_t start_time_; }; TickIntervalStats* mutable_proc_time() { return &proc_time_; } diff --git a/webrtc/modules/audio_processing/test/audioproc_float.cc b/webrtc/modules/audio_processing/test/audioproc_float.cc index 41e45bfdc6..33790d837f 100644 --- a/webrtc/modules/audio_processing/test/audioproc_float.cc +++ b/webrtc/modules/audio_processing/test/audioproc_float.cc @@ -25,7 +25,6 @@ #include "webrtc/modules/audio_processing/test/audio_file_processor.h" #include "webrtc/modules/audio_processing/test/protobuf_utils.h" #include "webrtc/modules/audio_processing/test/test_utils.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/trace_to_stderr.h" namespace { @@ -167,13 +166,14 @@ int main(int argc, char* argv[]) { if (FLAGS_perf) { const auto& proc_time = processor->proc_time(); - int64_t exec_time_us = proc_time.sum.Microseconds(); + int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec; printf( "\nExecution time: %.3f s, File time: %.2f s\n" "Time per chunk (mean, max, min):\n%.0f us, %.0f us, %.0f us\n", exec_time_us * 1e-6, num_chunks * 1.f / kChunksPerSecond, - exec_time_us * 1.f / num_chunks, 1.f * proc_time.max.Microseconds(), - 1.f * proc_time.min.Microseconds()); + exec_time_us * 1.f / num_chunks, + 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec, + 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec); } return 0; diff --git a/webrtc/modules/audio_processing/test/process_test.cc b/webrtc/modules/audio_processing/test/process_test.cc index 185bc142d5..527e0a1e3e 100644 --- a/webrtc/modules/audio_processing/test/process_test.cc +++ b/webrtc/modules/audio_processing/test/process_test.cc @@ -19,13 +19,13 @@ #include #include "webrtc/base/format_macros.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/test/protobuf_utils.h" #include "webrtc/modules/audio_processing/test/test_utils.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/test/testsupport/perf_test.h" #ifdef WEBRTC_ANDROID_PLATFORM_BUILD @@ -562,7 +562,7 @@ void void_main(int argc, char* argv[]) { int reverse_count = 0; int primary_count = 0; int near_read_bytes = 0; - TickInterval acc_ticks; + int64_t acc_nanos = 0; AudioFrame far_frame; AudioFrame near_frame; @@ -573,8 +573,8 @@ void void_main(int argc, char* argv[]) { int8_t stream_has_voice = 0; float ns_speech_prob = 0.0f; - TickTime t0 = TickTime::Now(); - TickTime t1 = t0; + int64_t t0 = rtc::TimeNanos(); + int64_t t1 = t0; int64_t max_time_us = 0; int64_t max_time_reverse_us = 0; int64_t min_time_us = 1e6; @@ -676,7 +676,7 @@ void void_main(int argc, char* argv[]) { } if (perf_testing) { - t0 = TickTime::Now(); + t0 = rtc::TimeNanos(); } if (msg.has_data()) { @@ -692,14 +692,15 @@ void void_main(int argc, char* argv[]) { } if (perf_testing) { - t1 = TickTime::Now(); - TickInterval tick_diff = t1 - t0; - acc_ticks += tick_diff; - if (tick_diff.Microseconds() > max_time_reverse_us) { - max_time_reverse_us = tick_diff.Microseconds(); + t1 = rtc::TimeNanos(); + int64_t diff_nanos = t1 - t0; + acc_nanos += diff_nanos; + int64_t diff_us = diff_nanos / rtc::kNumNanosecsPerMicrosec; + if (diff_us > max_time_reverse_us) { + max_time_reverse_us = diff_us; } - if (tick_diff.Microseconds() < min_time_reverse_us) { - min_time_reverse_us = tick_diff.Microseconds(); + if (diff_us < min_time_reverse_us) { + min_time_reverse_us = diff_us; } } @@ -737,7 +738,7 @@ void void_main(int argc, char* argv[]) { } if (perf_testing) { - t0 = TickTime::Now(); + t0 = rtc::TimeNanos(); } ASSERT_EQ(apm->kNoError, @@ -795,14 +796,15 @@ void void_main(int argc, char* argv[]) { } if (perf_testing) { - t1 = TickTime::Now(); - TickInterval tick_diff = t1 - t0; - acc_ticks += tick_diff; - if (tick_diff.Microseconds() > max_time_us) { - max_time_us = tick_diff.Microseconds(); + t1 = rtc::TimeNanos(); + int64_t diff_nanos = t1 - t0; + acc_nanos += diff_nanos; + int64_t diff_us = diff_nanos / rtc::kNumNanosecsPerMicrosec; + if (diff_us > max_time_us) { + max_time_us = diff_us; } - if (tick_diff.Microseconds() < min_time_us) { - min_time_us = tick_diff.Microseconds(); + if (diff_us < min_time_us) { + min_time_us = diff_us; } } @@ -925,21 +927,22 @@ void void_main(int argc, char* argv[]) { } if (perf_testing) { - t0 = TickTime::Now(); + t0 = rtc::TimeNanos(); } ASSERT_EQ(apm->kNoError, apm->ProcessReverseStream(&far_frame)); if (perf_testing) { - t1 = TickTime::Now(); - TickInterval tick_diff = t1 - t0; - acc_ticks += tick_diff; - if (tick_diff.Microseconds() > max_time_reverse_us) { - max_time_reverse_us = tick_diff.Microseconds(); + t1 = rtc::TimeNanos(); + int64_t diff_nanos = t1 - t0; + acc_nanos += diff_nanos; + int64_t diff_us = diff_nanos / rtc::kNumNanosecsPerMicrosec; + if (diff_us > max_time_reverse_us) { + max_time_reverse_us = diff_us; } - if (tick_diff.Microseconds() < min_time_reverse_us) { - min_time_reverse_us = tick_diff.Microseconds(); + if (diff_us < min_time_reverse_us) { + min_time_reverse_us = diff_us; } } @@ -982,7 +985,7 @@ void void_main(int argc, char* argv[]) { } if (perf_testing) { - t0 = TickTime::Now(); + t0 = rtc::TimeNanos(); } const int capture_level_in = capture_level; @@ -1030,14 +1033,15 @@ void void_main(int argc, char* argv[]) { } if (perf_testing) { - t1 = TickTime::Now(); - TickInterval tick_diff = t1 - t0; - acc_ticks += tick_diff; - if (tick_diff.Microseconds() > max_time_us) { - max_time_us = tick_diff.Microseconds(); + t1 = rtc::TimeNanos(); + int64_t diff_nanos = t1 - t0; + acc_nanos += diff_nanos; + int64_t diff_us = diff_nanos / rtc::kNumNanosecsPerMicrosec; + if (diff_us > max_time_us) { + max_time_us = diff_us; } - if (tick_diff.Microseconds() < min_time_us) { - min_time_us = tick_diff.Microseconds(); + if (diff_us < min_time_us) { + min_time_us = diff_us; } } @@ -1130,7 +1134,7 @@ void void_main(int argc, char* argv[]) { if (perf_testing) { if (primary_count > 0) { - int64_t exec_time = acc_ticks.Milliseconds(); + int64_t exec_time = acc_nanos / rtc::kNumNanosecsPerMillisec; printf("\nTotal time: %.3f s, file time: %.2f s\n", exec_time * 0.001, primary_count * 0.01); printf("Time per frame: %.3f ms (average), %.3f ms (max)," diff --git a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc index 2d3c2d9047..451acb3db5 100644 --- a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc +++ b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc @@ -15,6 +15,7 @@ #include #include "webrtc/base/macutils.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" #include "webrtc/system_wrappers/include/logging.h" @@ -141,7 +142,7 @@ bool IsChromeWindow(CGWindowID id) { } // namespace FullScreenChromeWindowDetector::FullScreenChromeWindowDetector() - : ref_count_(0) {} + : ref_count_(0), last_update_time_ns_(0) {} FullScreenChromeWindowDetector::~FullScreenChromeWindowDetector() {} @@ -161,10 +162,7 @@ CGWindowID FullScreenChromeWindowDetector::FindFullScreenWindow( if (static_cast(it->id) != full_screen_window_id) continue; - int64_t time_interval = - (TickTime::Now() - last_udpate_time_).Milliseconds(); - LOG(LS_WARNING) << "The full-screen window exists in the list, " - << "which was updated " << time_interval << "ms ago."; + LOG(LS_WARNING) << "The full-screen window exists in the list."; return kCGNullWindowID; } @@ -174,7 +172,7 @@ CGWindowID FullScreenChromeWindowDetector::FindFullScreenWindow( void FullScreenChromeWindowDetector::UpdateWindowListIfNeeded( CGWindowID original_window) { if (IsChromeWindow(original_window) && - (TickTime::Now() - last_udpate_time_).Milliseconds() + (rtc::TimeNanos() - last_update_time_ns_) / rtc::kNumNanosecsPerMillisec > kUpdateIntervalMs) { previous_window_list_.clear(); previous_window_list_.swap(current_window_list_); @@ -186,7 +184,7 @@ void FullScreenChromeWindowDetector::UpdateWindowListIfNeeded( } GetWindowList(¤t_window_list_); - last_udpate_time_ = TickTime::Now(); + last_update_time_ns_ = rtc::TimeNanos(); } } diff --git a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h index 186b9bf58f..838966d46e 100644 --- a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h +++ b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h @@ -16,7 +16,6 @@ #include "webrtc/base/constructormagic.h" #include "webrtc/modules/desktop_capture/window_capturer.h" #include "webrtc/system_wrappers/include/atomic32.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -60,7 +59,7 @@ class FullScreenChromeWindowDetector { // full-screen window exists in the list) if Capture() is called too soon. WindowCapturer::WindowList current_window_list_; WindowCapturer::WindowList previous_window_list_; - TickTime last_udpate_time_; + int64_t last_update_time_ns_; RTC_DISALLOW_COPY_AND_ASSIGN(FullScreenChromeWindowDetector); }; diff --git a/webrtc/modules/desktop_capture/screen_capturer_mac.mm b/webrtc/modules/desktop_capture/screen_capturer_mac.mm index 1acbda2d6e..bf6c72950c 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_mac.mm +++ b/webrtc/modules/desktop_capture/screen_capturer_mac.mm @@ -25,6 +25,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/macutils.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/desktop_geometry.h" @@ -36,7 +37,6 @@ #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" #include "webrtc/system_wrappers/include/logging.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -384,7 +384,7 @@ void ScreenCapturerMac::Start(Callback* callback) { } void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { - TickTime capture_start_time = TickTime::Now(); + int64_t capture_start_time_nanos = rtc::TimeNanos(); queue_.MoveToNextFrame(); RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); @@ -448,7 +448,8 @@ void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { desktop_config_monitor_->Unlock(); new_frame->set_capture_time_ms( - (TickTime::Now() - capture_start_time).Milliseconds()); + (rtc::TimeNanos() - capture_start_time_nanos) / + rtc::kNumNanosecsPerMillisec); callback_->OnCaptureCompleted(new_frame); } diff --git a/webrtc/modules/desktop_capture/screen_capturer_x11.cc b/webrtc/modules/desktop_capture/screen_capturer_x11.cc index 4bd6baa628..5540e6820f 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_x11.cc +++ b/webrtc/modules/desktop_capture/screen_capturer_x11.cc @@ -22,6 +22,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/constructormagic.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/differ.h" @@ -30,7 +31,6 @@ #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" #include "webrtc/system_wrappers/include/logging.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { namespace { @@ -236,7 +236,7 @@ void ScreenCapturerLinux::Start(Callback* callback) { } void ScreenCapturerLinux::Capture(const DesktopRegion& region) { - TickTime capture_start_time = TickTime::Now(); + int64_t capture_start_time_nanos = rtc::TimeNanos(); queue_.MoveToNextFrame(); RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); @@ -277,7 +277,8 @@ void ScreenCapturerLinux::Capture(const DesktopRegion& region) { DesktopFrame* result = CaptureScreen(); last_invalid_region_ = result->updated_region(); result->set_capture_time_ms( - (TickTime::Now() - capture_start_time).Milliseconds()); + (rtc::TimeNanos() - capture_start_time_nanos) / + rtc::kNumNanosecsPerMillisec); callback_->OnCaptureCompleted(result); } diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc index 2a5a87e90a..9df2e5fc9b 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc @@ -15,6 +15,7 @@ #include #include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/desktop_frame_win.h" @@ -25,7 +26,6 @@ #include "webrtc/modules/desktop_capture/win/desktop.h" #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" #include "webrtc/system_wrappers/include/logging.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -79,7 +79,7 @@ void ScreenCapturerWinGdi::SetSharedMemoryFactory( } void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { - TickTime capture_start_time = TickTime::Now(); + int64_t capture_start_time_nanos = rtc::TimeNanos(); queue_.MoveToNextFrame(); RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); @@ -137,7 +137,8 @@ void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { frame->mutable_updated_region()->Clear(); helper_.TakeInvalidRegion(frame->mutable_updated_region()); frame->set_capture_time_ms( - (TickTime::Now() - capture_start_time).Milliseconds()); + (rtc::TimeNanos() - capture_start_time_nanos) / + rtc::kNumNanosecsPerMillisec); callback_->OnCaptureCompleted(frame); } diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc index e3a5f258a8..6b4308bb7a 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc @@ -14,6 +14,7 @@ #include +#include "webrtc/base/timeutils.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/desktop_frame_win.h" @@ -24,7 +25,6 @@ #include "webrtc/modules/desktop_capture/win/desktop.h" #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" #include "webrtc/system_wrappers/include/logging.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -87,7 +87,7 @@ void ScreenCapturerWinMagnifier::SetSharedMemoryFactory( } void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) { - TickTime capture_start_time = TickTime::Now(); + int64_t capture_start_time_nanos = rtc::TimeNanos(); queue_.MoveToNextFrame(); @@ -168,7 +168,8 @@ void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) { frame->mutable_updated_region()->Clear(); helper_.TakeInvalidRegion(frame->mutable_updated_region()); frame->set_capture_time_ms( - (TickTime::Now() - capture_start_time).Milliseconds()); + (rtc::TimeNanos() - capture_start_time_nanos) / + rtc::kNumNanosecsPerMillisec); callback_->OnCaptureCompleted(frame); } diff --git a/webrtc/modules/desktop_capture/window_capturer_mac.mm b/webrtc/modules/desktop_capture/window_capturer_mac.mm index 67ee4e0c31..ac5fdb6bc1 100644 --- a/webrtc/modules/desktop_capture/window_capturer_mac.mm +++ b/webrtc/modules/desktop_capture/window_capturer_mac.mm @@ -24,7 +24,6 @@ #include "webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h" #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" #include "webrtc/system_wrappers/include/logging.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { diff --git a/webrtc/modules/media_file/media_file_impl.cc b/webrtc/modules/media_file/media_file_impl.cc index 76bcca74d2..27fe9613a3 100644 --- a/webrtc/modules/media_file/media_file_impl.cc +++ b/webrtc/modules/media_file/media_file_impl.cc @@ -14,7 +14,6 @@ #include "webrtc/modules/media_file/media_file_impl.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index 5b79fe385c..cda776bf22 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -17,6 +17,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/base/trace_event.h" +#include "webrtc/base/timeutils.h" #include "webrtc/call.h" #include "webrtc/call/rtc_event_log.h" #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" @@ -24,7 +25,6 @@ #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h" #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" #include "webrtc/modules/rtp_rtcp/source/time_util.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -116,10 +116,8 @@ RTPSender::RTPSender( RtcEventLog* event_log, SendPacketObserver* send_packet_observer) : clock_(clock), - // TODO(holmer): Remove this conversion when we remove the use of - // TickTime. - clock_delta_ms_(clock_->TimeInMilliseconds() - - TickTime::MillisecondTimestamp()), + // TODO(holmer): Remove this conversion? + clock_delta_ms_(clock_->TimeInMilliseconds() - rtc::TimeMillis()), random_(clock_->TimeInMicroseconds()), bitrates_(bitrate_callback), total_bitrate_sent_(clock, bitrates_.total_bitrate_observer()), diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc index 6d0f7a4627..4236e1f37d 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc @@ -13,10 +13,10 @@ #include #include "webrtc/base/logging.h" +#include "webrtc/base/timeutils.h" #include "webrtc/base/trace_event.h" #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -351,7 +351,7 @@ int32_t RTPSenderAudio::SendAudio(FrameType frameType, _rtpSender->SequenceNumber()); int32_t send_result = _rtpSender->SendToNetwork( dataBuffer, payloadSize, rtpHeaderLength, - TickTime::MillisecondTimestamp(), kAllowRetransmission, + rtc::TimeMillis(), kAllowRetransmission, RtpPacketSender::kHighPriority); if (first_packet_sent_()) { LOG(LS_INFO) << "First audio RTP packet sent to pacer"; @@ -450,7 +450,7 @@ int32_t RTPSenderAudio::SendTelephoneEventPacket(bool ended, "Audio::SendTelephoneEvent", "timestamp", dtmfTimeStamp, "seqnum", _rtpSender->SequenceNumber()); retVal = _rtpSender->SendToNetwork( - dtmfbuffer, 4, 12, TickTime::MillisecondTimestamp(), + dtmfbuffer, 4, 12, rtc::TimeMillis(), kAllowRetransmission, RtpPacketSender::kHighPriority); sendCount--; } while (sendCount > 0 && retVal == 0); diff --git a/webrtc/modules/rtp_rtcp/source/ssrc_database.cc b/webrtc/modules/rtp_rtcp/source/ssrc_database.cc index f1d1549e27..a96d05db46 100644 --- a/webrtc/modules/rtp_rtcp/source/ssrc_database.cc +++ b/webrtc/modules/rtp_rtcp/source/ssrc_database.cc @@ -9,9 +9,8 @@ */ #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" - +#include "webrtc/base/timeutils.h" #include "webrtc/base/checks.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -45,7 +44,7 @@ void SSRCDatabase::ReturnSSRC(uint32_t ssrc) { ssrcs_.erase(ssrc); } -SSRCDatabase::SSRCDatabase() : random_(TickTime::Now().Ticks()) {} +SSRCDatabase::SSRCDatabase() : random_(rtc::TimeMicros()) {} SSRCDatabase::~SSRCDatabase() {} diff --git a/webrtc/modules/utility/include/file_recorder.h b/webrtc/modules/utility/include/file_recorder.h index 09ed8ae350..480a4a9799 100644 --- a/webrtc/modules/utility/include/file_recorder.h +++ b/webrtc/modules/utility/include/file_recorder.h @@ -15,7 +15,6 @@ #include "webrtc/engine_configurations.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/media_file/media_file_defines.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/typedefs.h" #include "webrtc/video_frame.h" @@ -58,8 +57,7 @@ public: // Write frame to file. Frame should contain 10ms of un-ecoded audio data. virtual int32_t RecordAudioToFile( - const AudioFrame& frame, - const TickTime* playoutTS = NULL) = 0; + const AudioFrame& frame) = 0; // Open/create the file specified by fileName for writing audio/video data // (relative path is allowed). audioCodecInst specifies the encoding of the diff --git a/webrtc/modules/utility/source/file_player_impl.h b/webrtc/modules/utility/source/file_player_impl.h index beb6379ff0..62887da13b 100644 --- a/webrtc/modules/utility/source/file_player_impl.h +++ b/webrtc/modules/utility/source/file_player_impl.h @@ -19,7 +19,6 @@ #include "webrtc/modules/utility/include/file_player.h" #include "webrtc/modules/utility/source/coder.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/typedefs.h" namespace webrtc { diff --git a/webrtc/modules/utility/source/file_recorder_impl.cc b/webrtc/modules/utility/source/file_recorder_impl.cc index 88b20eeac2..b0a766f22e 100644 --- a/webrtc/modules/utility/source/file_recorder_impl.cc +++ b/webrtc/modules/utility/source/file_recorder_impl.cc @@ -130,8 +130,7 @@ bool FileRecorderImpl::IsRecording() const } int32_t FileRecorderImpl::RecordAudioToFile( - const AudioFrame& incomingAudioFrame, - const TickTime* playoutTS) + const AudioFrame& incomingAudioFrame) { if (codec_info_.plfreq == 0) { diff --git a/webrtc/modules/utility/source/file_recorder_impl.h b/webrtc/modules/utility/source/file_recorder_impl.h index 44169cc267..96f811d49e 100644 --- a/webrtc/modules/utility/source/file_recorder_impl.h +++ b/webrtc/modules/utility/source/file_recorder_impl.h @@ -27,7 +27,6 @@ #include "webrtc/modules/utility/include/file_recorder.h" #include "webrtc/modules/utility/source/coder.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -58,9 +57,7 @@ public: int32_t StopRecording() override; bool IsRecording() const override; int32_t codec_info(CodecInst& codecInst) const override; - int32_t RecordAudioToFile( - const AudioFrame& frame, - const TickTime* playoutTS = NULL) override; + int32_t RecordAudioToFile(const AudioFrame& frame) override; int32_t StartRecordingVideoFile( const char* fileName, const CodecInst& audioCodecInst, diff --git a/webrtc/modules/utility/source/process_thread_impl.cc b/webrtc/modules/utility/source/process_thread_impl.cc index 68c7ab676d..4e3606ca08 100644 --- a/webrtc/modules/utility/source/process_thread_impl.cc +++ b/webrtc/modules/utility/source/process_thread_impl.cc @@ -11,9 +11,9 @@ #include "webrtc/modules/utility/source/process_thread_impl.h" #include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/include/module.h" #include "webrtc/system_wrappers/include/logging.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { namespace { @@ -188,7 +188,7 @@ bool ProcessThreadImpl::Run(void* obj) { } bool ProcessThreadImpl::Process() { - int64_t now = TickTime::MillisecondTimestamp(); + int64_t now = rtc::TimeMillis(); int64_t next_checkpoint = now + (1000 * 60); { @@ -209,7 +209,7 @@ bool ProcessThreadImpl::Process() { // Use a new 'now' reference to calculate when the next callback // should occur. We'll continue to use 'now' above for the baseline // of calculating how long we should wait, to reduce variance. - int64_t new_now = TickTime::MillisecondTimestamp(); + int64_t new_now = rtc::TimeMillis(); m.next_callback = GetNextCallbackTime(m.module, new_now); } @@ -227,7 +227,7 @@ bool ProcessThreadImpl::Process() { } } - int64_t time_to_wait = next_checkpoint - TickTime::MillisecondTimestamp(); + int64_t time_to_wait = next_checkpoint - rtc::TimeMillis(); if (time_to_wait > 0) wake_up_->Wait(static_cast(time_to_wait)); diff --git a/webrtc/modules/utility/source/process_thread_impl_unittest.cc b/webrtc/modules/utility/source/process_thread_impl_unittest.cc index 16f3b501f8..5b31870ac4 100644 --- a/webrtc/modules/utility/source/process_thread_impl_unittest.cc +++ b/webrtc/modules/utility/source/process_thread_impl_unittest.cc @@ -13,9 +13,9 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/include/module.h" #include "webrtc/modules/utility/source/process_thread_impl.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -51,7 +51,7 @@ ACTION_P(Increment, counter) { } ACTION_P(SetTimestamp, ptr) { - *ptr = TickTime::MillisecondTimestamp(); + *ptr = rtc::TimeMillis(); } TEST(ProcessThreadImpl, StartStop) { diff --git a/webrtc/modules/video_capture/test/video_capture_unittest.cc b/webrtc/modules/video_capture/test/video_capture_unittest.cc index e75ad038c8..9d9eda92f2 100644 --- a/webrtc/modules/video_capture/test/video_capture_unittest.cc +++ b/webrtc/modules/video_capture/test/video_capture_unittest.cc @@ -16,19 +16,18 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/scoped_ref_ptr.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/utility/include/process_thread.h" #include "webrtc/modules/video_capture/video_capture.h" #include "webrtc/modules/video_capture/video_capture_factory.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/video_frame.h" using webrtc::CriticalSectionWrapper; using webrtc::CriticalSectionScoped; using webrtc::SleepMs; -using webrtc::TickTime; using webrtc::VideoCaptureAlarm; using webrtc::VideoCaptureCapability; using webrtc::VideoCaptureDataCallback; @@ -40,8 +39,8 @@ using webrtc::VideoCaptureModule; #define WAIT_(ex, timeout, res) \ do { \ res = (ex); \ - int64_t start = TickTime::MillisecondTimestamp(); \ - while (!res && TickTime::MillisecondTimestamp() < start + timeout) { \ + int64_t start = rtc::TimeMillis(); \ + while (!res && rtc::TimeMillis() < start + timeout) { \ SleepMs(5); \ res = (ex); \ } \ @@ -118,8 +117,8 @@ class TestVideoCaptureCallback : public VideoCaptureDataCallback { #endif // RenderTimstamp should be the time now. EXPECT_TRUE( - videoFrame.render_time_ms() >= TickTime::MillisecondTimestamp()-30 && - videoFrame.render_time_ms() <= TickTime::MillisecondTimestamp()); + videoFrame.render_time_ms() >= rtc::TimeMillis()-30 && + videoFrame.render_time_ms() <= rtc::TimeMillis()); if ((videoFrame.render_time_ms() > last_render_time_ms_ + (1000 * 1.1) / capability_.maxFPS && @@ -277,7 +276,7 @@ class VideoCaptureTest : public testing::Test { #endif TEST_F(VideoCaptureTest, MAYBE_CreateDelete) { for (int i = 0; i < 5; ++i) { - int64_t start_time = TickTime::MillisecondTimestamp(); + int64_t start_time = rtc::TimeMillis(); TestVideoCaptureCallback capture_observer; rtc::scoped_refptr module( OpenVideoCaptureDevice(0, &capture_observer)); @@ -296,19 +295,19 @@ TEST_F(VideoCaptureTest, MAYBE_CreateDelete) { ASSERT_NO_FATAL_FAILURE(StartCapture(module.get(), capability)); // Less than 4s to start the camera. - EXPECT_LE(TickTime::MillisecondTimestamp() - start_time, 4000); + EXPECT_LE(rtc::TimeMillis() - start_time, 4000); // Make sure 5 frames are captured. EXPECT_TRUE_WAIT(capture_observer.incoming_frames() >= 5, kTimeOut); EXPECT_GE(capture_observer.capture_delay(), 0); - int64_t stop_time = TickTime::MillisecondTimestamp(); + int64_t stop_time = rtc::TimeMillis(); EXPECT_EQ(0, module->StopCapture()); EXPECT_FALSE(module->CaptureStarted()); // Less than 3s to stop the camera. - EXPECT_LE(TickTime::MillisecondTimestamp() - stop_time, 3000); + EXPECT_LE(rtc::TimeMillis() - stop_time, 3000); } } @@ -492,10 +491,10 @@ TEST_F(VideoCaptureExternalTest, TestExternalCapture) { #define MAYBE_FrameRate FrameRate #endif TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { - int64_t testTime = 3; - TickTime startTime = TickTime::Now(); + uint64_t testTime = 3 * rtc::kNumNanosecsPerSec; + uint64_t startTime = rtc::TimeNanos(); - while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { + while ((rtc::TimeNanos() - startTime) < testTime) { size_t length = webrtc::CalcBufferSize(webrtc::kI420, test_frame_.width(), test_frame_.height()); @@ -510,8 +509,8 @@ TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { SleepMs(500); EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); - startTime = TickTime::Now(); - while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { + startTime = rtc::TimeNanos(); + while ((rtc::TimeNanos() - startTime) < testTime) { size_t length = webrtc::CalcBufferSize(webrtc::kI420, test_frame_.width(), test_frame_.height()); diff --git a/webrtc/modules/video_capture/video_capture_impl.cc b/webrtc/modules/video_capture/video_capture_impl.cc index b1e697edc2..c3d5f37091 100644 --- a/webrtc/modules/video_capture/video_capture_impl.cc +++ b/webrtc/modules/video_capture/video_capture_impl.cc @@ -13,6 +13,7 @@ #include #include "webrtc/base/refcount.h" +#include "webrtc/base/timeutils.h" #include "webrtc/base/trace_event.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/include/module_common_types.h" @@ -20,7 +21,6 @@ #include "webrtc/system_wrappers/include/clock.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/logging.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { namespace videocapturemodule { @@ -85,7 +85,8 @@ int64_t VideoCaptureImpl::TimeUntilNextProcess() CriticalSectionScoped cs(&_callBackCs); const int64_t kProcessIntervalMs = 300; return kProcessIntervalMs - - (TickTime::Now() - _lastProcessTime).Milliseconds(); + (rtc::TimeNanos() - _lastProcessTimeNanos) / + rtc::kNumNanosecsPerMillisec; } // Process any pending tasks such as timeouts @@ -93,12 +94,12 @@ void VideoCaptureImpl::Process() { CriticalSectionScoped cs(&_callBackCs); - const TickTime now = TickTime::Now(); - _lastProcessTime = TickTime::Now(); + const int64_t now_ns = rtc::TimeNanos(); + _lastProcessTimeNanos = rtc::TimeNanos(); // Handle No picture alarm - if (_lastProcessFrameCount.Ticks() == _incomingFrameTimes[0].Ticks() && + if (_lastProcessFrameTimeNanos == _incomingFrameTimesNanos[0] && _captureAlarm != Raised) { if (_noPictureAlarmCallBack && _captureCallBack) @@ -107,7 +108,7 @@ void VideoCaptureImpl::Process() _captureCallBack->OnNoPictureAlarm(_id, _captureAlarm); } } - else if (_lastProcessFrameCount.Ticks() != _incomingFrameTimes[0].Ticks() && + else if (_lastProcessFrameTimeNanos != _incomingFrameTimesNanos[0] && _captureAlarm != Cleared) { if (_noPictureAlarmCallBack && _captureCallBack) @@ -119,19 +120,21 @@ void VideoCaptureImpl::Process() } // Handle frame rate callback - if ((now - _lastFrameRateCallbackTime).Milliseconds() + if ((now_ns - _lastFrameRateCallbackTimeNanos) / + rtc::kNumNanosecsPerMillisec > kFrameRateCallbackInterval) { if (_frameRateCallBack && _captureCallBack) { - const uint32_t frameRate = CalculateFrameRate(now); + const uint32_t frameRate = CalculateFrameRate(now_ns); _captureCallBack->OnCaptureFrameRate(_id, frameRate); } - _lastFrameRateCallbackTime = now; // Can be set by EnableFrameRateCallback + // Can be set by EnableFrameRateCallback + _lastFrameRateCallbackTimeNanos = now_ns; } - _lastProcessFrameCount = _incomingFrameTimes[0]; + _lastProcessFrameTimeNanos = _incomingFrameTimesNanos[0]; } VideoCaptureImpl::VideoCaptureImpl(const int32_t id) @@ -141,15 +144,15 @@ VideoCaptureImpl::VideoCaptureImpl(const int32_t id) _captureDelay(0), _requestedCapability(), _callBackCs(*CriticalSectionWrapper::CreateCriticalSection()), - _lastProcessTime(TickTime::Now()), - _lastFrameRateCallbackTime(TickTime::Now()), + _lastProcessTimeNanos(rtc::TimeNanos()), + _lastFrameRateCallbackTimeNanos(rtc::TimeNanos()), _frameRateCallBack(false), _noPictureAlarmCallBack(false), _captureAlarm(Cleared), _setCaptureDelay(0), _dataCallBack(NULL), _captureCallBack(NULL), - _lastProcessFrameCount(TickTime::Now()), + _lastProcessFrameTimeNanos(rtc::TimeNanos()), _rotateFrame(kVideoRotation_0), apply_rotation_(false) { _requestedCapability.width = kDefaultWidth; @@ -157,7 +160,7 @@ VideoCaptureImpl::VideoCaptureImpl(const int32_t id) _requestedCapability.maxFPS = 30; _requestedCapability.rawType = kVideoI420; _requestedCapability.codecType = kVideoCodecUnknown; - memset(_incomingFrameTimes, 0, sizeof(_incomingFrameTimes)); + memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos)); } VideoCaptureImpl::~VideoCaptureImpl() @@ -295,7 +298,7 @@ int32_t VideoCaptureImpl::IncomingFrame( _captureFrame.set_rotation(kVideoRotation_0); } _captureFrame.set_ntp_time_ms(captureTime); - _captureFrame.set_render_time_ms(TickTime::MillisecondTimestamp()); + _captureFrame.set_render_time_ms(rtc::TimeMillis()); DeliverCapturedFrame(_captureFrame); } @@ -321,7 +324,7 @@ void VideoCaptureImpl::EnableFrameRateCallback(const bool enable) { _frameRateCallBack = enable; if (enable) { - _lastFrameRateCallbackTime = TickTime::Now(); + _lastFrameRateCallbackTimeNanos = rtc::TimeNanos(); } } @@ -341,7 +344,7 @@ void VideoCaptureImpl::EnableNoPictureAlarm(const bool enable) { void VideoCaptureImpl::UpdateFrameCount() { - if (_incomingFrameTimes[0].MicrosecondTimestamp() == 0) + if (_incomingFrameTimesNanos[0] / rtc::kNumNanosecsPerMicrosec == 0) { // first no shift } @@ -350,20 +353,22 @@ void VideoCaptureImpl::UpdateFrameCount() // shift for (int i = (kFrameRateCountHistorySize - 2); i >= 0; i--) { - _incomingFrameTimes[i + 1] = _incomingFrameTimes[i]; + _incomingFrameTimesNanos[i + 1] = _incomingFrameTimesNanos[i]; } } - _incomingFrameTimes[0] = TickTime::Now(); + _incomingFrameTimesNanos[0] = rtc::TimeNanos(); } -uint32_t VideoCaptureImpl::CalculateFrameRate(const TickTime& now) +uint32_t VideoCaptureImpl::CalculateFrameRate(int64_t now_ns) { int32_t num = 0; int32_t nrOfFrames = 0; for (num = 1; num < (kFrameRateCountHistorySize - 1); num++) { - if (_incomingFrameTimes[num].Ticks() <= 0 - || (now - _incomingFrameTimes[num]).Milliseconds() > kFrameRateHistoryWindowMs) // don't use data older than 2sec + if (_incomingFrameTimesNanos[num] <= 0 || + (now_ns - _incomingFrameTimesNanos[num]) / + rtc::kNumNanosecsPerMillisec > + kFrameRateHistoryWindowMs) // don't use data older than 2sec { break; } @@ -374,7 +379,8 @@ uint32_t VideoCaptureImpl::CalculateFrameRate(const TickTime& now) } if (num > 1) { - int64_t diff = (now - _incomingFrameTimes[num - 1]).Milliseconds(); + int64_t diff = (now_ns - _incomingFrameTimesNanos[num - 1]) / + rtc::kNumNanosecsPerMillisec; if (diff > 0) { return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); diff --git a/webrtc/modules/video_capture/video_capture_impl.h b/webrtc/modules/video_capture/video_capture_impl.h index 9c2cad7c95..7d785c3a90 100644 --- a/webrtc/modules/video_capture/video_capture_impl.h +++ b/webrtc/modules/video_capture/video_capture_impl.h @@ -20,7 +20,6 @@ #include "webrtc/common_video/rotation.h" #include "webrtc/modules/video_capture/video_capture.h" #include "webrtc/modules/video_capture/video_capture_config.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/video_frame.h" namespace webrtc @@ -116,12 +115,14 @@ protected: VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture. private: void UpdateFrameCount(); - uint32_t CalculateFrameRate(const TickTime& now); + uint32_t CalculateFrameRate(int64_t now_ns); CriticalSectionWrapper& _callBackCs; - TickTime _lastProcessTime; // last time the module process function was called. - TickTime _lastFrameRateCallbackTime; // last time the frame rate callback function was called. + // last time the module process function was called. + int64_t _lastProcessTimeNanos; + // last time the frame rate callback function was called. + int64_t _lastFrameRateCallbackTimeNanos; bool _frameRateCallBack; // true if EnableFrameRateCallback bool _noPictureAlarmCallBack; //true if EnableNoPictureAlarm VideoCaptureAlarm _captureAlarm; // current value of the noPictureAlarm @@ -130,8 +131,9 @@ private: VideoCaptureDataCallback* _dataCallBack; VideoCaptureFeedBack* _captureCallBack; - TickTime _lastProcessFrameCount; - TickTime _incomingFrameTimes[kFrameRateCountHistorySize];// timestamp for local captured frames + int64_t _lastProcessFrameTimeNanos; + // timestamp for local captured frames + int64_t _incomingFrameTimesNanos[kFrameRateCountHistorySize]; VideoRotation _rotateFrame; // Set if the frame should be rotated by the // capture module. diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc index e64babd599..9a9a0ddf16 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc @@ -17,6 +17,7 @@ #include #include +#include "webrtc/base/timeutils.h" #include "webrtc/system_wrappers/include/cpu_info.h" namespace webrtc { @@ -198,7 +199,7 @@ bool VideoProcessorImpl::ProcessFrame(int frame_number) { // Ensure we have a new statistics data object we can fill: FrameStatistic& stat = stats_->NewFrame(frame_number); - encode_start_ = TickTime::Now(); + encode_start_ns_ = rtc::TimeNanos(); // Use the frame number as "timestamp" to identify frames source_frame_.set_timestamp(frame_number); @@ -248,11 +249,11 @@ void VideoProcessorImpl::FrameEncoded( encoded_frame_type_ = encoded_image._frameType; - TickTime encode_stop = TickTime::Now(); + int64_t encode_stop_ns = rtc::TimeNanos(); int frame_number = encoded_image._timeStamp; FrameStatistic& stat = stats_->stats_[frame_number]; stat.encode_time_in_us = - GetElapsedTimeMicroseconds(encode_start_, encode_stop); + GetElapsedTimeMicroseconds(encode_start_ns_, encode_stop_ns); stat.encoding_successful = true; stat.encoded_frame_length_in_bytes = encoded_image._length; stat.frame_number = encoded_image._timeStamp; @@ -299,7 +300,7 @@ void VideoProcessorImpl::FrameEncoded( // Keep track of if frames are lost due to packet loss so we can tell // this to the encoder (this is handled by the RTP logic in the full stack) - decode_start_ = TickTime::Now(); + decode_start_ns_ = rtc::TimeNanos(); // TODO(kjellander): Pass fragmentation header to the decoder when // CL 172001 has been submitted and PacketManipulator supports this. int32_t decode_result = @@ -315,12 +316,12 @@ void VideoProcessorImpl::FrameEncoded( } void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) { - TickTime decode_stop = TickTime::Now(); + int64_t decode_stop_ns = rtc::TimeNanos(); int frame_number = image.timestamp(); // Report stats FrameStatistic& stat = stats_->stats_[frame_number]; stat.decode_time_in_us = - GetElapsedTimeMicroseconds(decode_start_, decode_stop); + GetElapsedTimeMicroseconds(decode_start_ns_, decode_stop_ns); stat.decoding_successful = true; // Check for resize action (either down or up): @@ -378,10 +379,9 @@ void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) { } } -int VideoProcessorImpl::GetElapsedTimeMicroseconds( - const webrtc::TickTime& start, - const webrtc::TickTime& stop) { - uint64_t encode_time = (stop - start).Microseconds(); +int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start, + int64_t stop) { + uint64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec; assert(encode_time < static_cast(std::numeric_limits::max())); return static_cast(encode_time); diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.h b/webrtc/modules/video_coding/codecs/test/videoprocessor.h index cd1c7b9d62..f0322dd67b 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.h +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.h @@ -19,7 +19,6 @@ #include "webrtc/modules/video_coding/include/video_codec_interface.h" #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" #include "webrtc/modules/video_coding/codecs/test/stats.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/frame_reader.h" #include "webrtc/test/testsupport/frame_writer.h" #include "webrtc/video_frame.h" @@ -179,8 +178,7 @@ class VideoProcessorImpl : public VideoProcessor { void FrameDecoded(const webrtc::VideoFrame& image); // Used for getting a 32-bit integer representing time // (checks the size is within signed 32-bit bounds before casting it) - int GetElapsedTimeMicroseconds(const webrtc::TickTime& start, - const webrtc::TickTime& stop); + int GetElapsedTimeMicroseconds(int64_t start, int64_t stop); // Updates the encoder with the target bit rate and the frame rate. void SetRates(int bit_rate, int frame_rate) override; // Return the size of the encoded frame in bytes. @@ -225,8 +223,8 @@ class VideoProcessorImpl : public VideoProcessor { // Statistics double bit_rate_factor_; // multiply frame length with this to get bit rate - webrtc::TickTime encode_start_; - webrtc::TickTime decode_start_; + int64_t encode_start_ns_; + int64_t decode_start_ns_; // Callback class required to implement according to the VideoEncoder API. class VideoProcessorEncodeCompleteCallback diff --git a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc index f3ebfa1f76..d562dd4bb9 100644 --- a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc +++ b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc @@ -14,9 +14,9 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" namespace webrtc { @@ -159,8 +159,8 @@ class TestVp8Impl : public ::testing::Test { } size_t WaitForEncodedFrame() const { - int64_t startTime = TickTime::MillisecondTimestamp(); - while (TickTime::MillisecondTimestamp() - startTime < kMaxWaitEncTimeMs) { + int64_t startTime = rtc::TimeMillis(); + while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { if (encode_complete_callback_->EncodeComplete()) { return encoded_frame_._length; } @@ -169,8 +169,8 @@ class TestVp8Impl : public ::testing::Test { } size_t WaitForDecodedFrame() const { - int64_t startTime = TickTime::MillisecondTimestamp(); - while (TickTime::MillisecondTimestamp() - startTime < kMaxWaitDecTimeMs) { + int64_t startTime = rtc::TimeMillis(); + while (rtc::TimeMillis() - startTime < kMaxWaitDecTimeMs) { if (decode_complete_callback_->DecodeComplete()) { return CalcBufferSize(kI420, decoded_frame_.width(), decoded_frame_.height()); diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc index 3eb47eedc0..b236f4e955 100644 --- a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc +++ b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc @@ -20,6 +20,7 @@ #include "libyuv/convert.h" // NOLINT #include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" #include "webrtc/base/trace_event.h" #include "webrtc/common_types.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" @@ -29,7 +30,6 @@ #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" #include "webrtc/system_wrappers/include/clock.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { namespace { @@ -166,7 +166,7 @@ VP8EncoderImpl::VP8EncoderImpl() tl1_frame_dropper_(kTl1MaxTimeToDropFrames), key_frame_request_(kMaxSimulcastStreams, false), quality_scaler_enabled_(false) { - uint32_t seed = static_cast(TickTime::MillisecondTimestamp()); + uint32_t seed = rtc::Time32(); srand(seed); picture_id_.reserve(kMaxSimulcastStreams); diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc b/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc index 33dae8d8e4..2802700953 100644 --- a/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc +++ b/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc @@ -12,10 +12,10 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" #include "webrtc/common_video/include/video_image.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/test/testsupport/metrics/video_metrics.h" #include "webrtc/tools/simple_command_line_parser.h" @@ -158,7 +158,7 @@ int SequenceCoder(webrtc::test::CommandLineParser* parser) { decoder->RegisterDecodeCompleteCallback(&decoder_callback); // Read->Encode->Decode sequence. // num_frames = -1 implies unlimited encoding (entire sequence). - int64_t starttime = webrtc::TickTime::MillisecondTimestamp(); + int64_t starttime = rtc::TimeMillis(); int frame_cnt = 1; int frames_processed = 0; input_frame.CreateEmptyFrame(width, height, width, half_width, half_width); @@ -176,7 +176,7 @@ int SequenceCoder(webrtc::test::CommandLineParser* parser) { ++frame_cnt; } printf("\nProcessed %d frames\n", frames_processed); - int64_t endtime = webrtc::TickTime::MillisecondTimestamp(); + int64_t endtime = rtc::TimeMillis(); int64_t totalExecutionTime = endtime - starttime; printf("Total execution time: %.2lf ms\n", static_cast(totalExecutionTime)); diff --git a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc index 9d06b6b136..ecd185856f 100644 --- a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -22,13 +22,13 @@ #include "vpx/vp8dx.h" #include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" #include "webrtc/base/keep_ref_until_done.h" #include "webrtc/base/logging.h" #include "webrtc/base/trace_event.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -77,7 +77,7 @@ VP9EncoderImpl::VP9EncoderImpl() // Use two spatial when screensharing with flexible mode. spatial_layer_(new ScreenshareLayersVP9(2)) { memset(&codec_, 0, sizeof(codec_)); - uint32_t seed = static_cast(TickTime::MillisecondTimestamp()); + uint32_t seed = rtc::Time32(); srand(seed); } diff --git a/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc b/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc index 577af41eb0..bdeef2abd5 100644 --- a/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc +++ b/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc @@ -14,8 +14,8 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/logging.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" namespace webrtc { @@ -30,7 +30,7 @@ class IvfFileWriterTest : public ::testing::Test { protected: void SetUp() override { const int64_t start_id = - reinterpret_cast(this) ^ TickTime::MicrosecondTimestamp(); + reinterpret_cast(this) ^ rtc::TimeMicros(); int64_t id = start_id; do { std::ostringstream oss; diff --git a/webrtc/modules/video_processing/content_analysis.cc b/webrtc/modules/video_processing/content_analysis.cc index 54c04da466..76dfb95b2b 100644 --- a/webrtc/modules/video_processing/content_analysis.cc +++ b/webrtc/modules/video_processing/content_analysis.cc @@ -13,7 +13,6 @@ #include #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { diff --git a/webrtc/modules/video_processing/test/video_processing_unittest.cc b/webrtc/modules/video_processing/test/video_processing_unittest.cc index f2667e770a..790994f083 100644 --- a/webrtc/modules/video_processing/test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/test/video_processing_unittest.cc @@ -15,8 +15,8 @@ #include #include +#include "webrtc/base/timeutils.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" namespace webrtc { @@ -144,11 +144,12 @@ TEST_F(VideoProcessingTest, Resampler) { for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { // Initiate test timer. - const TickTime time_start = TickTime::Now(); + const int64_t time_start = rtc::TimeNanos(); // Init the sourceFrame with a timestamp. - video_frame_.set_render_time_ms(time_start.MillisecondTimestamp()); - video_frame_.set_timestamp(time_start.MillisecondTimestamp() * 90); + int64_t time_start_ms = time_start / rtc::kNumNanosecsPerMillisec; + video_frame_.set_render_time_ms(time_start_ms); + video_frame_.set_timestamp(time_start_ms * 90); // Test scaling to different sizes: source is of |width|/|height| = 352/288. // Pure scaling: @@ -191,7 +192,8 @@ TEST_F(VideoProcessingTest, Resampler) { TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vp_); // Stop timer. - const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); + const int64_t runtime = + (rtc::TimeNanos() - time_start) / rtc::kNumNanosecsPerMicrosec; if (runtime < min_runtime || run_idx == 0) { min_runtime = runtime; } diff --git a/webrtc/modules/video_processing/video_decimator.cc b/webrtc/modules/video_processing/video_decimator.cc index 63e347b026..c6623fa836 100644 --- a/webrtc/modules/video_processing/video_decimator.cc +++ b/webrtc/modules/video_processing/video_decimator.cc @@ -9,9 +9,9 @@ */ #include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/video_processing/include/video_processing.h" #include "webrtc/modules/video_processing/video_decimator.h" -#include "webrtc/system_wrappers/include/tick_util.h" #define VD_MIN(a, b) ((a) < (b)) ? (a) : (b) @@ -95,7 +95,7 @@ bool VPMVideoDecimator::DropFrame() { } uint32_t VPMVideoDecimator::GetDecimatedFrameRate() { - ProcessIncomingframe_rate(TickTime::MillisecondTimestamp()); + ProcessIncomingframe_rate(rtc::TimeMillis()); if (!enable_temporal_decimation_) { return static_cast(incoming_frame_rate_ + 0.5f); } @@ -104,12 +104,12 @@ uint32_t VPMVideoDecimator::GetDecimatedFrameRate() { } uint32_t VPMVideoDecimator::Inputframe_rate() { - ProcessIncomingframe_rate(TickTime::MillisecondTimestamp()); + ProcessIncomingframe_rate(rtc::TimeMillis()); return static_cast(incoming_frame_rate_ + 0.5f); } void VPMVideoDecimator::UpdateIncomingframe_rate() { - int64_t now = TickTime::MillisecondTimestamp(); + int64_t now = rtc::TimeMillis(); if (incoming_frame_times_[0] == 0) { // First no shift. } else { diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn index aff29de502..66e6df5cc1 100644 --- a/webrtc/system_wrappers/BUILD.gn +++ b/webrtc/system_wrappers/BUILD.gn @@ -34,7 +34,6 @@ static_library("system_wrappers") { "include/static_instance.h", "include/stl_util.h", "include/stringize_macros.h", - "include/tick_util.h", "include/timestamp_extrapolator.h", "include/trace.h", "include/utf_util_win.h", @@ -65,7 +64,6 @@ static_library("system_wrappers") { "source/rw_lock_winxp_win.h", "source/sleep.cc", "source/sort.cc", - "source/tick_util.cc", "source/timestamp_extrapolator.cc", "source/trace_impl.cc", "source/trace_impl.h", diff --git a/webrtc/system_wrappers/include/tick_util.h b/webrtc/system_wrappers/include/tick_util.h deleted file mode 100644 index 52f9b4ae4d..0000000000 --- a/webrtc/system_wrappers/include/tick_util.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * 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. - */ - -// System independant wrapper for polling elapsed time in ms and us. -// The implementation works in the tick domain which can be mapped over to the -// time domain. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ - -#if _WIN32 -// Note: The Windows header must always be included before mmsystem.h -#include -#include -#elif WEBRTC_LINUX -#include -#elif WEBRTC_MAC -#include -#include -#else -#include -#include -#endif - -#include "webrtc/typedefs.h" - -namespace webrtc { - -class TickInterval; - -// Class representing the current time. -class TickTime { - public: - TickTime(); - explicit TickTime(int64_t ticks); - - // Current time in the tick domain. - static TickTime Now(); - - // Now in the time domain in ms. - static int64_t MillisecondTimestamp(); - - // Now in the time domain in us. - static int64_t MicrosecondTimestamp(); - - // Returns the number of ticks in the tick domain. - int64_t Ticks() const; - - static int64_t MillisecondsToTicks(const int64_t ms); - - static int64_t TicksToMilliseconds(const int64_t ticks); - - static int64_t TicksToMicroseconds(const int64_t ticks); - - // Returns a TickTime that is ticks later than the passed TickTime. - friend TickTime operator+(const TickTime lhs, const int64_t ticks); - TickTime& operator+=(const int64_t& ticks); - - // Returns a TickInterval that is the difference in ticks beween rhs and lhs. - friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); - - private: - static int64_t QueryOsForTicks(); - - int64_t ticks_; -}; - -// Represents a time delta in ticks. -class TickInterval { - public: - TickInterval(); - explicit TickInterval(int64_t interval); - - int64_t Milliseconds() const; - int64_t Microseconds() const; - - // Returns the sum of two TickIntervals as a TickInterval. - friend TickInterval operator+(const TickInterval& lhs, - const TickInterval& rhs); - TickInterval& operator+=(const TickInterval& rhs); - - // Returns a TickInterval corresponding to rhs - lhs. - friend TickInterval operator-(const TickInterval& lhs, - const TickInterval& rhs); - TickInterval& operator-=(const TickInterval& rhs); - - friend bool operator>(const TickInterval& lhs, const TickInterval& rhs); - friend bool operator<=(const TickInterval& lhs, const TickInterval& rhs); - friend bool operator<(const TickInterval& lhs, const TickInterval& rhs); - friend bool operator>=(const TickInterval& lhs, const TickInterval& rhs); - - private: - friend class TickTime; - friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); - - private: - int64_t interval_; -}; - -inline int64_t TickInterval::Milliseconds() const { - return TickTime::TicksToMilliseconds(interval_); -} - -inline int64_t TickInterval::Microseconds() const { - return TickTime::TicksToMicroseconds(interval_); -} - -inline TickInterval operator+(const TickInterval& lhs, - const TickInterval& rhs) { - return TickInterval(lhs.interval_ + rhs.interval_); -} - -inline TickInterval operator-(const TickInterval& lhs, - const TickInterval& rhs) { - return TickInterval(lhs.interval_ - rhs.interval_); -} - -inline TickInterval operator-(const TickTime& lhs, const TickTime& rhs) { - return TickInterval(lhs.ticks_ - rhs.ticks_); -} - -inline TickTime operator+(const TickTime lhs, const int64_t ticks) { - TickTime time = lhs; - time.ticks_ += ticks; - return time; -} - -inline bool operator>(const TickInterval& lhs, const TickInterval& rhs) { - return lhs.interval_ > rhs.interval_; -} - -inline bool operator<=(const TickInterval& lhs, const TickInterval& rhs) { - return lhs.interval_ <= rhs.interval_; -} - -inline bool operator<(const TickInterval& lhs, const TickInterval& rhs) { - return lhs.interval_ <= rhs.interval_; -} - -inline bool operator>=(const TickInterval& lhs, const TickInterval& rhs) { - return lhs.interval_ >= rhs.interval_; -} - -inline TickTime::TickTime() - : ticks_(0) { -} - -inline TickTime::TickTime(int64_t ticks) - : ticks_(ticks) { -} - -inline TickTime TickTime::Now() { - return TickTime(QueryOsForTicks()); -} - -inline int64_t TickTime::Ticks() const { - return ticks_; -} - -inline TickTime& TickTime::operator+=(const int64_t& ticks) { - ticks_ += ticks; - return *this; -} - -inline TickInterval::TickInterval() : interval_(0) { -} - -inline TickInterval::TickInterval(const int64_t interval) - : interval_(interval) { -} - -inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) { - interval_ += rhs.interval_; - return *this; -} - -inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) { - interval_ -= rhs.interval_; - return *this; -} - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ diff --git a/webrtc/system_wrappers/source/clock.cc b/webrtc/system_wrappers/source/clock.cc index 926b95a3df..05dabd8538 100644 --- a/webrtc/system_wrappers/source/clock.cc +++ b/webrtc/system_wrappers/source/clock.cc @@ -20,8 +20,8 @@ #endif #include "webrtc/base/criticalsection.h" +#include "webrtc/base/timeutils.h" #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { @@ -37,13 +37,13 @@ class RealTimeClock : public Clock { // Return a timestamp in milliseconds relative to some arbitrary source; the // source is fixed for this clock. int64_t TimeInMilliseconds() const override { - return TickTime::MillisecondTimestamp(); + return rtc::TimeMillis(); } // Return a timestamp in microseconds relative to some arbitrary source; the // source is fixed for this clock. int64_t TimeInMicroseconds() const override { - return TickTime::MicrosecondTimestamp(); + return rtc::TimeMicros(); } // Retrieve an NTP absolute timestamp in seconds and fractions of a second. diff --git a/webrtc/system_wrappers/source/condition_variable_unittest.cc b/webrtc/system_wrappers/source/condition_variable_unittest.cc index bf245e6b6b..5fc6bc6b73 100644 --- a/webrtc/system_wrappers/source/condition_variable_unittest.cc +++ b/webrtc/system_wrappers/source/condition_variable_unittest.cc @@ -17,8 +17,8 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/platform_thread.h" +#include "webrtc/base/timeutils.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { @@ -191,9 +191,9 @@ TEST(CondVarWaitTest, WaitingWaits) { InitializeCriticalSection(&crit_sect); ConditionVariableEventWin cond_var; EnterCriticalSection(&crit_sect); - int64_t start_ms = TickTime::MillisecondTimestamp(); + int64_t start_ms = rtc::TimeMillis(); EXPECT_FALSE(cond_var.SleepCS(&crit_sect, kVeryShortWaitMs)); - int64_t end_ms = TickTime::MillisecondTimestamp(); + int64_t end_ms = rtc::TimeMillis(); EXPECT_LE(start_ms + kVeryShortWaitMs, end_ms) << "actual elapsed:" << end_ms - start_ms; LeaveCriticalSection(&crit_sect); diff --git a/webrtc/system_wrappers/source/tick_util.cc b/webrtc/system_wrappers/source/tick_util.cc deleted file mode 100644 index 0485e42921..0000000000 --- a/webrtc/system_wrappers/source/tick_util.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ - -#include "webrtc/system_wrappers/include/tick_util.h" - -#include "webrtc/base/timeutils.h" - -namespace webrtc { - -int64_t TickTime::MillisecondTimestamp() { - return TicksToMilliseconds(TickTime::Now().Ticks()); -} - -int64_t TickTime::MicrosecondTimestamp() { - return TicksToMicroseconds(TickTime::Now().Ticks()); -} - -int64_t TickTime::MillisecondsToTicks(const int64_t ms) { - return ms * rtc::kNumNanosecsPerMillisec; -} - -int64_t TickTime::TicksToMilliseconds(const int64_t ticks) { - return ticks / rtc::kNumNanosecsPerMillisec; -} - -int64_t TickTime::TicksToMicroseconds(const int64_t ticks) { - return ticks / rtc::kNumNanosecsPerMicrosec; -} - -// Gets the native system tick count, converted to nanoseconds. -int64_t TickTime::QueryOsForTicks() { - return rtc::TimeNanos(); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/system_wrappers.gyp b/webrtc/system_wrappers/system_wrappers.gyp index cd6d3ea671..b61ecf28ee 100644 --- a/webrtc/system_wrappers/system_wrappers.gyp +++ b/webrtc/system_wrappers/system_wrappers.gyp @@ -42,7 +42,6 @@ 'include/static_instance.h', 'include/stl_util.h', 'include/stringize_macros.h', - 'include/tick_util.h', 'include/timestamp_extrapolator.h', 'include/trace.h', 'include/utf_util_win.h', @@ -77,7 +76,6 @@ 'source/rw_lock_winxp_win.h', 'source/sleep.cc', 'source/sort.cc', - 'source/tick_util.cc', 'source/timestamp_extrapolator.cc', 'source/trace_impl.cc', 'source/trace_impl.h', diff --git a/webrtc/system_wrappers/test/TestSort/TestSort.cc b/webrtc/system_wrappers/test/TestSort/TestSort.cc index b2b9f85755..8c585abb67 100644 --- a/webrtc/system_wrappers/test/TestSort/TestSort.cc +++ b/webrtc/system_wrappers/test/TestSort/TestSort.cc @@ -13,8 +13,8 @@ #include +#include "webrtc/base/timeutils.h" #include "webrtc/system_wrappers/include/sort.h" -#include "webrtc/system_wrappers/include/tick_util.h" // Excellent work polluting the global namespace Visual Studio... #undef max @@ -144,7 +144,7 @@ void RunSortTest(webrtc::Type sortType, bool keySort) printf("Running %s Sort() tests...\n", TypeEnumToString(sortType)); } - TickInterval accTicks; + int64_t accTicks; for (int i = 0; i < NumOfTests; i++) { for (int j = 0; j < DataLength; j++) @@ -159,7 +159,7 @@ void RunSortTest(webrtc::Type sortType, bool keySort) memcpy(keyRef, key, sizeof(key)); retVal = 0; - TickTime t0 = TickTime::Now(); + int64_t t0 = rtc::TimeNanos(); if (keySort) { retVal = webrtc::KeySort(data, key, DataLength, sizeof(LotsOfData), @@ -176,7 +176,7 @@ void RunSortTest(webrtc::Type sortType, bool keySort) //std::sort(key, key + DataLength); //qsort(key, DataLength, sizeof(KeyType), Compare); } - TickTime t1 = TickTime::Now(); + int64_t t1 = rtc::TimeNanos(); accTicks += (t1 - t0); if (retVal != 0) @@ -236,7 +236,7 @@ void RunSortTest(webrtc::Type sortType, bool keySort) printf("Compliance test passed over %d iterations\n", NumOfTests); - int64_t executeTime = accTicks.Milliseconds(); + int64_t executeTime = accTicks / rtc::kNumNanosecsPerMillisec; printf("Execute time: %.2f s\n\n", (float)executeTime / 1000); } diff --git a/webrtc/video/call_stats.cc b/webrtc/video/call_stats.cc index 09c967c2b1..59efcfa13d 100644 --- a/webrtc/video/call_stats.cc +++ b/webrtc/video/call_stats.cc @@ -16,7 +16,6 @@ #include "webrtc/base/constructormagic.h" #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/system_wrappers/include/metrics.h" -#include "webrtc/system_wrappers/include/tick_util.h" namespace webrtc { namespace { diff --git a/webrtc/video/call_stats_unittest.cc b/webrtc/video/call_stats_unittest.cc index 6e2e1bca78..8b3cde07a8 100644 --- a/webrtc/video/call_stats_unittest.cc +++ b/webrtc/video/call_stats_unittest.cc @@ -15,7 +15,6 @@ #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/system_wrappers/include/metrics.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/histogram.h" #include "webrtc/video/call_stats.h" diff --git a/webrtc/video/rtp_stream_receiver.cc b/webrtc/video/rtp_stream_receiver.cc index 5eeaa1bf5d..29bd78152e 100644 --- a/webrtc/video/rtp_stream_receiver.cc +++ b/webrtc/video/rtp_stream_receiver.cc @@ -25,7 +25,6 @@ #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" #include "webrtc/modules/video_coding/video_coding_impl.h" #include "webrtc/system_wrappers/include/metrics.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/video/receive_statistics_proxy.h" diff --git a/webrtc/video/video_stream_decoder.h b/webrtc/video/video_stream_decoder.h index 853806113b..24a0ea3449 100644 --- a/webrtc/video/video_stream_decoder.h +++ b/webrtc/video/video_stream_decoder.h @@ -21,7 +21,6 @@ #include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" #include "webrtc/modules/video_coding/include/video_coding_defines.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/typedefs.h" #include "webrtc/video/vie_sync_module.h" diff --git a/webrtc/video/vie_encoder.cc b/webrtc/video/vie_encoder.cc index 2a7c21adc9..b507372379 100644 --- a/webrtc/video/vie_encoder.cc +++ b/webrtc/video/vie_encoder.cc @@ -17,11 +17,11 @@ #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/base/trace_event.h" +#include "webrtc/base/timeutils.h" #include "webrtc/modules/pacing/paced_sender.h" #include "webrtc/modules/video_coding/include/video_coding.h" #include "webrtc/modules/video_coding/include/video_coding_defines.h" #include "webrtc/system_wrappers/include/metrics.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/video/overuse_frame_detector.h" #include "webrtc/video/send_statistics_proxy.h" #include "webrtc/video_frame.h" @@ -208,7 +208,7 @@ int ViEEncoder::GetPaddingNeededBps() const { // The amount of padding should decay to zero if no frames are being // captured/encoded unless a min-transmit bitrate is used. - int64_t now_ms = TickTime::MillisecondTimestamp(); + int64_t now_ms = rtc::TimeMillis(); if (now_ms - time_of_last_frame_activity_ms > kStopPaddingThresholdMs) pad_up_to_bitrate_bps = 0; @@ -257,7 +257,7 @@ void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) { VideoCodecType codec_type; { rtc::CritScope lock(&data_cs_); - time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); + time_of_last_frame_activity_ms_ = rtc::TimeMillis(); if (EncoderPaused()) { TraceFrameDropStart(); return; @@ -333,7 +333,7 @@ int32_t ViEEncoder::Encoded(const EncodedImage& encoded_image, const RTPFragmentationHeader* fragmentation) { { rtc::CritScope lock(&data_cs_); - time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); + time_of_last_frame_activity_ms_ = rtc::TimeMillis(); } if (stats_proxy_) { stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); diff --git a/webrtc/video/vie_remb.cc b/webrtc/video/vie_remb.cc index b759f5b72c..a5ccc52ba6 100644 --- a/webrtc/video/vie_remb.cc +++ b/webrtc/video/vie_remb.cc @@ -16,7 +16,6 @@ #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" #include "webrtc/modules/utility/include/process_thread.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { diff --git a/webrtc/video/vie_remb_unittest.cc b/webrtc/video/vie_remb_unittest.cc index c6eb363163..2c33401b45 100644 --- a/webrtc/video/vie_remb_unittest.cc +++ b/webrtc/video/vie_remb_unittest.cc @@ -16,7 +16,6 @@ #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" #include "webrtc/modules/utility/include/mock/mock_process_thread.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/video/vie_remb.h" using ::testing::_; diff --git a/webrtc/video/vie_sync_module.cc b/webrtc/video/vie_sync_module.cc index 02a82de4bb..2e62ff8143 100644 --- a/webrtc/video/vie_sync_module.cc +++ b/webrtc/video/vie_sync_module.cc @@ -12,6 +12,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" +#include "webrtc/base/timeutils.h" #include "webrtc/base/trace_event.h" #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" @@ -55,7 +56,7 @@ ViESyncModule::ViESyncModule(vcm::VideoReceiver* video_receiver) video_rtp_rtcp_(nullptr), voe_channel_id_(-1), voe_sync_interface_(nullptr), - last_sync_time_(TickTime::Now()), + last_sync_time_(rtc::TimeNanos()), sync_() {} ViESyncModule::~ViESyncModule() { @@ -84,12 +85,13 @@ void ViESyncModule::ConfigureSync(int voe_channel_id, int64_t ViESyncModule::TimeUntilNextProcess() { const int64_t kSyncIntervalMs = 1000; - return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds(); + return kSyncIntervalMs - + (rtc::TimeNanos() - last_sync_time_) / rtc::kNumNanosecsPerMillisec; } void ViESyncModule::Process() { rtc::CritScope lock(&data_cs_); - last_sync_time_ = TickTime::Now(); + last_sync_time_ = rtc::TimeNanos(); const int current_video_delay_ms = video_receiver_->Delay(); diff --git a/webrtc/video/vie_sync_module.h b/webrtc/video/vie_sync_module.h index 8a1933b7ea..18b6c5d094 100644 --- a/webrtc/video/vie_sync_module.h +++ b/webrtc/video/vie_sync_module.h @@ -18,7 +18,6 @@ #include "webrtc/base/criticalsection.h" #include "webrtc/modules/include/module.h" -#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/video/stream_synchronization.h" #include "webrtc/voice_engine/include/voe_video_sync.h" @@ -61,7 +60,7 @@ class ViESyncModule : public Module { RtpRtcp* video_rtp_rtcp_; int voe_channel_id_; VoEVideoSync* voe_sync_interface_; - TickTime last_sync_time_; + int64_t last_sync_time_; std::unique_ptr sync_; StreamSynchronization::Measurements audio_measurement_; StreamSynchronization::Measurements video_measurement_; diff --git a/webrtc/voice_engine/monitor_module.cc b/webrtc/voice_engine/monitor_module.cc index fb3c2b4920..8a1865a95b 100644 --- a/webrtc/voice_engine/monitor_module.cc +++ b/webrtc/voice_engine/monitor_module.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/system_wrappers/include/tick_util.h" +#include "webrtc/base/timeutils.h" #include "webrtc/voice_engine/monitor_module.h" namespace webrtc { @@ -17,7 +17,7 @@ namespace voe { MonitorModule::MonitorModule() : _observerPtr(NULL), - _lastProcessTime(TickTime::MillisecondTimestamp()) + _lastProcessTime(rtc::TimeMillis()) { } @@ -52,7 +52,7 @@ MonitorModule::DeRegisterObserver() int64_t MonitorModule::TimeUntilNextProcess() { - int64_t now = TickTime::MillisecondTimestamp(); + int64_t now = rtc::TimeMillis(); const int64_t kAverageProcessUpdateTimeMs = 1000; return kAverageProcessUpdateTimeMs - (now - _lastProcessTime); } @@ -60,7 +60,7 @@ MonitorModule::TimeUntilNextProcess() void MonitorModule::Process() { - _lastProcessTime = TickTime::MillisecondTimestamp(); + _lastProcessTime = rtc::TimeMillis(); rtc::CritScope lock(&_callbackCritSect); if (_observerPtr) {