FLIR: Faster UVC streaming.
@@ -346,7 +346,7 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
}
}
-static int snapshot(sensor_t *sensor, image_t *image, streaming_cb_t cb)
+static int snapshot(sensor_t *sensor, image_t *image, streaming_cb_t streaming_cb)
{
fb_update_jpeg_buffer();
@@ -354,6 +354,10 @@ static int snapshot(sensor_t *sensor, image_t *image, streaming_cb_t cb)
return -1;
}
+ bool frame_ready = false;
+ bool streaming = (streaming_cb != NULL); // Streaming mode.
+
+ do {
// The SPI DMA device is always clocking the FLIR Lepton in the background.
// The code below resets the vospi control values to let data be pulled in.
// If we need to re-sync we do it. Otherwise, after we finish pulling data
@@ -368,7 +372,13 @@ static int snapshot(sensor_t *sensor, image_t *image, streaming_cb_t cb)
if (vospi_resync == true) {
lepton_sync();
}
+ if (frame_ready == true && streaming_cb != NULL) {
+ // Start streaming the frame while a new one is captured.
+ streaming = streaming_cb(image);
+ frame_ready = false;
+ } else {
__WFI();
+ }
} while (vospi_pid < vospi_packets); // only checking one volatile var so atomic.
MAIN_FB()->w = MAIN_FB()->u;
@@ -440,6 +450,8 @@ static int snapshot(sensor_t *sensor, image_t *image, streaming_cb_t cb)
}
}
+ frame_ready = true;
+ } while (streaming && streaming_cb != NULL);
return 0;
}
