Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(voice): remove unused capture stream lease path

Steven Enamakel6c9e5ca2bbd6
diff --git a/crates/openhuman-core/src/voice/capture_lease.rs b/crates/openhuman-core/src/voice/capture_lease.rs
index ea8f544341..d8e35deab3 100644
--- a/crates/openhuman-core/src/voice/capture_lease.rs
+++ b/crates/openhuman-core/src/voice/capture_lease.rs
@@ -11,8 +11,8 @@ use std::sync::{
use tinybus::module::ModuleClient;
use tinyvoice_bus::{
capture::{
- AudioOutput, CaptureBatch, CaptureError, CaptureHandle, CapturePollRequest, CaptureResult,
- CaptureStream, MicrophonePermission, ReadAudioRequest, RecordingFinishRequest,
+ AudioOutput, CaptureError, CaptureHandle, CaptureResult, MicrophonePermission,
+ ReadAudioRequest, RecordingFinishRequest,
RecordingStartRequest, RecordingSummary, RecordingSummaryRequest,
},
names::methods,
@@ -26,17 +26,6 @@ static NEXT_ID: AtomicU64 = AtomicU64::new(1);
static LEASES: LazyLock<Mutex<HashMap<u64, Arc<State>>>> =
LazyLock::new(|| Mutex::new(HashMap::new()));
static HOOK: AtomicBool = AtomicBool::new(false);
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub(super) enum Kind {
- Recording,
-}
-impl Kind {
- fn generation(self) -> &'static AtomicU64 {
- match self {
- Self::Recording => &RECORDING_GENERATION,
- }
- }
-}
#[async_trait::async_trait]
trait Port: Send + Sync {
async fn call(
@@ -63,7 +52,6 @@ struct State {
id: u64,
port: Arc<dyn Port>,
handle: CaptureHandle,
- kind: Kind,
closed: AtomicBool,
serial: tokio::sync::Mutex<()>,
}
@@ -89,22 +77,14 @@ impl State {
if self.closed.load(Ordering::SeqCst) {
return Ok(());
}
- match self.kind {
- Kind::Recording => {
- cleanup_result(
- self.call::<()>(methods::RECORDING_CANCEL, (&self.handle,))
- .await?,
- )?;
- cleanup_result(
- self.call::<()>(methods::RELEASE_AUDIO_OUTPUT, (&self.handle,))
- .await?,
- )?;
- }
- Kind::Stream => cleanup_result(
- self.call::<()>(methods::CAPTURE_STOP, (&self.handle,))
- .await?,
- )?,
- }
+ cleanup_result(
+ self.call::<()>(methods::RECORDING_CANCEL, (&self.handle,))
+ .await?,
+ )?;
+ cleanup_result(
+ self.call::<()>(methods::RELEASE_AUDIO_OUTPUT, (&self.handle,))
+ .await?,
+ )?;
self.mark_closed();
Ok(())
}
@@ -121,12 +101,12 @@ pub(super) struct CaptureLease {
state: Arc<State>,
}
impl CaptureLease {
- pub(super) async fn reserve(config: &Config, kind: Kind) -> Result<Self, String> {
+ pub(super) async fn reserve(config: &Config) -> Result<Self, String> {
let port: Arc<dyn Port> = Arc::new(BusPort(crate::modules::client(config.clone())));
- Self::reserve_with_port(port, kind).await
+ Self::reserve_with_port(port).await
}
- async fn reserve_with_port(port: Arc<dyn Port>, kind: Kind) -> Result<Self, String> {
- let generation = kind.generation().load(Ordering::SeqCst);
+ async fn reserve_with_port(port: Arc<dyn Port>) -> Result<Self, String> {
+ let generation = RECORDING_GENERATION.load(Ordering::SeqCst);
let reply = port
.call(
methods::RESERVE_CAPTURE,
@@ -143,7 +123,6 @@ impl CaptureLease {
id: NEXT_ID.fetch_add(1, Ordering::Relaxed),
port,
handle: handle.map_err(capture_error)?,
- kind,
closed: AtomicBool::new(false),
serial: tokio::sync::Mutex::new(()),
});
@@ -153,7 +132,7 @@ impl CaptureLease {
.insert(state.id, state.clone());
register_shutdown();
let lease = Self { state };
- if generation != kind.generation().load(Ordering::SeqCst) {
+ if generation != RECORDING_GENERATION.load(Ordering::SeqCst) {
lease.close().await?;
return Err("capture cancelled during lifecycle change".into());
}
@@ -178,52 +157,6 @@ impl CaptureLease {
}
Ok(())
}
- pub(super) async fn start_stream(&self) -> Result<CaptureStream, String> {
- let _serial = self.state.serial.lock().await;
- self.state.check_open()?;
- let stream: CaptureStream = self
- .state
- .call(
- methods::CAPTURE_START,
- (RecordingStartRequest {
- permission: MicrophonePermission::Granted,
- handle: Some(self.state.handle.clone()),
- },),
- )
- .await?
- .map_err(capture_error)?;
- if stream.handle != self.state.handle
- || stream.format.source_rate == 0
- || stream.format.channels == 0
- {
- return Err(malformed());
- }
- Ok(stream)
- }
- pub(super) async fn poll(&self) -> Result<CaptureBatch, String> {
- let _serial = self.state.serial.lock().await;
- self.state.check_open()?;
- let batch: CaptureBatch = self
- .state
- .call(
- methods::CAPTURE_POLL,
- (CapturePollRequest {
- handle: self.state.handle.clone(),
- max_chunks: 2,
- },),
- )
- .await?
- .map_err(capture_error)?;
- if batch.chunks.len() > 2
- || batch.chunks.iter().any(|chunk| {
- chunk.samples.len() > 32_768
- || chunk.samples.iter().any(|sample| !sample.is_finite())
- })
- {
- return Err(malformed());
- }
- Ok(batch)
- }
pub(super) async fn finish(&self) -> Result<RecordingResult, String> {
let _serial = self.state.serial.lock().await;
self.state.check_open()?;
@@ -341,15 +274,11 @@ fn cleanup_result(result: CaptureResult<()>) -> Result<(), String> {
}
/// Release every retained capture lease on sign-out, including failed Drop cleanup.
pub(crate) async fn close_all() -> Result<(), String> {
- close_kind(None).await
-}
-async fn close_kind(kind: Option<Kind>) -> Result<(), String> {
RECORDING_GENERATION.fetch_add(1, Ordering::SeqCst);
let states: Vec<_> = LEASES
.lock()
.expect("capture lease registry poisoned")
.values()
- .filter(|state| kind.is_none_or(|kind| kind == state.kind))
.cloned()
.collect();
let mut failure = None;
@@ -369,7 +298,6 @@ fn register_shutdown() {
});
}
pub(crate) async fn shutdown_capture() {
- super::always_on::shutdown().await;
HOOK.store(false, Ordering::SeqCst);
if let Err(error) = close_all().await {
log::warn!("[voice_capture] shutdown cleanup pending: {error}");