mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-04-12 01:26:13 +00:00
refactoring
This commit is contained in:
@@ -100,15 +100,6 @@ struct device_t *device_init(void) {
|
|||||||
dev->n_buffers = get_cores_available() + 1;
|
dev->n_buffers = get_cores_available() + 1;
|
||||||
dev->min_frame_size = 128;
|
dev->min_frame_size = 128;
|
||||||
dev->timeout = 1;
|
dev->timeout = 1;
|
||||||
|
|
||||||
// FIXME: Not device params
|
|
||||||
dev->error_delay = 1;
|
|
||||||
# ifdef WITH_RAWSINK
|
|
||||||
dev->rawsink_name = "";
|
|
||||||
dev->rawsink_mode = 0660;
|
|
||||||
# endif
|
|
||||||
// end-of-fixme
|
|
||||||
|
|
||||||
dev->run = run;
|
dev->run = run;
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,15 +139,6 @@ struct device_t {
|
|||||||
bool persistent;
|
bool persistent;
|
||||||
unsigned timeout;
|
unsigned timeout;
|
||||||
|
|
||||||
// FIXME: Not device params
|
|
||||||
unsigned error_delay;
|
|
||||||
# ifdef WITH_RAWSINK
|
|
||||||
char *rawsink_name;
|
|
||||||
mode_t rawsink_mode;
|
|
||||||
bool rawsink_rm;
|
|
||||||
# endif
|
|
||||||
// end-of-fixme
|
|
||||||
|
|
||||||
struct controls_t ctl;
|
struct controls_t ctl;
|
||||||
|
|
||||||
struct device_runtime_t *run;
|
struct device_runtime_t *run;
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ int main(int argc, char *argv[]) {
|
|||||||
stream = stream_init(dev, encoder);
|
stream = stream_init(dev, encoder);
|
||||||
server = http_server_init(stream);
|
server = http_server_init(stream);
|
||||||
|
|
||||||
if ((exit_code = options_parse(options, dev, encoder, server)) == 0) {
|
if ((exit_code = options_parse(options, dev, encoder, stream, server)) == 0) {
|
||||||
# ifdef WITH_GPIO
|
# ifdef WITH_GPIO
|
||||||
gpio_init();
|
gpio_init();
|
||||||
# endif
|
# endif
|
||||||
|
|||||||
@@ -209,7 +209,10 @@ static int _parse_glitched_resolutions(const char *str, struct encoder_t *encode
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void _features(void);
|
static void _features(void);
|
||||||
static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server);
|
|
||||||
|
static void _help(
|
||||||
|
struct device_t *dev, struct encoder_t *encoder,
|
||||||
|
struct stream_t *stream, struct http_server_t *server);
|
||||||
|
|
||||||
|
|
||||||
struct options_t *options_init(int argc, char *argv[]) {
|
struct options_t *options_init(int argc, char *argv[]) {
|
||||||
@@ -236,7 +239,10 @@ void options_destroy(struct options_t *options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int options_parse(struct options_t *options, struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server) {
|
int options_parse(
|
||||||
|
struct options_t *options, struct device_t *dev, struct encoder_t *encoder,
|
||||||
|
struct stream_t *stream, struct http_server_t *server) {
|
||||||
|
|
||||||
# define OPT_SET(_dest, _value) { \
|
# define OPT_SET(_dest, _value) { \
|
||||||
_dest = _value; \
|
_dest = _value; \
|
||||||
break; \
|
break; \
|
||||||
@@ -349,7 +355,7 @@ int options_parse(struct options_t *options, struct device_t *dev, struct encode
|
|||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
case _O_DEVICE_TIMEOUT: OPT_NUMBER("--device-timeout", dev->timeout, 1, 60, 0);
|
case _O_DEVICE_TIMEOUT: OPT_NUMBER("--device-timeout", dev->timeout, 1, 60, 0);
|
||||||
case _O_DEVICE_ERROR_DELAY: OPT_NUMBER("--device-error-delay", dev->error_delay, 1, 60, 0);
|
case _O_DEVICE_ERROR_DELAY: OPT_NUMBER("--device-error-delay", stream->error_delay, 1, 60, 0);
|
||||||
|
|
||||||
case _O_IMAGE_DEFAULT:
|
case _O_IMAGE_DEFAULT:
|
||||||
OPT_CTL_DEFAULT_NOBREAK(brightness);
|
OPT_CTL_DEFAULT_NOBREAK(brightness);
|
||||||
@@ -396,9 +402,9 @@ int options_parse(struct options_t *options, struct device_t *dev, struct encode
|
|||||||
case _O_SERVER_TIMEOUT: OPT_NUMBER("--server-timeout", server->timeout, 1, 60, 0);
|
case _O_SERVER_TIMEOUT: OPT_NUMBER("--server-timeout", server->timeout, 1, 60, 0);
|
||||||
|
|
||||||
# ifdef WITH_RAWSINK
|
# ifdef WITH_RAWSINK
|
||||||
case _O_RAWSINK: OPT_SET(dev->rawsink_name, optarg);
|
case _O_RAWSINK: OPT_SET(stream->rawsink_name, optarg);
|
||||||
case _O_RAWSINK_MODE: OPT_NUMBER("--raw-sink-mode", dev->rawsink_mode, INT_MIN, INT_MAX, 8);
|
case _O_RAWSINK_MODE: OPT_NUMBER("--raw-sink-mode", stream->rawsink_mode, INT_MIN, INT_MAX, 8);
|
||||||
case _O_RAWSINK_RM: OPT_SET(dev->rawsink_rm, true);
|
case _O_RAWSINK_RM: OPT_SET(stream->rawsink_rm, true);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifdef WITH_GPIO
|
# ifdef WITH_GPIO
|
||||||
@@ -428,12 +434,12 @@ int options_parse(struct options_t *options, struct device_t *dev, struct encode
|
|||||||
case _O_FORCE_LOG_COLORS: OPT_SET(log_colored, true);
|
case _O_FORCE_LOG_COLORS: OPT_SET(log_colored, true);
|
||||||
case _O_NO_LOG_COLORS: OPT_SET(log_colored, false);
|
case _O_NO_LOG_COLORS: OPT_SET(log_colored, false);
|
||||||
|
|
||||||
case _O_HELP: _help(dev, encoder, server); return 1;
|
case _O_HELP: _help(dev, encoder, stream, server); return 1;
|
||||||
case _O_VERSION: puts(VERSION); return 1;
|
case _O_VERSION: puts(VERSION); return 1;
|
||||||
case _O_FEATURES: _features(); return 1;
|
case _O_FEATURES: _features(); return 1;
|
||||||
|
|
||||||
case 0: break;
|
case 0: break;
|
||||||
default: _help(dev, encoder, server); return -1;
|
default: _help(dev, encoder, stream, server); return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,7 +567,10 @@ static void _features(void) {
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server) {
|
static void _help(
|
||||||
|
struct device_t *dev, struct encoder_t *encoder,
|
||||||
|
struct stream_t *stream, struct http_server_t *server) {
|
||||||
|
|
||||||
printf("\nuStreamer - Lightweight and fast MJPG-HTTP streamer\n");
|
printf("\nuStreamer - Lightweight and fast MJPG-HTTP streamer\n");
|
||||||
printf("═══════════════════════════════════════════════════\n\n");
|
printf("═══════════════════════════════════════════════════\n\n");
|
||||||
printf("Version: %s; license: GPLv3\n", VERSION);
|
printf("Version: %s; license: GPLv3\n", VERSION);
|
||||||
@@ -611,7 +620,7 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
|
|||||||
# endif
|
# endif
|
||||||
printf(" --device-timeout <sec> ────────────── Timeout for device querying. Default: %u.\n\n", dev->timeout);
|
printf(" --device-timeout <sec> ────────────── Timeout for device querying. Default: %u.\n\n", dev->timeout);
|
||||||
printf(" --device-error-delay <sec> ────────── Delay before trying to connect to the device again\n");
|
printf(" --device-error-delay <sec> ────────── Delay before trying to connect to the device again\n");
|
||||||
printf(" after an error (timeout for example). Default: %u.\n\n", dev->error_delay);
|
printf(" after an error (timeout for example). Default: %u.\n\n", stream->error_delay);
|
||||||
printf("Image control options:\n");
|
printf("Image control options:\n");
|
||||||
printf("══════════════════════\n");
|
printf("══════════════════════\n");
|
||||||
printf(" --image-default ────────────────────── Reset all image settings below to default. Default: no change.\n\n");
|
printf(" --image-default ────────────────────── Reset all image settings below to default. Default: no change.\n\n");
|
||||||
@@ -661,7 +670,7 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
|
|||||||
printf("═════════════════\n");
|
printf("═════════════════\n");
|
||||||
printf(" --raw-sink <name> ────── Use the shared memory to sink RAW frames before encoding.\n");
|
printf(" --raw-sink <name> ────── Use the shared memory to sink RAW frames before encoding.\n");
|
||||||
printf(" Most likely you will never need it. Default: disabled.\n\n");
|
printf(" Most likely you will never need it. Default: disabled.\n\n");
|
||||||
printf(" --raw-sink-mode <mode> ─ Set RAW sink permissions (like 777). Default: %o.\n\n", dev->rawsink_mode);
|
printf(" --raw-sink-mode <mode> ─ Set RAW sink permissions (like 777). Default: %o.\n\n", stream->rawsink_mode);
|
||||||
printf(" --raw-sink-rm ────────── Remove shared memory on stop. Default: disabled.\n\n");
|
printf(" --raw-sink-rm ────────── Remove shared memory on stop. Default: disabled.\n\n");
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_GPIO
|
#ifdef WITH_GPIO
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "encoder.h"
|
#include "encoder.h"
|
||||||
|
#include "stream.h"
|
||||||
#include "http/server.h"
|
#include "http/server.h"
|
||||||
#ifdef WITH_GPIO
|
#ifdef WITH_GPIO
|
||||||
# include "gpio/gpio.h"
|
# include "gpio/gpio.h"
|
||||||
@@ -55,4 +56,6 @@ struct options_t {
|
|||||||
struct options_t *options_init(int argc, char *argv[]);
|
struct options_t *options_init(int argc, char *argv[]);
|
||||||
void options_destroy(struct options_t *options);
|
void options_destroy(struct options_t *options);
|
||||||
|
|
||||||
int options_parse(struct options_t *options, struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server);
|
int options_parse(
|
||||||
|
struct options_t *options, struct device_t *dev, struct encoder_t *encoder,
|
||||||
|
struct stream_t *stream, struct http_server_t *server);
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ struct stream_t *stream_init(struct device_t *dev, struct encoder_t *encoder) {
|
|||||||
atomic_init(&proc->slowdown, false);
|
atomic_init(&proc->slowdown, false);
|
||||||
|
|
||||||
A_CALLOC(stream, 1);
|
A_CALLOC(stream, 1);
|
||||||
|
// FIXME
|
||||||
|
stream->error_delay = 1;
|
||||||
|
# ifdef WITH_RAWSINK
|
||||||
|
stream->rawsink_name = "";
|
||||||
|
stream->rawsink_mode = 0660;
|
||||||
|
# endif
|
||||||
|
// end-of-fixme
|
||||||
stream->picture = picture_init();
|
stream->picture = picture_init();
|
||||||
stream->dev = dev;
|
stream->dev = dev;
|
||||||
stream->encoder = encoder;
|
stream->encoder = encoder;
|
||||||
@@ -116,8 +123,8 @@ void stream_loop(struct stream_t *stream) {
|
|||||||
|
|
||||||
# ifdef WITH_RAWSINK
|
# ifdef WITH_RAWSINK
|
||||||
struct rawsink_t *rawsink = NULL;
|
struct rawsink_t *rawsink = NULL;
|
||||||
if (DEV(rawsink_name[0]) != '\0') {
|
if (stream->rawsink_name[0] != '\0') {
|
||||||
rawsink = rawsink_init(DEV(rawsink_name), DEV(rawsink_mode), DEV(rawsink_rm), true);
|
rawsink = rawsink_init(stream->rawsink_name, stream->rawsink_mode, stream->rawsink_rm, true);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
@@ -290,7 +297,7 @@ static struct _workers_pool_t *_stream_init_loop(struct stream_t *stream) {
|
|||||||
LOG_INFO("Waiting for the device access ...");
|
LOG_INFO("Waiting for the device access ...");
|
||||||
access_error = errno;
|
access_error = errno;
|
||||||
}
|
}
|
||||||
sleep(stream->dev->error_delay);
|
sleep(stream->error_delay);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
SEP_INFO('=');
|
SEP_INFO('=');
|
||||||
@@ -298,8 +305,8 @@ static struct _workers_pool_t *_stream_init_loop(struct stream_t *stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((pool = _stream_init_one(stream)) == NULL) {
|
if ((pool = _stream_init_one(stream)) == NULL) {
|
||||||
LOG_INFO("Sleeping %u seconds before new stream init ...", stream->dev->error_delay);
|
LOG_INFO("Sleeping %u seconds before new stream init ...", stream->error_delay);
|
||||||
sleep(stream->dev->error_delay);
|
sleep(stream->error_delay);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,15 @@ struct stream_t {
|
|||||||
atomic_bool updated;
|
atomic_bool updated;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
|
// FIXME: Config params, move other to runtime
|
||||||
|
unsigned error_delay;
|
||||||
|
# ifdef WITH_RAWSINK
|
||||||
|
char *rawsink_name;
|
||||||
|
mode_t rawsink_mode;
|
||||||
|
bool rawsink_rm;
|
||||||
|
# endif
|
||||||
|
// end-of-fixme
|
||||||
|
|
||||||
struct process_t *proc;
|
struct process_t *proc;
|
||||||
struct device_t *dev;
|
struct device_t *dev;
|
||||||
struct encoder_t *encoder;
|
struct encoder_t *encoder;
|
||||||
|
|||||||
Reference in New Issue
Block a user