Files
TTSTDConnect/rust_core/src/media/renderer.rs
T
tongtong 31b9a52eb4 feat: 接入端到端 demo 与签名变体
- Flutter 桌面端通过 dart:ffi 调用 Rust Core cdylib
- 实现 ECDH P-256 密钥协商、HKDF 子密钥派生、AES-256-GCM 控制帧
- Android 被控端用派生密钥做控制帧加密与媒体包 MAC
- 新增 libopus JNI 骨架,默认回退 MediaCodec
- 新增 aosp/zhanxun/neutral 签名变体与系统 sharedUserId
- 本机独立信令服务与设置页开关
- 新增 .gitignore 排除所有编译产物与打包目录
2026-11-26 18:24:02 +08:00

91 lines
1.9 KiB
Rust

use std::collections::VecDeque;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PixelFormat {
Nv12,
Bgra8888,
Yuv420p,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DecodedFrame {
pub pts: u64,
pub width: u32,
pub height: u32,
pub format: PixelFormat,
pub data: Vec<u8>,
}
pub trait VideoRenderer: Send {
fn submit(&mut self, frame: DecodedFrame) -> Result<(), String>;
fn clear(&mut self);
}
pub trait AudioSink: Send {
fn submit(&mut self, pcm: &[i16]) -> Result<(), String>;
}
#[derive(Debug, Default)]
pub struct FrameQueue {
frames: VecDeque<DecodedFrame>,
capacity: usize,
}
impl FrameQueue {
pub fn new(capacity: usize) -> Self {
Self {
frames: VecDeque::new(),
capacity,
}
}
pub fn len(&self) -> usize {
self.frames.len()
}
pub fn is_empty(&self) -> bool {
self.frames.is_empty()
}
pub fn pop_frame(&mut self) -> Option<DecodedFrame> {
self.frames.pop_front()
}
}
impl VideoRenderer for FrameQueue {
fn submit(&mut self, frame: DecodedFrame) -> Result<(), String> {
if self.capacity > 0 && self.frames.len() >= self.capacity {
self.frames.pop_front();
}
self.frames.push_back(frame);
Ok(())
}
fn clear(&mut self) {
self.frames.clear();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn frame_queue_drops_oldest_frame() {
let mut queue = FrameQueue::new(2);
for pts in 0..3 {
queue
.submit(DecodedFrame {
pts,
width: 1920,
height: 1080,
format: PixelFormat::Nv12,
data: Vec::new(),
})
.unwrap();
}
assert_eq!(queue.len(), 2);
assert_eq!(queue.pop_frame().unwrap().pts, 1);
}
}