feat: Modify gst crate to add lot of more granularity

This commit is contained in:
uttarayan21
2025-12-22 13:27:30 +05:30
parent d42ef3b550
commit 043d1e99f0
23 changed files with 947 additions and 392 deletions

View File

@@ -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));
// }