FROM ubuntu:16.04
MAINTAINER Gwnagwoo Park <gw16.park@samsung.com>

RUN apt-get update
RUN apt-get install --no-install-recommends --no-install-suggests -y \
                    apt-utils ca-certificates build-essential git


# Install Dependencies
RUN apt-get install --no-install-recommends --no-install-suggests -y \
                    cmake autoconf autopoint \
                    gtk-doc-tools glib-2.0 \
                    bison flex libglib2.0-dev \
                    libunwind-dev libdw-dev libgtk-3-dev \
                    libx11-dev xorg-dev freeglut3-dev \
                    libglew1.5 libglew1.5-dev libglu1-mesa libglu1-mesa-dev \ 
                    libgl1-mesa-glx libgl1-mesa-dev \
                    libtheora-bin libtheora-dev libtheora-doc \
                    libvorbis-dev \
                    libcdparanoia-dev \
                    alsa-base alsa-tools \
                    libasound2-dev \
                    libopus-dev libvisual-0.4-dev libpango1.0-dev \
                    libwavpack-dev libspeex-dev \
                    libjpeg-dev \
                    libdv-dev libsoup2.4-dev qtdeclarative5-dev \
                    libcairo-dev \
                    # qt libjack-sdk \ 
                    x265 x264 \
                    libx264-dev \
                    yasm nasm libbz2-dev liblzma-dev

# Install Gstreamer
RUN git clone https://anongit.freedesktop.org/git/gstreamer/gstreamer.git \
              /root/gstreamer/gstreamer
WORKDIR /root/gstreamer/gstreamer
RUN git branch -av
RUN git checkout remotes/origin/1.16
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

# Install gst-plugins-base
RUN git clone https://anongit.freedesktop.org/git/gstreamer/gst-plugins-base.git \
              /root/gstreamer/gst-plugins-base
WORKDIR /root/gstreamer/gst-plugins-base
RUN git branch -av
RUN git checkout remotes/origin/1.16
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

# Install gst-plugins-good
RUN git clone https://anongit.freedesktop.org/git/gstreamer/gst-plugins-good.git \
              /root/gstreamer/gst-plugins-good
WORKDIR /root/gstreamer/gst-plugins-good
RUN git branch -av
RUN git checkout remotes/origin/1.16
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

# Install gst-plugins-bad
RUN git clone https://anongit.freedesktop.org/git/gstreamer/gst-plugins-bad.git \ 
              /root/gstreamer/gst-plugins-bad
WORKDIR /root/gstreamer/gst-plugins-bad
RUN git branch -av
RUN git checkout remotes/origin/1.16
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

# Install gst-plugins-ugly                    
RUN git clone https://anongit.freedesktop.org/git/gstreamer/gst-plugins-ugly.git \
              /root/gstreamer/gst-plugins-ugly
WORKDIR /root/gstreamer/gst-plugins-ugly
RUN git branch -av
RUN git checkout remotes/origin/1.16
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

# Install gst-libav
RUN git clone https://anongit.freedesktop.org/git/gstreamer/gst-libav.git \
              /root/gstreamer/gst-libav
WORKDIR /root/gstreamer/gst-libav
RUN git branch -av
RUN git checkout remotes/origin/1.16
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

# Install gst-rtsp-server
RUN git clone https://anongit.freedesktop.org/git/gstreamer/gst-rtsp-server.git \
              /root/gstreamer/gst-rtsp-server
WORKDIR /root/gstreamer/gst-rtsp-server
RUN git branch -av
RUN git checkout remotes/origin/1.16
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

COPY gstplaybin3.c /root/gstreamer/gst-plugins-base/gst/playback
WORKDIR /root/gstreamer/gst-plugins-base
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

COPY test-appsrc2.c /root/gstreamer/gst-rtsp-server/examples
WORKDIR /root/gstreamer/gst-rtsp-server
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

ENV LD_LIBRARY_PATH=/usr/local/lib
EXPOSE 8554

COPY gstrtspdefs.h /root/gstreamer/gst-plugins-base/gst-libs/gst/rtsp
COPY gstrtspdefs.c /root/gstreamer/gst-plugins-base/gst-libs/gst/rtsp
WORKDIR /root/gstreamer/gst-plugins-base
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install


COPY rtsp-client.h /root/gstreamer/gst-rtsp-server/gst/rtsp-server
COPY rtsp-client.c /root/gstreamer/gst-rtsp-server/gst/rtsp-server
WORKDIR /root/gstreamer/gst-rtsp-server
RUN ./autogen.sh --disable-gtk-doc
RUN make -j $(grep -c processor \proc cpuinfo)
RUN make install

WORKDIR /root/gstreamer/gst-rtsp-server/examples
