v4l2rtspserver: add package 5288/head
authorRoger <roger-@users.noreply.github.com>
Sun, 17 Dec 2017 00:04:43 +0000 (19:04 -0500)
committerRoger Dammit <roger.dammit@gmail.com>
Sun, 7 Jan 2018 17:51:23 +0000 (12:51 -0500)
Signed-off-by: Roger Dammit <rogerdammit@gmail.com>
multimedia/v4l2rtspserver/Makefile [new file with mode: 0644]
multimedia/v4l2rtspserver/files/config.openwrt [new file with mode: 0644]
multimedia/v4l2rtspserver/files/v4l2rtspserver.config [new file with mode: 0644]
multimedia/v4l2rtspserver/files/v4l2rtspserver.init [new file with mode: 0644]

diff --git a/multimedia/v4l2rtspserver/Makefile b/multimedia/v4l2rtspserver/Makefile
new file mode 100644 (file)
index 0000000..9d442ec
--- /dev/null
@@ -0,0 +1,85 @@
+#
+# Copyright (C) 2017 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+
+include $(TOPDIR)/rules.mk
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/mpromonet/v4l2rtspserver.git
+PKG_SOURCE_VERSION:=d7e8dd4d35a802219222642a2e3b28f2dc5069c1
+PKG_DATE:=2017-12-20
+
+PKG_NAME:=v4l2rtspserver
+PKG_VERSION:=$(PKG_DATE)-$(PKG_SOURCE_VERSION)
+PKG_RELEASE:=1
+PKG_MAINTAINER:=Roger Dammit <rogerdammit@gmail.com>
+
+LIVE555_VERSION:=2017.10.28
+LIVE555_MD5SUM:=a5acd14c4fa7b50f7270304d3b4a70ae
+LIVE555_FILE:=live.$(LIVE555_VERSION).tar.gz
+
+CMAKE_INSTALL:=1 
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/v4l2rtspserver
+       SECTION:=multimedia
+       CATEGORY:=Multimedia
+       TITLE:=v4l2rtspserver
+       DEPENDS:=+libstdcpp
+       URL:=https://github.com/mpromonet/v4l2rtspserver
+endef  
+
+define Package/v4l2rtspserver/description
+       RTSP server for v4L2 video sources
+endef
+
+define Package/v4l2rtspserver/conffiles
+       /etc/config/v4l2rtspserver
+endef
+
+define Download/live555
+       URL:=https://download.videolan.org/pub/contrib/live555/
+       FILE:=$(LIVE555_FILE)
+       MD5SUM:=$(LIVE555_MD5SUM)
+endef
+
+define Build/Prepare
+       $(Build/Prepare/Default)
+
+       ## need to compile some dependencies so that cmake will find them
+
+       # build live555
+        $(eval $(call Download,live555))
+
+       mkdir -p $(PKG_BUILD_DIR)/live555
+       $(TAR) -xf $(DL_DIR)/$(LIVE555_FILE) --strip=1 -C $(PKG_BUILD_DIR)/live555
+       $(CP) files/config.openwrt $(PKG_BUILD_DIR)/live555
+       ( cd $(PKG_BUILD_DIR)/live555; ./genMakefiles openwrt )
+
+       $(MAKE) $(MAKE_FLAGS) -C $(PKG_BUILD_DIR)/live555 
+       $(MAKE) -C $(PKG_BUILD_DIR)/live555 PREFIX="$(STAGING_DIR)/usr/" install
+
+       # build v4l2wrapper
+       $(MAKE) $(MAKE_FLAGS) -C $(PKG_BUILD_DIR)/v4l2wrapper CFLAGS="$(TARGET_CFLAGS) -I $(PKG_BUILD_DIR)/v4l2wrapper/inc"
+       $(CP) $(PKG_BUILD_DIR)/v4l2wrapper/libv4l2wrapper.a $(PKG_BUILD_DIR)
+
+       # patch cmake file
+       $(SED) 's/DEBUG/RELEASE/' $(PKG_BUILD_DIR)/CMakeLists.txt
+endef
+
+define Package/v4l2rtspserver/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/v4l2rtspserver-$(PKG_VERSION) $(1)/usr/bin/
+       mv $(1)/usr/bin/v4l2rtspserver-$(PKG_VERSION) $(1)/usr/bin/v4l2rtspserver
+
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) files/v4l2rtspserver.init $(1)/etc/init.d/v4l2rtspserver
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) files/v4l2rtspserver.config $(1)/etc/config/v4l2rtspserver
+endef 
+
+$(eval $(call BuildPackage,v4l2rtspserver))
diff --git a/multimedia/v4l2rtspserver/files/config.openwrt b/multimedia/v4l2rtspserver/files/config.openwrt
new file mode 100644 (file)
index 0000000..0c87988
--- /dev/null
@@ -0,0 +1,19 @@
+COMPILE_OPTS =                 $(INCLUDES) -I. -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLOCALE_NOT_USED -DNO_SSTREAM=1 -DALLOW_RTSP_SERVER_PORT_REUSE=1 
+C =                            c
+C_COMPILER =                   $(GCC)
+CFLAGS +=                      $(COMPILE_OPTS)
+C_FLAGS =                      $(CFLAGS)
+CPP =                          cpp
+CPLUSPLUS_COMPILER =           $(AS) # optimizations are only in AR apparently, so use instead of CXX
+CPLUSPLUS_FLAGS =              $(COMPILE_OPTS) -Wall -DBSD=1
+CPLUSPLUS_FLAGS +=             $(CPPFLAGS) -fexceptions
+OBJ =                          o
+LINK =                         $(CXX) -o
+LINK_OPTS =                    -L. $(LDFLAGS)
+CONSOLE_LINK_OPTS =            $(LINK_OPTS)
+LIBRARY_LINK =                 $(AR) cr 
+LIBRARY_LINK_OPTS =    
+LIB_SUFFIX =                   a
+LIBS_FOR_CONSOLE_APPLICATION = $(CXXLIBS)
+LIBS_FOR_GUI_APPLICATION =     $(LIBS_FOR_CONSOLE_APPLICATION)
+EXE =
diff --git a/multimedia/v4l2rtspserver/files/v4l2rtspserver.config b/multimedia/v4l2rtspserver/files/v4l2rtspserver.config
new file mode 100644 (file)
index 0000000..7561362
--- /dev/null
@@ -0,0 +1,10 @@
+config v4l2rtspserver 'core'
+       option enabled '0'
+       option device '/dev/video0'
+       option port '554'
+       option resolution '640x480'
+       option fps '15'
+       option path 'stream'
+       option username 'openwrt'
+       option password 'openwrt'
+       option format 'h264'
diff --git a/multimedia/v4l2rtspserver/files/v4l2rtspserver.init b/multimedia/v4l2rtspserver/files/v4l2rtspserver.init
new file mode 100644 (file)
index 0000000..e4c837e
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2017 OpenWrt.org
+
+# TODO: 
+# * support start multiple streams with one server
+# * support multiple usernames
+# * support HLS, etc.
+
+START=90
+STOP=10
+
+USE_PROCD=1
+
+SERVICE=v4l2rtspserver
+PROG=/usr/bin/$SERVICE
+
+error() {
+        logger -t "$SERVICE" "$@"
+}
+
+start_instance() {
+       local s="$1"
+
+       config_get_bool enabled "$1" 'enabled' 0
+       [ $enabled -eq 0 ] && return
+
+       # validate device
+       config_get device "$s" 'device'
+       if [ ! -c "$device" ]; then
+               error "device '$device' does not exist"
+               return 1
+       fi
+
+       # get options
+       config_get port "$s" 'port'
+       config_get resolution "$s" 'resolution'
+       config_get fps "$s" 'fps'
+       config_get username "$s" 'username'
+       config_get password "$s" 'password'
+       config_get path "$s" 'path'
+       config_get format "$s" 'format'
+
+       # pull out resolution width and height from string
+       local w="$(echo $resolution | cut -d'x' -f1)"
+       local h="$(echo $resolution | cut -d'x' -f2)"
+       
+       # make sure format is uppercase
+       format="$(echo $format | tr a-z A-Z)"
+
+       # build args
+       local args="-s"
+       args="$args -P $port"
+       args="$args -u ${path}"
+       args="$args -F $fps"
+       args="$args -W $w"
+       args="$args -H $h"
+       args="$args -f$format"
+       args="$args -c" # fixes issue with corrupt frames with H264
+               
+       if [ -n "$username" ]; then
+               args="$args -U ${username}:${password}"
+       fi
+
+       cmd="$PROG $args $device"
+
+       # procd stuff
+       procd_open_instance
+       procd_set_param file /etc/config/$SERVICE
+       procd_set_param command $cmd
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_add_mdns "rtsp" "tcp" "$port" "daemon=$SERVICE" "path=/$path"
+       procd_close_instance
+}
+
+start_service() {
+       config_load "$SERVICE"
+       config_foreach start_instance "$SERVICE"
+}
+
+service_triggers() {
+       procd_add_reload_trigger "$SERVICE"
+}