Skip to content

Commit 610cb3f

Browse files
authored
Generic refactoring (#109)
* Generic refactoring
1 parent e1eedd8 commit 610cb3f

9 files changed

Lines changed: 189 additions & 223 deletions

File tree

issue-report.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ffmpeg_version=ffmpeg
88
# shellcheck source=/.github/workflows/mock/VERSION
99
source "/etc/VERSION"
10-
# shellcheck source=/patch_config.sh
10+
# shellcheck source=/utils/patch_config.sh
1111
source "/var/packages/VideoStation/patch_config.sh" || echo "No patch_config.sh"
1212
dsm_version="$productversion $buildnumber-$smallfixnumber"
1313
vs_path=/var/packages/VideoStation

motd.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
A new version of the wrapper was deployed (v2.6) fixing an issue with offline transcoding.
22
You can find the changelog here: https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher/releases/tag/2.6
33

4+
/!\ PLEASE FOLLOW THE UPDATE PROCEDURE IN THE CHANGELOG TO UPDATE /!\
5+
46
As always, please let me know of any issue you could have.

patcher.sh

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ wrappers=(
2020
vs_base_path=/var/packages/VideoStation
2121
vs_path="$vs_base_path/target"
2222
libsynovte_path="$vs_path/lib/libsynovte.so"
23-
vs_scripts=("preuninst")
2423
cp_base_path=/var/packages/CodecPack
2524
cp_path="$cp_base_path/target"
2625
cp_bin_path="$cp_path/bin"
@@ -197,21 +196,6 @@ patch() {
197196
exit 1
198197
fi
199198

200-
for filename in "${vs_scripts[@]}"; do
201-
if [[ -f "$vs_base_path/scripts/$filename" ]]; then
202-
info "Saving current $filename script as $filename.orig"
203-
mv -n "$vs_base_path/scripts/$filename" "$vs_base_path/scripts/$filename.orig"
204-
205-
download "$filename.sh" "$repo_base_url/$branch/scripts/$filename.sh" "$vs_base_path/scripts/$filename"
206-
207-
info "Injecting script variables..."
208-
repo_full_url="$repo_base_url/$branch"
209-
sed -i -e "s|@repo_full_url@|$repo_full_url|" "$vs_base_path/scripts/$filename"
210-
211-
chmod 755 "$vs_base_path/scripts/$filename"
212-
fi
213-
done
214-
215199
for filename in "${wrappers[@]}"; do
216200
if [[ -f "$vs_path/bin/$filename" ]]; then
217201
info "Saving current $filename as $filename.orig"
@@ -221,6 +205,8 @@ patch() {
221205
chown root:VideoStation "$vs_path/bin/$filename"
222206
chmod 750 "$vs_path/bin/$filename"
223207
chmod u+s "$vs_path/bin/$filename"
208+
209+
sed -i -e "s/@package_name@/VideoStation/" "$vs_path/bin/$filename"
224210
fi
225211
done
226212

@@ -233,24 +219,61 @@ patch() {
233219
info "Patching CodecPack's $filename"
234220

235221
mv -n "$cp_bin_path/$filename" "$cp_bin_path/$filename.orig"
236-
ln -s -f "$vs_path/bin/$target" "$cp_bin_path/$filename"
222+
download "$filename.sh" "$repo_base_url/$branch/wrappers/$target.sh" "$cp_bin_path/$filename"
223+
chmod 750 "$cp_bin_path/$filename"
224+
chmod u+s "$cp_bin_path/$filename"
225+
226+
sed -i -e "s/@package_name@/CodecPack/" "$cp_bin_path/$filename"
237227
fi
238228
done
229+
230+
if [[ -d "$cp_path/lib/gstreamer" ]]; then
231+
gst_lib_path="$cp_path/lib/gstreamer/patch"
232+
gst_plugin_path="$cp_path/lib/gstreamer/gstreamer-1.0/patch"
233+
234+
info "Downloading CodecPack's gstreamer plugins..."
235+
236+
mkdir "$gst_plugin_path"
237+
for plugin in "${gstreamer_plugins[@]}"; do
238+
download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$gst_plugin_path/$plugin.so"
239+
done
240+
241+
mkdir "$gst_lib_path"
242+
mkdir -p "$gst_lib_path/dri"
243+
mkdir -p "$gst_lib_path/x264-10bit"
244+
mkdir -p "$gst_lib_path/x265-10bit"
245+
246+
for lib in "${gstreamer_libs[@]}"; do
247+
download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$gst_lib_path/$lib"
248+
done
249+
fi
250+
251+
mkdir "$cp_base_path/patch"
252+
download "CodecPack's patch_config.sh" "$repo_base_url/$branch/utils/patch_config.sh" "$cp_base_path/patch/patch_config.sh"
253+
download "CodecPack's patch_utils.sh" "$repo_base_url/$branch/utils/patch_utils.sh" "$cp_base_path/patch/patch_utils.sh"
254+
255+
info "Setting CodecPack's ffmpeg version to: ffmpeg$ffmpegversion"
256+
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$cp_base_path/patch/patch_config.sh"
239257
fi
240258

241259
if [[ -f "$vs_path/bin/gst-launch-1.0" ]]; then
260+
gst_lib_path="$vs_path/lib/gstreamer/patch"
261+
gst_plugin_path="$vs_path/lib/gstreamer/gstreamer-1.0/patch"
262+
242263
info "Downloading gstreamer plugins..."
243264

265+
mkdir "$gst_plugin_path"
244266
for plugin in "${gstreamer_plugins[@]}"; do
245-
download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
267+
download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$gst_plugin_path/$plugin.so"
246268
done
247269

248-
mkdir -p "$vs_path/lib/gstreamer/dri"
249-
mkdir -p "$vs_path/lib/gstreamer/x264-10bit"
250-
mkdir -p "$vs_path/lib/gstreamer/x265-10bit"
270+
mkdir "$gst_lib_path"
271+
mkdir -p "$gst_lib_path/dri"
272+
mkdir -p "$gst_lib_path/x264-10bit"
273+
mkdir -p "$gst_lib_path/x265-10bit"
251274

252275
for lib in "${gstreamer_libs[@]}"; do
253-
download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$vs_path/lib/gstreamer/$lib"
276+
download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$gst_lib_path/$lib"
254277
done
255278

256279
info "Saving current GSTOmx configuration..."
@@ -260,10 +283,12 @@ patch() {
260283
cp -n "$cp_path/etc/gstomx.conf" "$vs_path/etc/gstomx.conf"
261284
fi
262285

263-
download "patch_config.sh" "$repo_base_url/$branch/patch_config.sh" "$vs_base_path/patch_config.sh"
286+
mkdir "$vs_base_path/patch"
287+
download "VideoStation's patch_config.sh" "$repo_base_url/$branch/utils/patch_config.sh" "$vs_base_path/patch/patch_config.sh"
288+
download "VideoStation's patch_utils.sh" "$repo_base_url/$branch/utils/patch_utils.sh" "$vs_base_path/patch/patch_utils.sh"
264289

265290
info "Setting ffmpeg version to: ffmpeg$ffmpegversion"
266-
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_base_path/patch_config.sh"
291+
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_base_path/patch/patch_config.sh"
267292

268293
info "Saving current libsynovte.so as libsynovte.so.orig"
269294
cp -n "$libsynovte_path" "$libsynovte_path.orig"
@@ -293,32 +318,33 @@ unpatch() {
293318
mv -T -f "$filename" "${filename::-5}"
294319
done
295320

296-
find "$vs_base_path/scripts" -type f -name "*.orig" | while read -r filename; do
297-
info "Restoring VideoStation's $filename script"
298-
mv -T -f "$filename" "${filename::-5}"
299-
done
300-
301321
if [[ -d $cp_bin_path ]]; then
302322
for file in "${cp_to_patch[@]}"; do
303323
filename="${file%%:*}"
324+
target="${file##*:}"
325+
326+
rm -f "$cp_bin_path/$target"
304327

305328
if [[ -f "$cp_bin_path/$filename.orig" ]]; then
306329
info "Restoring CodecPack's $filename"
307330
mv -T -f "$cp_bin_path/$filename.orig" "$cp_bin_path/$filename"
308331
fi
309332
done
333+
334+
if [[ -d "$cp_path/lib/gstreamer" ]]; then
335+
info "Removing CodecPack gstreamer's patched libraries and plugins"
336+
rm -rf "$cp_path/lib/gstreamer/patch"
337+
rm -rf "$cp_path/lib/gstreamer/gstreamer-1.0/patch"
338+
fi
339+
340+
info "Remove CodecPack's patch directory"
341+
rm -rf "$cp_base_path/patch"
310342
fi
311343

312344
if [[ -f "$vs_path/bin/gst-launch-1.0" ]]; then
313-
for plugin in "${gstreamer_plugins[@]}"; do
314-
info "Removing gstreamer's $plugin plugin"
315-
rm -f "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
316-
done
317-
318-
for lib in "${gstreamer_libs[@]}"; do
319-
info "Removing gstreamer's $lib library"
320-
rm -f "$vs_path/lib/gstreamer/$lib"
321-
done
345+
info "Removing VideoStation gstreamer's patched libraries and plugins"
346+
rm -rf "$vs_path/lib/gstreamer/patch"
347+
rm -rf "$vs_path/lib/gstreamer/gstreamer-1.0/patch"
322348

323349
if [[ -f "$vs_path/etc/gstomx.conf.orig" ]]; then
324350
info "Restoring GSTOmx configuration..."
@@ -328,8 +354,8 @@ unpatch() {
328354
fi
329355
fi
330356

331-
info "Remove patch config."
332-
rm -f "$vs_base_path/patch_config.sh"
357+
info "Remove VideoStation's patch directory."
358+
rm -rf "$vs_base_path/patch"
333359

334360
restart_packages
335361
clean

scripts/preuninst.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.

utils/patch_utils.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
stderrfile=/dev/null
4+
child=""
5+
pid=$$
6+
7+
log() {
8+
local now
9+
now=$(date '+%Y-%m-%d %H:%M:%S')
10+
echo "[$now] [$1] $2" >> "$stderrfile"
11+
}
12+
13+
newline() {
14+
echo "" >> "$stderrfile"
15+
}
16+
17+
info() {
18+
log "INFO" "$1"
19+
}
20+
21+
kill_child() {
22+
if [[ "$child" != "" ]]; then
23+
kill "$child" > /dev/null 2> /dev/null || :
24+
fi
25+
}
26+
27+
endprocess() {
28+
info "========================================[end $0 $pid]"
29+
newline
30+
31+
if [[ $errcode -eq 1 ]]; then
32+
cp "$stderrfile" "$stderrfile.prev"
33+
fi
34+
35+
kill_child
36+
rm -f "$stderrfile"
37+
38+
exit "$errcode"
39+
}
40+
41+
handle_error() {
42+
log "ERROR" "An error occurred"
43+
newline
44+
errcode=1
45+
kill_child
46+
}
47+
48+
fix_args() {
49+
while [[ $# -gt 0 ]]; do
50+
case "$1" in
51+
-acodec)
52+
shift
53+
if [[ "$1" = "libfaac" ]]; then
54+
args+=("-acodec" "aac")
55+
else
56+
args+=("-acodec" "libfdk_aac")
57+
fi
58+
;;
59+
60+
-vf)
61+
shift
62+
arg="$1"
63+
64+
if [[ "$arg" =~ "scale_vaapi" ]]; then
65+
scale_w=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\1/p')
66+
scale_h=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\2/p')
67+
68+
if (( scale_w && scale_h )); then
69+
arg="scale_vaapi=w=$scale_w:h=$scale_h:format=nv12,hwupload,setsar=sar=1"
70+
else
71+
arg="scale_vaapi=format=nv12,hwupload,setsar=sar=1"
72+
fi
73+
fi
74+
75+
args+=("-vf" "$arg")
76+
;;
77+
78+
-r)
79+
shift
80+
;;
81+
82+
*) args+=("$1") ;;
83+
esac
84+
85+
shift
86+
done
87+
}

0 commit comments

Comments
 (0)