Display Gstreamer video on Android
-
Sorry, I don't have an example by hand but based on the QtMultimedia sources, the first thing I'd do is get gstreamer for Android and then I'd modify the plugins.pro file and add the gstreamer subdir to the list in the android scope.
-
The QtGstreamer module is on a lower-level. It essentially provides you a nice Qt API to build your GStreamer pipelines and a set of video sync for QtWidgets and QtQuick.
-
It should run on the same platforms as Qt as long as you can satisfy its dependencies.
I'd first try to build the backend. It will likely be less work.
-
@SGaist understood. Thanks for the explanations. About backend:
I need download GStreamer for Android(this I already did, right?), create plugins.pro file in the my project(I don't know even what is it, but I will read) and add GStreamer dir to the list in the android scope(don't heard about this too). Is it all what I need? -
No, you have to build the plugin from the sources and then install them
-
@SGaist can you share the link which describes what I need to do? Or some additional reading? I'm sorry but I really don't understand a lot of things. Where I need to set a plugins.pro? What I need to set within it? About which plugin are you said? How and where I need to install it? How connect GStreamer to all these things?
-
You don't need to create any file. You have to first get the sources of the QtMultimedia module.
There you'll find the plugins folder with the matching plugins.pro file
-
Hi don-prog!
I've had the same issue as you...displaying a GStreamer video on Android within a Qt application!
It was a hard way to find out how to get it alltogether work and it took me a long time! I wasn't able to find really useful hints about this issue.First I also tried it with QtGStreamer, but I didn't get it work for Android. After trying and trying and trying (...) I decided to look for another way to go. By the way - for Linux the QtGStreamer worked like a charm.
As you can see at this link (https://wiki.qt.io/Qt_5.5.0_Multimedia_Backends) the multimedia backend of Qt uses different multimedia frameworks on different platforms --> GStreamer is only used for Linux and I think this decision wasn't made causeless! I don't think it will be so easy to get the Qt's GStreamer-Backend to work for Android since a Qt application for Android comes with partial other characteristics than a Qt application for Linux. That's based in the differences between the dissimilar windowing-systems of Android and Desktop-Linux.
If you display some patience I'll show you how I did it?
Greetz, Lukas
-
Hi and welcome to devnet,
@LuJoRi Indeed it wasn't mad causeless because Qt uses as much as possible native frameworks.
If I understand you correctly you successfully used GStreamer on Android with Qt to do video rendering ?
-
@SGaist, yes exactly! It was one of my core topics of my master thesis which I'll finally release after the weekend :)
@don-prog, @SGaist, are you interested in my solution? It will take some time for me to explain you in english since it isn't my first language (it's german).A few quick hints:
-
you should look for a surface of the Java/Android-API and get the pointer on it via ANativeWindow_fromSurface(...) --> so you can handle the surface's display area within C++/Qt
-
with this pointer you are able to use the standard GStreamer way to render a video in a specific display area.
Your function call was:
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(video_sink), this->ui->playback_widget->winId());
--> you have to use the pointer on the native window instead of winId()...the winId() function returns useful values on Linux but not on Android!
-
-
@don-prog Sure thing !
That may avoid @don-prog some pain.
@don-prog you would need to add
gstreamer
to SUBDIRS. It's the name of the plugin dir. However, AFAIK, that plugin uses pkg-config to find gstreamer's library/includes so it may be problematic. You would have to put the the paths yourself in there. -
@LuJoRi many thanks for your support and experience! I am very interested in your solution because I already thought about some way like yours, but I have some misunderstandings:
How can I use ANativeWindow_fromSurface() from Qt and with which arguments? -
@don-prog you have to do function calls from C++/Qt to Java/Android-API via JNI. Look for QAndroidJniObject (http://doc.qt.io/qt-5/qandroidjniobject.html) --> that's a way to create instances of classes of the Java/Android-API. Furthermore you can call their methods - for example via
QAndroidJniObject::callObjectMethod(const char *methodName, const char *signature, ... )
That means that you first have to manage a Java surface object will be created. You do this via JNI. Then you can put this one as an argument to the ANativeWindow_fromSurface function.
-
@don-prog
The first agrument requires something like a pointer on the Java environment which is needed because on Android even a Qt application is based on a JVM respectively ART (Android Runtime).
The second one is the C++/Qt handle of the Java surface. Once you've retrieved it after your JNI calls, you can cast it to jobject type and then put it to the ANativeWindow_fromSurface function :)Unfortunately I'm short of time the next days (till sunday). Regardless I'd really like to help you! Feel free to ask if there are any questions :)