Files
platform-external-webrtc/api/metronome/metronome.h
Markus Handell be400e465b Metronome: disable & refactor for single-threaded operation.
The Chromium implementation unfortunately has a rare deadlock.
Rather than patching that up, we're changing the metronome
implementation to be able to use a single-threaded environment
instead.

The metronome functionality is disabled in VideoReceiveStream2
construction inside call.cc.

The new design does not have listener registration or
deresigstration and instead accepts and invokes callbacks, on
the same sequence that requested the callback. This allows
the clients to use features such as WeakPtrFactories or
ScopedThreadSafety for cancellation.

The CL will be followed up with cleanup CLs that removes
registration APIs once downstream consumers have adapted.

Bug: chromium:1381982
Change-Id: I43732d1971e2276c39b431a04365cd2fc3c55c25
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282280
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38582}
2022-11-08 12:23:40 +00:00

62 lines
2.2 KiB
C++

/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef API_METRONOME_METRONOME_H_
#define API_METRONOME_METRONOME_H_
#include "api/task_queue/task_queue_base.h"
#include "api/units/time_delta.h"
#include "rtc_base/system/rtc_export.h"
namespace webrtc {
// The Metronome posts OnTick() calls requested with RequestCallOnNextTick.
// The API is designed to be fully used from a single task queue. Scheduled
// callbacks are executed on the same sequence as they were requested on. There
// are no features implemented for cancellation. When that's needed, use e.g.
// ScopedTaskSafety from the client.
//
// The metronome concept is still under experimentation, and may not be availble
// in all platforms or applications. See https://crbug.com/1253787 for more
// details.
//
// Metronome implementations must be thread-compatible.
class RTC_EXPORT Metronome {
public:
// TODO(crbug.com/1381982): remove stale classes and methods once downstream
// dependencies adapts.
class RTC_EXPORT TickListener {
public:
virtual ~TickListener() = default;
virtual void OnTick() = 0;
virtual TaskQueueBase* OnTickTaskQueue() = 0;
};
virtual ~Metronome() = default;
// TODO(crbug.com/1381982): remove stale classes and methods once downstream
// dependencies adapts.
virtual void AddListener(TickListener* listener);
virtual void RemoveListener(TickListener* listener);
// Requests a call to `callback` on the next tick. Scheduled callbacks are
// executed on the same sequence as they were requested on. There are no
// features for cancellation. When that's needed, use e.g. ScopedTaskSafety
// from the client.
virtual void RequestCallOnNextTick(absl::AnyInvocable<void() &&> callback) {}
// Returns the current tick period of the metronome.
virtual TimeDelta TickPeriod() const = 0;
};
} // namespace webrtc
#endif // API_METRONOME_METRONOME_H_