- Go 99%
- Makefile 1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
|
||
| docs | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| .woodpecker.yml | ||
| appsink.go | ||
| bus.go | ||
| eos_test.go | ||
| gerror.go | ||
| go.mod | ||
| go.sum | ||
| gst.go | ||
| gst_test.go | ||
| library.go | ||
| LICENSE | ||
| loader_unix.go | ||
| loader_windows.go | ||
| Makefile | ||
| pipeline.go | ||
| property.go | ||
| property_test.go | ||
| query.go | ||
| query_test.go | ||
| README.md | ||
| state_test.go | ||
gst-purego
A cgo-free binding for GStreamer, loaded at run time with purego, in the same spirit as gtk4-purego.
The binding is deliberately small: it covers building a pipeline from its
description, driving its state, reading its bus, moving the cursor, reading
properties, and pulling decoded samples from an appsink — not every GStreamer
API. docs/DESIGN.md lists the functions that are in scope and the decisions
behind them.
gst.Init()
pipeline, err := gst.ParseLaunch("pipewiresrc ! audioconvert ! opusenc ! oggmux ! filesink location=note.ogg")
if err != nil {
return err
}
defer pipeline.Close()
if err := pipeline.SetState(gst.StatePlaying); err != nil {
return err
}
defer pipeline.SetState(gst.StateNull)
Rules
- No cgo.
CGO_ENABLED=0is pinned by the Makefile; the library is opened withpurego.Dlopenand its symbols are resolved lazily. - A missing library is not a crash.
gst.Available()reports whether GStreamer could be loaded; a caller that only plays media keeps working without it. - One C function, one Go function. No clever wrapper layers: the generated and hand-written names mirror the C ones, like the GTK binding does.
- Nothing here knows about GTK. The pipeline is a string built by the caller; this package returns errors, it does not open dialogs.
- No build tag, no plugin. GStreamer plugins are loaded by GStreamer itself; the binding never guesses which ones are installed.
Platforms
The libraries are opened at run time, so the same Go binary works wherever GStreamer is installed. The shared objects do not have the same name everywhere, and the loader tries them in this order:
| system | library | where |
|---|---|---|
| Linux | libgstreamer-1.0.so.0 |
the distribution path |
| macOS | libgstreamer-1.0.0.dylib |
DYLD_* paths, then /opt/homebrew/lib, /usr/local/lib, /Library/Frameworks/GStreamer.framework/Versions/1.0/lib |
| Windows | gstreamer-1.0-0.dll |
the executable directory and PATH |
libgstapp (the appsink) and libgobject (the properties) follow the same
pattern: libgstapp-1.0.so.0 / libgstapp-1.0.0.dylib / gstapp-1.0-0.dll, and
libgobject-2.0.so.0 / libgobject-2.0.0.dylib / gobject-2.0-0.dll.
- Windows: install the MSVC runtime package and add
C:\gstreamer\1.0\msvc_x86_64\bintoPATH. GStreamer finds its plugins relative togstreamer-1.0-0.dll, so the installation layout must be kept. - macOS:
brew install gstreameris enough; the official.pkginstalls a framework, which is also found. With a Homebrew prefix of your own, setDYLD_FALLBACK_LIBRARY_PATHto itslibdirectory. - Linux: only the runtime package is needed. The
-develpackage brings the unversioned.sosymlink, which is a fallback, not a requirement.
Build and test
make check # build, vet, lint, tests
make test # tests only: they skip when libgstreamer is absent
The tests need gstreamer1 and a couple of plugins
(gst-plugins-base, gst-plugins-good, gst-plugins-bad for opusenc):
sudo dnf install gstreamer1 gstreamer1-plugins-base gstreamer1-plugins-good \
gstreamer1-plugins-bad-free
Related projects
gtk4-purego is the GTK4 binding this
project is modelled on. The two divide the work: gtk4-purego owns the window
and its widgets, gst-purego runs the pipeline, and neither imports the other.
An application that needs both depends on both and keeps the rendering between
them — for example by pulling samples from an appsink.
Licence
MIT, like the GTK binding.