diff options
Diffstat (limited to 'main')
| -rw-r--r-- | main/stream_server.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/main/stream_server.c b/main/stream_server.c index 7876968..10d1e1b 100644 --- a/main/stream_server.c +++ b/main/stream_server.c @@ -9,6 +9,7 @@ #include "freertos/task.h" #include "lwip/netdb.h" #include "lwip/sockets.h" +#include "sys/ioctl.h" #include "display.h" #include "jpeg_decoder.h" @@ -132,6 +133,19 @@ static void handle_client(int fd, const char *peer) continue; } + // "Always paint the latest" — if the socket already has more + // bytes queued in the kernel receive buffer, at least one more + // header is on the way. The frame we just finished receiving + // is no longer the freshest possible; skip its decode+paint + // (saves ~6ms per skip) and loop straight to the next header. + // This trades some intermediate frames for lower + // glass-to-glass latency on the latest one. + int queued = 0; + if (ioctl(fd, FIONREAD, &queued) == 0 && queued >= HEADER_BYTES) { + jpeg_decoder_unlock(); + continue; + } + size_t back_size = 0; void *back = display_back_buffer(&back_size); uint16_t w = 0, h = 0; |
