feat: Add keybinds to minimal example

This commit is contained in:
uttarayan21
2025-12-25 21:43:55 +05:30
parent a2491695b3
commit 4ed15c97f0
13 changed files with 156 additions and 113 deletions

View File

@@ -8,6 +8,7 @@ pub mod pipeline;
pub mod plugins;
#[macro_use]
pub mod wrapper;
pub mod sample;
pub use bin::*;
pub use bus::*;
@@ -19,6 +20,7 @@ pub use gstreamer::{Message, MessageType, MessageView, State};
pub use pad::*;
pub use pipeline::*;
pub use plugins::*;
pub use sample::*;
pub(crate) mod priv_prelude {
pub use crate::errors::*;

View File

@@ -60,6 +60,15 @@ impl Pipeline {
Ok(())
}
#[track_caller]
pub fn stop(&self) -> Result<()> {
self.inner
.set_state(gstreamer::State::Null)
.change_context(Error)
.attach("Failed to set pipeline to Null state")?;
Ok(())
}
#[track_caller]
pub fn set_state(&self, state: gstreamer::State) -> Result<gstreamer::StateChangeSuccess> {
let result = self
@@ -165,6 +174,12 @@ pub trait PipelineExt: ChildOf<Pipeline> + Sync {
fn ready(&self) -> Result<()> {
self.upcast_ref().ready()
}
#[track_caller]
fn stop(&self) -> Result<()> {
self.upcast_ref().stop()
}
#[track_caller]
fn set_state(&self, state: gstreamer::State) -> Result<gstreamer::StateChangeSuccess> {
self.upcast_ref().set_state(state)

View File

@@ -25,41 +25,41 @@ impl AppSink {
Ok(AppSink { inner })
}
pub fn with_emit_signals(self, emit: bool) -> Self {
pub fn emit_signals(&mut self, emit: bool) -> &mut Self {
self.inner.set_property("emit-signals", emit);
self
}
pub fn with_async(self, async_: bool) -> Self {
pub fn async_(&mut self, async_: bool) -> &mut Self {
self.inner.set_property("async", async_);
self
}
pub fn with_sync(self, sync: bool) -> Self {
pub fn sync(&mut self, sync: bool) -> &mut Self {
self.inner.set_property("sync", sync);
self
}
pub fn with_drop(self, drop: bool) -> Self {
pub fn drop(&mut self, drop: bool) -> &mut Self {
self.inner.set_property("drop", drop);
self
}
pub fn with_caps(self, caps: Caps) -> Self {
pub fn caps(&mut self, caps: Caps) -> &mut Self {
self.inner.set_property("caps", caps.inner);
self
}
pub fn with_callbacks(self, callbacks: gstreamer_app::AppSinkCallbacks) -> Self {
pub fn callbacks(&mut self, callbacks: gstreamer_app::AppSinkCallbacks) -> &mut Self {
self.appsink().set_callbacks(callbacks);
self
}
pub fn on_new_frame<F>(self, mut f: F) -> Self
pub fn on_new_frame<F>(&mut self, mut f: F) -> &mut Self
where
F: FnMut(&AppSink) -> Result<(), gstreamer::FlowError> + Send + 'static,
{
self.with_emit_signals(true).with_callbacks(
self.emit_signals(true).callbacks(
AppSinkCallbacks::builder()
.new_sample(move |appsink| {
use glib::object::Cast;
@@ -109,44 +109,6 @@ impl AppSink {
}
}
impl From<gstreamer::Sample> for Sample {
fn from(inner: gstreamer::Sample) -> Self {
Sample { inner }
}
}
#[repr(transparent)]
#[derive(Debug, Clone)]
pub struct Sample {
pub inner: gstreamer::Sample,
}
use gstreamer::BufferRef;
impl Sample {
#[doc(alias = "empty")]
pub fn new() -> Self {
Self {
inner: gstreamer::Sample::builder().build(),
}
}
pub fn buffer(&self) -> Option<&BufferRef> {
self.inner.buffer()
}
pub fn caps(&self) -> Option<&gstreamer::CapsRef> {
self.inner.caps()
}
pub fn info(&self) -> Option<&gstreamer::StructureRef> {
self.inner.info()
}
// pub fn set_buffer(&mut self) {
// self.inner.set_buffer(None);
// }
}
#[test]
fn test_appsink() {
use gstreamer::prelude::*;
@@ -164,13 +126,12 @@ fn test_appsink() {
let video_convert = plugins::videoconvertscale::VideoConvert::new("vcvcvcvcvcvcvcvcvcvcvcvcvc")
.expect("Create videoconvert");
let appsink = app::AppSink::new("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
.expect("Create appsink")
.with_caps(
Caps::builder(CapsType::Video)
.field("format", "RGB")
.build(),
);
let mut appsink = app::AppSink::new("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").expect("Create appsink");
appsink.caps(
Caps::builder(CapsType::Video)
.field("format", "RGB")
.build(),
);
let mut video_sink = video_convert
.link(&appsink)

View File

@@ -1,2 +1,4 @@
pub mod playbin3;
pub use playbin3::*;
pub mod playbin;
pub use playbin::*;

View File

@@ -43,6 +43,12 @@ impl Playbin3 {
self
}
/// Sets the maximum size of the ring buffer in bytes.
pub fn with_ring_buffer_max_size(self, size: u64) -> Self {
self.inner.set_property("ring-buffer-max-size", size);
self
}
pub fn with_video_sink(self, video_sink: &impl ChildOf<Element>) -> Self {
self.inner
.set_property("video-sink", &video_sink.upcast_ref().inner);