fuchsia_audio/
lib.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use anyhow::{anyhow, Context, Error};
6use fidl::endpoints::ServerEnd;
7use fidl_fuchsia_audio_controller as fac;
8use futures::TryStreamExt;
9use std::sync::atomic::{AtomicBool, Ordering};
10
11pub mod dai;
12pub mod device;
13pub mod format;
14pub mod format_set;
15pub mod registry;
16pub mod sigproc;
17#[cfg(target_os = "fuchsia")]
18pub mod vmo_buffer;
19
20pub use format::{parse_duration, str_to_clock, Format};
21pub use registry::Registry;
22#[cfg(target_os = "fuchsia")]
23pub use vmo_buffer::VmoBuffer;
24
25pub async fn stop_listener(
26    canceler: ServerEnd<fac::RecordCancelerMarker>,
27    stop_signal: &AtomicBool,
28) -> Result<(), Error> {
29    let mut stream = canceler.into_stream();
30
31    let item = stream.try_next().await;
32    stop_signal.store(true, Ordering::SeqCst);
33
34    match item {
35        Ok(Some(request)) => match request {
36            fac::RecordCancelerRequest::Cancel { responder } => {
37                responder.send(Ok(())).context("FIDL error with stop request")
38            }
39            _ => Err(anyhow!("Unimplemented method on canceler")),
40        },
41        Ok(None) => Ok(()),
42        Err(e) => Err(anyhow!("FIDL error with stop request: {e}")),
43    }
44}