I want to write an application to scan QR code, based on GNOME stack: GTK+, Gstreamer, Wayland.
I plan to use Gstreamer to stream webcam video and embed in a GTK+ app. I want this app to be pure Wayland. The problem is that there are so few documentation about letting Gstreamer put its display to an area of GTK window. There is one example about GStreamer + Wayland in gstreamer-plugins-bad repo, but it is in C. I want Python + GIR.
So, could you please give a working example for Python 3.8 + Gstreamer 1.16.2?
Hi.
If the example you mentioned is written using GI, then porting it can be quite easy. Just look at the function used and see it’s proper binding in PyGObject API Reference.
If you run into any trouble, please feel free to bring it up ^^
It is for a completely different purpose, but should give you an idea about how the streaming works. I don’t have a webcam, so I can’t quite involve here.
GDK does not expose Wayland introspection data because the underlying C types have no introspection data either.
You can do a hacky type check of the type of GdkDisplay using a string, e.g.:
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
display = Gdk.Display.get_default()
if 'GdkWaylandDisplay' in str(type(display)):
print('Yes')
else:
print('No')
will print Yes when run under Wayland, and No when run under other backends.
Actually, I deliberately want it to work with Wayland. There is already tutorial to make it with X Window System, but I want to make a native-Wayland app.
The transition from X to Wayland is too slow, so I want to create more and more Wayland apps to urge this transition.
That’s not what drives transitions; you don’t write “Wayland” apps, you just write applications. On Wayland you can deal with some fast paths, but you’ll also need to deal with the fact that they are not available to all languages—namely, it’s mostly C.
If you want to write a video player you should really use the GTK video widget available in GStreamer; it will try and use the most appropriate pipeline for the platform it’s running on—Wayland, Windows, X11, etc—and will also use the appropriate graphics pipeline to ensure you’re not performing excessive copies of the data in order to put it on the screen.
I also have examples in Rust but I don’t know if there are examples for Python somewhere.
Generally it all works the same though: you create the sink element like any other GStreamer element, via the "widget" property you can get a GtkWidget and that you would include in your UI then. Anything passed to the GStreamer sink would then be rendered inside that GtkWidget.