fix(record): fall back to millimeter for unknown depth unit

This commit is contained in:
2026-03-12 11:00:25 +08:00
parent 59ff8b79d9
commit a21d4b6769
3 changed files with 81 additions and 26 deletions
+17 -11
View File
@@ -192,6 +192,14 @@ bool frame_info_equal(const ipc::FrameInfo &lhs, const ipc::FrameInfo &rhs) {
lhs.buffer_size == rhs.buffer_size;
}
[[nodiscard]]
ipc::DepthUnit normalize_depth_unit_for_recording(ipc::DepthUnit unit) {
if (unit == ipc::DepthUnit::Unknown) {
return ipc::DepthUnit::Millimeter;
}
return unit;
}
[[nodiscard]]
std::expected<record::RawDepthMapView, std::string> make_depth_map_view(const ipc::CoherentSnapshot &snapshot) {
if (!snapshot.depth_info) {
@@ -200,9 +208,6 @@ std::expected<record::RawDepthMapView, std::string> make_depth_map_view(const ip
if (snapshot.depth.empty()) {
return std::unexpected("depth plane bytes are missing");
}
if (snapshot.depth_unit == ipc::DepthUnit::Unknown) {
return std::unexpected("depth plane unit is unknown");
}
const auto &depth_info = *snapshot.depth_info;
if (depth_info.depth != ipc::Depth::F32 || depth_info.pixel_format != ipc::PixelFormat::GRAY) {
@@ -223,7 +228,7 @@ std::expected<record::RawDepthMapView, std::string> make_depth_map_view(const ip
.timestamp_ns = snapshot.metadata.timestamp_ns,
.width = depth_info.width,
.height = depth_info.height,
.source_unit = snapshot.depth_unit,
.source_unit = normalize_depth_unit_for_recording(snapshot.depth_unit),
.pixels = std::span<const float>(
reinterpret_cast<const float *>(snapshot.depth.data()),
pixel_count),
@@ -551,13 +556,15 @@ int run_pipeline(const RuntimeConfig &config) {
continue;
}
if (mcap_sink.has_value() && !snapshot->depth.empty()) {
if (snapshot->depth_unit == ipc::DepthUnit::Unknown) {
if (!warned_unknown_depth_unit) {
spdlog::warn("pipeline depth plane present but depth_unit is unknown; skipping depth MCAP recording");
warned_unknown_depth_unit = true;
if (mcap_sink.has_value() && !snapshot->depth.empty()) {
if (snapshot->depth_unit == ipc::DepthUnit::Unknown) {
if (!warned_unknown_depth_unit) {
spdlog::warn(
"pipeline depth plane present but depth_unit is unknown; assuming millimeters for MCAP recording, producer should upgrade to the ABI with explicit depth_unit metadata");
warned_unknown_depth_unit = true;
}
}
} else {
auto depth_map = make_depth_map_view(*snapshot);
if (!depth_map) {
const auto reason = "pipeline depth snapshot invalid: " + depth_map.error();
@@ -572,7 +579,6 @@ int run_pipeline(const RuntimeConfig &config) {
continue;
}
}
}
stats.pushed_frames += 1;
auto drain = drain_encoder(