fix(video): try to optimize memory leaks
This commit is contained in:
@@ -13,7 +13,7 @@ use std::sync::{Arc, Mutex, atomic::AtomicBool};
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VideoSource {
|
||||
pub(crate) playbin: Playbin3,
|
||||
pub(crate) videoconvert: VideoConvert,
|
||||
// pub(crate) videoconvert: VideoConvert,
|
||||
pub(crate) appsink: AppSink,
|
||||
pub(crate) bus: Bus,
|
||||
pub(crate) ready: Arc<AtomicBool>,
|
||||
@@ -26,22 +26,25 @@ impl VideoSource {
|
||||
/// now.
|
||||
pub fn new(url: impl AsRef<str>) -> Result<Self> {
|
||||
Gst::new();
|
||||
let videoconvert = VideoConvert::new("iced-video-convert")
|
||||
// .change_context(Error)?
|
||||
// .with_output_format(gst::plugins::videoconvertscale::VideoFormat::Rgba)
|
||||
.change_context(Error)?;
|
||||
// let videoconvert = VideoConvert::new("iced-video-convert")
|
||||
// // .change_context(Error)?
|
||||
// // .with_output_format(gst::plugins::videoconvertscale::VideoFormat::Rgba)
|
||||
// .change_context(Error)?;
|
||||
let appsink = AppSink::new("iced-video-sink")
|
||||
.change_context(Error)?
|
||||
.with_caps(
|
||||
Caps::builder(CapsType::Video)
|
||||
.field("format", "RGBA")
|
||||
.build(),
|
||||
);
|
||||
let video_sink = videoconvert.link(&appsink).change_context(Error)?;
|
||||
.with_drop(true);
|
||||
// .with_caps(
|
||||
// Caps::builder(CapsType::Video)
|
||||
// .field("format", "RGBA")
|
||||
// .build(),
|
||||
// );
|
||||
// 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);
|
||||
.with_buffer_duration(core::time::Duration::from_secs(2))
|
||||
.with_buffer_size(2000000)
|
||||
.with_video_sink(&appsink);
|
||||
let bus = playbin.bus().change_context(Error)?;
|
||||
playbin.pause().change_context(Error)?;
|
||||
let ready = Arc::new(AtomicBool::new(false));
|
||||
@@ -57,12 +60,8 @@ impl VideoSource {
|
||||
};
|
||||
{
|
||||
let mut guard = frame.lock().expect("BUG: Mutex poisoned");
|
||||
let old_sample = core::mem::replace(&mut *guard, sample);
|
||||
// dbg!(old_sample.caps());
|
||||
// dbg!(old_sample.inner.buffer_list());
|
||||
// drop(old_sample);
|
||||
core::mem::replace(&mut *guard, sample);
|
||||
ready.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
drop(guard);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -71,7 +70,7 @@ impl VideoSource {
|
||||
|
||||
Ok(Self {
|
||||
playbin,
|
||||
videoconvert,
|
||||
// videoconvert,
|
||||
appsink,
|
||||
bus,
|
||||
ready,
|
||||
|
||||
Reference in New Issue
Block a user