MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ window_frame_tick()

MAYAFLUX_API std::shared_ptr< Vruta::BroadcastSource< WindowFrame > > MayaFlux::Kriya::window_frame_tick ( const std::shared_ptr< Core::Window > &  window)

Create a BroadcastSource<bool> ticking once per captured window frame.

Registers a frame observer with DisplayService for the given window. The window must have capture enabled and the capture state must have been initialized (either via WindowAccessProcessor or set_capture_enabled before the first rendered frame).

Returns nullptr if the DisplayService is unavailable, the window is null, or capture state is not yet active for the window.

The observer callback is non-blocking. Signal delivery is safe across thread boundaries; the BroadcastSource handles the coroutine resume path.

auto src = Kriya::window_frame_tick(window);
get_event_manager()->add_event(std::make_shared<Vruta::Event>(
Kriya::on_signal(src, [](const Kriya::WindowFrame& frame) {
// frame.data, frame.width, frame.height, frame.format
})));
std::shared_ptr< Vruta::BroadcastSource< WindowFrame > > window_frame_tick(const std::shared_ptr< Core::Window > &window)
Create a BroadcastSource<bool> ticking once per captured window frame.
Vruta::Event on_signal(std::shared_ptr< Vruta::BroadcastSource< T > > source, Callback callback)
Creates an Event coroutine that fires on every signal from a BroadcastSource.
std::shared_ptr< Vruta::EventManager > get_event_manager()
Gets the event manager from the default engine.
Definition Chronie.cpp:27

Definition at line 39 of file BroadcastEvents.cpp.

41{
42 auto* svc = Registry::BackendRegistry::instance()
44
45 if (!svc || !window)
46 return nullptr;
47
48 struct State {
50 Registry::Service::DisplayService* svc { nullptr };
51 std::shared_ptr<Core::Window> window;
52 uint32_t observer_id { 0 };
53
54 ~State()
55 {
56 if (svc && observer_id) {
58 std::static_pointer_cast<void>(window), observer_id);
59 }
60 }
61 };
62
63 auto state = std::make_shared<State>();
64 state->svc = svc;
65 state->window = window;
66
67 state->observer_id = svc->register_frame_observer(
68 std::static_pointer_cast<void>(window),
69
70 [weak = std::weak_ptr<State>(state)](
71 const std::shared_ptr<std::vector<uint8_t>>& buf,
72 uint32_t w, uint32_t h, uint32_t fmt) {
73 if (!buf) {
74 return;
75 }
76
77 if (auto s = weak.lock())
78 s->source.signal({ .data = buf, .width = w, .height = h, .format = fmt });
79 });
80
81 if (!state->observer_id)
82 return nullptr;
83
84 return { state, &state->source };
85}
uint32_t h
Definition InkPress.cpp:28
Awaitable single-value broadcast channel for cross-thread signal delivery.
std::function< void(const std::shared_ptr< void > &, uint32_t)> unregister_frame_observer
Unregister a previously registered per-frame observer.
Backend display and presentation service interface.

References MayaFlux::Registry::BackendRegistry::get_service(), h, MayaFlux::Registry::BackendRegistry::instance(), and MayaFlux::Registry::Service::DisplayService::unregister_frame_observer.

+ Here is the call graph for this function: