Generic refactoring (#109)

* Generic refactoring
pull/111/head 2.7
Alex 1 year ago committed by GitHub
parent e1eedd869c
commit 610cb3f47b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,7 +7,7 @@
ffmpeg_version=ffmpeg
# shellcheck source=/.github/workflows/mock/VERSION
source "/etc/VERSION"
# shellcheck source=/patch_config.sh
# shellcheck source=/utils/patch_config.sh
source "/var/packages/VideoStation/patch_config.sh" || echo "No patch_config.sh"
dsm_version="$productversion $buildnumber-$smallfixnumber"
vs_path=/var/packages/VideoStation

@ -1,4 +1,6 @@
A new version of the wrapper was deployed (v2.6) fixing an issue with offline transcoding.
You can find the changelog here: https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher/releases/tag/2.6
/!\ PLEASE FOLLOW THE UPDATE PROCEDURE IN THE CHANGELOG TO UPDATE /!\
As always, please let me know of any issue you could have.

@ -20,7 +20,6 @@ wrappers=(
vs_base_path=/var/packages/VideoStation
vs_path="$vs_base_path/target"
libsynovte_path="$vs_path/lib/libsynovte.so"
vs_scripts=("preuninst")
cp_base_path=/var/packages/CodecPack
cp_path="$cp_base_path/target"
cp_bin_path="$cp_path/bin"
@ -197,21 +196,6 @@ patch() {
exit 1
fi
for filename in "${vs_scripts[@]}"; do
if [[ -f "$vs_base_path/scripts/$filename" ]]; then
info "Saving current $filename script as $filename.orig"
mv -n "$vs_base_path/scripts/$filename" "$vs_base_path/scripts/$filename.orig"
download "$filename.sh" "$repo_base_url/$branch/scripts/$filename.sh" "$vs_base_path/scripts/$filename"
info "Injecting script variables..."
repo_full_url="$repo_base_url/$branch"
sed -i -e "s|@repo_full_url@|$repo_full_url|" "$vs_base_path/scripts/$filename"
chmod 755 "$vs_base_path/scripts/$filename"
fi
done
for filename in "${wrappers[@]}"; do
if [[ -f "$vs_path/bin/$filename" ]]; then
info "Saving current $filename as $filename.orig"
@ -221,6 +205,8 @@ patch() {
chown root:VideoStation "$vs_path/bin/$filename"
chmod 750 "$vs_path/bin/$filename"
chmod u+s "$vs_path/bin/$filename"
sed -i -e "s/@package_name@/VideoStation/" "$vs_path/bin/$filename"
fi
done
@ -233,24 +219,61 @@ patch() {
info "Patching CodecPack's $filename"
mv -n "$cp_bin_path/$filename" "$cp_bin_path/$filename.orig"
ln -s -f "$vs_path/bin/$target" "$cp_bin_path/$filename"
download "$filename.sh" "$repo_base_url/$branch/wrappers/$target.sh" "$cp_bin_path/$filename"
chmod 750 "$cp_bin_path/$filename"
chmod u+s "$cp_bin_path/$filename"
sed -i -e "s/@package_name@/CodecPack/" "$cp_bin_path/$filename"
fi
done
if [[ -d "$cp_path/lib/gstreamer" ]]; then
gst_lib_path="$cp_path/lib/gstreamer/patch"
gst_plugin_path="$cp_path/lib/gstreamer/gstreamer-1.0/patch"
info "Downloading CodecPack's gstreamer plugins..."
mkdir "$gst_plugin_path"
for plugin in "${gstreamer_plugins[@]}"; do
download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$gst_plugin_path/$plugin.so"
done
mkdir "$gst_lib_path"
mkdir -p "$gst_lib_path/dri"
mkdir -p "$gst_lib_path/x264-10bit"
mkdir -p "$gst_lib_path/x265-10bit"
for lib in "${gstreamer_libs[@]}"; do
download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$gst_lib_path/$lib"
done
fi
mkdir "$cp_base_path/patch"
download "CodecPack's patch_config.sh" "$repo_base_url/$branch/utils/patch_config.sh" "$cp_base_path/patch/patch_config.sh"
download "CodecPack's patch_utils.sh" "$repo_base_url/$branch/utils/patch_utils.sh" "$cp_base_path/patch/patch_utils.sh"
info "Setting CodecPack's ffmpeg version to: ffmpeg$ffmpegversion"
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$cp_base_path/patch/patch_config.sh"
fi
if [[ -f "$vs_path/bin/gst-launch-1.0" ]]; then
gst_lib_path="$vs_path/lib/gstreamer/patch"
gst_plugin_path="$vs_path/lib/gstreamer/gstreamer-1.0/patch"
info "Downloading gstreamer plugins..."
mkdir "$gst_plugin_path"
for plugin in "${gstreamer_plugins[@]}"; do
download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$gst_plugin_path/$plugin.so"
done
mkdir -p "$vs_path/lib/gstreamer/dri"
mkdir -p "$vs_path/lib/gstreamer/x264-10bit"
mkdir -p "$vs_path/lib/gstreamer/x265-10bit"
mkdir "$gst_lib_path"
mkdir -p "$gst_lib_path/dri"
mkdir -p "$gst_lib_path/x264-10bit"
mkdir -p "$gst_lib_path/x265-10bit"
for lib in "${gstreamer_libs[@]}"; do
download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$vs_path/lib/gstreamer/$lib"
download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$gst_lib_path/$lib"
done
info "Saving current GSTOmx configuration..."
@ -260,10 +283,12 @@ patch() {
cp -n "$cp_path/etc/gstomx.conf" "$vs_path/etc/gstomx.conf"
fi
download "patch_config.sh" "$repo_base_url/$branch/patch_config.sh" "$vs_base_path/patch_config.sh"
mkdir "$vs_base_path/patch"
download "VideoStation's patch_config.sh" "$repo_base_url/$branch/utils/patch_config.sh" "$vs_base_path/patch/patch_config.sh"
download "VideoStation's patch_utils.sh" "$repo_base_url/$branch/utils/patch_utils.sh" "$vs_base_path/patch/patch_utils.sh"
info "Setting ffmpeg version to: ffmpeg$ffmpegversion"
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_base_path/patch_config.sh"
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_base_path/patch/patch_config.sh"
info "Saving current libsynovte.so as libsynovte.so.orig"
cp -n "$libsynovte_path" "$libsynovte_path.orig"
@ -293,32 +318,33 @@ unpatch() {
mv -T -f "$filename" "${filename::-5}"
done
find "$vs_base_path/scripts" -type f -name "*.orig" | while read -r filename; do
info "Restoring VideoStation's $filename script"
mv -T -f "$filename" "${filename::-5}"
done
if [[ -d $cp_bin_path ]]; then
for file in "${cp_to_patch[@]}"; do
filename="${file%%:*}"
target="${file##*:}"
rm -f "$cp_bin_path/$target"
if [[ -f "$cp_bin_path/$filename.orig" ]]; then
info "Restoring CodecPack's $filename"
mv -T -f "$cp_bin_path/$filename.orig" "$cp_bin_path/$filename"
fi
done
if [[ -d "$cp_path/lib/gstreamer" ]]; then
info "Removing CodecPack gstreamer's patched libraries and plugins"
rm -rf "$cp_path/lib/gstreamer/patch"
rm -rf "$cp_path/lib/gstreamer/gstreamer-1.0/patch"
fi
info "Remove CodecPack's patch directory"
rm -rf "$cp_base_path/patch"
fi
if [[ -f "$vs_path/bin/gst-launch-1.0" ]]; then
for plugin in "${gstreamer_plugins[@]}"; do
info "Removing gstreamer's $plugin plugin"
rm -f "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
done
for lib in "${gstreamer_libs[@]}"; do
info "Removing gstreamer's $lib library"
rm -f "$vs_path/lib/gstreamer/$lib"
done
info "Removing VideoStation gstreamer's patched libraries and plugins"
rm -rf "$vs_path/lib/gstreamer/patch"
rm -rf "$vs_path/lib/gstreamer/gstreamer-1.0/patch"
if [[ -f "$vs_path/etc/gstomx.conf.orig" ]]; then
info "Restoring GSTOmx configuration..."
@ -328,8 +354,8 @@ unpatch() {
fi
fi
info "Remove patch config."
rm -f "$vs_base_path/patch_config.sh"
info "Remove VideoStation's patch directory."
rm -rf "$vs_base_path/patch"
restart_packages
clean

@ -1,6 +0,0 @@
#!/bin/sh
repo_full_url=@repo_full_url@
curl "$repo_full_url/patcher.sh" | bash -s -- -a unpatch
exit 0

@ -0,0 +1,87 @@
#!/bin/bash
stderrfile=/dev/null
child=""
pid=$$
log() {
local now
now=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$now] [$1] $2" >> "$stderrfile"
}
newline() {
echo "" >> "$stderrfile"
}
info() {
log "INFO" "$1"
}
kill_child() {
if [[ "$child" != "" ]]; then
kill "$child" > /dev/null 2> /dev/null || :
fi
}
endprocess() {
info "========================================[end $0 $pid]"
newline
if [[ $errcode -eq 1 ]]; then
cp "$stderrfile" "$stderrfile.prev"
fi
kill_child
rm -f "$stderrfile"
exit "$errcode"
}
handle_error() {
log "ERROR" "An error occurred"
newline
errcode=1
kill_child
}
fix_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-acodec)
shift
if [[ "$1" = "libfaac" ]]; then
args+=("-acodec" "aac")
else
args+=("-acodec" "libfdk_aac")
fi
;;
-vf)
shift
arg="$1"
if [[ "$arg" =~ "scale_vaapi" ]]; then
scale_w=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\1/p')
scale_h=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\2/p')
if (( scale_w && scale_h )); then
arg="scale_vaapi=w=$scale_w:h=$scale_h:format=nv12,hwupload,setsar=sar=1"
else
arg="scale_vaapi=format=nv12,hwupload,setsar=sar=1"
fi
fi
args+=("-vf" "$arg")
;;
-r)
shift
;;
*) args+=("$1") ;;
esac
shift
done
}

@ -1,5 +1,14 @@
#!/bin/bash
# shellcheck source=/utils/patch_config.sh
source "/var/packages/VideoStation/patch/patch_config.sh" 2> /dev/null ||
source "/var/packages/CodecPack/patch/patch_config.sh" 2> /dev/null
# shellcheck source=/utils/patch_utils.sh
source "/var/packages/VideoStation/patch/patch_utils.sh" 2> /dev/null ||
source "/var/packages/CodecPack/patch/patch_utils.sh" 2> /dev/null ||
{ echo "Cannot load patch_utils.sh" >> "ffmpeg-0.stderr.prev" && echo "Cannot load patch_utils.sh" && exit 1; }
#########################
# VARS
#########################
@ -9,93 +18,8 @@ pid=$$
child=""
stderrfile="/tmp/ffmpeg-$pid.stderr"
errcode=0
# shellcheck source=/patch_config.sh
source "/var/packages/VideoStation/patch_config.sh"
#########################
# UTILS
#########################
log() {
local now
now=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$now] [$1] $2" >> $stderrfile
}
newline() {
echo "" >> $stderrfile
}
info() {
log "INFO" "$1"
}
handle_error() {
log "ERROR" "An error occurred"
newline
errcode=1
kill_child
}
kill_child() {
if [[ "$child" != "" ]]; then
kill "$child"
fi
}
endprocess() {
info "========================================[end ffmpeg $pid]"
newline
if [[ $errcode -eq 1 ]]; then
cp "$stderrfile" "$stderrfile.prev"
fi
kill_child
rm -f "$stderrfile"
exit $errcode
}
fix_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-acodec)
shift
if [[ "$1" = "libfaac" ]]; then
args+=("-acodec" "aac")
else
args+=("-acodec" "libfdk_aac")
fi
;;
-vf)
shift
arg="$1"
if [[ "$arg" =~ "scale_vaapi" ]]; then
scale_w=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\1/p')
scale_h=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\2/p')
if (( scale_w && scale_h )); then
arg="scale_vaapi=w=$scale_w:h=$scale_h:format=nv12,hwupload,setsar=sar=1"
else
arg="scale_vaapi=format=nv12,hwupload,setsar=sar=1"
fi
fi
args+=("-vf" "$arg")
;;
-r)
shift
;;
*) args+=("$1") ;;
esac
shift
done
}
path=$(realpath "$0")
args=()
#########################
# ENTRYPOINT
@ -109,12 +33,12 @@ rm -f /tmp/ffmpeg*.stderr.prev
fix_args "$@"
newline
info "========================================[start ffmpeg $pid]"
info "========================================[start $0 $pid]"
info "DEFAULT ARGS: $*"
info "UPDATED ARGS: ${args[*]}"
info "Trying with VideoStation's ffmpeg with fixed args..."
/var/packages/VideoStation/target/bin/ffmpeg.orig "${args[@]}" <&0 2>> $stderrfile &
info "Trying fixed args with $path.orig ..."
"${path}.orig" "${args[@]}" <&0 2>> $stderrfile &
child=$!
wait "$child"
@ -123,8 +47,8 @@ if [[ $errcode -eq 0 ]]; then
fi
errcode=0
info "Trying with VideoStation's ffmpeg with default args..."
/var/packages/VideoStation/target/bin/ffmpeg.orig "$@" <&0 2>> $stderrfile &
info "Trying default args with $path.orig ..."
"${path}.orig" "$@" <&0 2>> $stderrfile &
child=$!
wait "$child"
@ -133,7 +57,7 @@ if [[ $errcode -eq 0 ]]; then
fi
errcode=0
info "Trying with SC's ffmpeg and fixed args..."
info "Trying with SC's $ffmpeg_version and fixed args..."
"/var/packages/${ffmpeg_version}/target/bin/ffmpeg" "${args[@]}" <&0 2>> $stderrfile &
child=$!
wait "$child"

@ -2,6 +2,11 @@
export GST_DEBUG=1 #1: ERROR (Log fatal errors only).
# shellcheck source=/utils/patch_utils.sh
source "/var/packages/VideoStation/patch/patch_utils.sh" 2> /dev/null ||
source "/var/packages/CodecPack/patch/patch_utils.sh" 2> /dev/null ||
{ echo "Cannot load patch_utils.sh" >> "gstinspect-0.stderr.prev" && echo "Cannot load patch_utils.sh" && exit 1; }
#########################
# VARS
#########################
@ -9,48 +14,9 @@ export GST_DEBUG=1 #1: ERROR (Log fatal errors only).
pid=$$
child=""
stderrfile="/tmp/gstinspect-$pid.stderr"
path=$(realpath "$0")
errcode=0
#########################
# UTILS
#########################
log() {
local now
now=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$now] [$1] $2" >> $stderrfile
}
newline() {
echo "" >> $stderrfile
}
info() {
log "INFO" "$1"
}
handle_error() {
log "ERROR" "An error occurred"
newline
errcode=1
endprocess
}
endprocess() {
info "========================================[end gst $pid]"
newline
if [[ $errcode -eq 1 ]]; then
cp "$stderrfile" "$stderrfile.prev"
fi
rm "$stderrfile"
if [[ "$child" != "" ]]; then
kill "$child"
fi
exit $errcode
}
#########################
# ENTRYPOINT
#########################
@ -64,7 +30,7 @@ newline
info "========================================[start gst-inspect $pid]"
info "GST_ARGS: $*"
/var/packages/VideoStation/target/bin/gst-inspect-1.0.orig "$@" 2>> $stderrfile &
"$path.orig" "$@" 2>> $stderrfile &
child=$!
wait "$child"

