feat: 新增安卓平台支持

This commit is contained in:
mofeng-git
2026-05-24 08:37:19 +00:00
parent dc6475776e
commit b31aae284d
105 changed files with 7900 additions and 473 deletions

View File

@@ -1,4 +1,5 @@
use arc_swap::ArcSwap;
#[cfg(feature = "desktop")]
use parking_lot::Mutex as ParkingMutex;
use parking_lot::RwLock as ParkingRwLock;
use std::collections::{HashMap, VecDeque};
@@ -6,13 +7,18 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::broadcast;
use tracing::{debug, info, warn};
#[cfg(feature = "desktop")]
use tracing::debug;
use tracing::{info, warn};
/// Generation token paired with `client_id` so [`unregister_client`] ignores stale drops.
pub type ClientGeneration = u64;
#[cfg(feature = "desktop")]
use crate::video::codec::traits::{Encoder, EncoderConfig};
#[cfg(feature = "desktop")]
use crate::video::codec::JpegEncoder;
#[cfg(feature = "desktop")]
use crate::video::format::PixelFormat;
use crate::video::VideoFrame;
@@ -108,6 +114,7 @@ pub struct MjpegStreamHandler {
last_frame_ts: ParkingRwLock<Option<Instant>>,
dropped_same_frames: AtomicU64,
max_drop_same_frames: AtomicU64,
#[cfg(feature = "desktop")]
jpeg_encoder: ParkingMutex<Option<JpegEncoder>>,
jpeg_quality: AtomicU64,
}
@@ -126,6 +133,7 @@ impl MjpegStreamHandler {
sequence: AtomicU64::new(0),
clients: ParkingRwLock::new(HashMap::new()),
next_generation: AtomicU64::new(1),
#[cfg(feature = "desktop")]
jpeg_encoder: ParkingMutex::new(None),
auto_pause_config: ParkingRwLock::new(AutoPauseConfig::default()),
last_frame_ts: ParkingRwLock::new(None),
@@ -157,6 +165,7 @@ impl MjpegStreamHandler {
}
let frame = if !frame.format.is_compressed() {
#[cfg(feature = "desktop")]
match self.encode_to_jpeg(&frame) {
Ok(jpeg_frame) => jpeg_frame,
Err(e) => {
@@ -164,6 +173,13 @@ impl MjpegStreamHandler {
return;
}
}
#[cfg(not(feature = "desktop"))]
{
warn!(
"Dropping non-JPEG frame for MJPEG stream on Android; native encoder is not wired yet"
);
return;
}
} else {
frame
};
@@ -200,6 +216,7 @@ impl MjpegStreamHandler {
let _ = self.frame_notify.send(());
}
#[cfg(feature = "desktop")]
fn encode_to_jpeg(&self, frame: &VideoFrame) -> Result<VideoFrame, String> {
let resolution = frame.resolution;
let sequence = self.sequence.load(Ordering::Relaxed);

View File

@@ -1,7 +1,9 @@
//! MJPEG multipart streaming and WebSocket HID (for MJPEG mode).
pub mod mjpeg;
#[cfg(feature = "desktop")]
pub mod ws_hid;
pub use mjpeg::{ClientGuard, MjpegStreamHandler};
#[cfg(feature = "desktop")]
pub use ws_hid::WsHidHandler;