fix:移动文件位置

This commit is contained in:
nnbcccscdscdsc
2026-03-31 20:54:37 +08:00
parent 771829d99d
commit dcb50219dd
5 changed files with 82 additions and 135 deletions

View File

@@ -18,7 +18,9 @@ JPEG_FRAME_DIR = WORKSPACE_ROOT / "RobotDataShow" / "jpeg-frames"
GEOSTREAM_JSON_PATH = WORKSPACE_ROOT / "GeoStream" / "gps_latest.json"
GEOSTREAM_STALE_SECONDS = 15
SAMPLE_CDATA_DIR = PROJECT_ROOT / "SampleCData"
OMNISOCKET_CONFIG_PATH = SAMPLE_CDATA_DIR / "config" / "omnisocket_demo.yaml"
CONFIG_DIR = PROJECT_ROOT / "config"
PRIMARY_OMNISOCKET_CONFIG_PATH = CONFIG_DIR / "omnisocket_demo.yaml"
LEGACY_OMNISOCKET_CONFIG_PATH = SAMPLE_CDATA_DIR / "config" / "omnisocket_demo.yaml"
VIDEO_SOURCE_MODE = os.getenv("VIDEO_SOURCE_MODE", "auto").strip().lower()
OMNISOCKET_FRAME_FRESH_SECONDS = 2.0
@@ -27,6 +29,12 @@ def utc_iso_now() -> str:
return datetime.now(UTC).isoformat(timespec="seconds").replace("+00:00", "Z")
def resolve_omnisocket_config_path() -> Path:
if PRIMARY_OMNISOCKET_CONFIG_PATH.exists():
return PRIMARY_OMNISOCKET_CONFIG_PATH
return LEGACY_OMNISOCKET_CONFIG_PATH
class OmniSocketVideoReceiver:
def __init__(self) -> None:
self._lock = threading.Lock()
@@ -88,16 +96,17 @@ class OmniSocketVideoReceiver:
# transport + video_receiver。
# 即使配置文件不存在,也允许回退到默认值继续运行。
config: dict[str, Any] = {}
if OMNISOCKET_CONFIG_PATH.exists():
config_path = resolve_omnisocket_config_path()
if config_path.exists():
try:
try:
import yaml # type: ignore
with OMNISOCKET_CONFIG_PATH.open("r", encoding="utf-8") as file:
with config_path.open("r", encoding="utf-8") as file:
config = yaml.safe_load(file) or {}
except ImportError:
# 如果当前环境没有 PyYAML就用一个足够支撑当前 demo 配置的简化解析器。
config = self._load_simple_yaml_config(OMNISOCKET_CONFIG_PATH)
config = self._load_simple_yaml_config(config_path)
except Exception as error: # pragma: no cover - 可选依赖
self._last_error = f"config load failed: {error}"
@@ -268,6 +277,7 @@ class OmniSocketVideoReceiver:
def get_status(self) -> dict[str, Any]:
self.ensure_started()
config = self._load_config()
config_path = resolve_omnisocket_config_path()
transport_cfg = config.get("transport", {})
video_cfg = config.get("video_receiver", {})
with self._lock:
@@ -282,7 +292,7 @@ class OmniSocketVideoReceiver:
"frames_received": self._frames_received,
"latest_sequence": self._latest_sequence,
"last_error": self._last_error,
"config_path": str(OMNISOCKET_CONFIG_PATH),
"config_path": str(config_path),
"server_addr": str(transport_cfg.get("server_addr", "")),
"relay_via": str(transport_cfg.get("relay_via", "")),
"peer_id": str(video_cfg.get("peer_id", "")),