The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/vive: Fallback to v4l2 camera timestamps when lighthouse is on

The pulse 0xFD of the report 0x25 comes at 54hz and thus we are assuming its
timestamp are the camera frame timestamps. However, it seems that this report
stops coming when the lighthouses are enabled and instead we get a 0x28 report.
This commit silently handles the 0x28 instead of throwing errors and fallbacks
to using v4l2 timestamps instead of the previous timestamps from pulse 0xFD.

authored by

Mateo de Mayo and committed by
Jakob Bornecrantz
5503d75c 642549b5

+19 -4
+7 -1
src/xrt/drivers/vive/vive_device.c
··· 548 548 } 549 549 550 550 if (sensor_id == 0xfd) { // Camera frame timestamp 551 - vive_source_push_frame_ticks(d->source, pulse->timestamp); 551 + vive_source_push_frame_ticks(d->source, timestamp); 552 552 continue; 553 553 } 554 554 ··· 579 579 case VIVE_HEADSET_LIGHTHOUSE_PULSE_REPORT_ID: return "VIVE_HEADSET_LIGHTHOUSE_PULSE_REPORT_ID"; 580 580 case VIVE_CONTROLLER_LIGHTHOUSE_PULSE_REPORT_ID: return "VIVE_CONTROLLER_LIGHTHOUSE_PULSE_REPORT_ID"; 581 581 case VIVE_HEADSET_LIGHTHOUSE_V2_PULSE_REPORT_ID: return "VIVE_HEADSET_LIGHTHOUSE_V2_PULSE_REPORT_ID"; 582 + case VIVE_HEADSET_LIGHTHOUSE_V2_PULSE_RAW_REPORT_ID: return "VIVE_HEADSET_LIGHTHOUSE_V2_PULSE_RAW_REPORT_ID"; 582 583 default: return "Unknown"; 583 584 } 584 585 } ··· 728 729 if (!_is_report_size_valid(d, ret, 59, buffer[0])) 729 730 return false; 730 731 if (!_print_pulse_report_v2(d, buffer)) 732 + return false; 733 + break; 734 + case VIVE_HEADSET_LIGHTHOUSE_V2_PULSE_RAW_REPORT_ID: 735 + // Report starts coming when lighthouses are in sight 736 + if (!_is_report_size_valid(d, ret, 64, buffer[0])) 731 737 return false; 732 738 break; 733 739 default:
+7
src/xrt/drivers/vive/vive_protocol.h
··· 286 286 287 287 } __attribute__((packed)); 288 288 289 + #define VIVE_HEADSET_LIGHTHOUSE_V2_PULSE_RAW_REPORT_ID 0x28 290 + 291 + struct vive_headset_lighthouse_v2_pulse_raw_report 292 + { 293 + uint8_t unknown[64]; 294 + } __attribute__((packed)); 295 + 289 296 struct vive_headset_lighthouse_pulse 290 297 { 291 298 uint8_t id;
+5 -3
src/xrt/drivers/vive/vive_source.c
··· 73 73 if (vive_ts_count == 0) { // This seems to happen in some runs 74 74 // This code assumes vive_timestamps will always be populated before v4l2 75 75 // receives a frame, thus if we reach this, this assumption has failed. 76 - VIVE_ERROR(vs, "Received a v4l2 frame but thwere are no vive timestamps to use"); 77 - VIVE_ERROR(vs, "Will continue, but frame timestamps could be off by one"); 78 - return false; 76 + // As a fallback we'll use the v4l2 timestamp corrected to monotonic clock. 77 + VIVE_TRACE(vs, "No vive timestamps available for this v4l2 frame, will use v4l2 timestamp"); 78 + timepoint_ns hw_ts = v4l2_ts - vs->hw2v4l2; 79 + xf->timestamp = hw_ts + vs->hw2mono; 80 + return true; 79 81 } 80 82 81 83 os_mutex_lock(vive_timestamps_lock);