metronome.h (1785B)
1 /* 2 * Copyright (c) 2022 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 API_METRONOME_METRONOME_H_ 12 #define API_METRONOME_METRONOME_H_ 13 14 #include "absl/functional/any_invocable.h" 15 #include "api/units/time_delta.h" 16 #include "rtc_base/system/rtc_export.h" 17 18 namespace webrtc { 19 20 // The Metronome posts OnTick() calls requested with RequestCallOnNextTick. 21 // The API is designed to be fully used from a single task queue. Scheduled 22 // callbacks are executed on the same sequence as they were requested on. There 23 // are no features implemented for cancellation. When that's needed, use e.g. 24 // ScopedTaskSafety from the client. 25 // 26 // The metronome concept is still under experimentation, and may not be availble 27 // in all platforms or applications. See https://crbug.com/1253787 for more 28 // details. 29 // 30 // Metronome implementations must be thread-compatible. 31 class RTC_EXPORT Metronome { 32 public: 33 virtual ~Metronome() = default; 34 35 // Requests a call to `callback` on the next tick. Scheduled callbacks are 36 // executed on the same sequence as they were requested on. There are no 37 // features for cancellation. When that's needed, use e.g. ScopedTaskSafety 38 // from the client. 39 virtual void RequestCallOnNextTick( 40 absl::AnyInvocable<void() &&> /* callback */) {} 41 42 // Returns the current tick period of the metronome. 43 virtual TimeDelta TickPeriod() const = 0; 44 }; 45 46 } // namespace webrtc 47 48 #endif // API_METRONOME_METRONOME_H_