From 14d0d81fdf07065fc051ad1b5d40076b0b2049b1 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 26 Sep 2026 15:14:04 +0000 Subject: [PATCH] wip: rustfmt, clippy fixes for the Android target --- .github/workflows/ci.yml | 2 +- crates/tsc-android/src/app.rs | 8 ++++---- crates/tsc-android/src/bridge.rs | 9 +++++++-- crates/tsc-android/src/capture.rs | 8 +++++++- crates/tsc-android/src/foreground.rs | 5 ++++- crates/tsc-media/src/capture/mod.rs | 2 +- crates/tsc-media/src/codec/image_layout.rs | 17 ++++++++++++----- crates/tsc-media/src/codec/mediacodec.rs | 12 ++++++++++-- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be550e6..f7a4991 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -144,7 +144,7 @@ jobs: run: cargo install cargo-ndk --locked --version 4.1.2 - name: clippy (Android target, deny warnings) run: | - cargo ndk -t arm64-v8a --platform 29 clippy --locked -p tsc-android --no-deps -- -D warnings + cargo ndk -t arm64-v8a --platform 29 clippy --locked -p tsc-android -p tsc-ui --no-deps -- -D warnings cargo ndk -t arm64-v8a --platform 29 clippy --locked -p tsc-media --no-default-features --no-deps -- -D warnings - name: Debug APK working-directory: android diff --git a/crates/tsc-android/src/app.rs b/crates/tsc-android/src/app.rs index f1c2d63..9ab9fd8 100644 --- a/crates/tsc-android/src/app.rs +++ b/crates/tsc-android/src/app.rs @@ -111,10 +111,10 @@ fn watch_voice(host: &'static EngineHost) { loop { match events.recv().await { Ok(event) => { - if let Some(text) = with_foreground(|f| f.update(&event)) { - if let Err(e) = bridge::set_voice_notification(text.as_deref()) { - warn!("voice service: {e}"); - } + if let Some(text) = with_foreground(|f| f.update(&event)) + && let Err(e) = bridge::set_voice_notification(text.as_deref()) + { + warn!("voice service: {e}"); } } Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue, diff --git a/crates/tsc-android/src/bridge.rs b/crates/tsc-android/src/bridge.rs index 59ec77f..53ce2b3 100644 --- a/crates/tsc-android/src/bridge.rs +++ b/crates/tsc-android/src/bridge.rs @@ -39,8 +39,13 @@ pub fn context<'local>(env: &mut Env<'local>) -> Result> { let class = BRIDGE .get() .ok_or_else(|| Error::ClassNotFound { name: "io.github.faumaray.tsc.Bridge".into() })?; - env.call_static_method(class, jni_str!("context"), jni_sig!(() -> android.content.Context), &[])? - .l() + env.call_static_method( + class, + jni_str!("context"), + jni_sig!(() -> android.content.Context), + &[], + )? + .l() } /// Ask for the microphone and notification permissions if not granted yet. diff --git a/crates/tsc-android/src/capture.rs b/crates/tsc-android/src/capture.rs index f34decf..08275c6 100644 --- a/crates/tsc-android/src/capture.rs +++ b/crates/tsc-android/src/capture.rs @@ -159,7 +159,13 @@ pub fn wants_frames() -> bool { } /// A captured RGBA frame. Returns `false` once nobody wants frames. -pub fn on_frame(pixels: Vec, width: u32, height: u32, stride: usize, timestamp_ns: i64) -> bool { +pub fn on_frame( + pixels: Vec, + width: u32, + height: u32, + stride: usize, + timestamp_ns: i64, +) -> bool { with_state(|s| { let timestamp = since(&mut s.first_frame_ns, timestamp_ns); let Some(frames) = &s.frames else { diff --git a/crates/tsc-android/src/foreground.rs b/crates/tsc-android/src/foreground.rs index 6e328e4..0dee48d 100644 --- a/crates/tsc-android/src/foreground.rs +++ b/crates/tsc-android/src/foreground.rs @@ -91,7 +91,10 @@ mod tests { capabilities: Capabilities::default(), }; assert_eq!(fg.update(&info), Some(Some("Connecting to Home".into()))); - assert_eq!(fg.update(&voice(1, VoiceState::Connected)), Some(Some("In voice on Home".into()))); + assert_eq!( + fg.update(&voice(1, VoiceState::Connected)), + Some(Some("In voice on Home".into())) + ); assert_eq!(fg.update(&voice(1, VoiceState::Connected)), None, "no change"); assert_eq!( fg.update(&voice(2, VoiceState::Connecting)), diff --git a/crates/tsc-media/src/capture/mod.rs b/crates/tsc-media/src/capture/mod.rs index c8a10d3..2717fb9 100644 --- a/crates/tsc-media/src/capture/mod.rs +++ b/crates/tsc-media/src/capture/mod.rs @@ -22,13 +22,13 @@ use crate::frame::{AudioBuffer, VideoFrame}; use crate::queue::FrameReceiver; use crate::{Error, Result}; +pub mod external; #[cfg(all(target_os = "linux", feature = "pipewire"))] pub mod pipewire_audio; #[cfg(all(target_os = "linux", feature = "pipewire"))] pub mod portal; #[cfg(all(target_os = "linux", feature = "pipewire"))] mod pw; -pub mod external; pub mod synthetic; #[cfg(windows)] pub mod windows; diff --git a/crates/tsc-media/src/codec/image_layout.rs b/crates/tsc-media/src/codec/image_layout.rs index e63bc02..e77e3c9 100644 --- a/crates/tsc-media/src/codec/image_layout.rs +++ b/crates/tsc-media/src/codec/image_layout.rs @@ -130,7 +130,11 @@ impl ImageLayout { pub fn buffer_len(&self) -> usize { let (cw, ch) = chroma_size(self.width, self.height); let end = |p: &PlaneLayout, w: usize, h: usize| { - if w == 0 || h == 0 { 0 } else { p.offset + (h - 1) * p.row_inc + (w - 1) * p.col_inc + 1 } + if w == 0 || h == 0 { + 0 + } else { + p.offset + (h - 1) * p.row_inc + (w - 1) * p.col_inc + 1 + } }; let (w, h) = (self.width as usize, self.height as usize); end(&self.y, w, h).max(end(&self.u, cw, ch)).max(end(&self.v, cw, ch)) @@ -163,7 +167,11 @@ impl ImageLayout { let uv = PlaneLayout { col_inc: 1, ..self.u }; FrameData::Nv12 { y, uv: read_plane(buf, &uv, cw * 2, ch) } } else { - FrameData::I420 { y, u: read_plane(buf, &self.u, cw, ch), v: read_plane(buf, &self.v, cw, ch) } + FrameData::I420 { + y, + u: read_plane(buf, &self.u, cw, ch), + v: read_plane(buf, &self.v, cw, ch), + } }; let frame = VideoFrame { width: self.width, @@ -303,9 +311,8 @@ mod tests { #[test] fn crop_and_size_checks() { // A decoder buffer of 8x6 (stride 8) showing 6x4. - let layout = ImageLayout::from_color_format(COLOR_FORMAT_I420, 8, 6, 8, 6) - .unwrap() - .cropped(6, 4); + let layout = + ImageLayout::from_color_format(COLOR_FORMAT_I420, 8, 6, 8, 6).unwrap().cropped(6, 4); assert_eq!((layout.width, layout.height), (6, 4)); assert_eq!(layout.u.offset, 48); assert!(ImageLayout::from_color_format(COLOR_FORMAT_FLEXIBLE, 8, 6, 8, 6).is_none()); diff --git a/crates/tsc-media/src/codec/mediacodec.rs b/crates/tsc-media/src/codec/mediacodec.rs index d24910e..864fff0 100644 --- a/crates/tsc-media/src/codec/mediacodec.rs +++ b/crates/tsc-media/src/codec/mediacodec.rs @@ -25,7 +25,9 @@ use ndk::media::media_format::MediaFormat; use tracing::{debug, info}; use super::hw::HardwareEncoderFactory; -use super::image_layout::{COLOR_FORMAT_FLEXIBLE, COLOR_FORMAT_I420, COLOR_FORMAT_NV12, ImageLayout}; +use super::image_layout::{ + COLOR_FORMAT_FLEXIBLE, COLOR_FORMAT_I420, COLOR_FORMAT_NV12, ImageLayout, +}; use super::{Codec, EncodedFrame, EncoderBackend, EncoderConfig, VideoDecoder, VideoEncoder}; use crate::frame::{FrameData, VideoFrame}; use crate::{Error, Result, convert}; @@ -178,7 +180,13 @@ struct EncoderSession { } impl MediaCodecEncoder { - fn format(&self, width: u32, height: u32, color_format: i32, profile: Option) -> MediaFormat { + fn format( + &self, + width: u32, + height: u32, + color_format: i32, + profile: Option, + ) -> MediaFormat { let mut format = MediaFormat::new(); format.set_str("mime", mime(self.codec)); format.set_i32("width", width as i32);