added os-switch build for gstreamer
This commit is contained in:
parent
d8def332bf
commit
c029d6ccc5
2 changed files with 104 additions and 32 deletions
82
src/gst.rs
82
src/gst.rs
|
@ -1,6 +1,8 @@
|
||||||
use gstreamer::{
|
use gstreamer::{
|
||||||
self as gst,
|
self as gst,
|
||||||
prelude::{Cast, ElementExtManual, GstBinExtManual},
|
prelude::{
|
||||||
|
Cast, ElementExt, ElementExtManual, GObjectExtManualGst, GstBinExt, GstBinExtManual, PadExt,
|
||||||
|
},
|
||||||
ElementFactory,
|
ElementFactory,
|
||||||
};
|
};
|
||||||
use gstreamer_app as gst_app;
|
use gstreamer_app as gst_app;
|
||||||
|
@ -14,16 +16,27 @@ pub struct Pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
const HEIGHT: usize = 480;
|
const HEIGHT: usize = 480;
|
||||||
|
const SOCKET_PATH: &str = "/tmp/VCS-streamer-shm";
|
||||||
|
|
||||||
pub fn new_pipeline(config: &AppConfig) -> Pipeline {
|
pub fn new_pipeline(config: &AppConfig) -> Pipeline {
|
||||||
let pipeline = gst::Pipeline::builder()
|
let pipeline = gst::Pipeline::builder()
|
||||||
.name("camera_to_rtp_pipeine")
|
.name("camera_to_rtp_pipeine")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// let source = ElementFactory::make("mfvideosrc")
|
let source = {
|
||||||
let source = ElementFactory::make("v4l2src")
|
#[cfg(target_os = "windows")]
|
||||||
.build()
|
{
|
||||||
.expect("Could not make mfvideosrc element!");
|
ElementFactory::make("mfvideosrc")
|
||||||
|
.build()
|
||||||
|
.expect("Could not make mfvideosrc element!")
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
ElementFactory::make("v4l2src")
|
||||||
|
.build()
|
||||||
|
.expect("Could not make mfvideosrc element!")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let video_convert = ElementFactory::make("videoconvert")
|
let video_convert = ElementFactory::make("videoconvert")
|
||||||
.build()
|
.build()
|
||||||
|
@ -33,6 +46,10 @@ pub fn new_pipeline(config: &AppConfig) -> Pipeline {
|
||||||
.build()
|
.build()
|
||||||
.expect("Could not make videoscale gst element!");
|
.expect("Could not make videoscale gst element!");
|
||||||
|
|
||||||
|
let tee = ElementFactory::make("tee")
|
||||||
|
.build()
|
||||||
|
.expect("Could not make Tee gst element!");
|
||||||
|
|
||||||
let video_scale = ElementFactory::make("videoscale")
|
let video_scale = ElementFactory::make("videoscale")
|
||||||
.property("add-borders", true)
|
.property("add-borders", true)
|
||||||
.build()
|
.build()
|
||||||
|
@ -61,6 +78,7 @@ pub fn new_pipeline(config: &AppConfig) -> Pipeline {
|
||||||
&source,
|
&source,
|
||||||
&video_convert,
|
&video_convert,
|
||||||
&video_rate,
|
&video_rate,
|
||||||
|
&tee,
|
||||||
&video_scale,
|
&video_scale,
|
||||||
&vp8enc,
|
&vp8enc,
|
||||||
&rtp,
|
&rtp,
|
||||||
|
@ -68,8 +86,31 @@ pub fn new_pipeline(config: &AppConfig) -> Pipeline {
|
||||||
])
|
])
|
||||||
.expect("Could not add all the stuff to the pipeline");
|
.expect("Could not add all the stuff to the pipeline");
|
||||||
|
|
||||||
gst::Element::link_many(&[&source, &video_convert, &video_rate, &video_scale])
|
source
|
||||||
.expect("Could not link source through video scale!");
|
.link(&video_convert)
|
||||||
|
.expect("Could not link source to video convert");
|
||||||
|
|
||||||
|
let tee_caps = gstreamer::Caps::builder("video/x-raw").build();
|
||||||
|
|
||||||
|
video_convert
|
||||||
|
.link_filtered(&tee, &tee_caps)
|
||||||
|
.expect("Could not link video convert and tee!");
|
||||||
|
|
||||||
|
let tee_src_1 = tee
|
||||||
|
.request_pad_simple("src_%u")
|
||||||
|
.expect("Could not get src pad 1 from tee");
|
||||||
|
|
||||||
|
tee_src_1
|
||||||
|
.link(
|
||||||
|
&video_rate
|
||||||
|
.static_pad("sink")
|
||||||
|
.expect("Could not get static sink pad from video_rate"),
|
||||||
|
)
|
||||||
|
.expect("Could not link tee pad and video rate");
|
||||||
|
|
||||||
|
video_rate
|
||||||
|
.link(&video_scale)
|
||||||
|
.expect("Could not link video rate to video scale");
|
||||||
|
|
||||||
video_scale
|
video_scale
|
||||||
.link_filtered(&vp8enc, &video_scale_caps)
|
.link_filtered(&vp8enc, &video_scale_caps)
|
||||||
|
@ -78,6 +119,33 @@ pub fn new_pipeline(config: &AppConfig) -> Pipeline {
|
||||||
gst::Element::link_many(&[&vp8enc, &rtp, app_sink.upcast_ref()])
|
gst::Element::link_many(&[&vp8enc, &rtp, app_sink.upcast_ref()])
|
||||||
.expect("Could not gst link vp8enc through appsink!");
|
.expect("Could not gst link vp8enc through appsink!");
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
let hailo_sink = ElementFactory::make("shmsink")
|
||||||
|
.build()
|
||||||
|
.expect("Could not create the shared memory sink!");
|
||||||
|
|
||||||
|
hailo_sink.set_property_from_str("socket-path", SOCKET_PATH);
|
||||||
|
hailo_sink.set_property_from_str("sync", "true");
|
||||||
|
hailo_sink.set_property_from_str("wait-for-connection", "false");
|
||||||
|
|
||||||
|
pipeline
|
||||||
|
.add(&hailo_sink)
|
||||||
|
.expect("Could not add hailo shm to pipeline bin!");
|
||||||
|
|
||||||
|
let tee_src_2 = tee
|
||||||
|
.request_pad_simple("src_%u")
|
||||||
|
.expect("Could not create hailo tee src pad");
|
||||||
|
|
||||||
|
tee_src_2
|
||||||
|
.link(
|
||||||
|
&hailo_sink
|
||||||
|
.static_pad("sink")
|
||||||
|
.expect("Could not get hailo static sink pad"),
|
||||||
|
)
|
||||||
|
.expect("Could not link tee src pad to hailo sink pad");
|
||||||
|
}
|
||||||
|
|
||||||
Pipeline {
|
Pipeline {
|
||||||
pipeline,
|
pipeline,
|
||||||
sink: app_sink,
|
sink: app_sink,
|
||||||
|
|
54
src/main.rs
54
src/main.rs
|
@ -166,34 +166,37 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut do_webrtc = false;
|
let mut do_webrtc = false;
|
||||||
match app_receiver.recv().await {
|
loop {
|
||||||
Ok(ApplicationMessage::NameRequest(None)) => {
|
match app_receiver.recv().await {
|
||||||
if let Err(e) = app_sender
|
Ok(ApplicationMessage::NameRequest(None)) => {
|
||||||
.send(ApplicationMessage::NameRequest(Some(
|
if let Err(e) = app_sender
|
||||||
SATELLITE_NAME.to_owned(),
|
.send(ApplicationMessage::NameRequest(Some(
|
||||||
)))
|
SATELLITE_NAME.to_owned(),
|
||||||
.await
|
)))
|
||||||
{
|
.await
|
||||||
error!("Could not let the remote know my name! {e}");
|
{
|
||||||
|
error!("Could not let the remote know my name! {e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Ok(ApplicationMessage::ConnectionSupportsWebRTCRequest) => {
|
||||||
Ok(ApplicationMessage::ConnectionSupportsWebRTCRequest) => {
|
if let Err(e) = app_sender
|
||||||
if let Err(e) = app_sender
|
.send(ApplicationMessage::ConnectionSupportsWebRTC(true))
|
||||||
.send(ApplicationMessage::ConnectionSupportsWebRTC(true))
|
.await
|
||||||
.await
|
{
|
||||||
{
|
error!("Coudl not post request webrtc support=true to async channel, dropping connection: {e}");
|
||||||
error!("Coudl not post request webrtc support=true to async channel, dropping connection: {e}");
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(ApplicationMessage::ConnectionSupportsWebRTC(state)) => {
|
||||||
|
do_webrtc = state;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
Ok(ApplicationMessage::ConnectionSupportsWebRTC(state)) => {
|
error!("Could not receive incoming message from remote during webrtc status check!: {e}");
|
||||||
do_webrtc = state;
|
}
|
||||||
}
|
_ => {
|
||||||
Err(e) => {
|
info!("Received unhandled message from remote");
|
||||||
error!("Could not receive incoming message from remote during webrtc status check!: {e}");
|
}
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
info!("Received unhandled message from remote");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +343,7 @@ async fn main() {
|
||||||
error!("I got a tracking boxes message?");
|
error!("I got a tracking boxes message?");
|
||||||
}
|
}
|
||||||
ApplicationMessage::ManualMovementOverride((x, y)) => {
|
ApplicationMessage::ManualMovementOverride((x, y)) => {
|
||||||
|
debug!("Received a manual override {}, {}", x, y);
|
||||||
if let Err(e) = to_mec.send(ApplicationEvent::ManualMoveEvent((x, y))).await {
|
if let Err(e) = to_mec.send(ApplicationEvent::ManualMoveEvent((x, y))).await {
|
||||||
error!("Could not send manual override to state machine! {e}");
|
error!("Could not send manual override to state machine! {e}");
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue