Gstreamer 1.10 Cross Compiling

This guide is intended for Raspberry Pi 3B.

0. The Motive

Gstreamer on the package list of Rasbian is 1.4.4 currently, and does not support GRAY16 for some reason. It works fine on Ubuntu based version where the packaged is updated to 1.10.0.

Therefore, building from source is required to support GRAY16 on Raspberry Pi.

1. Set Up Directories

Firstly we need gstreamer source codes, Raspbian root directories (can be simply copy paste) as well as gcc cross compile toolchains.

Gstreamer Source Code

Put them in a convenient folder, say /opt/repos/gstsrc/

> git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer
> git clone git://anongit.freedesktop.org/git/gstreamer/orc
> git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-base
> git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-good
> git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-bad
> git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-ugly
> git clone git://anongit.freedesktop.org/git/gstreamer/gst-libav
> git clone git://anongit.freedesktop.org/git/gstreamer/gst-omx
From: https://lists.freedesktop.org/archives/gstreamer-openmax/2013-March/000724.html 

Remember to git checkout to the latest stable versions for every repositories, to reduce nasty dependency issues.

Raspbian Root Directories

Copy essntial root directories from a running raspberry pi to Ubuntu PC. The command below should put the directories under /opt/piroot/

> rsync -raz --delete-after –info=progress2 --safe-links \
    pi@:/{lib,usr,opt,etc} piroot

Notice:

  • The command should be re-excecuted when new pacakges and dependencies are installed.
  • plugins packages requires installation of gstreamer, base, orc to function. Make sure the packages are present in the piroot/ folder before compiling from the source

Toolchain (arm-linux-gnueabihf-)

We are using the gcc tools under ./arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin

> git clone https://github.com/raspberrypi/tools.git --depth=1 pitools

Installed Folder (symlink optional)

To make ‘make install’ virtually installs to the piroot directories, the symbolic link can be set up shown below:

> sudo ln -s /opt/piroot/opt/gst-installed/ ./gst-installed

2. General Dependencies

libtool, gtk-doc, glib-2.0 (libglib2.0-dev), gobject-2.0 (included with glib)
might be needed: libgstreamer....

3. Compile ‘gstreamer’

Now you should have /opt/piroot, /opt/tools, /opt/repos/gstsrc.

edit ~/.bashrc (or maybe ~/.profile if necessary) to add path to your arm cross gcc, so the program can find the gcc and ld anywhere:

> export PATH=$PATH:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin

Under /opt/repos/gstsrc/gstreamer, edit autogen.sh to restrict compiler to only access source codes and libraries in Rasbian root, not the live machine root:

#///////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////
# added definition for cross compiling for pi
SYSROOT=/opt/piroot # simulated pi system directory
CROSS_COMPILER=arm-linux-gnueabihf # name of CC, the host environment
CROSS_PATH=/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin # location of CC toolchain (download from git directly)
PREFIX=/opt/gst-installed # final installation location
CONFIGURE_ADDON="--build=i686-pc-linux-gnu --host=${CROSS_COMPILER} --prefix=${PREFIX} --with-sysroot=${SYSROOT} \
 --with-package-origin=RPi3-Version PKG_CONFIG=/usr/bin/arm-linux-gnueabihf-pkg-config LIBS=-lpcre" # pkg-config is outside the sysroot, so must be specified separately

echo 
echo "Current PATH=${PATH}"
echo 

export LDFLAGS="--sysroot ${SYSROOT}"

export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig" # Don't mix up .pc files from your host and build target
#PKG_CONFIG_LIBDIR see http://ilgthegeek.old.livius.net/2015/02/05/pkg-config-search-path/
#pkg-config --list-all
#///////////////////////////////////////////////////////////////////////////
CONFIGURE_DEF_OPT="${CONFIGURE_ADDON} --enable-maintainer-mode --disable-tests --disable-examples" #--enable-gtk-doc removed
#///////////////////////////////////////////////////////////////////////////

