feat: add optional boolean flag for live video format selection for cases where automatic detection might fail

This commit is contained in:
Daniel Bomfim 2024-09-17 17:01:29 -03:00
parent 563c5ee559
commit 02fdd69fff

View file

@ -115,10 +115,10 @@ impl Video {
/// Note that live sourced will report the duration to be zero. /// Note that live sourced will report the duration to be zero.
pub fn new(uri: &url::Url) -> Result<Self, Error> { pub fn new(uri: &url::Url) -> Result<Self, Error> {
let pipeline = format!("uridecodebin uri=\"{}\" ! videoconvert ! videoscale ! appsink name=iced_video caps=video/x-raw,format=RGBA,pixel-aspect-ratio=1/1", uri.as_str()); let pipeline = format!("uridecodebin uri=\"{}\" ! videoconvert ! videoscale ! appsink name=iced_video caps=video/x-raw,format=RGBA,pixel-aspect-ratio=1/1", uri.as_str());
Self::from_pipeline(pipeline) Self::from_pipeline(pipeline, None)
} }
pub fn from_pipeline<S: AsRef<str>>(pipeline: S) -> Result<Self, Error> { pub fn from_pipeline<S: AsRef<str>>(pipeline: S, is_live: Option<bool>) -> Result<Self, Error> {
static NEXT_ID: AtomicU64 = AtomicU64::new(0); static NEXT_ID: AtomicU64 = AtomicU64::new(0);
let id = NEXT_ID.fetch_add(1, Ordering::SeqCst); let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);
@ -127,7 +127,12 @@ impl Video {
let pipeline = gst::parse::launch(pipeline.as_ref())? let pipeline = gst::parse::launch(pipeline.as_ref())?
.downcast::<gst::Pipeline>() .downcast::<gst::Pipeline>()
.map_err(|_| Error::Cast)?; .map_err(|_| Error::Cast)?;
let mut live = false; let mut live = false;
match is_live {
Some(is_live) => live = is_live,
None => {
pipeline pipeline
.iterate_sources() .iterate_sources()
.foreach(|elem| { .foreach(|elem| {
@ -138,6 +143,8 @@ impl Video {
} }
}) })
.unwrap(); .unwrap();
}
};
let app_sink_name = "iced_video"; let app_sink_name = "iced_video";
let app_sink = pipeline let app_sink = pipeline