breadcast/breadcast-caststream-sys/vendor/openscreen/platform/api/task_runner.h
Breadway 8c745d18e0
Some checks failed
dev release / build (push) Failing after 12s
Implement Cast Streaming mirroring, DLNA casting, daemon+GUI, and breadd integration
Builds out the full v1 scope: a vendored+patched openscreen subset for
low-latency Cast Streaming (Mirroring receiver 0F5096E8) alongside the
existing Cast V2/HLS and new DLNA/AVTransport casting paths, breadcastd's
Idle/Casting state machine with a private IPC socket, the breadcast GTK4
popup as a thin IPC client, and bread.cast.*/bread.command.cast.* breadd
integration (device discovery, start/stop, mirroring lifecycle events).
Also adds bakery/systemd/Forgejo CI packaging.

Validated end-to-end against a real Chromecast/Google TV: negotiated
Cast Streaming session, live pipeline playback, and daemon+GUI click-to-cast/
stop through the actual popup.
2026-08-03 09:07:21 +08:00

64 lines
2.3 KiB
C++

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PLATFORM_API_TASK_RUNNER_H_
#define PLATFORM_API_TASK_RUNNER_H_
#include <future>
#include <utility>
#include "platform/api/time.h"
namespace openscreen {
// A thread-safe API surface that allows for posting tasks. The underlying
// implementation may be single or multi-threaded, and all complication should
// be handled by the implementation class. The implementation must guarantee:
// (1) Tasks shall not overlap in time/CPU.
// (2) Tasks shall run sequentially, e.g. posting task A then B implies
// that A shall run before B.
// (3) If task A is posted before task B, then any mutation in A happens-before
// B runs (even if A and B run on different threads).
class TaskRunner {
public:
using Task = std::packaged_task<void()>;
virtual ~TaskRunner() = default;
// Takes any callable target (function, lambda-expression, std::bind result,
// etc.) that should be run at the first convenient time.
template <typename Functor>
inline void PostTask(Functor f) {
PostPackagedTask(Task(std::move(f)));
}
// Takes any callable target (function, lambda-expression, std::bind result,
// etc.) that should be run no sooner than `delay` time from now. Note that
// the Task might run after an additional delay, especially under heavier
// system load. There is no deadline concept.
template <typename Functor>
inline void PostTaskWithDelay(Functor f, Clock::duration delay) {
PostPackagedTaskWithDelay(Task(std::move(f)), delay);
}
// Implementations should provide the behavior explained in the comments above
// for PostTask[WithDelay](). Client code may also call these directly when
// passing an existing Task object.
virtual void PostPackagedTask(Task task) = 0;
virtual void PostPackagedTaskWithDelay(Task task, Clock::duration delay) = 0;
// Return true if the calling thread is the thread that task runner is using
// to run tasks, false otherwise.
virtual bool IsRunningOnTaskRunner() = 0;
// Posts a task to delete `object`.
template <class T>
void DeleteSoon(const T* object) {
PostTask([object] { delete static_cast<const T*>(object); });
}
};
} // namespace openscreen
#endif // PLATFORM_API_TASK_RUNNER_H_