Remarks:

  • LIBS=-lpcre is added to solve some dependency issues on some packages
  • LDFLAGS
  • PKG_CONFIG points to the excutable on the compiling machine, outside the sysroot
  • PKG_CONFIG_PATH is cleared to ensure no configs are refered to ouside the piroot/ target sysroot
  • PKG_CONFIG_LIBDIR is then added, with : separation to tell the linker and compiler where to find the pkgconfig info from. Make sure they are all within sysroot
  • –prefix= is the installation folder. Do not put in the home folder as it varies from pc to pc
  • –disable-tests –disable-examples are used to speed up compilation

If all the directory setting are tuned correct, the following 3 commands will not generate errors:

> ./autogen.sh # turn off tests and examples
> make
> make install

If you want to make the install into .deb pacakge, try

> make uninstall
> checkinstall -D --install=no
(sudo is not necesssary if permissions of the target folder is set correctly)
(use architecture = armhf)

3. Compile ‘orc’

For ./autogen.h

#///////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////
# added definition for cross compiling for pi
SYSROOT=/opt/piroot # simulated pi system directory
CROSS_COMPILER=arm-linux-gnueabihf # name of CC, the host environment
CROSS_PATH=/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin # location of CC toolchain (download from git directly)
PREFIX=/opt/gst-installed 
 # final installation location
CONFIGURE_ADDON="--host=${CROSS_COMPILER} --target=${CROSS_COMPILER} --prefix=${PREFIX} --with-sysroot=${SYSROOT} \
 PKG_CONFIG=/usr/bin/arm-linux-gnueabihf-pkg-config " # pkg-config is outside the sysroot, so must be specified separately

echo 
echo "Current PATH=${PATH}"
echo 

