From 5ae4fe7400137bf49b7b725688844dcd4d3ec0aa Mon Sep 17 00:00:00 2001 From: Morse Micro Date: Wed, 18 Sep 2024 00:34:49 +1000 Subject: [PATCH] aws-kvs: add the aws-kvs package. The AWS KVS SDK provides functionality to easily stream video from connected devices to AWS for processing, including ML, playback, and analytics. The Morse Micro package adds procd support to manage stream configuration and triggering the aws stream. --- .gitattributes | 5 ++ multimedia/aws-kvs/Makefile | 63 +++++++++++++++++++ .../aws-kvs/files/002-libcurl_setopts.patch | 23 +++++++ multimedia/aws-kvs/files/etc/config/aws_kvs | 0 multimedia/aws-kvs/files/etc/init.d/aws_kvs | 53 ++++++++++++++++ .../001-libcurl-adaptations-for-openwrt.patch | 52 +++++++++++++++ 6 files changed, 196 insertions(+) create mode 100644 multimedia/aws-kvs/Makefile create mode 100644 multimedia/aws-kvs/files/002-libcurl_setopts.patch create mode 100644 multimedia/aws-kvs/files/etc/config/aws_kvs create mode 100755 multimedia/aws-kvs/files/etc/init.d/aws_kvs create mode 100644 multimedia/aws-kvs/patches/001-libcurl-adaptations-for-openwrt.patch diff --git a/.gitattributes b/.gitattributes index 72c1b76..ee90227 100644 --- a/.gitattributes +++ b/.gitattributes @@ -48,3 +48,8 @@ *.7z binary *.ttf binary *.pyc binary + +# aws-kvs files unfortunately have CRs in them, which means the patch +# files mix LF and CRLF. +multimedia/aws-kvs/patches/*.patch -text +multimedia/aws-kvs/files/*.patch -text diff --git a/multimedia/aws-kvs/Makefile b/multimedia/aws-kvs/Makefile new file mode 100644 index 0000000..bdd7098 --- /dev/null +++ b/multimedia/aws-kvs/Makefile @@ -0,0 +1,63 @@ +# +# Copyright 2023 Morse Micro +# +# This is free software, licensed under the Apache License, Version 2.0. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=aws-kvs +PKG_VERSION:=3.4.1 + +ARCHIVE_NAME:=amazon-kinesis-video-streams-producer-sdk-cpp +PKG_SOURCE:= $(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/awslabs/$(ARCHIVE_NAME)/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=ac85de2cd61326150471bdce68176c2c8e93cff979633bc6b99f6293de8dd5d4 +PKG_BUILD_DIR:=$(BUILD_DIR)/$(ARCHIVE_NAME)-$(PKG_VERSION) + +PKG_USE_NINJA:=1 +PKG_MAINTAINER:=Morse Micro + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/cmake.mk +include $(INCLUDE_DIR)/nls.mk + + +define Package/aws-kvs + SECTION:=multimedia + CATEGORY:=Multimedia + SUBMENU:=Streaming + URL:=https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git + TITLE:=Amazon Kinesis Video Streams Producer + DEPENDS:= +libopenssl +libcurl +log4cplus +libgstreamer1 +libgst1app +gst1-mod-videoparsersbad +gstreamer1-utils +gst1-mod-rtpmanager +gst1-mod-udp +gstreamer1-plugins-base +@PACKAGE_gstreamer1-plugins-good +gst1-mod-rtsp +gst1-mod-rtp $(INTL_DEPENDS) +endef + + +define Package/aws-kvs/description + Amazon Kinesis Video Streams provides a service that publishes a video stream to AWS Kinesis Video Streams using the gstreamer plugins +endef + +CMAKE_OPTIONS += -DBUILD_dumpcap=ON +CMAKE_OPTIONS += -DBUILD_DEPENDENCIES=OFF +CMAKE_OPTIONS += -DCOMPILER_WARNINGS=ON +CMAKE_OPTIONS += -DCONSTRAINED_DEVICE=ON +CMAKE_OPTIONS += -DBUILD_GSTREAMER_PLUGIN=ON + +define Build/Prepare + $(Build/Prepare/Default) + $(CP) files/*.patch $(PKG_BUILD_DIR)/ +endef + +define Package/aws-kvs/install + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/etc/init.d/aws_kvs $(1)/etc/init.d/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_BIN) ./files/etc/config/aws_kvs $(1)/etc/config/ + $(INSTALL_DIR) $(1)/usr/lib + $(INSTALL_DATA) $(PKG_BUILD_DIR)/dependency/libkvscproducer/kvscproducer-src/libcproducer.so $(1)/usr/lib/ + $(INSTALL_DATA) $(PKG_BUILD_DIR)/libKinesisVideoProducer.so $(1)/usr/lib/ + $(INSTALL_DIR) $(1)/usr/lib/gstreamer-1.0 + $(INSTALL_DATA) $(PKG_BUILD_DIR)/libgstkvssink.so $(1)/usr/lib/gstreamer-1.0/ +endef + +$(eval $(call BuildPackage,aws-kvs)) diff --git a/multimedia/aws-kvs/files/002-libcurl_setopts.patch b/multimedia/aws-kvs/files/002-libcurl_setopts.patch new file mode 100644 index 0000000..64117a4 --- /dev/null +++ b/multimedia/aws-kvs/files/002-libcurl_setopts.patch @@ -0,0 +1,23 @@ +#File: 002-libcurl_setopts.patch +#Description: The provided patch addresses an issue stemming from the default libcurl setting, which attempts to resolve the AWS URL to IPv6. This resolution fails, resulting in a 'could not resolve host' error. The patch adjusts the curl option to IPv4, effectively resolving the host successfully. + +--- a/dependency/libkvscproducer/kvscproducer-src/src/source/Common/Curl/CurlCall.c 2023-11-13 13:05:46.950163615 +1100 ++++ b/dependency/libkvscproducer/kvscproducer-src/src/source/Common/Curl/CurlCall.c 2023-11-13 13:06:43.684309233 +1100 +@@ -58,6 +58,7 @@ + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaderList); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer); + curl_easy_setopt(curl, CURLOPT_URL, pRequestInfo->url); ++ curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, getSslCertNameFromType(pRequestInfo->certType)); + curl_easy_setopt(curl, CURLOPT_SSLCERT, pRequestInfo->sslCertPath); + curl_easy_setopt(curl, CURLOPT_SSLKEY, pRequestInfo->sslPrivateKeyPath); +--- a/dependency/libkvscproducer/kvscproducer-src/src/source/Response.c 2023-11-14 10:49:38.987263012 +1100 ++++ b/dependency/libkvscproducer/kvscproducer-src/src/source/Response.c 2023-11-14 10:49:57.367256068 +1100 +@@ -147,6 +147,7 @@ + curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, pCallInfo->errorBuffer); + + curl_easy_setopt(pCurl, CURLOPT_URL, pRequestInfo->url); ++ curl_easy_setopt(pCurl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + curl_easy_setopt(pCurl, CURLOPT_NOSIGNAL, 1); + + // Setting up limits for curl timeout diff --git a/multimedia/aws-kvs/files/etc/config/aws_kvs b/multimedia/aws-kvs/files/etc/config/aws_kvs new file mode 100644 index 0000000..e69de29 diff --git a/multimedia/aws-kvs/files/etc/init.d/aws_kvs b/multimedia/aws-kvs/files/etc/init.d/aws_kvs new file mode 100755 index 0000000..083b9fc --- /dev/null +++ b/multimedia/aws-kvs/files/etc/init.d/aws_kvs @@ -0,0 +1,53 @@ +#!/bin/sh /etc/rc.common + +START=90 +STOP=01 +USE_PROCD=1 +SERVICE=aws_kvs + +get_aws_kvs_credentials() { + local stream=$1 + config_get access_key $stream access_key + config_get secret_key $stream secret_key + config_get region $stream region + config_get stream_name $stream stream_name + config_get storage_size $stream storage_size + config_get location $stream stream_url + + if [ -z "$access_key" ] || [ -z "$secret_key" ] || [ -z "$region" ] || [ -z "$stream_name" ] || [ -z "$storage_size" ]; then + logger -t $SERVICE -p daemon.crit "One or more AWS Kinesis Video Streaming credentials are missing. Cannot start the service." + return 1 + fi +} + +create_gst_instance() { + local stream=$1 + config_get enable $stream enable + if [ "$enable" == "1" ]; then + procd_open_instance $stream + get_aws_kvs_credentials $stream + procd_set_param env GST_PLUGIN_PATH=/usr/lib/gstreamer-1.0 + procd_set_param command gst-launch-1.0 + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_append_param command rtspsrc location="$location" short-header=TRUE ! rtph264depay ! h264parse ! kvssink + procd_append_param command stream-name="$stream_name" + procd_append_param command storage-size=$storage_size + procd_append_param command access-key=$access_key + procd_append_param command secret-key=$secret_key + procd_append_param command aws-region=$region + procd_close_instance + else + logger -t $SERVICE -p daemon.info "Stream $stream is disabled" + fi +} +start_service() { + #For each stream create a gst instance + config_load aws_kvs + config_foreach create_gst_instance kvs_stream +} + +service_triggers() { + procd_add_reload_trigger aws_kvs +} + diff --git a/multimedia/aws-kvs/patches/001-libcurl-adaptations-for-openwrt.patch b/multimedia/aws-kvs/patches/001-libcurl-adaptations-for-openwrt.patch new file mode 100644 index 0000000..d48d7cb --- /dev/null +++ b/multimedia/aws-kvs/patches/001-libcurl-adaptations-for-openwrt.patch @@ -0,0 +1,52 @@ +From 49515f24d12d1e47b4ed0a746395894cfc87d939 Mon Sep 17 00:00:00 2001 +From: jdelapla +Date: Wed, 11 Oct 2023 11:26:43 -0700 +Subject: [PATCH] Alpine stackoverflow fix (#1084) + +* Update producer-c dependency to allow for Constrained device flag +--- + CMake/Dependencies/libkvscproducer-CMakeLists.txt | 4 ++-- + CMakeLists.txt | 1 + + README.md | 1 + + 3 files changed, 4 insertions(+), 2 deletions(-) + +diff --git a/README.md b/README.md +index 473caa5..b0014d3 100644 +--- a/README.md ++++ b/README.md +@@ -94,6 +94,7 @@ You can pass the following options to `cmake ..`. + * `-DUNDEFINED_BEHAVIOR_SANITIZER` Build with UndefinedBehaviorSanitizer + * `-DALIGNED_MEMORY_MODEL` Build for aligned memory model only devices. Default is OFF. + * `-DBUILD_LOG4CPLUS_HOST` Specify host-name for log4cplus for cross-compilation. Default is OFF. ++* `-DCONSTRAINED_DEVICE` Set the thread stack size to 0.5MB, needed for Alpine builds + + #### To Include JNI + +diff --git a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt 2023-11-10 14:53:25.865727556 +1100 ++++ b/CMakeLists.txt 2023-11-10 15:00:51.255565535 +1100 +@@ -16,7 +16,7 @@ + option(BUILD_DEPENDENCIES "Whether or not to build depending libraries from source" ON) + option(BUILD_OPENSSL_PLATFORM "If buildng OpenSSL what is the target platform" OFF) + option(BUILD_LOG4CPLUS_HOST "Specify host-name for log4cplus for cross-compilation" OFF) +- ++option(CONSTRAINED_DEVICE "Set thread stack size to 0.5MB" OFF) + + # Developer Flags + option(BUILD_TEST "Build the testing tree" OFF) + +diff --git a/CMake/Dependencies/libkvscproducer-CMakeLists.txt b/CMake/Dependencies/libkvscproducer-CMakeLists.txt +--- a/CMake/Dependencies/libkvscproducer-CMakeLists.txt 2023-11-14 10:39:58.047477235 +1100 ++++ b/CMake/Dependencies/libkvscproducer-CMakeLists.txt 2023-11-14 10:41:03.727453683 +1100 +@@ -7,9 +7,10 @@ + # clone repo only + ExternalProject_Add(libkvscproducer-download + GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-producer-c.git +- GIT_TAG 178109a5dbfc5288ba5cf7fab1dc1afd5e2e182b ++ GIT_TAG 5e8a5cfa0e2e12304983abbe0a9fa023b574ef9a + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/kvscproducer-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/kvscproducer-build" ++ PATCH_COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR}/../../ patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/../../002-libcurl_setopts.patch + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ""