dioxuscut_renderer/
render_frames.rs1use thiserror::Error;
6
7#[derive(Debug, Error)]
9pub enum RenderError {
10 #[error("IO error: {0}")]
11 Io(#[from] std::io::Error),
12 #[error("Server error: {0}")]
13 Server(#[from] crate::server::ServerError),
14 #[error("Encode error: {0}")]
15 Encode(String),
16 #[error("Frame {0} failed: {1}")]
17 FrameFailed(u32, String),
18}
19
20#[derive(Debug, Clone)]
22pub struct RenderConfig {
23 pub url: String,
25 pub output_dir: std::path::PathBuf,
27 pub width: u32,
29 pub height: u32,
31 pub fps: f64,
33 pub duration_in_frames: u32,
35 pub frame_range: Option<std::ops::RangeInclusive<u32>>,
37 pub concurrency: usize,
39}
40
41impl RenderConfig {
42 pub fn new(
44 url: String,
45 output_dir: impl Into<std::path::PathBuf>,
46 width: u32,
47 height: u32,
48 fps: f64,
49 duration_in_frames: u32,
50 ) -> Self {
51 Self {
52 url,
53 output_dir: output_dir.into(),
54 width,
55 height,
56 fps,
57 duration_in_frames,
58 frame_range: None,
59 concurrency: num_cpus(),
60 }
61 }
62
63 pub fn effective_range(&self) -> std::ops::RangeInclusive<u32> {
65 self.frame_range
66 .clone()
67 .unwrap_or(0..=self.duration_in_frames.saturating_sub(1))
68 }
69}
70
71fn num_cpus() -> usize {
72 std::thread::available_parallelism()
73 .map(|n| n.get())
74 .unwrap_or(4)
75}