mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-18 02:55:46 +00:00
--device-persistent
This commit is contained in:
parent
6cc202133e
commit
ca07a9155b
@ -85,7 +85,7 @@ struct device_t *device_init() {
|
||||
dev->n_buffers = max_u(sysconf(_SC_NPROCESSORS_ONLN), 1) + 1;
|
||||
dev->n_workers = dev->n_buffers;
|
||||
dev->timeout = 1;
|
||||
dev->error_timeout = 1;
|
||||
dev->error_delay = 1;
|
||||
dev->run = run;
|
||||
return dev;
|
||||
}
|
||||
|
||||
@ -74,8 +74,9 @@ struct device_t {
|
||||
unsigned n_workers;
|
||||
unsigned every_frame;
|
||||
unsigned min_frame_size;
|
||||
bool persistent;
|
||||
unsigned timeout;
|
||||
unsigned error_timeout;
|
||||
unsigned error_delay;
|
||||
|
||||
struct device_runtime_t *run;
|
||||
sig_atomic_t volatile stop;
|
||||
|
||||
13
src/main.c
13
src/main.c
@ -59,7 +59,8 @@ static const struct option _long_opts[] = {
|
||||
{"encoder-omx-use-ijg", required_argument, NULL, 500},
|
||||
# endif
|
||||
{"device-timeout", required_argument, NULL, 1000},
|
||||
{"device-error-timeout", required_argument, NULL, 1001},
|
||||
{"device-persistent", no_argument, NULL, 1001},
|
||||
{"device-error-delay", required_argument, NULL, 1002},
|
||||
|
||||
{"host", required_argument, NULL, 's'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
@ -122,8 +123,9 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
|
||||
printf(" Default: disabled.\n\n");
|
||||
# endif
|
||||
printf(" --device-timeout <seconds> -- Timeout for device querying. Default: %d\n\n", dev->timeout);
|
||||
printf(" --device-error-timeout <seconds> -- Delay before trying to connect to the device again\n");
|
||||
printf(" after a timeout. Default: %d\n\n", dev->error_timeout);
|
||||
printf(" --device-persistent -- Don't re-initialize device on timeout. Default: disabled.\n\n");
|
||||
printf(" --device-error-delay <seconds> -- Delay before trying to connect to the device again\n");
|
||||
printf(" after a timeout. Default: %d\n\n", dev->error_delay);
|
||||
printf("HTTP server options:\n");
|
||||
printf("--------------------\n");
|
||||
printf(" --host <address> -- Listen on Hostname or IP. Default: %s\n\n", server->host);
|
||||
@ -189,8 +191,9 @@ static int _parse_options(int argc, char *argv[], struct device_t *dev, struct e
|
||||
# ifdef OMX_ENCODER
|
||||
case 500: OPT_SET(encoder->omx_use_ijg, true);
|
||||
# endif
|
||||
case 1000: OPT_UNSIGNED(dev->timeout, "--timeout", 1, 60);
|
||||
case 1001: OPT_UNSIGNED(dev->error_timeout, "--error-timeout", 1, 60);
|
||||
case 1000: OPT_UNSIGNED(dev->timeout, "--device-timeout", 1, 60);
|
||||
case 1001: OPT_SET(dev->persistent, true);
|
||||
case 1002: OPT_UNSIGNED(dev->error_delay, "--device-error-delay", 1, 60);
|
||||
|
||||
case 's': OPT_SET(server->host, optarg);
|
||||
case 'p': OPT_UNSIGNED(server->port, "--port", 1, 65535);
|
||||
|
||||
21
src/stream.c
21
src/stream.c
@ -87,10 +87,13 @@ void stream_loop(struct stream_t *stream) {
|
||||
unsigned fluency_passed = 0;
|
||||
unsigned captured_fps_accum = 0;
|
||||
long long captured_fps_second = 0;
|
||||
bool persistent_timeout_reported = false;
|
||||
|
||||
LOG_DEBUG("Allocation memory for stream picture ...");
|
||||
A_CALLOC(stream->picture.data, stream->dev->run->max_picture_size);
|
||||
|
||||
LOG_INFO("Capturing ...");
|
||||
|
||||
while (!stream->dev->stop) {
|
||||
int free_worker_number = -1;
|
||||
|
||||
@ -154,10 +157,20 @@ void stream_loop(struct stream_t *stream) {
|
||||
}
|
||||
|
||||
} else if (retval == 0) {
|
||||
LOG_ERROR("Mainloop select() timeout");
|
||||
break;
|
||||
if (stream->dev->persistent) {
|
||||
if (!persistent_timeout_reported) {
|
||||
LOG_ERROR("Mainloop select() timeout, polling ...")
|
||||
persistent_timeout_reported = true;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
LOG_ERROR("Mainloop select() timeout");
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
persistent_timeout_reported = false;
|
||||
|
||||
if (FD_ISSET(stream->dev->run->fd, &read_fds)) {
|
||||
LOG_DEBUG("Frame is ready");
|
||||
|
||||
@ -327,8 +340,8 @@ static int _stream_init_loop(struct device_t *dev, struct workers_pool_t *pool)
|
||||
LOG_DEBUG("%s: *dev->stop = %d", __FUNCTION__, dev->stop);
|
||||
while (!dev->stop) {
|
||||
if ((retval = _stream_init(dev, pool)) < 0) {
|
||||
LOG_INFO("Sleeping %d seconds before new stream init ...", dev->error_timeout);
|
||||
sleep(dev->error_timeout);
|
||||
LOG_INFO("Sleeping %d seconds before new stream init ...", dev->error_delay);
|
||||
sleep(dev->error_delay);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user