[Gstreamer] Missing AppSink in GirCore bindings
Description
In older GStreamer C# bindings, the AppSink class was available and allowed processing of video/audio frames directly in the client application — instead of relying solely on built-in sinks like autovideosink or autoaudiosink.
This was extremely useful for scenarios like:
- Real-time frame analysis for computer vision
- Custom rendering
- Integration with other libraries
Issue
In Gir.Core, the AppSink class appears to be missing. This limits the ability to capture and process buffers directly from the pipeline in .NET applications.
Example use case (from older bindings)
var appSink = new AppSink("app_sink")
{
Drop = true, // drop frames if cannot keep up
MaxLateness = (long)TimeSpan.FromSeconds(0.1).TotalNanoseconds, // maximum latency to achieve at least 30 fps
MaxBuffers = 1, // no buffering for video sink
Qos = true, // QoS for video sink
EnableLastSample = true, // no need for last sample as we are pulling samples
EmitSignals = true,
Sync = SyncForSinksEnabled // synchronized playback
};
appSink.NewSample += VideoSinkOnNewSample;
appSink.NewPreroll += VideoSinkOnNewPreroll;
_pipeline.Add(appSink);
private void VideoSinkOnNewSample(object o, NewSampleArgs args)
{
var appSink = (AppSink)o;
using (var sample = appSink.PullSample())
{
_eventSource.NotifyNewSample(sample);
}
}
private void VideoSinkOnNewPreroll(object o, NewPrerollArgs args)
{
var appSink = (AppSink)o;
var prerollSample = appSink.PullPreroll();
_eventSource.Info("Preroll frame received");
_eventSource.NotifyNewSample(prerollSample, true);
prerollSample.Dispose();
}
Can you check if it is part of one of this Gir files: https://github.com/gircore/gir-files/tree/main/linux
If not there is probably a gstreamer binding missing.
Hi,
Yes it's missing, in gstreamer it's actually in different file GstApp-1.0.gir, attaching it for reference. Does that mean another package should be generated? Also old library is binding AppSink methods to gstapp-1.0-0.dll.
Here is the file for reference: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/girs/GstApp-1.0.gir
Would that be difficult to add? Is that about adding one more project to Libs like GstApp-1.0 then adding GstApp-1.0.gir file, then running source code generator or some custom tuning is usually needed?
The first step is to get the gir file into https://github.com/gircore/gir-files . But this repo is fully automated. The gir files are extracted from msys2, brew, and GNOME Flatpak SDK.
The first step would be to find out where the gir files are hidden in those package registries. For linux it looks like there is a GstApp-1.0.gir inside the flatpak sdk. Do you know if GstApp is available for windows / mac? I could not find it on a first glance.
If this is known the equivalent to this PR must be done.
Hi, i tested gstreamer installation using MSYS2 on windows:
pacman -S \
mingw-w64-x86_64-pkg-config \
mingw-w64-x86_64-gobject-introspection \
mingw-w64-x86_64-libadwaita \
mingw-w64-x86_64-gtk4 \
mingw-w64-x86_64-gtk3 \
mingw-w64-x86_64-gstreamer \
mingw-w64-x86_64-gst-plugins-good \
mingw-w64-x86_64-gst-plugins-base \
mingw-w64-x86_64-gtksourceview5 \
mingw-w64-x86_64-libsecret \
mingw-w64-x86_64-librsvg
It looks like all these gir files are installed then, including GstApp:
So I think just need to add GstApp to gir_files.txt - created PR: https://github.com/gircore/gir-files/pull/210 (not sure how to test if it works though - Need to run pipelines for all platforms somehow)
I run the pipeline for Mac and it seems to work. The version in there looks like it is to new: https://github.com/gircore/gir-files/actions/runs/15929291654/job/44934247379
This is because we hold back packages from windows and mac to match Linux.
@jwharm what do you think do we simply take the new version and afterwards reduce the version number again?
GstAppSink didn't change between version 1.24 and 1.26, so it's safe to take the newer version. But you have to be careful not to upgrade the other GStreamer gir files together with it.
Appsink is a welcome addition for me too (example).
GstApp is now available in Gir-files.
I will update the gir files submodule shortly. @toomasz afterwards you could do the equivalent of https://github.com/gircore/gir.core/commit/9380c74d0f00402d3c0d9d67926bc2b71b993bd2
A nice to have thing would be a minimal sample that show that the bindings work in principle.
The GirCore repository can now access GstApp-1.0.gir file. A new project/nuget can be added.
PR created - https://github.com/gircore/gir.core/pull/1276 I would like to port this sample https://github.com/GStreamer/gstreamer-sharp/blob/master/samples/BasicTutorial8.cs but looks like #1275 is a blocker, some properties used to read frame data are missing (MapInfo.Data).
Also there are other problems:
- lack of Element.Link/Unlink override that accepts multiple Elements
- lack of [] operator for element for setting properties
- App Sink expects AppSinkHandle instead of string
- Gst.Buffer also expects BufferOwnedHandle instead of it's arguments
- Lack of some properties Will try to check those issues when I have time
The sample you mentioned is not a basic sample for me. It would be nice to have it working but I don't have the capacity to keep it updated.
But feel free to publish it under your name. We can link it if you want to.
Fixed with #1276.
If you want to improve the support even further please open a new issue.