vcs-camera-satellite/src/gst.rs

85 lines
2.4 KiB
Rust
Raw Normal View History

2024-08-19 20:40:52 -07:00
use gstreamer::{
self as gst,
2024-08-25 17:17:40 -07:00
prelude::{Cast, ElementExtManual, GstBinExtManual},
2024-08-19 20:40:52 -07:00
ElementFactory,
};
use gstreamer_app as gst_app;
2024-08-25 17:17:40 -07:00
use crate::config::AppConfig;
2024-08-19 20:40:52 -07:00
pub struct Pipeline {
pub pipeline: gst::Pipeline,
pub sink: gst_app::AppSink,
}
2024-08-25 17:17:40 -07:00
const HEIGHT: usize = 480;
pub fn new_pipeline(config: &AppConfig) -> Pipeline {
2024-08-19 20:40:52 -07:00
let pipeline = gst::Pipeline::builder()
.name("camera_to_rtp_pipeine")
.build();
2024-09-18 10:43:20 -07:00
let source = ElementFactory::make("mfvideosrc")
.build()
.expect("Could not make mfvideosrc element!");
let video_convert = ElementFactory::make("videoconvert")
.build()
.expect("Could not make videoconvert gst element!");
2024-08-19 20:40:52 -07:00
2024-09-18 10:43:20 -07:00
let video_rate = ElementFactory::make("videorate")
.build()
.expect("Could not make videoscale gst element!");
2024-08-19 20:40:52 -07:00
2024-08-25 17:17:40 -07:00
let video_scale = ElementFactory::make("videoscale")
.property("add-borders", true)
.build()
.unwrap();
let video_scale_caps = gstreamer::Caps::builder("video/x-raw")
.field("height", HEIGHT as i32)
.field("width", (HEIGHT as f64 * config.aspect_ratio) as i32)
2024-09-18 10:43:20 -07:00
// .field("framerate", gstreamer::Fraction::new(30, 1))
2024-08-25 17:17:40 -07:00
.build();
// We are using VP8 because VP9 resulted in much worse video quality
// when testing -NY 8/25/2024
2024-09-18 10:43:20 -07:00
let vp8enc = ElementFactory::make("vp8enc")
.build()
.expect("Could not make vp8enc gst element!");
2024-08-19 20:40:52 -07:00
2024-09-18 10:43:20 -07:00
let rtp = ElementFactory::make("rtpvp8pay")
.build()
.expect("Could not make rtpvp8pay gst element!");
2024-08-19 20:40:52 -07:00
let app_sink = gst_app::AppSink::builder().build();
pipeline
.add_many([
&source,
&video_convert,
2024-09-18 10:43:20 -07:00
&video_rate,
2024-08-25 17:17:40 -07:00
&video_scale,
2024-08-19 20:40:52 -07:00
&vp8enc,
&rtp,
app_sink.upcast_ref(),
])
.expect("Could not add all the stuff to the pipeline");
2024-09-18 10:43:20 -07:00
gst::Element::link_many(&[&source, &video_convert, &video_rate, &video_scale])
.expect("Could not link source through video scale!");
2024-08-25 17:17:40 -07:00
video_scale
.link_filtered(&vp8enc, &video_scale_caps)
.expect("Could not link videoscale to vp8enc with caps!");
2024-09-18 10:43:20 -07:00
gst::Element::link_many(&[&vp8enc, &rtp, app_sink.upcast_ref()])
.expect("Could not gst link vp8enc through appsink!");
2024-08-19 20:40:52 -07:00
Pipeline {
pipeline,
sink: app_sink,
}
}