merged a basic example

This commit is contained in:
Nickiel12 2024-08-10 21:05:02 -07:00
commit 7e3a973860
3 changed files with 92 additions and 35 deletions

65
Cargo.lock generated
View file

@ -486,6 +486,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "bitstream-io"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c12d1856e42f0d817a835fe55853957c85c8c8a470114029143d3f12671446e"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.4" version = "0.10.4"
@ -501,6 +507,12 @@ version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "byte-slice-cast"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
version = "1.5.0" version = "1.5.0"
@ -978,6 +990,39 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "gst-plugin-rtp"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c73a24533857d3c5d5de3a512a381e43b92d93089828a0a705d7d81e326f128"
dependencies = [
"anyhow",
"atomic_refcell",
"bitstream-io",
"byte-slice-cast",
"chrono",
"futures",
"gio",
"gst-plugin-version-helper",
"gstreamer",
"gstreamer-audio",
"gstreamer-base",
"gstreamer-net",
"gstreamer-rtp",
"gstreamer-video",
"hex",
"log",
"once_cell",
"rand",
"rtcp-types",
"rtp-types",
"slab",
"smallvec",
"thiserror",
"time",
"tokio",
]
[[package]] [[package]]
name = "gst-plugin-version-helper" name = "gst-plugin-version-helper"
version = "0.8.2" version = "0.8.2"
@ -2412,6 +2457,25 @@ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]]
name = "rtcp-types"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce5248489db464de29835170cd1f6e19933146b0016789effc59cb53d9f13844"
dependencies = [
"thiserror",
]
[[package]]
name = "rtp-types"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01b38bb7fd9425628876786934ade84ec5cb63905804f073583e6554d33f9af"
dependencies = [
"smallvec",
"thiserror",
]
[[package]] [[package]]
name = "rust-ini" name = "rust-ini"
version = "0.19.0" version = "0.19.0"
@ -3260,6 +3324,7 @@ dependencies = [
"anyhow", "anyhow",
"config", "config",
"ctrlc", "ctrlc",
"gst-plugin-rtp",
"gst-plugin-webrtc", "gst-plugin-webrtc",
"gstreamer", "gstreamer",
"gstreamer-webrtc", "gstreamer-webrtc",

View file

@ -10,6 +10,7 @@ anyhow = "1.0.86"
config = "0.14.0" config = "0.14.0"
ctrlc = "3.4.4" ctrlc = "3.4.4"
gst-plugin-webrtc = { version = "0.13.0", features = ["v1_22"] } gst-plugin-webrtc = { version = "0.13.0", features = ["v1_22"] }
gst-plugin-rtp = "0.13.0"
gstreamer = { version = "0.23.0", features = ["v1_22"] } gstreamer = { version = "0.23.0", features = ["v1_22"] }
gstreamer-webrtc = { version = "0.23.0", features = ["v1_22"] } gstreamer-webrtc = { version = "0.23.0", features = ["v1_22"] }
lazy_static = "1.5.0" lazy_static = "1.5.0"

View file

@ -2,7 +2,7 @@ use std::sync::{atomic::AtomicBool, Arc};
use anyhow::Error; use anyhow::Error;
use gstreamer::{prelude::*, Element, ElementFactory, Pipeline, State}; use gstreamer::{prelude::*, Element, ElementFactory, Pipeline, State};
use gstrswebrtc::{signaller as signaller_interface, webrtcsink}; use gstrswebrtc::{signaller::Signallable, webrtcsink};
mod config; mod config;
mod signaller; mod signaller;
@ -33,56 +33,47 @@ fn main() -> Result<(), Error> {
// GSTREAMER SETUP // GSTREAMER SETUP
gstreamer::init()?; gstreamer::init()?;
gstrswebrtc::plugin_register_static()?; gstrswebrtc::plugin_register_static()?;
gstrsrtp::plugin_register_static()?;
// PIPELINE INSTANTIATION // working pipeline
let custom_signaller = signaller::MyCustomSignaller::new(); // gst-launch-1.0 videotestsrc \
let webrtcsink = webrtcsink::BaseWebRTCSink::with_signaller( // ! video/x-raw,width=1920,height=1080,format=I420 \
signaller_interface::Signallable::from(custom_signaller), // ! x264enc speed-preset=ultrafast bitrate=2000 \
); // ! video/x-h264,profile=baseline \
// ! whipclientsink signaller::whip-endpoint=http://localhost:8889/mystream/whip
let pipeline = Pipeline::with_name("rstp-pipeline"); let pipeline = Pipeline::with_name("rstp-pipeline");
// let source = ElementFactory::make("videotestsrc") // let source = ElementFactory::make("videotestsrc")
let source = ElementFactory::make("videotestsrc").build().unwrap(); let source = ElementFactory::make("videotestsrc").build().unwrap();
let convert = ElementFactory::make("x264enc").build().unwrap(); let convert = ElementFactory::make("x264enc")
.property("speed-preset", "ultrafast")
.property("bitrate", 2000)
.build().unwrap();
pipeline let whipsink = ElementFactory::make("whipclientsink")
.add_many([&source, &convert, webrtcsink.upcast_ref()]) .build()
.unwrap(); .unwrap();
Element::link_many([&source, &convert, webrtcsink.upcast_ref::<Element>()]).unwrap(); pipeline
.add_many([&source, &convert, whipsink.upcast_ref()])
.unwrap();
if let Some(whipsink) = whipsink.dynamic_cast_ref::<gstrswebrtc::webrtcsink::WhipWebRTCSink>() {
let signaller = whipsink.property::<Signallable>("signaller");
signaller.set_property_from_str(
"whip-endpoint",
&format!("http://localhost:{}/whip", 8889),
);
}
// PIPELINE START // PIPELINE START
// pipeline.set_state(State::Playing).unwrap(); // pipeline.set_state(State::Playing).unwrap();
// BUT WHEN WILL IT END?
loop { loop {
if let Ok((ws, resp)) = tungstenite::connect(format!("ws://{}:{}", config.destination_ip, config.destination_port)) {
while !to_quit.load(std::sync::atmoic::Ordering::SeqCst) {
match ws.read() {
Err(e) => {
error!("There was an error from the websocket: {e}");
break;
},
Ok(msg) => {
match msg {
Message::Text(text) => {
info!("There was a text message! {text}");
match text {
"StartStream" => pipeline.set_state(State::Playing),
"StopStream" => pipeline.set_state(State::Paused),
_ =>
}
}
}
}
}
}
}
if to_quit.load(std::sync::atomic::Ordering::SeqCst) { if to_quit.load(std::sync::atomic::Ordering::SeqCst) {
println!("Recieved Ctrl+C, stopping"); println!("Recieved Ctrl+C, stopping");