mirror of
https://github.com/BetterCorp/BetterFrame.git
synced 2026-05-26 23:26:34 +00:00
fix: stop old pipelines before re-render to prevent buffer overload
This commit is contained in:
parent
374a2e091b
commit
3a8fd70528
1 changed files with 20 additions and 4 deletions
|
|
@ -2,6 +2,10 @@ use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
|
||||||
|
thread_local! {
|
||||||
|
static ACTIVE_PIPELINES: RefCell<Vec<gstreamer::Pipeline>> = RefCell::new(Vec::new());
|
||||||
|
}
|
||||||
|
|
||||||
use gtk4::prelude::*;
|
use gtk4::prelude::*;
|
||||||
use gtk4::{self as gtk, Application, ApplicationWindow, Box as GtkBox, Grid, Label, Orientation, Picture};
|
use gtk4::{self as gtk, Application, ApplicationWindow, Box as GtkBox, Grid, Label, Orientation, Picture};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
@ -138,6 +142,16 @@ fn show_pairing_code(window: &ApplicationWindow, code: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_bundle(window: &ApplicationWindow, bundle: KioskBundle) {
|
fn render_bundle(window: &ApplicationWindow, bundle: KioskBundle) {
|
||||||
|
// Stop and clear any existing pipelines BEFORE building the new layout
|
||||||
|
ACTIVE_PIPELINES.with(|p| {
|
||||||
|
let mut pipes = p.borrow_mut();
|
||||||
|
info!("stopping {} active pipelines before re-render", pipes.len());
|
||||||
|
for pipe in pipes.iter() {
|
||||||
|
pipeline::stop(pipe);
|
||||||
|
}
|
||||||
|
pipes.clear();
|
||||||
|
});
|
||||||
|
|
||||||
let layout = bundle.layouts.iter()
|
let layout = bundle.layouts.iter()
|
||||||
.find(|l| l.is_default)
|
.find(|l| l.is_default)
|
||||||
.or_else(|| bundle.layouts.first());
|
.or_else(|| bundle.layouts.first());
|
||||||
|
|
@ -223,10 +237,12 @@ fn render_bundle(window: &ApplicationWindow, bundle: KioskBundle) {
|
||||||
|
|
||||||
window.set_child(Some(&grid));
|
window.set_child(Some(&grid));
|
||||||
|
|
||||||
let pipelines_ref = pipelines.clone();
|
// Move newly-created pipelines into the global registry so we can stop
|
||||||
window.connect_destroy(move |_| {
|
// them on the next reload-bundle
|
||||||
for pipe in pipelines_ref.borrow().iter() {
|
ACTIVE_PIPELINES.with(|p| {
|
||||||
pipeline::stop(pipe);
|
let mut global = p.borrow_mut();
|
||||||
|
for pipe in pipelines.borrow().iter() {
|
||||||
|
global.push(pipe.clone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue