mediamtx: add MediaMTX package

From the MediaMTX README:
MediaMTX (formerly rtsp-simple-server) is a ready-to-use and
zero-dependency real-time media server and media proxy that allows
to publish, read, proxy, record and playback video and audio streams.

It has been conceived as a "media router" that routes media streams
from one end to the other.
This commit is contained in:
Morse Micro 2024-09-18 00:32:20 +10:00 committed by Arien Judge
parent f90c675d65
commit 802c5c8afe
5 changed files with 210 additions and 0 deletions

View File

@ -0,0 +1,70 @@
#
# Copyright 2023 Morse Micro
#
# This is free software, licensed under the Apache License, Version 2.0.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=mediamtx
PKG_VERSION:=1.4.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/bluenviron/mediamtx/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=8360d5e0337df599efb7a4200956caf59870965019140f976aba53673e81dc50
PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_PARALLEL:=1
PKG_BUILD_FLAGS:=no-mips16
GO_PKG:=github.com/bluenviron/mediamtx
GO_PKG_LDFLAGS_X:=$(GO_PKG)/internal/core.version=$(PKG_VERSION)
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
include $(INCLUDE_DIR)/nls.mk
# Original Makefile had this, but the Golang in our version doesn't seem to support it.
# GO_MOD_ARGS:=-buildvcs=false
define Package/mediamtx
SECTION:=multimedia
CATEGORY:=Multimedia
TITLE:=MediaMTX
URL:=https://github.com/bluenviron/mediamtx
DEPENDS=$(GO_ARCH_DEPENDS) +PACKAGE_libcamera:libcamera +PACKAGE_libcamera:libfreetype $(INTL_DEPENDS)
MENU:=1
endef
# To support the rpicamera, there's a minimal binary that mediamtx spawns
# to read the stream. For now, we equate 'rpicamera' with 'libcamera'.
# Ideally, we'd have a separate config option, but if you define that option
# inside this package we seem to end up with some kind of recursive dependency
# issue as our dependencies are enabled by this as well.
ifeq ($(CONFIG_PACKAGE_libcamera),y)
GO_PKG_TAGS:=rpicamera
MAKE_PATH=internal/protocols/rpicamera/exe
define Build/Compile
$(call Build/Compile/Default)
$(call GoPackage/Build/Compile)
endef
endif
define Package/mediamtx/install
$(call GoPackage/Package/Install/Bin,$(1))
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) files/mediamtx.init $(1)/etc/init.d/mediamtx
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) files/mediamtx.config $(1)/etc/config/mediamtx
endef
define Package/mediamtx/description
Ready-to-use server and proxy that allows users to publish, read and proxy live video and audio streams through various protocols.
If libcamera is enabled, it will try to build its rpicamera support.
endef
$(eval $(call GoBinPackage,mediamtx))
$(eval $(call BuildPackage,mediamtx))

View File

@ -0,0 +1,9 @@
config mediamtx
# luci-app-camera and camera-onvif-server need to know about this port.
# By default, it's set to 9997.
option api_address '127.0.0.1:9997'
option webrtc_address ':8889'
option hls_address ':8888'
# This port is also in the camera-onvif-server configuration
# as it needs to return the correct stream URL.
option rtsp_address ':554'

View File

@ -0,0 +1,87 @@
#!/bin/sh /etc/rc.common
START=90
STOP=10
USE_PROCD=1
SERVICE=mediamtx
error() {
logger -t "$SERVICE" "$@"
}
start_instance() {
local s="$1"
local conffile="/var/run/$SERVICE-$s.json"
# get options
# Having a port option enables that ability.
config_get api_address "$s" 'api_address' ''
config_get rtsp_address "$s" 'rtsp_address' ''
config_get webrtc_address "$s" 'webrtc_address' ''
config_get hls_address "$s" 'hls_address' ''
config_get rtmp_address "$s" 'rtmp_address' ''
config_get log_level "$s" 'log_level' 'info'
# Generate config file from options.
json_init
if [ -n "$api_address" ]; then
json_add_boolean "api" 1
json_add_string "apiAddress" "$api_address"
else
json_add_boolean "api" 0
fi
json_add_string "logLevel" "$log_level"
if [ -n "$rtsp_address" ]; then
json_add_boolean "rtsp" 1
json_add_string "rtspAddress" "$rtsp_address"
else
json_add_boolean "rtsp" 0
fi
if [ -n "$webrtc_address" ]; then
json_add_boolean "webrtc" 1
json_add_string "webrtcAddress" "$webrtc_address"
else
json_add_boolean "webrtc" 0
fi
if [ -n "$hls_address" ]; then
json_add_boolean "hls" 1
json_add_string "hlsAddress" "$hls_address"
else
json_add_boolean "hls" 0
fi
if [ -n "$rtmp_address" ]; then
json_add_boolean "rtmp" 1
json_add_string "rtmpAddress" "$rtmp_address"
else
json_add_boolean "rtmp" 0
fi
json_dump > "$conffile"
# procd stuff
procd_open_instance
# We don't need to watch the conffile, since mediamtx does that for us
# (and reloads when it changes).
procd_set_param command mediamtx "$conffile"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}
start_service() {
config_load "$SERVICE"
config_foreach start_instance "$SERVICE"
}
service_triggers() {
procd_add_reload_trigger "$SERVICE"
}

View File

@ -0,0 +1,16 @@
OpenWrt replaces xxd with a simple perl implementation that doesn't
understand longopts.
diff --git a/internal/protocols/rpicamera/exe/Makefile b/internal/protocols/rpicamera/exe/Makefile
index d2a1901..987d87f 100644
--- a/internal/protocols/rpicamera/exe/Makefile
+++ b/internal/protocols/rpicamera/exe/Makefile
@@ -37,7 +37,7 @@ OBJS = \
all: exe
text_font.h: text_font.ttf
- xxd --include $< > text_font.h
+ xxd -i $< > text_font.h
%.o: %.c text_font.h
$(CC) $(CFLAGS) -c $< -o $@

View File

@ -0,0 +1,28 @@
diff --git a/internal/protocols/rpicamera/exe/Makefile b/internal/protocols/rpicamera/exe/Makefile
index d2a1901..16fbf3b 100644
--- a/internal/protocols/rpicamera/exe/Makefile
+++ b/internal/protocols/rpicamera/exe/Makefile
@@ -1,4 +1,4 @@
-CFLAGS = \
+CFLAGS += \
-Ofast \
-Werror \
-Wall \
@@ -7,7 +7,7 @@ CFLAGS = \
-Wno-unused-result \
$$(pkg-config --cflags freetype2)
-CXXFLAGS = \
+CXXFLAGS += \
-Ofast \
-Werror \
-Wall \
@@ -17,7 +17,7 @@ CXXFLAGS = \
-std=c++17 \
$$(pkg-config --cflags libcamera)
-LDFLAGS = \
+LDFLAGS += \
-s \
-pthread \
$$(pkg-config --libs freetype2) \