Merge pull request #12 from eaglesemanation/master

Add non-str pipeline support
This commit is contained in:
jazzfool 2024-09-21 12:48:23 +10:00 committed by GitHub
commit 65f9cc5a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 7 deletions

2
Cargo.lock generated
View file

@ -1419,7 +1419,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_video_player" name = "iced_video_player"
version = "0.1.3" version = "0.3.0"
dependencies = [ dependencies = [
"glib", "glib",
"gstreamer", "gstreamer",

View file

@ -10,6 +10,7 @@
//! use iced_video_player::{Video, VideoPlayer}; //! use iced_video_player::{Video, VideoPlayer};
//! use iced::{Sandbox, Element}; //! use iced::{Sandbox, Element};
//! //!
//! # #![allow(clippy::needless_doctest_main)]
//! fn main() { //! fn main() {
//! App::run(Default::default()); //! App::run(Default::default());
//! } //! }

View file

@ -1,8 +1,7 @@
use crate::Error; use crate::Error;
use gst::prelude::*;
use gst_base::prelude::*;
use gstreamer as gst; use gstreamer as gst;
use gstreamer_app as gst_app; use gstreamer_app as gst_app;
use gstreamer_app::prelude::*;
use gstreamer_base as gst_base; use gstreamer_base as gst_base;
use iced::widget::image as img; use iced::widget::image as img;
use std::cell::RefCell; use std::cell::RefCell;
@ -118,16 +117,29 @@ impl Video {
Self::from_pipeline(pipeline, None) Self::from_pipeline(pipeline, None)
} }
/// Creates a new video based on GStreamer pipeline in a same format as used in gst-launch-1.0.
/// Expects an appsink plugin to be present with name set to `iced_video` and caps to
/// `video/x-raw,format=RGBA,pixel-aspect-ratio=1/1`
pub fn from_pipeline<S: AsRef<str>>(pipeline: S, is_live: Option<bool>) -> 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);
let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);
gst::init()?; gst::init()?;
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)?;
Self::from_gst_pipeline(pipeline, is_live)
}
/// Creates a new video based on GStreamer pipeline.
/// Expects an appsink plugin to be present with name set to `iced_video` and caps to
/// `video/x-raw,format=RGBA,pixel-aspect-ratio=1/1`
pub fn from_gst_pipeline(
pipeline: gst::Pipeline,
is_live: Option<bool>,
) -> Result<Self, Error> {
gst::init()?;
static NEXT_ID: AtomicU64 = AtomicU64::new(0);
let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);
let mut live = false; let mut live = false;
match is_live { match is_live {