Files
markbase/markbase-fskit/src/fskit/frame_align.rs
Warren 1300a4e223
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled
MarkBase架构升级:Multi-Volume Virtual Tree + Dual-View Management + Git Remote修正
核心功能:
-  Categories/Series双视图管理(category_view.rs + import_markdown.rs)
-  FUSE Multi-Volume支持(tree_type参数)
-  SSH/SFTP/SCP/rsync协议完整实现(4042行)
-  NFS/SMB Module Phase 1-3完成
-  Archive Module Phase 1-4完成(2916行)
-  Download Center API完整实现
-  S3兼容API实现(560行)

Git配置修正:
-  删除错误origin(gitea.momentry.ddns.net)
-  删除m5max128(指向机器名)
-  设置origin = m5max128gitea.momentry.ddns.net/admin/markbase
-  设置m4minigitea = m4minigitea.momentry.ddns.net/warren/markbase

数据清理:
-  删除38个临时SQLite(保留accusys.sqlite、demo.sqlite)
-  删除.bak、test_*.bin、调试脚本等临时文件
-  删除临时目录(build/、download files/、raid_test/等)
-  更新.gitignore排除临时文件

架构优化:
- 52个文件修改,2434行新增,4739行删除
- Workspace成员整合(16个crate)
- 数据库状态:accusys.sqlite保留(主demo测试)

远程同步:
-  准备推送到m5max128gitea(远程Gitea)
-  准备推送到m4minigitea(本地Gitea)
2026-06-12 12:59:54 +08:00

162 lines
4.2 KiB
Rust

use std::path::Path;
pub struct FrameAlignment {
codec: CodecType,
frame_size: usize,
frame_boundary: usize,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CodecType {
ProRes,
H264,
HEVC,
DNxHD,
DNxHR,
XAVC,
AVCIntra,
Unknown,
}
impl FrameAlignment {
pub fn detect(file_path: &Path) -> Option<Self> {
let ext = file_path
.extension()
.and_then(|e| e.to_str())
.map(|e| e.to_lowercase());
let codec = match ext.as_deref() {
Some("mov") => CodecType::ProRes,
Some("mp4") => CodecType::H264,
Some("m4v") => CodecType::H264,
Some("mxf") => CodecType::DNxHD,
Some("avi") => CodecType::Unknown,
Some("mkv") => CodecType::Unknown,
_ => CodecType::Unknown,
};
if codec == CodecType::Unknown {
return None;
}
Some(FrameAlignment {
codec,
frame_size: 0,
frame_boundary: 4096,
})
}
pub fn is_aligned(&self, offset: usize, size: usize) -> bool {
if self.frame_size == 0 {
return offset % self.frame_boundary == 0 && size % self.frame_boundary == 0;
}
offset % self.frame_size == 0 && size % self.frame_size == 0
}
pub fn optimal_chunk_size(&self) -> usize {
if self.frame_size == 0 {
return self.frame_boundary;
}
self.frame_size
}
pub fn align_offset(&self, offset: usize) -> usize {
if self.frame_size == 0 {
let boundary = self.frame_boundary;
(offset / boundary) * boundary
} else {
(offset / self.frame_size) * self.frame_size
}
}
pub fn align_size(&self, size: usize) -> usize {
if self.frame_size == 0 {
let boundary = self.frame_boundary;
((size + boundary - 1) / boundary) * boundary
} else {
((size + self.frame_size - 1) / self.frame_size) * self.frame_size
}
}
pub fn get_codec(&self) -> CodecType {
self.codec
}
}
impl Default for FrameAlignment {
fn default() -> Self {
FrameAlignment {
codec: CodecType::Unknown,
frame_size: 0,
frame_boundary: 4096,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_frame_alignment_prores() {
let path = Path::new("/test/video.mov");
let alignment = FrameAlignment::detect(path);
assert!(alignment.is_some());
let align = alignment.unwrap();
assert_eq!(align.get_codec(), CodecType::ProRes);
}
#[test]
fn test_frame_alignment_h264() {
let path = Path::new("/test/video.mp4");
let alignment = FrameAlignment::detect(path);
assert!(alignment.is_some());
let align = alignment.unwrap();
assert_eq!(align.get_codec(), CodecType::H264);
}
#[test]
fn test_frame_alignment_dnxhd() {
let path = Path::new("/test/video.mxf");
let alignment = FrameAlignment::detect(path);
assert!(alignment.is_some());
let align = alignment.unwrap();
assert_eq!(align.get_codec(), CodecType::DNxHD);
}
#[test]
fn test_frame_alignment_unknown() {
let path = Path::new("/test/document.pdf");
let alignment = FrameAlignment::detect(path);
assert!(alignment.is_none());
}
#[test]
fn test_alignment_boundary() {
let align = FrameAlignment::default();
assert!(align.is_aligned(0, 4096));
assert!(align.is_aligned(4096, 4096));
assert!(!align.is_aligned(100, 4096));
}
#[test]
fn test_align_offset() {
let align = FrameAlignment::default();
assert_eq!(align.align_offset(0), 0);
assert_eq!(align.align_offset(4096), 4096);
assert_eq!(align.align_offset(5000), 4096);
assert_eq!(align.align_offset(8192), 8192);
}
#[test]
fn test_align_size() {
let align = FrameAlignment::default();
assert_eq!(align.align_size(0), 0);
assert_eq!(align.align_size(4096), 4096);
assert_eq!(align.align_size(5000), 8192);
assert_eq!(align.align_size(100), 4096);
}
}