Skip to content

Commit

Permalink
added the cross compiled binaries built by my local machine. added up…
Browse files Browse the repository at this point in the history
…load release assets script. added scripts for building debian packages and support for cross-compilation.
  • Loading branch information
yjdwbj committed Jul 27, 2024
1 parent 0a11d45 commit 843df57
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:
DEBIAN_FRONTEND: noninteractive
run: |
sudo -E apt-get -qq update
sudo -E apt-get -qq install build-essential wget git tree libelf-dev debmake debhelper make -y
sudo -E apt-get -qq install build-essential wget git tree make bison flex yasm
sudo -E apt-get -qq install gcc-arm-linux-gnueabi libelf-dev debmake debhelper make -y
sudo -E apt-get -qq install gcc g++ binutils binutils-arm-linux-gnueabi gcc-arm-linux-gnueabi -y
- name: Install gstreamera library
env:
Expand Down
48 changes: 41 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,62 @@

CC=gcc
# CC ?=gcc
# -fsanitize=address is optional
CFLAGS :=-g -Wall -fno-omit-frame-pointer -DJETSON_NANO=$$(bash -c 'if [ -f /etc/nv_tegra_release ]; then echo 1; else echo 0; fi')
EXE=gwc

ifeq ($(ARCH),arm)
CFLAGS :=-g -Wall -fno-omit-frame-pointer
ARCH := arm
CROSS_COMPILE := arm-linux-gnueabi-
CC :=$(CROSS_COMPILE)gcc
SYSROOT :=${HOME}/3TB-DISK/gitlab/docker-cross-compile-qt5/builds/riotboard/debian-4.0-stable/debian-armhf
PKG_CONFIG_PATH :=${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig
LDFLAGS :=--sysroot=${SYSROOT} -L${SYSROOT}/usr/lib/arm-linux-gnueabihf -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 -Wl,-rpath-link ${SYSROOT}/usr/lib/arm-linux-gnueabihf
endif

ifeq ($(ARCH),arm64)
CFLAGS :=-g -Wall -fno-omit-frame-pointer -DJETSON_NANO=$$(bash -c 'if [ -f /etc/nv_tegra_release ]; then echo 1; else echo 0; fi')
ARCH := arm64
CROSS_COMPILE := aarch64-linux-gnu-
CC :=$(CROSS_COMPILE)gcc
SYSROOT :=${HOME}/3TB-DISK/gitlab/docker-cross-compile-qt5/builds/sun50i_a64-repo/debian-4.0-bookworm/debian-arm64
PKG_CONFIG_PATH :=${SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig
LDFLAGS :=--sysroot=${SYSROOT} -L${SYSROOT}/usr/lib/aarch64-linux-gnu -Wl,-dynamic-linker,/lib/ld-linux-aarch64.so.1 -Wl,-rpath-link ${SYSROOT}/usr/lib/aarch64-linux-gnu
endif

ifeq ($(ARCH),amd64)
CFLAGS :=-g -Wall -fno-omit-frame-pointer

endif

# https://makefiletutorial.com/#makefile-cookbook
# https://github.com/theicfire/makefiletutorial
#
#
BLIBS := $(shell pkg-config --libs --cflags gstreamer-webrtc-1.0 gstreamer-sdp-1.0 libsoup-3.0 json-glib-1.0 libudev)

# ARMHF_CFLAGS := -I${SYSROOT}/usr/include \
# -I${SYSROOT}/usr/include/glib-2.0 \
# -I${SYSROOT}/usr/lib/arm-linux-gnueabihf/glib-2.0/include \
# -I${SYSROOT}/usr/include/gstreamer-1.0 \
# -I${SYSROOT}/usr/include/arm-linux-gnueabihf \
# -I${SYSROOT}/usr/include/json-glib-1.0 \
# -I${SYSROOT}/usr/include/libmount -I/usr/include/blkid \
# -I${SYSROOT}/usr/include/orc-0.4 -I/usr/include/libsoup-3.0 \
# -I${SYSROOT}/usr/include/sysprof-4 -pthread

CFLAGS := $(CFLAGS) $$(pkg-config --cflags glib-2.0 gstreamer-1.0 json-glib-1.0 gstreamer-webrtc-1.0 gstreamer-sdp-1.0 libsoup-3.0 sqlite3 libudev)
LIBS=$$(pkg-config --libs glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 gstreamer-sdp-1.0 gstreamer-app-1.0 gstreamer-base-1.0 libsoup-3.0 json-glib-1.0 sqlite3 libudev)
LIBS :=$(LDFLAGS) $$(pkg-config --libs glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 gstreamer-sdp-1.0 gstreamer-app-1.0 gstreamer-base-1.0 libsoup-3.0 json-glib-1.0 sqlite3 libudev)
BLIBS :=$(LDFLAGS) $(shell pkg-config --libs --cflags gstreamer-webrtc-1.0 gstreamer-sdp-1.0 libsoup-3.0 json-glib-1.0 libudev)


all: webrtc-sendonly rtspsrc-webrtc gwc
webrtc-sendonly: webrtc-sendonly.c v4l2ctl.c common_priv.c media.c
"$(CC)" $(CFLAGS) $^ $(BLIBS) -o $@
$(CC) $(CFLAGS) $^ $(BLIBS) -o $@

rtspsrc-webrtc: rtspsrc-webrtc.c v4l2ctl.c common_priv.c media.c
"$(CC)" $(CFLAGS) $^ $(BLIBS) -o $@
$(CC) $(CFLAGS) $^ $(BLIBS) -o $@

gwc: v4l2ctl.c sql.c soup.c gst-app.c main.c common_priv.c media.c
"${CC}" -Wall -g -O0 ${CFLAGS} $^ ${LIBS} -o $@
$(CC) -Wall -g -O0 ${CFLAGS} $^ $(LIBS) -o $@


clean:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ You'll need `meson`, the `gstreamer-plugins-bad,gstreamer-plugins-good` library,
## Install Development Environment (Optional)

```sh
~$ sudo apt-get install libgstreamer{1.0-dev,-plugins-{bad1.0-dev,base1.0-dev}} libsoup-3.0-dev libsqlite3-dev libjson-glib-dev -y
~$ sudo apt-get install libgstreamer{1.0-dev,-plugins-{bad1.0-dev,base1.0-dev}} \
libsoup-3.0-dev libsqlite3-dev libjson-glib-dev libudev-dev libblkid-dev \
libmount-dev -y
```

## Supported SBC
Expand Down
171 changes: 159 additions & 12 deletions build_debian_package.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,172 @@
#!/bin/bash

ARCH=$(dpkg --print-architecture)
make clean
make
# ARCH=$(dpkg --print-architecture)
# make clean
# make
VERSION=0.1.2
TAG=v${VERSION}

if [ -d deb_root ]; then
rm -rf deb_root
fi

mkdir -pv deb_root/
cp -a debian/gwc/ deb_root/
sed -i "/^Architecture:/!b;cArchitecture: ${ARCH}" deb_root/gwc/DEBIAN/control
mkdir -pv deb_root/gwc/{usr/sbin,etc/gwc}
function create_debian_folder() {
PKG_ARCH=$1
DEB_PKG_ROOT=$2

cp gwc webrtc-sendonly rtspsrc-webrtc deb_root/gwc/usr/sbin/
cp -a webroot create-server-cert.sh add_user.sh config.example deb_root/gwc/etc/gwc
if [ -d ${DEB_PKG_ROOT} ]; then
rm -rf ${DEB_PKG_ROOT}
fi
mkdir -pv ${DEB_PKG_ROOT}/{DEBIAN,etc/{gwc,default,systemd/user},usr/sbin}

hash_tag=$(git rev-parse --short HEAD)
dpkg-deb --root-owner-group -b deb_root/gwc ../gwc-git-$(date +%Y-%m-%d)_${hash_tag}_${ARCH}.deb
cat > ${DEB_PKG_ROOT}/DEBIAN/control<< EOF
Package: gst-webrtc-camera
Version: ${VERSION}
Architecture: ${PKG_ARCH}
Maintainer: Michael Liu <yjdwbj@gmail.com>
Installed-Size: 1421
Depends: libglib2.0-0 (>= 2.74),
gstreamer1.0-x (>= 1.22),
gstreamer1.0-opencv (>= 1.22),
gstreamer1.0-plugins-bad (>= 1.22),
gstreamer1.0-plugins-good (>= 1.22),
gstreamer1.0-plugins-base (>= 1.22),
gstreamer1.0-plugins-ugly (>= 1.22),
libgstreamer-plugins-bad1.0-0 (>= 1.22),
libgstreamer-plugins-base1.0-0 (>= 1.22),
libgstreamer-opencv1.0-0 (>= 1.22),
libgstreamer1.0-0 (>= 1.22),
libsoup-3.0-0 (>= 3.2.2),
libjson-glib-1.0-0 (>= 1.6),
sqlite3 (>= 3.40),
libudev1
Section: misc
Priority: optional
Homepage: https://github.com/yjdwbj/
Description: webrtc camera base on gstreamer,
Gst-webrtc-camera project base on gstreamer,project function cover the offical's tutorial and more.
ex: hlssink,udpsink,appsink,splitmuxsink, and webrtc. It's privider offer webrtc camera and hls access
and also record audio and video to file triggered by timer or some signal.
EOF
if [ ${PKG_ARCH} == "arm" ]; then
sed -i "/^Architecture:/!b;cArchitecture: armhf" ${DEB_PKG_ROOT}/DEBIAN/control
fi
cat > ${DEB_PKG_ROOT}/DEBIAN/postinst <<EOF
#!/bin/bash
GWC_USER_PATH=/home/\${SUDO_USER}/.config/gwc
if [ ! -d \${GWC_USER_PATH} ]; then
echo "Not found old config files, then create new."
mkdir -pv \${GWC_USER_PATH}
cp -a /etc/gwc/config.example \${GWC_USER_PATH}/config.json
cp -a /etc/gwc/webroot \${GWC_USER_PATH}/
cp -a /etc/gwc/*.sh \${GWC_USER_PATH}/
cd \${GWC_USER_PATH}/
./create-server-cert.sh
./add_user.sh -u test -p test -r lcy-gsteramer-camera -d \${GWC_USER_PATH}/webrtc.db
chown \${SUDO_USER}:\${SUDO_USER} -R \${GWC_USER_PATH}
fi
exit 0
EOF
chmod 755 ${DEB_PKG_ROOT}/DEBIAN/postinst

cat > ${DEB_PKG_ROOT}/etc/default/rtsp-gwc<<EOF
# Default settings for rtsp-gwc.
# systemctl --user status rtsp-gwc
RTSP_USER=admin
RTSP_PWD=admin
RTSP_URL=http://192.168.2.10
RTSP_PORT=9002
EOF

cat > ${DEB_PKG_ROOT}/etc/systemd/user/gwc.service <<EOF
[Unit]
Description=Gstreamer webrtc camera
Documentation=https://github.com/yjdwbj/gst-webrtc-camera
After=multi-user.target
[Service]
ExecStart=/usr/sbin/gwc
Restart=no
Type=simple
StandardOutput=append:/tmp/gwc.log
StandardError=append:/tmp/gwc.log
[Install]
WantedBy=default.target
EOF
chmod 755 ${DEB_PKG_ROOT}/etc/systemd/user/gwc.service
cat > ${DEB_PKG_ROOT}/etc/systemd/user/rtsp-gwc.service <<EOF
[Unit]
Description=Rtsp redirect by gstreamer webrtc
Documentation=https://github.com/yjdwbj/gst-webrtc-camera
After=multi-user.target
[Service]
EnvironmentFile=/etc/default/rtsp-gwc
ExecStart=/usr/sbin/rtspsrc-webrtc -c \${RTSP_URL} -u \${RTSP_USER} -p \${RTSP_PWD} --port=\${RTSP_PORT}
Restart=no
Type=simple
StandardOutput=append:/tmp/rtsp-gwc.log
StandardError=append:/tmp/rtsp-gwc.log
[Install]
WantedBy=default.target
EOF
chmod 755 ${DEB_PKG_ROOT}/etc/systemd/user/rtsp-gwc.service
}

function build_target() {
TARGET_ARCH=$1
case $TARGET_ARCH in
arm)
ARCH=${TARGET_ARCH}
CROSS_COMPILE=arm-linux-gnueabi-
CC=${CROSS_COMPILE}gcc
SYSROOT=${HOME}/3TB-DISK/gitlab/docker-cross-compile-qt5/builds/riotboard/debian-4.0-stable/debian-armhf
# PKG_CONFIG_PATH=${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig
# LDFLAGS=--sysroot=${SYSROOT} -L${SYSROOT}/usr/lib/arm-linux-gnueabihf -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 -Wl,-rpath-link ${SYSROOT}/usr/lib/arm-linux-gnueabihf
;;
arm64)
ARCH=${TARGET_ARCH}
CROSS_COMPILE=aarch64-linux-gnu-
CC=${CROSS_COMPILE}gcc
SYSROOT=${HOME}/3TB-DISK/gitlab/docker-cross-compile-qt5/builds/sun50i_a64-repo/debian-4.0-bookworm/debian-arm64
# PKG_CONFIG_PATH=${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig
# LDFLAGS=--sysroot=${SYSROOT} -L${SYSROOT}/usr/lib/arm-linux-gnueabihf -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 -Wl,-rpath-link ${SYSROOT}/usr/lib/arm-linux-gnueabihf
;;
*)
echo "build native mode"
esac

local DEB_PKG_ROOT=deb_root/${TARGET_ARCH}

make clean
make ARCH=${ARCH} SYSROOT=${SYSROOT}

create_debian_folder ${TARGET_ARCH} "${DEB_PKG_ROOT}"

cp gwc webrtc-sendonly rtspsrc-webrtc ${DEB_PKG_ROOT}/usr/sbin/
cp -a webroot create-server-cert.sh add_user.sh config.example ${DEB_PKG_ROOT}/etc/gwc

hash_tag=$(git rev-parse --short HEAD)
TARGET_FILE=../gwc-git-$(date +%Y-%m-%d)_${hash_tag}_${TAG}_${TARGET_ARCH}.deb
[ -f ${TARGET_FILE} ] && rm -rf ${TARGET_FILE}
dpkg-deb --root-owner-group -b ${DEB_PKG_ROOT} ${TARGET_FILE}
./upload-github-release-asset.sh tag="LATEST" filename=${TARGET_FILE}
}


for arch in arm amd64 arm64
do
build_target $arch
done

rm -rf deb_root
echo "package done!!!"

exit 0

Expand Down
2 changes: 1 addition & 1 deletion debian/gwc/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

GWC_USER_PATH=/home/${SUDO_USER}/.config/gwc

echo "Running post install script."
if [ ! -d ${GWC_USER_PATH} ]; then
echo "Not found old config files, then create new."
mkdir -pv ${GWC_USER_PATH}
Expand Down
3 changes: 1 addition & 2 deletions gst-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ static GstPadLinkReturn link_request_src_pad(GstElement *src, GstElement *dst) {
gst_element_class_get_metadata(klass, GST_ELEMENT_METADATA_KLASS);
// g_print("class name:%s\n", klassname);
#if GST_VERSION_MINOR >= 20
g_print("GST_VERSION_MINOR >=20\n");
src_pad = gst_element_request_pad_simple(src, "src_%u");

if(src_pad == NULL)
Expand Down Expand Up @@ -3136,7 +3135,7 @@ GstElement *create_instance() {
config_data.webrtc.udpsink.port);
GstElement *cmdlinebin = gst_parse_launch(cmdline, NULL);
gst_element_set_state(cmdlinebin, GST_STATE_READY);
g_print("run cmdline: %s\n", cmdline);
// g_print("run cmdline: %s\n", cmdline);
gst_element_set_state(cmdlinebin, GST_STATE_PLAYING);
g_free(cmdline);

Expand Down
2 changes: 1 addition & 1 deletion rtspsrc-webrtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ create_receiver_entry(SoupWebsocketConnection *connection, AppData *app) {
get_rtsp_url(app);

// gchar *turn_srv = NULL;
gchar *webrtc_name = g_strdup_printf("send_%" G_GUINT64_FORMAT, (intptr_t)(receiver_entry->connection));
gchar *webrtc_name = g_strdup_printf("send_%" G_GUINT64_FORMAT, (u_long)(receiver_entry->connection));
gchar *video_src = g_strdup_printf("udpsrc %s ! "
" application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,payload=(int)96 ! "
" %s. ",
Expand Down
4 changes: 2 additions & 2 deletions soup.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static gchar *get_table_list() {
gchar *list = g_strdup("( ");
GList *item = g_hash_table_get_keys(webrtc_connected_table);
for (; item; item = item->next) {
gchar *td = g_strdup_printf("%" G_GUINT64_FORMAT ",", (intptr_t)(item->data));
gchar *td = g_strdup_printf("%" G_GUINT64_FORMAT ",", (u_long)(item->data));
gchar *tmp = g_strconcat(list, td, NULL);
g_free(list);
g_free(td);
Expand Down Expand Up @@ -510,7 +510,7 @@ static void soup_websocket_handler(G_GNUC_UNUSED SoupServer *server,
// webrtc_entry->client = client_context;
webrtc_entry->send_channel = NULL;
webrtc_entry->receive_channel = NULL;
webrtc_entry->hash_id = (intptr_t)(webrtc_entry->connection);
webrtc_entry->hash_id = (u_long)(webrtc_entry->connection);

g_object_ref(G_OBJECT(connection));

Expand Down
66 changes: 66 additions & 0 deletions upload-github-release-asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
#
# Author: Stefan Buck
# License: MIT
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
#
# This script accepts the following parameters:
#
# * owner
# * repo
# * tag
# * filename
# * github_api_token
#
# Script to upload a release asset using the GitHub API v3.
#
# Example:
#
# upload-github-release-asset.sh github_api_token=TOKEN owner=stefanbuck repo=playground tag=v0.1.0 filename=./build.zip
#

# Check dependencies.
set -e
xargs=$(which gxargs || which xargs)

# Validate settings.
[ "$TRACE" ] && set -x

CONFIG=$@

for line in $CONFIG; do
eval "$line"
done

# Define variables.
OWNER=yjdwbj
REPO_NAME=gst-webrtc-camera
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/$OWNER/$REPO_NAME"
GH_TAGS="$GH_REPO/releases/tags/$tag"
AUTH="Authorization: token ${GITHUB_TOKEN}"
WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
CURL_ARGS="-LJO#"

if [[ "$tag" == 'LATEST' ]]; then
GH_TAGS="$GH_REPO/releases/latest"
fi

# Validate token.
curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }

# Read asset tags.
response=$(curl -sH "$AUTH" $GH_TAGS)

# Get ID of the asset based on given filename.
eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; }

# Upload asset
echo "Uploading asset... "

# Construct url
GH_ASSET="https://uploads.github.com/repos/${OWNER}/${REPO_NAME}/releases/$id/assets?name=$(basename $filename)"

curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" $GH_ASSET
Loading

0 comments on commit 843df57

Please sign in to comment.