MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BroadcastEvents.cpp
Go to the documentation of this file.
1#include "BroadcastEvents.hpp"
2
7
8namespace MayaFlux::Kriya {
9
10std::shared_ptr<Vruta::BroadcastSource<bool>> audio_output_tick()
11{
14
15 if (!svc)
16 return nullptr;
17
18 struct State {
21 uint32_t observer_id { 0 };
22 ~State()
23 {
24 if (svc)
25 svc->unregister_output_observer(observer_id);
26 }
27 };
28
29 auto state = std::make_shared<State>();
30 state->svc = svc;
31 state->observer_id = svc->register_output_observer(
32 [s = state.get()](const double*, uint32_t) {
33 s->source.signal(true);
34 });
35
36 return { state, &state->source };
37}
38
39std::shared_ptr<Vruta::BroadcastSource<WindowFrame>> window_frame_tick(
40 const std::shared_ptr<Core::Window>& window)
41{
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}
86
87} // namespace MayaFlux::Kriya
uint32_t h
Definition InkPress.cpp:28
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
Awaitable single-value broadcast channel for cross-thread signal delivery.
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.
std::shared_ptr< Vruta::BroadcastSource< bool > > audio_output_tick()
Create a BroadcastSource<bool> ticking once per audio output cycle.
std::function< void(uint32_t)> unregister_output_observer
Unregister a previously registered observer.
Backend audio subsystem service interface.
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.