@ -1,6 +1,12 @@
#!/bin/bash
export GST_DEBUG=1 #1: ERROR (Log fatal errors only).
export LD_LIBRARY_PATH=/var/packages/@package_name@/target/lib/gstreamer/patch
# shellcheck source=/utils/patch_utils.sh
source "/var/packages/VideoStation/patch/patch_utils.sh" 2> /dev/null ||
source "/var/packages/CodecPack/patch/patch_utils.sh" 2> /dev/null ||
{ echo "Cannot load patch_utils.sh" >> "gstlaunch-0.stderr.prev" && echo "Cannot load patch_utils.sh" && exit 1; }
#########################
# VARS
@ -9,48 +15,9 @@ export GST_DEBUG=1 #1: ERROR (Log fatal errors only).
pid=$$
child=""
stderrfile="/tmp/gstlaunch-$pid.stderr"
path=$(realpath "$0")
errcode=0
#########################
# UTILS
#########################
log() {
local now
now=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$now] [$1] $2" >> $stderrfile
}
newline() {
echo "" >> $stderrfile
}
info() {
log "INFO" "$1"
}
handle_error() {
log "ERROR" "An error occurred"
newline
errcode=1
endprocess
}
endprocess() {
info "========================================[end gst $pid]"
newline
if [[ $errcode -eq 1 ]]; then
cp "$stderrfile" "$stderrfile.prev"
fi
rm "$stderrfile"
if [[ "$child" != "" ]]; then
kill "$child"
fi
exit $errcode
}
#########################
# ENTRYPOINT
#########################
@ -61,10 +28,10 @@ trap handle_error ERR
rm -f /tmp/gstlaunch*.stderr.prev
newline
info "========================================[start gst-launch $pid]"
info "========================================[start $0 $pid]"
info "GST_ARGS: $*"
/var/packages/VideoStation/target/bin/gst-launch-1.0.orig "$@" 2>> $stderrfile &
"$path.orig" "$@" 2>> $stderrfile &
child=$!
wait "$child"

Loading…
Cancel
Save