PDA

View Full Version : Including external header (gst.h)



Plox
15th October 2013, 11:48
Good day fellow programmers,

I am trying to include Gstreamer into my Qt application.
In order to do so I need to include "gst.h".

So far I've tried to simply add it to the main.cpp file.

#include <gst/gst.h>
I've also tried the direct file path:

#include "/usr/include/gstreamer-1.0/gst/gst.h"

I've also tried specifying an INCLUDEPATH in the .pro file:

INCLUDEPATH += /usr/include/gstreamer-1.0/gst
As this didn't work I tried to be a bit more specific:

unix:INCLUDEPATH += /usr/include/gstreamer-1.0/gst

During these tries I've been using the command in main.cpp
#include <gst/gst.h> but received the error all the time
/home/finn/GST_Test2/main.cpp:2: error: gst/gst.h: No such file or directory.

Besides that I also tried using PKGCONFIG:

unix {
CONFIG += link_pkgconfig
PKGCONFIG += gstreamer-1.0
}

According to this commands result gstreamer-1.0 exists on the target system.

pkg-config --list-all | grep gstreamer


However I always receive the error
:-1: error: Package gstreamer-1.0 not found

The target system is a Raspberry Pi running Linux Debian. I've been able to successfully build applications on that system which is why I would guess that the target system should not be the problem.

The file gst.h does exist on the target system in the directory /usr/include/gstreamer-1.0/gst

Does anyone has an idea how to properly include gst.h into my Qt project?
Thanks a lot!

Best regards,
Plox

stampede
15th October 2013, 12:51
INCLUDEPATH += /usr/include/gstreamer-1.0/gst
but you try to include the header with "gst/gst.h", compiler can't find it because probably there is no "gst" subdir in "/usr/include/gstreamer-1.0/gst" directory.
If the file path is "/usr/include/gstreamer-1.0/gst/gst.h" then you need to add "INCLUDEPATH += /usr/include/gstreamer-1.0/" and include with "gst/gst.h", or "INCLUDEPATH += /usr/include/gstreamer-1.0/gst" and include with #include <gst.h>

Plox
15th October 2013, 13:09
Thank you for your answer, stampede.

I modified said code lines.

This is the .pro file:

INCLUDEPATH += /usr/include/gstreamer-1.0/

And this is the main.cpp:

#include "gst/gst.h"

Sadly I am still getting the error:

/home/finn/GST_Test2/main.cpp:2: error: gst/gst.h: No such file or directory

Why does this error still occur?

Thanks a lot!

stampede
15th October 2013, 13:17
gstreamer-1.0 exists on the target system
By "target system" you mean the system on which you want to deploy your app, or the machine where you are trying to build the app ? I'm just confused about the term "target system".
This file should be present on the build machine. Does it exist on your computer (the one where you are developing the app) ?

Plox
15th October 2013, 13:36
I am developing my app on a desktop pc running Ubuntu for a Raspberry Pi running Debian.
The file I want to include only exists on the Raspberry.

Do I need to copy it onto the Ubuntu machine in order to use it, although it's functionality is only going to be used on the Raspberry?

stampede
15th October 2013, 13:40
Yes, your compiler needs to have access to all the headers and libraries in order to build your application. Make sure to install the gstreamer package in development version.

Plox
15th October 2013, 13:50
Allright, thanks a lot for your help, I greatly appreciate it!

One last question: What is the difference between the regular gstreamer version and dev version?

