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

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

Issue 2109133003: Added empty directory with myself as owner for new mixer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Renamed to avoid compilation crashes and added build file. Created 4 years, 5 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
(Empty)
1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/base/timeutils.h"
12 #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h"
13 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
14
15 namespace webrtc {
16 TimeScheduler::TimeScheduler(const int64_t periodicityInMs)
17 : _crit(CriticalSectionWrapper::CreateCriticalSection()),
18 _isStarted(false),
19 _lastPeriodMark(),
20 _periodicityInMs(periodicityInMs),
21 _periodicityInTicks(periodicityInMs * rtc::kNumNanosecsPerMillisec),
22 _missedPeriods(0) {}
23
24 TimeScheduler::~TimeScheduler() {
25 delete _crit;
26 }
27
28 int32_t TimeScheduler::UpdateScheduler() {
29 CriticalSectionScoped cs(_crit);
30 if (!_isStarted) {
31 _isStarted = true;
32 _lastPeriodMark = rtc::TimeNanos();
33 return 0;
34 }
35 // Don't perform any calculations until the debt of pending periods have
36 // been worked off.
37 if (_missedPeriods > 0) {
38 _missedPeriods--;
39 return 0;
40 }
41
42 // Calculate the time that has past since previous call to this function.
43 int64_t tickNow = rtc::TimeNanos();
44 int64_t amassedTicks = tickNow - _lastPeriodMark;
45 int64_t amassedMs = amassedTicks / rtc::kNumNanosecsPerMillisec;
46
47 // Calculate the number of periods the time that has passed correspond to.
48 int64_t periodsToClaim = amassedMs / _periodicityInMs;
49
50 // One period will be worked off by this call. Make sure that the number of
51 // pending periods don't end up being negative (e.g. if this function is
52 // called to often).
53 if (periodsToClaim < 1) {
54 periodsToClaim = 1;
55 }
56
57 // Update the last period mark without introducing any drifting.
58 // Note that if this fuunction is called to often _lastPeriodMark can
59 // refer to a time in the future which in turn will yield TimeToNextUpdate
60 // that is greater than the periodicity
61 for (int64_t i = 0; i < periodsToClaim; i++) {
62 _lastPeriodMark += _periodicityInTicks;
63 }
64
65 // Update the total amount of missed periods note that we have processed
66 // one period hence the - 1
67 _missedPeriods += periodsToClaim - 1;
68 return 0;
69 }
70
71 int32_t TimeScheduler::TimeToNextUpdate(int64_t& updateTimeInMS) const {
72 CriticalSectionScoped cs(_crit);
73 // Missed periods means that the next UpdateScheduler() should happen
74 // immediately.
75 if (_missedPeriods > 0) {
76 updateTimeInMS = 0;
77 return 0;
78 }
79
80 // Calculate the time (in ms) that has past since last call to
81 // UpdateScheduler()
82 int64_t tickNow = rtc::TimeNanos();
83 int64_t ticksSinceLastUpdate = tickNow - _lastPeriodMark;
84 const int64_t millisecondsSinceLastUpdate =
85 ticksSinceLastUpdate / rtc::kNumNanosecsPerMillisec;
86
87 updateTimeInMS = _periodicityInMs - millisecondsSinceLastUpdate;
88 updateTimeInMS = (updateTimeInMS < 0) ? 0 : updateTimeInMS;
89 return 0;
90 }
91 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/source/time_scheduler.h ('k') | webrtc/modules/audio_mixer/test/alex_new_fancy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698