pub mod partition;
pub mod render;
pub mod replace;
pub mod scan;
pub mod worker;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, AtomicU64};
use std::sync::Mutex;
use crate::transcode;
pub const MIN_TRANSCODE_DURATION_SECS: f64 = 1.0;
#[derive(Debug, Clone)]
pub struct ScanItem {
pub file: PathBuf,
pub iso_path: Option<PathBuf>,
pub inner_path: Option<String>,
pub inner_paths: Option<Vec<String>>,
pub title_suffix: Option<String>,
}
pub struct WorkItem {
pub path: PathBuf,
pub bitrate_kbps: u32,
pub duration_secs: f64,
pub pix_fmt: String,
pub source_size: u64,
pub color: transcode::ColorMetadata,
pub iso_path: Option<PathBuf>,
pub inner_path: Option<String>,
pub inner_paths: Option<Vec<String>>,
pub title_suffix: Option<String>,
pub primary_audio_index: Option<u32>,
}
pub struct WorkerSlot {
pub info: Mutex<Option<(String, String)>>,
pub progress: AtomicU64,
pub speed: AtomicU64,
pub queued: AtomicBool,
pub disk_wait: AtomicBool,
}
impl WorkerSlot {
pub fn new() -> Self {
WorkerSlot {
info: Mutex::new(None),
progress: AtomicU64::new(0),
speed: AtomicU64::new(0),
queued: AtomicBool::new(false),
disk_wait: AtomicBool::new(false),
}
}
pub fn clear(&self) {
use std::sync::atomic::Ordering;
*self.info.lock().unwrap() = None;
self.progress.store(0, Ordering::Relaxed);
self.speed.store(0, Ordering::Relaxed);
self.queued.store(false, Ordering::Relaxed);
self.disk_wait.store(false, Ordering::Relaxed);
}
}
impl Default for WorkerSlot {
fn default() -> Self {
Self::new()
}
}
pub static CANCELLED: AtomicBool = AtomicBool::new(false);
pub static LD_KILL: AtomicBool = AtomicBool::new(false);
pub static TMP_DIRS: Mutex<Vec<PathBuf>> = Mutex::new(Vec::new());
pub fn cleanup_tmp_dirs() {
if let Ok(dirs) = TMP_DIRS.lock() {
for dir in dirs.iter() {
cleanup_tmp_in_dir(dir);
}
}
}
fn cleanup_tmp_in_dir(dir: &std::path::Path) {
if let Ok(entries) = std::fs::read_dir(dir) {
for entry in entries.flatten() {
if let Some(name) = entry.file_name().to_str() {
if name.starts_with(".hvac_tmp_") {
let _ = std::fs::remove_file(entry.path());
}
}
}
}
}