oximedia_proxy/workflow/
offline.rs1use crate::{ConformEngine, ProxyGenerator, ProxyLinkManager, ProxyPreset, Result};
4use std::path::Path;
5
6pub struct OfflineWorkflow {
8 link_manager: ProxyLinkManager,
9 generator: ProxyGenerator,
10}
11
12impl OfflineWorkflow {
13 pub async fn new(db_path: impl AsRef<Path>) -> Result<Self> {
19 let link_manager = ProxyLinkManager::new(db_path).await?;
20 let generator = ProxyGenerator::new();
21
22 Ok(Self {
23 link_manager,
24 generator,
25 })
26 }
27
28 pub async fn ingest(
34 &mut self,
35 original: impl AsRef<Path>,
36 proxy_output: impl AsRef<Path>,
37 preset: ProxyPreset,
38 ) -> Result<()> {
39 let result = self
41 .generator
42 .generate(&original, &proxy_output, preset)
43 .await?;
44
45 self.link_manager
47 .link_proxy_with_metadata(
48 &proxy_output,
49 &original,
50 preset.to_settings().scale_factor,
51 result.codec,
52 result.duration,
53 None,
54 std::collections::HashMap::new(),
55 )
56 .await?;
57
58 tracing::info!(
59 "Ingested {} -> proxy {}",
60 original.as_ref().display(),
61 proxy_output.as_ref().display()
62 );
63
64 Ok(())
65 }
66
67 pub async fn conform(
73 &self,
74 edl_path: impl AsRef<Path>,
75 output: impl AsRef<Path>,
76 ) -> Result<crate::ConformResult> {
77 let db_path = std::env::temp_dir().join("workflow_conform.json");
78 let engine = ConformEngine::new(&db_path).await?;
79 engine.conform_from_edl(edl_path, output).await
80 }
81}
82
83#[cfg(test)]
84mod tests {
85 use super::*;
86
87 #[tokio::test]
88 async fn test_offline_workflow_creation() {
89 let temp_dir = std::env::temp_dir();
90 let db_path = temp_dir.join("test_offline.json");
91
92 let workflow = OfflineWorkflow::new(&db_path).await;
93 assert!(workflow.is_ok());
94
95 let _ = std::fs::remove_file(db_path);
97 }
98}