49 lines
1.8 KiB
Rust
49 lines
1.8 KiB
Rust
//! Headless HLS pipeline probe: can playbin3 reach PLAYING on a live m3u8?
|
|
use gstreamer as gst;
|
|
use gstreamer::prelude::*;
|
|
|
|
fn main() {
|
|
gst::init().unwrap();
|
|
let uri = std::env::args().nth(1).expect("usage: hls_probe <url>");
|
|
let playbin = gst::ElementFactory::make("playbin3")
|
|
.property("uri", &uri)
|
|
.property(
|
|
"video-sink",
|
|
gst::ElementFactory::make("fakevideosink").build().unwrap(),
|
|
)
|
|
.property(
|
|
"audio-sink",
|
|
gst::ElementFactory::make("fakesink").build().unwrap(),
|
|
)
|
|
.build()
|
|
.unwrap();
|
|
playbin.set_state(gst::State::Playing).unwrap();
|
|
let bus = playbin.bus().unwrap();
|
|
let start = std::time::Instant::now();
|
|
while start.elapsed().as_secs() < 20 {
|
|
if let Some(msg) = bus.timed_pop(gst::ClockTime::from_seconds(1)) {
|
|
match msg.view() {
|
|
gst::MessageView::Error(e) => {
|
|
println!("ERROR: {} ({:?})", e.error(), e.debug());
|
|
std::process::exit(1);
|
|
}
|
|
gst::MessageView::StateChanged(sc) => {
|
|
if sc.src().map(|s| s == &playbin).unwrap_or(false)
|
|
&& sc.current() == gst::State::Playing
|
|
{
|
|
println!("PLAYING reached — HLS pipeline works");
|
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
let pos = playbin.query_position::<gst::ClockTime>();
|
|
println!("position after 3s: {pos:?}");
|
|
playbin.set_state(gst::State::Null).unwrap();
|
|
std::process::exit(0);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
println!("TIMEOUT: never reached PLAYING");
|
|
std::process::exit(2);
|
|
}
|