I see weird behavior in a program that I am writing using the NewTek NDI SDK for receiving video. It basically receives frames from a video source, and I can then handle each frame individually:
void handle_frame(NDIlib_video_frame_v2_t &video_frame)
{
printf(
"Frame received (%dx%d), timestamp: %ld, timecode: %ld, timestamp_ms: %f, timecode_ms: %f, metadata: %s",
video_frame.xres,
video_frame.yres,
video_frame.timestamp,
video_frame.timecode,
(float)video_frame.timestamp / 10000.0f,
(float)video_frame.timecode / 10000.0f,
video_frame.p_metadata
);
}
void receive_frames(NDIlib_recv_instance_t &pNDI_recv)
{
while (true) {
NDIlib_video_frame_v2_t video_frame;
NDIlib_frame_type_e frame_type = NDIlib_recv_capture_v2(pNDI_recv, &video_frame, nullptr, nullptr, 5000);
switch (frame_type) {
case NDIlib_frame_type_video:
handle_frame(video_frame);
NDIlib_recv_free_video_v2(pNDI_recv, &video_frame);
break;
default:
break;
}
}
}
Now, this is the output I get for a few subsequent calls:
Frame received (1920x1080), timestamp: 16170169126246802, timecode: 16170169126639307, timestamp_ms: 1617016913920.000000, timecode_ms: 1617016913920.000000, metadata: (null)
Frame received (1920x1080), timestamp: 16170169126593547, timecode: 16170169126972974, timestamp_ms: 1617016913920.000000, timecode_ms: 1617016913920.000000, metadata: (null)
Frame received (1920x1080), timestamp: 16170169126832240, timecode: 16170169127306641, timestamp_ms: 1617016913920.000000, timecode_ms: 1617016913920.000000, metadata: (null)
Notice that the timestamp/timecode values change on every call, but once I divide them and log them, they are … always the same! They always take the value of the first time I made the division (1617016913920.000000
).
What's even weirder is that they take the same value, despite using timestamp
and timecode
for both.
How can this be? How could the function use the value of a previous call?
Could it be that the video_frame
instance underneath was changed somehow? But how could the other printed values then be correct in the context?
Even when I print the (divided) values directly inside the case
branch, the result is the same.
I feel like I'm missing something obvious here, but I cannot explain it.