From a123a1997f3ab527ab83b44ca18bec94883f46d0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 18 Apr 2025 23:33:29 +0200 Subject: use impl Hash for cache key instead of string --- remuxer/src/metadata.rs | 24 +++++++++++------------- remuxer/src/seek_index.rs | 6 +----- 2 files changed, 12 insertions(+), 18 deletions(-) (limited to 'remuxer') diff --git a/remuxer/src/metadata.rs b/remuxer/src/metadata.rs index c8a5f8f..4a496fe 100644 --- a/remuxer/src/metadata.rs +++ b/remuxer/src/metadata.rs @@ -33,20 +33,17 @@ pub struct MatroskaMetadata { pub infojson: Option>, } pub fn checked_matroska_metadata(path: &Path) -> Result>> { - cache_memory( - &["mkmeta-check-v1", path.to_string_lossy().as_ref()], - || { - let mut magic = [0; 4]; - File::open(path)?.read_exact(&mut magic).ok(); - if !matches!(magic, [0x1A, 0x45, 0xDF, 0xA3]) { - return Ok(None); - } - Ok(Some((*matroska_metadata(path)?).clone())) - }, - ) + cache_memory("mkmeta-check-v1", path, || { + let mut magic = [0; 4]; + File::open(path)?.read_exact(&mut magic).ok(); + if !matches!(magic, [0x1A, 0x45, 0xDF, 0xA3]) { + return Ok(None); + } + Ok(Some((*matroska_metadata(path)?).clone())) + }) } pub fn matroska_metadata(path: &Path) -> Result> { - cache_memory(&["mkmeta-v3", path.to_string_lossy().as_ref()], || { + cache_memory("mkmeta-v3", path, || { info!("reading {path:?}"); let mut file = BufReader::new(File::open(path)?); let mut file = file.by_ref().take(u64::MAX); @@ -86,7 +83,8 @@ pub fn matroska_metadata(path: &Path) -> Result> { | "cover.avif" => { cover = Some( AssetInner::Cache(cache_file( - &["att-cover", path.to_string_lossy().as_ref()], + "att-cover", + path, move |mut file| { file.write_all(&f.data)?; Ok(()) diff --git a/remuxer/src/seek_index.rs b/remuxer/src/seek_index.rs index 82f62fb..1e1ce02 100644 --- a/remuxer/src/seek_index.rs +++ b/remuxer/src/seek_index.rs @@ -15,11 +15,8 @@ use jellymatroska::{ use log::{debug, info, trace, warn}; use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path, sync::Arc}; -pub const SEEK_INDEX_VERSION: u32 = 0x5eef1de4; - #[derive(Debug, Clone, Decode, Encode)] pub struct SeekIndex { - pub version: u32, pub blocks: Vec, pub keyframes: Vec, } @@ -35,7 +32,6 @@ pub struct BlockIndex { impl Default for SeekIndex { fn default() -> Self { Self { - version: SEEK_INDEX_VERSION, blocks: Vec::new(), keyframes: Vec::new(), } @@ -43,7 +39,7 @@ impl Default for SeekIndex { } pub fn get_seek_index(path: &Path) -> anyhow::Result>>> { - cache_memory(&["seekindex", path.to_str().unwrap()], move || { + cache_memory("seekindex-v1", path, move || { info!("generating seek index for {path:?}"); let input = File::open(path).context("opening source file")?; let mut input = EbmlReader::new(BufReader::new(input)); -- cgit v1.2.3-70-g09d2