diff --git a/http/http_h264.c b/http/http_h264.c index 1a12f43..37384e3 100644 --- a/http/http_h264.c +++ b/http/http_h264.c @@ -40,9 +40,14 @@ void http_video(http_worker_t *worker, FILE *stream) goto error; } + unsigned char *data = buf->start; + if (buf->v4l2_buffer.flags & V4L2_BUF_FLAG_KEYFRAME) { had_key_frame = true; - E_LOG_DEBUG(buf, "Got key frame!"); + E_LOG_DEBUG(buf, "Got key frame (from V4L2)!"); + } else if (buf->used >= 5 && (data[4] & 0x1F) == 0x07) { + had_key_frame = true; + E_LOG_DEBUG(buf, "Got key frame (from buffer)!"); } if (had_key_frame) { diff --git a/http/http_jpeg.c b/http/http_jpeg.c index c01cd34..d88d3d9 100644 --- a/http/http_jpeg.c +++ b/http/http_jpeg.c @@ -48,7 +48,7 @@ void http_snapshot(http_worker_t *worker, FILE *stream) if (!buf) { http_404_header(worker, stream); fprintf(stream, "No snapshot captured yet.\r\n"); - return; + goto error; } fprintf(stream, "HTTP/1.1 200 OK\r\n"); diff --git a/hw/links.c b/hw/links.c index 9b6269b..666b0d3 100644 --- a/hw/links.c +++ b/hw/links.c @@ -48,8 +48,9 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_lis fds[n].events = POLLHUP; if (count_enqueued > 0) fds[n].events |= POLLOUT; - buf_lists[n] = source; - links[n] = link; + fds[n].revents = 0; + buf_lists[n] = sink; + links[n] = NULL; n++; // Can this chain pauses @@ -68,6 +69,7 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_lis fds[n].events = POLLHUP; if (!source->device->paused) fds[n].events |= POLLIN; + fds[n].revents = 0; buf_lists[n] = source; links[n] = link; n++; @@ -117,6 +119,18 @@ error: return -1; } +void print_pollfds(struct pollfd *fds, int n) +{ + if (!getenv("DEBUG_FDS")) { + return; + } + + for (int i = 0; i < n; i++) { + printf("poll(i=%i, fd=%d, events=%08x, revents=%08x)\n", i, fds[i].fd, fds[i].events, fds[i].revents); + } + printf("pollfds = %d\n", n); +} + int links_step(link_t *all_links, int timeout) { struct pollfd fds[N_FDS] = {0}; @@ -125,7 +139,9 @@ int links_step(link_t *all_links, int timeout) buffer_t *buf; int n = _build_fds(all_links, fds, links, buf_lists, N_FDS); + print_pollfds(fds, n); int ret = poll(fds, n, timeout); + print_pollfds(fds, n); if (ret < 0 && errno != EINTR) { return errno; @@ -135,11 +151,12 @@ int links_step(link_t *all_links, int timeout) buffer_list_t *buf_list = buf_lists[i]; link_t *link = links[i]; - E_LOG_DEBUG(buf_list, "pool event=%s%s%s%s/%08x streaming=%d enqueued=%d/%d", - !fds[i].revents ? "NONE" : "", - fds[i].revents & POLLIN ? "IN" : "", - fds[i].revents & POLLOUT ? "OUT" : "", - fds[i].revents & POLLERR ? "ERR" : "", + E_LOG_DEBUG(buf_list, "pool event=%s%s%s%s%s%08x streaming=%d enqueued=%d/%d", + !fds[i].revents ? "NONE/" : "", + fds[i].revents & POLLIN ? "IN/" : "", + fds[i].revents & POLLOUT ? "OUT/" : "", + fds[i].revents & POLLHUP ? "HUP/" : "", + fds[i].revents & POLLERR ? "ERR/" : "", fds[i].revents, buf_list->streaming, buffer_list_count_enqueued(buf_list),