225{
226 auto svc = std::make_shared<Registry::Service::AudioBackendService>();
227
228 svc->get_output_snapshot = [this]() -> std::span<const double> {
232 return {};
234 };
235
236 svc->register_output_observer = [this](
237 std::function<void(const double*, uint32_t)> cb) -> uint32_t {
239#ifdef MAYAFLUX_PLATFORM_MACOS
242 do {
244 (*copy)[id] = cb;
245 next = copy;
246 } while (!m_observers_ptr.compare_exchange_weak(
248 std::memory_order_release, std::memory_order_acquire));
250#else
252 std::shared_ptr<ObserverMap> next;
253 do {
254 next = std::make_shared<ObserverMap>(*
current);
255 (*next)[id] = cb;
258 std::memory_order_release, std::memory_order_acquire));
259#endif
260 return id;
261 };
262
263 svc->unregister_output_observer = [this](uint32_t id) {
264#ifdef MAYAFLUX_PLATFORM_MACOS
267 do {
269 copy->erase(id);
270 next = copy;
271 } while (!m_observers_ptr.compare_exchange_weak(
273 std::memory_order_release, std::memory_order_acquire));
275#else
277 std::shared_ptr<ObserverMap> next;
278 do {
279 next = std::make_shared<ObserverMap>(*
current);
280 next->erase(id);
283 std::memory_order_release, std::memory_order_acquire));
284#endif
285 };
286
290 [svc]() -> void* { return svc.get(); });
291}
std::atomic< std::shared_ptr< ObserverMap > > m_observers
std::atomic< uint32_t > m_snapshot_size
std::atomic< const double * > m_snapshot_ptr
std::unordered_map< uint32_t, std::function< void(const double *, uint32_t)> > ObserverMap
std::shared_ptr< Registry::Service::AudioBackendService > m_audio_backend_service
std::atomic< uint32_t > m_next_observer_id
void register_service(ServiceFactory factory)
Register a backend service capability.
static BackendRegistry & instance()
Get the global registry instance.