--- /dev/null
+#
+# Copyright (C) 2020 Sebastian Kemper <sebastian_ml@gmx.net>
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+include $(INCLUDE_DIR)/kernel.mk
+
+PKG_NAME:=rtpengine
+PKG_VERSION:=mr8.3.1.4
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/sipwise/rtpengine/tar.gz/$(PKG_VERSION)?
+PKG_HASH:=18c998b776b36bec6d8c9d92ba21a38ffad76ccd20d66f99799420550eaa6fd4
+
+PKG_LICENSE:=GPL-3.0
+PKG_LICENSE_FILES:=LICENSE
+
+PKG_MAINTAINER:=Sebastian Kemper <sebastian_ml@gmx.net>
+
+PKG_BUILD_PARALLEL:=1
+
+PKG_BUILD_DEPENDS:=gperf/host
+
+include $(INCLUDE_DIR)/package.mk
+
+ENGINE_DEPENDS := \
+ +glib2 \
+ +json-glib \
+ +libevent2 \
+ +libevent2-pthreads \
+ +libhiredis \
+ +libip4tc \
+ +libopenssl \
+ +libpcap \
+ +libpcre \
+ +xmlrpc-c-client \
+ +zlib
+
+ENGINE_DEPENDS_TRANSCODING := \
+ $(ENGINE_DEPENDS) \
+ +bcg729 \
+ +libffmpeg-full \
+ +libmariadb \
+ +libspandsp
+
+RECORDING_DEPENDS := \
+ +glib2 \
+ +libffmpeg-full \
+ +libmariadb \
+ +libopenssl
+
+RTPENGINE_USERID:=$(PKG_NAME)=378:$(PKG_NAME)=378
+
+define Package/rtpengine/Default
+ URL:=https://github.com/sipwise/rtpengine
+endef
+
+define Package/rtpengine/Template
+$(call Package/rtpengine/Default)
+ TITLE:=Sipwise RTP Engine
+ CATEGORY:=Network
+ SECTION:=net
+ SUBMENU:=Telephony
+ USERID:=$(RTPENGINE_USERID)
+endef
+
+define Package/rtpengine/description/Template
+The Sipwise NGCP rtpengine is a proxy for RTP traffic and other UDP
+based media traffic. It's meant to be used with the Kamailio SIP proxy
+and forms a drop-in replacement for any of the other available RTP and
+media proxies.
+endef
+
+define Package/rtpengine
+$(call Package/rtpengine/Template)
+ VARIANT:=transcode
+ DEPENDS := \
+ $(patsubst +%,+PACKAGE_rtpengine:%,$(ENGINE_DEPENDS_TRANSCODING)) \
+ +IPV6:libip6tc
+endef
+
+define Package/rtpengine/conffiles
+/etc/config/rtpengine
+/etc/init.d/rtpengine
+/etc/rtpengine/rtpengine.conf
+endef
+
+define Package/rtpengine/description
+$(call Package/rtpengine/description/Template)
+
+Please consider installing kmod-ipt-rtpengine.
+
+endef
+
+define Package/rtpengine/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/daemon/rtpengine $(1)/usr/bin
+
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/rtpengine.init $(1)/etc/init.d/rtpengine
+
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_CONF) ./files/rtpengine.conf $(1)/etc/config/rtpengine
+
+ $(INSTALL_DIR) $(1)/etc/rtpengine
+ $(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/rtpengine.sample.conf \
+ $(1)/etc/rtpengine/rtpengine.conf
+
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
+ $(INSTALL_BIN) ./files/rtpengine.hotplug \
+ $(1)/etc/hotplug.d/iface/90-rtpengine
+endef
+
+define Package/rtpengine-no-transcode
+$(call Package/rtpengine/Template)
+ TITLE+= (no transcoding)
+ VARIANT:=no-transcode
+ CONFLICTS:=rtpengine
+ DEPENDS := \
+ $(patsubst +%,+PACKAGE_rtpengine-no-transcode:%,$(ENGINE_DEPENDS)) \
+ +IPV6:libip6tc
+endef
+
+Package/rtpengine-no-transcode/conffiles=$(Package/rtpengine/conffiles)
+
+define Package/rtpengine-no-transcode/description
+$(call Package/rtpengine/description/Template)
+
+This package comes without transcoding support.
+
+Please consider installing kmod-ipt-rtpengine.
+
+endef
+
+Package/rtpengine-no-transcode/install=$(Package/rtpengine/install)
+
+define Package/rtpengine-recording
+$(call Package/rtpengine/Default)
+ TITLE:=Sipwise RTP Recording Daemon
+ CATEGORY:=Network
+ SECTION:=net
+ SUBMENU:=Telephony
+ USERID:=$(RTPENGINE_USERID)
+ DEPENDS:=$(patsubst +%,+PACKAGE_rtpengine-recording:%,$(RECORDING_DEPENDS))
+endef
+
+define Package/rtpengine-recording/conffiles
+/etc/config/rtpengine-recording
+/etc/rtpengine/rtpengine-recording.conf
+endef
+
+define Package/rtpengine-recording/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) \
+ $(PKG_BUILD_DIR)/recording-daemon/rtpengine-recording \
+ $(1)/usr/bin
+
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/rtpengine-recording.init \
+ $(1)/etc/init.d/rtpengine-recording
+
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_CONF) ./files/rtpengine-recording.conf \
+ $(1)/etc/config/rtpengine-recording
+
+ $(INSTALL_DIR) $(1)/etc/rtpengine
+ $(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/rtpengine-recording.sample.conf \
+ $(1)/etc/rtpengine/rtpengine-recording.conf
+endef
+
+define Package/iptables-mod-rtpengine
+$(call Package/rtpengine/Default)
+ TITLE:=Sipwise rtpengine iptables extension
+ CATEGORY:=Network
+ SECTION:=net
+ SUBMENU:=Firewall
+ DEPENDS:=+PACKAGE_iptables-mod-rtpengine:libxtables
+endef
+
+define Package/iptables-mod-rtpengine/install
+ $(INSTALL_DIR) $(1)/usr/lib/iptables
+ $(INSTALL_BIN) \
+ $(PKG_BUILD_DIR)/iptables-extension/libxt_RTPENGINE.so \
+ $(1)/usr/lib/iptables
+endef
+
+define KernelPackage/ipt-rtpengine
+$(call Package/rtpengine/Default)
+ TITLE:=Sipwise rtpengine netfilter module
+ SUBMENU:=Netfilter Extensions
+ FILES:=$(PKG_BUILD_DIR)/kernel-module/xt_RTPENGINE.$(LINUX_KMOD_SUFFIX)
+ AUTOLOAD:=$(call AutoProbe,xt_RTPENGINE)
+ DEPENDS := \
+ +PACKAGE_kmod-ipt-rtpengine:kmod-crypto-hash \
+ +PACKAGE_kmod-ipt-rtpengine:kmod-ipt-core
+ MODPARAMS.xt_RTPENGINE := \
+ proc_uid=$(PKG_NAME) \
+ proc_gid=$(PKG_NAME)
+endef
+
+define KernelPackage/ipt-rtpengine/description
+Netfilter kernel module for rtpengine
+
+endef
+
+MAKE_VARS+=RTPENGINE_VERSION=$(PKG_VERSION)
+
+ifeq ($(BUILD_VARIANT),no-transcode)
+ MAKE_VARS+=with_transcoding=no
+endif
+
+define Build/Configure
+endef
+
+define Build/Compile
+
+ifneq ($(CONFIG_PACKAGE_kmod-ipt-rtpengine),)
+ RTPENGINE_VERSION=$(PKG_VERSION) $(MAKE) \
+ -C $(PKG_BUILD_DIR)/kernel-module \
+ KSRC=$(LINUX_DIR) \
+ ARCH=$(LINUX_KARCH) \
+ CROSS_COMPILE=$(TARGET_CROSS)
+endif
+
+ifneq ($(CONFIG_PACKAGE_iptables-mod-rtpengine),)
+ $(call Build/Compile/Default,-C $(PKG_BUILD_DIR)/iptables-extension)
+endif
+
+ifneq ($(CONFIG_PACKAGE_rtpengine)$(CONFIG_PACKAGE_rtpengine-no-transcode),)
+ $(call Build/Compile/Default,-C $(PKG_BUILD_DIR)/daemon)
+endif
+
+ifneq ($(CONFIG_PACKAGE_rtpengine-recording),)
+ $(call Build/Compile/Default,-C $(PKG_BUILD_DIR)/recording-daemon)
+endif
+
+endef
+
+define Build/InstallDev
+endef
+
+$(eval $(call BuildPackage,rtpengine-no-transcode))
+$(eval $(call KernelPackage,ipt-rtpengine))
+$(eval $(call BuildPackage,iptables-mod-rtpengine))
+$(eval $(call BuildPackage,rtpengine))
+$(eval $(call BuildPackage,rtpengine-recording))
--- /dev/null
+#!/bin/sh /etc/rc.common
+
+START=90
+
+NAME=rtpengine
+COMMAND="/usr/bin/$NAME"
+
+USE_PROCD=1
+
+#PROCD_DEBUG=1
+
+LOGGER="/usr/bin/logger -t $NAME"
+LOG_ERR="$LOGGER -p user.err -s"
+
+run_instance() {
+ procd_open_instance
+ procd_set_param command $COMMAND
+ procd_append_param command \
+ --config-file=/etc/$NAME/$NAME.conf \
+ --config-section="$2" \
+ $3 \
+ -f
+ # forward all output to logd
+ procd_set_param stderr 1
+ procd_set_param stdout 1
+ procd_set_param pidfile "/var/run/$NAME-$1.pid"
+ procd_set_param user $NAME
+ procd_close_instance
+
+ $LOGGER instance "$1" has started
+}
+
+handle_instance() {
+ config_get opts "$1" opts
+ config_get section "$1" section
+
+ run_instance "$1" "$section" "$opts"
+}
+
+start_service() {
+ config_load $NAME
+
+ config_get_bool enabled global enabled 0
+
+ rtp_spool_dir=/var/spool/rtpengine
+
+ if [ "$enabled" -eq 1 ]; then
+ if ! [ -e "$rtp_spool_dir" ]; then
+ mkdir -m 0750 -p "$rtp_spool_dir"
+ [ -d "$rtp_spool_dir" ] && \
+ chown $NAME:$NAME "$rtp_spool_dir"
+ fi
+ config_foreach handle_instance instance
+ else
+ $LOG_ERR service not enabled
+ $LOG_ERR edit /etc/config/$NAME
+ fi
+}