feat: Restructure the gst parent<->child relations
This commit is contained in:
@@ -1,19 +1,8 @@
|
||||
use crate::priv_prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppSink {
|
||||
inner: gstreamer::Element,
|
||||
}
|
||||
|
||||
impl IsElement for AppSink {
|
||||
fn as_element(&self) -> &Element {
|
||||
unsafe { core::mem::transmute(&self.inner) }
|
||||
}
|
||||
|
||||
fn into_element(self) -> Element {
|
||||
Element { inner: self.inner }
|
||||
}
|
||||
}
|
||||
wrap_gst!(AppSink, gstreamer::Element);
|
||||
parent_child!(Pipeline, AppSink, downcast); // since AppSink is an Element internaly
|
||||
parent_child!(Element, AppSink);
|
||||
|
||||
impl Sink for AppSink {}
|
||||
|
||||
@@ -136,28 +125,8 @@ fn test_appsink() {
|
||||
.expect("Link videoconvert to appsink");
|
||||
|
||||
let playbin3 = playbin3.with_video_sink(&video_sink);
|
||||
playbin3.play().expect("Play video");
|
||||
let bus = playbin3.bus().unwrap();
|
||||
// playbin3.play().expect("Play playbin3");
|
||||
|
||||
std::thread::spawn({
|
||||
let playbin3 = playbin3.clone();
|
||||
move || {
|
||||
loop {
|
||||
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
playbin3.play();
|
||||
playbin3.wait_non_null_sync();
|
||||
let sample = appsink
|
||||
.try_pull_sample(core::time::Duration::from_secs(5))
|
||||
.expect("Pull sample from appsink")
|
||||
.expect("No sample received from appsink");
|
||||
|
||||
dbg!(sample.caps());
|
||||
|
||||
playbin3.play();
|
||||
tracing::info!("Played");
|
||||
}
|
||||
}
|
||||
});
|
||||
for msg in bus.iter_timed(None) {
|
||||
match msg.view() {
|
||||
gstreamer::MessageView::Eos(..) => {
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
use crate::*;
|
||||
use crate::priv_prelude::*;
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct AutoVideoSink {
|
||||
inner: gstreamer::Element,
|
||||
}
|
||||
|
||||
impl IsElement for AutoVideoSink {
|
||||
fn as_element(&self) -> &Element {
|
||||
unsafe { core::mem::transmute(&self.inner) }
|
||||
}
|
||||
|
||||
fn into_element(self) -> Element {
|
||||
Element { inner: self.inner }
|
||||
}
|
||||
}
|
||||
wrap_gst!(AutoVideoSink, gstreamer::Element);
|
||||
parent_child!(Element, AutoVideoSink);
|
||||
parent_child!(Bin, AutoVideoSink, downcast);
|
||||
|
||||
impl Sink for AutoVideoSink {}
|
||||
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
use crate::priv_prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[repr(transparent)]
|
||||
pub struct Playbin3 {
|
||||
pub(crate) inner: gstreamer::Element,
|
||||
}
|
||||
wrap_gst!(Playbin3, gstreamer::Element);
|
||||
parent_child!(Element, Playbin3);
|
||||
parent_child!(Pipeline, Playbin3, downcast);
|
||||
parent_child!(Bin, Playbin3, downcast);
|
||||
|
||||
impl Drop for Playbin3 {
|
||||
fn drop(&mut self) {
|
||||
let _ = self
|
||||
.inner
|
||||
.set_state(gstreamer::State::Null)
|
||||
.inspect_err(|e| {
|
||||
tracing::error!("Failed to set playbin3 to Null state on drop: {:?}", e)
|
||||
});
|
||||
self.set_state(gstreamer::State::Null).ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,24 +27,24 @@ impl Playbin3 {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_video_sink(self, video_sink: &impl IsElement) -> Self {
|
||||
pub fn with_video_sink(self, video_sink: &impl ChildOf<Element>) -> Self {
|
||||
use gstreamer::prelude::*;
|
||||
self.inner
|
||||
.set_property("video-sink", &video_sink.as_element().inner);
|
||||
.set_property("video-sink", &video_sink.upcast_ref().inner);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_text_sink(self, text_sink: &impl IsElement) -> Self {
|
||||
pub fn with_text_sink(self, text_sink: &impl ChildOf<Element>) -> Self {
|
||||
use gstreamer::prelude::*;
|
||||
self.inner
|
||||
.set_property("text-sink", &text_sink.as_element().inner);
|
||||
.set_property("text-sink", &text_sink.upcast_ref().inner);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_audio_sink(self, audio_sink: &impl IsElement) -> Self {
|
||||
pub fn with_audio_sink(self, audio_sink: &impl ChildOf<Element>) -> Self {
|
||||
use gstreamer::prelude::*;
|
||||
self.inner
|
||||
.set_property("audio-sink", &audio_sink.as_element().inner);
|
||||
.set_property("audio-sink", &audio_sink.upcast_ref().inner);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -63,93 +57,16 @@ impl Playbin3 {
|
||||
use gstreamer::prelude::*;
|
||||
self.inner.property::<f64>("volume")
|
||||
}
|
||||
|
||||
// pub fn play(&self) -> Result<()> {
|
||||
// use gstreamer::prelude::*;
|
||||
// self.inner
|
||||
// .set_state(gstreamer::State::Playing)
|
||||
// .change_context(Error)
|
||||
// .attach("Failed to set playbin3 to Playing state")?;
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// pub fn pause(&self) -> Result<()> {
|
||||
// use gstreamer::prelude::*;
|
||||
// self.inner
|
||||
// .set_state(gstreamer::State::Paused)
|
||||
// .change_context(Error)
|
||||
// .attach("Failed to set playbin3 to Paused state")?;
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// pub fn bus(&self) -> Result<Bus> {
|
||||
// let bus = self
|
||||
// .inner
|
||||
// .bus()
|
||||
// .ok_or(Error)
|
||||
// .attach("Failed to get bus from playbin3")?;
|
||||
// Ok(Bus { bus })
|
||||
// }
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn test_playbin3() {
|
||||
// use gstreamer::prelude::*;
|
||||
// use tracing_subscriber::prelude::*;
|
||||
// tracing_subscriber::registry()
|
||||
// .with(
|
||||
// tracing_subscriber::fmt::layer()
|
||||
// .with_thread_ids(true)
|
||||
// .with_file(true),
|
||||
// )
|
||||
// .init();
|
||||
// tracing::info!("Linking videoconvert to appsink");
|
||||
// Gst::new();
|
||||
// let playbin3 = Playbin3::new("pppppppppppppppppppppppppppppp").unwrap().with_uri("https://jellyfin.tsuba.darksailor.dev/Items/6010382cf25273e624d305907010d773/Download?api_key=036c140222464878862231ef66a2bc9c");
|
||||
//
|
||||
// let video_convert = plugins::videoconvertscale::VideoConvert::new("vcvcvcvcvcvcvcvcvcvcvcvcvc")
|
||||
// .expect("Create videoconvert");
|
||||
// let appsink =
|
||||
// autodetect::AutoVideoSink::new("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").expect("Create appsink");
|
||||
//
|
||||
// let mut video_sink = video_convert
|
||||
// .link(&appsink)
|
||||
// .expect("Link videoconvert to appsink");
|
||||
//
|
||||
// let playbin3 = playbin3.with_video_sink(&video_sink);
|
||||
// let bus = playbin3.bus().unwrap();
|
||||
// playbin3.play().expect("Play playbin3");
|
||||
// std::thread::spawn(move || loop {
|
||||
// std::thread::sleep(std::time::Duration::from_secs(15));
|
||||
// playbin3.play();
|
||||
// tracing::info!("Played");
|
||||
// });
|
||||
// for msg in bus.iter_timed(None) {
|
||||
// match msg.view() {
|
||||
// gstreamer::MessageView::Eos(..) => {
|
||||
// tracing::info!("End of stream reached");
|
||||
// break;
|
||||
// }
|
||||
// gstreamer::MessageView::Error(err) => {
|
||||
// tracing::error!(
|
||||
// "Error from {:?}: {} ({:?})",
|
||||
// err.src().map(|s| s.path_string()),
|
||||
// err.error(),
|
||||
// err.debug()
|
||||
// );
|
||||
// break;
|
||||
// }
|
||||
// gstreamer::MessageView::StateChanged(state) => {
|
||||
// eprintln!(
|
||||
// "State changed from {:?} to \x1b[33m{:?}\x1b[0m for {:?}",
|
||||
// state.old(),
|
||||
// state.current(),
|
||||
// state.src().map(|s| s.path_string())
|
||||
// );
|
||||
// }
|
||||
// _ => {}
|
||||
// }
|
||||
// // tracing::info!("{:#?}", &msg.view());
|
||||
// }
|
||||
// // std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
// }
|
||||
impl core::ops::Deref for Playbin3 {
|
||||
type Target = Pipeline;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
let gp = self
|
||||
.inner
|
||||
.downcast_ref::<gstreamer::Pipeline>()
|
||||
.expect("BUG: Playbin3 must be a pipeline");
|
||||
unsafe { &*(gp as *const _ as *const Pipeline) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
use crate::*;
|
||||
use crate::priv_prelude::*;
|
||||
#[doc(inline)]
|
||||
pub use gstreamer_video::VideoFormat;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VideoConvert {
|
||||
inner: gstreamer::Element,
|
||||
}
|
||||
|
||||
impl IsElement for VideoConvert {
|
||||
fn as_element(&self) -> &Element {
|
||||
unsafe { core::mem::transmute(&self.inner) }
|
||||
}
|
||||
|
||||
fn into_element(self) -> Element {
|
||||
Element { inner: self.inner }
|
||||
}
|
||||
}
|
||||
wrap_gst!(VideoConvert, gstreamer::Element);
|
||||
parent_child!(Element, VideoConvert);
|
||||
|
||||
impl Sink for VideoConvert {}
|
||||
impl Source for VideoConvert {}
|
||||
|
||||
Reference in New Issue
Block a user