-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·75 lines (64 loc) · 1.75 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·75 lines (64 loc) · 1.75 KB
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
#!/bin/bash
DEVICE=/dev/video0
EDID_FILE=/opt/display/1080p50edid
MPLAYER_PID=""
HDMI_CONNECTED=false
start_mplayer() {
echo "Starting mplayer..."
mplayer tv:// \
-tv driver=v4l2:device=$DEVICE:width=1920:height=1080:noaudio:outfmt=uyvy: \
-fs -vo sdl -zoom -screenw 800 -screenh 480 &
MPLAYER_PID=$!
}
stop_mplayer() {
if [ -n "$MPLAYER_PID" ] && kill -0 "$MPLAYER_PID" 2>/dev/null; then
echo "Stopping mplayer (PID $MPLAYER_PID)..."
kill "$MPLAYER_PID"
wait "$MPLAYER_PID" 2>/dev/null
fi
MPLAYER_PID=""
}
setup_video() {
echo "Configuring video device..."
v4l2-ctl --query-dv-timings
sleep 1
v4l2-ctl --set-dv-bt-timings query
sleep 1
v4l2-ctl --device=$DEVICE --set-fmt-video=width=1920,height=1080,pixelformat=UYVY
sleep 1
}
is_hdmi_connected() {
v4l2-ctl --query-dv-timings >/dev/null 2>&1
}
# ---- INITIAL SETUP ----
echo "Waiting for $DEVICE to become available..."
while [ ! -e $DEVICE ]; do
sleep 1
done
echo "$DEVICE detected"
echo "Injecting EDID once..."
v4l2-ctl --set-edid=file=$EDID_FILE --fix-edid-checksums
sleep 2
echo "Monitoring HDMI connection and mplayer..."
while true; do
if is_hdmi_connected; then
if ! $HDMI_CONNECTED; then
echo "HDMI connected!"
HDMI_CONNECTED=true
setup_video
start_mplayer
fi
# If mplayer is not running, restart it
if [ -z "$MPLAYER_PID" ] || ! kill -0 "$MPLAYER_PID" 2>/dev/null; then
echo "mplayer crashed or exited. Restarting..."
start_mplayer
fi
else
if $HDMI_CONNECTED; then
echo "HDMI disconnected!"
HDMI_CONNECTED=false
stop_mplayer
fi
fi
sleep 1
done