diff options
Diffstat (limited to 'remuxer/src/seek_index.rs')
-rw-r--r-- | remuxer/src/seek_index.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/remuxer/src/seek_index.rs b/remuxer/src/seek_index.rs index f269a23..93a425c 100644 --- a/remuxer/src/seek_index.rs +++ b/remuxer/src/seek_index.rs @@ -4,6 +4,7 @@ Copyright (C) 2023 metamuffin <metamuffin.org> */ use anyhow::Result; +use jellybase::cache::cache_memory; use jellycommon::seek_index::{BlockIndex, SeekIndex}; use jellymatroska::{ block::Block, @@ -12,27 +13,17 @@ use jellymatroska::{ MatroskaTag, }; use log::{debug, info, trace, warn}; -use std::{collections::BTreeMap, fs::File, path::Path}; +use std::{collections::BTreeMap, fs::File, path::Path, sync::Arc}; -pub fn write_all(path: &Path) -> Result<()> { - if path.with_extension(&format!("si.1")).exists() { - info!("seek index already present"); - return Ok(()); - } - let seek_index = { +pub fn get_seek_index(path: &Path) -> anyhow::Result<Arc<BTreeMap<u64, Arc<SeekIndex>>>> { + cache_memory(&["seekindex", path.to_str().unwrap()], move || { + info!("generating seek index for {path:?}"); let input = File::open(&path).unwrap(); let mut input = EbmlReader::new(input); - import_seek_index(&mut input)? - }; - for (tn, index) in seek_index { - info!("writing index {tn} with {} blocks", index.blocks.len()); - bincode::encode_into_std_write( - index, - &mut File::create(path.with_extension(&format!("si.{tn}")))?, - bincode::config::standard(), - )?; - } - Ok(()) + let index = import_seek_index(&mut input)?; + info!("done"); + Ok(index.into_iter().map(|(k, v)| (k, Arc::new(v))).collect()) + }) } pub fn import_seek_index(input: &mut EbmlReader) -> Result<BTreeMap<u64, SeekIndex>> { |