OLD | NEW |
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/base/timeutils.h" |
12 #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h" | 12 #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h" |
13 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
14 | 13 |
15 namespace webrtc { | 14 namespace webrtc { |
16 TimeScheduler::TimeScheduler(const int64_t periodicityInMs) | 15 TimeScheduler::TimeScheduler(const int64_t periodicityInMs) |
17 : _crit(CriticalSectionWrapper::CreateCriticalSection()), | 16 : _isStarted(false), |
18 _isStarted(false), | |
19 _lastPeriodMark(), | 17 _lastPeriodMark(), |
20 _periodicityInMs(periodicityInMs), | 18 _periodicityInMs(periodicityInMs), |
21 _periodicityInTicks(periodicityInMs * rtc::kNumNanosecsPerMillisec), | 19 _periodicityInTicks(periodicityInMs * rtc::kNumNanosecsPerMillisec), |
22 _missedPeriods(0) | 20 _missedPeriods(0) {} |
23 { | |
24 } | |
25 | 21 |
26 TimeScheduler::~TimeScheduler() | 22 int32_t TimeScheduler::UpdateScheduler() { |
27 { | 23 rtc::CritScope cs(&_crit); |
28 delete _crit; | |
29 } | |
30 | |
31 int32_t TimeScheduler::UpdateScheduler() | |
32 { | |
33 CriticalSectionScoped cs(_crit); | |
34 if(!_isStarted) | 24 if(!_isStarted) |
35 { | 25 { |
36 _isStarted = true; | 26 _isStarted = true; |
37 _lastPeriodMark = rtc::TimeNanos(); | 27 _lastPeriodMark = rtc::TimeNanos(); |
38 return 0; | 28 return 0; |
39 } | 29 } |
40 // Don't perform any calculations until the debt of pending periods have | 30 // Don't perform any calculations until the debt of pending periods have |
41 // been worked off. | 31 // been worked off. |
42 if(_missedPeriods > 0) | 32 if(_missedPeriods > 0) |
43 { | 33 { |
(...skipping 28 matching lines...) Expand all Loading... |
72 | 62 |
73 // Update the total amount of missed periods note that we have processed | 63 // Update the total amount of missed periods note that we have processed |
74 // one period hence the - 1 | 64 // one period hence the - 1 |
75 _missedPeriods += periodsToClaim - 1; | 65 _missedPeriods += periodsToClaim - 1; |
76 return 0; | 66 return 0; |
77 } | 67 } |
78 | 68 |
79 int32_t TimeScheduler::TimeToNextUpdate( | 69 int32_t TimeScheduler::TimeToNextUpdate( |
80 int64_t& updateTimeInMS) const | 70 int64_t& updateTimeInMS) const |
81 { | 71 { |
82 CriticalSectionScoped cs(_crit); | 72 rtc::CritScope cs(&_crit); |
83 // Missed periods means that the next UpdateScheduler() should happen | 73 // Missed periods means that the next UpdateScheduler() should happen |
84 // immediately. | 74 // immediately. |
85 if(_missedPeriods > 0) | 75 if(_missedPeriods > 0) |
86 { | 76 { |
87 updateTimeInMS = 0; | 77 updateTimeInMS = 0; |
88 return 0; | 78 return 0; |
89 } | 79 } |
90 | 80 |
91 // Calculate the time (in ms) that has past since last call to | 81 // Calculate the time (in ms) that has past since last call to |
92 // UpdateScheduler() | 82 // UpdateScheduler() |
93 int64_t tickNow = rtc::TimeNanos(); | 83 int64_t tickNow = rtc::TimeNanos(); |
94 int64_t ticksSinceLastUpdate = tickNow - _lastPeriodMark; | 84 int64_t ticksSinceLastUpdate = tickNow - _lastPeriodMark; |
95 const int64_t millisecondsSinceLastUpdate = | 85 const int64_t millisecondsSinceLastUpdate = |
96 ticksSinceLastUpdate / rtc::kNumNanosecsPerMillisec; | 86 ticksSinceLastUpdate / rtc::kNumNanosecsPerMillisec; |
97 | 87 |
98 updateTimeInMS = _periodicityInMs - millisecondsSinceLastUpdate; | 88 updateTimeInMS = _periodicityInMs - millisecondsSinceLastUpdate; |
99 updateTimeInMS = (updateTimeInMS < 0) ? 0 : updateTimeInMS; | 89 updateTimeInMS = (updateTimeInMS < 0) ? 0 : updateTimeInMS; |
100 return 0; | 90 return 0; |
101 } | 91 } |
102 } // namespace webrtc | 92 } // namespace webrtc |
OLD | NEW |