mirror of
				https://github.com/slint-ui/slint.git
				synced 2025-11-03 21:24:17 +00:00 
			
		
		
		
	GStreamer example: move video sink setup to a submodule
This makes it easier to reuse in a larger application.
This commit is contained in:
		
							parent
							
								
									78c47bbb27
								
							
						
					
					
						commit
						2d6a9c65d3
					
				
					 4 changed files with 27 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -6,10 +6,7 @@ slint::include_modules!();
 | 
			
		|||
use futures::stream::StreamExt;
 | 
			
		||||
use gst::{prelude::*, MessageView};
 | 
			
		||||
 | 
			
		||||
#[cfg(slint_gstreamer_egl)]
 | 
			
		||||
mod egl_integration;
 | 
			
		||||
#[cfg(not(slint_gstreamer_egl))]
 | 
			
		||||
mod software_rendering;
 | 
			
		||||
mod slint_video_sink;
 | 
			
		||||
 | 
			
		||||
fn main() -> anyhow::Result<()> {
 | 
			
		||||
    slint::BackendSelector::new()
 | 
			
		||||
| 
						 | 
				
			
			@ -28,10 +25,6 @@ fn main() -> anyhow::Result<()> {
 | 
			
		|||
        .downcast::<gst::Pipeline>()
 | 
			
		||||
        .unwrap();
 | 
			
		||||
 | 
			
		||||
    let new_frame_callback = |app: App, new_frame| {
 | 
			
		||||
        app.set_video_frame(new_frame);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Handle messages from the GStreamer pipeline bus.
 | 
			
		||||
    // For most GStreamer objects with buses, you can use `while let Some(msg) = bus.next().await`
 | 
			
		||||
    // inside an async closure passed to `slint::spawn_local` to read messages from the bus.
 | 
			
		||||
| 
						 | 
				
			
			@ -73,10 +66,7 @@ fn main() -> anyhow::Result<()> {
 | 
			
		|||
    })
 | 
			
		||||
    .unwrap();
 | 
			
		||||
 | 
			
		||||
    #[cfg(not(slint_gstreamer_egl))]
 | 
			
		||||
    software_rendering::init(&app, &pipeline, new_frame_callback, bus_sender)?;
 | 
			
		||||
    #[cfg(slint_gstreamer_egl)]
 | 
			
		||||
    egl_integration::init(&app, &pipeline, new_frame_callback, bus_sender)?;
 | 
			
		||||
    slint_video_sink::init(&app, &pipeline, bus_sender)?;
 | 
			
		||||
 | 
			
		||||
    let pipeline_weak_for_callback = pipeline.downgrade();
 | 
			
		||||
    app.on_toggle_pause_play(move || {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										25
									
								
								examples/gstreamer-player/slint_video_sink/mod.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								examples/gstreamer-player/slint_video_sink/mod.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
 | 
			
		||||
// SPDX-License-Identifier: MIT
 | 
			
		||||
 | 
			
		||||
use crate::App;
 | 
			
		||||
use futures::channel::mpsc::UnboundedSender;
 | 
			
		||||
 | 
			
		||||
#[cfg(slint_gstreamer_egl)]
 | 
			
		||||
mod egl_integration;
 | 
			
		||||
#[cfg(not(slint_gstreamer_egl))]
 | 
			
		||||
mod software_rendering;
 | 
			
		||||
 | 
			
		||||
pub fn init(
 | 
			
		||||
    app: &App,
 | 
			
		||||
    pipeline: &gst::Pipeline,
 | 
			
		||||
    bus_sender: UnboundedSender<gst::Message>,
 | 
			
		||||
) -> anyhow::Result<()> {
 | 
			
		||||
    let new_frame_callback = |app: App, new_frame| {
 | 
			
		||||
        app.set_video_frame(new_frame);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    #[cfg(not(slint_gstreamer_egl))]
 | 
			
		||||
    return software_rendering::init(app, pipeline, new_frame_callback, bus_sender);
 | 
			
		||||
    #[cfg(slint_gstreamer_egl)]
 | 
			
		||||
    return egl_integration::init(app, pipeline, new_frame_callback, bus_sender);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue