1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef API_METRONOME_METRONOME_H_ 12*d9f75844SAndroid Build Coastguard Worker #define API_METRONOME_METRONOME_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include "api/task_queue/task_queue_base.h" 15*d9f75844SAndroid Build Coastguard Worker #include "api/units/time_delta.h" 16*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/system/rtc_export.h" 17*d9f75844SAndroid Build Coastguard Worker 18*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker // The Metronome posts OnTick() calls requested with RequestCallOnNextTick. 21*d9f75844SAndroid Build Coastguard Worker // The API is designed to be fully used from a single task queue. Scheduled 22*d9f75844SAndroid Build Coastguard Worker // callbacks are executed on the same sequence as they were requested on. There 23*d9f75844SAndroid Build Coastguard Worker // are no features implemented for cancellation. When that's needed, use e.g. 24*d9f75844SAndroid Build Coastguard Worker // ScopedTaskSafety from the client. 25*d9f75844SAndroid Build Coastguard Worker // 26*d9f75844SAndroid Build Coastguard Worker // The metronome concept is still under experimentation, and may not be availble 27*d9f75844SAndroid Build Coastguard Worker // in all platforms or applications. See https://crbug.com/1253787 for more 28*d9f75844SAndroid Build Coastguard Worker // details. 29*d9f75844SAndroid Build Coastguard Worker // 30*d9f75844SAndroid Build Coastguard Worker // Metronome implementations must be thread-compatible. 31*d9f75844SAndroid Build Coastguard Worker class RTC_EXPORT Metronome { 32*d9f75844SAndroid Build Coastguard Worker public: 33*d9f75844SAndroid Build Coastguard Worker virtual ~Metronome() = default; 34*d9f75844SAndroid Build Coastguard Worker 35*d9f75844SAndroid Build Coastguard Worker // Requests a call to `callback` on the next tick. Scheduled callbacks are 36*d9f75844SAndroid Build Coastguard Worker // executed on the same sequence as they were requested on. There are no 37*d9f75844SAndroid Build Coastguard Worker // features for cancellation. When that's needed, use e.g. ScopedTaskSafety 38*d9f75844SAndroid Build Coastguard Worker // from the client. RequestCallOnNextTick(absl::AnyInvocable<void ()&&> callback)39*d9f75844SAndroid Build Coastguard Worker virtual void RequestCallOnNextTick(absl::AnyInvocable<void() &&> callback) {} 40*d9f75844SAndroid Build Coastguard Worker 41*d9f75844SAndroid Build Coastguard Worker // Returns the current tick period of the metronome. 42*d9f75844SAndroid Build Coastguard Worker virtual TimeDelta TickPeriod() const = 0; 43*d9f75844SAndroid Build Coastguard Worker }; 44*d9f75844SAndroid Build Coastguard Worker 45*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 46*d9f75844SAndroid Build Coastguard Worker 47*d9f75844SAndroid Build Coastguard Worker #endif // API_METRONOME_METRONOME_H_ 48