Skip the first JPEG/RAW frame.

* Set BPP to zero in set_pixformat to skip compressing/sending the first frame.
This commit is contained in:
iabdalkader 2016-03-06 02:32:11 +02:00
parent 911f9827ea
commit 87f9c92f1b

View File

@ -314,36 +314,24 @@ int sensor_set_pixformat(pixformat_t pixformat)
{ {
uint32_t jpeg_mode = DCMI_JPEG_DISABLE; uint32_t jpeg_mode = DCMI_JPEG_DISABLE;
// Set BPP to zero to skip the first frame.
fb->bpp = 0;
if (sensor.pixformat == pixformat) { if (sensor.pixformat == pixformat) {
/* no change */ // No change
return 0; return 0;
} }
if (sensor.set_pixformat == NULL if (sensor.set_pixformat == NULL
|| sensor.set_pixformat(&sensor, pixformat) != 0) { || sensor.set_pixformat(&sensor, pixformat) != 0) {
/* operation not supported */ // Operation not supported
return -1; return -1;
} }
/* set pixel format */ // Set pixel format
sensor.pixformat = pixformat; sensor.pixformat = pixformat;
/* set bytes per pixel */ // Set JPEG mode
switch (pixformat) {
case PIXFORMAT_GRAYSCALE:
fb->bpp = 1;
break;
case PIXFORMAT_RGB565:
case PIXFORMAT_YUV422:
fb->bpp = 2;
break;
case PIXFORMAT_JPEG:
fb->bpp = 0;
break;
default:
return -1;
}
if (pixformat == PIXFORMAT_JPEG) { if (pixformat == PIXFORMAT_JPEG) {
jpeg_mode = DCMI_JPEG_ENABLE; jpeg_mode = DCMI_JPEG_ENABLE;
} }
@ -538,10 +526,10 @@ int sensor_snapshot(image_t *image)
volatile uint16_t length; volatile uint16_t length;
uint32_t snapshot_start; uint32_t snapshot_start;
// Compress the framebuffer for the IDE only for non-JPEG // Compress the framebuffer for the IDE only for non-JPEG images and
// images and only if the IDE has requested a framebuffer. // only if the IDE has requested a framebuffer and it's not the first frame.
// Note: This doesn't run unless the camera is connected to PC. // Note: This doesn't run unless the camera is connected to PC.
if (fb->request && sensor.pixformat != PIXFORMAT_JPEG && if (fb->bpp && fb->request && sensor.pixformat != PIXFORMAT_JPEG &&
SENSOR_HW_FLAGS_GET(&sensor, SENSOR_HW_FLAGS_SW_JPEG)) { SENSOR_HW_FLAGS_GET(&sensor, SENSOR_HW_FLAGS_SW_JPEG)) {
// The framebuffer is compressed in place. // The framebuffer is compressed in place.
// Assuming we have at least 128KBs of SRAM. // Assuming we have at least 128KBs of SRAM.
@ -554,15 +542,17 @@ int sensor_snapshot(image_t *image)
fb->bpp = dst.bpp; fb->bpp = dst.bpp;
} }
// Note: fb->bpp is set to zero for the first JPEG frame. // Note: fb->bpp is set to zero for the first frame.
// If BPP is not zero, then we have a valid frame (compressed or raw).
fb->ready = (fb->bpp>0); fb->ready = (fb->bpp>0);
// Wait for the IDE to read the framebuffer before it gets overwritten with a new frame, and // Wait for the IDE to read the framebuffer before it gets overwritten with a new frame, and
// after all the image processing code has run (which possibily draws over the framebuffer). // after all the image processing code has run (which possibily draws over the framebuffer).
//
// This fakes double buffering without having to allocate a second buffer and allows us to // This fakes double buffering without having to allocate a second buffer and allows us to
// re-use the framebuffer for software JPEG compression. // re-use the framebuffer for software JPEG compression.
// Note: This loop is executed only if the USB debug is active and we have a valid frame.
while (fb->ready && fb->request) { while (fb->ready && fb->request) {
// Note: This delay is only executed when the USB debug is active.
systick_sleep(2); systick_sleep(2);
} }
fb->ready = 0; fb->ready = 0;