Compare commits
2 Commits
a8fb9b3b9f
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 269ff4ee2f | |||
| 6bdfeb68db |
Executable → Regular
+26
-22
@@ -15,12 +15,13 @@ load_config() {
|
||||
[ -f "$CONFIG_FILE" ] || return
|
||||
SOURCE_TYPE=$(grep -o '"source_type":"[^"]*"' "$CONFIG_FILE" 2>/dev/null | cut -d'"' -f4)
|
||||
RTSP_URL=$(grep -o '"rtsp_url":"[^"]*"' "$CONFIG_FILE" 2>/dev/null | cut -d'"' -f4)
|
||||
TCP_URL=$(grep -o '"tcp_url":"[^"]*"' "$CONFIG_FILE" 2>/dev/null | cut -d'"' -f4)
|
||||
MP4_PATH=$(grep -o '"mp4_path":"[^"]*"' "$CONFIG_FILE" 2>/dev/null | cut -d'"' -f4)
|
||||
RES_W=$(grep -o '"res_w":[0-9]*' "$CONFIG_FILE" 2>/dev/null | cut -d: -f2)
|
||||
RES_H=$(grep -o '"res_h":[0-9]*' "$CONFIG_FILE" 2>/dev/null | cut -d: -f2)
|
||||
FPS=$(grep -o '"fps":[0-9]*' "$CONFIG_FILE" 2>/dev/null | cut -d: -f2)
|
||||
ROTATION=$(grep -o '"rotation":[0-9]*' "$CONFIG_FILE" 2>/dev/null | cut -d: -f2)
|
||||
: ${SOURCE_TYPE:=mp4} ${RTSP_URL:=rtsp://192.168.1.100:8554/stream}
|
||||
: ${SOURCE_TYPE:=mp4} ${RTSP_URL:=rtsp://192.168.1.100:8554/stream} ${TCP_URL:=tcp://192.168.1.100:5000}
|
||||
: ${MP4_PATH:=/sdcard/Movies/2.mp4} ${RES_W:=1920} ${RES_H:=1080} ${FPS:=30} ${ROTATION:=0}
|
||||
}
|
||||
|
||||
@@ -70,8 +71,18 @@ case "${1:-help}" in
|
||||
status)
|
||||
get_status_json
|
||||
;;
|
||||
stop)
|
||||
log "stop: killing provider and feeder"
|
||||
pkill -9 -f "/virtual_camera_provider" 2>/dev/null || true
|
||||
pkill -9 -f "ffmpeg.*video0" 2>/dev/null || true
|
||||
echo 1 > /data/local/tmp/virtualcam_disabled 2>/dev/null
|
||||
log "stop: disabled flag set"
|
||||
get_status_json
|
||||
log "stop: done"
|
||||
;;
|
||||
start)
|
||||
log "start: killing old provider"
|
||||
log "start: removing disable flag"
|
||||
rm -f /data/local/tmp/virtualcam_disabled 2>/dev/null
|
||||
pkill -9 -f "/virtual_camera_provider" 2>/dev/null || true
|
||||
mkdir -p "$LIB_DST" 2>/dev/null
|
||||
cp "$MODDIR/vendor/lib64"/*.so "$LIB_DST/" 2>/dev/null
|
||||
@@ -85,6 +96,7 @@ case "${1:-help}" in
|
||||
restart)
|
||||
log "restart: killing provider"
|
||||
pkill -9 -f "/virtual_camera_provider" 2>/dev/null || true
|
||||
rm -f /data/local/tmp/virtualcam_disabled 2>/dev/null
|
||||
sleep 2
|
||||
mkdir -p "$LIB_DST" 2>/dev/null
|
||||
cp "$MODDIR/vendor/lib64"/*.so "$LIB_DST/" 2>/dev/null
|
||||
@@ -95,13 +107,9 @@ case "${1:-help}" in
|
||||
get_status_json
|
||||
log "restart: done"
|
||||
;;
|
||||
stop)
|
||||
log "stop: killing provider"
|
||||
pkill -9 -f "/virtual_camera_provider" 2>/dev/null || true
|
||||
log "stop: done"
|
||||
echo '{"status":"stopped"}'
|
||||
;;
|
||||
start_feeder)
|
||||
log "start_feeder: removing feeder disable flag"
|
||||
rm -f /data/local/tmp/virtualcam_feeder_disabled 2>/dev/null
|
||||
log "start_feeder: loading config"
|
||||
load_config
|
||||
pkill -9 -f "ffmpeg.*video0" 2>/dev/null || true
|
||||
@@ -121,6 +129,11 @@ case "${1:-help}" in
|
||||
nohup "$FF" -rtsp_transport tcp -i "$RTSP_URL" \
|
||||
-vf "${VFILTER}scale=${RES_W}:${RES_H},fps=${FPS:-30}" \
|
||||
-f v4l2 -pix_fmt yuv420p /dev/video0 > /dev/null 2>&1 &
|
||||
elif [ "$SOURCE_TYPE" = "tcp" ]; then
|
||||
nohup "$FF" -fflags nobuffer -flags low_delay -analyzeduration 0 -use_wallclock_as_timestamps 1 \
|
||||
-i "$TCP_URL" \
|
||||
-vf "${VFILTER}scale=${RES_W}:${RES_H},fps=${FPS:-30}" \
|
||||
-f v4l2 -pix_fmt yuv420p /dev/video0 > /dev/null 2>&1 &
|
||||
elif [ "$SOURCE_TYPE" = "mp4" ] && [ -f "$MP4_PATH" ]; then
|
||||
nohup "$FF" -stream_loop -1 -re -i "$MP4_PATH" \
|
||||
-vf "${VFILTER}scale=${RES_W}:${RES_H},fps=${FPS:-30}" \
|
||||
@@ -135,14 +148,15 @@ case "${1:-help}" in
|
||||
echo '{"status":"feeder_started"}'
|
||||
;;
|
||||
stop_feeder)
|
||||
log "stop_feeder: killing ffmpeg"
|
||||
log "stop_feeder: killing ffmpeg and setting feeder disable flag"
|
||||
pkill -9 -f "ffmpeg.*video0" 2>/dev/null || true
|
||||
echo 1 > /data/local/tmp/virtualcam_feeder_disabled 2>/dev/null
|
||||
log "stop_feeder: done"
|
||||
echo '{"status":"feeder_stopped"}'
|
||||
get_status_json
|
||||
;;
|
||||
get_config)
|
||||
load_config
|
||||
echo "{\"source_type\":\"$SOURCE_TYPE\",\"rtsp_url\":\"$RTSP_URL\",\"mp4_path\":\"$MP4_PATH\",\"res_w\":${RES_W:-1920},\"res_h\":${RES_H:-1080},\"fps\":${FPS:-30},\"rotation\":${ROTATION:-0}}"
|
||||
echo "{\"source_type\":\"$SOURCE_TYPE\",\"rtsp_url\":\"$RTSP_URL\",\"tcp_url\":\"$TCP_URL\",\"mp4_path\":\"$MP4_PATH\",\"res_w\":${RES_W:-1920},\"res_h\":${RES_H:-1080},\"fps\":${FPS:-30},\"rotation\":${ROTATION:-0}}"
|
||||
;;
|
||||
validate)
|
||||
PROVIDER_PID=$(pgrep -f "/virtual_camera_provider" | head -1)
|
||||
@@ -170,17 +184,7 @@ case "${1:-help}" in
|
||||
)\""
|
||||
echo "}"
|
||||
;;
|
||||
device_info)
|
||||
dumpsys media.camera 2>/dev/null > /data/local/tmp/cam_dump.txt 2>/dev/null
|
||||
F0=$(dumpsys media.camera 2>/dev/null | grep -A10 "virtual/0 (" | grep Facing | head -1)
|
||||
F1=$(dumpsys media.camera 2>/dev/null | grep -A10 "virtual/1 (" | grep Facing | head -1)
|
||||
L0=$(dumpsys media.camera 2>/dev/null | grep -A10 "virtual/0 (" | grep "FULL\|LEVEL" | head -1)
|
||||
L1=$(dumpsys media.camera 2>/dev/null | grep -A10 "virtual/1 (" | grep "FULL\|LEVEL" | head -1)
|
||||
echo "Camera0: Facing=$F0 Level=$L0"
|
||||
echo "Camera1: Facing=$F1 Level=$L1"
|
||||
echo "Full dump: /data/local/tmp/cam_dump.txt"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {status|start|stop|restart|start_feeder|stop_feeder|get_config|validate|device_info}"
|
||||
echo "Usage: $0 {status|start|stop|restart|start_feeder|stop_feeder|get_config|validate}"
|
||||
;;
|
||||
esac
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ cp "$MODDIR/vendor/bin/virtual_camera_provider" "$PROVIDER_DST" 2>/dev/null || t
|
||||
chmod 755 "$PROVIDER_DST" 2>/dev/null || true
|
||||
cp "$MODDIR/vendor/lib64"/*.so "$LIB_DST/" 2>/dev/null || true
|
||||
|
||||
# Start provider in background (failure won't block boot)
|
||||
# Start provider in background (always at boot, disable flag is for runtime only)
|
||||
if [ -x "$PROVIDER_DST" ]; then
|
||||
nohup env LD_LIBRARY_PATH="$LIB_DST" "$PROVIDER_DST" -d /dev/video0 -w 1920 -h 1080 -i virtual </dev/null >/dev/null 2>&1 &
|
||||
echo "[$(date)] provider started"
|
||||
|
||||
+25
-22
@@ -4,6 +4,7 @@ PROVIDER_DST="/data/local/tmp/virtual_camera_provider"
|
||||
LIB_DST="/data/local/tmp/virtualcam_libs"
|
||||
BOOT_LOG="$MODDIR/boot.log"
|
||||
MODULE_PROP="$MODDIR/module.prop"
|
||||
DISABLE_FLAG="/data/local/tmp/virtualcam_disabled"
|
||||
|
||||
log() {
|
||||
echo "[$(date)] $*" >> "$BOOT_LOG"
|
||||
@@ -11,34 +12,35 @@ log() {
|
||||
|
||||
log "service.sh starting"
|
||||
|
||||
# Clear any stale disable flag from a previous session
|
||||
# This ensures the module always starts fresh after boot
|
||||
rm -f /data/local/tmp/virtualcam_disabled
|
||||
|
||||
# Wait for boot to settle
|
||||
sleep 30
|
||||
|
||||
# Load v4l2loopback if not already loaded (safe here, boot is complete)
|
||||
# Load v4l2loopback if not already loaded
|
||||
if ! lsmod 2>/dev/null | grep -q v4l2loopback; then
|
||||
log "service: loading v4l2loopback"
|
||||
insmod "$MODDIR/v4l2loopback.ko" devices=2 video_nr=0,1 card_label="VirtualCam" exclusive_caps=0 2>/dev/null && \
|
||||
log "service: v4l2loopback loaded" || log "service: v4l2loopback load failed"
|
||||
fi
|
||||
|
||||
# Configure v4l2loopback for seamless loop transitions:
|
||||
# sustain_framerate=1 repeats the last written frame when the writer pauses
|
||||
# timeout=0 prevents kernel from injecting black timeout images
|
||||
sleep 2 # Wait for device nodes to appear
|
||||
# Configure v4l2loopback
|
||||
sleep 2
|
||||
if [ -c /dev/video0 ]; then
|
||||
v4l2-ctl -d /dev/video0 -c sustain_framerate=1 >/dev/null 2>&1 || true
|
||||
v4l2-ctl -d /dev/video0 -c timeout=0 >/dev/null 2>&1 || true
|
||||
log "service: v4l2loopback configured (sustain_framerate=1, timeout=0)"
|
||||
log "service: v4l2loopback configured"
|
||||
fi
|
||||
|
||||
# Start feeder FIRST so /dev/video0 has a format set before provider starts
|
||||
# This prevents mmap EACCES in V4L2 reader
|
||||
# Start feeder then provider at boot (unless disabled flag exists)
|
||||
if [ ! -f "$DISABLE_FLAG" ]; then
|
||||
if [ -f "/data/local/tmp/virtualcam_config.json" ]; then
|
||||
log "service: starting feeder before provider"
|
||||
/system/bin/sh "$MODDIR/control.sh" start_feeder >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# Now start provider (feeder already writing, so mmap will succeed)
|
||||
if ! pgrep -f virtual_camera_provider >/dev/null 2>&1 && [ -x "$PROVIDER_DST" ]; then
|
||||
log "service: starting provider"
|
||||
nohup env LD_LIBRARY_PATH="$LIB_DST" "$PROVIDER_DST" \
|
||||
@@ -46,6 +48,9 @@ if ! pgrep -f virtual_camera_provider >/dev/null 2>&1 && [ -x "$PROVIDER_DST" ];
|
||||
</dev/null >/dev/null 2>&1 &
|
||||
log "service: provider launched"
|
||||
fi
|
||||
else
|
||||
log "service: disabled flag exists, skipping auto-start"
|
||||
fi
|
||||
|
||||
# Periodic watchdog + description update
|
||||
while true; do
|
||||
@@ -54,7 +59,6 @@ while true; do
|
||||
V4L2=$(lsmod 2>/dev/null | grep -q v4l2loopback && echo 1 || echo 0)
|
||||
SVC=$(service list 2>/dev/null | grep -q "virtual/0" && echo 1 || echo 0)
|
||||
|
||||
# Determine status
|
||||
if [ -n "$PROVIDER_PID" ] && [ "$SVC" = "1" ]; then
|
||||
STATUS="active"
|
||||
elif [ -n "$PROVIDER_PID" ] || [ "$SVC" = "1" ]; then
|
||||
@@ -78,21 +82,21 @@ while true; do
|
||||
fi
|
||||
fi
|
||||
|
||||
# Restart provider if dead
|
||||
if [ -z "$PROVIDER_PID" ] && [ -x "$PROVIDER_DST" ]; then
|
||||
log "service: provider died, restarting"
|
||||
nohup env LD_LIBRARY_PATH="$LIB_DST" "$PROVIDER_DST" \
|
||||
-d /dev/video0 -w 1920 -h 1080 -i virtual \
|
||||
</dev/null >/dev/null 2>&1 &
|
||||
fi
|
||||
|
||||
# Auto-start feeder if not running and config exists
|
||||
# Only auto-restart if not disabled
|
||||
if [ ! -f "$DISABLE_FLAG" ] && [ ! -f "/data/local/tmp/virtualcam_feeder_disabled" ]; then
|
||||
if [ -z "$FEEDER_PID" ] && [ -f "/data/local/tmp/virtualcam_config.json" ]; then
|
||||
log "service: auto-starting feeder"
|
||||
/system/bin/sh "$MODDIR/control.sh" start_feeder >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Memory check: kill provider/feeder if RSS exceeds 512MB (safety limit)
|
||||
if [ -z "$FEEDER_PID" ] && [ -f "/data/local/tmp/virtualcam_config.json" ]; then
|
||||
log "service: auto-starting feeder"
|
||||
/system/bin/sh "$MODDIR/control.sh" start_feeder >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Memory check
|
||||
for pid in $PROVIDER_PID $FEEDER_PID; do
|
||||
[ -z "$pid" ] && continue
|
||||
rss_kb=$(cat /proc/$pid/status 2>/dev/null | grep VmRSS | awk '{print $2}')
|
||||
@@ -102,14 +106,13 @@ while true; do
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if stock HAL came back and kill it
|
||||
# Kill stock HAL if it reappears
|
||||
STOCK_PIDS=$(ps -A | grep -i "camera.provider" | grep -v "virtual_camera_provider" | awk '{print $1}')
|
||||
if [ -n "$STOCK_PIDS" ]; then
|
||||
for pid in $STOCK_PIDS; do
|
||||
log "service: killing stock HAL PID $pid"
|
||||
kill -9 "$pid" 2>/dev/null || true
|
||||
done
|
||||
# Try to stop the service via property if possible
|
||||
setprop ctl.stop vendor.camera-provider-2-7-google 2>/dev/null || true
|
||||
setprop ctl.stop vendor.camera-provider-pixel 2>/dev/null || true
|
||||
fi
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+2
-1
@@ -3,9 +3,11 @@
|
||||
<div class="card"><div class="card-title">Status</div><div id="status-msg" style="font-size:11px;color:#f85149;margin-bottom:6px"></div><div class="dashboard" id="status-dash"></div></div>
|
||||
<div class="card"><div class="card-title">Video Source</div><div class="source-selector">
|
||||
<button class="src-btn active" data-src="rtsp">RTSP</button>
|
||||
<button class="src-btn" data-src="tcp">TCP</button>
|
||||
<button class="src-btn" data-src="mp4">MP4</button>
|
||||
</div>
|
||||
<div id="rtsp-config"><label>RTSP URL</label><input type="text" id="rtsp-url" placeholder="rtsp://192.168.1.100:8554/stream"></div>
|
||||
<div id="tcp-config" class="hidden"><label>TCP URL</label><input type="text" id="tcp-url" placeholder="tcp://192.168.1.100:5000"></div>
|
||||
<div id="mp4-config" class="hidden"><label>MP4 Path</label><input type="text" id="mp4-path" placeholder="/sdcard/Download/video.mp4"></div>
|
||||
<div class="row"><div><label>Width</label><input type="number" id="res-w" value="1920" class="num"></div><div><label>Height</label><input type="number" id="res-h" value="1080" class="num"></div><div><label>FPS</label><input type="number" id="fps" value="30" class="num"></div></div>
|
||||
<div class="row"><div><label>Rotation</label><select id="rotation" class="num"><option value="0">0</option><option value="90">90</option><option value="180">180</option><option value="270">270</option></select></div></div>
|
||||
@@ -19,6 +21,5 @@
|
||||
<button id="btn-unfeed" class="btn danger">Stop Feeder</button>
|
||||
<button id="btn-refresh" class="btn">Refresh</button>
|
||||
</div></div>
|
||||
<div class="card"><div class="card-title">Device Info <button id="btn-deviceinfo" class="btn-sm">Refresh</button></div><div id="device-info" class="device-info"><p class="muted">Tap Refresh to load</p></div></div>
|
||||
<div class="card"><div class="card-title">Log <span id="log-count" class="log-count"></span></div><div id="console" class="console"></div></div>
|
||||
</div><script src="script.js"></script></body></html>
|
||||
|
||||
+40
-25
@@ -4,50 +4,65 @@ function log(m,t){const e=document.getElementById('console');if(!e)return;const
|
||||
function run(a){try{ksu.exec(CMD+' '+a);log(a+' OK','ok')}catch(e){log(a+' error: '+e.message,'err')}updateDash()}
|
||||
function updateDash(){try{
|
||||
const r=typeof ksu!=='undefined'?ksu.exec(CMD+' status'):null;
|
||||
if(!r||typeof r!=='string'){document.getElementById('status-dash').innerHTML='<div class="stat" style="grid-column:1/3;color:#f85149">No data</div>';return}
|
||||
if(!r||typeof r!=='string'){document.getElementById('status-dash').innerHTML='<div style="grid-column:1/3;color:#f85149;text-align:center;padding:12px">No data</div>';return}
|
||||
const s=JSON.parse(r);
|
||||
const d=document.getElementById('status-dash');if(!d)return;
|
||||
const sc=s.status==='active'?'green':(s.status==='partial'?'yellow':'red');
|
||||
const st=s.status==='active'?'ACTIVE':(s.status==='partial'?'PARTIAL':'STOPPED');
|
||||
let v=[];
|
||||
if(s.camera2_level) v=[['camera2','green',s.camera2_level],['Checks',s.checks&&s.checks.includes('provider_ok')?'green':'red',s.checks||'?']];
|
||||
d.innerHTML=[['Status',sc,st],['Provider',s.provider_pid>0?'green':'red',s.provider_pid>0?'PID '+s.provider_pid:'Stopped'],['Feeder',s.feeder_pid>0?'green':'red',s.feeder_pid>0?'PID '+s.feeder_pid:'Stopped'],['Service',s.service_registered==1?'green':'red',s.service_registered==1?'Registered':'Missing'],['v4l2',s.v4l2_loaded==1?'green':'red',s.v4l2_loaded==1?'Loaded':'Missing'],['Device','yellow',s.video0||'N/A'],...v].map(i=>`<div class="stat"><span class="l">${i[0]}</span><span class="v ${i[1]}">${i[2]}</span></div>`).join('');
|
||||
document.getElementById('subtitle').textContent=s.status==='active'?'Feeding video to /dev/video0':'Physical cameras NOT replaced';
|
||||
const colorMap={active:'green',partial:'yellow',stopped:'red',idle:'red'};
|
||||
const sc=colorMap[s.status]||'yellow';
|
||||
const st=s.status.toUpperCase();
|
||||
d.innerHTML=[['Status',sc,st],['Provider',s.provider_pid>0?'green':'red',s.provider_pid>0?'PID '+s.provider_pid:'Stopped'],['Feeder',s.feeder_pid>0?'green':'red',s.feeder_pid>0?'PID '+s.feeder_pid:'Stopped'],['Service',s.service_registered==1?'green':'red',s.service_registered==1?'Registered':'Missing'],['v4l2',s.v4l2_loaded==1?'green':'red',s.v4l2_loaded==1?'Loaded':'Missing'],['Device','yellow',s.video0||'N/A']].map(i=>`<div class="stat"><span class="l">${i[0]}</span><span class="v ${i[1]}">${i[2]}</span></div>`).join('');
|
||||
document.getElementById('subtitle').textContent=s.status==='active'?'Physical cameras replaced':s.status==='partial'?'Starting up...':'Not running';
|
||||
// Toggle buttons based on state
|
||||
document.getElementById('btn-start').style.display=s.provider_pid>0?'none':'block';
|
||||
document.getElementById('btn-stop').style.display=s.provider_pid>0?'block':'none';
|
||||
document.getElementById('btn-restart').style.display=s.provider_pid>0?'block':'none';
|
||||
document.getElementById('btn-feed').style.display=s.feeder_pid>0?'none':'block';
|
||||
document.getElementById('btn-unfeed').style.display=s.feeder_pid>0?'block':'none';
|
||||
if(s.status!==_ps||s.provider_pid!==_pp||s.feeder_pid!==_pf){_ps=s.status;_pp=s.provider_pid;_pf=s.feeder_pid;log('Status: '+st+' pid='+s.provider_pid+' feeder='+s.feeder_pid,'ok')}
|
||||
}catch(e){log('Dash error: '+e.message,'err')}}
|
||||
function loadDeviceInfo(){try{
|
||||
const r=ksu.exec(CMD+' device_info');
|
||||
document.getElementById('device-info').innerHTML=r?'<pre style="background:#0d1117;border:1px solid #30363d;border-radius:4px;padding:8px;font-size:10px;overflow-x:auto;white-space:pre-wrap">'+r.replace(/</g,'<').replace(/>/g,'>')+'</pre>':'<p class="muted">No data</p>';
|
||||
log('Device info loaded','ok');
|
||||
}catch(e){log('DevInfo error: '+e.message,'err')}}
|
||||
document.getElementById('btn-start')?.addEventListener('click',()=>run('start'));
|
||||
document.getElementById('btn-stop')?.addEventListener('click',()=>run('stop'));
|
||||
document.getElementById('btn-restart')?.addEventListener('click',()=>run('restart'));
|
||||
document.getElementById('btn-feed')?.addEventListener('click',()=>run('start_feeder'));
|
||||
document.getElementById('btn-unfeed')?.addEventListener('click',()=>run('stop_feeder'));
|
||||
document.getElementById('btn-refresh')?.addEventListener('click',updateDash);
|
||||
document.getElementById('btn-save')?.addEventListener('click',()=>{
|
||||
const src=document.querySelector('.src-btn.active')?.dataset.src||'mp4';
|
||||
const json=JSON.stringify({source_type:src,rtsp_url:document.getElementById('rtsp-url').value,mp4_path:document.getElementById('mp4-path').value,res_w:parseInt(document.getElementById('res-w').value)||1920,res_h:parseInt(document.getElementById('res-h').value)||1080,fps:parseInt(document.getElementById('fps').value)||30,rotation:parseInt(document.getElementById('rotation').value)||0});
|
||||
const json=JSON.stringify({source_type:src,rtsp_url:document.getElementById('rtsp-url').value,tcp_url:document.getElementById('tcp-url').value,mp4_path:document.getElementById('mp4-path').value,res_w:parseInt(document.getElementById('res-w').value)||1920,res_h:parseInt(document.getElementById('res-h').value)||1080,fps:parseInt(document.getElementById('fps').value)||30,rotation:parseInt(document.getElementById('rotation').value)||0});
|
||||
ksu.exec("echo '"+json+"' > /data/local/tmp/virtualcam_config.json");
|
||||
log('Config saved','ok');
|
||||
// Restart feeder with new config if running
|
||||
try {
|
||||
const st = JSON.parse(ksu.exec(CMD+' status')||'{}');
|
||||
if (st.feeder_pid > 0) {
|
||||
ksu.exec(CMD+' stop_feeder');
|
||||
setTimeout(function(){ksu.exec(CMD+' start_feeder');log('Feeder restarted','ok');},2000);
|
||||
}
|
||||
} catch(e) {}
|
||||
});
|
||||
document.getElementById('btn-refresh')?.addEventListener('click',updateDash);
|
||||
document.getElementById('btn-deviceinfo')?.addEventListener('click',loadDeviceInfo);
|
||||
document.querySelectorAll('.src-btn').forEach(b=>b.addEventListener('click',()=>{
|
||||
document.querySelectorAll('.src-btn').forEach(x=>x.classList.remove('active'));
|
||||
b.classList.add('active');
|
||||
document.getElementById('rtsp-config').classList.toggle('hidden',b.dataset.src!=='rtsp');
|
||||
document.getElementById('mp4-config').classList.toggle('hidden',b.dataset.src!=='mp4');
|
||||
}));
|
||||
updateDash();
|
||||
setInterval(updateDash,5000);
|
||||
document.getElementById('btn-refresh')?.addEventListener('click',updateDash);
|
||||
document.getElementById('btn-deviceinfo')?.addEventListener('click',loadDeviceInfo);
|
||||
document.querySelectorAll('.src-btn').forEach(b=>b.addEventListener('click',()=>{
|
||||
document.querySelectorAll('.src-btn').forEach(x=>x.classList.remove('active'));
|
||||
b.classList.add('active');
|
||||
document.getElementById('rtsp-config').classList.toggle('hidden',b.dataset.src!=='rtsp');
|
||||
document.getElementById('tcp-config').classList.toggle('hidden',b.dataset.src!=='tcp');
|
||||
document.getElementById('mp4-config').classList.toggle('hidden',b.dataset.src!=='mp4');
|
||||
}));
|
||||
// Load saved config into UI fields
|
||||
try {
|
||||
const cfg = JSON.parse(ksu.exec(CMD+' get_config')||'{}');
|
||||
if (cfg.source_type) {
|
||||
document.querySelectorAll('.src-btn').forEach(b => b.classList.toggle('active', b.dataset.src === cfg.source_type));
|
||||
document.getElementById('rtsp-config').classList.toggle('hidden', cfg.source_type !== 'rtsp');
|
||||
document.getElementById('tcp-config').classList.toggle('hidden', cfg.source_type !== 'tcp');
|
||||
document.getElementById('mp4-config').classList.toggle('hidden', cfg.source_type !== 'mp4');
|
||||
}
|
||||
if (cfg.rtsp_url) document.getElementById('rtsp-url').value = cfg.rtsp_url;
|
||||
if (cfg.tcp_url) document.getElementById('tcp-url').value = cfg.tcp_url;
|
||||
if (cfg.mp4_path) document.getElementById('mp4-path').value = cfg.mp4_path;
|
||||
if (cfg.res_w) document.getElementById('res-w').value = cfg.res_w;
|
||||
if (cfg.res_h) document.getElementById('res-h').value = cfg.res_h;
|
||||
if (cfg.fps) document.getElementById('fps').value = cfg.fps;
|
||||
if (cfg.rotation) document.getElementById('rotation').value = cfg.rotation;
|
||||
} catch(e) {}
|
||||
updateDash();
|
||||
setInterval(updateDash,5000);
|
||||
|
||||
Reference in New Issue
Block a user