Getting QtGstreamer work over Windows
Nikos Chantziaras
realnc at gmail.com
Thu Mar 5 08:03:36 PST 2015
On 04/03/15 20:16, maxilase wrote:
> I saw on some post that a few people managed to make QtGst work on Windows
> however the didn't described their procedure.
>
> Can anyone help me about it ?
Not a direct answer to your question, but I was in a similar situation.
In the end, I simply used gstreamer directly instead of going through
QtGStreamer. I had it working perfectly on Linux, but on Windows I never
got it working. GStreamer is a C API, so you can use it directly inside
your C++ code without issues.
If you want to go down that route, you need to make sure that gstreamer
is able to dispatch messages. For that to happen, you need to start a
glib event loop. You can do that in a glib thread. The code for that is
very simple. First have a GThread function where you will start a glib
event loop:
GMainLoop* gloop = 0;
GThread* gthread = 0;
extern "C" {
static gpointer glibMainLoopThreadFunc(gpointer)
{
gloop = g_main_loop_new(0, false);
g_main_loop_run(gloop);
g_main_loop_unref(gloop);
gloop = 0;
return 0;
}
} // extern "C"
Then simply start that function in a GThread:
// If the version of Qt we're running in does not use GLib, we need to
// start a GMainLoop so that gstreamer can dispatch events.
const QMetaObject* mo =
QAbstractEventDispatcher::instance(hApp->thread())->metaObject();
if (gloop == 0
&& strcmp(mo->className(), "QEventDispatcherGlib") != 0
&& strcmp(mo->superClass()->className(),"QEventDispatcherGlib")!=0)
{
gthread = g_thread_new(0, glibMainLoopThreadFunc, 0);
}
You don't *need* the check for Qt glib support, but this will keep your
code portable to Linux, where Qt is using a glib event loop and thus
there's no need to start your own.
Note that the messages coming from gstreamer will be delivered from that
thread. So if you need to call into GUI code from there, you need to use
signals and slots or issue QMetaObject::invokeMethod() calls on slots.
In my code, I use the latter and the connection type is decided on
whether I started my own GMainLoop or not:
Qt::ConnectionType conType = gloop ?
Qt::BlockingQueuedConnection
: Qt::DirectConnection;
// ...
QMetaObject::invokeMethod(widget, "someSlotFunction");
More information about the gstreamer-devel
mailing list