edit/clip.rs
1//! Reference to the source recording an [`EditProject`](crate::EditProject)
2//! edits.
3
4use std::path::PathBuf;
5
6use serde::{Deserialize, Serialize};
7
8use crate::segment::Frame;
9
10/// Immutable metadata about the source recording a project edits.
11///
12/// The editor never rewrites the source file; every edit is expressed
13/// against this reference (segments index into `0..frame_count`, the
14/// renderer decodes from `path`). Stored in the project file so a
15/// project re-opens against the right media.
16#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
17pub struct ClipRef {
18 /// Absolute path to the source recording on disk.
19 pub path: PathBuf,
20 /// Source frame width in pixels.
21 pub width: u32,
22 /// Source frame height in pixels.
23 pub height: u32,
24 /// Source frame rate (frames per second).
25 pub source_fps: u32,
26 /// Total number of frames in the source recording.
27 pub frame_count: Frame,
28}
29
30impl ClipRef {
31 /// Build a reference from a path + the source recording's metadata.
32 #[must_use]
33 pub fn new(
34 path: PathBuf,
35 width: u32,
36 height: u32,
37 source_fps: u32,
38 frame_count: Frame,
39 ) -> Self {
40 Self {
41 path,
42 width,
43 height,
44 source_fps,
45 frame_count,
46 }
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn clip_ref_round_trips_fields() {
56 let c = ClipRef::new(PathBuf::from("/tmp/rec.mp4"), 1920, 1080, 30, 900);
57 assert_eq!(c.width, 1920);
58 assert_eq!(c.height, 1080);
59 assert_eq!(c.source_fps, 30);
60 assert_eq!(c.frame_count, 900);
61 assert_eq!(c.path, PathBuf::from("/tmp/rec.mp4"));
62 }
63}