added handshakes

This commit is contained in:
Brad Stein 2025-07-04 03:41:39 -05:00
parent 84790ea470
commit 49022b3714
5 changed files with 41 additions and 9 deletions

View File

@ -140,13 +140,11 @@ impl LesavkaClientApp {
std::env::var("LESAVKA_CAM_SOURCE").ok().as_deref()
)?);
tokio::spawn(Self::cam_loop(vid_ep.clone(), cam));
if caps.microphone {
let mic = Arc::new(MicrophoneCapture::new()?);
tokio::spawn(Self::mic_loop(vid_ep.clone(), mic));
}
}
let mic = Arc::new(MicrophoneCapture::new()?);
tokio::spawn(Self::mic_loop(vid_ep.clone(), mic));
if caps.microphone {
let mic = Arc::new(MicrophoneCapture::new()?);
tokio::spawn(Self::voice_loop(vid_ep.clone(), mic)); // renamed
}
/*────────── central reactor ───────────────────*/
tokio::select! {
@ -269,7 +267,7 @@ impl LesavkaClientApp {
}
/*──────────────── mic stream ─────────────────*/
async fn mic_loop(ep: Channel, mic: Arc<MicrophoneCapture>) {
async fn voice_loop(ep: Channel, mic: Arc<MicrophoneCapture>) {
let mut delay = Duration::from_secs(1);
static FAIL_CNT: AtomicUsize = AtomicUsize::new(0);
loop {

View File

@ -81,7 +81,7 @@ impl CameraCapture {
let buf = sample.buffer()?;
let map = buf.map_readable().ok()?;
let pts = buf.pts().unwrap_or(gst::ClockTime::ZERO).nseconds() / 1_000;
Some(VideoPacket { id: 0, pts, data: map.as_slice().to_vec() })
Some(VideoPacket { id: 2, pts, data: map.as_slice().to_vec() })
}
/// Fuzzymatch devices under `/dev/v4l/by-id`

32
server/src/handshake.rs Normal file
View File

@ -0,0 +1,32 @@
// ─── server/src/handshake.rs ───────────────────────────────────────────────
use tonic::{Request, Response, Status};
use lesavka_common::lesavka::{
Empty, HandshakeSet,
handshake_server::{Handshake, HandshakeServer},
};
/// Static capabilities for now; could be probed at runtime
pub struct HandshakeSvc {
pub camera: bool,
pub microphone: bool,
}
#[tonic::async_trait]
impl Handshake for HandshakeSvc {
async fn get_capabilities(
&self,
_req: Request<Empty>,
) -> Result<Response<HandshakeSet>, Status> {
Ok(Response::new(HandshakeSet {
camera: self.camera,
microphone: self.microphone,
}))
}
}
impl HandshakeSvc {
pub fn server() -> HandshakeServer<Self> {
HandshakeServer::new(Self { camera: true, microphone: true })
}
}

View File

@ -3,3 +3,4 @@
pub mod audio;
pub mod video;
pub mod gadget;
pub mod handshake;

View File

@ -28,7 +28,7 @@ use lesavka_common::lesavka::{
MonitorRequest, VideoPacket, AudioPacket
};
use lesavka_server::{gadget::UsbGadget, video, audio};
use lesavka_server::{gadget::UsbGadget, video, audio, handshake::HandshakeSvc};
/*──────────────── constants ────────────────*/
/// **false** = never reset automatically.
@ -305,6 +305,7 @@ async fn main() -> anyhow::Result<()> {
.tcp_nodelay(true)
.max_frame_size(Some(2*1024*1024))
.add_service(RelayServer::new(handler))
.add_service(HandshakeSvc::server())
.add_service(ReflBuilder::configure().build_v1().unwrap())
.serve(([0,0,0,0], 50051).into())
.await?;