Improve clocks support
This commit is contained in:
@ -35,7 +35,7 @@ void http_video(http_worker_t *worker, FILE *stream)
|
|||||||
buffer_lock_use(&http_h264, 1);
|
buffer_lock_use(&http_h264, 1);
|
||||||
|
|
||||||
while (!feof(stream)) {
|
while (!feof(stream)) {
|
||||||
buffer_t *buf = buffer_lock_get(&http_h264, 3, &counter);
|
buffer_t *buf = buffer_lock_get(&http_h264, 0, &counter);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ void http_snapshot(http_worker_t *worker, FILE *stream)
|
|||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
buffer_lock_use(&http_jpeg, 1);
|
buffer_lock_use(&http_jpeg, 1);
|
||||||
buffer_t *buf = buffer_lock_get(&http_jpeg, 1, &counter);
|
buffer_t *buf = buffer_lock_get(&http_jpeg, 0, &counter);
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
http_404_header(worker, stream);
|
http_404_header(worker, stream);
|
||||||
@ -68,7 +68,7 @@ void http_stream(http_worker_t *worker, FILE *stream)
|
|||||||
buffer_lock_use(&http_jpeg, 1);
|
buffer_lock_use(&http_jpeg, 1);
|
||||||
|
|
||||||
while (!feof(stream)) {
|
while (!feof(stream)) {
|
||||||
buffer_t *buf = buffer_lock_get(&http_jpeg, 3, &counter);
|
buffer_t *buf = buffer_lock_get(&http_jpeg, 0, &counter);
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
fprintf(stream, STREAM_ERROR, -1, "No frames.");
|
fprintf(stream, STREAM_ERROR, -1, "No frames.");
|
||||||
|
@ -49,14 +49,15 @@ void buffer_lock_capture(buffer_lock_t *buf_lock, buffer_t *buf)
|
|||||||
pthread_mutex_unlock(&buf_lock->lock);
|
pthread_mutex_unlock(&buf_lock->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_t *buffer_lock_get(buffer_lock_t *buf_lock, int timeout_s, int *counter)
|
buffer_t *buffer_lock_get(buffer_lock_t *buf_lock, int timeout_ms, int *counter)
|
||||||
{
|
{
|
||||||
buffer_t *buf = NULL;
|
buffer_t *buf = NULL;
|
||||||
struct timeval now;
|
|
||||||
struct timespec timeout;
|
struct timespec timeout;
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
timeout.tv_nsec = now.tv_usec;
|
if(!timeout_ms)
|
||||||
timeout.tv_sec = now.tv_sec + timeout_s;
|
timeout_ms = DEFAULT_BUFFER_LOCK_GET_TIMEOUT;
|
||||||
|
|
||||||
|
get_time_us(CLOCK_REALTIME, &timeout, NULL, timeout_ms * 1000LL * 1000LL);
|
||||||
|
|
||||||
pthread_mutex_lock(&buf_lock->lock);
|
pthread_mutex_lock(&buf_lock->lock);
|
||||||
if (*counter == buf_lock->counter || !buf_lock->buf) {
|
if (*counter == buf_lock->counter || !buf_lock->buf) {
|
||||||
|
@ -16,6 +16,7 @@ typedef struct buffer_lock_s {
|
|||||||
} buffer_lock_t;
|
} buffer_lock_t;
|
||||||
|
|
||||||
#define DEFAULT_BUFFER_LOCK_TIMEOUT 16 // ~60fps
|
#define DEFAULT_BUFFER_LOCK_TIMEOUT 16 // ~60fps
|
||||||
|
#define DEFAULT_BUFFER_LOCK_GET_TIMEOUT 2000 // 2s
|
||||||
|
|
||||||
#define DEFINE_BUFFER_LOCK(_name, _timeout_ms) static buffer_lock_t _name = { \
|
#define DEFINE_BUFFER_LOCK(_name, _timeout_ms) static buffer_lock_t _name = { \
|
||||||
.name = #_name, \
|
.name = #_name, \
|
||||||
@ -25,7 +26,7 @@ typedef struct buffer_lock_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void buffer_lock_capture(buffer_lock_t *buf_lock, buffer_t *buf);
|
void buffer_lock_capture(buffer_lock_t *buf_lock, buffer_t *buf);
|
||||||
buffer_t *buffer_lock_get(buffer_lock_t *buf_lock, int timeout_s, int *counter);
|
buffer_t *buffer_lock_get(buffer_lock_t *buf_lock, int timeout_ms, int *counter);
|
||||||
bool buffer_lock_needs_buffer(buffer_lock_t *buf_lock);
|
bool buffer_lock_needs_buffer(buffer_lock_t *buf_lock);
|
||||||
void buffer_lock_use(buffer_lock_t *buf_lock, int ref);
|
void buffer_lock_use(buffer_lock_t *buf_lock, int ref);
|
||||||
bool buffer_lock_is_used(buffer_lock_t *buf_lock);
|
bool buffer_lock_is_used(buffer_lock_t *buf_lock);
|
||||||
|
@ -220,7 +220,7 @@ int links_loop(link_t *all_links, bool *running)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(*running) {
|
while(*running) {
|
||||||
if (links_step(all_links, 1000) < 0) {
|
if (links_step(all_links, LINKS_LOOP_INTERVAL) < 0) {
|
||||||
links_stream(all_links, false);
|
links_stream(all_links, false);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "v4l2.h"
|
#include "v4l2.h"
|
||||||
|
|
||||||
|
#define LINKS_LOOP_INTERVAL 100
|
||||||
|
|
||||||
typedef struct buffer_s buffer_t;
|
typedef struct buffer_s buffer_t;
|
||||||
typedef struct buffer_list_s buffer_list_t;
|
typedef struct buffer_list_s buffer_list_t;
|
||||||
|
|
||||||
|
16
hw/v4l2.c
16
hw/v4l2.c
@ -80,10 +80,17 @@ int shrink_to_block(int size, int block)
|
|||||||
return size / block * block;
|
return size / block * block;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv)
|
uint64_t get_time_us(clockid_t clock, struct timespec *ts, struct timeval *tv, int64_t delays_us)
|
||||||
{
|
{
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(clock, &now);
|
||||||
|
|
||||||
|
if (delays_us > 0) {
|
||||||
|
now.tv_nsec += delays_us * 1000LL;
|
||||||
|
now.tv_sec += now.tv_nsec / (1000LL * 1000LL * 1000LL);
|
||||||
|
now.tv_nsec %= 1000LL * 1000LL * 1000LL;
|
||||||
|
}
|
||||||
|
|
||||||
if (ts) {
|
if (ts) {
|
||||||
*ts = now;
|
*ts = now;
|
||||||
}
|
}
|
||||||
@ -93,3 +100,8 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv)
|
|||||||
}
|
}
|
||||||
return now.tv_sec * 1000000LL + now.tv_nsec / 1000;
|
return now.tv_sec * 1000000LL + now.tv_nsec / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv)
|
||||||
|
{
|
||||||
|
return get_time_us(CLOCK_MONOTONIC, ts, tv, 0);
|
||||||
|
}
|
||||||
|
@ -34,6 +34,7 @@ fourcc_string fourcc_to_string(unsigned format);
|
|||||||
unsigned fourcc_to_stride(unsigned width, unsigned format);
|
unsigned fourcc_to_stride(unsigned width, unsigned format);
|
||||||
int xioctl(const char *name, int fd, int request, void *arg);
|
int xioctl(const char *name, int fd, int request, void *arg);
|
||||||
uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv);
|
uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv);
|
||||||
|
uint64_t get_time_us(clockid_t clock, struct timespec *ts, struct timeval *tv, int64_t delays_us);
|
||||||
int shrink_to_block(int size, int block);
|
int shrink_to_block(int size, int block);
|
||||||
|
|
||||||
#define E_XIOCTL(dev, _fd, _request, _value, _msg, ...) do { \
|
#define E_XIOCTL(dev, _fd, _request, _value, _msg, ...) do { \
|
||||||
|
Reference in New Issue
Block a user