Skip to content

Commit acb2adf

Browse files
tcavallaripiedar
authored andcommitted
Improved OpenNI driver
* OpenNI wants the timestamp in microseconds so we have to divide the 60MHz clock timestamp to get the correct value * Input timestamp is a uint32_t, thus overflowing after ~70s. The timestamp now is stored in a uint64_t value, overflows are now handled and the returned time is monotonically increasing. (cherry picked from commit 85a9980) Signed-off-by: Benn Snyder <[email protected]>
1 parent ec0b75d commit acb2adf

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

OpenNI2-FreenectDriver/src/VideoStream.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace FreenectDriver
1111
{
1212
private:
1313
unsigned int frame_id; // number each frame
14+
uint64_t prev_timestamp; // timestamp of the last processed frame
1415

1516
virtual OniStatus setVideoMode(OniVideoMode requested_mode) = 0;
1617
virtual void populateFrame(void* data, OniFrame* frame) const = 0;
@@ -26,6 +27,7 @@ namespace FreenectDriver
2627
public:
2728
VideoStream(Freenect::FreenectDevice* device) :
2829
frame_id(1),
30+
prev_timestamp(0),
2931
device(device),
3032
mirroring(false)
3133
{
@@ -42,11 +44,24 @@ namespace FreenectDriver
4244

4345
OniFrame* frame = getServices().acquireFrame();
4446
frame->frameIndex = frame_id++;
45-
frame->timestamp = timestamp;
4647
frame->videoMode = video_mode;
4748
frame->width = video_mode.resolutionX;
4849
frame->height = video_mode.resolutionY;
4950

51+
// Handle overflow, input timestamp comes from a 60MHz clock and overflows
52+
// in ~70s
53+
if (timestamp < prev_timestamp)
54+
{
55+
uint32_t prev_int = static_cast<uint32_t>(prev_timestamp);
56+
uint64_t temp_delta = std::abs<int64_t>(timestamp - prev_int);
57+
prev_timestamp += temp_delta;
58+
} else {
59+
prev_timestamp = timestamp;
60+
}
61+
62+
// OpenNI wants the value in microseconds
63+
frame->timestamp = prev_timestamp / 60;
64+
5065
populateFrame(data, frame);
5166
raiseNewFrame(frame);
5267
getServices().releaseFrame(frame);

0 commit comments

Comments
 (0)