This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stld
executable file
·135 lines (117 loc) · 2.85 KB
/
stld
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# Copyright 2022 Jamie Woods, Insanity Radio - all rights reserved.
# See LICENSE
usage() {
echo "Usage:"
echo " $0 tx --host 127.0.0.1 --port 3600 --source 'autoaudiosrc' [--redundancy 0-2]"
echo " $0 rx --host 127.0.0.1 --port 3600 --sink 'autoaudiosink' [--latency 200]"
exit 1;
}
HOST=127.0.0.1
BIND=0.0.0.0
PORT=3600
SOURCE=autoaudiosrc
SINK=autoaudiosink
SAMPLE_RATE=48000
REDUNDANCY=0
LATENCY=200
GST_LAUNCH="/usr/bin/nice -n -20 gst-launch-1.0"
TCP=
while [[ $# -gt 0 ]]; do
case $1 in
tx)
[[ $MODE ]] && (echo Mode already set; exit 1)
MODE=tx
CLIENT_SERVER=client
shift ;;
rx)
[[ $MODE ]] && (echo Mode already set; exit 1)
MODE=rx
CLIENT_SERVER=server
shift ;;
--host)
HOST="$2"
shift; shift ;;
--port)
PORT="$2"
shift; shift ;;
--bind)
BIND="$2"
shift; shift ;;
--source)
SOURCE="$2"
shift; shift ;;
--sink)
SINK="$2"
shift; shift ;;
--latency)
LATENCY="$2"
shift; shift ;;
--redundancy)
REDUNDANCY="$2"
shift; shift ;;
--gst-launch)
GST_LAUNCH="$2"
shift; shift ;;
--sample-rate)
SAMPLE_RATE="$2"
shift; shift ;;
--tcp)
TCP=1
DISTANCE="0"
shift ;;
-*|--*)
echo "Unknown option $1"
usage
exit 1 ;;
*)
;;
esac
done
LATENCY_NSEC="${LATENCY}000000"
[[ $MODE ]] || usage
trap_ctrlC() {
echo "Press CTRL-C again to exit. Restarting in 1 second"
sleep 1 || exit 1
}
trap trap_ctrlC SIGINT SIGTERM
echo "** Starting GStreamer"
echo
while true; do
if [[ $MODE == "tx" ]]; then
if [[ $TCP == 1 ]]; then
SINK="rtpL16pay pt=96 ! rtpstreampay ! tcp${CLIENT_SERVER}sink port=$PORT host=$BIND"
else
SINK="rtpL16pay mtu=1023 pt=103 ! rtpredenc distance=$REDUNDANCY pt=122 ! udpsink host=$HOST port=$PORT"
fi
$GST_LAUNCH $SOURCE do-timestamp=true \
! audioconvert ! audioresample ! queue \
! audio/x-raw,format=S16BE,channels=2,rate=$SAMPLE_RATE \
! $SINK
elif [[ $MODE == "rx" ]]; then
if [[ $TCP == 1 ]]; then
SOURCE="tcp${CLIENT_SERVER}src host=$HOST port=$PORT do-timestamp=true \
! application/x-rtp-stream,clock-rate=$SAMPLE_RATE,media=audio,payload=96,encoding-name=L16 \
! rtpstreamdepay \
! rtpstorage size-time=220000000 \
! rtpjitterbuffer latency=$LATENCY"
else
SOURCE="udpsrc uri=udp://$HOST:$PORT caps=\"application/x-rtp,payload=103\" \
! rtpreddec pt=122 \
! rtpstorage size-time=${LATENCY_NSEC}00 ! application/x-rtp, payload=103, media=audio \
! rtpjitterbuffer do-lost=1 mode=slave do-retransmission=1 max-misorder-time=${LATENCY}0 rtx-retry-period=$LATENCY latency=$LATENCY"
fi
echo $SOURCE
$GST_LAUNCH $SOURCE \
! rtpL16depay \
! rawaudioparse format=pcm pcm-format=s16be sample-rate=$SAMPLE_RATE num-channels=2 \
! audioconvert ! queue ! audiorate ! queue \
! $SINK
else
usage
fi
echo
echo "** Restarting GStreamer"
echo
sleep 0.25
done