export LDFLAGS="--sysroot ${SYSROOT}"
export CPPFLAGS="-I${SYSROOT}/usr/include -I${SYSROOT}/usr/include/arm-linux-gnueabihf" # this is needed for some libirary like stdlib-bsearch.h
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig/":"${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig" # Don't mix up .pc files from your host and build target


#///////////////////////////////////////////////////////////////////////////
CONFIGURE_DEF_OPT="${CONFIGURE_ADDON} --disable-static --enable-maintainer-mode" #--enable-gtk-doc removed
#///////////////////////////////////////////////////////////////////////////

Remarks:

  • LIBS=-lpcre is not required

4. Compiling ‘gst-plugins-base’

#///////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////
# added definition for cross compiling for pi
SYSROOT=/opt/piroot # simulated pi system directory
CROSS_COMPILER=arm-linux-gnueabihf # name of CC, the host environment
CROSS_PATH=/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin # location of CC toolchain (download from git directly)
PREFIX=/opt/gst-installed # final installation location
CONFIGURE_ADDON="--build=i686-pc-linux-gnu --host=${CROSS_COMPILER} --prefix=${PREFIX} --with-sysroot=${SYSROOT} \
 --with-package-origin=RPi3-Version PKG_CONFIG=/usr/bin/arm-linux-gnueabihf-pkg-config \
 LIBS=-lpcre " # pkg-config is outside the sysroot, so must be specified separately

echo 
echo "Current PATH=${PATH}"
echo 

export LDFLAGS="--sysroot ${SYSROOT}"

# to include pkgconfig in custom folders
export CPPFLAGS="-I${SYSROOT}/usr/include -I${SYSROOT}/usr/include/arm-linux-gnueabihf \
 -I${PREFIX}/include/orc-0.4" # this is needed for some libirary like stdlib-bsearch.h
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig/":"${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig" # Don't mix up .pc files from your host and build target
#${PREFIX}/lib/pkgconfig/ is needed in addtion compared to gstreamer
#PKG_CONFIG_LIBDIR see http://ilgthegeek.old.livius.net/2015/02/05/pkg-config-search-path/
#pkg-config --list-all
#///////////////////////////////////////////////////////////////////////////
CONFIGURE_DEF_OPT="${CONFIGURE_ADDON} --enable-maintainer-mode --disable-tests --disable-examples" #--enable-gtk-doc removed
#///////////////////////////////////////////////////////////////////////////

Remarks:

  • Additional CPPFLAGS is needed to enable orc and other dependencies (headers)

4. Compiling ‘gst-plugins-good’

#///////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////
# added definition for cross compiling for pi
SYSROOT=/opt/piroot # simulated pi system directory
CROSS_COMPILER=arm-linux-gnueabihf # name of CC, the host environment
CROSS_PATH=/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin # location of CC toolchain (download from git directly)
PREFIX=/opt/gst-installed # final installation location
CONFIGURE_ADDON="--build=i686-pc-linux-gnu --host=${CROSS_COMPILER} --prefix=${PREFIX} --with-sysroot=${SYSROOT} \
 --with-package-origin=RPi3-Version PKG_CONFIG=/usr/bin/arm-linux-gnueabihf-pkg-config" # pkg-config is outside the sysroot, so must be specified separately

echo 
echo "Current PATH=${PATH}"
echo 
export LIBS="-lpcre -lz -lm"
export LDFLAGS="--sysroot ${SYSROOT}"

# to include pkgconfig in custom folders
export CPPFLAGS="-I${SYSROOT}/usr/include -I${SYSROOT}/usr/include/arm-linux-gnueabihf \
 -I${PREFIX}/include/orc-0.4 -I${PREFIX}/include/gstreamer-1.0" # this is needed for some libirary like stdlib-bsearch.h
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig/":"${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig" # Don't mix up .pc files from your host and build target
#${PREFIX}/lib/pkgconfig/ is needed in addtion compared to gstreamer
#PKG_CONFIG_LIBDIR see http://ilgthegeek.old.livius.net/2015/02/05/pkg-config-search-path/
pkg-config --list-all
pkg-config zlib --modversion
#///////////////////////////////////////////////////////////////////////////
CONFIGURE_DEF_OPT="${CONFIGURE_ADDON} --enable-maintainer-mode --disable-examples" #--enable-gtk-doc removed
#///////////////////////////////////////////////////////////////////////////

Remarks:

  • Extra dependency of -I${PREFIX}/include/gstreamer-1.0
  • add
    LIBS="-lpcre -lz -lm"

5. Compiling ‘gst-omx’

#///////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////
# added definition for cross compiling for pi
SYSROOT=/opt/piroot # simulated pi system directory
CROSS_COMPILER=arm-linux-gnueabihf # name of CC, the host environment
CROSS_PATH=/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin # location of CC toolchain (download from git directly)
PREFIX=/opt/gst-installed # final installation location
CONFIGURE_ADDON="--build=i686-pc-linux-gnu --host=${CROSS_COMPILER} --prefix=${PREFIX} --with-sysroot=${SYSROOT} \
 --with-package-origin=RPi3-Version PKG_CONFIG=/usr/bin/arm-linux-gnueabihf-pkg-config \
 LIBS=-lpcre " # pkg-config is outside the sysroot, so must be specified separately

echo 
echo "Current PATH=${PATH}"
echo 

export LDFLAGS="--sysroot ${SYSROOT}"

# to include pkgconfig in custom folders
export CPPFLAGS="-I${SYSROOT}/usr/include -I${SYSROOT}/usr/include/arm-linux-gnueabihf \
 -I${PREFIX}/include/orc-0.4 -I${PREFIX}/include/gstreamer-1.0 -I${SYSROOT}/opt/vc/include/IL" # this is needed for some libirary like stdlib-bsearch.h
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig/":"${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig" # Don't mix up .pc files from your host and build target
#${PREFIX}/lib/pkgconfig/ is needed in addtion compared to gstreamer
#PKG_CONFIG_LIBDIR see http://ilgthegeek.old.livius.net/2015/02/05/pkg-config-search-path/
pkg-config --list-all
#///////////////////////////////////////////////////////////////////////////
CONFIGURE_DEF_OPT="${CONFIGURE_ADDON} --with-omx-target=rpi --enable-maintainer-mode -disable-examples" #--enable-gtk-doc removed
#///////////////////////////////////////////////////////////////////////////

Remarks:

  • There is extra dependency of
    -I${SYSROOT}/opt/vc/include/IL

    to be set

  • --with-omx-target=rpi
  • might need
    --with-omx-header-path=/opt/vc/include/IL
  • To compile with installed packages, which is installed in weird places in
    /usr/lib/arm-linux-gnueabihf/. Try fixing the prefix and libdir

    --prefix=/usr --libdir=/usr/lib/arm-linux-gnueabihf/
  • old version of gst-omx (1.2.0) does not seem to work with newer versions (i.e. 1.8.3)

6. Compiling ‘gst-plugins-bad’ & ‘..-ugly’

#///////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////
# added definition for cross compiling for pi
SYSROOT=/opt/piroot # simulated pi system directory
CROSS_COMPILER=arm-linux-gnueabihf # name of CC, the host environment
CROSS_PATH=/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin # location of CC toolchain (download from git directly)
PREFIX=/opt/gst-installed # final installation location
CONFIGURE_ADDON="--build=i686-pc-linux-gnu --host=${CROSS_COMPILER} --prefix=${PREFIX} --with-sysroot=${SYSROOT} \
 --with-package-origin=RPi3-Version PKG_CONFIG=/usr/bin/arm-linux-gnueabihf-pkg-config \
 LIBS=-lpcre " # pkg-config is outside the sysroot, so must be specified separately

echo 
echo "Current PATH=${PATH}"
echo 

export LDFLAGS="--sysroot ${SYSROOT}"

# to include pkgconfig in custom folders
export CPPFLAGS="-I${SYSROOT}/usr/include -I${SYSROOT}/usr/include/arm-linux-gnueabihf \
 -I${PREFIX}/include/orc-0.4 -I${PREFIX}/include/gstreamer-1.0" # this is needed for some libirary like stdlib-bsearch.h
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig/":"${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig" # Don't mix up .pc files from your host and build target
#${PREFIX}/lib/pkgconfig/ is needed in addtion compared to gstreamer
#PKG_CONFIG_LIBDIR see http://ilgthegeek.old.livius.net/2015/02/05/pkg-config-search-path/
pkg-config --list-all
#///////////////////////////////////////////////////////////////////////////
CONFIGURE_DEF_OPT="${CONFIGURE_ADDON} --enable-maintainer-mode --disable-tests --disable-examples" #--enable-gtk-doc removed
#///////////////////////////////////////////////////////////////////////////

Remarks:

  • NIL

7. Compiling ‘gst-libav’ (unsuccessful)

There is extra dependency of  -I${SYSROOT}/opt/vc/include/IL to be set.

av_warn_unused_result in the avformat.h is not defined. Add “#include “libavutil/attributes.h” in the beginning

change configure.ac

#////////////////////////////////////////////////////////////////////////////////////
 # Enable pic and static so that we get .a files, but with PIC code.
 emblibav_configure_args="$emblibav_configure_args \
 --enable-static --enable-pic \
 --disable-avdevice --disable-postproc \
 --disable-programs --disable-ffserver --disable-ffplay --disable-ffprobe --enable-ffmpeg \
 --disable-encoder=flac --enable-protocols --disable-devices \
 --disable-network --enable-hwaccels --disable-dxva2 --disable-vdpau \
 --disable-filters --enable-filter=yadif --disable-doc --disable-vda --disable-d3d11va --disable-dxva2 \
 --disable-audiotoolbox --enable-videotoolbox --disable-vaapi --disable-crystalhd \
 --disable-mediacodec --disable-nvenc --disable-mmal --enable-omx \
 --enable-omx-rpi --disable-cuda --disable-cuvid --disable-libmfx \
 --disable-libnpp --disable-iconv --disable-jni --enable-optimizations"

# changed --disable-omx --disable-omx-rpi --disable-hwaccels --disable-ffmpeg --disable-protocols --disable-videotoolbox
#////////////////////////////////////////////////////////////////////////////////////
AG_GST_SET_ERROR_CFLAGS($FATAL_WARNINGS, ==> remove -Wundef

Wundef —- removed from config.mak (gst-libs/…/libav)

remove #check_cflags -Wundef in configure in libav

Setting Environment Variable

set GST_PLUGIN_SYSTEM_PATH, GST_PLUGIN_SYSTEM_PATH_1_0 to point to (gst installation folder)/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: