Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
olbender committed Jun 9, 2018
0 parents commit c94e571
Show file tree
Hide file tree
Showing 8 changed files with 17,307 additions and 0 deletions.
119 changes: 119 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Copyright (C) 2018 Ola Benderius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

cmake_minimum_required(VERSION 3.2)

project(opendlv-ui-videostream)

################################################################################
# Defining the relevant versions of OpenDLV Standard Message Set and libcluon.
set(OPENDLV_STANDARD_MESSAGE_SET opendlv-standard-message-set-v0.9.5.odvd)
set(CLUON_COMPLETE cluon-complete-v0.0.99.hpp)

################################################################################
# Set the search path for .cmake files.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH})

################################################################################
# This project requires C++14 or newer.
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Strip unneeded symbols from binaries.
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
# Build a static binary.
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
# Add further warning levels.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-D_XOPEN_SOURCE=700 \
-D_FORTIFY_SOURCE=2 \
-O2 \
-fstack-protector \
-fomit-frame-pointer \
-pipe \
-pedantic -pedantic-errors \
-Werror \
-Weffc++ \
-Wall -Wextra -Wshadow -Wdeprecated \
-Wdiv-by-zero -Wfloat-equal -Wfloat-conversion -Wsign-compare -Wpointer-arith \
-Wuninitialized -Wunreachable-code \
-Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-but-set-parameter -Wunused-but-set-variable \
-Wunused-value -Wunused-variable -Wunused-result \
-Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn")
# Threads are necessary for linking the resulting binaries as UDPReceiver is running in parallel.
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

find_program(FOUND_CLUON cluon-msc)

################################################################################
# Find installed libcluon
if(FOUND_CLUON)
message(STATUS "Libcluon: found at " ${FOUND_CLUON})
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/cluon-msc
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E create_symlink ${FOUND_CLUON} ${CMAKE_BINARY_DIR}/cluon-msc
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/src/${CLUON_COMPLETE} ${CMAKE_BINARY_DIR}/cluon-complete.hpp
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/cluon-complete.hpp ${CMAKE_BINARY_DIR}/cluon-complete.cpp)
else()
################################################################################
# Extract cluon-msc from cluon-complete.hpp.
message(STATUS "Libcluon: not found - generating cluon-msc from header file")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/cluon-msc
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/src/${CLUON_COMPLETE} ${CMAKE_BINARY_DIR}/cluon-complete.hpp
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/cluon-complete.hpp ${CMAKE_BINARY_DIR}/cluon-complete.cpp
COMMAND ${CMAKE_CXX_COMPILER} -o ${CMAKE_BINARY_DIR}/cluon-msc ${CMAKE_BINARY_DIR}/cluon-complete.cpp -std=c++14 -pthread -D HAVE_CLUON_MSC
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/${CLUON_COMPLETE})
endif()


################################################################################
# Generate opendlv-standard-message-set.{hpp,cpp} from ${OPENDLV_STANDARD_MESSAGE_SET} file.
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/opendlv-standard-message-set.cpp
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_BINARY_DIR}/cluon-msc --cpp-sources --cpp-add-include-file=opendlv-standard-message-set.hpp --out=${CMAKE_BINARY_DIR}/opendlv-standard-message-set.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/${OPENDLV_STANDARD_MESSAGE_SET}
COMMAND ${CMAKE_BINARY_DIR}/cluon-msc --cpp-headers --out=${CMAKE_BINARY_DIR}/opendlv-standard-message-set.hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/${OPENDLV_STANDARD_MESSAGE_SET}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/${OPENDLV_STANDARD_MESSAGE_SET} ${CMAKE_BINARY_DIR}/cluon-msc)
# Add current build directory as include directory as it contains generated files.
include_directories(SYSTEM ${CMAKE_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

set(LIBRARIES Threads::Threads)

if(UNIX)
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
find_package(LibRT REQUIRED)
set(LIBRARIES ${LIBRARIES} ${LIBRT_LIBRARIES})
include_directories(SYSTEM ${LIBRT_INCLUDE_DIR})
endif()
endif()

find_package(OpenCV REQUIRED)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
set(LIBRARIES ${LIBRARIES} ${OpenCV_LIBS})

################################################################################
# Gather all object code first to avoid double compilation.
add_library(${PROJECT_NAME}-core OBJECT ${CMAKE_BINARY_DIR}/opendlv-standard-message-set.cpp)

################################################################################
# Create executable.
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/${PROJECT_NAME}.cpp $<TARGET_OBJECTS:${PROJECT_NAME}-core>)
target_link_libraries(${PROJECT_NAME} ${LIBRARIES})

################################################################################
# Install executable.
install(TARGETS ${PROJECT_NAME} DESTINATION bin COMPONENT ${PROJECT_NAME})
49 changes: 49 additions & 0 deletions Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (C) 2018 Ola Benderius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

FROM alpine:3.7 as builder
MAINTAINER Ola Benderius "ola.benderius@chalmers.se"
RUN echo http://dl-4.alpinelinux.org/alpine/edge/main > /etc/apk/repositories && \
echo http://dl-4.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
echo http://dl-4.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories && \
apk update && \
apk --no-cache add \
cmake \
g++ \
opencv \
opencv-dev \
make
ADD . /opt/sources
WORKDIR /opt/sources
RUN mkdir build && \
cd build && \
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/tmp .. && \
make && make install


FROM alpine:3.7
MAINTAINER Ola Benderius "ola.benderius@chalmers.se"

RUN echo http://dl-4.alpinelinux.org/alpine/edge/main > /etc/apk/repositories && \
echo http://dl-4.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
echo http://dl-4.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories && \
apk update && \
apk --no-cache add \
opencv-libs \
libcanberra-gtk3

WORKDIR /usr/bin
COPY --from=builder /tmp/bin .
ENTRYPOINT ["/usr/bin/opendlv-ui-videostream"]
42 changes: 42 additions & 0 deletions Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (C) 2018 Ola Benderius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


FROM resin/armv7hf-debian:buster as builder
RUN [ "cross-build-start" ]
RUN apt-get update -y && apt-get install -y apt-utils
RUN apt-get install -y libopencv-dev libopencv-core-dev libopencv-highgui-dev
RUN apt-get install -y cmake g++ make

ADD . /opt/sources
WORKDIR /opt/sources
RUN mkdir build && \
cd build && \
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/tmp .. && \
make && make install

RUN [ "cross-build-end" ]


FROM resin/armv7hf-debian:buster
RUN [ "cross-build-start" ]
RUN apt-get update -y && apt-get install -y apt-utils
RUN apt-get install -y libopencv-dev libopencv-core-dev libopencv-highgui-dev

WORKDIR /usr/bin
COPY --from=builder /tmp/bin .
CMD ["/usr/bin/opendlv-ui-videostream"]

RUN [ "cross-build-end" ]
121 changes: 121 additions & 0 deletions FindLibRT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# You may redistribute this program and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

if(NOT LIBRT_FOUND)

IF(${CMAKE_C_COMPILER} MATCHES "arm")
# We are on ARM.
find_path(LIBRT_INCLUDE_DIR
NAMES
time.h
PATHS
${LIBRTDIR}/include/
)

find_file(
LIBRT_LIBRARIES librt.a
PATHS
${LIBRTDIR}/lib/
/usr/lib/arm-linux-gnueabihf/
/usr/lib/arm-linux-gnueabi/
)
set (LIBRT_DYNAMIC "Using static library.")

if (NOT LIBRT_LIBRARIES)
find_library(
LIBRT_LIBRARIES rt
PATHS
${LIBRTDIR}/lib/
/usr/lib/arm-linux-gnueabihf/
/usr/lib/arm-linux-gnueabi/
)
set (LIBRT_DYNAMIC "Using dynamic library.")
endif (NOT LIBRT_LIBRARIES)
ELSE()
IF("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
# We are on x86_64.
find_path(LIBRT_INCLUDE_DIR
NAMES
time.h
PATHS
${LIBRTDIR}/include/
)

find_file(
LIBRT_LIBRARIES librt.a
PATHS
${LIBRTDIR}/lib/
/usr/lib/x86_64-linux-gnu/
/usr/local/lib64/
/usr/lib64/
/usr/lib/
)
set (LIBRT_DYNAMIC "Using static library.")

if (NOT LIBRT_LIBRARIES)
find_library(
LIBRT_LIBRARIES rt
PATHS
${LIBRTDIR}/lib/
/usr/lib/x86_64-linux-gnu/
/usr/local/lib64/
/usr/lib64/
/usr/lib/
)
set (LIBRT_DYNAMIC "Using dynamic library.")
endif (NOT LIBRT_LIBRARIES)
ELSE()
# We are on x86.
find_path(LIBRT_INCLUDE_DIR
NAMES
time.h
PATHS
${LIBRTDIR}/include/
)

find_file(
LIBRT_LIBRARIES librt.a
PATHS
${LIBRTDIR}/lib/
/usr/lib/i386-linux-gnu/
/usr/local/lib/
/usr/lib/
)
set (LIBRT_DYNAMIC "Using static library.")

if (NOT LIBRT_LIBRARIES)
find_library(
LIBRT_LIBRARIES rt
PATHS
${LIBRTDIR}/lib/
/usr/lib/i386-linux-gnu/
/usr/local/lib/
/usr/lib/
)
set (LIBRT_DYNAMIC "Using dynamic library.")
endif (NOT LIBRT_LIBRARIES)
ENDIF()
ENDIF()

if (LIBRT_INCLUDE_DIR AND LIBRT_LIBRARIES)
set (LIBRT_FOUND TRUE)
endif (LIBRT_INCLUDE_DIR AND LIBRT_LIBRARIES)

if (LIBRT_FOUND)
message(STATUS "Found librt: ${LIBRT_INCLUDE_DIR}, ${LIBRT_LIBRARIES} ${LIBRT_DYNAMIC}")
else (LIBRT_FOUND)
if (Librt_FIND_REQUIRED)
message (FATAL_ERROR "Could not find librt, try to setup LIBRT_PREFIX accordingly")
endif (Librt_FIND_REQUIRED)
endif (LIBRT_FOUND)

endif (NOT LIBRT_FOUND)
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# opendlv-ui-videostream

This repository provides the source code to hook into a shared memory video
stream and send it over a conference. The image will be encoded in JPEG format,
and sent as the ImageReading message from the Standard message set.

## Usage
This microservice is created automatically on new releases, via Docker's public registry:

* [x86_64](https://hub.docker.com/r/chalmersrevere/opendlv-ui-videostream-amd64/tags/)
* [armhf](https://hub.docker.com/r/chalmersrevere/opendlv-ui-videostream-armhf/tags/)

To run this microservice using our pre-built Docker multi-arch images,
simply start it as:

```
docker run \
--rm \
-ti \
--init \
-v /dev/shm:/dev/shm \
--ulimit memlock=4000000:4000000 \
opendlv-ui-videostream \
--cid=111 \
--freq=5
--name=camera0 \
--width=1024 \
--height=768 \
--bpp=24 \
--scaled-width=256
--scaled-height=192
```

## Build from sources
To build this software, you need cmake, C++14 or newer, and make. Having these
preconditions, just run `cmake` and `make` as follows:

```
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=Release ..
make && make install
```


## License

* This project is released under the terms of the GNU GPLv3 License
Loading

0 comments on commit c94e571

Please sign in to comment.