stampede
15th October 2013, 14:03
Regular version doesn't include headers required for developing applications using gstreamer, only shared libraries:
file list for regular libgstreamer (http://packages.ubuntu.com/raring/amd64/libgstreamer1.0-0/filelist)
file list for libgstreamer-dev (http://packages.ubuntu.com/raring/amd64/libgstreamer1.0-dev/filelist)

Plox
15th October 2013, 19:57
I am afraid that I'll need help in another matter regarding this development step too.

I've installed gstreamer on the Ubuntu machine, set the proper INCLUDEPATH and included gst.h into main.cpp.
A look into the file system confirms that gstreamer has been successfully installed as all header files seem to be present.

After resolving some issues regarding glib all dependencies seem to be sorted out, however I am experiencing an error as soon as I try to actually call functions from gst.h.

This is the error I receive:

undefined reference to 'gst_init'

As I am receiving this error for every gst.h function I reduced main.cpp to only include gst_init.

#include <QtCore/QCoreApplication>
#include <gst/gst.h>

int main(int argc, char *argv[]){
QCoreApplication a(argc, argv);

gst_init (NULL,NULL);
return a.exec();
}


The file gst.h is where it's supposed to be and based on the fact that Creator even suggests "gst_init" once I type e.g "gst" into main.cpp and since the function "gst_init" is underlayed with that typical grey box I think that gst.h has been successfully included into this project.

Why do I still receive such error messages?

Thanks a lot for your help!

stampede
15th October 2013, 20:11
"Undefined reference ..." is a linker error, you need to add library path and link to gst libraries, in .pro file:


LIBS += -L /path/to/gstreamer/libraries
LIBS += <gstreamer cflags>

I dont know what are the parameters exactly, try "pkg-config --cflags --libs gstreamer-1.0" to get the values.
btw. I think you will find some useful informations here (http://docs.gstreamer.com/pages/viewpage.action?pageId=327735)

Plox
15th October 2013, 20:27
That makes sense. This will be the first thing to be tried out tomorrow morning.

Thank you for your help, this really made my day.

Plox
16th October 2013, 10:27
It's me again..

I run the command you suggested to get the cflags and the libs.
This is the output:

finn@ubuntu:~$ pkg-config --libs gstreamer-1.0
-pthread -lgstreamer-1.0 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0


finn@ubuntu:~$ pkg-config --cflags gstreamer-1.0
-pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include

Including the cflags into the .pro file obviously isn't a problem but I can't find any of the files listed in the -libs output, even though I searched through the entire file system.
Searching for the listed files without "l" in front of them wasn't successfull either as I do find matching directories but no matching files.

If I run Qt with this .pro file:


(...)
INCLUDEPATH += /usr/include/gstreamer-1.0/
LIBS += -L -pthread -lgstreamer-1.0 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0
LIBS += -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include

I get the following output:

:-1: error: cannot find -lgobject-2.0
:-1: error: cannot find -lgmodule-2.0
:-1: error: cannot find -lgthread-2.0
:-1: error: cannot find -lglib-2.0


I am sure this is a pretty noobish question but this is the first time I am actually working with the .pro file and this is driving me nuts.

Thank you!

stampede
16th October 2013, 10:52
For example, if you want to link to a library "/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so", you should do:


LIBS += -lgstreamer-1.0
LIBS += -L/usr/lib/x86_64-linux-gnu/

So if you are looking for a library named "gthread-2.0" try to search for a file "libgthread-2.0.so" etc...

There are many resources about using shared libraries, for example this one (http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html)
Try to do some research if you are not sure what those "-L , -I, -l, ..." really mean.

myta212
17th October 2013, 05:55
Hi Plox,
Your problem related with you dont give the right path for your "include" and "library" file.
If you have an experienced about Makefile, I think you will not get a problem when using "pro" file.

I am try to get gst library from here http://docs.gstreamer.com/display/GstSDK/Installing+on+Linux
Are you have all required gst library ? If not, try to check the above link.

I am try your code and setting my pro file like this :


QT += core

QT -= gui

TARGET = tesgst
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app
INCLUDEPATH += /usr/include/gstreamer-0.10/ \
/usr/include/glib-2.0/ \
/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \
/usr/include/libxml2/
LIBS += `pkg-config --cflags --libs gstreamer-0.10`

SOURCES += main.cpp

You only need to look at "INCLUDEPATH" and "LIBS" part (ignore the other part).
The INCLUDEPATH maybe different with the other linux version. So, please check at your error message when compiling your program.
That error maybe related with "you dont have" or "you dont setting the right path".
You can use "find", "locate" or the other command to get the right path for you.

I have success to compile your program using this setting with my Ubuntu 12.04.
Best regards,

Toto

Plox
17th October 2013, 18:37
The integration of gst.h now works like a charm.
Thank you so much!
This brought me a looooog way!

I am now able to compile and run this (http://developer.nokia.com/Community/Wiki/How_to_use_gstreamer_with_Qt) code.
However I am experiencing performance issues which indicates that playbin is not using hardware acceleration althought gst-omx is installed on the RPi.

According to this (http://docs.gstreamer.com/display/GstSDK/Playback+tutorial+8%3A+Hardware-accelerated+video+decoding) guide all I need to do is change the rank of the plugin which is doing the hw acceleration.

However if I try to combine this ( http://docs.gstreamer.com/pages/viewpage.action?pageId=327735"] (http://docs.gstreamer.com/pages/viewpage.action?pageId=327735) ) and this (http://docs.gstreamer.com/display/GstSDK/Playback+tutorial+8%3A+Hardware-accelerated+video+decoding) code I receive the following output:


** (GTK_Test_RPI:6770): WARNING **: Command line `dbus-launch --autolaunch=34069147acf8a24283639d4a51f267a2 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n

** (GTK_Test_RPI:6770): WARNING **: Command line `dbus-launch --autolaunch=34069147acf8a24283639d4a51f267a2 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n

** (GTK_Test_RPI:6770): WARNING **: Command line `dbus-launch --autolaunch=34069147acf8a24283639d4a51f267a2 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n

** (GTK_Test_RPI:6770): WARNING **: Command line `dbus-launch --autolaunch=34069147acf8a24283639d4a51f267a2 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n

** (GTK_Test_RPI:6770): WARNING **: Command line `dbus-launch --autolaunch=34069147acf8a24283639d4a51f267a2 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
xcb_connection_has_error() returned true
xcb_connection_has_error() returned true
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started

** (GTK_Test_RPI:6770): WARNING **: Too old frames, bug in decoder -- please file a bug

This is the code I run:

#include <gst/gst.h>


static void enable_factory (const gchar *name, gboolean enable) {

g_type_init ();

GstRegistry *registry = NULL;
GstElementFactory *factory = NULL;

registry = gst_registry_get ();
if (!registry) return;

factory = gst_element_factory_find (name);
if (!factory) return;

if (enable) {
gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory), GST_RANK_PRIMARY + 1);
}
else {
gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory), GST_RANK_NONE);
}

gst_registry_add_feature (registry, GST_PLUGIN_FEATURE (factory));
return;
}


int main(int argc, char *argv[]) {

GstElement *pipeline;
GstBus *bus;
GstMessage *msg;


enable_factory("omxmpeg2videodec", true);

/* Initialize GStreamer */
gst_init (&argc, &argv);

/* Build the pipeline */
pipeline = gst_parse_launch ("playbin uri=http://192.168.178.51:8001", NULL);

/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);

/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));

/* Free resources */
if (msg != NULL)
gst_message_unref (msg);
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}


Edit:
And this is the interesting part of the .pro file:



INCLUDEPATH += /opt/rpi/sysroot/usr/include/gstreamer-1.0
LIBS += -lglib-2.0 -lpthread -lgstreamer-1.0 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt
LIBS += -L/opt/rpi/sysroot/lib/arm-linux-gnueabihf/ -L/opt/rpi/sysroot/usr/lib/arm-linux-gnueabihf/



The error output is exactly the same as if I would run the main function without trying to increase the decoders rank.



Edited because of a moronic mistake.

paul_espinosa_pi
25th December 2014, 21:33
hello i had the same problem
i am triying with gstreamer but i installed precompiled version …of this page
https://wiki.matthiasbock.net/index.php/Hardware-accelerated_video_playback_on_the_Raspberry_Pi#gst reamer
i run some examples in the console but i need to add to qt 4 …to play misic with gstreamer
my file.pro
INCLUDE PATH += /usr/lib/arm-linux-gnueabiht/gstreamer-1.0
LIBS += -L/ /usr/lib/arm-linux-gnueabiht/gstreamer-1.0
LIBS += -lglib-2.0 -lpthread -lgstreamer-1.0 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt
and in the main.cpp
#include <gst/gst.h>
but show this error gst/gst.h no such file or directory
how i can writhe or use correctly this libs ????
i need play mp3 in my raspberry in an aplicacion