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

Side by Side Diff: webrtc/modules/audio_coding/neteq/tick_timer.h

Issue 1903043003: WIP: Adding a centralized NetEq Clock (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@neteq-remove-type-param
Patch Set: Created 4 years, 8 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) 2016 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 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TICK_TIMER_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TICK_TIMER_H_
13
14 #include <memory>
15
16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/typedefs.h"
18
19 namespace webrtc {
20 class TickTimer {
21 public:
22 class Stopwatch {
23 public:
24 explicit Stopwatch(const TickTimer& ticktimer);
25
26 uint64_t ElapsedTicks() const { return ticktimer_.ticks() - starttick_; }
27 uint64_t ElapsedMs() const {
28 const uint64_t elapsed_ticks = ticktimer_.ticks() - starttick_;
29 return elapsed_ticks < UINT64_MAX / 10 ? elapsed_ticks * 10 : UINT64_MAX;
30 }
31
32 private:
33 const TickTimer& ticktimer_;
34 const uint64_t starttick_;
35 };
36
37 class Countdown {
38 public:
39 Countdown(const TickTimer& ticktimer, uint64_t ticks_to_count);
40
41 ~Countdown();
42
43 bool Finished() const {
44 return stopwatch_->ElapsedTicks() >= ticks_to_count_;
45 }
46
47 private:
48 const std::unique_ptr<Stopwatch> stopwatch_;
49 const uint64_t ticks_to_count_;
50 };
51
52 TickTimer() {}
53
54 void Increment() { ++ticks_; }
55
56 void Increment(uint64_t x) { ticks_ += x; }
57
58 uint64_t ticks() const { return ticks_; }
59
60 // Returns a new Stopwatch object, based on the current TickTimer. Note that
61 // the new Stopwatch object contains a reference to the current TickTimer,
62 // and must therefore not outlive the TickTimer.
63 std::unique_ptr<Stopwatch> GetNewStopwatch() const {
64 return std::unique_ptr<Stopwatch>(new Stopwatch(*this));
65 }
66
67 // Returns a new Countdown object, based on the current TickTimer. Note that
68 // the new Countdown object contains a reference to the current TickTimer,
69 // and must therefore not outlive the TickTimer.
70 std::unique_ptr<Countdown> GetNewCountdown(uint64_t ticks_to_count) const {
71 return std::unique_ptr<Countdown>(new Countdown(*this, ticks_to_count));
72 }
73
74 private:
75 uint64_t ticks_ = 0;
76 RTC_DISALLOW_COPY_AND_ASSIGN(TickTimer);
77 };
78
79 } // namespace webrtc
80 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TICK_TIMER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/payload_splitter.cc ('k') | webrtc/modules/audio_coding/neteq/tick_timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698