forked from bfields/openwrt-recording
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecorder
84 lines (76 loc) · 2.3 KB
/
recorder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
#
# Copyright J. Bruce Fields, 2024
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
MNT=/tmp/mnt
recorder=""
trap 'true' SIGHUP
sleep infinity &
dummy=$!
trap ' kill $dummy;
[ -n "$recorder" ] && kill $recorder;
umount -l "$MNT";
exit' SIGTERM
first=0
while true; do
if [ $first -eq 0 ]; then first=1; else
if [ -n "$recorder" ]; then waiton=$recorder;
else waiton=$dummy; fi
wait $waiton
fi
card=$( arecord -l|grep '^card' )
disk=/dev/sd?1
[ -e $disk ] && [ -n "$card" ]
ready=$?
# PIDs can be reused, but this test is probably reliable enough
# for our purposes:
if [ -n "$recorder" -a ! -e /proc/$recorder ]; then
recorder="";
umount -l "$MNT"
fi
if [ $ready -ne 0 ]; then
if [ -n "$recorder" ]; then
# recording's still running but something's
# been disconnected; try to clean up:
# openwrt actually seems to unmount automatically,
# but, just to be sure:
umount -l "$MNT"
kill -9 $recorder
recorder=""
fi
continue
fi
if [ -n "$recorder" ]; then continue; fi
# openwrt seems to delete mountpoints on unmount automatically,
# so we need to recreate it here:
mkdir -p "$MNT"
mount $disk "$MNT" || continue
while true; do
name=$(date +"%Y-%m-%d-%Hh%Mm%Ss")
logfile="/${MNT}/${name}.log"
if [ ! -e "$logfile" ]; then break; fi
sleep 1
done
{
# probably better to parse $device somehow. Should get
# channel count and other parameters automatically too.
# snippet originally taken from
# https://askubuntu.com/questions/868266/how-to-record-multitrack-indefinitely
arecord --device=hw:0,0 --channels=18 --file-type=raw \
--format=S32_LE --rate=44100 --buffer-time=20000000 \
> "${MNT}/${name}.raw" 2> >(ts -s >&2) &
recorder=$!
} # >"$logfile" 2>&1
done