Skip to main content

renderbox_sdk/graph/
input.rs

1use std::cell::RefCell;
2use std::collections::BTreeMap;
3use std::rc::Rc;
4
5use renderbox_dsl::OpNode;
6
7use crate::sorts::{Audio, Video};
8
9use super::builder::GraphBuilder;
10use super::stream::Stream;
11
12pub fn input(path: impl AsRef<str>) -> (Stream<Video>, Stream<Audio>) {
13    let graph = Rc::new(RefCell::new(GraphBuilder::new_internal()));
14    let node_id = graph.borrow_mut().add_node(OpNode::Input {
15        path: Some(path.as_ref().to_string()),
16        variadic: false,
17        opts: BTreeMap::new(),
18    });
19    (
20        Stream::new(node_id, Rc::clone(&graph)),
21        Stream::new(node_id, graph),
22    )
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn input_creates_graph_with_one_node() {
31        let (v, a) = input("test.mp4");
32        assert_eq!(v.graph.borrow().arena.len(), 1);
33        assert_eq!(v.node_id, a.node_id);
34        assert!(Rc::ptr_eq(&v.graph, &a.graph));
35    }
36}