Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: webrtc/modules/audio_conference_mixer/source/time_scheduler.cc

Issue 1888593004: Delete all use of tick_util.h. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/timeutils.h"
11 #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h" 12 #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h"
12 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 13 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
13 14
14 namespace webrtc { 15 namespace webrtc {
15 TimeScheduler::TimeScheduler(const int64_t periodicityInMs) 16 TimeScheduler::TimeScheduler(const int64_t periodicityInMs)
16 : _crit(CriticalSectionWrapper::CreateCriticalSection()), 17 : _crit(CriticalSectionWrapper::CreateCriticalSection()),
17 _isStarted(false), 18 _isStarted(false),
18 _lastPeriodMark(), 19 _lastPeriodMark(),
19 _periodicityInMs(periodicityInMs), 20 _periodicityInMs(periodicityInMs),
20 _periodicityInTicks(TickTime::MillisecondsToTicks(periodicityInMs)), 21 _periodicityInTicks(periodicityInMs * rtc::kNumNanosecsPerMillisec),
21 _missedPeriods(0) 22 _missedPeriods(0)
22 { 23 {
23 } 24 }
24 25
25 TimeScheduler::~TimeScheduler() 26 TimeScheduler::~TimeScheduler()
26 { 27 {
27 delete _crit; 28 delete _crit;
28 } 29 }
29 30
30 int32_t TimeScheduler::UpdateScheduler() 31 int32_t TimeScheduler::UpdateScheduler()
31 { 32 {
32 CriticalSectionScoped cs(_crit); 33 CriticalSectionScoped cs(_crit);
33 if(!_isStarted) 34 if(!_isStarted)
34 { 35 {
35 _isStarted = true; 36 _isStarted = true;
36 _lastPeriodMark = TickTime::Now(); 37 _lastPeriodMark = rtc::TimeNanos();
37 return 0; 38 return 0;
38 } 39 }
39 // Don't perform any calculations until the debt of pending periods have 40 // Don't perform any calculations until the debt of pending periods have
40 // been worked off. 41 // been worked off.
41 if(_missedPeriods > 0) 42 if(_missedPeriods > 0)
42 { 43 {
43 _missedPeriods--; 44 _missedPeriods--;
44 return 0; 45 return 0;
45 } 46 }
46 47
47 // Calculate the time that has past since previous call to this function. 48 // Calculate the time that has past since previous call to this function.
48 TickTime tickNow = TickTime::Now(); 49 int64_t tickNow = rtc::TimeNanos();
49 TickInterval amassedTicks = tickNow - _lastPeriodMark; 50 int64_t amassedTicks = tickNow - _lastPeriodMark;
50 int64_t amassedMs = amassedTicks.Milliseconds(); 51 int64_t amassedMs = amassedTicks / rtc::kNumNanosecsPerMillisec;
51 52
52 // Calculate the number of periods the time that has passed correspond to. 53 // Calculate the number of periods the time that has passed correspond to.
53 int64_t periodsToClaim = amassedMs / _periodicityInMs; 54 int64_t periodsToClaim = amassedMs / _periodicityInMs;
54 55
55 // One period will be worked off by this call. Make sure that the number of 56 // One period will be worked off by this call. Make sure that the number of
56 // pending periods don't end up being negative (e.g. if this function is 57 // pending periods don't end up being negative (e.g. if this function is
57 // called to often). 58 // called to often).
58 if(periodsToClaim < 1) 59 if(periodsToClaim < 1)
59 { 60 {
60 periodsToClaim = 1; 61 periodsToClaim = 1;
(...skipping 21 matching lines...) Expand all
82 // Missed periods means that the next UpdateScheduler() should happen 83 // Missed periods means that the next UpdateScheduler() should happen
83 // immediately. 84 // immediately.
84 if(_missedPeriods > 0) 85 if(_missedPeriods > 0)
85 { 86 {
86 updateTimeInMS = 0; 87 updateTimeInMS = 0;
87 return 0; 88 return 0;
88 } 89 }
89 90
90 // Calculate the time (in ms) that has past since last call to 91 // Calculate the time (in ms) that has past since last call to
91 // UpdateScheduler() 92 // UpdateScheduler()
92 TickTime tickNow = TickTime::Now(); 93 int64_t tickNow = rtc::TimeNanos();
93 TickInterval ticksSinceLastUpdate = tickNow - _lastPeriodMark; 94 int64_t ticksSinceLastUpdate = tickNow - _lastPeriodMark;
94 const int64_t millisecondsSinceLastUpdate = 95 const int64_t millisecondsSinceLastUpdate =
95 ticksSinceLastUpdate.Milliseconds(); 96 ticksSinceLastUpdate / rtc::kNumNanosecsPerMillisec;
96 97
97 updateTimeInMS = _periodicityInMs - millisecondsSinceLastUpdate; 98 updateTimeInMS = _periodicityInMs - millisecondsSinceLastUpdate;
98 updateTimeInMS = (updateTimeInMS < 0) ? 0 : updateTimeInMS; 99 updateTimeInMS = (updateTimeInMS < 0) ? 0 : updateTimeInMS;
99 return 0; 100 return 0;
100 } 101 }
101 } // namespace webrtc 102 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_conference_mixer/source/time_scheduler.h ('k') | webrtc/modules/audio_device/audio_device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698