Compare commits
2 commits
712a4a01e3
...
7e3a973860
Author | SHA1 | Date | |
---|---|---|---|
|
7e3a973860 | ||
|
a0121315b7 |
3 changed files with 92 additions and 35 deletions
65
Cargo.lock
generated
65
Cargo.lock
generated
|
@ -486,6 +486,12 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitstream-io"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c12d1856e42f0d817a835fe55853957c85c8c8a470114029143d3f12671446e"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
|
@ -501,6 +507,12 @@ version = "3.16.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||
|
||||
[[package]]
|
||||
name = "byte-slice-cast"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
|
@ -978,6 +990,39 @@ dependencies = [
|
|||
"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]]
|
||||
name = "gst-plugin-version-helper"
|
||||
version = "0.8.2"
|
||||
|
@ -2412,6 +2457,25 @@ dependencies = [
|
|||
"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]]
|
||||
name = "rust-ini"
|
||||
version = "0.19.0"
|
||||
|
@ -3260,6 +3324,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"config",
|
||||
"ctrlc",
|
||||
"gst-plugin-rtp",
|
||||
"gst-plugin-webrtc",
|
||||
"gstreamer",
|
||||
"gstreamer-webrtc",
|
||||
|
|
|
@ -10,6 +10,7 @@ anyhow = "1.0.86"
|
|||
config = "0.14.0"
|
||||
ctrlc = "3.4.4"
|
||||
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-webrtc = { version = "0.23.0", features = ["v1_22"] }
|
||||
lazy_static = "1.5.0"
|
||||
|
|
61
src/main.rs
61
src/main.rs
|
@ -2,7 +2,7 @@ use std::sync::{atomic::AtomicBool, Arc};
|
|||
|
||||
use anyhow::Error;
|
||||
use gstreamer::{prelude::*, Element, ElementFactory, Pipeline, State};
|
||||
use gstrswebrtc::{signaller as signaller_interface, webrtcsink};
|
||||
use gstrswebrtc::{signaller::Signallable, webrtcsink};
|
||||
|
||||
mod config;
|
||||
mod signaller;
|
||||
|
@ -33,56 +33,47 @@ fn main() -> Result<(), Error> {
|
|||
// GSTREAMER SETUP
|
||||
gstreamer::init()?;
|
||||
gstrswebrtc::plugin_register_static()?;
|
||||
gstrsrtp::plugin_register_static()?;
|
||||
|
||||
// PIPELINE INSTANTIATION
|
||||
let custom_signaller = signaller::MyCustomSignaller::new();
|
||||
let webrtcsink = webrtcsink::BaseWebRTCSink::with_signaller(
|
||||
signaller_interface::Signallable::from(custom_signaller),
|
||||
);
|
||||
// working pipeline
|
||||
// gst-launch-1.0 videotestsrc \
|
||||
// ! video/x-raw,width=1920,height=1080,format=I420 \
|
||||
// ! 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 source = ElementFactory::make("videotestsrc")
|
||||
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
|
||||
.add_many([&source, &convert, webrtcsink.upcast_ref()])
|
||||
let whipsink = ElementFactory::make("whipclientsink")
|
||||
.build()
|
||||
.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.set_state(State::Playing).unwrap();
|
||||
|
||||
|
||||
// BUT WHEN WILL IT END?
|
||||
|
||||
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) {
|
||||
println!("Recieved Ctrl+C, stopping");
|
||||
|
||||
|
|
Loading…
Reference in a new issue