cat > /tmp/run_dual.sh << 'SCRIPT_EOF'
#!/bin/sh
while true; do
exec 9<>/dev/dri/card0 2>/dev/null
if [ $? -ne 0 ]; then
echo "DRM 장치 열기 실패, 3초 후 재시도" >> /tmp/dualplane5.log
sleep 3
continue
fi
> /tmp/dualplane5.log
GST_DEBUG=3 gst-launch-1.0 \
rtspsrc location="rtsp://tapoID:tapoPASSWD@192.168.0.2:554/stream2" latency=0 protocols=tcp name=src1 timeout=5000000 \
src1. ! application/x-rtp,media=video ! rtph264depay ! h264parse ! avdec_h264 \
! kmssink sync=false skip-vsync=true fd=9 plane-id=96 render-rectangle="<0,0,960,1080>" \
rtspsrc location="rtsp://tapoID:tapoPASSWD@192.168.0.2:554/stream7" latency=0 protocols=tcp name=src2 timeout=5000000 \
src2. ! application/x-rtp,media=video ! rtph264depay ! h264parse ! avdec_h264 \
! kmssink sync=false skip-vsync=true fd=9 plane-id=107 render-rectangle="<960,0,960,1080>" \
>> /tmp/dualplane5.log 2>&1 &
GST_PID=$!
LAST_SIZE=0
STALL_COUNT=0
while kill -0 $GST_PID 2>/dev/null; do
sleep 5
CUR_SIZE=$(wc -c < /tmp/dualplane5.log 2>/dev/null)
if [ "$CUR_SIZE" = "$LAST_SIZE" ]; then
STALL_COUNT=$((STALL_COUNT + 1))
else
STALL_COUNT=0
fi
LAST_SIZE=$CUR_SIZE
# 15초(3회 연속) 동안 로그 크기 변화 없으면 = 멈춘 것으로 판단
if [ $STALL_COUNT -ge 3 ]; then
echo "15초간 활동 없음, 강제 재시작" >> /tmp/dualplane5.log
kill -9 $GST_PID 2>/dev/null
break
fi
done
exec 9<&-
echo "파이프라인 종료됨, 3초 후 재시작" >> /tmp/dualplane5.log
sleep 3
done
SCRIPT_EOF
chmod +x /tmp/run_dual.sh
댓글 없음:
댓글 쓰기