feat: Modify gst crate to add lot of more granularity
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::*;
|
||||
use crate::priv_prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppSink {
|
||||
inner: gstreamer::Element,
|
||||
}
|
||||
@@ -32,9 +33,9 @@ impl AppSink {
|
||||
Ok(AppSink { inner })
|
||||
}
|
||||
|
||||
pub fn with_caps(mut self, caps: &gstreamer::Caps) -> Self {
|
||||
pub fn with_caps(mut self, caps: Caps) -> Self {
|
||||
use gstreamer::prelude::*;
|
||||
// self.inner.set_caps(Some(caps));
|
||||
self.inner.set_property("caps", caps.inner);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ impl AppSink {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn pull_sample(&self, timeout: impl Into<Option<core::time::Duration>>) -> Result<Sample> {
|
||||
pub fn pull_sample(&self) -> Result<Sample> {
|
||||
use gstreamer::prelude::*;
|
||||
self.appsink()
|
||||
.pull_sample()
|
||||
@@ -62,7 +63,7 @@ impl AppSink {
|
||||
.map(From::from))
|
||||
}
|
||||
|
||||
pub fn pull_preroll(&self, timeout: impl Into<Option<core::time::Duration>>) -> Result<Sample> {
|
||||
pub fn pull_preroll(&self) -> Result<Sample> {
|
||||
use gstreamer::prelude::*;
|
||||
self.appsink()
|
||||
.pull_preroll()
|
||||
@@ -83,26 +84,106 @@ impl AppSink {
|
||||
}
|
||||
}
|
||||
|
||||
fn duration_to_clocktime(
|
||||
timeout: impl Into<Option<core::time::Duration>>,
|
||||
) -> Result<Option<gstreamer::ClockTime>> {
|
||||
match timeout.into() {
|
||||
Some(dur) => {
|
||||
let clocktime = gstreamer::ClockTime::try_from(dur)
|
||||
.change_context(Error)
|
||||
.attach("Failed to convert duration to ClockTime")?;
|
||||
Ok(Some(clocktime))
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sample {
|
||||
inner: gstreamer::Sample,
|
||||
}
|
||||
|
||||
impl From<gstreamer::Sample> for Sample {
|
||||
fn from(inner: gstreamer::Sample) -> Self {
|
||||
Sample { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct Sample {
|
||||
inner: gstreamer::Sample,
|
||||
}
|
||||
|
||||
use gstreamer::BufferRef;
|
||||
impl Sample {
|
||||
pub fn buffer(&self) -> Option<&BufferRef> {
|
||||
self.inner.buffer()
|
||||
}
|
||||
|
||||
pub fn caps(&self) -> Option<&gstreamer::CapsRef> {
|
||||
self.inner.caps()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_appsink() {
|
||||
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 = playback::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 = app::AppSink::new("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||
.expect("Create appsink")
|
||||
.with_caps(
|
||||
Caps::builder(CapsType::Video)
|
||||
.field("format", "RGB")
|
||||
.build(),
|
||||
);
|
||||
|
||||
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({
|
||||
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(..) => {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::*;
|
||||
use crate::priv_prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[repr(transparent)]
|
||||
pub struct Playbin3 {
|
||||
inner: gstreamer::Element,
|
||||
pub(crate) inner: gstreamer::Element,
|
||||
}
|
||||
|
||||
impl Drop for Playbin3 {
|
||||
@@ -61,65 +64,92 @@ impl Playbin3 {
|
||||
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 bus(&self) -> Result<Bus> {
|
||||
let bus = self
|
||||
.inner
|
||||
.bus()
|
||||
.ok_or(Error)
|
||||
.attach("Failed to get bus from playbin3")?;
|
||||
Ok(Bus { bus })
|
||||
}
|
||||
// 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");
|
||||
gstreamer::init().unwrap();
|
||||
let playbin3 = Playbin3::new("test_playbin3").unwrap().with_uri("https://jellyfin.tsuba.darksailor.dev/Items/6010382cf25273e624d305907010d773/Download?api_key=036c140222464878862231ef66a2bc9c");
|
||||
// let mut video_sink = Bin::new("wgpu_video_sink");
|
||||
//
|
||||
// let video_convert = plugins::videoconvertscale::VideoConvert::new("wgpu_video_convert")
|
||||
// .expect("Create videoconvert");
|
||||
// let appsink = AppSink::new("test_appsink").expect("Create appsink");
|
||||
let appsink = plugins::autodetect::AutoVideoSink::new("test_autodetect_video_sink")
|
||||
.expect("Create autodetect video sink");
|
||||
// video_convert
|
||||
// .link(&appsink)
|
||||
// .expect("Link videoconvert to appsink");
|
||||
//
|
||||
// let sink_pad = video_convert.sink_pad();
|
||||
// let sink_pad = Pad::ghost(&sink_pad).expect("Create ghost pad from videoconvert src");
|
||||
// video_sink
|
||||
// .add(appsink)
|
||||
// .expect("Add appsink to video sink")
|
||||
// .add(video_convert)
|
||||
// .expect("Add videoconvert to video sink")
|
||||
// .add_pad(&sink_pad)
|
||||
// .expect("Add ghost pad to video sink");
|
||||
// sink_pad.activate(true).expect("Activate ghost pad");
|
||||
|
||||
let playbin3 = playbin3.with_video_sink(&appsink);
|
||||
playbin3.play().unwrap();
|
||||
let bus = playbin3.bus().unwrap();
|
||||
for msg in bus.iter_timed(None) {
|
||||
tracing::info!("{:#?}", &msg.view());
|
||||
}
|
||||
// std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
}
|
||||
// #[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));
|
||||
// }
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::*;
|
||||
pub use gstreamer_video::VideoFormat;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VideoConvert {
|
||||
inner: gstreamer::Element,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user