Skip to main content

oximedia_proxy/conform/
engine.rs

1//! Conforming engine for relinking proxies to originals.
2
3use super::edl::EdlConformer;
4use crate::{ProxyLinkManager, Result};
5use std::path::Path;
6
7/// Conforming engine for proxy-to-original workflows.
8pub struct ConformEngine {
9    link_manager: ProxyLinkManager,
10}
11
12impl ConformEngine {
13    /// Create a new conform engine with the specified link database.
14    ///
15    /// # Errors
16    ///
17    /// Returns an error if the database cannot be opened.
18    pub async fn new(db_path: impl AsRef<Path>) -> Result<Self> {
19        let link_manager = ProxyLinkManager::new(db_path).await?;
20        Ok(Self { link_manager })
21    }
22
23    /// Conform from an EDL file.
24    ///
25    /// # Errors
26    ///
27    /// Returns an error if conforming fails.
28    pub async fn conform_from_edl(
29        &self,
30        edl_path: impl AsRef<Path>,
31        output: impl AsRef<Path>,
32    ) -> Result<ConformResult> {
33        let conformer = EdlConformer::new(&self.link_manager);
34        conformer.conform(edl_path, output).await
35    }
36
37    /// Relink a single proxy file to its original.
38    ///
39    /// # Errors
40    ///
41    /// Returns an error if no link exists for the proxy.
42    pub fn relink(&self, proxy_path: impl AsRef<Path>) -> Result<&Path> {
43        self.link_manager.get_original(proxy_path)
44    }
45
46    /// Get the link manager.
47    #[must_use]
48    pub const fn link_manager(&self) -> &ProxyLinkManager {
49        &self.link_manager
50    }
51}
52
53/// Result of a conform operation.
54#[derive(Debug, Clone)]
55pub struct ConformResult {
56    /// Output file path.
57    pub output_path: std::path::PathBuf,
58
59    /// Number of clips relinked.
60    pub clips_relinked: usize,
61
62    /// Number of clips that couldn't be relinked.
63    pub clips_failed: usize,
64
65    /// Total duration in seconds.
66    pub total_duration: f64,
67
68    /// Frame-accurate conforming was successful.
69    pub frame_accurate: bool,
70}
71
72#[cfg(test)]
73mod tests {
74    use super::*;
75
76    #[tokio::test]
77    async fn test_conform_engine_creation() {
78        let temp_dir = std::env::temp_dir();
79        let db_path = temp_dir.join("test_conform.json");
80
81        let engine = ConformEngine::new(&db_path).await;
82        assert!(engine.is_ok());
83
84        // Clean up
85        let _ = std::fs::remove_file(db_path);
86    }
87}