feat: Modify gst crate to add lot of more granularity
This commit is contained in:
64
crates/iced-video/src/source.rs
Normal file
64
crates/iced-video/src/source.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VideoSource {
|
||||
playbin: Playbin3,
|
||||
videoconvert: VideoConvert,
|
||||
appsink: AppSink,
|
||||
bus: Bus,
|
||||
}
|
||||
|
||||
impl VideoSource {
|
||||
/// Creates a new video source from the given URL.
|
||||
/// Since this doesn't have to parse the pipeline manually, we aren't sanitizing the URL for
|
||||
/// now.
|
||||
pub async fn new(url: impl AsRef<str>) -> Result<Self> {
|
||||
Gst::new();
|
||||
let videoconvert = VideoConvert::new("iced-video-convert").change_context(Error)?;
|
||||
let appsink = AppSink::new("iced-video-sink").change_context(Error)?;
|
||||
let video_sink = videoconvert.link(&appsink).change_context(Error)?;
|
||||
let playbin = gst::plugins::playback::Playbin3::new("iced-video")
|
||||
.change_context(Error)?
|
||||
.with_uri(url.as_ref())
|
||||
.with_video_sink(&video_sink);
|
||||
let bus = playbin.bus().change_context(Error)?;
|
||||
playbin.wait_ready()?;
|
||||
// let bus_stream = bus.stream();
|
||||
// bus_stream.find(|message| {
|
||||
// let view = message.view();
|
||||
// if let gst::MessageView::StateChanged(change) = view {
|
||||
// change.current() == gst::State::Ready
|
||||
// } else {
|
||||
// false
|
||||
// }
|
||||
// });
|
||||
|
||||
Ok(Self {
|
||||
playbin,
|
||||
videoconvert,
|
||||
appsink,
|
||||
bus,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn play(&self) -> Result<()> {
|
||||
self.playbin
|
||||
.play()
|
||||
.change_context(Error)
|
||||
.attach("Failed to play video")
|
||||
}
|
||||
|
||||
pub fn pause(&self) -> Result<()> {
|
||||
self.playbin
|
||||
.pause()
|
||||
.change_context(Error)
|
||||
.attach("Failed to pause video")
|
||||
}
|
||||
|
||||
pub fn bus(&self) -> &Bus {}
|
||||
// pub fn copy_frame_to_texture(&self, texture: wgpu::TextureView) -> Result<()> {
|
||||
// let frame = self
|
||||
// .appsink
|
||||
// .try_pull_sample(core::time::Duration::from_millis(1))?
|
||||
// .ok_or(Error)
|
||||
// .attach("No video frame available")?;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user