mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-19 16:26:30 +00:00
Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
472673ea90 | ||
|
|
f7ebe31c71 | ||
|
|
3a831817f4 | ||
|
|
913cdac7a6 | ||
|
|
777697dc1e | ||
|
|
5f437b9a35 | ||
|
|
b089f896da | ||
|
|
0e521ad0c6 | ||
|
|
620a0ec847 | ||
|
|
7a1d4816ed | ||
|
|
aec8431024 | ||
|
|
5b18e29555 | ||
|
|
2717248581 | ||
|
|
afd305e87d | ||
|
|
e3d8132237 | ||
|
|
1f32e875c3 | ||
|
|
2e88fb9294 | ||
|
|
d68f8e6d86 | ||
|
|
b380beba6d | ||
|
|
3a06a484ce | ||
|
|
0307d3bdb6 | ||
|
|
f2dd9c3c5a | ||
|
|
4e3f873f0d | ||
|
|
029440cf82 | ||
|
|
df74f5cf18 | ||
|
|
97494c3531 | ||
|
|
71544880d1 | ||
|
|
83127e58ff | ||
|
|
604a8f7cb4 | ||
|
|
602c1747d5 | ||
|
|
a2b8b35070 | ||
|
|
dd7701be38 | ||
|
|
1c9bd91b31 | ||
|
|
e19a3ca7ff | ||
|
|
b2d1a5612d | ||
|
|
f3e0613de3 | ||
|
|
5baf921660 | ||
|
|
6cabcd39f1 | ||
|
|
3df3658e4f | ||
|
|
f21fc5f6d3 | ||
|
|
b70ed98af9 | ||
|
|
52cdabe150 | ||
|
|
fe86997d08 | ||
|
|
df39b824c6 | ||
|
|
db297db52e | ||
|
|
b304364af9 | ||
|
|
ddec4e8478 | ||
|
|
28ca658621 | ||
|
|
270d3ae3a9 | ||
|
|
c1f080f29f |
@@ -1,7 +1,7 @@
|
||||
[bumpversion]
|
||||
commit = True
|
||||
tag = True
|
||||
current_version = 6.25
|
||||
current_version = 6.40
|
||||
parse = (?P<major>\d+)\.(?P<minor>\d+)
|
||||
serialize =
|
||||
{major}.{minor}
|
||||
|
||||
41
Makefile
41
Makefile
@@ -1,43 +1,64 @@
|
||||
-include config.mk
|
||||
|
||||
|
||||
# =====
|
||||
DESTDIR ?=
|
||||
PREFIX ?= /usr/local
|
||||
MANPREFIX ?= $(PREFIX)/share/man
|
||||
|
||||
CC ?= gcc
|
||||
PY ?= python3
|
||||
PKG_CONFIG ?= pkg-config
|
||||
CFLAGS ?= -O3
|
||||
LDFLAGS ?=
|
||||
|
||||
R_DESTDIR = $(if $(DESTDIR),$(shell realpath "$(DESTDIR)"),)
|
||||
|
||||
WITH_PYTHON ?= 0
|
||||
WITH_JANUS ?= 0
|
||||
WITH_V4P ?= 0
|
||||
WITH_GPIO ?= 0
|
||||
WITH_SYSTEMD ?= 0
|
||||
WITH_PTHREAD_NP ?= 1
|
||||
WITH_SETPROCTITLE ?= 1
|
||||
WITH_PDEATHSIG ?= 1
|
||||
|
||||
define optbool
|
||||
$(filter $(shell echo $(1) | tr A-Z a-z), yes on 1)
|
||||
endef
|
||||
MK_WITH_PYTHON = $(call optbool,$(WITH_PYTHON))
|
||||
MK_WITH_JANUS = $(call optbool,$(WITH_JANUS))
|
||||
MK_WITH_V4P = $(call optbool,$(WITH_V4P))
|
||||
MK_WITH_GPIO = $(call optbool,$(WITH_GPIO))
|
||||
MK_WITH_SYSTEMD = $(call optbool,$(WITH_SYSTEMD))
|
||||
MK_WITH_PTHREAD_NP = $(call optbool,$(WITH_PTHREAD_NP))
|
||||
MK_WITH_SETPROCTITLE = $(call optbool,$(WITH_SETPROCTITLE))
|
||||
MK_WITH_PDEATHSIG = $(call optbool,$(WITH_PDEATHSIG))
|
||||
|
||||
export
|
||||
|
||||
_LINTERS_IMAGE ?= ustreamer-linters
|
||||
|
||||
|
||||
# =====
|
||||
ifeq (__not_found__,$(shell which pkg-config 2>/dev/null || echo "__not_found__"))
|
||||
$(error "No pkg-config found in $(PATH)")
|
||||
ifeq (__not_found__,$(shell which $(PKG_CONFIG) 2>/dev/null || echo "__not_found__"))
|
||||
$(error "No $(PKG_CONFIG) found in $(PATH)")
|
||||
endif
|
||||
|
||||
|
||||
# =====
|
||||
define optbool
|
||||
$(filter $(shell echo $(1) | tr A-Z a-z), yes on 1)
|
||||
endef
|
||||
|
||||
ifeq ($(V),)
|
||||
ECHO = @
|
||||
endif
|
||||
|
||||
|
||||
# =====
|
||||
all:
|
||||
+ $(MAKE) apps
|
||||
ifneq ($(call optbool,$(WITH_PYTHON)),)
|
||||
ifneq ($(MK_WITH_PYTHON),)
|
||||
+ $(MAKE) python
|
||||
endif
|
||||
ifneq ($(call optbool,$(WITH_JANUS)),)
|
||||
ifneq ($(MK_WITH_JANUS),)
|
||||
+ $(MAKE) janus
|
||||
endif
|
||||
|
||||
@@ -61,10 +82,10 @@ janus:
|
||||
|
||||
install: all
|
||||
$(MAKE) -C src install
|
||||
ifneq ($(call optbool,$(WITH_PYTHON)),)
|
||||
ifneq ($(MK_WITH_PYTHON),)
|
||||
$(MAKE) -C python install
|
||||
endif
|
||||
ifneq ($(call optbool,$(WITH_JANUS)),)
|
||||
ifneq ($(MK_WITH_JANUS),)
|
||||
$(MAKE) -C janus install
|
||||
endif
|
||||
mkdir -p $(R_DESTDIR)$(MANPREFIX)/man1
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|----------|---------------|-------------------|
|
||||
| Multithreaded JPEG encoding | ✔ | ✘ |
|
||||
| Hardware image encoding<br>on Raspberry Pi | ✔ | ✘ |
|
||||
| Behavior when the device<br>is disconnected while streaming | ✔ Shows a black screen<br>with ```NO SIGNAL``` on it<br>until reconnected | ✘ Stops the streaming <sup>1</sup> |
|
||||
| Behavior when the device<br>is disconnected while streaming | ✔ Shows a black screen<br>with ```NO LIVE VIDEO``` on it<br>until reconnected | ✘ Stops the streaming <sup>1</sup> |
|
||||
| [DV-timings](https://linuxtv.org/downloads/v4l-dvb-apis-new/userspace-api/v4l/dv-timings.html) support -<br>the ability to change resolution<br>on the fly by source signal | ✔ | ☹ Partially yes <sup>1</sup> |
|
||||
| Option to skip frames when streaming<br>static images by HTTP to save the traffic | ✔ <sup>2</sup> | ✘ |
|
||||
| Streaming via UNIX domain socket | ✔ | ✘ |
|
||||
@@ -44,7 +44,7 @@ You need to download the µStreamer onto your system and build it from the sourc
|
||||
* FreeBSD port: https://www.freshports.org/multimedia/ustreamer.
|
||||
|
||||
### Preconditions
|
||||
You'll need ```make```, ```gcc```, ```libevent``` with ```pthreads``` support, ```libjpeg9```/```libjpeg-turbo``` and ```libbsd``` (only for Linux).
|
||||
You'll need ```make```, ```gcc```, ```pkg-config```, ```libevent``` with ```pthreads``` support, ```libjpeg9```/```libjpeg-turbo``` and ```libbsd``` (only for Linux).
|
||||
|
||||
* Arch: `sudo pacman -S libevent libjpeg-turbo libutil-linux libbsd`.
|
||||
* Raspberry OS Bullseye: `sudo apt install libevent-dev libjpeg62-turbo libbsd-dev`. Add `libgpiod-dev` for `WITH_GPIO=1` and `libsystemd-dev` for `WITH_SYSTEMD=1` and `libasound2-dev libspeex-dev libspeexdsp-dev libopus-dev` for `WITH_JANUS=1`.
|
||||
|
||||
@@ -2,6 +2,7 @@ R_DESTDIR ?=
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
CC ?= gcc
|
||||
PKG_CONFIG ?= pkg-config
|
||||
CFLAGS ?= -O3
|
||||
LDFLAGS ?=
|
||||
|
||||
@@ -9,21 +10,20 @@ LDFLAGS ?=
|
||||
# =====
|
||||
_PLUGIN = libjanus_ustreamer.so
|
||||
|
||||
_CFLAGS = -fPIC -MD -c -std=c17 -Wall -Wextra -D_GNU_SOURCE $(shell pkg-config --cflags glib-2.0) $(CFLAGS)
|
||||
_LDFLAGS = -shared -lm -pthread -lrt -ljansson -lopus -lasound -lspeexdsp $(shell pkg-config --libs glib-2.0) $(LDFLAGS)
|
||||
_CFLAGS = -fPIC -MD -c -std=c17 -Wall -Wextra -D_GNU_SOURCE $(shell $(PKG_CONFIG) --cflags glib-2.0) $(CFLAGS)
|
||||
_LDFLAGS = -shared -lm -pthread -lrt -ljansson -lopus -lasound -lspeexdsp $(shell $(PKG_CONFIG) --libs glib-2.0) $(LDFLAGS)
|
||||
|
||||
_SRCS = $(shell ls src/uslibs/*.c src/*.c)
|
||||
|
||||
_BUILD = build
|
||||
|
||||
|
||||
define optbool
|
||||
$(filter $(shell echo $(1) | tr A-Z a-z), yes on 1)
|
||||
endef
|
||||
# =====
|
||||
ifneq ($(shell sh -c 'uname 2>/dev/null || echo Unknown'),FreeBSD)
|
||||
override _LDFLAGS += -latomic
|
||||
endif
|
||||
|
||||
|
||||
WITH_PTHREAD_NP ?= 1
|
||||
ifneq ($(call optbool,$(WITH_PTHREAD_NP)),)
|
||||
ifneq ($(MK_WITH_PTHREAD_NP),)
|
||||
override _CFLAGS += -DWITH_PTHREAD_NP
|
||||
endif
|
||||
|
||||
|
||||
@@ -205,8 +205,15 @@ static void *_video_or_acap_thread(void *v_client, bool video) {
|
||||
}*/
|
||||
|
||||
if (rtp.video) {
|
||||
const uint video_orient = atomic_load(&client->video_orient);
|
||||
uint video_orient = atomic_load(&client->video_orient);
|
||||
if (video_orient != 0) {
|
||||
// The extension rotates the video clockwise, but want it counterclockwise.
|
||||
// It's more intuitive for people who have seen a protractor at least once in their life.
|
||||
if (video_orient == 90) {
|
||||
video_orient = 270;
|
||||
} else if (video_orient == 270) {
|
||||
video_orient = 90;
|
||||
}
|
||||
packet.extensions.video_rotation = video_orient;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <janus/config.h>
|
||||
#include <janus/plugins/plugin.h>
|
||||
@@ -64,7 +65,16 @@ us_config_s *us_config_init(const char *config_dir_path) {
|
||||
US_JLOG_INFO("config", "Missing config value: acap.tc358743");
|
||||
goto error;
|
||||
}
|
||||
config->aplay_dev_name = _get_value(jcfg, "aplay", "device");
|
||||
if ((config->aplay_dev_name = _get_value(jcfg, "aplay", "device")) != NULL) {
|
||||
char *path = _get_value(jcfg, "aplay", "check");
|
||||
if (path != NULL) {
|
||||
if (access(path, F_OK) != 0) {
|
||||
US_JLOG_INFO("config", "No check file found, aplay will be disabled");
|
||||
US_DELETE(config->aplay_dev_name, free);
|
||||
}
|
||||
US_DELETE(path, free);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
|
||||
@@ -59,6 +59,9 @@
|
||||
#include "memsinkfd.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
static const char *const default_ice_url = "stun:stun.l.google.com:19302";
|
||||
|
||||
static us_config_s *_g_config = NULL;
|
||||
static const useconds_t _g_watchers_polling = 100000;
|
||||
|
||||
@@ -669,10 +672,12 @@ static struct janus_plugin_result *_plugin_handle_message(
|
||||
}
|
||||
|
||||
} else if (!strcmp(request_str, "features")) {
|
||||
const char *const ice_url = getenv("JANUS_USTREAMER_WEB_ICE_URL");
|
||||
json_t *const features = json_pack(
|
||||
"{sbsb}",
|
||||
"{s:b, s:b, s:{s:s?}}",
|
||||
"audio", (_g_rtpa != NULL),
|
||||
"mic", (_g_rtpa != NULL && _g_config->aplay_dev_name != NULL)
|
||||
"mic", (_g_rtpa != NULL && _g_config->aplay_dev_name != NULL),
|
||||
"ice", "url", (ice_url != NULL ? ice_url : default_ice_url)
|
||||
);
|
||||
PUSH_STATUS("features", features, NULL);
|
||||
json_decref(features);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.\" Manpage for ustreamer-dump.
|
||||
.\" Open an issue or pull request to https://github.com/pikvm/ustreamer to correct errors or typos
|
||||
.TH USTREAMER-DUMP 1 "version 6.25" "January 2021"
|
||||
.TH USTREAMER-DUMP 1 "version 6.40" "January 2021"
|
||||
|
||||
.SH NAME
|
||||
ustreamer-dump \- Dump uStreamer's memory sink to file
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.\" Manpage for ustreamer.
|
||||
.\" Open an issue or pull request to https://github.com/pikvm/ustreamer to correct errors or typos
|
||||
.TH USTREAMER 1 "version 6.25" "November 2020"
|
||||
.TH USTREAMER 1 "version 6.40" "November 2020"
|
||||
|
||||
.SH NAME
|
||||
ustreamer \- stream MJPEG video from any V4L2 device to the network
|
||||
@@ -52,7 +52,7 @@ Initial image resolution. Default: 640x480.
|
||||
.TP
|
||||
.BR \-m\ \fIfmt ", " \-\-format\ \fIfmt
|
||||
Image format.
|
||||
Available: YUYV, YVYU, UYVY, RGB565, RGB24, JPEG; default: YUYV.
|
||||
Available: YUYV, YVYU, UYVY, YUV420, YVU420, RGB565, RGB24, GREY, MJPEG, JPEG; default: YUYV.
|
||||
.TP
|
||||
.BR \-a\ \fIstd ", " \-\-tv\-standard\ \fIstd
|
||||
Force TV standard.
|
||||
@@ -274,7 +274,10 @@ Timeout for lock. Default: 1.
|
||||
.SS "Process options"
|
||||
.TP
|
||||
.BR \-\-exit\-on\-parent\-death
|
||||
Exit the program if the parent process is dead. Required \fBHAS_PDEATHSIG\fR feature. Default: disabled.
|
||||
Exit the program if the parent process is dead. Required \fBWITH_PDEATHSIG\fR feature. Default: disabled.
|
||||
.TP
|
||||
.BR \-\-exit\-on\-device\-error
|
||||
Exit on any device error instead of polling until success. Default: disabled.
|
||||
.TP
|
||||
.BR \-\-exit\-on\-no\-clients \fIsec
|
||||
Exit the program if there have been no stream or sink clients or any HTTP requests in the last N seconds. Default: 0 (disabled).
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
pkgname=ustreamer
|
||||
pkgver=6.25
|
||||
pkgver=6.40
|
||||
pkgrel=1
|
||||
pkgdesc="Lightweight and fast MJPEG-HTTP streamer"
|
||||
url="https://github.com/pikvm/ustreamer"
|
||||
@@ -18,7 +18,7 @@ md5sums=(SKIP)
|
||||
_options="WITH_GPIO=1 WITH_SYSTEMD=1"
|
||||
if [ -e /usr/bin/python3 ]; then
|
||||
_options="$_options WITH_PYTHON=1"
|
||||
depends+=(python)
|
||||
depends+=("python>=3.13" "python<3.14")
|
||||
makedepends+=(python-setuptools python-pip python-build python-wheel)
|
||||
fi
|
||||
if [ -e /usr/include/janus/plugins/plugin.h ];then
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=ustreamer
|
||||
PKG_VERSION:=6.25
|
||||
PKG_VERSION:=6.40
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=Maxim Devaev <mdevaev@gmail.com>
|
||||
|
||||
@@ -25,7 +25,7 @@ define Package/ustreamer
|
||||
SECTION:=multimedia
|
||||
CATEGORY:=Multimedia
|
||||
TITLE:=uStreamer
|
||||
DEPENDS:=+libpthread +libjpeg +libv4l +libbsd +libevent2 +libevent2-core +libevent2-extra +libevent2-pthreads
|
||||
DEPENDS:=+libatomic +libpthread +libjpeg +libv4l +libbsd +libevent2 +libevent2-core +libevent2-extra +libevent2-pthreads
|
||||
URL:=https://github.com/pikvm/ustreamer
|
||||
endef
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
-include ../config.mk
|
||||
|
||||
R_DESTDIR ?=
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
@@ -8,7 +6,7 @@ PY ?= python3
|
||||
|
||||
# =====
|
||||
all: root
|
||||
root: $(shell find src -type f,l)
|
||||
root: $(shell find src -type f,l) setup.py
|
||||
$(info == PY_BUILD ustreamer-*.so)
|
||||
rm -rf root
|
||||
$(ECHO) $(PY) -m build --skip-dependency-check --no-isolation
|
||||
|
||||
@@ -5,19 +5,36 @@ from setuptools import setup
|
||||
|
||||
|
||||
# =====
|
||||
def _find_sources(suffix: str) -> list[str]:
|
||||
def _find_sources() -> list[str]:
|
||||
sources: list[str] = []
|
||||
for (root_path, _, names) in os.walk("src"):
|
||||
for name in names:
|
||||
if name.endswith(suffix):
|
||||
if name.endswith(".c"):
|
||||
sources.append(os.path.join(root_path, name))
|
||||
return sources
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def _find_flags() -> dict[str, bool]:
|
||||
return {
|
||||
key[3:]: (value.strip().lower() in ["true", "on", "1"])
|
||||
for (key, value) in sorted(os.environ.items())
|
||||
if key.startswith("MK_WITH_")
|
||||
}
|
||||
|
||||
|
||||
def _make_d_features(flags: dict[str, bool]) -> str:
|
||||
features = " ".join([
|
||||
f"{key}={int(value)}"
|
||||
for (key, value) in flags.items()
|
||||
])
|
||||
return f"-DUS_FEATURES=\"{features}\""
|
||||
|
||||
|
||||
def main() -> None:
|
||||
flags = _find_flags()
|
||||
setup(
|
||||
name="ustreamer",
|
||||
version="6.25",
|
||||
version="6.40",
|
||||
description="uStreamer tools",
|
||||
author="Maxim Devaev",
|
||||
author_email="mdevaev@gmail.com",
|
||||
@@ -26,9 +43,16 @@ if __name__ == "__main__":
|
||||
Extension(
|
||||
"ustreamer",
|
||||
libraries=["rt", "m", "pthread"],
|
||||
extra_compile_args=["-std=c17", "-D_GNU_SOURCE"],
|
||||
extra_compile_args=[
|
||||
"-std=c17", "-D_GNU_SOURCE",
|
||||
_make_d_features(flags),
|
||||
],
|
||||
undef_macros=["NDEBUG"],
|
||||
sources=_find_sources(".c"),
|
||||
sources=_find_sources(),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
1
python/src/uslibs/const.h
Symbolic link
1
python/src/uslibs/const.h
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../src/libs/const.h
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "uslibs/const.h"
|
||||
#include "uslibs/types.h"
|
||||
#include "uslibs/errors.h"
|
||||
#include "uslibs/tools.h"
|
||||
@@ -48,6 +49,8 @@ static void _MemsinkObject_destroy_internals(_MemsinkObject *self) {
|
||||
}
|
||||
|
||||
static int _MemsinkObject_init(_MemsinkObject *self, PyObject *args, PyObject *kwargs) {
|
||||
self->fd = -1;
|
||||
|
||||
self->lock_timeout = 1;
|
||||
self->wait_timeout = 1;
|
||||
|
||||
@@ -228,7 +231,8 @@ static PyObject *_MemsinkObject_wait_frame(_MemsinkObject *self, PyObject *args,
|
||||
} \
|
||||
Py_DECREF(m_tmp); \
|
||||
}
|
||||
# define SET_NUMBER(x_key, x_from, x_to) SET_VALUE(#x_key, Py##x_to##_From##x_from(self->frame->x_key))
|
||||
# define SET_NUMBER(x_key, x_from, x_to) \
|
||||
SET_VALUE(#x_key, Py##x_to##_From##x_from(self->frame->x_key))
|
||||
|
||||
SET_NUMBER(width, Long, Long);
|
||||
SET_NUMBER(height, Long, Long);
|
||||
@@ -275,7 +279,8 @@ static PyMethodDef _MemsinkObject_methods[] = {
|
||||
};
|
||||
|
||||
static PyGetSetDef _MemsinkObject_getsets[] = {
|
||||
# define ADD_GETTER(x_field) {.name = #x_field, .get = (getter)_MemsinkObject_getter_##x_field}
|
||||
# define ADD_GETTER(x_field) \
|
||||
{.name = #x_field, .get = (getter)_MemsinkObject_getter_##x_field}
|
||||
ADD_GETTER(obj),
|
||||
ADD_GETTER(lock_timeout),
|
||||
ADD_GETTER(wait_timeout),
|
||||
@@ -304,20 +309,30 @@ static PyModuleDef _Module = {
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_ustreamer(void) {
|
||||
PyObject *module = PyModule_Create(&_Module);
|
||||
if (module == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject *module = NULL;
|
||||
|
||||
if (PyType_Ready(&_MemsinkType) < 0) {
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
Py_INCREF(&_MemsinkType);
|
||||
|
||||
if (PyModule_AddObject(module, "Memsink", (PyObject*)&_MemsinkType) < 0) {
|
||||
return NULL;
|
||||
if ((module = PyModule_Create(&_Module)) == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
# define ADD(x_what, x_key, x_value) \
|
||||
{ if (PyModule_Add##x_what(module, x_key, x_value) < 0) { goto error; } }
|
||||
ADD(StringConstant, "__version__", US_VERSION);
|
||||
ADD(StringConstant, "VERSION", US_VERSION);
|
||||
ADD(IntConstant, "VERSION_MAJOR", US_VERSION_MAJOR);
|
||||
ADD(IntConstant, "VERSION_MINOR", US_VERSION_MINOR);
|
||||
ADD(StringConstant, "FEATURES", US_FEATURES); // Defined in setup.py
|
||||
ADD(ObjectRef, "Memsink", (PyObject*)&_MemsinkType);
|
||||
# undef ADD
|
||||
return module;
|
||||
|
||||
error:
|
||||
if (module != NULL) {
|
||||
Py_DECREF(module);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
57
src/Makefile
57
src/Makefile
@@ -2,6 +2,7 @@ R_DESTDIR ?=
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
CC ?= gcc
|
||||
PKG_CONFIG ?= pkg-config
|
||||
CFLAGS ?= -O3
|
||||
LDFLAGS ?=
|
||||
|
||||
@@ -13,9 +14,9 @@ _V4P = ustreamer-v4p.bin
|
||||
|
||||
_CFLAGS = -MD -c -std=c17 -Wall -Wextra -D_GNU_SOURCE $(CFLAGS)
|
||||
|
||||
_USTR_LDFLAGS = $(LDFLAGS) -lm -ljpeg -pthread -lrt -latomic -levent -levent_pthreads
|
||||
_DUMP_LDFLAGS = $(LDFLAGS) -lm -ljpeg -pthread -lrt -latomic
|
||||
_V4P_LDFLAGS = $(LDFLAGS) -lm -ljpeg -pthread -lrt -latomic
|
||||
_USTR_LDFLAGS = $(LDFLAGS) -lm -ljpeg -pthread -lrt -levent -levent_pthreads
|
||||
_DUMP_LDFLAGS = $(LDFLAGS) -lm -ljpeg -pthread -lrt
|
||||
_V4P_LDFLAGS = $(LDFLAGS) -lm -ljpeg -pthread -lrt
|
||||
|
||||
_USTR_SRCS = $(shell ls \
|
||||
libs/*.c \
|
||||
@@ -40,53 +41,59 @@ _V4P_SRCS = $(shell ls \
|
||||
|
||||
_BUILD = build
|
||||
|
||||
|
||||
_TARGETS = $(_USTR) $(_DUMP)
|
||||
_OBJS = $(_USTR_SRCS:%.c=$(_BUILD)/%.o) $(_DUMP_SRCS:%.c=$(_BUILD)/%.o)
|
||||
|
||||
|
||||
define optbool
|
||||
$(filter $(shell echo $(1) | tr A-Z a-z), yes on 1)
|
||||
endef
|
||||
# =====
|
||||
ifneq ($(shell sh -c 'uname 2>/dev/null || echo Unknown'),FreeBSD)
|
||||
override _USTR_LDFLAGS += -latomic
|
||||
override _DUMP_LDFLAGS += -latomic
|
||||
override _V4P_LDFLAGS += -latomic
|
||||
endif
|
||||
|
||||
ifneq ($(MK_WITH_PYTHON),)
|
||||
override _CFLAGS += -DMK_WITH_PYTHON
|
||||
endif
|
||||
|
||||
ifneq ($(call optbool,$(WITH_GPIO)),)
|
||||
override _CFLAGS += -DWITH_GPIO $(shell pkg-config --atleast-version=2 libgpiod 2> /dev/null && echo -DHAVE_GPIOD2)
|
||||
ifneq ($(MK_WITH_JANUS),)
|
||||
override _CFLAGS += -DMK_WITH_JANUS
|
||||
endif
|
||||
|
||||
ifneq ($(MK_WITH_GPIO),)
|
||||
override _CFLAGS += -DMK_WITH_GPIO -DWITH_GPIO $(shell $(PKG_CONFIG) --atleast-version=2 libgpiod 2> /dev/null && echo -DHAVE_GPIOD2)
|
||||
override _USTR_LDFLAGS += -lgpiod
|
||||
override _USTR_SRCS += $(shell ls ustreamer/gpio/*.c)
|
||||
endif
|
||||
|
||||
|
||||
ifneq ($(call optbool,$(WITH_SYSTEMD)),)
|
||||
override _CFLAGS += -DWITH_SYSTEMD
|
||||
ifneq ($(MK_WITH_SYSTEMD),)
|
||||
override _CFLAGS += -DMK_WITH_SYSTEMD -DWITH_SYSTEMD
|
||||
override _USTR_LDFLAGS += -lsystemd
|
||||
override _USTR_SRCS += $(shell ls ustreamer/http/systemd/*.c)
|
||||
endif
|
||||
|
||||
|
||||
WITH_PTHREAD_NP ?= 1
|
||||
ifneq ($(call optbool,$(WITH_PTHREAD_NP)),)
|
||||
override _CFLAGS += -DWITH_PTHREAD_NP
|
||||
ifneq ($(MK_WITH_PTHREAD_NP),)
|
||||
override _CFLAGS += -DMK_WITH_PTHREAD_NP -DWITH_PTHREAD_NP
|
||||
endif
|
||||
|
||||
|
||||
WITH_SETPROCTITLE ?= 1
|
||||
ifneq ($(call optbool,$(WITH_SETPROCTITLE)),)
|
||||
override _CFLAGS += -DWITH_SETPROCTITLE
|
||||
ifneq ($(MK_WITH_SETPROCTITLE),)
|
||||
override _CFLAGS += -DMK_WITH_SETPROCTITLE -DWITH_SETPROCTITLE
|
||||
ifeq ($(shell uname -s | tr A-Z a-z),linux)
|
||||
override _USTR_LDFLAGS += -lbsd
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(MK_WITH_PDEATHSIG),)
|
||||
override _CFLAGS += -DMK_WITH_PDEATHSIG -DWITH_PDEATHSIG
|
||||
endif
|
||||
|
||||
WITH_V4P ?= 0
|
||||
ifneq ($(call optbool,$(WITH_V4P)),)
|
||||
ifneq ($(MK_WITH_V4P),)
|
||||
override _TARGETS += $(_V4P)
|
||||
override _OBJS += $(_V4P_SRCS:%.c=$(_BUILD)/%.o)
|
||||
override _CFLAGS += -DWITH_V4P $(shell pkg-config --cflags libdrm)
|
||||
override _V4P_LDFLAGS += $(shell pkg-config --libs libdrm)
|
||||
override _CFLAGS += -DMK_WITH_V4P -DWITH_V4P $(shell $(PKG_CONFIG) --cflags libdrm)
|
||||
override _V4P_LDFLAGS += $(shell $(PKG_CONFIG) --libs libdrm)
|
||||
override _USTR_SRCS += $(shell ls libs/drm/*.c)
|
||||
override _USTR_LDFLAGS += $(shell pkg-config --libs libdrm)
|
||||
override _USTR_LDFLAGS += $(shell $(PKG_CONFIG) --libs libdrm)
|
||||
endif
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "threading.h"
|
||||
#include "frame.h"
|
||||
#include "xioctl.h"
|
||||
#include "tc358743.h"
|
||||
|
||||
|
||||
static const struct {
|
||||
@@ -67,6 +68,9 @@ static const struct {
|
||||
{"YUYV", V4L2_PIX_FMT_YUYV},
|
||||
{"YVYU", V4L2_PIX_FMT_YVYU},
|
||||
{"UYVY", V4L2_PIX_FMT_UYVY},
|
||||
{"YUV420", V4L2_PIX_FMT_YUV420},
|
||||
{"YVU420", V4L2_PIX_FMT_YVU420},
|
||||
{"GREY", V4L2_PIX_FMT_GREY},
|
||||
{"RGB565", V4L2_PIX_FMT_RGB565},
|
||||
{"RGB24", V4L2_PIX_FMT_RGB24},
|
||||
{"BGR24", V4L2_PIX_FMT_BGR24},
|
||||
@@ -190,12 +194,18 @@ int us_capture_open(us_capture_s *cap) {
|
||||
_LOG_DEBUG("Capture device fd=%d opened", run->fd);
|
||||
|
||||
if (cap->dv_timings && cap->persistent) {
|
||||
struct v4l2_control ctl = {.id = V4L2_CID_DV_RX_POWER_PRESENT};
|
||||
if (!us_xioctl(run->fd, VIDIOC_G_CTRL, &ctl)) {
|
||||
if (!ctl.value) {
|
||||
goto error_no_cable;
|
||||
}
|
||||
}
|
||||
_LOG_DEBUG("Probing DV-timings or QuerySTD ...");
|
||||
if (_capture_open_dv_timings(cap, false) < 0) {
|
||||
US_ONCE_FOR(run->open_error_once, __LINE__, {
|
||||
_LOG_ERROR("No signal from source");
|
||||
});
|
||||
goto error_no_signal;
|
||||
switch (_capture_open_dv_timings(cap, false)) {
|
||||
case 0: break;
|
||||
case US_ERROR_NO_SIGNAL: goto error_no_signal;
|
||||
case US_ERROR_NO_SYNC: goto error_no_sync;
|
||||
default: goto error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +223,15 @@ int us_capture_open(us_capture_s *cap) {
|
||||
if (_capture_open_format(cap, true) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (cap->dv_timings && cap->persistent) {
|
||||
struct v4l2_control ctl = {.id = TC358743_CID_LANES_ENOUGH};
|
||||
if (!us_xioctl(run->fd, VIDIOC_G_CTRL, &ctl)) {
|
||||
if (!ctl.value) {
|
||||
_LOG_ERROR("Not enough lanes, hardware can't handle this signal");
|
||||
goto error_no_lanes;
|
||||
}
|
||||
}
|
||||
}
|
||||
_capture_open_hw_fps(cap);
|
||||
_capture_open_jpeg_quality(cap);
|
||||
if (_capture_open_io_method(cap) < 0) {
|
||||
@@ -245,9 +264,23 @@ error_no_device:
|
||||
us_capture_close(cap);
|
||||
return US_ERROR_NO_DEVICE;
|
||||
|
||||
error_no_signal:
|
||||
error_no_cable:
|
||||
us_capture_close(cap);
|
||||
return US_ERROR_NO_DATA;
|
||||
return US_ERROR_NO_CABLE;
|
||||
|
||||
error_no_signal:
|
||||
US_ONCE_FOR(run->open_error_once, __LINE__, { _LOG_ERROR("No signal from source"); });
|
||||
us_capture_close(cap);
|
||||
return US_ERROR_NO_SIGNAL;
|
||||
|
||||
error_no_sync:
|
||||
US_ONCE_FOR(run->open_error_once, __LINE__, { _LOG_ERROR("No sync on signal"); });
|
||||
us_capture_close(cap);
|
||||
return US_ERROR_NO_SYNC;
|
||||
|
||||
error_no_lanes:
|
||||
us_capture_close(cap);
|
||||
return US_ERROR_NO_LANES;
|
||||
|
||||
error:
|
||||
run->open_error_once = 0;
|
||||
@@ -536,19 +569,28 @@ bool _capture_is_buffer_valid(const us_capture_s *cap, const struct v4l2_buffer
|
||||
if (us_is_jpeg(cap->run->format)) {
|
||||
if (buf->bytesused < 125) {
|
||||
// https://stackoverflow.com/questions/2253404/what-is-the-smallest-valid-jpeg-file-size-in-bytes
|
||||
_LOG_DEBUG("Discarding invalid frame, too small to be a valid JPEG: bytesused=%u", buf->bytesused);
|
||||
_LOG_DEBUG("Discarding invalid frame, too small to be a valid JPEG: bytesused=%u",
|
||||
buf->bytesused);
|
||||
return false;
|
||||
}
|
||||
|
||||
const u8 *const end_ptr = data + buf->bytesused;
|
||||
const u8 *const eoi_ptr = end_ptr - 2;
|
||||
const u16 eoi_marker = (((u16)(eoi_ptr[0]) << 8) | eoi_ptr[1]);
|
||||
if (eoi_marker != 0xFFD9 && eoi_marker != 0xD900 && eoi_marker != 0x0000) {
|
||||
const u16 begin_marker = (((u16)(data[0]) << 8) | data[1]);
|
||||
if (begin_marker != 0xFFD8) {
|
||||
_LOG_DEBUG("Discarding JPEG frame with invalid header: begin_marker=0x%04x, bytesused=%u",
|
||||
begin_marker, buf->bytesused);
|
||||
return false;
|
||||
}
|
||||
|
||||
const u8 *const end_ptr = data + buf->bytesused - 2;
|
||||
const u16 end_marker = (((u16)(end_ptr[0]) << 8) | end_ptr[1]);
|
||||
if (end_marker != 0xFFD9 && end_marker != 0xD900 && end_marker != 0x0000) {
|
||||
if (!cap->allow_truncated_frames) {
|
||||
_LOG_DEBUG("Discarding truncated JPEG frame: eoi_marker=0x%04x, bytesused=%u", eoi_marker, buf->bytesused);
|
||||
_LOG_DEBUG("Discarding truncated JPEG frame: end_marker=0x%04x, bytesused=%u",
|
||||
end_marker, buf->bytesused);
|
||||
return false;
|
||||
}
|
||||
_LOG_DEBUG("Got truncated JPEG frame: eoi_marker=0x%04x, bytesused=%u", eoi_marker, buf->bytesused);
|
||||
_LOG_DEBUG("Got truncated JPEG frame: end_marker=0x%04x, bytesused=%u",
|
||||
end_marker, buf->bytesused);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,6 +659,10 @@ static int _capture_open_dv_timings(us_capture_s *cap, bool apply) {
|
||||
// TC358743 errors here (see in the kernel: drivers/media/i2c/tc358743.c):
|
||||
// - ENOLINK: No valid signal (SYS_STATUS & MASK_S_TMDS)
|
||||
// - ENOLCK: No sync on signal (SYS_STATUS & MASK_S_SYNC)
|
||||
switch (errno) {
|
||||
case ENOLINK: return US_ERROR_NO_SIGNAL;
|
||||
case ENOLCK: return US_ERROR_NO_SYNC;
|
||||
}
|
||||
dv_errno = errno;
|
||||
goto querystd;
|
||||
} else if (!apply) {
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#define US_VIDEO_MAX_FPS ((uint)120)
|
||||
|
||||
#define US_STANDARDS_STR "PAL, NTSC, SECAM"
|
||||
#define US_FORMATS_STR "YUYV, YVYU, UYVY, RGB565, RGB24, BGR24, MJPEG, JPEG"
|
||||
#define US_FORMATS_STR "YUYV, YVYU, UYVY, YUV420, YVU420, RGB565, RGB24, BGR24, GREY, MJPEG, JPEG"
|
||||
#define US_IO_METHODS_STR "MMAP, USERPTR"
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
|
||||
#define US_VERSION_MAJOR 6
|
||||
#define US_VERSION_MINOR 25
|
||||
#define US_VERSION_MINOR 40
|
||||
|
||||
#define US_MAKE_VERSION2(_major, _minor) #_major "." #_minor
|
||||
#define US_MAKE_VERSION1(_major, _minor) US_MAKE_VERSION2(_major, _minor)
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#ifdef __linux__
|
||||
# include <sys/sysmacros.h>
|
||||
#endif
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
@@ -376,7 +378,7 @@ int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_capture_s *ca
|
||||
DRAW_MSG("=== PiKVM ===\n \n< UNSUPPORTED CAPTURE FORMAT >");
|
||||
break;
|
||||
case US_DRM_STUB_NO_SIGNAL:
|
||||
DRAW_MSG("=== PiKVM ===\n \n< NO SIGNAL >");
|
||||
DRAW_MSG("=== PiKVM ===\n \n< NO LIVE VIDEO >");
|
||||
break;
|
||||
case US_DRM_STUB_BUSY:
|
||||
DRAW_MSG("=== PiKVM ===\n \n< ONLINE IS ACTIVE >");
|
||||
@@ -664,6 +666,15 @@ static drmModeModeInfo *_find_best_mode(drmModeConnector *conn, uint width, uint
|
||||
continue; // Discard interlaced
|
||||
}
|
||||
const float mode_hz = _get_refresh_rate(mode);
|
||||
if (width == 640 && height == 416 && mode->hdisplay == 640 && mode->vdisplay == 480) {
|
||||
// A special case for some ancient DOS device with VGA converter.
|
||||
// @CapnKirk in Discord
|
||||
if (hz > 0 && mode_hz < hz) {
|
||||
best = mode;
|
||||
best->vdisplay = 416;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mode->hdisplay == width && mode->vdisplay == height) {
|
||||
best = mode; // Any mode with exact resolution
|
||||
if (hz > 0 && mode_hz == hz) {
|
||||
|
||||
@@ -24,4 +24,8 @@
|
||||
|
||||
#define US_ERROR_COMMON -1
|
||||
#define US_ERROR_NO_DEVICE -2
|
||||
#define US_ERROR_NO_DATA -3
|
||||
#define US_ERROR_NO_CABLE -3
|
||||
#define US_ERROR_NO_SIGNAL -4
|
||||
#define US_ERROR_NO_SYNC -5
|
||||
#define US_ERROR_NO_LANES -6
|
||||
#define US_ERROR_NO_DATA -7
|
||||
|
||||
@@ -82,16 +82,32 @@ bool us_frame_compare(const us_frame_s *a, const us_frame_s *b) {
|
||||
uint us_frame_get_padding(const us_frame_s *frame) {
|
||||
uint bytes_per_pixel = 0;
|
||||
switch (frame->format) {
|
||||
case V4L2_PIX_FMT_YUV420:
|
||||
case V4L2_PIX_FMT_YVU420:
|
||||
case V4L2_PIX_FMT_GREY:
|
||||
bytes_per_pixel = 1;
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_YUYV:
|
||||
case V4L2_PIX_FMT_YVYU:
|
||||
case V4L2_PIX_FMT_UYVY:
|
||||
case V4L2_PIX_FMT_RGB565: bytes_per_pixel = 2; break;
|
||||
case V4L2_PIX_FMT_RGB565:
|
||||
bytes_per_pixel = 2;
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_BGR24:
|
||||
case V4L2_PIX_FMT_RGB24: bytes_per_pixel = 3; break;
|
||||
case V4L2_PIX_FMT_RGB24:
|
||||
bytes_per_pixel = 3;
|
||||
break;
|
||||
|
||||
// case V4L2_PIX_FMT_H264:
|
||||
case V4L2_PIX_FMT_MJPEG:
|
||||
case V4L2_PIX_FMT_JPEG: bytes_per_pixel = 0; break;
|
||||
default: assert(0 && "Unknown format");
|
||||
case V4L2_PIX_FMT_JPEG:
|
||||
bytes_per_pixel = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0 && "Unknown format");
|
||||
}
|
||||
if (bytes_per_pixel > 0 && frame->stride > frame->width) {
|
||||
return (frame->stride - frame->width * bytes_per_pixel);
|
||||
|
||||
@@ -121,9 +121,16 @@ void us_frametext_draw(us_frametext_s *ft, const char *text, uint width, uint he
|
||||
if (block_width == 0 || block_height == 0) {
|
||||
goto empty;
|
||||
}
|
||||
uint scale_x = frame->width / block_width / 2;
|
||||
uint scale_y = frame->height / block_height / 3;
|
||||
if (scale_x < scale_y / 1.5) {
|
||||
|
||||
// Ширина текста должна быть от 75%, до половины экрана, в зависимости от длины
|
||||
const float div_x = US_MAX(US_MIN((100 / block_width * 2), 2.0), 1.5);
|
||||
|
||||
// Высоту тоже отрегулировать как-нибудь
|
||||
const float div_y = US_MAX(US_MIN((70 / block_height * 2), 2.0), 1.5);
|
||||
|
||||
uint scale_x = frame->width / block_width / div_x;
|
||||
uint scale_y = frame->height / block_height / div_y;
|
||||
if (scale_x < scale_y / 1.5) { // Keep proportions
|
||||
scale_y = scale_x * 1.5;
|
||||
} else if (scale_y < scale_x * 1.5) {
|
||||
scale_x = scale_y / 1.5;
|
||||
|
||||
@@ -25,14 +25,8 @@
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#if defined(__linux__)
|
||||
# define HAS_PDEATHSIG
|
||||
#elif defined(__FreeBSD__)
|
||||
#if defined(__FreeBSD__)
|
||||
# include <sys/param.h>
|
||||
# if __FreeBSD_version >= 1102000
|
||||
# define HAS_PDEATHSIG
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -49,20 +43,22 @@
|
||||
# error setproctitle() not implemented, you can disable it using WITH_SETPROCTITLE=0
|
||||
# endif
|
||||
#endif
|
||||
#ifdef HAS_PDEATHSIG
|
||||
|
||||
#ifdef WITH_PDEATHSIG
|
||||
# if defined(__linux__)
|
||||
# include <sys/prctl.h>
|
||||
# elif defined(__FreeBSD__)
|
||||
# elif defined(__FreeBSD__) && (__FreeBSD_version >= 1102000)
|
||||
# include <sys/procctl.h>
|
||||
# else
|
||||
# error WITH_PDEATHSIG is not supported on your system
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
#ifdef WITH_SETPROCTITLE
|
||||
# include "tools.h"
|
||||
#endif
|
||||
#ifdef HAS_PDEATHSIG
|
||||
# include "logging.h"
|
||||
#endif
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
#ifdef WITH_SETPROCTITLE
|
||||
@@ -70,7 +66,7 @@ extern char **environ;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAS_PDEATHSIG
|
||||
#ifdef WITH_PDEATHSIG
|
||||
INLINE int us_process_track_parent_death(void) {
|
||||
const pid_t parent = getppid();
|
||||
int signum = SIGTERM;
|
||||
|
||||
@@ -33,17 +33,6 @@
|
||||
#include "xioctl.h"
|
||||
|
||||
|
||||
#ifndef V4L2_CID_USER_TC358743_BASE
|
||||
# define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080)
|
||||
#endif
|
||||
#ifndef TC358743_CID_AUDIO_PRESENT
|
||||
# define TC358743_CID_AUDIO_PRESENT (V4L2_CID_USER_TC358743_BASE + 1)
|
||||
#endif
|
||||
#ifndef TC358743_CID_AUDIO_SAMPLING_RATE
|
||||
# define TC358743_CID_AUDIO_SAMPLING_RATE (V4L2_CID_USER_TC358743_BASE + 0)
|
||||
#endif
|
||||
|
||||
|
||||
int us_tc358743_xioctl_get_audio_hz(int fd, uint *audio_hz) {
|
||||
*audio_hz = 0;
|
||||
|
||||
|
||||
@@ -22,7 +22,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <linux/v4l2-controls.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
|
||||
#ifndef V4L2_CID_USER_TC358743_BASE
|
||||
# define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080)
|
||||
#endif
|
||||
|
||||
#ifndef TC358743_CID_AUDIO_SAMPLING_RATE
|
||||
# define TC358743_CID_AUDIO_SAMPLING_RATE (V4L2_CID_USER_TC358743_BASE + 0)
|
||||
#endif
|
||||
|
||||
#ifndef TC358743_CID_AUDIO_PRESENT
|
||||
# define TC358743_CID_AUDIO_PRESENT (V4L2_CID_USER_TC358743_BASE + 1)
|
||||
#endif
|
||||
|
||||
#ifndef TC358743_CID_LANES_ENOUGH
|
||||
# define TC358743_CID_LANES_ENOUGH (V4L2_CID_USER_TC358743_BASE + 2)
|
||||
#endif
|
||||
|
||||
|
||||
int us_tc358743_xioctl_get_audio_hz(int fd, uint *audio_hz);
|
||||
|
||||
@@ -36,7 +36,7 @@ us_blank_s *us_blank_init(void) {
|
||||
blank->ft = us_frametext_init();
|
||||
blank->raw = blank->ft->frame;
|
||||
blank->jpeg = us_frame_init();
|
||||
us_blank_draw(blank, "< NO SIGNAL >", 640, 480);
|
||||
us_blank_draw(blank, "< NO LIVE VIDEO >", 640, 480);
|
||||
return blank;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ typedef struct {
|
||||
static void _jpeg_set_dest_frame(j_compress_ptr jpeg, us_frame_s *frame);
|
||||
|
||||
static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||
static void _jpeg_write_scanlines_yuv_planar(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||
static void _jpeg_write_scanlines_grey(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||
#ifndef JCS_EXTENSIONS
|
||||
@@ -50,7 +52,7 @@ static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg);
|
||||
static void _jpeg_term_destination(j_compress_ptr jpeg);
|
||||
|
||||
|
||||
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned quality) {
|
||||
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, uint quality) {
|
||||
// This function based on compress_image_to_jpeg() from mjpg-streamer
|
||||
|
||||
us_frame_encoding_begin(src, dest, V4L2_PIX_FMT_JPEG);
|
||||
@@ -69,11 +71,23 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned q
|
||||
switch (src->format) {
|
||||
case V4L2_PIX_FMT_YUYV:
|
||||
case V4L2_PIX_FMT_YVYU:
|
||||
case V4L2_PIX_FMT_UYVY: jpeg.in_color_space = JCS_YCbCr; break;
|
||||
case V4L2_PIX_FMT_UYVY:
|
||||
case V4L2_PIX_FMT_YUV420:
|
||||
case V4L2_PIX_FMT_YVU420:
|
||||
jpeg.in_color_space = JCS_YCbCr;
|
||||
break;
|
||||
case V4L2_PIX_FMT_GREY:
|
||||
jpeg.input_components = 1;
|
||||
jpeg.in_color_space = JCS_GRAYSCALE;
|
||||
break;
|
||||
# ifdef JCS_EXTENSIONS
|
||||
case V4L2_PIX_FMT_BGR24: jpeg.in_color_space = JCS_EXT_BGR; break;
|
||||
case V4L2_PIX_FMT_BGR24:
|
||||
jpeg.in_color_space = JCS_EXT_BGR;
|
||||
break;
|
||||
# endif
|
||||
default: jpeg.in_color_space = JCS_RGB; break;
|
||||
default:
|
||||
jpeg.in_color_space = JCS_RGB;
|
||||
break;
|
||||
}
|
||||
|
||||
jpeg_set_defaults(&jpeg);
|
||||
@@ -85,9 +99,27 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned q
|
||||
// https://www.fourcc.org/yuv.php
|
||||
case V4L2_PIX_FMT_YUYV:
|
||||
case V4L2_PIX_FMT_YVYU:
|
||||
case V4L2_PIX_FMT_UYVY: _jpeg_write_scanlines_yuv(&jpeg, src); break;
|
||||
case V4L2_PIX_FMT_RGB565: _jpeg_write_scanlines_rgb565(&jpeg, src); break;
|
||||
case V4L2_PIX_FMT_RGB24: _jpeg_write_scanlines_rgb24(&jpeg, src); break;
|
||||
case V4L2_PIX_FMT_UYVY:
|
||||
_jpeg_write_scanlines_yuv(&jpeg, src);
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_YUV420:
|
||||
case V4L2_PIX_FMT_YVU420:
|
||||
_jpeg_write_scanlines_yuv_planar(&jpeg, src);
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_GREY:
|
||||
_jpeg_write_scanlines_grey(&jpeg, src);
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_RGB565:
|
||||
_jpeg_write_scanlines_rgb565(&jpeg, src);
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_RGB24:
|
||||
_jpeg_write_scanlines_rgb24(&jpeg, src);
|
||||
break;
|
||||
|
||||
case V4L2_PIX_FMT_BGR24:
|
||||
# ifdef JCS_EXTENSIONS
|
||||
_jpeg_write_scanlines_rgb24(&jpeg, src); // Use native JCS_EXT_BGR
|
||||
@@ -121,19 +153,19 @@ static void _jpeg_set_dest_frame(j_compress_ptr jpeg, us_frame_s *frame) {
|
||||
}
|
||||
|
||||
static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||
uint8_t *line_buf;
|
||||
u8 *line_buf;
|
||||
US_CALLOC(line_buf, frame->width * 3);
|
||||
|
||||
const unsigned padding = us_frame_get_padding(frame);
|
||||
const uint8_t *data = frame->data;
|
||||
const uint padding = us_frame_get_padding(frame);
|
||||
const u8 *data = frame->data;
|
||||
|
||||
while (jpeg->next_scanline < frame->height) {
|
||||
uint8_t *ptr = line_buf;
|
||||
u8 *ptr = line_buf;
|
||||
|
||||
for (unsigned x = 0; x < frame->width; ++x) {
|
||||
for (uint x = 0; x < frame->width; ++x) {
|
||||
// See also: https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/pixfmt-uyvy.html
|
||||
const bool is_odd_pixel = x & 1;
|
||||
uint8_t y, u, v;
|
||||
u8 y, u, v;
|
||||
if (frame->format == V4L2_PIX_FMT_YUYV) {
|
||||
y = data[is_odd_pixel ? 2 : 0];
|
||||
u = data[1];
|
||||
@@ -167,21 +199,104 @@ static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const u
|
||||
free(line_buf);
|
||||
}
|
||||
|
||||
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||
uint8_t *line_buf;
|
||||
static void _jpeg_write_scanlines_yuv_planar(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||
u8 *line_buf;
|
||||
US_CALLOC(line_buf, frame->width * 3);
|
||||
|
||||
const unsigned padding = us_frame_get_padding(frame);
|
||||
const uint8_t *data = frame->data;
|
||||
const uint padding = us_frame_get_padding(frame);
|
||||
const uint image_size = frame->width * frame->height;
|
||||
const uint chroma_array_size = (frame->used - image_size) / 2;
|
||||
const uint chroma_matrix_order = (image_size / chroma_array_size) == 16 ? 4 : 2;
|
||||
const u8 *data = frame->data;
|
||||
const u8 *chroma1_data = frame->data + image_size;
|
||||
const u8 *chroma2_data = frame->data + image_size + chroma_array_size;
|
||||
|
||||
//US_LOG_DEBUG("Planar data: Image Size %u, Chroma Array Size %u, Chroma Matrix Order %u",
|
||||
// image_size, chroma_array_size, chroma_matrix_order);
|
||||
|
||||
while (jpeg->next_scanline < frame->height) {
|
||||
uint8_t *ptr = line_buf;
|
||||
u8 *ptr = line_buf;
|
||||
|
||||
for (unsigned x = 0; x < frame->width; ++x) {
|
||||
const unsigned int two_byte = (data[1] << 8) + data[0];
|
||||
for (uint x = 0; x < frame->width; ++x) {
|
||||
// See also: https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/pixfmt-yuv420.html
|
||||
u8 y = data[x];
|
||||
u8 u;
|
||||
u8 v;
|
||||
uint chroma_position = x / chroma_matrix_order;
|
||||
|
||||
switch (frame->format) {
|
||||
case V4L2_PIX_FMT_YUV420:
|
||||
u = chroma1_data[chroma_position];
|
||||
v = chroma2_data[chroma_position];
|
||||
break;
|
||||
case V4L2_PIX_FMT_YVU420:
|
||||
u = chroma2_data[chroma_position];
|
||||
v = chroma1_data[chroma_position];
|
||||
break;
|
||||
default:
|
||||
assert(0 && "Unsupported pixel format");
|
||||
return; // Makes linter happy
|
||||
}
|
||||
|
||||
ptr[0] = y;
|
||||
ptr[1] = u;
|
||||
ptr[2] = v;
|
||||
ptr += 3;
|
||||
}
|
||||
|
||||
data += frame->width + padding;
|
||||
|
||||
if (jpeg->next_scanline > 0 && jpeg->next_scanline % chroma_matrix_order == 0) {
|
||||
chroma1_data += (frame->width + padding) / chroma_matrix_order;
|
||||
chroma2_data += (frame->width + padding) / chroma_matrix_order;
|
||||
}
|
||||
|
||||
JSAMPROW scanlines[1] = {line_buf};
|
||||
jpeg_write_scanlines(jpeg, scanlines, 1);
|
||||
}
|
||||
|
||||
free(line_buf);
|
||||
}
|
||||
|
||||
static void _jpeg_write_scanlines_grey(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||
u8 *line_buf;
|
||||
US_CALLOC(line_buf, frame->width);
|
||||
|
||||
const uint padding = us_frame_get_padding(frame);
|
||||
const u8 *data = frame->data;
|
||||
|
||||
while (jpeg->next_scanline < frame->height) {
|
||||
u8 *ptr = line_buf;
|
||||
|
||||
for (uint x = 0; x < frame->width; ++x) {
|
||||
ptr[0] = data[x];
|
||||
ptr += 1;
|
||||
}
|
||||
|
||||
data += frame->width + padding;
|
||||
|
||||
JSAMPROW scanlines[1] = {line_buf};
|
||||
jpeg_write_scanlines(jpeg, scanlines, 1);
|
||||
}
|
||||
|
||||
free(line_buf);
|
||||
}
|
||||
|
||||
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||
u8 *line_buf;
|
||||
US_CALLOC(line_buf, frame->width * 3);
|
||||
|
||||
const uint padding = us_frame_get_padding(frame);
|
||||
const u8 *data = frame->data;
|
||||
|
||||
while (jpeg->next_scanline < frame->height) {
|
||||
u8 *ptr = line_buf;
|
||||
|
||||
for (uint x = 0; x < frame->width; ++x) {
|
||||
const uint two_byte = (data[1] << 8) + data[0];
|
||||
|
||||
ptr[0] = data[1] & 248; // Red
|
||||
ptr[1] = (uint8_t)((two_byte & 2016) >> 3); // Green
|
||||
ptr[1] = (u8)((two_byte & 2016) >> 3); // Green
|
||||
ptr[2] = (data[0] & 31) * 8; // Blue
|
||||
ptr += 3;
|
||||
|
||||
@@ -197,8 +312,8 @@ static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, cons
|
||||
}
|
||||
|
||||
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||
const unsigned padding = us_frame_get_padding(frame);
|
||||
uint8_t *data = frame->data;
|
||||
const uint padding = us_frame_get_padding(frame);
|
||||
u8 *data = frame->data;
|
||||
|
||||
while (jpeg->next_scanline < frame->height) {
|
||||
JSAMPROW scanlines[1] = {data};
|
||||
@@ -210,17 +325,17 @@ static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const
|
||||
|
||||
#ifndef JCS_EXTENSIONS
|
||||
static void _jpeg_write_scanlines_bgr24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||
uint8_t *line_buf;
|
||||
u8 *line_buf;
|
||||
US_CALLOC(line_buf, frame->width * 3);
|
||||
|
||||
const unsigned padding = us_frame_get_padding(frame);
|
||||
uint8_t *data = frame->data;
|
||||
const uint padding = us_frame_get_padding(frame);
|
||||
u8 *data = frame->data;
|
||||
|
||||
while (jpeg->next_scanline < frame->height) {
|
||||
uint8_t *ptr = line_buf;
|
||||
u8 *ptr = line_buf;
|
||||
|
||||
// swap B and R values
|
||||
for (unsigned x = 0; x < frame->width * 3; x += 3) {
|
||||
for (uint x = 0; x < frame->width * 3; x += 3) {
|
||||
ptr[0] = data[x + 2];
|
||||
ptr[1] = data[x + 1];
|
||||
ptr[2] = data[x];
|
||||
|
||||
@@ -35,4 +35,4 @@
|
||||
#include "../../../libs/frame.h"
|
||||
|
||||
|
||||
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned quality);
|
||||
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, uint quality);
|
||||
|
||||
@@ -880,7 +880,7 @@ static void _http_send_snapshot(us_server_s *server) {
|
||||
if (!captured_meta.online) {
|
||||
if (blank == NULL) {
|
||||
blank = us_blank_init();
|
||||
us_blank_draw(blank, "< NO SIGNAL >", captured_meta.width, captured_meta.height);
|
||||
us_blank_draw(blank, "< NO LIVE VIDEO >", captured_meta.width, captured_meta.height);
|
||||
}
|
||||
frame = blank->jpeg;
|
||||
}
|
||||
|
||||
@@ -114,9 +114,10 @@ enum _US_OPT_VALUES {
|
||||
_O_GPIO_HAS_HTTP_CLIENTS,
|
||||
# endif
|
||||
|
||||
# ifdef HAS_PDEATHSIG
|
||||
# ifdef WITH_PDEATHSIG
|
||||
_O_EXIT_ON_PARENT_DEATH,
|
||||
# endif
|
||||
_O_EXIT_ON_DEVICE_ERROR,
|
||||
_O_EXIT_ON_NO_CLIENTS,
|
||||
# ifdef WITH_SETPROCTITLE
|
||||
_O_PROCESS_NAME_PREFIX,
|
||||
@@ -138,7 +139,7 @@ static const struct option _LONG_OPTS[] = {
|
||||
{"input", required_argument, NULL, _O_INPUT},
|
||||
{"resolution", required_argument, NULL, _O_RESOLUTION},
|
||||
{"format", required_argument, NULL, _O_FORMAT},
|
||||
{"format-swap-rgb", required_argument, NULL, _O_FORMAT_SWAP_RGB},
|
||||
{"format-swap-rgb", no_argument, NULL, _O_FORMAT_SWAP_RGB},
|
||||
{"tv-standard", required_argument, NULL, _O_TV_STANDARD},
|
||||
{"io-method", required_argument, NULL, _O_IO_METHOD},
|
||||
{"desired-fps", required_argument, NULL, _O_DESIRED_FPS},
|
||||
@@ -224,9 +225,10 @@ static const struct option _LONG_OPTS[] = {
|
||||
{"gpio-has-http-clients", required_argument, NULL, _O_GPIO_HAS_HTTP_CLIENTS},
|
||||
# endif
|
||||
|
||||
# ifdef HAS_PDEATHSIG
|
||||
# ifdef WITH_PDEATHSIG
|
||||
{"exit-on-parent-death", no_argument, NULL, _O_EXIT_ON_PARENT_DEATH},
|
||||
# endif
|
||||
{"exit-on-device-error", no_argument, NULL, _O_EXIT_ON_DEVICE_ERROR},
|
||||
{"exit-on-no-clients", required_argument, NULL, _O_EXIT_ON_NO_CLIENTS},
|
||||
# ifdef WITH_SETPROCTITLE
|
||||
{"process-name-prefix", required_argument, NULL, _O_PROCESS_NAME_PREFIX},
|
||||
@@ -483,13 +485,14 @@ int options_parse(us_options_s *options, us_capture_s *cap, us_encoder_s *enc, u
|
||||
case _O_GPIO_HAS_HTTP_CLIENTS: OPT_NUMBER("--gpio-has-http-clients", us_g_gpio.has_http_clients.pin, 0, 256, 0);
|
||||
# endif
|
||||
|
||||
# ifdef HAS_PDEATHSIG
|
||||
# ifdef WITH_PDEATHSIG
|
||||
case _O_EXIT_ON_PARENT_DEATH:
|
||||
if (us_process_track_parent_death() < 0) {
|
||||
return -1;
|
||||
};
|
||||
break;
|
||||
# endif
|
||||
case _O_EXIT_ON_DEVICE_ERROR: OPT_SET(stream->exit_on_device_error, true);
|
||||
case _O_EXIT_ON_NO_CLIENTS: OPT_NUMBER("--exit-on-no-clients", stream->exit_on_no_clients, 0, 86400, 0);
|
||||
# ifdef WITH_SETPROCTITLE
|
||||
case _O_PROCESS_NAME_PREFIX: OPT_SET(process_name_prefix, optarg);
|
||||
@@ -581,34 +584,52 @@ static int _check_instance_id(const char *str) {
|
||||
}
|
||||
|
||||
static void _features(void) {
|
||||
# ifdef WITH_GPIO
|
||||
# ifdef MK_WITH_PYTHON
|
||||
puts("+ WITH_PYTHON");
|
||||
# else
|
||||
puts("- WITH_PYTHON");
|
||||
# endif
|
||||
|
||||
# ifdef MK_WITH_JANUS
|
||||
puts("+ WITH_JANUS");
|
||||
# else
|
||||
puts("- WITH_JANUS");
|
||||
# endif
|
||||
|
||||
# ifdef MK_WITH_V4P
|
||||
puts("+ WITH_V4P");
|
||||
# else
|
||||
puts("- WITH_V4P");
|
||||
# endif
|
||||
|
||||
# ifdef MK_WITH_GPIO
|
||||
puts("+ WITH_GPIO");
|
||||
# else
|
||||
puts("- WITH_GPIO");
|
||||
# endif
|
||||
|
||||
# ifdef WITH_SYSTEMD
|
||||
# ifdef MK_WITH_SYSTEMD
|
||||
puts("+ WITH_SYSTEMD");
|
||||
# else
|
||||
puts("- WITH_SYSTEMD");
|
||||
# endif
|
||||
|
||||
# ifdef WITH_PTHREAD_NP
|
||||
# ifdef MK_WITH_PTHREAD_NP
|
||||
puts("+ WITH_PTHREAD_NP");
|
||||
# else
|
||||
puts("- WITH_PTHREAD_NP");
|
||||
# endif
|
||||
|
||||
# ifdef WITH_SETPROCTITLE
|
||||
# ifdef MK_WITH_SETPROCTITLE
|
||||
puts("+ WITH_SETPROCTITLE");
|
||||
# else
|
||||
puts("- WITH_SETPROCTITLE");
|
||||
# endif
|
||||
|
||||
# ifdef HAS_PDEATHSIG
|
||||
puts("+ HAS_PDEATHSIG");
|
||||
# ifdef MK_WITH_PDEATHSIG
|
||||
puts("+ WITH_PDEATHSIG");
|
||||
# else
|
||||
puts("- HAS_PDEATHSIG");
|
||||
puts("- WITH_PDEATHSIG");
|
||||
# endif
|
||||
}
|
||||
|
||||
@@ -740,11 +761,11 @@ static void _help(FILE *fp, const us_capture_s *cap, const us_encoder_s *enc, co
|
||||
SAY(" --gpio-stream-online <pin> ──── Set 1 while streaming. Default: disabled.\n");
|
||||
SAY(" --gpio-has-http-clients <pin> ─ Set 1 while stream has at least one client. Default: disabled.\n");
|
||||
# endif
|
||||
# if (defined(HAS_PDEATHSIG) || defined(WITH_SETPROCTITLE))
|
||||
# if (defined(WITH_PDEATHSIG) || defined(WITH_SETPROCTITLE))
|
||||
SAY("Process options:");
|
||||
SAY("════════════════");
|
||||
# endif
|
||||
# ifdef HAS_PDEATHSIG
|
||||
# ifdef WITH_PDEATHSIG
|
||||
SAY(" --exit-on-parent-death ─────── Exit the program if the parent process is dead. Default: disabled.\n");
|
||||
# endif
|
||||
SAY(" --exit-on-no-clients <sec> ──── Exit the program if there have been no stream or sink clients");
|
||||
|
||||
@@ -129,7 +129,7 @@ us_stream_s *us_stream_init(us_capture_s *cap, us_encoder_s *enc) {
|
||||
|
||||
void us_stream_update_blank(us_stream_s *stream, const us_capture_s *cap) {
|
||||
us_stream_runtime_s *const run = stream->run;
|
||||
us_blank_draw(run->blank, "< NO SIGNAL >", cap->width, cap->height);
|
||||
us_blank_draw(run->blank, "< NO LIVE VIDEO >", cap->width, cap->height);
|
||||
us_fpsi_frame_to_meta(run->blank->raw, &run->notify_meta); // Initial "unchanged" meta
|
||||
_stream_update_captured_fpsi(stream, run->blank->raw, false);
|
||||
}
|
||||
@@ -529,6 +529,8 @@ static int _stream_init_loop(us_stream_s *stream) {
|
||||
|
||||
int once = 0;
|
||||
while (!atomic_load(&stream->run->stop)) {
|
||||
const char *blank_reason = "< NO LIVE VIDEO >";
|
||||
|
||||
# ifdef WITH_GPIO
|
||||
us_gpio_set_stream_online(false);
|
||||
# endif
|
||||
@@ -554,17 +556,68 @@ static int _stream_init_loop(us_stream_s *stream) {
|
||||
switch (us_capture_open(stream->cap)) {
|
||||
case 0: break;
|
||||
case US_ERROR_NO_DEVICE:
|
||||
case US_ERROR_NO_DATA:
|
||||
US_ONCE({ US_LOG_INFO("Waiting for the capture device ..."); });
|
||||
goto offline_and_retry;
|
||||
blank_reason = (
|
||||
"< NO CAPTURE DEVICE >\n \n"
|
||||
" Possible reasons: \n \n"
|
||||
" - Device unplugged \n \n"
|
||||
" - Bad config \n \n"
|
||||
" - Malfunction "
|
||||
);
|
||||
goto silent_error;
|
||||
case US_ERROR_NO_CABLE:
|
||||
blank_reason = (
|
||||
"< NO VIDEO SOURCE >\n \n"
|
||||
" Possible reasons: \n \n"
|
||||
" - Source is off \n \n"
|
||||
" - Cable problems "
|
||||
);
|
||||
goto silent_error;
|
||||
case US_ERROR_NO_SIGNAL:
|
||||
blank_reason = (
|
||||
"< NO SIGNAL DETECTED >\n \n"
|
||||
" Possible reasons: \n \n"
|
||||
" - Video suspended \n \n"
|
||||
" - Cable problems "
|
||||
);
|
||||
goto silent_error;
|
||||
case US_ERROR_NO_SYNC:
|
||||
blank_reason = (
|
||||
"< NO SYNC WITH SIGNAL >\n \n"
|
||||
" Possible reasons: \n \n"
|
||||
" - Source is crazy \n \n"
|
||||
" - Cable problems "
|
||||
);
|
||||
goto silent_error;
|
||||
case US_ERROR_NO_LANES:
|
||||
blank_reason = (
|
||||
"< UNSUPPORTED SIGNAL TIMINGS >\n \n"
|
||||
" Possible reasons: \n \n"
|
||||
" - Too high frequency \n \n"
|
||||
" - Source ignores EDID \n \n"
|
||||
" - Invalid EDID "
|
||||
);
|
||||
goto verbose_error;
|
||||
default:
|
||||
once = 0;
|
||||
goto offline_and_retry;
|
||||
goto verbose_error;
|
||||
}
|
||||
us_encoder_open(stream->enc, stream->cap);
|
||||
return 0;
|
||||
|
||||
silent_error:
|
||||
if (!stream->exit_on_device_error) {
|
||||
US_ONCE({ US_LOG_INFO("Waiting for the capture device ..."); });
|
||||
}
|
||||
goto offline_and_retry;
|
||||
|
||||
verbose_error:
|
||||
once = 0;
|
||||
goto offline_and_retry;
|
||||
|
||||
offline_and_retry:
|
||||
if (stream->exit_on_device_error) {
|
||||
US_LOG_INFO("Device error, exiting ...");
|
||||
us_process_suicide();
|
||||
}
|
||||
for (uint count = 0; count < stream->error_delay * 10; ++count) {
|
||||
if (atomic_load(&run->stop)) {
|
||||
break;
|
||||
@@ -577,7 +630,7 @@ static int _stream_init_loop(us_stream_s *stream) {
|
||||
width = stream->cap->width;
|
||||
height = stream->cap->height;
|
||||
}
|
||||
us_blank_draw(run->blank, "< NO SIGNAL >", width, height);
|
||||
us_blank_draw(run->blank, blank_reason, width, height);
|
||||
|
||||
_stream_update_captured_fpsi(stream, run->blank->raw, false);
|
||||
_stream_expose_jpeg(stream, run->blank->jpeg);
|
||||
|
||||
@@ -80,6 +80,7 @@ typedef struct {
|
||||
bool notify_parent;
|
||||
bool slowdown;
|
||||
uint error_delay;
|
||||
bool exit_on_device_error;
|
||||
uint exit_on_no_clients;
|
||||
|
||||
us_memsink_s *jpeg_sink;
|
||||
|
||||
Reference in New Issue
Block a user