Improve tracking
This commit is contained in:
parent
944b051daa
commit
e86bedd95a
@ -18,6 +18,7 @@ typedef struct buffer_list_s {
|
||||
unsigned fmt_width, fmt_height, fmt_format, fmt_bytesperline, fmt_interval_us;
|
||||
bool do_timestamps;
|
||||
|
||||
uint64_t last_enqueued_us;
|
||||
uint64_t last_dequeued_us;
|
||||
|
||||
bool streaming;
|
||||
|
@ -58,7 +58,7 @@ bool buffer_consumed(buffer_t *buf, const char *who)
|
||||
|
||||
E_XIOCTL(buf, buf->buf_list->device->fd, VIDIOC_QBUF, &buf->v4l2_buffer, "Can't queue buffer.");
|
||||
buf->enqueued = true;
|
||||
buf->enqueue_time_us = get_monotonic_time_us(NULL, NULL);
|
||||
buf->enqueue_time_us = buf->buf_list->last_enqueued_us = get_monotonic_time_us(NULL, NULL);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&buffer_lock);
|
||||
|
27
hw/links.c
27
hw/links.c
@ -68,20 +68,9 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_lis
|
||||
|
||||
int count_enqueued = buffer_list_count_enqueued(source);
|
||||
|
||||
bool can_dequeue = count_enqueued > 0;
|
||||
int64_t since_last_us = now_us - source->last_dequeued_us;
|
||||
if (since_last_us < source->fmt_interval_us) {
|
||||
can_dequeue = false;
|
||||
|
||||
int64_t since_last_ms = since_last_us / 1000;
|
||||
if (since_last_ms < *max_timeout_ms) {
|
||||
*max_timeout_ms = since_last_ms;
|
||||
}
|
||||
}
|
||||
|
||||
fds[n].fd = source->device->fd;
|
||||
fds[n].events = POLLHUP;
|
||||
if (can_dequeue)
|
||||
if (count_enqueued > 0)
|
||||
fds[n].events |= POLLIN;
|
||||
fds[n].revents = 0;
|
||||
buf_lists[n] = source;
|
||||
@ -144,18 +133,20 @@ void print_pollfds(struct pollfd *fds, int n)
|
||||
printf("pollfds = %d\n", n);
|
||||
}
|
||||
|
||||
int links_step(link_t *all_links, int timeout_ms)
|
||||
int links_step(link_t *all_links, int *timeout_ms)
|
||||
{
|
||||
struct pollfd fds[N_FDS] = {0};
|
||||
link_t *links[N_FDS];
|
||||
buffer_list_t *buf_lists[N_FDS];
|
||||
buffer_t *buf;
|
||||
|
||||
int n = _build_fds(all_links, fds, links, buf_lists, N_FDS, &timeout_ms);
|
||||
int n = _build_fds(all_links, fds, links, buf_lists, N_FDS, timeout_ms);
|
||||
print_pollfds(fds, n);
|
||||
int ret = poll(fds, n, timeout_ms);
|
||||
int ret = poll(fds, n, *timeout_ms);
|
||||
print_pollfds(fds, n);
|
||||
|
||||
uint64_t now_us = get_monotonic_time_us(NULL, NULL);
|
||||
|
||||
if (ret < 0 && errno != EINTR) {
|
||||
return errno;
|
||||
}
|
||||
@ -241,11 +232,15 @@ int links_loop(link_t *all_links, bool *running)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int timeout_ms = LINKS_LOOP_INTERVAL;
|
||||
|
||||
while(*running) {
|
||||
if (links_step(all_links, LINKS_LOOP_INTERVAL) < 0) {
|
||||
if (links_step(all_links, &timeout_ms) < 0) {
|
||||
links_stream(all_links, false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
timeout_ms = LINKS_LOOP_INTERVAL;
|
||||
}
|
||||
|
||||
links_stream(all_links, false);
|
||||
|
@ -20,5 +20,5 @@ typedef struct link_s {
|
||||
} link_t;
|
||||
|
||||
int links_init(link_t *all_links);
|
||||
int links_step(link_t *all_links, int timeout);
|
||||
int links_step(link_t *all_links, int *timeout_ms);
|
||||
int links_loop(link_t *all_links, bool *running);
|
||||
|
Loading…
x
Reference in New Issue
Block a user