Turn off audio ducking for webrtc output.
[chromium-blink-merge.git] / cc / scheduler / delay_based_time_source.h
blob18c8002f2925b746461572c5e31a12526d5ad8d4
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_
6 #define CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_
8 #include <string>
10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h"
12 #include "cc/base/cc_export.h"
14 namespace base { class SingleThreadTaskRunner; }
16 namespace cc {
18 class CC_EXPORT TimeSourceClient {
19 public:
20 virtual void OnTimerTick() = 0;
22 protected:
23 virtual ~TimeSourceClient() {}
26 // This timer implements a time source that achieves the specified interval
27 // in face of millisecond-precision delayed callbacks and random queueing
28 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase.
29 class CC_EXPORT DelayBasedTimeSource
30 : public base::RefCounted<DelayBasedTimeSource> {
31 public:
32 static scoped_refptr<DelayBasedTimeSource> Create(
33 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner);
35 virtual void SetClient(TimeSourceClient* client);
37 // TimeSource implementation
38 virtual void SetTimebaseAndInterval(base::TimeTicks timebase,
39 base::TimeDelta interval);
41 virtual base::TimeTicks SetActive(bool active);
42 virtual bool Active() const;
44 // Get the last and next tick times. NextTickTime() returns null when
45 // inactive.
46 virtual base::TimeTicks LastTickTime() const;
47 virtual base::TimeTicks NextTickTime() const;
49 // Virtual for testing.
50 virtual base::TimeTicks Now() const;
52 virtual scoped_ptr<base::Value> AsValue() const;
54 protected:
55 DelayBasedTimeSource(base::TimeDelta interval,
56 base::SingleThreadTaskRunner* task_runner);
57 virtual ~DelayBasedTimeSource();
59 virtual std::string TypeString() const;
61 base::TimeTicks NextTickTarget(base::TimeTicks now);
62 void PostNextTickTask(base::TimeTicks now);
63 void OnTimerFired();
65 struct Parameters {
66 Parameters(base::TimeDelta interval, base::TimeTicks tick_target)
67 : interval(interval), tick_target(tick_target) {}
68 base::TimeDelta interval;
69 base::TimeTicks tick_target;
72 TimeSourceClient* client_;
73 base::TimeTicks last_tick_time_;
75 // current_parameters_ should only be written by PostNextTickTask.
76 // next_parameters_ will take effect on the next call to PostNextTickTask.
77 // Maintaining a pending set of parameters allows NextTickTime() to always
78 // reflect the actual time we expect OnTimerFired to be called.
79 Parameters current_parameters_;
80 Parameters next_parameters_;
82 bool active_;
84 base::SingleThreadTaskRunner* task_runner_;
85 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_;
87 private:
88 friend class base::RefCounted<DelayBasedTimeSource>;
89 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource);
92 // DelayBasedTimeSource uses base::TimeTicks::HighResNow as its timebase.
93 class DelayBasedTimeSourceHighRes : public DelayBasedTimeSource {
94 public:
95 static scoped_refptr<DelayBasedTimeSourceHighRes> Create(
96 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner);
98 virtual base::TimeTicks Now() const OVERRIDE;
100 protected:
101 DelayBasedTimeSourceHighRes(base::TimeDelta interval,
102 base::SingleThreadTaskRunner* task_runner);
103 virtual ~DelayBasedTimeSourceHighRes();
105 virtual std::string TypeString() const OVERRIDE;
107 private:
108 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSourceHighRes);
111 } // namespace cc
113 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_