mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-27 20:26:31 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcc90341c9 | ||
|
|
7e102c88cd | ||
|
|
e131a3ba49 | ||
|
|
e393be4c63 | ||
|
|
cf4f5f5b2a | ||
|
|
1190059359 | ||
|
|
910b27feb4 | ||
|
|
60ca92d367 | ||
|
|
4f44c5efa1 | ||
|
|
3504095871 | ||
|
|
6eeb49ef75 | ||
|
|
9353b3474a | ||
|
|
dfc98a67f2 | ||
|
|
904c76fa93 | ||
|
|
f0a7ca5c94 | ||
|
|
bb4e9db7e7 | ||
|
|
61f2bfa00e | ||
|
|
49eb7f6e51 | ||
|
|
b5375b835a | ||
|
|
e3e2c5cead | ||
|
|
ef4150877b | ||
|
|
cc00d0fea3 | ||
|
|
91a1e48a7c | ||
|
|
f381113d50 | ||
|
|
a6304959f4 | ||
|
|
57bc6e160d |
@@ -1,7 +1,7 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
current_version = 1.8
|
current_version = 1.14
|
||||||
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?)?
|
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?)?
|
||||||
serialize =
|
serialize =
|
||||||
{major}.{minor}
|
{major}.{minor}
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
/pkg/arch/src/
|
/pkg/arch/src/
|
||||||
/pkg/arch/v*.tar.gz
|
/pkg/arch/v*.tar.gz
|
||||||
/pkg/arch/ustreamer-*.pkg.tar.xz
|
/pkg/arch/ustreamer-*.pkg.tar.xz
|
||||||
|
/pkg/arch/ustreamer-*.pkg.tar.zst
|
||||||
/build/
|
/build/
|
||||||
/config.mk
|
/config.mk
|
||||||
/vgcore.*
|
/vgcore.*
|
||||||
|
|||||||
18
Makefile
18
Makefile
@@ -44,13 +44,13 @@ override CFLAGS += -DWITH_PTHREAD_NP
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
#WITH_SETPROCTITLE ?= 1
|
WITH_SETPROCTITLE ?= 1
|
||||||
#ifneq ($(call optbool,$(WITH_SETPROCTITLE)),)
|
ifneq ($(call optbool,$(WITH_SETPROCTITLE)),)
|
||||||
#ifeq ($(shell uname -s | tr A-Z a-z),linux)
|
ifeq ($(shell uname -s | tr A-Z a-z),linux)
|
||||||
#_LIBS += -lbsd
|
_LIBS += -lbsd
|
||||||
#endif
|
endif
|
||||||
#override CFLAGS += -DWITH_SETPROCTITLE
|
override CFLAGS += -DWITH_SETPROCTITLE
|
||||||
#endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
@@ -87,7 +87,7 @@ $(PROG): $(_SRCS:%.c=$(BUILD)/%.o)
|
|||||||
$(BUILD)/%.o: %.c
|
$(BUILD)/%.o: %.c
|
||||||
$(info -- CC $<)
|
$(info -- CC $<)
|
||||||
@ mkdir -p $(dir $@) || true
|
@ mkdir -p $(dir $@) || true
|
||||||
@ $(CC) $< -o $@ $(CFLAGS) $(_LIBS)
|
@ $(CC) $< -o $@ $(CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
@@ -109,5 +109,5 @@ push:
|
|||||||
|
|
||||||
clean-all: clean
|
clean-all: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf pkg/arch/pkg pkg/arch/src pkg/arch/v*.tar.gz pkg/arch/ustreamer-*.pkg.tar.xz
|
rm -rf pkg/arch/pkg pkg/arch/src pkg/arch/v*.tar.gz pkg/arch/ustreamer-*.pkg.tar.{xz,zst}
|
||||||
rm -rf $(PROG) $(BUILD) vgcore.* *.sock
|
rm -rf $(PROG) $(BUILD) vgcore.* *.sock
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ If you're going to live-stream from your backyard webcam and need to control it,
|
|||||||
# Building
|
# Building
|
||||||
You'll need ```make```, ```gcc```, ```libevent``` with ```pthreads``` support, ```libjpeg8```/```libjpeg-turbo```, ```libuuid``` and ```libbsd``` (only for Linux).
|
You'll need ```make```, ```gcc```, ```libevent``` with ```pthreads``` support, ```libjpeg8```/```libjpeg-turbo```, ```libuuid``` and ```libbsd``` (only for Linux).
|
||||||
|
|
||||||
|
* Arch: `sudo pacman -S libevent libjpeg-turbo libutil-linux libbsd`.
|
||||||
|
* Raspbian: `sudo apt install libevent-dev libevent-pthreads-2.1-6-dev libjpeg8-dev uuid-dev libbsd-dev`.
|
||||||
|
* Debian: `sudo apt install build-essential libevent-dev libjpeg62-turbo-dev uuid-dev libbsd-dev`.
|
||||||
|
|
||||||
On Raspberry Pi you can build the program with OpenMAX IL. To do this pass option ```WITH_OMX=1``` to ```make```. To enable GPIO support install [wiringPi](http://wiringpi.com) and pass option ```WITH_GPIO=1```. If the compiler reports about a missing function ```pthread_get_name_np()``` (or similar), add option ```WITH_PTHREAD_NP=0``` (it's enabled by default). For the similar error with ```setproctitle()``` add option ```WITH_SETPROCTITLE=0```.
|
On Raspberry Pi you can build the program with OpenMAX IL. To do this pass option ```WITH_OMX=1``` to ```make```. To enable GPIO support install [wiringPi](http://wiringpi.com) and pass option ```WITH_GPIO=1```. If the compiler reports about a missing function ```pthread_get_name_np()``` (or similar), add option ```WITH_PTHREAD_NP=0``` (it's enabled by default). For the similar error with ```setproctitle()``` add option ```WITH_SETPROCTITLE=0```.
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -64,6 +68,10 @@ $ ./ustreamer \
|
|||||||
|
|
||||||
You can always view the full list of options with ```ustreamer --help```.
|
You can always view the full list of options with ```ustreamer --help```.
|
||||||
|
|
||||||
|
-----
|
||||||
|
# Tips
|
||||||
|
* [Running uStreamer via systemd service](https://github.com/pikvm/ustreamer/issues/16)
|
||||||
|
|
||||||
-----
|
-----
|
||||||
# License
|
# License
|
||||||
Copyright (C) 2018 by Maxim Devaev mdevaev@gmail.com
|
Copyright (C) 2018 by Maxim Devaev mdevaev@gmail.com
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
# Сборка
|
# Сборка
|
||||||
Для сборки вам понадобятся ```make```, ```gcc```, ```libevent``` с поддержкой ```pthreads```, ```libjpeg8```/```libjpeg-turbo```, ```libuuid``` и ```libbsd``` (только для Linux).
|
Для сборки вам понадобятся ```make```, ```gcc```, ```libevent``` с поддержкой ```pthreads```, ```libjpeg8```/```libjpeg-turbo```, ```libuuid``` и ```libbsd``` (только для Linux).
|
||||||
|
|
||||||
|
* Arch: `sudo pacman -S libevent libjpeg-turbo libutil-linux libbsd`.
|
||||||
|
* Raspbian: `sudo apt install libevent-dev libevent-pthreads-2.1-6-dev libjpeg8-dev uuid-dev libbsd-dev`.
|
||||||
|
* Debian: `sudo apt install build-essential libevent-dev libjpeg62-turbo-dev uuid-dev libbsd-dev`.
|
||||||
|
|
||||||
На Raspberry Pi программу можно собрать с поддержкой OpenMAX IL. Для этого передайте ```make``` параметр ```WITH_OMX=1```. Для включения сборки с поддержкой GPIO установите [wiringPi](http://wiringpi.com) и добавьте параметр ```WITH_GPIO=1```. Если при сборке компилятор ругается на отсутствие функции ```pthread_get_name_np()``` или другой подобной, добавьте параметр ```WITH_PTHREAD_NP=0``` (по умолчанию он включен). При аналогичной ошибке с функцией ```setproctitle()``` добавьте параметр ```WITH_SETPROCTITLE=0```.
|
На Raspberry Pi программу можно собрать с поддержкой OpenMAX IL. Для этого передайте ```make``` параметр ```WITH_OMX=1```. Для включения сборки с поддержкой GPIO установите [wiringPi](http://wiringpi.com) и добавьте параметр ```WITH_GPIO=1```. Если при сборке компилятор ругается на отсутствие функции ```pthread_get_name_np()``` или другой подобной, добавьте параметр ```WITH_PTHREAD_NP=0``` (по умолчанию он включен). При аналогичной ошибке с функцией ```setproctitle()``` добавьте параметр ```WITH_SETPROCTITLE=0```.
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -64,6 +68,10 @@ $ ./ustreamer \
|
|||||||
|
|
||||||
За полным списком опций обращайтесь ко встроенной справке: ```ustreamer --help```.
|
За полным списком опций обращайтесь ко встроенной справке: ```ustreamer --help```.
|
||||||
|
|
||||||
|
-----
|
||||||
|
# Советы
|
||||||
|
* [Запуск с помощью systemd-сервиса](https://github.com/pikvm/ustreamer/issues/16)
|
||||||
|
|
||||||
-----
|
-----
|
||||||
# Лицензия
|
# Лицензия
|
||||||
Copyright (C) 2018 by Maxim Devaev mdevaev@gmail.com
|
Copyright (C) 2018 by Maxim Devaev mdevaev@gmail.com
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
pkgname=ustreamer
|
pkgname=ustreamer
|
||||||
pkgver=1.8
|
pkgver=1.14
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Lightweight and fast MJPG-HTTP streamer"
|
pkgdesc="Lightweight and fast MJPG-HTTP streamer"
|
||||||
url="https://github.com/pikvm/ustreamer"
|
url="https://github.com/pikvm/ustreamer"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=ustreamer
|
PKG_NAME:=ustreamer
|
||||||
PKG_VERSION:=1.8
|
PKG_VERSION:=1.14
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_MAINTAINER:=Maxim Devaev <mdevaev@gmail.com>
|
PKG_MAINTAINER:=Maxim Devaev <mdevaev@gmail.com>
|
||||||
|
|
||||||
|
|||||||
@@ -23,5 +23,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef VERSION
|
#ifndef VERSION
|
||||||
# define VERSION "1.8"
|
# define VERSION "1.14"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
99
src/device.c
99
src/device.c
@@ -77,9 +77,10 @@ static int _device_open_mmap(struct device_t *dev);
|
|||||||
static int _device_open_queue_buffers(struct device_t *dev);
|
static int _device_open_queue_buffers(struct device_t *dev);
|
||||||
static void _device_open_alloc_picbufs(struct device_t *dev);
|
static void _device_open_alloc_picbufs(struct device_t *dev);
|
||||||
static int _device_apply_resolution(struct device_t *dev, unsigned width, unsigned height);
|
static int _device_apply_resolution(struct device_t *dev, unsigned width, unsigned height);
|
||||||
|
|
||||||
static void _device_apply_controls(struct device_t *dev);
|
static void _device_apply_controls(struct device_t *dev);
|
||||||
static int _device_check_control(struct device_t *dev, const char *name, unsigned cid, int value, bool quiet);
|
static int _device_query_control(struct device_t *dev, struct v4l2_queryctrl *query, const char *name, unsigned cid, bool quiet);
|
||||||
static void _device_set_control(struct device_t *dev, const char *name, unsigned cid, int value, bool quiet);
|
static void _device_set_control(struct device_t *dev, struct v4l2_queryctrl *query, const char *name, unsigned cid, int value, bool quiet);
|
||||||
|
|
||||||
static const char *_format_to_string_fourcc(char *buf, size_t size, unsigned format);
|
static const char *_format_to_string_fourcc(char *buf, size_t size, unsigned format);
|
||||||
static const char *_format_to_string_nullable(unsigned format);
|
static const char *_format_to_string_nullable(unsigned format);
|
||||||
@@ -286,7 +287,7 @@ int device_grab_buffer(struct device_t *dev) {
|
|||||||
|
|
||||||
dev->run->hw_buffers[buf_info.index].used = buf_info.bytesused;
|
dev->run->hw_buffers[buf_info.index].used = buf_info.bytesused;
|
||||||
memcpy(&dev->run->hw_buffers[buf_info.index].buf_info, &buf_info, sizeof(struct v4l2_buffer));
|
memcpy(&dev->run->hw_buffers[buf_info.index].buf_info, &buf_info, sizeof(struct v4l2_buffer));
|
||||||
dev->run->pictures[buf_info.index]->grab_time = get_now_monotonic();
|
dev->run->pictures[buf_info.index]->grab_ts = get_now_monotonic();
|
||||||
return buf_info.index;
|
return buf_info.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +391,7 @@ static int _device_apply_dv_timings(struct device_t *dev) {
|
|||||||
LOG_DEBUG("Calling ioctl(VIDIOC_QUERY_DV_TIMINGS) ...");
|
LOG_DEBUG("Calling ioctl(VIDIOC_QUERY_DV_TIMINGS) ...");
|
||||||
if (xioctl(dev->run->fd, VIDIOC_QUERY_DV_TIMINGS, &dv) == 0) {
|
if (xioctl(dev->run->fd, VIDIOC_QUERY_DV_TIMINGS, &dv) == 0) {
|
||||||
LOG_INFO("Got new DV timings: resolution=%ux%u, pixclk=%llu",
|
LOG_INFO("Got new DV timings: resolution=%ux%u, pixclk=%llu",
|
||||||
dv.bt.width, dv.bt.height, dv.bt.pixelclock);
|
dv.bt.width, dv.bt.height, (unsigned long long)dv.bt.pixelclock); // Issue #11
|
||||||
|
|
||||||
LOG_DEBUG("Calling ioctl(VIDIOC_S_DV_TIMINGS) ...");
|
LOG_DEBUG("Calling ioctl(VIDIOC_S_DV_TIMINGS) ...");
|
||||||
if (xioctl(dev->run->fd, VIDIOC_S_DV_TIMINGS, &dv) < 0) {
|
if (xioctl(dev->run->fd, VIDIOC_S_DV_TIMINGS, &dv) < 0) {
|
||||||
@@ -610,65 +611,81 @@ static int _device_apply_resolution(struct device_t *dev, unsigned width, unsign
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _device_apply_controls(struct device_t *dev) {
|
static void _device_apply_controls(struct device_t *dev) {
|
||||||
# define SET_CID(_cid, _dest, _value, _quiet) { \
|
# define SET_CID_VALUE(_cid, _field, _value, _quiet) { \
|
||||||
if (_device_check_control(dev, #_dest, _cid, _value, _quiet) == 0) { \
|
struct v4l2_queryctrl query; \
|
||||||
_device_set_control(dev, #_dest, _cid, _value, _quiet); \
|
if (_device_query_control(dev, &query, #_field, _cid, _quiet) == 0) { \
|
||||||
|
_device_set_control(dev, &query, #_field, _cid, _value, _quiet); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define SET_CID_MANUAL(_cid, _dest) { \
|
# define SET_CID_DEFAULT(_cid, _field, _quiet) { \
|
||||||
if (dev->ctl._dest.value_set) { \
|
struct v4l2_queryctrl query; \
|
||||||
SET_CID(_cid, _dest, dev->ctl._dest.value, false); \
|
if (_device_query_control(dev, &query, #_field, _cid, _quiet) == 0) { \
|
||||||
|
_device_set_control(dev, &query, #_field, _cid, query.default_value, _quiet); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define SET_CID_AUTO(_cid_auto, _cid_manual, _dest) { \
|
# define CONTROL_MANUAL_CID(_cid, _field) { \
|
||||||
if (dev->ctl._dest.value_set || dev->ctl._dest.auto_set) { \
|
if (dev->ctl._field.mode == CTL_MODE_VALUE) { \
|
||||||
SET_CID(_cid_auto, _dest##_auto, dev->ctl._dest.auto_set, dev->ctl._dest.value_set); \
|
SET_CID_VALUE(_cid, _field, dev->ctl._field.value, false); \
|
||||||
SET_CID_MANUAL(_cid_manual, _dest); \
|
} else if (dev->ctl._field.mode == CTL_MODE_DEFAULT) { \
|
||||||
|
SET_CID_DEFAULT(_cid, _field, false); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_CID_AUTO (V4L2_CID_AUTOBRIGHTNESS, V4L2_CID_BRIGHTNESS, brightness);
|
# define CONTROL_AUTO_CID(_cid_auto, _cid_manual, _field) { \
|
||||||
SET_CID_MANUAL ( V4L2_CID_CONTRAST, contrast);
|
if (dev->ctl._field.mode == CTL_MODE_VALUE) { \
|
||||||
SET_CID_MANUAL ( V4L2_CID_SATURATION, saturation);
|
SET_CID_VALUE(_cid_auto, _field##_auto, 0, true); \
|
||||||
SET_CID_AUTO (V4L2_CID_HUE_AUTO, V4L2_CID_HUE, hue);
|
SET_CID_VALUE(_cid_manual, _field, dev->ctl._field.value, false); \
|
||||||
SET_CID_MANUAL ( V4L2_CID_GAMMA, gamma);
|
} else if (dev->ctl._field.mode == CTL_MODE_AUTO) { \
|
||||||
SET_CID_MANUAL ( V4L2_CID_SHARPNESS, sharpness);
|
SET_CID_VALUE(_cid_auto, _field##_auto, 1, false); \
|
||||||
SET_CID_MANUAL ( V4L2_CID_BACKLIGHT_COMPENSATION, backlight_compensation);
|
} else if (dev->ctl._field.mode == CTL_MODE_DEFAULT) { \
|
||||||
SET_CID_AUTO (V4L2_CID_AUTO_WHITE_BALANCE, V4L2_CID_WHITE_BALANCE_TEMPERATURE, white_balance);
|
SET_CID_VALUE(_cid_auto, _field##_auto, 0, true); /* Reset inactive flag */ \
|
||||||
SET_CID_AUTO (V4L2_CID_AUTOGAIN, V4L2_CID_GAIN, gain);
|
SET_CID_DEFAULT(_cid_manual, _field, false); \
|
||||||
|
SET_CID_DEFAULT(_cid_auto, _field##_auto, false); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
# undef SET_CID_AUTO
|
CONTROL_AUTO_CID (V4L2_CID_AUTOBRIGHTNESS, V4L2_CID_BRIGHTNESS, brightness);
|
||||||
# undef SET_CID_MANUAL
|
CONTROL_MANUAL_CID ( V4L2_CID_CONTRAST, contrast);
|
||||||
# undef SET_CID
|
CONTROL_MANUAL_CID ( V4L2_CID_SATURATION, saturation);
|
||||||
|
CONTROL_AUTO_CID (V4L2_CID_HUE_AUTO, V4L2_CID_HUE, hue);
|
||||||
|
CONTROL_MANUAL_CID ( V4L2_CID_GAMMA, gamma);
|
||||||
|
CONTROL_MANUAL_CID ( V4L2_CID_SHARPNESS, sharpness);
|
||||||
|
CONTROL_MANUAL_CID ( V4L2_CID_BACKLIGHT_COMPENSATION, backlight_compensation);
|
||||||
|
CONTROL_AUTO_CID (V4L2_CID_AUTO_WHITE_BALANCE, V4L2_CID_WHITE_BALANCE_TEMPERATURE, white_balance);
|
||||||
|
CONTROL_AUTO_CID (V4L2_CID_AUTOGAIN, V4L2_CID_GAIN, gain);
|
||||||
|
|
||||||
|
# undef CONTROL_AUTO_CID
|
||||||
|
# undef CONTROL_MANUAL_CID
|
||||||
|
# undef SET_CID_DEFAULT
|
||||||
|
# undef SET_CID_VALUE
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _device_check_control(struct device_t *dev, const char *name, unsigned cid, int value, bool quiet) {
|
static int _device_query_control(struct device_t *dev, struct v4l2_queryctrl *query, const char *name, unsigned cid, bool quiet) {
|
||||||
struct v4l2_queryctrl query;
|
MEMSET_ZERO(*query);
|
||||||
|
query->id = cid;
|
||||||
|
|
||||||
MEMSET_ZERO(query);
|
if (xioctl(dev->run->fd, VIDIOC_QUERYCTRL, query) < 0 || query->flags & V4L2_CTRL_FLAG_DISABLED) {
|
||||||
query.id = cid;
|
|
||||||
|
|
||||||
if (xioctl(dev->run->fd, VIDIOC_QUERYCTRL, &query) < 0 || query.flags & V4L2_CTRL_FLAG_DISABLED) {
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
LOG_ERROR("Changing control %s is unsupported", name);
|
LOG_ERROR("Changing control %s is unsupported", name);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (value < query.minimum || value > query.maximum || value % query.step != 0) {
|
|
||||||
if (!quiet) {
|
|
||||||
LOG_ERROR("Invalid value %d of control %s: min=%d, max=%d, default=%d, step=%u",
|
|
||||||
value, name, query.minimum, query.maximum, query.default_value, query.step);
|
|
||||||
}
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _device_set_control(struct device_t *dev, const char *name, unsigned cid, int value, bool quiet) {
|
static void _device_set_control(struct device_t *dev, struct v4l2_queryctrl *query, const char *name, unsigned cid, int value, bool quiet) {
|
||||||
struct v4l2_control ctl;
|
struct v4l2_control ctl;
|
||||||
|
|
||||||
|
if (value < query->minimum || value > query->maximum || value % query->step != 0) {
|
||||||
|
if (!quiet) {
|
||||||
|
LOG_ERROR("Invalid value %d of control %s: min=%d, max=%d, default=%d, step=%u",
|
||||||
|
value, name, query->minimum, query->maximum, query->default_value, query->step);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MEMSET_ZERO(ctl);
|
MEMSET_ZERO(ctl);
|
||||||
ctl.id = cid;
|
ctl.id = cid;
|
||||||
ctl.value = value;
|
ctl.value = value;
|
||||||
@@ -678,7 +695,7 @@ static void _device_set_control(struct device_t *dev, const char *name, unsigned
|
|||||||
LOG_PERROR("Can't set control %s", name);
|
LOG_PERROR("Can't set control %s", name);
|
||||||
}
|
}
|
||||||
} else if (!quiet) {
|
} else if (!quiet) {
|
||||||
LOG_INFO("Using control %s: %d", name, ctl.value);
|
LOG_INFO("Applying control %s: %d", name, ctl.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/device.h
12
src/device.h
@@ -64,10 +64,16 @@ struct device_runtime_t {
|
|||||||
bool capturing;
|
bool capturing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum control_mode_t {
|
||||||
|
CTL_MODE_NONE = 0,
|
||||||
|
CTL_MODE_VALUE,
|
||||||
|
CTL_MODE_AUTO,
|
||||||
|
CTL_MODE_DEFAULT,
|
||||||
|
};
|
||||||
|
|
||||||
struct control_t {
|
struct control_t {
|
||||||
int value;
|
enum control_mode_t mode;
|
||||||
bool value_set;
|
int value;
|
||||||
bool auto_set;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct controls_t {
|
struct controls_t {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, uns
|
|||||||
|
|
||||||
assert(encoder->run->type != ENCODER_TYPE_UNKNOWN);
|
assert(encoder->run->type != ENCODER_TYPE_UNKNOWN);
|
||||||
|
|
||||||
dev->run->pictures[buf_index]->encode_begin_time = get_now_monotonic();
|
dev->run->pictures[buf_index]->encode_begin_ts = get_now_monotonic();
|
||||||
|
|
||||||
if (encoder->run->type == ENCODER_TYPE_CPU) {
|
if (encoder->run->type == ENCODER_TYPE_CPU) {
|
||||||
cpu_encoder_compress_buffer(dev, buf_index, encoder->run->quality);
|
cpu_encoder_compress_buffer(dev, buf_index, encoder->run->quality);
|
||||||
@@ -216,7 +216,7 @@ int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, uns
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
dev->run->pictures[buf_index]->encode_end_time = get_now_monotonic();
|
dev->run->pictures[buf_index]->encode_end_ts = get_now_monotonic();
|
||||||
|
|
||||||
dev->run->pictures[buf_index]->width = dev->run->width;
|
dev->run->pictures[buf_index]->width = dev->run->width;
|
||||||
dev->run->pictures[buf_index]->height = dev->run->height;
|
dev->run->pictures[buf_index]->height = dev->run->height;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ const char *guess_mime_type(const char *path) {
|
|||||||
char *dot;
|
char *dot;
|
||||||
char *ext;
|
char *ext;
|
||||||
|
|
||||||
dot = strchr(path, '.');
|
dot = strrchr(path, '.');
|
||||||
if (dot == NULL || strchr(dot, '/') != NULL) {
|
if (dot == NULL || strchr(dot, '/') != NULL) {
|
||||||
goto misc;
|
goto misc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
#include "../tools.h"
|
#include "../tools.h"
|
||||||
#include "../threading.h"
|
#include "../threading.h"
|
||||||
#include "../logging.h"
|
#include "../logging.h"
|
||||||
|
#include "../process.h"
|
||||||
#include "../picture.h"
|
#include "../picture.h"
|
||||||
#include "../encoder.h"
|
#include "../encoder.h"
|
||||||
#include "../stream.h"
|
#include "../stream.h"
|
||||||
@@ -157,6 +158,7 @@ void http_server_destroy(struct http_server_t *server) {
|
|||||||
int http_server_listen(struct http_server_t *server) {
|
int http_server_listen(struct http_server_t *server) {
|
||||||
{
|
{
|
||||||
if (server->static_path[0] != '\0') {
|
if (server->static_path[0] != '\0') {
|
||||||
|
LOG_INFO("Enabling HTTP file server: %s", server->static_path);
|
||||||
evhttp_set_gencb(server->run->http, _http_callback_static, (void *)server);
|
evhttp_set_gencb(server->run->http, _http_callback_static, (void *)server);
|
||||||
} else {
|
} else {
|
||||||
assert(!evhttp_set_cb(server->run->http, "/", _http_callback_root, (void *)server));
|
assert(!evhttp_set_cb(server->run->http, "/", _http_callback_root, (void *)server));
|
||||||
@@ -172,9 +174,12 @@ int http_server_listen(struct http_server_t *server) {
|
|||||||
# define EXPOSED(_next) server->run->exposed->_next
|
# define EXPOSED(_next) server->run->exposed->_next
|
||||||
// See _expose_blank_picture()
|
// See _expose_blank_picture()
|
||||||
picture_copy(server->run->blank, EXPOSED(picture));
|
picture_copy(server->run->blank, EXPOSED(picture));
|
||||||
EXPOSED(expose_begin_time) = get_now_monotonic();
|
EXPOSED(expose_begin_ts) = get_now_monotonic();
|
||||||
EXPOSED(expose_cmp_time) = EXPOSED(expose_begin_time);
|
EXPOSED(expose_cmp_ts) = EXPOSED(expose_begin_ts);
|
||||||
EXPOSED(expose_end_time) = EXPOSED(expose_begin_time);
|
EXPOSED(expose_end_ts) = EXPOSED(expose_begin_ts);
|
||||||
|
// See _http_exposed_refresh()
|
||||||
|
EXPOSED(notify_last_width) = EXPOSED(picture->width);
|
||||||
|
EXPOSED(notify_last_height) = EXPOSED(picture->height);
|
||||||
# undef EXPOSED
|
# undef EXPOSED
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -326,7 +331,7 @@ static void _http_callback_static(struct evhttp_request *request, void *v_server
|
|||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evbuffer_add_file(buf, fd, 0, st.st_size) < 0) {
|
if (st.st_size > 0 && evbuffer_add_file(buf, fd, 0, st.st_size) < 0) {
|
||||||
LOG_ERROR("HTTP: Can't serve static file %s", static_path);
|
LOG_ERROR("HTTP: Can't serve static file %s", static_path);
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
@@ -446,17 +451,17 @@ static void _http_callback_snapshot(struct evhttp_request *request, void *v_serv
|
|||||||
|
|
||||||
ADD_TIME_HEADER("X-Timestamp", get_now_real());
|
ADD_TIME_HEADER("X-Timestamp", get_now_real());
|
||||||
|
|
||||||
ADD_HEADER("X-UStreamer-Online", bool_to_string(EXPOSED(online)));
|
ADD_HEADER("X-UStreamer-Online", bool_to_string(EXPOSED(online)));
|
||||||
ADD_UNSIGNED_HEADER("X-UStreamer-Dropped", EXPOSED(dropped));
|
ADD_UNSIGNED_HEADER("X-UStreamer-Dropped", EXPOSED(dropped));
|
||||||
ADD_UNSIGNED_HEADER("X-UStreamer-Width", EXPOSED(picture->width));
|
ADD_UNSIGNED_HEADER("X-UStreamer-Width", EXPOSED(picture->width));
|
||||||
ADD_UNSIGNED_HEADER("X-UStreamer-Height", EXPOSED(picture->height));
|
ADD_UNSIGNED_HEADER("X-UStreamer-Height", EXPOSED(picture->height));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Grab-Time", EXPOSED(picture->grab_time));
|
ADD_TIME_HEADER("X-UStreamer-Grab-Timestamp", EXPOSED(picture->grab_ts));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Encode-Begin-Time", EXPOSED(picture->encode_begin_time));
|
ADD_TIME_HEADER("X-UStreamer-Encode-Begin-Timestamp", EXPOSED(picture->encode_begin_ts));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Encode-End-Time", EXPOSED(picture->encode_end_time));
|
ADD_TIME_HEADER("X-UStreamer-Encode-End-Timestamp", EXPOSED(picture->encode_end_ts));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Expose-Begin-Time", EXPOSED(expose_begin_time));
|
ADD_TIME_HEADER("X-UStreamer-Expose-Begin-Timestamp", EXPOSED(expose_begin_ts));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Expose-Cmp-Time", EXPOSED(expose_cmp_time));
|
ADD_TIME_HEADER("X-UStreamer-Expose-Cmp-Timestamp", EXPOSED(expose_cmp_ts));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Expose-End-Time", EXPOSED(expose_end_time));
|
ADD_TIME_HEADER("X-UStreamer-Expose-End-Timestamp", EXPOSED(expose_end_ts));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Send-Time", get_now_monotonic());
|
ADD_TIME_HEADER("X-UStreamer-Send-Timestamp", get_now_monotonic());
|
||||||
|
|
||||||
# undef ADD_UNSUGNED_HEADER
|
# undef ADD_UNSUGNED_HEADER
|
||||||
# undef ADD_TIME_HEADER
|
# undef ADD_TIME_HEADER
|
||||||
@@ -637,12 +642,12 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
|||||||
EXPOSED(picture->width),
|
EXPOSED(picture->width),
|
||||||
EXPOSED(picture->height),
|
EXPOSED(picture->height),
|
||||||
client->fps,
|
client->fps,
|
||||||
EXPOSED(picture->grab_time),
|
EXPOSED(picture->grab_ts),
|
||||||
EXPOSED(picture->encode_begin_time),
|
EXPOSED(picture->encode_begin_ts),
|
||||||
EXPOSED(picture->encode_end_time),
|
EXPOSED(picture->encode_end_ts),
|
||||||
EXPOSED(expose_begin_time),
|
EXPOSED(expose_begin_ts),
|
||||||
EXPOSED(expose_cmp_time),
|
EXPOSED(expose_cmp_ts),
|
||||||
EXPOSED(expose_end_time),
|
EXPOSED(expose_end_ts),
|
||||||
now
|
now
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -790,6 +795,25 @@ static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, void *v_serv
|
|||||||
# undef UNLOCK_STREAM
|
# undef UNLOCK_STREAM
|
||||||
|
|
||||||
_http_queue_send_stream(server, stream_updated, picture_updated);
|
_http_queue_send_stream(server, stream_updated, picture_updated);
|
||||||
|
|
||||||
|
# define EXPOSED(_next) server->run->exposed->_next
|
||||||
|
|
||||||
|
if (
|
||||||
|
picture_updated
|
||||||
|
&& server->notify_parent
|
||||||
|
&& (
|
||||||
|
EXPOSED(notify_last_online) != EXPOSED(online)
|
||||||
|
|| EXPOSED(notify_last_width) != EXPOSED(picture->width)
|
||||||
|
|| EXPOSED(notify_last_height) != EXPOSED(picture->height)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
EXPOSED(notify_last_online) = EXPOSED(online);
|
||||||
|
EXPOSED(notify_last_width) = EXPOSED(picture->width);
|
||||||
|
EXPOSED(notify_last_height) = EXPOSED(picture->height);
|
||||||
|
process_notify_parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
# undef EXPOSED
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
||||||
@@ -797,7 +821,7 @@ static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
|||||||
# define STREAM(_next) server->run->stream->_next
|
# define STREAM(_next) server->run->stream->_next
|
||||||
|
|
||||||
EXPOSED(captured_fps) = STREAM(captured_fps);
|
EXPOSED(captured_fps) = STREAM(captured_fps);
|
||||||
EXPOSED(expose_begin_time) = get_now_monotonic();
|
EXPOSED(expose_begin_ts) = get_now_monotonic();
|
||||||
|
|
||||||
if (server->drop_same_frames) {
|
if (server->drop_same_frames) {
|
||||||
if (
|
if (
|
||||||
@@ -805,16 +829,16 @@ static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
|||||||
&& EXPOSED(dropped) < server->drop_same_frames
|
&& EXPOSED(dropped) < server->drop_same_frames
|
||||||
&& picture_compare(EXPOSED(picture), STREAM(picture))
|
&& picture_compare(EXPOSED(picture), STREAM(picture))
|
||||||
) {
|
) {
|
||||||
EXPOSED(expose_cmp_time) = get_now_monotonic();
|
EXPOSED(expose_cmp_ts) = get_now_monotonic();
|
||||||
EXPOSED(expose_end_time) = EXPOSED(expose_cmp_time);
|
EXPOSED(expose_end_ts) = EXPOSED(expose_cmp_ts);
|
||||||
LOG_VERBOSE("HTTP: Dropped same frame number %u; cmp_time=%.06Lf",
|
LOG_VERBOSE("HTTP: Dropped same frame number %u; cmp_time=%.06Lf",
|
||||||
EXPOSED(dropped), EXPOSED(expose_cmp_time) - EXPOSED(expose_begin_time));
|
EXPOSED(dropped), EXPOSED(expose_cmp_ts) - EXPOSED(expose_begin_ts));
|
||||||
EXPOSED(dropped) += 1;
|
EXPOSED(dropped) += 1;
|
||||||
return false; // Not updated
|
return false; // Not updated
|
||||||
} else {
|
} else {
|
||||||
EXPOSED(expose_cmp_time) = get_now_monotonic();
|
EXPOSED(expose_cmp_ts) = get_now_monotonic();
|
||||||
LOG_VERBOSE("HTTP: Passed same frame check (frames are differ); cmp_time=%.06Lf",
|
LOG_VERBOSE("HTTP: Passed same frame check (frames are differ); cmp_time=%.06Lf",
|
||||||
EXPOSED(expose_cmp_time) - EXPOSED(expose_begin_time));
|
EXPOSED(expose_cmp_ts) - EXPOSED(expose_begin_ts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -824,11 +848,11 @@ static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
|||||||
|
|
||||||
EXPOSED(online) = true;
|
EXPOSED(online) = true;
|
||||||
EXPOSED(dropped) = 0;
|
EXPOSED(dropped) = 0;
|
||||||
EXPOSED(expose_cmp_time) = EXPOSED(expose_begin_time);
|
EXPOSED(expose_cmp_ts) = EXPOSED(expose_begin_ts);
|
||||||
EXPOSED(expose_end_time) = get_now_monotonic();
|
EXPOSED(expose_end_ts) = get_now_monotonic();
|
||||||
|
|
||||||
LOG_VERBOSE("HTTP: Exposed new frame; full exposition time = %.06Lf",
|
LOG_VERBOSE("HTTP: Exposed new frame; full exposition time = %.06Lf",
|
||||||
EXPOSED(expose_end_time) - EXPOSED(expose_begin_time));
|
EXPOSED(expose_end_ts) - EXPOSED(expose_begin_ts));
|
||||||
|
|
||||||
# undef EXPOSED
|
# undef EXPOSED
|
||||||
return true; // Updated
|
return true; // Updated
|
||||||
@@ -837,8 +861,8 @@ static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
|||||||
static bool _expose_blank_picture(struct http_server_t *server) {
|
static bool _expose_blank_picture(struct http_server_t *server) {
|
||||||
# define EXPOSED(_next) server->run->exposed->_next
|
# define EXPOSED(_next) server->run->exposed->_next
|
||||||
|
|
||||||
EXPOSED(expose_begin_time) = get_now_monotonic();
|
EXPOSED(expose_begin_ts) = get_now_monotonic();
|
||||||
EXPOSED(expose_cmp_time) = EXPOSED(expose_begin_time);
|
EXPOSED(expose_cmp_ts) = EXPOSED(expose_begin_ts);
|
||||||
|
|
||||||
# define EXPOSE_BLANK picture_copy(server->run->blank, EXPOSED(picture))
|
# define EXPOSE_BLANK picture_copy(server->run->blank, EXPOSED(picture))
|
||||||
|
|
||||||
@@ -848,7 +872,7 @@ static bool _expose_blank_picture(struct http_server_t *server) {
|
|||||||
EXPOSE_BLANK;
|
EXPOSE_BLANK;
|
||||||
} else if (server->last_as_blank > 0) { // Если нужен таймер - запустим
|
} else if (server->last_as_blank > 0) { // Если нужен таймер - запустим
|
||||||
LOG_INFO("HTTP: Freezing last alive frame for %d seconds", server->last_as_blank);
|
LOG_INFO("HTTP: Freezing last alive frame for %d seconds", server->last_as_blank);
|
||||||
EXPOSED(last_as_blank_time) = get_now_monotonic();
|
EXPOSED(last_as_blank_ts) = get_now_monotonic();
|
||||||
} else { // last_as_blank == 0 - показываем последний фрейм вечно
|
} else { // last_as_blank == 0 - показываем последний фрейм вечно
|
||||||
LOG_INFO("HTTP: Freezing last alive frame forever");
|
LOG_INFO("HTTP: Freezing last alive frame forever");
|
||||||
}
|
}
|
||||||
@@ -857,12 +881,12 @@ static bool _expose_blank_picture(struct http_server_t *server) {
|
|||||||
|
|
||||||
if ( // Если уже оффлайн, включена фича last_as_blank с таймером и он запущен
|
if ( // Если уже оффлайн, включена фича last_as_blank с таймером и он запущен
|
||||||
server->last_as_blank > 0
|
server->last_as_blank > 0
|
||||||
&& EXPOSED(last_as_blank_time) > 0
|
&& EXPOSED(last_as_blank_ts) > 0
|
||||||
&& EXPOSED(last_as_blank_time) + server->last_as_blank < EXPOSED(expose_begin_time)
|
&& EXPOSED(last_as_blank_ts) + server->last_as_blank < EXPOSED(expose_begin_ts)
|
||||||
) {
|
) {
|
||||||
LOG_INFO("HTTP: Changed last alive frame to BLANK");
|
LOG_INFO("HTTP: Changed last alive frame to BLANK");
|
||||||
EXPOSE_BLANK;
|
EXPOSE_BLANK;
|
||||||
EXPOSED(last_as_blank_time) = 0; // Останавливаем таймер
|
EXPOSED(last_as_blank_ts) = 0; // Останавливаем таймер
|
||||||
goto updated;
|
goto updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -871,7 +895,7 @@ static bool _expose_blank_picture(struct http_server_t *server) {
|
|||||||
if (EXPOSED(dropped) < server->run->drop_same_frames_blank) {
|
if (EXPOSED(dropped) < server->run->drop_same_frames_blank) {
|
||||||
LOG_PERF("HTTP: Dropped same frame (BLANK) number %u", EXPOSED(dropped));
|
LOG_PERF("HTTP: Dropped same frame (BLANK) number %u", EXPOSED(dropped));
|
||||||
EXPOSED(dropped) += 1;
|
EXPOSED(dropped) += 1;
|
||||||
EXPOSED(expose_end_time) = get_now_monotonic();
|
EXPOSED(expose_end_ts) = get_now_monotonic();
|
||||||
return false; // Not updated
|
return false; // Not updated
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -879,7 +903,7 @@ static bool _expose_blank_picture(struct http_server_t *server) {
|
|||||||
EXPOSED(captured_fps) = 0;
|
EXPOSED(captured_fps) = 0;
|
||||||
EXPOSED(online) = false;
|
EXPOSED(online) = false;
|
||||||
EXPOSED(dropped) = 0;
|
EXPOSED(dropped) = 0;
|
||||||
EXPOSED(expose_end_time) = get_now_monotonic();
|
EXPOSED(expose_end_ts) = get_now_monotonic();
|
||||||
return true; // Updated
|
return true; // Updated
|
||||||
|
|
||||||
# undef EXPOSED
|
# undef EXPOSED
|
||||||
|
|||||||
@@ -61,10 +61,14 @@ struct exposed_t {
|
|||||||
unsigned queued_fps;
|
unsigned queued_fps;
|
||||||
bool online;
|
bool online;
|
||||||
unsigned dropped;
|
unsigned dropped;
|
||||||
long double expose_begin_time;
|
long double expose_begin_ts;
|
||||||
long double expose_cmp_time;
|
long double expose_cmp_ts;
|
||||||
long double expose_end_time;
|
long double expose_end_ts;
|
||||||
long double last_as_blank_time;
|
long double last_as_blank_ts;
|
||||||
|
|
||||||
|
bool notify_last_online;
|
||||||
|
unsigned notify_last_width;
|
||||||
|
unsigned notify_last_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct http_server_runtime_t {
|
struct http_server_runtime_t {
|
||||||
@@ -100,6 +104,8 @@ struct http_server_t {
|
|||||||
unsigned fake_width;
|
unsigned fake_width;
|
||||||
unsigned fake_height;
|
unsigned fake_height;
|
||||||
|
|
||||||
|
bool notify_parent;
|
||||||
|
|
||||||
struct http_server_runtime_t *run;
|
struct http_server_runtime_t *run;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "../tools.h"
|
#include "../tools.h"
|
||||||
// #include "../logging.h"
|
#include "../logging.h"
|
||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ char *find_static_file_path(const char *root_path, const char *request_path) {
|
|||||||
|
|
||||||
simplified_path = simplify_request_path(request_path);
|
simplified_path = simplify_request_path(request_path);
|
||||||
if (simplified_path[0] == '\0') {
|
if (simplified_path[0] == '\0') {
|
||||||
|
LOG_VERBOSE("HTTP: Invalid request path %s to static", request_path);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,13 +51,14 @@ char *find_static_file_path(const char *root_path, const char *request_path) {
|
|||||||
|
|
||||||
# define LOAD_STAT { \
|
# define LOAD_STAT { \
|
||||||
if (lstat(path, &st) < 0) { \
|
if (lstat(path, &st) < 0) { \
|
||||||
/* LOG_PERROR("Can't stat() file %s", path); */ \
|
LOG_VERBOSE_PERROR("HTTP: Can't stat() static path %s", path); \
|
||||||
goto error; \
|
goto error; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
LOAD_STAT;
|
LOAD_STAT;
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
|
LOG_VERBOSE("HTTP: Requested static path %s is a directory, trying %s/index.html", path, path);
|
||||||
strcat(path, "/index.html");
|
strcat(path, "/index.html");
|
||||||
LOAD_STAT;
|
LOAD_STAT;
|
||||||
}
|
}
|
||||||
@@ -64,12 +66,12 @@ char *find_static_file_path(const char *root_path, const char *request_path) {
|
|||||||
# undef LOAD_STAT
|
# undef LOAD_STAT
|
||||||
|
|
||||||
if (!S_ISREG(st.st_mode)) {
|
if (!S_ISREG(st.st_mode)) {
|
||||||
// LOG_ERROR("Not a regulary file: %s", path);
|
LOG_VERBOSE("HTTP: Not a regular file: %s", path);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(path, R_OK) < 0) {
|
if (access(path, R_OK) < 0) {
|
||||||
// LOG_PERROR("Can't access() R_OK file %s", path);
|
LOG_VERBOSE_PERROR("HTTP: Can't access() R_OK file %s", path);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,14 +88,14 @@ pthread_mutex_t log_mutex;
|
|||||||
|
|
||||||
|
|
||||||
#define LOG_PRINTF_NOLOCK(_label_color, _label, _msg_color, _msg, ...) { \
|
#define LOG_PRINTF_NOLOCK(_label_color, _label, _msg_color, _msg, ...) { \
|
||||||
char _buf[MAX_THREAD_NAME] = {0}; \
|
char _tname_buf[MAX_THREAD_NAME] = {0}; \
|
||||||
thread_get_name(_buf); \
|
thread_get_name(_tname_buf); \
|
||||||
if (log_colored) { \
|
if (log_colored) { \
|
||||||
printf(COLOR_GRAY "-- " _label_color _label COLOR_GRAY " [%.03Lf %9s]" " -- " COLOR_RESET _msg_color _msg COLOR_RESET, \
|
printf(COLOR_GRAY "-- " _label_color _label COLOR_GRAY " [%.03Lf %9s]" " -- " COLOR_RESET _msg_color _msg COLOR_RESET, \
|
||||||
get_now_monotonic(), _buf, ##__VA_ARGS__); \
|
get_now_monotonic(), _tname_buf, ##__VA_ARGS__); \
|
||||||
} else { \
|
} else { \
|
||||||
printf("-- " _label " [%.03Lf %9s] -- " _msg, \
|
printf("-- " _label " [%.03Lf %9s] -- " _msg, \
|
||||||
get_now_monotonic(), _buf, ##__VA_ARGS__); \
|
get_now_monotonic(), _tname_buf, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
putchar('\n'); \
|
putchar('\n'); \
|
||||||
fflush(stdout); \
|
fflush(stdout); \
|
||||||
@@ -112,9 +112,9 @@ pthread_mutex_t log_mutex;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_PERROR(_msg, ...) { \
|
#define LOG_PERROR(_msg, ...) { \
|
||||||
char _buf[1024] = {0}; \
|
char _perror_buf[1024] = {0}; \
|
||||||
char *_ptr = errno_to_string(_buf, 1024); \
|
char *_perror_ptr = errno_to_string(_perror_buf, 1024); \
|
||||||
LOG_ERROR(_msg ": %s", ##__VA_ARGS__, _ptr); \
|
LOG_ERROR(_msg ": %s", ##__VA_ARGS__, _perror_ptr); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_INFO(_msg, ...) { \
|
#define LOG_INFO(_msg, ...) { \
|
||||||
@@ -143,6 +143,14 @@ pthread_mutex_t log_mutex;
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LOG_VERBOSE_PERROR(_msg, ...) { \
|
||||||
|
if (log_level >= LOG_LEVEL_VERBOSE) { \
|
||||||
|
char _perror_buf[1024] = {0}; \
|
||||||
|
char *_perror_ptr = errno_to_string(_perror_buf, 1024); \
|
||||||
|
LOG_PRINTF(COLOR_BLUE, "VERB ", COLOR_BLUE, _msg ": %s", ##__VA_ARGS__, _perror_ptr); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define LOG_DEBUG(_msg, ...) { \
|
#define LOG_DEBUG(_msg, ...) { \
|
||||||
if (log_level >= LOG_LEVEL_DEBUG) { \
|
if (log_level >= LOG_LEVEL_DEBUG) { \
|
||||||
LOG_PRINTF(COLOR_GRAY, "DEBUG", COLOR_GRAY, _msg, ##__VA_ARGS__); \
|
LOG_PRINTF(COLOR_GRAY, "DEBUG", COLOR_GRAY, _msg, ##__VA_ARGS__); \
|
||||||
|
|||||||
11
src/main.c
11
src/main.c
@@ -25,6 +25,11 @@
|
|||||||
# error WTF dude? Asserts are good things!
|
# error WTF dude? Asserts are good things!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#if CHAR_BIT != 8
|
||||||
|
# error There are not 8 bits in a char!
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
@@ -98,6 +103,7 @@ static void _install_signal_handlers(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
struct options_t *options;
|
||||||
struct device_t *dev;
|
struct device_t *dev;
|
||||||
struct encoder_t *encoder;
|
struct encoder_t *encoder;
|
||||||
struct stream_t *stream;
|
struct stream_t *stream;
|
||||||
@@ -105,8 +111,8 @@ int main(int argc, char *argv[]) {
|
|||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
|
|
||||||
LOGGING_INIT;
|
LOGGING_INIT;
|
||||||
|
|
||||||
A_THREAD_RENAME("main");
|
A_THREAD_RENAME("main");
|
||||||
|
options = options_init(argc, argv);
|
||||||
|
|
||||||
# ifdef WITH_GPIO
|
# ifdef WITH_GPIO
|
||||||
GPIO_INIT;
|
GPIO_INIT;
|
||||||
@@ -117,7 +123,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 = parse_options(argc, argv, dev, encoder, server)) == 0) {
|
if ((exit_code = options_parse(options, dev, encoder, server)) == 0) {
|
||||||
# ifdef WITH_GPIO
|
# ifdef WITH_GPIO
|
||||||
GPIO_INIT_PINOUT;
|
GPIO_INIT_PINOUT;
|
||||||
# endif
|
# endif
|
||||||
@@ -153,6 +159,7 @@ int main(int argc, char *argv[]) {
|
|||||||
GPIO_SET_LOW(prog_running);
|
GPIO_SET_LOW(prog_running);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
options_destroy(options);
|
||||||
if (exit_code == 0) {
|
if (exit_code == 0) {
|
||||||
LOG_INFO("Bye-bye");
|
LOG_INFO("Bye-bye");
|
||||||
}
|
}
|
||||||
|
|||||||
137
src/options.c
137
src/options.c
@@ -25,9 +25,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#ifdef WITH_OMX
|
#include <string.h>
|
||||||
# include <string.h>
|
#include <strings.h>
|
||||||
#endif
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
@@ -82,19 +81,16 @@ enum _OPT_VALUES {
|
|||||||
_O_DEVICE_TIMEOUT = 10000,
|
_O_DEVICE_TIMEOUT = 10000,
|
||||||
_O_DEVICE_ERROR_DELAY,
|
_O_DEVICE_ERROR_DELAY,
|
||||||
|
|
||||||
|
_O_IMAGE_DEFAULT,
|
||||||
_O_BRIGHTNESS,
|
_O_BRIGHTNESS,
|
||||||
_O_BRIGHTNESS_AUTO,
|
|
||||||
_O_CONTRAST,
|
_O_CONTRAST,
|
||||||
_O_SATURATION,
|
_O_SATURATION,
|
||||||
_O_HUE,
|
_O_HUE,
|
||||||
_O_HUE_AUTO,
|
|
||||||
_O_GAMMA,
|
_O_GAMMA,
|
||||||
_O_SHARPNESS,
|
_O_SHARPNESS,
|
||||||
_O_BACKLIGHT_COMPENSATION,
|
_O_BACKLIGHT_COMPENSATION,
|
||||||
_O_WHITE_BALANCE,
|
_O_WHITE_BALANCE,
|
||||||
_O_WHITE_BALANCE_AUTO,
|
|
||||||
_O_GAIN,
|
_O_GAIN,
|
||||||
_O_GAIN_AUTO,
|
|
||||||
|
|
||||||
_O_USER,
|
_O_USER,
|
||||||
_O_PASSWD,
|
_O_PASSWD,
|
||||||
@@ -114,6 +110,7 @@ enum _OPT_VALUES {
|
|||||||
#ifdef WITH_SETPROCTITLE
|
#ifdef WITH_SETPROCTITLE
|
||||||
_O_PROCESS_NAME_PREFIX,
|
_O_PROCESS_NAME_PREFIX,
|
||||||
#endif
|
#endif
|
||||||
|
_O_NOTIFY_PARENT,
|
||||||
|
|
||||||
_O_LOG_LEVEL,
|
_O_LOG_LEVEL,
|
||||||
_O_PERF,
|
_O_PERF,
|
||||||
@@ -145,19 +142,16 @@ static const struct option _LONG_OPTS[] = {
|
|||||||
{"device-timeout", required_argument, NULL, _O_DEVICE_TIMEOUT},
|
{"device-timeout", required_argument, NULL, _O_DEVICE_TIMEOUT},
|
||||||
{"device-error-delay", required_argument, NULL, _O_DEVICE_ERROR_DELAY},
|
{"device-error-delay", required_argument, NULL, _O_DEVICE_ERROR_DELAY},
|
||||||
|
|
||||||
|
{"image-default", no_argument, NULL, _O_IMAGE_DEFAULT},
|
||||||
{"brightness", required_argument, NULL, _O_BRIGHTNESS},
|
{"brightness", required_argument, NULL, _O_BRIGHTNESS},
|
||||||
{"brightness-auto", no_argument, NULL, _O_BRIGHTNESS_AUTO},
|
|
||||||
{"contrast", required_argument, NULL, _O_CONTRAST},
|
{"contrast", required_argument, NULL, _O_CONTRAST},
|
||||||
{"saturation", required_argument, NULL, _O_SATURATION},
|
{"saturation", required_argument, NULL, _O_SATURATION},
|
||||||
{"hue", required_argument, NULL, _O_HUE},
|
{"hue", required_argument, NULL, _O_HUE},
|
||||||
{"hue-auto", no_argument, NULL, _O_HUE_AUTO},
|
|
||||||
{"gamma", required_argument, NULL, _O_GAMMA},
|
{"gamma", required_argument, NULL, _O_GAMMA},
|
||||||
{"sharpness", required_argument, NULL, _O_SHARPNESS},
|
{"sharpness", required_argument, NULL, _O_SHARPNESS},
|
||||||
{"backlight-compensation", required_argument, NULL, _O_BACKLIGHT_COMPENSATION},
|
{"backlight-compensation", required_argument, NULL, _O_BACKLIGHT_COMPENSATION},
|
||||||
{"white-balance", required_argument, NULL, _O_WHITE_BALANCE},
|
{"white-balance", required_argument, NULL, _O_WHITE_BALANCE},
|
||||||
{"white-balance-auto", no_argument, NULL, _O_WHITE_BALANCE_AUTO},
|
|
||||||
{"gain", required_argument, NULL, _O_GAIN},
|
{"gain", required_argument, NULL, _O_GAIN},
|
||||||
{"gain-auto", no_argument, NULL, _O_GAIN_AUTO},
|
|
||||||
|
|
||||||
{"host", required_argument, NULL, _O_HOST},
|
{"host", required_argument, NULL, _O_HOST},
|
||||||
{"port", required_argument, NULL, _O_PORT},
|
{"port", required_argument, NULL, _O_PORT},
|
||||||
@@ -187,6 +181,7 @@ static const struct option _LONG_OPTS[] = {
|
|||||||
#ifdef WITH_SETPROCTITLE
|
#ifdef WITH_SETPROCTITLE
|
||||||
{"process-name-prefix", required_argument, NULL, _O_PROCESS_NAME_PREFIX},
|
{"process-name-prefix", required_argument, NULL, _O_PROCESS_NAME_PREFIX},
|
||||||
#endif
|
#endif
|
||||||
|
{"notify-parent", no_argument, NULL, _O_NOTIFY_PARENT},
|
||||||
|
|
||||||
{"log-level", required_argument, NULL, _O_LOG_LEVEL},
|
{"log-level", required_argument, NULL, _O_LOG_LEVEL},
|
||||||
{"perf", no_argument, NULL, _O_PERF},
|
{"perf", no_argument, NULL, _O_PERF},
|
||||||
@@ -212,7 +207,31 @@ 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 http_server_t *server);
|
||||||
|
|
||||||
|
|
||||||
int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server) {
|
struct options_t *options_init(int argc, char *argv[]) {
|
||||||
|
struct options_t *options;
|
||||||
|
|
||||||
|
A_CALLOC(options, 1);
|
||||||
|
options->argc = argc;
|
||||||
|
options->argv = argv;
|
||||||
|
|
||||||
|
A_CALLOC(options->argv_copy, argc);
|
||||||
|
for (int index = 0; index < argc; ++index) {
|
||||||
|
assert(options->argv_copy[index] = strdup(argv[index]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
void options_destroy(struct options_t *options) {
|
||||||
|
for (int index = 0; index < options->argc; ++index) {
|
||||||
|
free(options->argv_copy[index]);
|
||||||
|
}
|
||||||
|
free(options->argv_copy);
|
||||||
|
free(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int options_parse(struct options_t *options, struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server) {
|
||||||
# define OPT_SET(_dest, _value) { \
|
# define OPT_SET(_dest, _value) { \
|
||||||
_dest = _value; \
|
_dest = _value; \
|
||||||
break; \
|
break; \
|
||||||
@@ -253,16 +272,29 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
|
|||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define OPT_CTL(_dest) { \
|
# define OPT_CTL_DEFAULT_NOBREAK(_dest) { \
|
||||||
dev->ctl._dest.value_set = true; \
|
dev->ctl._dest.mode = CTL_MODE_DEFAULT; \
|
||||||
dev->ctl._dest.auto_set = false; \
|
}
|
||||||
OPT_NUMBER("--"#_dest, dev->ctl._dest.value, INT_MIN, INT_MAX, 0); \
|
|
||||||
|
# define OPT_CTL_MANUAL(_dest) { \
|
||||||
|
if (!strcasecmp(optarg, "default")) { \
|
||||||
|
OPT_CTL_DEFAULT_NOBREAK(_dest); \
|
||||||
|
} else { \
|
||||||
|
dev->ctl._dest.mode = CTL_MODE_VALUE; \
|
||||||
|
OPT_NUMBER("--"#_dest, dev->ctl._dest.value, INT_MIN, INT_MAX, 0); \
|
||||||
|
} \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define OPT_CTL_AUTO(_dest) { \
|
# define OPT_CTL_AUTO(_dest) { \
|
||||||
dev->ctl._dest.value_set = false; \
|
if (!strcasecmp(optarg, "default")) { \
|
||||||
dev->ctl._dest.auto_set = true; \
|
OPT_CTL_DEFAULT_NOBREAK(_dest); \
|
||||||
|
} else if (!strcasecmp(optarg, "auto")) { \
|
||||||
|
dev->ctl._dest.mode = CTL_MODE_AUTO; \
|
||||||
|
} else { \
|
||||||
|
dev->ctl._dest.mode = CTL_MODE_VALUE; \
|
||||||
|
OPT_NUMBER("--"#_dest, dev->ctl._dest.value, INT_MIN, INT_MAX, 0); \
|
||||||
|
} \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +317,7 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, short_opts, _LONG_OPTS, NULL)) >= 0) {
|
while ((ch = getopt_long(options->argc, options->argv_copy, short_opts, _LONG_OPTS, NULL)) >= 0) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case _O_DEVICE: OPT_SET(dev->path, optarg);
|
case _O_DEVICE: OPT_SET(dev->path, optarg);
|
||||||
case _O_INPUT: OPT_NUMBER("--input", dev->input, 0, 128, 0);
|
case _O_INPUT: OPT_NUMBER("--input", dev->input, 0, 128, 0);
|
||||||
@@ -313,19 +345,26 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
|
|||||||
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", dev->error_delay, 1, 60, 0);
|
||||||
|
|
||||||
case _O_BRIGHTNESS: OPT_CTL(brightness);
|
case _O_IMAGE_DEFAULT:
|
||||||
case _O_BRIGHTNESS_AUTO: OPT_CTL_AUTO(brightness);
|
OPT_CTL_DEFAULT_NOBREAK(brightness);
|
||||||
case _O_CONTRAST: OPT_CTL(contrast);
|
OPT_CTL_DEFAULT_NOBREAK(contrast);
|
||||||
case _O_SATURATION: OPT_CTL(saturation);
|
OPT_CTL_DEFAULT_NOBREAK(saturation);
|
||||||
case _O_HUE: OPT_CTL(hue);
|
OPT_CTL_DEFAULT_NOBREAK(hue);
|
||||||
case _O_HUE_AUTO: OPT_CTL_AUTO(hue);
|
OPT_CTL_DEFAULT_NOBREAK(gamma);
|
||||||
case _O_GAMMA: OPT_CTL(gamma);
|
OPT_CTL_DEFAULT_NOBREAK(sharpness);
|
||||||
case _O_SHARPNESS: OPT_CTL(sharpness);
|
OPT_CTL_DEFAULT_NOBREAK(backlight_compensation);
|
||||||
case _O_BACKLIGHT_COMPENSATION: OPT_CTL(backlight_compensation);
|
OPT_CTL_DEFAULT_NOBREAK(white_balance);
|
||||||
case _O_WHITE_BALANCE: OPT_CTL(white_balance);
|
OPT_CTL_DEFAULT_NOBREAK(gain);
|
||||||
case _O_WHITE_BALANCE_AUTO: OPT_CTL_AUTO(white_balance);
|
break;
|
||||||
case _O_GAIN: OPT_CTL(gain);
|
case _O_BRIGHTNESS: OPT_CTL_AUTO(brightness);
|
||||||
case _O_GAIN_AUTO: OPT_CTL_AUTO(gain);
|
case _O_CONTRAST: OPT_CTL_MANUAL(contrast);
|
||||||
|
case _O_SATURATION: OPT_CTL_MANUAL(saturation);
|
||||||
|
case _O_HUE: OPT_CTL_AUTO(hue);
|
||||||
|
case _O_GAMMA: OPT_CTL_MANUAL(gamma);
|
||||||
|
case _O_SHARPNESS: OPT_CTL_MANUAL(sharpness);
|
||||||
|
case _O_BACKLIGHT_COMPENSATION: OPT_CTL_MANUAL(backlight_compensation);
|
||||||
|
case _O_WHITE_BALANCE: OPT_CTL_AUTO(white_balance);
|
||||||
|
case _O_GAIN: OPT_CTL_AUTO(gain);
|
||||||
|
|
||||||
case _O_HOST: OPT_SET(server->host, optarg);
|
case _O_HOST: OPT_SET(server->host, optarg);
|
||||||
case _O_PORT: OPT_NUMBER("--port", server->port, 1, 65535, 0);
|
case _O_PORT: OPT_NUMBER("--port", server->port, 1, 65535, 0);
|
||||||
@@ -359,6 +398,7 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
|
|||||||
# ifdef WITH_SETPROCTITLE
|
# ifdef WITH_SETPROCTITLE
|
||||||
case _O_PROCESS_NAME_PREFIX: OPT_SET(process_name_prefix, optarg);
|
case _O_PROCESS_NAME_PREFIX: OPT_SET(process_name_prefix, optarg);
|
||||||
# endif
|
# endif
|
||||||
|
case _O_NOTIFY_PARENT: OPT_SET(server->notify_parent, true);
|
||||||
|
|
||||||
case _O_LOG_LEVEL: OPT_NUMBER("--log-level", log_level, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, 0);
|
case _O_LOG_LEVEL: OPT_NUMBER("--log-level", log_level, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, 0);
|
||||||
case _O_PERF: OPT_SET(log_level, LOG_LEVEL_PERF);
|
case _O_PERF: OPT_SET(log_level, LOG_LEVEL_PERF);
|
||||||
@@ -378,12 +418,13 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
|
|||||||
|
|
||||||
# ifdef WITH_SETPROCTITLE
|
# ifdef WITH_SETPROCTITLE
|
||||||
if (process_name_prefix != NULL) {
|
if (process_name_prefix != NULL) {
|
||||||
process_set_name_prefix(argc, argv, process_name_prefix);
|
process_set_name_prefix(options->argc, options->argv, process_name_prefix);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# undef OPT_CTL_AUTO
|
# undef OPT_CTL_AUTO
|
||||||
# undef OPT_CTL
|
# undef OPT_CTL_MANUAL
|
||||||
|
# undef OPT_CTL_DEFAULT_NOBREAK
|
||||||
# undef OPT_PARSE
|
# undef OPT_PARSE
|
||||||
# undef OPT_RESOLUTION
|
# undef OPT_RESOLUTION
|
||||||
# undef OPT_NUMBER
|
# undef OPT_NUMBER
|
||||||
@@ -540,19 +581,17 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
|
|||||||
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", dev->error_delay);
|
||||||
printf("Image control options:\n");
|
printf("Image control options:\n");
|
||||||
printf("══════════════════════\n");
|
printf("══════════════════════\n");
|
||||||
printf(" --brightness <N> ───────────── Set brightness. Default: no change.\n\n");
|
printf(" --image-default ────────────────────── Reset all image settings bellow to default. Default: no change.\n\n");
|
||||||
printf(" --brightness-auto ──────────── Enable automatic brightness control. Default: no change.\n\n");
|
printf(" --brightness <N|auto|default> ──────── Set brightness. Default: no change.\n\n");
|
||||||
printf(" --contrast <N> ─────────────── Set contrast. Default: no change.\n\n");
|
printf(" --contrast <N|default> ─────────────── Set contrast. Default: no change.\n\n");
|
||||||
printf(" --saturation <N> ───────────── Set saturation. Default: no change.\n\n");
|
printf(" --saturation <N|default> ───────────── Set saturation. Default: no change.\n\n");
|
||||||
printf(" --hue <N> ──────────────────── Set hue. Default: no change.\n\n");
|
printf(" --hue <N|auto|default> ─────────────── Set hue. Default: no change.\n\n");
|
||||||
printf(" --hue-auto ─────────────────── Enable automatic hue control. Default: no change.\n\n");
|
printf(" --gamma <N|default> ─────────────────── Set gamma. Default: no change.\n\n");
|
||||||
printf(" --gamma <N> ────────────────── Set gamma. Default: no change.\n\n");
|
printf(" --sharpness <N|default> ────────────── Set sharpness. Default: no change.\n\n");
|
||||||
printf(" --sharpness <N> ────────────── Set sharpness. Default: no change.\n\n");
|
printf(" --backlight-compensation <N|default> ─ Set backlight compensation. Default: no change.\n\n");
|
||||||
printf(" --backlight-compensation <N> ─ Set backlight compensation. Default: no change.\n\n");
|
printf(" --white-balance <N|auto|default> ───── Set white balance. Default: no change.\n\n");
|
||||||
printf(" --white-balance <N> ────────── Set white balance. Default: no change.\n\n");
|
printf(" --gain <N|auto|default> ────────────── Set gain. Default: no change.\n\n");
|
||||||
printf(" --white-balance-auto ───────── Enable automatic white balance control. Default: no change.\n\n");
|
printf(" Hint: use v4l2-ctl --list-ctrls-menus to query available controls of the device.\n\n");
|
||||||
printf(" --gain <N> ─────────────────── Set gain. Default: no change.\n\n");
|
|
||||||
printf(" --gain-auto ────────────────── Enable automatic gain control. Default: no change.\n\n");
|
|
||||||
printf("HTTP server options:\n");
|
printf("HTTP server options:\n");
|
||||||
printf("════════════════════\n");
|
printf("════════════════════\n");
|
||||||
printf(" -s|--host <address> ──────── Listen on Hostname or IP. Default: %s.\n\n", server->host);
|
printf(" -s|--host <address> ──────── Listen on Hostname or IP. Default: %s.\n\n", server->host);
|
||||||
@@ -576,7 +615,7 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
|
|||||||
printf(" or webcams, it's useless. Default: disabled.\n\n");
|
printf(" or webcams, it's useless. Default: disabled.\n\n");
|
||||||
printf(" -l|--slowdown ────────────── Slowdown capturing to 1 FPS or less when no stream clients are connected.\n");
|
printf(" -l|--slowdown ────────────── Slowdown capturing to 1 FPS or less when no stream clients are connected.\n");
|
||||||
printf(" Useful to reduce CPU consumption. Default: disabled.\n\n");
|
printf(" Useful to reduce CPU consumption. Default: disabled.\n\n");
|
||||||
printf(" -R|--fake-resolution <WxH> ─ Override image resolution for state. Default: disabled.\n\n");
|
printf(" -R|--fake-resolution <WxH> ─ Override image resolution for the /state. Default: disabled.\n\n");
|
||||||
printf(" --server-timeout <sec> ───── Timeout for client connections. Default: %u.\n\n", server->timeout);
|
printf(" --server-timeout <sec> ───── Timeout for client connections. Default: %u.\n\n", server->timeout);
|
||||||
#ifdef WITH_GPIO
|
#ifdef WITH_GPIO
|
||||||
printf("GPIO options:\n");
|
printf("GPIO options:\n");
|
||||||
@@ -597,6 +636,8 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
|
|||||||
#ifdef WITH_SETPROCTITLE
|
#ifdef WITH_SETPROCTITLE
|
||||||
printf(" --process-name-prefix <str> ── Set process name prefix which will be displayed in the process list\n");
|
printf(" --process-name-prefix <str> ── Set process name prefix which will be displayed in the process list\n");
|
||||||
printf(" like '<str>: ustreamer --blah-blah-blah'. Default: disabled.\n\n");
|
printf(" like '<str>: ustreamer --blah-blah-blah'. Default: disabled.\n\n");
|
||||||
|
printf(" --notify-parent ────────────── Send SIGUSR2 to the parent process when the stream parameters are changed.\n");
|
||||||
|
printf(" Checking changes is performed for the online flag and image resolution.\n\n");
|
||||||
#endif
|
#endif
|
||||||
printf("Logging options:\n");
|
printf("Logging options:\n");
|
||||||
printf("════════════════\n");
|
printf("════════════════\n");
|
||||||
|
|||||||
@@ -27,4 +27,14 @@
|
|||||||
#include "http/server.h"
|
#include "http/server.h"
|
||||||
|
|
||||||
|
|
||||||
int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t *encoder, struct http_server_t *server);
|
struct options_t {
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
char **argv_copy;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct options_t *options_init(int argc, char *argv[]);
|
||||||
|
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);
|
||||||
|
|||||||
@@ -84,9 +84,9 @@ void picture_copy(const struct picture_t *src, struct picture_t *dest) {
|
|||||||
COPY(width);
|
COPY(width);
|
||||||
COPY(height);
|
COPY(height);
|
||||||
|
|
||||||
COPY(grab_time);
|
COPY(grab_ts);
|
||||||
COPY(encode_begin_time);
|
COPY(encode_begin_ts);
|
||||||
COPY(encode_end_time);
|
COPY(encode_end_ts);
|
||||||
|
|
||||||
# undef COPY
|
# undef COPY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ struct picture_t {
|
|||||||
size_t allocated;
|
size_t allocated;
|
||||||
unsigned width;
|
unsigned width;
|
||||||
unsigned height;
|
unsigned height;
|
||||||
long double grab_time;
|
long double grab_ts;
|
||||||
long double encode_begin_time;
|
long double encode_begin_ts;
|
||||||
long double encode_end_time;
|
long double encode_end_ts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
# define HAS_PDEATHSIG
|
# define HAS_PDEATHSIG
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
@@ -32,19 +38,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAS_PDEATHSIG
|
|
||||||
# include <signal.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef WITH_SETPROCTITLE
|
#ifdef WITH_SETPROCTITLE
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# if defined(__linux__)
|
# if defined(__linux__)
|
||||||
# include <bsd/unistd.h>
|
# include <bsd/unistd.h>
|
||||||
# include <sys/types.h>
|
|
||||||
# elif (defined(__FreeBSD__) || defined(__DragonFly__))
|
# elif (defined(__FreeBSD__) || defined(__DragonFly__))
|
||||||
# include <unistd.h>
|
//# include <unistd.h>
|
||||||
# include <sys/types.h>
|
//# include <sys/types.h>
|
||||||
# elif (defined(__NetBSD__) || defined(__OpenBSD__)) // setproctitle() placed in stdlib.h
|
# elif (defined(__NetBSD__) || defined(__OpenBSD__)) // setproctitle() placed in stdlib.h
|
||||||
# else
|
# else
|
||||||
# error setproctitle() not implemented, you can disable it using WITH_SETPROCTITLE=0
|
# error setproctitle() not implemented, you can disable it using WITH_SETPROCTITLE=0
|
||||||
@@ -72,6 +73,7 @@ extern char **environ;
|
|||||||
|
|
||||||
#ifdef HAS_PDEATHSIG
|
#ifdef HAS_PDEATHSIG
|
||||||
INLINE int process_track_parent_death(void) {
|
INLINE int process_track_parent_death(void) {
|
||||||
|
pid_t parent = getppid();
|
||||||
int signum = SIGTERM;
|
int signum = SIGTERM;
|
||||||
# if defined(__linux__)
|
# if defined(__linux__)
|
||||||
int retval = prctl(PR_SET_PDEATHSIG, signum);
|
int retval = prctl(PR_SET_PDEATHSIG, signum);
|
||||||
@@ -85,8 +87,8 @@ INLINE int process_track_parent_death(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kill(getppid(), 0) < 0) {
|
if (kill(parent, 0) < 0) {
|
||||||
LOG_PERROR("The parent process is already dead");
|
LOG_PERROR("The parent process %d is already dead", parent);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,3 +130,11 @@ INLINE void process_set_name_prefix(int argc, char *argv[], const char *prefix)
|
|||||||
free(cmdline);
|
free(cmdline);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
INLINE void process_notify_parent(void) {
|
||||||
|
pid_t parent = getppid();
|
||||||
|
|
||||||
|
if (kill(parent, SIGUSR2) < 0) {
|
||||||
|
LOG_PERROR("Can't send SIGUSR2 to the parent process %d", parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ struct _worker_t {
|
|||||||
atomic_bool has_job;
|
atomic_bool has_job;
|
||||||
bool job_timely;
|
bool job_timely;
|
||||||
bool job_failed;
|
bool job_failed;
|
||||||
long double job_start_time;
|
long double job_start_ts;
|
||||||
pthread_cond_t has_job_cond;
|
pthread_cond_t has_job_cond;
|
||||||
|
|
||||||
pthread_mutex_t *free_workers_mutex;
|
pthread_mutex_t *free_workers_mutex;
|
||||||
@@ -454,10 +454,10 @@ static void *_worker_thread(void *v_worker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (device_release_buffer(worker->dev, worker->buf_index) == 0) {
|
if (device_release_buffer(worker->dev, worker->buf_index) == 0) {
|
||||||
worker->job_start_time = PICTURE(encode_begin_time);
|
worker->job_start_ts = PICTURE(encode_begin_ts);
|
||||||
atomic_store(&worker->has_job, false);
|
atomic_store(&worker->has_job, false);
|
||||||
|
|
||||||
worker->last_comp_time = PICTURE(encode_end_time) - worker->job_start_time;
|
worker->last_comp_time = PICTURE(encode_end_ts) - worker->job_start_ts;
|
||||||
|
|
||||||
LOG_VERBOSE("Compressed new JPEG: size=%zu, time=%0.3Lf, worker=%u, buffer=%u",
|
LOG_VERBOSE("Compressed new JPEG: size=%zu, time=%0.3Lf, worker=%u, buffer=%u",
|
||||||
PICTURE(used), worker->last_comp_time, worker->number, worker->buf_index);
|
PICTURE(used), worker->last_comp_time, worker->number, worker->buf_index);
|
||||||
@@ -498,7 +498,7 @@ static struct _worker_t *_workers_pool_wait(struct _workers_pool_t *pool) {
|
|||||||
if (
|
if (
|
||||||
!atomic_load(&pool->workers[number].has_job) && (
|
!atomic_load(&pool->workers[number].has_job) && (
|
||||||
ready_worker == NULL
|
ready_worker == NULL
|
||||||
|| ready_worker->job_start_time < pool->workers[number].job_start_time
|
|| ready_worker->job_start_ts < pool->workers[number].job_start_ts
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
ready_worker = &pool->workers[number];
|
ready_worker = &pool->workers[number];
|
||||||
|
|||||||
Reference in New Issue
Block a user