Spaces:
Sleeping
Sleeping
Zhen Ye
commited on
Commit
路
19fdabe
1
Parent(s):
78d352c
Fix video playback race condition, local file protocol, and backend worker crash
Browse files- frontend/js/core/video.js +2 -2
- frontend/js/main.js +25 -9
- inference.py +15 -0
frontend/js/core/video.js
CHANGED
|
@@ -246,7 +246,7 @@ APP.core.video.fetchDepthVideo = async function () {
|
|
| 246 |
throw new Error(`Failed to fetch depth video: ${resp.statusText}`);
|
| 247 |
}
|
| 248 |
|
| 249 |
-
const nullOrigin = (window.location && window.location.origin) === "null";
|
| 250 |
if (nullOrigin) {
|
| 251 |
state.hf.depthBlob = null;
|
| 252 |
state.hf.depthVideoUrl = `${state.hf.depthVideoUrl}?t=${Date.now()}`;
|
|
@@ -311,7 +311,7 @@ APP.core.video.fetchProcessedVideo = async function () {
|
|
| 311 |
throw new Error(`Failed to fetch video: ${resp.statusText}`);
|
| 312 |
}
|
| 313 |
|
| 314 |
-
const nullOrigin = (window.location && window.location.origin) === "null";
|
| 315 |
if (nullOrigin) {
|
| 316 |
state.hf.processedBlob = null;
|
| 317 |
state.hf.processedUrl = `${state.hf.videoUrl}?t=${Date.now()}`;
|
|
|
|
| 246 |
throw new Error(`Failed to fetch depth video: ${resp.statusText}`);
|
| 247 |
}
|
| 248 |
|
| 249 |
+
const nullOrigin = (window.location && window.location.origin) === "null" || (window.location && window.location.protocol === "file:");
|
| 250 |
if (nullOrigin) {
|
| 251 |
state.hf.depthBlob = null;
|
| 252 |
state.hf.depthVideoUrl = `${state.hf.depthVideoUrl}?t=${Date.now()}`;
|
|
|
|
| 311 |
throw new Error(`Failed to fetch video: ${resp.statusText}`);
|
| 312 |
}
|
| 313 |
|
| 314 |
+
const nullOrigin = (window.location && window.location.origin) === "null" || (window.location && window.location.protocol === "file:");
|
| 315 |
if (nullOrigin) {
|
| 316 |
state.hf.processedBlob = null;
|
| 317 |
state.hf.processedUrl = `${state.hf.videoUrl}?t=${Date.now()}`;
|
frontend/js/main.js
CHANGED
|
@@ -470,21 +470,27 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 470 |
log("Video processing complete.", "g");
|
| 471 |
// Stop streaming mode once video is ready
|
| 472 |
stopStreamingMode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
}).catch(err => {
|
| 474 |
log(`Polling error: ${err.message}`, "e");
|
| 475 |
stopStreamingMode();
|
| 476 |
});
|
| 477 |
|
| 478 |
-
|
| 479 |
-
setStatus("
|
| 480 |
-
log("
|
| 481 |
|
| 482 |
-
// Seed tracks for Tab 2
|
| 483 |
-
seedTracksFromTab1();
|
| 484 |
-
renderFrameRadar();
|
| 485 |
|
| 486 |
-
// Generate intel summary (async)
|
| 487 |
-
computeIntelSummary();
|
| 488 |
|
| 489 |
} catch (err) {
|
| 490 |
setStatus("bad", "ERROR 路 Reason failed");
|
|
@@ -614,6 +620,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 614 |
return;
|
| 615 |
}
|
| 616 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
// Switch to engage tab
|
| 618 |
const engageTab = $(`.tabbtn[data-tab="engage"]`);
|
| 619 |
if (engageTab) engageTab.click();
|
|
@@ -621,7 +635,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 621 |
// Set video source
|
| 622 |
if (videoEngage) {
|
| 623 |
videoEngage.src = state.hf.processedUrl || state.videoUrl;
|
| 624 |
-
videoEngage.play()
|
|
|
|
|
|
|
| 625 |
}
|
| 626 |
|
| 627 |
state.tracker.running = true;
|
|
|
|
| 470 |
log("Video processing complete.", "g");
|
| 471 |
// Stop streaming mode once video is ready
|
| 472 |
stopStreamingMode();
|
| 473 |
+
|
| 474 |
+
state.hasReasoned = true;
|
| 475 |
+
setStatus("good", "READY 路 Reason complete (you can Engage)");
|
| 476 |
+
log("Reason complete. Ready to Engage.", "g");
|
| 477 |
+
|
| 478 |
+
// Seed tracks for Tab 2
|
| 479 |
+
seedTracksFromTab1();
|
| 480 |
+
renderFrameRadar();
|
| 481 |
+
|
| 482 |
+
// Generate intel summary (async)
|
| 483 |
+
computeIntelSummary();
|
| 484 |
}).catch(err => {
|
| 485 |
log(`Polling error: ${err.message}`, "e");
|
| 486 |
stopStreamingMode();
|
| 487 |
});
|
| 488 |
|
| 489 |
+
// Initial status (processing in background)
|
| 490 |
+
setStatus("warn", "PROCESSING 路 Analysing video...");
|
| 491 |
+
log("Reasoning started (processing in background)...", "t");
|
| 492 |
|
|
|
|
|
|
|
|
|
|
| 493 |
|
|
|
|
|
|
|
| 494 |
|
| 495 |
} catch (err) {
|
| 496 |
setStatus("bad", "ERROR 路 Reason failed");
|
|
|
|
| 620 |
return;
|
| 621 |
}
|
| 622 |
|
| 623 |
+
if (state.hf.asyncJobId) {
|
| 624 |
+
log("Processing still in progress. Please wait.", "w");
|
| 625 |
+
// If we are streaming, make sure we are on the engage tab to see it
|
| 626 |
+
const engageTab = $(`.tabbtn[data-tab="engage"]`);
|
| 627 |
+
if (engageTab) engageTab.click();
|
| 628 |
+
return;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
// Switch to engage tab
|
| 632 |
const engageTab = $(`.tabbtn[data-tab="engage"]`);
|
| 633 |
if (engageTab) engageTab.click();
|
|
|
|
| 635 |
// Set video source
|
| 636 |
if (videoEngage) {
|
| 637 |
videoEngage.src = state.hf.processedUrl || state.videoUrl;
|
| 638 |
+
videoEngage.play().catch(err => {
|
| 639 |
+
log(`Video playback failed: ${err.message}`, "e");
|
| 640 |
+
});
|
| 641 |
}
|
| 642 |
|
| 643 |
state.tracker.running = true;
|
inference.py
CHANGED
|
@@ -1328,6 +1328,11 @@ def run_inference(
|
|
| 1328 |
queue_in.put((frames_fed, frame)) # Blocks if full
|
| 1329 |
frames_fed += 1
|
| 1330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1331 |
# Signal workers to stop
|
| 1332 |
for _ in range(num_workers):
|
| 1333 |
try:
|
|
@@ -1565,6 +1570,11 @@ def run_segmentation(
|
|
| 1565 |
queue_in.put((frames_fed, frame))
|
| 1566 |
frames_fed += 1
|
| 1567 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1568 |
for _ in workers:
|
| 1569 |
try: queue_in.put(None, timeout=5.0)
|
| 1570 |
except Full: pass
|
|
@@ -1899,6 +1909,11 @@ def run_depth_inference(
|
|
| 1899 |
queue_in.put((frames_fed, frame))
|
| 1900 |
frames_fed += 1
|
| 1901 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1902 |
for _ in workers:
|
| 1903 |
try: queue_in.put(None, timeout=5.0)
|
| 1904 |
except Full: pass
|
|
|
|
| 1328 |
queue_in.put((frames_fed, frame)) # Blocks if full
|
| 1329 |
frames_fed += 1
|
| 1330 |
|
| 1331 |
+
# Update total_frames to actual count so writer knows when to stop
|
| 1332 |
+
if frames_fed != total_frames:
|
| 1333 |
+
logging.info("Updating total_frames from %d to %d (actual fed)", total_frames, frames_fed)
|
| 1334 |
+
total_frames = frames_fed
|
| 1335 |
+
|
| 1336 |
# Signal workers to stop
|
| 1337 |
for _ in range(num_workers):
|
| 1338 |
try:
|
|
|
|
| 1570 |
queue_in.put((frames_fed, frame))
|
| 1571 |
frames_fed += 1
|
| 1572 |
|
| 1573 |
+
# Update total_frames to actual count
|
| 1574 |
+
if frames_fed != total_frames:
|
| 1575 |
+
logging.info("Updating total_frames from %d to %d (actual fed)", total_frames, frames_fed)
|
| 1576 |
+
total_frames = frames_fed
|
| 1577 |
+
|
| 1578 |
for _ in workers:
|
| 1579 |
try: queue_in.put(None, timeout=5.0)
|
| 1580 |
except Full: pass
|
|
|
|
| 1909 |
queue_in.put((frames_fed, frame))
|
| 1910 |
frames_fed += 1
|
| 1911 |
|
| 1912 |
+
# Update total_frames to actual count
|
| 1913 |
+
if frames_fed != total_frames:
|
| 1914 |
+
logging.info("Updating total_frames from %d to %d (actual fed)", total_frames, frames_fed)
|
| 1915 |
+
total_frames = frames_fed
|
| 1916 |
+
|
| 1917 |
for _ in workers:
|
| 1918 |
try: queue_in.put(None, timeout=5.0)
|
| 1919 |
except Full: pass
|