Compare commits

...

29 Commits
v6.4 ... v6.9

Author SHA1 Message Date
Maxim Devaev
d64077c2d5 Bump version: 6.8 → 6.9 2024-03-27 21:39:03 +02:00
Maxim Devaev
83f12baa61 refactoring 2024-03-27 19:27:28 +02:00
Maxim Devaev
b6fac2608d ustreamer-v4p: bring back busy message 2024-03-27 19:22:21 +02:00
Maxim Devaev
e6ebc12505 replaced comment 2024-03-27 02:14:36 +02:00
Maxim Devaev
8c92ab6f47 ustreamer: blank drm output by timeout 2024-03-26 22:20:08 +02:00
Maxim Devaev
7dc492d875 refactoring 2024-03-26 21:51:47 +02:00
Maxim Devaev
d43014346d Bump version: 6.7 → 6.8 2024-03-26 20:23:16 +02:00
Maxim Devaev
bcd447963c build fix 2024-03-26 20:22:10 +02:00
Maxim Devaev
eec6cfd0d4 lint fix 2024-03-26 20:10:06 +02:00
Maxim Devaev
f177300e69 ustreamer/drm: fixed assertion 2024-03-26 18:59:33 +02:00
Maxim Devaev
7015a26a63 Userspace workaround for the wrong TC358743 RGB bytes ordering
- https://github.com/raspberrypi/linux/issues/6068
2024-03-26 18:35:13 +02:00
Maxim Devaev
290282b6b6 drm: fixed big endian case for rgb/bgr 2024-03-26 18:05:51 +02:00
Maxim Devaev
a339ff5d06 v4p mode in ustreamer 2024-03-26 17:45:53 +02:00
Maxim Devaev
8d4e9a6ca0 renamed us_hw_buffer_s to us_capture_hwbuf_s 2024-03-26 01:54:01 +02:00
Maxim Devaev
f0f5fcd67f renamed us_device* to us_capture* 2024-03-26 01:25:04 +02:00
Maxim Devaev
02fabc7b45 Bump version: 6.6 → 6.7 2024-03-25 20:16:52 +02:00
Maxim Devaev
bdf55396e5 fixed memsink data offset 2024-03-25 20:15:38 +02:00
Maxim Devaev
976f466038 PKGBUILD: fixed missing python-wheel 2024-03-23 19:40:29 +02:00
Maxim Devaev
b79b4fd55e Bump version: 6.5 → 6.6 2024-03-22 15:58:21 +02:00
Maxim Devaev
6d77f5334f updated copyright date 2024-03-22 15:57:16 +02:00
Maxim Devaev
25957de017 direct call of setup.py is deprecated 2024-03-22 15:55:06 +02:00
Maxim Devaev
847f34e10c fixed symlink 2024-03-22 14:12:43 +02:00
Maxim Devaev
0ab8e0d05e DESTDIR always transformed to absolute R_DESTDIR 2024-03-22 12:59:37 +02:00
Kiyofumi Kondoh
ac88996a8c adapt pacman 6.1 and lower version (#266)
* adapt pacman 6.1 and lower version

* remove legacy operation
2024-03-21 22:47:23 +02:00
Maxim Devaev
408157c82b Bump version: 6.4 → 6.5 2024-03-21 13:33:29 +02:00
Maxim Devaev
7356dea737 renamed options --sink* to --jpeg-sink* 2024-03-21 13:21:51 +02:00
Maxim Devaev
87a75a816a memsink: suffix-based memory limites 2024-03-20 22:55:37 +02:00
Maxim Devaev
b6a2332207 refactoring 2024-03-20 17:51:56 +02:00
Maxim Devaev
34c0dcb1ce refactoring 2024-03-19 19:33:55 +02:00
122 changed files with 1171 additions and 950 deletions

View File

@@ -1,7 +1,7 @@
[bumpversion] [bumpversion]
commit = True commit = True
tag = True tag = True
current_version = 6.4 current_version = 6.9
parse = (?P<major>\d+)\.(?P<minor>\d+) parse = (?P<major>\d+)\.(?P<minor>\d+)
serialize = serialize =
{major}.{minor} {major}.{minor}

3
.gitignore vendored
View File

@@ -3,8 +3,9 @@
/pkg/arch/pkg/ /pkg/arch/pkg/
/pkg/arch/src/ /pkg/arch/src/
/src/build/ /src/build/
/python/build/ /python/dist/
/python/ustreamer.egg-info/ /python/ustreamer.egg-info/
/python/root/
/janus/build/ /janus/build/
/ustreamer /ustreamer
/ustreamer-* /ustreamer-*

View File

@@ -9,6 +9,8 @@ PY ?= python3
CFLAGS ?= -O3 CFLAGS ?= -O3
LDFLAGS ?= LDFLAGS ?=
R_DESTDIR = $(if $(DESTDIR),$(shell realpath "$(DESTDIR)"),)
export export
_LINTERS_IMAGE ?= ustreamer-linters _LINTERS_IMAGE ?= ustreamer-linters
@@ -43,7 +45,7 @@ apps:
python: python:
$(MAKE) -C python $(MAKE) -C python
$(ECHO) ln -sf python/build/lib.*/*.so . $(ECHO) ln -sf python/root/usr/lib/python*/site-packages/*.so .
janus: janus:
@@ -59,10 +61,10 @@ endif
ifneq ($(call optbool,$(WITH_JANUS)),) ifneq ($(call optbool,$(WITH_JANUS)),)
$(MAKE) -C janus install $(MAKE) -C janus install
endif endif
mkdir -p $(DESTDIR)$(MANPREFIX)/man1 mkdir -p $(R_DESTDIR)$(MANPREFIX)/man1
for man in $(shell ls man); do \ for man in $(shell ls man); do \
install -m644 man/$$man $(DESTDIR)$(MANPREFIX)/man1/$$man; \ install -m644 man/$$man $(R_DESTDIR)$(MANPREFIX)/man1/$$man; \
gzip -f $(DESTDIR)$(MANPREFIX)/man1/$$man; \ gzip -f $(R_DESTDIR)$(MANPREFIX)/man1/$$man; \
done done

View File

@@ -209,7 +209,7 @@ v4l2 utilities provide the tools to manage USB webcam setting and information. S
----- -----
# License # License
Copyright (C) 2018-2023 by Maxim Devaev mdevaev@gmail.com Copyright (C) 2018-2024 by Maxim Devaev mdevaev@gmail.com
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -1,4 +1,4 @@
DESTDIR ?= R_DESTDIR ?=
PREFIX ?= /usr/local PREFIX ?= /usr/local
CC ?= gcc CC ?= gcc
@@ -42,8 +42,8 @@ $(_BUILD)/%.o: %.c
install: $(_PLUGIN) install: $(_PLUGIN)
mkdir -p $(DESTDIR)$(PREFIX)/lib/ustreamer/janus mkdir -p $(R_DESTDIR)$(PREFIX)/lib/ustreamer/janus
install -m755 $(_PLUGIN) $(DESTDIR)$(PREFIX)/lib/ustreamer/janus/$(PLUGIN) install -m755 $(_PLUGIN) $(R_DESTDIR)$(PREFIX)/lib/ustreamer/janus/$(PLUGIN)
clean: clean:

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -214,7 +214,7 @@ static _enc_buffer_s *_enc_buffer_init(void) {
static void *_pcm_thread(void *v_audio) { static void *_pcm_thread(void *v_audio) {
US_THREAD_SETTLE("us_a_pcm"); US_THREAD_SETTLE("us_a_pcm");
us_audio_s *const audio = (us_audio_s *)v_audio; us_audio_s *const audio = v_audio;
u8 in[_MAX_BUF8]; u8 in[_MAX_BUF8];
while (!atomic_load(&audio->stop)) { while (!atomic_load(&audio->stop)) {
@@ -244,7 +244,7 @@ static void *_pcm_thread(void *v_audio) {
static void *_encoder_thread(void *v_audio) { static void *_encoder_thread(void *v_audio) {
US_THREAD_SETTLE("us_a_enc"); US_THREAD_SETTLE("us_a_enc");
us_audio_s *const audio = (us_audio_s *)v_audio; us_audio_s *const audio = v_audio;
s16 in_res[_MAX_BUF16]; s16 in_res[_MAX_BUF16];
while (!atomic_load(&audio->stop)) { while (!atomic_load(&audio->stop)) {

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -104,7 +104,7 @@ static void *_audio_thread(void *v_client) {
} }
static void *_common_thread(void *v_client, bool video) { static void *_common_thread(void *v_client, bool video) {
us_janus_client_s *const client = (us_janus_client_s *)v_client; us_janus_client_s *const client = v_client;
us_ring_s *const ring = (video ? client->video_ring : client->audio_ring); us_ring_s *const ring = (video ? client->video_ring : client->audio_ring);
assert(ring != NULL); // Audio may be NULL assert(ring != NULL); // Audio may be NULL

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -58,7 +58,7 @@ int us_memsink_fd_wait_frame(int fd, us_memsink_shared_s *mem, u64 last_id) {
} }
int us_memsink_fd_get_frame(int fd, us_memsink_shared_s *mem, us_frame_s *frame, u64 *frame_id, bool key_required) { int us_memsink_fd_get_frame(int fd, us_memsink_shared_s *mem, us_frame_s *frame, u64 *frame_id, bool key_required) {
us_frame_set_data(frame, mem->data, mem->used); us_frame_set_data(frame, us_memsink_get_data(mem), mem->used);
US_FRAME_COPY_META(mem, frame); US_FRAME_COPY_META(mem, frame);
*frame_id = mem->id; *frame_id = mem->id;
mem->last_client_ts = us_get_now_monotonic(); mem->last_client_ts = us_get_now_monotonic();

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -136,12 +136,18 @@ static void *_video_sink_thread(void *arg) {
int fd = -1; int fd = -1;
us_memsink_shared_s *mem = NULL; us_memsink_shared_s *mem = NULL;
const uz data_size = us_memsink_calculate_size(_g_config->video_sink_name);
if (data_size == 0) {
US_ONCE({ US_JLOG_ERROR("video", "Invalid memsink object suffix"); });
goto close_memsink;
}
if ((fd = shm_open(_g_config->video_sink_name, O_RDWR, 0)) <= 0) { if ((fd = shm_open(_g_config->video_sink_name, O_RDWR, 0)) <= 0) {
US_ONCE({ US_JLOG_PERROR("video", "Can't open memsink"); }); US_ONCE({ US_JLOG_PERROR("video", "Can't open memsink"); });
goto close_memsink; goto close_memsink;
} }
if ((mem = us_memsink_shared_map(fd)) == NULL) { if ((mem = us_memsink_shared_map(fd, data_size)) == NULL) {
US_ONCE({ US_JLOG_PERROR("video", "Can't map memsink"); }); US_ONCE({ US_JLOG_PERROR("video", "Can't map memsink"); });
goto close_memsink; goto close_memsink;
} }
@@ -178,7 +184,10 @@ static void *_video_sink_thread(void *arg) {
} }
close_memsink: close_memsink:
US_DELETE(mem, us_memsink_shared_unmap); if (mem != NULL) {
us_memsink_shared_unmap(mem, data_size);
mem = NULL;
}
US_CLOSE_FD(fd); US_CLOSE_FD(fd);
US_JLOG_INFO("video", "Memsink closed"); US_JLOG_INFO("video", "Memsink closed");
sleep(1); // error_delay sleep(1); // error_delay

View File

@@ -5,7 +5,7 @@
# This source file is partially based on this code: # # This source file is partially based on this code: #
# - https://github.com/catid/kvm/blob/master/kvm_pipeline/src # # - https://github.com/catid/kvm/blob/master/kvm_pipeline/src #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -57,7 +57,7 @@ void us_rtp_write_header(us_rtp_s *rtp, u32 pts, bool marked) {
++rtp->seq; ++rtp->seq;
# define WRITE_BE_U32(x_offset, x_value) \ # define WRITE_BE_U32(x_offset, x_value) \
*((u32 *)(rtp->datagram + x_offset)) = __builtin_bswap32(x_value) *((u32*)(rtp->datagram + x_offset)) = __builtin_bswap32(x_value)
WRITE_BE_U32(0, word0); WRITE_BE_U32(0, word0);
WRITE_BE_U32(4, pts); WRITE_BE_U32(4, pts);
WRITE_BE_U32(8, rtp->ssrc); WRITE_BE_U32(8, rtp->ssrc);

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -5,7 +5,7 @@
# This source file is partially based on this code: # # This source file is partially based on this code: #
# - https://github.com/catid/kvm/blob/master/kvm_pipeline/src # # - https://github.com/catid/kvm/blob/master/kvm_pipeline/src #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -0,0 +1 @@
../../../src/libs/memsinksh.c

View File

@@ -1,44 +0,0 @@
/*****************************************************************************
# #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
*****************************************************************************/
#pragma once
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
typedef long long sll;
typedef ssize_t sz;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef unsigned uint;
typedef unsigned long long ull;
typedef size_t uz;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef long double ldf;

1
janus/src/uslibs/types.h Symbolic link
View File

@@ -0,0 +1 @@
../../../src/libs/types.h

View File

@@ -1,6 +1,6 @@
.\" Manpage for ustreamer-dump. .\" Manpage for ustreamer-dump.
.\" Open an issue or pull request to https://github.com/pikvm/ustreamer to correct errors or typos .\" Open an issue or pull request to https://github.com/pikvm/ustreamer to correct errors or typos
.TH USTREAMER-DUMP 1 "version 6.4" "January 2021" .TH USTREAMER-DUMP 1 "version 6.9" "January 2021"
.SH NAME .SH NAME
ustreamer-dump \- Dump uStreamer's memory sink to file ustreamer-dump \- Dump uStreamer's memory sink to file

View File

@@ -1,6 +1,6 @@
.\" Manpage for ustreamer. .\" Manpage for ustreamer.
.\" Open an issue or pull request to https://github.com/pikvm/ustreamer to correct errors or typos .\" Open an issue or pull request to https://github.com/pikvm/ustreamer to correct errors or typos
.TH USTREAMER 1 "version 6.4" "November 2020" .TH USTREAMER 1 "version 6.9" "November 2020"
.SH NAME .SH NAME
ustreamer \- stream MJPEG video from any V4L2 device to the network ustreamer \- stream MJPEG video from any V4L2 device to the network
@@ -212,25 +212,25 @@ Timeout for client connections. Default: 10.
.SS "JPEG sink options" .SS "JPEG sink options"
With shared memory sink you can write a stream to a file. See \fBustreamer-dump\fR(1) for more info. With shared memory sink you can write a stream to a file. See \fBustreamer-dump\fR(1) for more info.
.TP .TP
.BR \-\-sink\ \fIname .BR \-\-jpeg\-sink\ \fIname
Use the specified shared memory object to sink JPEG frames. Default: disabled. Use the specified shared memory object to sink JPEG frames. The name should end with a suffix ".jpeg" or ":jpeg". Default: disabled.
.TP .TP
.BR \-\-sink\-mode\ \fImode .BR \-\-jpeg\-sink\-mode\ \fImode
Set JPEG sink permissions (like 777). Default: 660. Set JPEG sink permissions (like 777). Default: 660.
.TP .TP
.BR \-\-sink\-rm .BR \-\-jpeg\-sink\-rm
Remove shared memory on stop. Default: disabled. Remove shared memory on stop. Default: disabled.
.TP .TP
.BR \-\-sink\-client\-ttl\ \fIsec .BR \-\-jpeg\-sink\-client\-ttl\ \fIsec
Client TTL. Default: 10. Client TTL. Default: 10.
.TP .TP
.BR \-\-sink\-timeout\ \fIsec .BR \-\-jpeg\-sink\-timeout\ \fIsec
Timeout for lock. Default: 1. Timeout for lock. Default: 1.
.SS "H264 sink options" .SS "H264 sink options"
.TP .TP
.BR \-\-h264\-sink\ \fIname .BR \-\-h264\-sink\ \fIname
Use the specified shared memory object to sink H264 frames. Default: disabled. Use the specified shared memory object to sink H264 frames. The name should end with a suffix ".h264" or ":h264". Default: disabled.
.TP .TP
.BR \-\-h264\-sink\-mode\ \fImode .BR \-\-h264\-sink\-mode\ \fImode
Set H264 sink permissions (like 777). Default: 660. Set H264 sink permissions (like 777). Default: 660.
@@ -253,6 +253,22 @@ Interval between keyframes. Default: 30.
.BR \-\-h264\-m2m\-device\ \fI/dev/path .BR \-\-h264\-m2m\-device\ \fI/dev/path
Path to V4L2 mem-to-mem encoder device. Default: auto-select. Path to V4L2 mem-to-mem encoder device. Default: auto-select.
.SS "RAW sink options"
.TP
.BR \-\-raw\-sink\ \fIname
Use the specified shared memory object to sink RAW frames. The name should end with a suffix ".raw" or ":raw". Default: disabled.
.TP
.BR \-\-raw\-sink\-mode\ \fImode
Set RAW sink permissions (like 777). Default: 660.
.TP
.BR \-\-raw\-sink\-rm
Remove shared memory on stop. Default: disabled.
.TP
.BR \-\-raw\-sink\-client\-ttl\ \fIsec
Client TTL. Default: 10.
.TP
.BR \-\-raw\-sink\-timeout\ \fIsec
Timeout for lock. Default: 1.
.SS "Process options" .SS "Process options"
.TP .TP

View File

@@ -3,7 +3,7 @@
pkgname=ustreamer pkgname=ustreamer
pkgver=6.4 pkgver=6.9
pkgrel=1 pkgrel=1
pkgdesc="Lightweight and fast MJPEG-HTTP streamer" pkgdesc="Lightweight and fast MJPEG-HTTP streamer"
url="https://github.com/pikvm/ustreamer" url="https://github.com/pikvm/ustreamer"
@@ -19,7 +19,7 @@ _options="WITH_GPIO=1 WITH_SYSTEMD=1"
if [ -e /usr/bin/python3 ]; then if [ -e /usr/bin/python3 ]; then
_options="$_options WITH_PYTHON=1" _options="$_options WITH_PYTHON=1"
depends+=(python) depends+=(python)
makedepends+=(python-setuptools) makedepends+=(python-setuptools python-pip python-build python-wheel)
fi fi
if [ -e /usr/include/janus/plugins/plugin.h ];then if [ -e /usr/include/janus/plugins/plugin.h ];then
depends+=(janus-gateway alsa-lib opus) depends+=(janus-gateway alsa-lib opus)
@@ -28,12 +28,6 @@ if [ -e /usr/include/janus/plugins/plugin.h ];then
fi fi
# LD does not link mmal with this option
# This DOESN'T affect setup.py
LDFLAGS="${LDFLAGS//--as-needed/}"
export LDFLAGS="${LDFLAGS//,,/,}"
build() { build() {
cd "$srcdir" cd "$srcdir"
rm -rf $pkgname-build rm -rf $pkgname-build

View File

@@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=ustreamer PKG_NAME:=ustreamer
PKG_VERSION:=6.4 PKG_VERSION:=6.9
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=Maxim Devaev <mdevaev@gmail.com> PKG_MAINTAINER:=Maxim Devaev <mdevaev@gmail.com>

2
python/MANIFEST.in Normal file
View File

@@ -0,0 +1,2 @@
include setup.py
recursive-include src *.c *h

View File

@@ -1,6 +1,6 @@
-include ../config.mk -include ../config.mk
DESTDIR ?= R_DESTDIR ?=
PREFIX ?= /usr/local PREFIX ?= /usr/local
PY ?= python3 PY ?= python3
@@ -9,12 +9,14 @@ PY ?= python3
# ===== # =====
all: all:
$(info == PY_BUILD ustreamer-*.so) $(info == PY_BUILD ustreamer-*.so)
$(ECHO) $(PY) setup.py build rm -rf root
$(ECHO) $(PY) -m build --skip-dependency-check --no-isolation
$(ECHO) $(PY) -m pip install dist/*.whl --ignore-installed --root=./root
install: install:
$(PY) setup.py install --prefix=$(PREFIX) --root=$(if $(DESTDIR),$(DESTDIR),/) $(PY) -m pip install dist/*.whl --ignore-installed --prefix=$(PREFIX) --root=$(if $(R_DESTDIR),$(R_DESTDIR),/)
clean: clean:
rm -rf build ustreamer.egg-info rm -rf root dist ustreamer.egg-info

View File

@@ -17,7 +17,7 @@ def _find_sources(suffix: str) -> list[str]:
if __name__ == "__main__": if __name__ == "__main__":
setup( setup(
name="ustreamer", name="ustreamer",
version="6.4", version="6.9",
description="uStreamer tools", description="uStreamer tools",
author="Maxim Devaev", author="Maxim Devaev",
author_email="mdevaev@gmail.com", author_email="mdevaev@gmail.com",
@@ -29,7 +29,6 @@ if __name__ == "__main__":
extra_compile_args=["-std=c17", "-D_GNU_SOURCE"], extra_compile_args=["-std=c17", "-D_GNU_SOURCE"],
undef_macros=["NDEBUG"], undef_macros=["NDEBUG"],
sources=_find_sources(".c"), sources=_find_sources(".c"),
depends=_find_sources(".h"),
), ),
], ],
) )

View File

@@ -0,0 +1 @@
../../../src/libs/memsinksh.c

View File

@@ -1,44 +0,0 @@
/*****************************************************************************
# #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
*****************************************************************************/
#pragma once
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
typedef long long sll;
typedef ssize_t sz;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef unsigned uint;
typedef unsigned long long ull;
typedef size_t uz;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef long double ldf;

1
python/src/uslibs/types.h Symbolic link
View File

@@ -0,0 +1 @@
../../../src/libs/types.h

View File

@@ -26,6 +26,7 @@ typedef struct {
double lock_timeout; double lock_timeout;
double wait_timeout; double wait_timeout;
double drop_same_frames; double drop_same_frames;
uz data_size;
int fd; int fd;
us_memsink_shared_s *mem; us_memsink_shared_s *mem;
@@ -37,7 +38,10 @@ typedef struct {
static void _MemsinkObject_destroy_internals(_MemsinkObject *self) { static void _MemsinkObject_destroy_internals(_MemsinkObject *self) {
US_DELETE(self->mem, us_memsink_shared_unmap); if (self->mem != NULL) {
us_memsink_shared_unmap(self->mem, self->data_size);
self->mem = NULL;
}
US_CLOSE_FD(self->fd); US_CLOSE_FD(self->fd);
US_DELETE(self->frame, us_frame_destroy); US_DELETE(self->frame, us_frame_destroy);
} }
@@ -64,13 +68,18 @@ static int _MemsinkObject_init(_MemsinkObject *self, PyObject *args, PyObject *k
SET_DOUBLE(drop_same_frames, >= 0); SET_DOUBLE(drop_same_frames, >= 0);
# undef SET_DOUBLE # undef SET_DOUBLE
if ((self->data_size = us_memsink_calculate_size(self->obj)) == 0) {
PyErr_SetString(PyExc_ValueError, "Invalid memsink object suffix");
return -1;
}
self->frame = us_frame_init(); self->frame = us_frame_init();
if ((self->fd = shm_open(self->obj, O_RDWR, 0)) == -1) { if ((self->fd = shm_open(self->obj, O_RDWR, 0)) == -1) {
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
goto error; goto error;
} }
if ((self->mem = us_memsink_shared_map(self->fd)) == NULL) { if ((self->mem = us_memsink_shared_map(self->fd, self->data_size)) == NULL) {
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
goto error; goto error;
} }
@@ -99,11 +108,11 @@ static PyObject *_MemsinkObject_close(_MemsinkObject *self, PyObject *Py_UNUSED(
static PyObject *_MemsinkObject_enter(_MemsinkObject *self, PyObject *Py_UNUSED(ignored)) { static PyObject *_MemsinkObject_enter(_MemsinkObject *self, PyObject *Py_UNUSED(ignored)) {
Py_INCREF(self); Py_INCREF(self);
return (PyObject *)self; return (PyObject*)self;
} }
static PyObject *_MemsinkObject_exit(_MemsinkObject *self, PyObject *Py_UNUSED(ignored)) { static PyObject *_MemsinkObject_exit(_MemsinkObject *self, PyObject *Py_UNUSED(ignored)) {
return PyObject_CallMethod((PyObject *)self, "close", ""); return PyObject_CallMethod((PyObject*)self, "close", "");
} }
static int _wait_frame(_MemsinkObject *self) { static int _wait_frame(_MemsinkObject *self) {
@@ -139,7 +148,7 @@ static int _wait_frame(_MemsinkObject *self) {
if ( if (
US_FRAME_COMPARE_GEOMETRY(self->mem, self->frame) US_FRAME_COMPARE_GEOMETRY(self->mem, self->frame)
&& (self->frame_ts + self->drop_same_frames > now_ts) && (self->frame_ts + self->drop_same_frames > now_ts)
&& !memcmp(self->frame->data, mem->data, mem->used) && !memcmp(self->frame->data, us_memsink_get_data(mem), mem->used)
) { ) {
self->frame_id = mem->id; self->frame_id = mem->id;
goto retry; goto retry;
@@ -190,7 +199,7 @@ static PyObject *_MemsinkObject_wait_frame(_MemsinkObject *self, PyObject *args,
} }
us_memsink_shared_s *mem = self->mem; us_memsink_shared_s *mem = self->mem;
us_frame_set_data(self->frame, mem->data, mem->used); us_frame_set_data(self->frame, us_memsink_get_data(mem), mem->used);
US_FRAME_COPY_META(self->mem, self->frame); US_FRAME_COPY_META(self->mem, self->frame);
self->frame_id = mem->id; self->frame_id = mem->id;
self->frame_ts = us_get_now_monotonic(); self->frame_ts = us_get_now_monotonic();
@@ -230,7 +239,7 @@ static PyObject *_MemsinkObject_wait_frame(_MemsinkObject *self, PyObject *args,
SET_NUMBER(grab_ts, Double, Float); SET_NUMBER(grab_ts, Double, Float);
SET_NUMBER(encode_begin_ts, Double, Float); SET_NUMBER(encode_begin_ts, Double, Float);
SET_NUMBER(encode_end_ts, Double, Float); SET_NUMBER(encode_end_ts, Double, Float);
SET_VALUE("data", PyBytes_FromStringAndSize((const char *)self->frame->data, self->frame->used)); SET_VALUE("data", PyBytes_FromStringAndSize((const char*)self->frame->data, self->frame->used));
# undef SET_NUMBER # undef SET_NUMBER
# undef SET_VALUE # undef SET_VALUE
@@ -305,7 +314,7 @@ PyMODINIT_FUNC PyInit_ustreamer(void) {
Py_INCREF(&_MemsinkType); Py_INCREF(&_MemsinkType);
if (PyModule_AddObject(module, "Memsink", (PyObject *)&_MemsinkType) < 0) { if (PyModule_AddObject(module, "Memsink", (PyObject*)&_MemsinkType) < 0) {
return NULL; return NULL;
} }

View File

@@ -1,4 +1,4 @@
DESTDIR ?= R_DESTDIR ?=
PREFIX ?= /usr/local PREFIX ?= /usr/local
CC ?= gcc CC ?= gcc
@@ -12,11 +12,11 @@ _DUMP = ustreamer-dump.bin
_V4P = ustreamer-v4p.bin _V4P = ustreamer-v4p.bin
_CFLAGS = -MD -c -std=c17 -Wall -Wextra -D_GNU_SOURCE $(CFLAGS) _CFLAGS = -MD -c -std=c17 -Wall -Wextra -D_GNU_SOURCE $(CFLAGS)
_LDFLAGS = $(LDFLAGS)
_COMMON_LIBS = -lm -ljpeg -pthread -lrt -latomic _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_LIBS = $(_COMMON_LIBS) -levent -levent_pthreads
_USTR_SRCS = $(shell ls \ _USTR_SRCS = $(shell ls \
libs/*.c \ libs/*.c \
ustreamer/*.c \ ustreamer/*.c \
@@ -27,15 +27,14 @@ _USTR_SRCS = $(shell ls \
ustreamer/*.c \ ustreamer/*.c \
) )
_DUMP_LIBS = $(_COMMON_LIBS)
_DUMP_SRCS = $(shell ls \ _DUMP_SRCS = $(shell ls \
libs/*.c \ libs/*.c \
dump/*.c \ dump/*.c \
) )
_V4P_LIBS = $(_COMMON_LIBS)
_V4P_SRCS = $(shell ls \ _V4P_SRCS = $(shell ls \
libs/*.c \ libs/*.c \
libs/drm/*.c \
v4p/*.c \ v4p/*.c \
) )
@@ -52,16 +51,16 @@ endef
ifneq ($(call optbool,$(WITH_GPIO)),) ifneq ($(call optbool,$(WITH_GPIO)),)
_USTR_LIBS += -lgpiod
override _CFLAGS += -DWITH_GPIO $(shell pkg-config --atleast-version=2 libgpiod 2> /dev/null && echo -DHAVE_GPIOD2) override _CFLAGS += -DWITH_GPIO $(shell pkg-config --atleast-version=2 libgpiod 2> /dev/null && echo -DHAVE_GPIOD2)
_USTR_SRCS += $(shell ls ustreamer/gpio/*.c) override _USTR_LDFLAGS += -lgpiod
override _USTR_SRCS += $(shell ls ustreamer/gpio/*.c)
endif endif
ifneq ($(call optbool,$(WITH_SYSTEMD)),) ifneq ($(call optbool,$(WITH_SYSTEMD)),)
_USTR_LIBS += -lsystemd
override _CFLAGS += -DWITH_SYSTEMD override _CFLAGS += -DWITH_SYSTEMD
_USTR_SRCS += $(shell ls ustreamer/http/systemd/*.c) override _USTR_LDFLAGS += -lsystemd
override _USTR_SRCS += $(shell ls ustreamer/http/systemd/*.c)
endif endif
@@ -73,10 +72,10 @@ 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)
_USTR_LIBS += -lbsd
endif
override _CFLAGS += -DWITH_SETPROCTITLE override _CFLAGS += -DWITH_SETPROCTITLE
ifeq ($(shell uname -s | tr A-Z a-z),linux)
override _USTR_LDFLAGS += -lbsd
endif
endif endif
@@ -84,8 +83,10 @@ WITH_V4P ?= 0
ifneq ($(call optbool,$(WITH_V4P)),) ifneq ($(call optbool,$(WITH_V4P)),)
override _TARGETS += $(_V4P) override _TARGETS += $(_V4P)
override _OBJS += $(_V4P_SRCS:%.c=$(_BUILD)/%.o) override _OBJS += $(_V4P_SRCS:%.c=$(_BUILD)/%.o)
override _CFLAGS += $(shell pkg-config --cflags libdrm) override _CFLAGS += -DWITH_V4P $(shell pkg-config --cflags libdrm)
_V4P_LDFLAGS = $(shell pkg-config --libs 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)
endif endif
@@ -94,29 +95,31 @@ all: $(_TARGETS)
install: all install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin mkdir -p $(R_DESTDIR)$(PREFIX)/bin
for i in $(subst .bin,,$(_TARGETS)); do \ for i in $(subst .bin,,$(_TARGETS)); do \
install -m755 $$i.bin $(DESTDIR)$(PREFIX)/bin/$$i; \ install -m755 $$i.bin $(R_DESTDIR)$(PREFIX)/bin/$$i; \
done done
install-strip: install install-strip: install
for i in $(subst .bin,,$(_TARGETS)); do strip $(DESTDIR)$(PREFIX)/bin/$$i; done for i in $(subst .bin,,$(_TARGETS)); do \
strip $(R_DESTDIR)$(PREFIX)/bin/$$i; \
done
$(_USTR): $(_USTR_SRCS:%.c=$(_BUILD)/%.o) $(_USTR): $(_USTR_SRCS:%.c=$(_BUILD)/%.o)
$(info == LD $@) $(info == LD $@)
$(ECHO) $(CC) $^ -o $@ $(_LDFLAGS) $(_USTR_LIBS) $(ECHO) $(CC) $^ -o $@ $(_USTR_LDFLAGS)
$(_DUMP): $(_DUMP_SRCS:%.c=$(_BUILD)/%.o) $(_DUMP): $(_DUMP_SRCS:%.c=$(_BUILD)/%.o)
$(info == LD $@) $(info == LD $@)
$(ECHO) $(CC) $^ -o $@ $(_LDFLAGS) $(_DUMP_LIBS) $(ECHO) $(CC) $^ -o $@ $(_DUMP_LDFLAGS)
$(_V4P): $(_V4P_SRCS:%.c=$(_BUILD)/%.o) $(_V4P): $(_V4P_SRCS:%.c=$(_BUILD)/%.o)
$(info == LD $@) $(info == LD $@)
$(ECHO) $(CC) $^ -o $@ $(_LDFLAGS) $(_V4P_LDFLAGS) $(_V4P_LIBS) $(ECHO) $(CC) $^ -o $@ $(_V4P_LDFLAGS)
$(_BUILD)/%.o: %.c $(_BUILD)/%.o: %.c

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -47,7 +47,7 @@ us_output_file_s *us_output_file_init(const char *path, bool json) {
} }
void us_output_file_write(void *v_output, const us_frame_s *frame) { void us_output_file_write(void *v_output, const us_frame_s *frame) {
us_output_file_s *output = (us_output_file_s *)v_output; us_output_file_s *output = v_output;
if (output->json) { if (output->json) {
us_base64_encode(frame->data, frame->used, &output->base64_data, &output->base64_allocated); us_base64_encode(frame->data, frame->used, &output->base64_data, &output->base64_allocated);
fprintf(output->fp, fprintf(output->fp,
@@ -66,7 +66,7 @@ void us_output_file_write(void *v_output, const us_frame_s *frame) {
} }
void us_output_file_destroy(void *v_output) { void us_output_file_destroy(void *v_output) {
us_output_file_s *output = (us_output_file_s *)v_output; us_output_file_s *output = v_output;
US_DELETE(output->base64_data, free); US_DELETE(output->base64_data, free);
if (output->fp && output->fp != stdout) { if (output->fp && output->fp != stdout) {
if (fclose(output->fp) < 0) { if (fclose(output->fp) < 0) {

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -182,7 +182,7 @@ int main(int argc, char *argv[]) {
_output_context_s ctx = {0}; _output_context_s ctx = {0};
if (output_path && output_path[0] != '\0') { if (output_path && output_path[0] != '\0') {
if ((ctx.v_output = (void *)us_output_file_init(output_path, output_json)) == NULL) { if ((ctx.v_output = (void*)us_output_file_init(output_path, output_json)) == NULL) {
return 1; return 1;
} }
ctx.write = us_output_file_write; ctx.write = us_output_file_write;
@@ -296,7 +296,7 @@ static void _help(FILE *fp) {
SAY("\nuStreamer-dump - Dump uStreamer's memory sink to file"); SAY("\nuStreamer-dump - Dump uStreamer's memory sink to file");
SAY("═════════════════════════════════════════════════════"); SAY("═════════════════════════════════════════════════════");
SAY("Version: %s; license: GPLv3", US_VERSION); SAY("Version: %s; license: GPLv3", US_VERSION);
SAY("Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com>\n"); SAY("Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com>\n");
SAY("Example:"); SAY("Example:");
SAY("════════"); SAY("════════");
SAY(" ustreamer-dump --sink test --output - \\"); SAY(" ustreamer-dump --sink test --output - \\");

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -49,7 +49,7 @@ typedef struct {
int dma_fd; int dma_fd;
bool grabbed; bool grabbed;
atomic_int refs; atomic_int refs;
} us_hw_buffer_s; } us_capture_hwbuf_s;
typedef struct { typedef struct {
int fd; int fd;
@@ -62,13 +62,13 @@ typedef struct {
uint jpeg_quality; uint jpeg_quality;
uz raw_size; uz raw_size;
uint n_bufs; uint n_bufs;
us_hw_buffer_s *hw_bufs; us_capture_hwbuf_s *bufs;
bool dma; bool dma;
enum v4l2_buf_type capture_type; enum v4l2_buf_type capture_type;
bool capture_mplane; bool capture_mplane;
bool streamon; bool streamon;
int open_error_reported; int open_error_reported;
} us_device_runtime_s; } us_capture_runtime_s;
typedef enum { typedef enum {
CTL_MODE_NONE = 0, CTL_MODE_NONE = 0,
@@ -104,6 +104,8 @@ typedef struct {
uint width; uint width;
uint height; uint height;
uint format; uint format;
bool format_swap_rgb;
uint jpeg_quality; uint jpeg_quality;
v4l2_std_id standard; v4l2_std_id standard;
enum v4l2_memory io_method; enum v4l2_memory io_method;
@@ -116,22 +118,22 @@ typedef struct {
bool persistent; bool persistent;
uint timeout; uint timeout;
us_controls_s ctl; us_controls_s ctl;
us_device_runtime_s *run; us_capture_runtime_s *run;
} us_device_s; } us_capture_s;
us_device_s *us_device_init(void); us_capture_s *us_capture_init(void);
void us_device_destroy(us_device_s *dev); void us_capture_destroy(us_capture_s *cap);
int us_device_parse_format(const char *str); int us_capture_parse_format(const char *str);
int us_device_parse_standard(const char *str); int us_capture_parse_standard(const char *str);
int us_device_parse_io_method(const char *str); int us_capture_parse_io_method(const char *str);
int us_device_open(us_device_s *dev); int us_capture_open(us_capture_s *cap);
void us_device_close(us_device_s *dev); void us_capture_close(us_capture_s *cap);
int us_device_grab_buffer(us_device_s *dev, us_hw_buffer_s **hw); int us_capture_hwbuf_grab(us_capture_s *cap, us_capture_hwbuf_s **hw);
int us_device_release_buffer(us_device_s *dev, us_hw_buffer_s *hw); int us_capture_hwbuf_release(us_capture_s *cap, us_capture_hwbuf_s *hw);
void us_device_buffer_incref(us_hw_buffer_s *hw); void us_capture_hwbuf_incref(us_capture_hwbuf_s *hw);
void us_device_buffer_decref(us_hw_buffer_s *hw); void us_capture_hwbuf_decref(us_capture_hwbuf_s *hw);

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -26,7 +26,7 @@
#define US_VERSION_MAJOR 6 #define US_VERSION_MAJOR 6
#define US_VERSION_MINOR 4 #define US_VERSION_MINOR 9
#define US_MAKE_VERSION2(_major, _minor) #_major "." #_minor #define US_MAKE_VERSION2(_major, _minor) #_major "." #_minor
#define US_MAKE_VERSION1(_major, _minor) US_MAKE_VERSION2(_major, _minor) #define US_MAKE_VERSION1(_major, _minor) US_MAKE_VERSION2(_major, _minor)

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -37,17 +37,18 @@
#include <drm_fourcc.h> #include <drm_fourcc.h>
#include <libdrm/drm.h> #include <libdrm/drm.h>
#include "../libs/types.h" #include "../types.h"
#include "../libs/tools.h" #include "../tools.h"
#include "../libs/logging.h" #include "../logging.h"
#include "../libs/frame.h" #include "../frame.h"
#include "../libs/frametext.h" #include "../frametext.h"
#include "../capture.h"
static void _drm_vsync_callback(int fd, uint n_frame, uint sec, uint usec, void *v_buf); static void _drm_vsync_callback(int fd, uint n_frame, uint sec, uint usec, void *v_buf);
static int _drm_check_status(us_drm_s *drm); static int _drm_check_status(us_drm_s *drm);
static void _drm_ensure_dpms_power(us_drm_s *drm, bool on); static void _drm_ensure_dpms_power(us_drm_s *drm, bool on);
static int _drm_init_buffers(us_drm_s *drm, const us_device_s *dev); static int _drm_init_buffers(us_drm_s *drm, const us_capture_s *cap);
static int _drm_find_sink(us_drm_s *drm, uint width, uint height, float hz); static int _drm_find_sink(us_drm_s *drm, uint width, uint height, float hz);
static drmModeModeInfo *_find_best_mode(drmModeConnector *conn, uint width, uint height, float hz); static drmModeModeInfo *_find_best_mode(drmModeConnector *conn, uint width, uint height, float hz);
@@ -57,11 +58,11 @@ static const char *_connector_type_to_string(u32 type);
static float _get_refresh_rate(const drmModeModeInfo *mode); static float _get_refresh_rate(const drmModeModeInfo *mode);
#define _D_LOG_ERROR(x_msg, ...) US_LOG_ERROR("DRM: " x_msg, ##__VA_ARGS__) #define _LOG_ERROR(x_msg, ...) US_LOG_ERROR("DRM: " x_msg, ##__VA_ARGS__)
#define _D_LOG_PERROR(x_msg, ...) US_LOG_PERROR("DRM: " x_msg, ##__VA_ARGS__) #define _LOG_PERROR(x_msg, ...) US_LOG_PERROR("DRM: " x_msg, ##__VA_ARGS__)
#define _D_LOG_INFO(x_msg, ...) US_LOG_INFO("DRM: " x_msg, ##__VA_ARGS__) #define _LOG_INFO(x_msg, ...) US_LOG_INFO("DRM: " x_msg, ##__VA_ARGS__)
#define _D_LOG_VERBOSE(x_msg, ...) US_LOG_VERBOSE("DRM: " x_msg, ##__VA_ARGS__) #define _LOG_VERBOSE(x_msg, ...) US_LOG_VERBOSE("DRM: " x_msg, ##__VA_ARGS__)
#define _D_LOG_DEBUG(x_msg, ...) US_LOG_DEBUG("DRM: " x_msg, ##__VA_ARGS__) #define _LOG_DEBUG(x_msg, ...) US_LOG_DEBUG("DRM: " x_msg, ##__VA_ARGS__)
us_drm_s *us_drm_init(void) { us_drm_s *us_drm_init(void) {
@@ -78,7 +79,7 @@ us_drm_s *us_drm_init(void) {
US_CALLOC(drm, 1); US_CALLOC(drm, 1);
// drm->path = "/dev/dri/card0"; // drm->path = "/dev/dri/card0";
drm->path = "/dev/dri/by-path/platform-gpu-card"; drm->path = "/dev/dri/by-path/platform-gpu-card";
drm->port = "HDMI-A-1"; drm->port = "HDMI-A-2"; // OUT2 on PiKVM V4 Plus
drm->timeout = 5; drm->timeout = 5;
drm->run = run; drm->run = run;
return drm; return drm;
@@ -90,7 +91,7 @@ void us_drm_destroy(us_drm_s *drm) {
US_DELETE(drm, free); // cppcheck-suppress uselessAssignmentPtrArg US_DELETE(drm, free); // cppcheck-suppress uselessAssignmentPtrArg
} }
int us_drm_open(us_drm_s *drm, const us_device_s *dev) { int us_drm_open(us_drm_s *drm, const us_capture_s *cap) {
us_drm_runtime_s *const run = drm->run; us_drm_runtime_s *const run = drm->run;
assert(run->fd < 0); assert(run->fd < 0);
@@ -101,33 +102,33 @@ int us_drm_open(us_drm_s *drm, const us_device_s *dev) {
default: goto error; default: goto error;
} }
_D_LOG_INFO("Configuring DRM device for %s ...", (dev == NULL ? "STUB" : "DMA")); _LOG_INFO("Configuring DRM device for %s ...", (cap == NULL ? "STUB" : "DMA"));
if ((run->fd = open(drm->path, O_RDWR | O_CLOEXEC | O_NONBLOCK)) < 0) { if ((run->fd = open(drm->path, O_RDWR | O_CLOEXEC | O_NONBLOCK)) < 0) {
_D_LOG_PERROR("Can't open DRM device"); _LOG_PERROR("Can't open DRM device");
goto error; goto error;
} }
_D_LOG_DEBUG("DRM device fd=%d opened", run->fd); _LOG_DEBUG("DRM device fd=%d opened", run->fd);
int stub = 0; // Open the real device with DMA int stub = 0; // Open the real device with DMA
if (dev == NULL) { if (cap == NULL) {
stub = US_DRM_STUB_USER; stub = US_DRM_STUB_USER;
} else if (dev->run->format != V4L2_PIX_FMT_RGB24) { } else if (cap->run->format != V4L2_PIX_FMT_RGB24 && cap->run->format != V4L2_PIX_FMT_BGR24) {
stub = US_DRM_STUB_BAD_FORMAT; stub = US_DRM_STUB_BAD_FORMAT;
char fourcc_str[8]; char fourcc_str[8];
us_fourcc_to_string(dev->run->format, fourcc_str, 8); us_fourcc_to_string(cap->run->format, fourcc_str, 8);
_D_LOG_ERROR("Input format %s is not supported, forcing to STUB ...", fourcc_str); _LOG_ERROR("Input format %s is not supported, forcing to STUB ...", fourcc_str);
} }
# define CHECK_CAP(x_cap) { \ # define CHECK_CAP(x_cap) { \
_D_LOG_DEBUG("Checking %s ...", #x_cap); \ _LOG_DEBUG("Checking %s ...", #x_cap); \
u64 m_check; \ u64 m_check; \
if (drmGetCap(run->fd, x_cap, &m_check) < 0) { \ if (drmGetCap(run->fd, x_cap, &m_check) < 0) { \
_D_LOG_PERROR("Can't check " #x_cap); \ _LOG_PERROR("Can't check " #x_cap); \
goto error; \ goto error; \
} \ } \
if (!m_check) { \ if (!m_check) { \
_D_LOG_ERROR(#x_cap " is not supported"); \ _LOG_ERROR(#x_cap " is not supported"); \
goto error; \ goto error; \
} \ } \
} }
@@ -137,9 +138,9 @@ int us_drm_open(us_drm_s *drm, const us_device_s *dev) {
} }
# undef CHECK_CAP # undef CHECK_CAP
const uint width = (stub > 0 ? 0 : dev->run->width); const uint width = (stub > 0 ? 0 : cap->run->width);
const uint height = (stub > 0 ? 0 : dev->run->height); const uint height = (stub > 0 ? 0 : cap->run->height);
const uint hz = (stub > 0 ? 0 : dev->run->hz); const uint hz = (stub > 0 ? 0 : cap->run->hz);
switch (_drm_find_sink(drm, width, height, hz)) { switch (_drm_find_sink(drm, width, height, hz)) {
case 0: break; case 0: break;
case -2: goto unplugged; case -2: goto unplugged;
@@ -148,24 +149,24 @@ int us_drm_open(us_drm_s *drm, const us_device_s *dev) {
if ((stub == 0) && (width != run->mode.hdisplay || height < run->mode.vdisplay)) { if ((stub == 0) && (width != run->mode.hdisplay || height < run->mode.vdisplay)) {
// We'll try to show something instead of nothing if height != vdisplay // We'll try to show something instead of nothing if height != vdisplay
stub = US_DRM_STUB_BAD_RESOLUTION; stub = US_DRM_STUB_BAD_RESOLUTION;
_D_LOG_ERROR("There is no appropriate modes for the capture, forcing to STUB ..."); _LOG_ERROR("There is no appropriate modes for the capture, forcing to STUB ...");
} }
if (_drm_init_buffers(drm, (stub > 0 ? NULL : dev)) < 0) { if (_drm_init_buffers(drm, (stub > 0 ? NULL : cap)) < 0) {
goto error; goto error;
} }
run->saved_crtc = drmModeGetCrtc(run->fd, run->crtc_id); run->saved_crtc = drmModeGetCrtc(run->fd, run->crtc_id);
_D_LOG_DEBUG("Setting up CRTC ..."); _LOG_DEBUG("Setting up CRTC ...");
if (drmModeSetCrtc(run->fd, run->crtc_id, run->bufs[0].id, 0, 0, &run->conn_id, 1, &run->mode) < 0) { if (drmModeSetCrtc(run->fd, run->crtc_id, run->bufs[0].id, 0, 0, &run->conn_id, 1, &run->mode) < 0) {
_D_LOG_PERROR("Can't set CRTC"); _LOG_PERROR("Can't set CRTC");
goto error; goto error;
} }
run->opened_for_stub = (stub > 0); run->opened_for_stub = (stub > 0);
run->exposing_dma_fd = -1; run->exposing_dma_fd = -1;
run->unplugged_reported = false; run->unplugged_reported = false;
_D_LOG_INFO("Opened for %s ...", (run->opened_for_stub ? "STUB" : "DMA")); _LOG_INFO("Opened for %s ...", (run->opened_for_stub ? "STUB" : "DMA"));
return stub; return stub;
error: error:
@@ -174,7 +175,7 @@ error:
unplugged: unplugged:
if (!run->unplugged_reported) { if (!run->unplugged_reported) {
_D_LOG_ERROR("Display is not plugged"); _LOG_ERROR("Display is not plugged");
run->unplugged_reported = true; run->unplugged_reported = true;
} }
us_drm_close(drm); us_drm_close(drm);
@@ -193,33 +194,33 @@ void us_drm_close(us_drm_s *drm) {
} }
if (run->saved_crtc != NULL) { if (run->saved_crtc != NULL) {
_D_LOG_DEBUG("Restoring CRTC ..."); _LOG_DEBUG("Restoring CRTC ...");
if (drmModeSetCrtc(run->fd, if (drmModeSetCrtc(run->fd,
run->saved_crtc->crtc_id, run->saved_crtc->buffer_id, run->saved_crtc->crtc_id, run->saved_crtc->buffer_id,
run->saved_crtc->x, run->saved_crtc->y, run->saved_crtc->x, run->saved_crtc->y,
&run->conn_id, 1, &run->saved_crtc->mode &run->conn_id, 1, &run->saved_crtc->mode
) < 0 && errno != ENOENT) { ) < 0 && errno != ENOENT) {
_D_LOG_PERROR("Can't restore CRTC"); _LOG_PERROR("Can't restore CRTC");
} }
drmModeFreeCrtc(run->saved_crtc); drmModeFreeCrtc(run->saved_crtc);
run->saved_crtc = NULL; run->saved_crtc = NULL;
} }
if (run->bufs != NULL) { if (run->bufs != NULL) {
_D_LOG_DEBUG("Releasing buffers ..."); _LOG_DEBUG("Releasing buffers ...");
for (uint n_buf = 0; n_buf < run->n_bufs; ++n_buf) { for (uint n_buf = 0; n_buf < run->n_bufs; ++n_buf) {
us_drm_buffer_s *const buf = &run->bufs[n_buf]; us_drm_buffer_s *const buf = &run->bufs[n_buf];
if (buf->fb_added && drmModeRmFB(run->fd, buf->id) < 0) { if (buf->fb_added && drmModeRmFB(run->fd, buf->id) < 0) {
_D_LOG_PERROR("Can't remove buffer=%u", n_buf); _LOG_PERROR("Can't remove buffer=%u", n_buf);
} }
if (buf->dumb_created) { if (buf->dumb_created) {
struct drm_mode_destroy_dumb destroy = {.handle = buf->handle}; struct drm_mode_destroy_dumb destroy = {.handle = buf->handle};
if (drmIoctl(run->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy) < 0) { if (drmIoctl(run->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy) < 0) {
_D_LOG_PERROR("Can't destroy dumb buffer=%u", n_buf); _LOG_PERROR("Can't destroy dumb buffer=%u", n_buf);
} }
} }
if (buf->data != NULL && munmap(buf->data, buf->allocated)) { if (buf->data != NULL && munmap(buf->data, buf->allocated)) {
_D_LOG_PERROR("Can't unmap buffer=%u", n_buf); _LOG_PERROR("Can't unmap buffer=%u", n_buf);
} }
} }
US_DELETE(run->bufs, free); US_DELETE(run->bufs, free);
@@ -236,7 +237,7 @@ void us_drm_close(us_drm_s *drm) {
run->stub_n_buf = 0; run->stub_n_buf = 0;
if (say) { if (say) {
_D_LOG_INFO("Closed"); _LOG_INFO("Closed");
} }
} }
@@ -275,13 +276,13 @@ int us_drm_wait_for_vsync(us_drm_s *drm) {
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(run->fd, &fds); FD_SET(run->fd, &fds);
_D_LOG_DEBUG("Calling select() for VSync ..."); _LOG_DEBUG("Calling select() for VSync ...");
const int result = select(run->fd + 1, &fds, NULL, NULL, &timeout); const int result = select(run->fd + 1, &fds, NULL, NULL, &timeout);
if (result < 0) { if (result < 0) {
_D_LOG_PERROR("Can't select(%d) device for VSync", run->fd); _LOG_PERROR("Can't select(%d) device for VSync", run->fd);
return -1; return -1;
} else if (result == 0) { } else if (result == 0) {
_D_LOG_ERROR("Device timeout while waiting VSync"); _LOG_ERROR("Device timeout while waiting VSync");
return -1; return -1;
} }
@@ -289,9 +290,9 @@ int us_drm_wait_for_vsync(us_drm_s *drm) {
.version = DRM_EVENT_CONTEXT_VERSION, .version = DRM_EVENT_CONTEXT_VERSION,
.page_flip_handler = _drm_vsync_callback, .page_flip_handler = _drm_vsync_callback,
}; };
_D_LOG_DEBUG("Handling DRM event (maybe VSync) ..."); _LOG_DEBUG("Handling DRM event (maybe VSync) ...");
if (drmHandleEvent(run->fd, &ctx) < 0) { if (drmHandleEvent(run->fd, &ctx) < 0) {
_D_LOG_PERROR("Can't handle DRM event"); _LOG_PERROR("Can't handle DRM event");
return -1; return -1;
} }
return 0; return 0;
@@ -305,10 +306,10 @@ static void _drm_vsync_callback(int fd, uint n_frame, uint sec, uint usec, void
us_drm_buffer_s *const buf = v_buf; us_drm_buffer_s *const buf = v_buf;
*buf->ctx.has_vsync = true; *buf->ctx.has_vsync = true;
*buf->ctx.exposing_dma_fd = -1; *buf->ctx.exposing_dma_fd = -1;
_D_LOG_DEBUG("Got VSync signal"); _LOG_DEBUG("Got VSync signal");
} }
int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_device_s *dev) { int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_capture_s *cap) {
us_drm_runtime_s *const run = drm->run; us_drm_runtime_s *const run = drm->run;
assert(run->fd >= 0); assert(run->fd >= 0);
@@ -324,24 +325,19 @@ int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_device_s *dev
# define DRAW_MSG(x_msg) us_frametext_draw(run->ft, (x_msg), run->mode.hdisplay, run->mode.vdisplay) # define DRAW_MSG(x_msg) us_frametext_draw(run->ft, (x_msg), run->mode.hdisplay, run->mode.vdisplay)
switch (stub) { switch (stub) {
case US_DRM_STUB_BAD_RESOLUTION: { case US_DRM_STUB_BAD_RESOLUTION: {
assert(dev != NULL); assert(cap != NULL);
char msg[1024]; char msg[1024];
US_SNPRINTF(msg, 1023, US_SNPRINTF(msg, 1023,
"=== PiKVM ===" "=== PiKVM ==="
"\n \n< UNSUPPORTED RESOLUTION >" "\n \n< UNSUPPORTED RESOLUTION >"
"\n \n< %ux%up%.02f >" "\n \n< %ux%up%.02f >"
"\n \nby this display", "\n \nby this display",
dev->run->width, dev->run->height, dev->run->hz); cap->run->width, cap->run->height, cap->run->hz);
DRAW_MSG(msg); DRAW_MSG(msg);
break; break;
}; };
case US_DRM_STUB_BAD_FORMAT: case US_DRM_STUB_BAD_FORMAT:
DRAW_MSG( DRAW_MSG("=== PiKVM ===\n \n< UNSUPPORTED CAPTURE FORMAT >");
"=== PiKVM ==="
"\n \n< UNSUPPORTED CAPTURE FORMAT >"
"\n \nIt shouldn't happen ever."
"\n \nPlease check the logs and report a bug:"
"\n \n- https://github.com/pikvm/pikvm -");
break; break;
case US_DRM_STUB_NO_SIGNAL: case US_DRM_STUB_NO_SIGNAL:
DRAW_MSG("=== PiKVM ===\n \n< NO SIGNAL >"); DRAW_MSG("=== PiKVM ===\n \n< NO SIGNAL >");
@@ -359,24 +355,24 @@ int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_device_s *dev
run->has_vsync = false; run->has_vsync = false;
_D_LOG_DEBUG("Copying STUB frame ...") _LOG_DEBUG("Copying STUB frame ...")
memcpy(buf->data, run->ft->frame->data, US_MIN(run->ft->frame->used, buf->allocated)); memcpy(buf->data, run->ft->frame->data, US_MIN(run->ft->frame->used, buf->allocated));
_D_LOG_DEBUG("Exposing STUB framebuffer n_buf=%u ...", run->stub_n_buf); _LOG_DEBUG("Exposing STUB framebuffer n_buf=%u ...", run->stub_n_buf);
const int retval = drmModePageFlip( const int retval = drmModePageFlip(
run->fd, run->crtc_id, buf->id, run->fd, run->crtc_id, buf->id,
DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_PAGE_FLIP_ASYNC, DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_PAGE_FLIP_ASYNC,
buf); buf);
if (retval < 0) { if (retval < 0) {
_D_LOG_PERROR("Can't expose STUB framebuffer n_buf=%u ...", run->stub_n_buf); _LOG_PERROR("Can't expose STUB framebuffer n_buf=%u ...", run->stub_n_buf);
} }
_D_LOG_DEBUG("Exposed STUB framebuffer n_buf=%u", run->stub_n_buf); _LOG_DEBUG("Exposed STUB framebuffer n_buf=%u", run->stub_n_buf);
run->stub_n_buf = (run->stub_n_buf + 1) % run->n_bufs; run->stub_n_buf = (run->stub_n_buf + 1) % run->n_bufs;
return retval; return retval;
} }
int us_drm_expose_dma(us_drm_s *drm, const us_hw_buffer_s *hw) { int us_drm_expose_dma(us_drm_s *drm, const us_capture_hwbuf_s *hw) {
us_drm_runtime_s *const run = drm->run; us_drm_runtime_s *const run = drm->run;
us_drm_buffer_s *const buf = &run->bufs[hw->buf.index]; us_drm_buffer_s *const buf = &run->bufs[hw->buf.index];
@@ -392,15 +388,15 @@ int us_drm_expose_dma(us_drm_s *drm, const us_hw_buffer_s *hw) {
run->has_vsync = false; run->has_vsync = false;
_D_LOG_DEBUG("Exposing DMA framebuffer n_buf=%u ...", hw->buf.index); _LOG_DEBUG("Exposing DMA framebuffer n_buf=%u ...", hw->buf.index);
const int retval = drmModePageFlip( const int retval = drmModePageFlip(
run->fd, run->crtc_id, buf->id, run->fd, run->crtc_id, buf->id,
DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_PAGE_FLIP_ASYNC, DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_PAGE_FLIP_ASYNC,
buf); buf);
if (retval < 0) { if (retval < 0) {
_D_LOG_PERROR("Can't expose DMA framebuffer n_buf=%u ...", run->stub_n_buf); _LOG_PERROR("Can't expose DMA framebuffer n_buf=%u ...", run->stub_n_buf);
} }
_D_LOG_DEBUG("Exposed DMA framebuffer n_buf=%u", run->stub_n_buf); _LOG_DEBUG("Exposed DMA framebuffer n_buf=%u", run->stub_n_buf);
run->exposing_dma_fd = hw->dma_fd; run->exposing_dma_fd = hw->dma_fd;
return retval; return retval;
} }
@@ -409,35 +405,35 @@ static int _drm_check_status(us_drm_s *drm) {
us_drm_runtime_s *run = drm->run; us_drm_runtime_s *run = drm->run;
if (run->status_fd < 0) { if (run->status_fd < 0) {
_D_LOG_DEBUG("Trying to find status file ..."); _LOG_DEBUG("Trying to find status file ...");
struct stat st; struct stat st;
if (stat(drm->path, &st) < 0) { if (stat(drm->path, &st) < 0) {
_D_LOG_PERROR("Can't stat() DRM device"); _LOG_PERROR("Can't stat() DRM device");
goto error; goto error;
} }
const uint mi = minor(st.st_rdev); const uint mi = minor(st.st_rdev);
_D_LOG_DEBUG("DRM device minor(st_rdev)=%u", mi); _LOG_DEBUG("DRM device minor(st_rdev)=%u", mi);
char path[128]; char path[128];
US_SNPRINTF(path, 127, "/sys/class/drm/card%u-%s/status", mi, drm->port); US_SNPRINTF(path, 127, "/sys/class/drm/card%u-%s/status", mi, drm->port);
_D_LOG_DEBUG("Opening status file %s ...", path); _LOG_DEBUG("Opening status file %s ...", path);
if ((run->status_fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) { if ((run->status_fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) {
_D_LOG_PERROR("Can't open status file: %s", path); _LOG_PERROR("Can't open status file: %s", path);
goto error; goto error;
} }
_D_LOG_DEBUG("Status file fd=%d opened", run->status_fd); _LOG_DEBUG("Status file fd=%d opened", run->status_fd);
} }
char status_ch; char status_ch;
if (read(run->status_fd, &status_ch, 1) != 1) { if (read(run->status_fd, &status_ch, 1) != 1) {
_D_LOG_PERROR("Can't read status file"); _LOG_PERROR("Can't read status file");
goto error; goto error;
} }
if (lseek(run->status_fd, 0, SEEK_SET) != 0) { if (lseek(run->status_fd, 0, SEEK_SET) != 0) {
_D_LOG_PERROR("Can't rewind status file"); _LOG_PERROR("Can't rewind status file");
goto error; goto error;
} }
_D_LOG_DEBUG("Current display status: %c", status_ch); _LOG_DEBUG("Current display status: %c", status_ch);
return (status_ch == 'd' ? -2 : 0); return (status_ch == 'd' ? -2 : 0);
error: error:
@@ -448,24 +444,26 @@ error:
static void _drm_ensure_dpms_power(us_drm_s *drm, bool on) { static void _drm_ensure_dpms_power(us_drm_s *drm, bool on) {
us_drm_runtime_s *const run = drm->run; us_drm_runtime_s *const run = drm->run;
if (run->dpms_id > 0 && run->dpms_state != (int)on) { if (run->dpms_id > 0 && run->dpms_state != (int)on) {
_D_LOG_INFO("Changing DPMS power mode: %d -> %u ...", run->dpms_state, on); _LOG_INFO("Changing DPMS power mode: %d -> %u ...", run->dpms_state, on);
if (drmModeConnectorSetProperty( if (drmModeConnectorSetProperty(
run->fd, run->conn_id, run->dpms_id, run->fd, run->conn_id, run->dpms_id,
(on ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF) (on ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF)
) < 0) { ) < 0) {
_D_LOG_PERROR("Can't set DPMS power=%u (ignored)", on); _LOG_PERROR("Can't set DPMS power=%u (ignored)", on);
} }
} }
run->dpms_state = (int)on; run->dpms_state = (int)on;
} }
static int _drm_init_buffers(us_drm_s *drm, const us_device_s *dev) { static int _drm_init_buffers(us_drm_s *drm, const us_capture_s *cap) {
us_drm_runtime_s *const run = drm->run; us_drm_runtime_s *const run = drm->run;
const uint n_bufs = (dev == NULL ? 4 : dev->run->n_bufs); const uint n_bufs = (cap == NULL ? 4 : cap->run->n_bufs);
const char *name = (dev == NULL ? "STUB" : "DMA"); const char *name = (cap == NULL ? "STUB" : "DMA");
_D_LOG_DEBUG("Initializing %u %s buffers ...", n_bufs, name); _LOG_DEBUG("Initializing %u %s buffers ...", n_bufs, name);
uint format = DRM_FORMAT_RGB888;
US_CALLOC(run->bufs, n_bufs); US_CALLOC(run->bufs, n_bufs);
for (run->n_bufs = 0; run->n_bufs < n_bufs; ++run->n_bufs) { for (run->n_bufs = 0; run->n_bufs < n_bufs; ++run->n_bufs) {
@@ -479,14 +477,14 @@ static int _drm_init_buffers(us_drm_s *drm, const us_device_s *dev) {
u32 strides[4] = {0}; u32 strides[4] = {0};
u32 offsets[4] = {0}; u32 offsets[4] = {0};
if (dev == NULL) { if (cap == NULL) {
struct drm_mode_create_dumb create = { struct drm_mode_create_dumb create = {
.width = run->mode.hdisplay, .width = run->mode.hdisplay,
.height = run->mode.vdisplay, .height = run->mode.vdisplay,
.bpp = 24, .bpp = 24,
}; };
if (drmIoctl(run->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create) < 0) { if (drmIoctl(run->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create) < 0) {
_D_LOG_PERROR("Can't create %s buffer=%u", name, n_buf); _LOG_PERROR("Can't create %s buffer=%u", name, n_buf);
return -1; return -1;
} }
buf->handle = create.handle; buf->handle = create.handle;
@@ -494,7 +492,7 @@ static int _drm_init_buffers(us_drm_s *drm, const us_device_s *dev) {
struct drm_mode_map_dumb map = {.handle = create.handle}; struct drm_mode_map_dumb map = {.handle = create.handle};
if (drmIoctl(run->fd, DRM_IOCTL_MODE_MAP_DUMB, &map) < 0) { if (drmIoctl(run->fd, DRM_IOCTL_MODE_MAP_DUMB, &map) < 0) {
_D_LOG_PERROR("Can't prepare dumb buffer=%u to mapping", n_buf); _LOG_PERROR("Can't prepare dumb buffer=%u to mapping", n_buf);
return -1; return -1;
} }
if ((buf->data = mmap( if ((buf->data = mmap(
@@ -502,7 +500,7 @@ static int _drm_init_buffers(us_drm_s *drm, const us_device_s *dev) {
PROT_READ | PROT_WRITE, MAP_SHARED, PROT_READ | PROT_WRITE, MAP_SHARED,
run->fd, map.offset run->fd, map.offset
)) == MAP_FAILED) { )) == MAP_FAILED) {
_D_LOG_PERROR("Can't map buffer=%u", n_buf); _LOG_PERROR("Can't map buffer=%u", n_buf);
return -1; return -1;
} }
memset(buf->data, 0, create.size); memset(buf->data, 0, create.size);
@@ -512,20 +510,25 @@ static int _drm_init_buffers(us_drm_s *drm, const us_device_s *dev) {
strides[0] = create.pitch; strides[0] = create.pitch;
} else { } else {
if (drmPrimeFDToHandle(run->fd, dev->run->hw_bufs[n_buf].dma_fd, &buf->handle) < 0) { if (drmPrimeFDToHandle(run->fd, cap->run->bufs[n_buf].dma_fd, &buf->handle) < 0) {
_D_LOG_PERROR("Can't import DMA buffer=%u from capture device", n_buf); _LOG_PERROR("Can't import DMA buffer=%u from capture device", n_buf);
return -1; return -1;
} }
handles[0] = buf->handle; handles[0] = buf->handle;
strides[0] = dev->run->stride; strides[0] = cap->run->stride;
switch (cap->run->format) {
case V4L2_PIX_FMT_RGB24: format = (DRM_FORMAT_BIG_ENDIAN ? DRM_FORMAT_BGR888 : DRM_FORMAT_RGB888); break;
case V4L2_PIX_FMT_BGR24: format = (DRM_FORMAT_BIG_ENDIAN ? DRM_FORMAT_RGB888 : DRM_FORMAT_BGR888); break;
}
} }
if (drmModeAddFB2( if (drmModeAddFB2(
run->fd, run->fd,
run->mode.hdisplay, run->mode.vdisplay, DRM_FORMAT_RGB888, run->mode.hdisplay, run->mode.vdisplay, format,
handles, strides, offsets, &buf->id, 0 handles, strides, offsets, &buf->id, 0
)) { )) {
_D_LOG_PERROR("Can't setup buffer=%u", n_buf); _LOG_PERROR("Can't setup buffer=%u", n_buf);
return -1; return -1;
} }
buf->fb_added = true; buf->fb_added = true;
@@ -538,22 +541,22 @@ static int _drm_find_sink(us_drm_s *drm, uint width, uint height, float hz) {
run->crtc_id = 0; run->crtc_id = 0;
_D_LOG_DEBUG("Trying to find the appropriate sink ..."); _LOG_DEBUG("Trying to find the appropriate sink ...");
drmModeRes *res = drmModeGetResources(run->fd); drmModeRes *res = drmModeGetResources(run->fd);
if (res == NULL) { if (res == NULL) {
_D_LOG_PERROR("Can't get resources info"); _LOG_PERROR("Can't get resources info");
goto done; goto done;
} }
if (res->count_connectors <= 0) { if (res->count_connectors <= 0) {
_D_LOG_ERROR("Can't find any connectors"); _LOG_ERROR("Can't find any connectors");
goto done; goto done;
} }
for (int ci = 0; ci < res->count_connectors; ++ci) { for (int ci = 0; ci < res->count_connectors; ++ci) {
drmModeConnector *conn = drmModeGetConnector(run->fd, res->connectors[ci]); drmModeConnector *conn = drmModeGetConnector(run->fd, res->connectors[ci]);
if (conn == NULL) { if (conn == NULL) {
_D_LOG_PERROR("Can't get connector index=%d", ci); _LOG_PERROR("Can't get connector index=%d", ci);
goto done; goto done;
} }
@@ -565,37 +568,37 @@ static int _drm_find_sink(us_drm_s *drm, uint width, uint height, float hz) {
drmModeFreeConnector(conn); drmModeFreeConnector(conn);
continue; continue;
} }
_D_LOG_INFO("Using connector %s: conn_type=%d, conn_type_id=%d", _LOG_INFO("Using connector %s: conn_type=%d, conn_type_id=%d",
drm->port, conn->connector_type, conn->connector_type_id); drm->port, conn->connector_type, conn->connector_type_id);
if (conn->connection != DRM_MODE_CONNECTED) { if (conn->connection != DRM_MODE_CONNECTED) {
_D_LOG_ERROR("Connector for port %s has !DRM_MODE_CONNECTED", drm->port); _LOG_ERROR("Connector for port %s has !DRM_MODE_CONNECTED", drm->port);
drmModeFreeConnector(conn); drmModeFreeConnector(conn);
goto done; goto done;
} }
drmModeModeInfo *best; drmModeModeInfo *best;
if ((best = _find_best_mode(conn, width, height, hz)) == NULL) { if ((best = _find_best_mode(conn, width, height, hz)) == NULL) {
_D_LOG_ERROR("Can't find any appropriate display modes"); _LOG_ERROR("Can't find any appropriate display modes");
drmModeFreeConnector(conn); drmModeFreeConnector(conn);
goto unplugged; goto unplugged;
} }
_D_LOG_INFO("Using best mode: %ux%up%.02f", _LOG_INFO("Using best mode: %ux%up%.02f",
best->hdisplay, best->vdisplay, _get_refresh_rate(best)); best->hdisplay, best->vdisplay, _get_refresh_rate(best));
if ((run->dpms_id = _find_dpms(run->fd, conn)) > 0) { if ((run->dpms_id = _find_dpms(run->fd, conn)) > 0) {
_D_LOG_INFO("Using DPMS: id=%u", run->dpms_id); _LOG_INFO("Using DPMS: id=%u", run->dpms_id);
} else { } else {
_D_LOG_INFO("Using DPMS: None"); _LOG_INFO("Using DPMS: None");
} }
u32 taken_crtcs = 0; // Unused here u32 taken_crtcs = 0; // Unused here
if ((run->crtc_id = _find_crtc(run->fd, res, conn, &taken_crtcs)) == 0) { if ((run->crtc_id = _find_crtc(run->fd, res, conn, &taken_crtcs)) == 0) {
_D_LOG_ERROR("Can't find CRTC"); _LOG_ERROR("Can't find CRTC");
drmModeFreeConnector(conn); drmModeFreeConnector(conn);
goto done; goto done;
} }
_D_LOG_INFO("Using CRTC: id=%u", run->crtc_id); _LOG_INFO("Using CRTC: id=%u", run->crtc_id);
run->conn_id = conn->connector_id; run->conn_id = conn->connector_id;
memcpy(&run->mode, best, sizeof(drmModeModeInfo)); memcpy(&run->mode, best, sizeof(drmModeModeInfo));

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -25,10 +25,10 @@
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include "../libs/types.h" #include "../types.h"
#include "../libs/frame.h" #include "../frame.h"
#include "../libs/frametext.h" #include "../frametext.h"
#include "../libs/device.h" #include "../capture.h"
typedef enum { typedef enum {
@@ -83,10 +83,10 @@ typedef struct {
us_drm_s *us_drm_init(void); us_drm_s *us_drm_init(void);
void us_drm_destroy(us_drm_s *drm); void us_drm_destroy(us_drm_s *drm);
int us_drm_open(us_drm_s *drm, const us_device_s *dev); int us_drm_open(us_drm_s *drm, const us_capture_s *cap);
void us_drm_close(us_drm_s *drm); void us_drm_close(us_drm_s *drm);
int us_drm_dpms_power_off(us_drm_s *drm); int us_drm_dpms_power_off(us_drm_s *drm);
int us_drm_wait_for_vsync(us_drm_s *drm); int us_drm_wait_for_vsync(us_drm_s *drm);
int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_device_s *dev); int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_capture_s *cap);
int us_drm_expose_dma(us_drm_s *drm, const us_hw_buffer_s *hw); int us_drm_expose_dma(us_drm_s *drm, const us_capture_hwbuf_s *hw);

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -56,6 +56,11 @@ us_memsink_s *us_memsink_init(
US_LOG_INFO("Using %s-sink: %s", name, obj); US_LOG_INFO("Using %s-sink: %s", name, obj);
if ((sink->data_size = us_memsink_calculate_size(obj)) == 0) {
US_LOG_ERROR("%s-sink: Invalid object suffix", name);
goto error;
}
const mode_t mask = umask(0); const mode_t mask = umask(0);
sink->fd = shm_open(sink->obj, (server ? O_RDWR | O_CREAT : O_RDWR), mode); sink->fd = shm_open(sink->obj, (server ? O_RDWR | O_CREAT : O_RDWR), mode);
umask(mask); umask(mask);
@@ -65,12 +70,12 @@ us_memsink_s *us_memsink_init(
goto error; goto error;
} }
if (sink->server && ftruncate(sink->fd, sizeof(us_memsink_shared_s)) < 0) { if (sink->server && ftruncate(sink->fd, sizeof(us_memsink_shared_s) + sink->data_size) < 0) {
US_LOG_PERROR("%s-sink: Can't truncate shared memory", name); US_LOG_PERROR("%s-sink: Can't truncate shared memory", name);
goto error; goto error;
} }
if ((sink->mem = us_memsink_shared_map(sink->fd)) == NULL) { if ((sink->mem = us_memsink_shared_map(sink->fd, sink->data_size)) == NULL) {
US_LOG_PERROR("%s-sink: Can't mmap shared memory", name); US_LOG_PERROR("%s-sink: Can't mmap shared memory", name);
goto error; goto error;
} }
@@ -83,7 +88,7 @@ error:
void us_memsink_destroy(us_memsink_s *sink) { void us_memsink_destroy(us_memsink_s *sink) {
if (sink->mem != NULL) { if (sink->mem != NULL) {
if (us_memsink_shared_unmap(sink->mem) < 0) { if (us_memsink_shared_unmap(sink->mem, sink->data_size) < 0) {
US_LOG_PERROR("%s-sink: Can't unmap shared memory", sink->name); US_LOG_PERROR("%s-sink: Can't unmap shared memory", sink->name);
} }
} }
@@ -160,9 +165,9 @@ int us_memsink_server_put(us_memsink_s *sink, const us_frame_s *frame, bool *key
const ldf now = us_get_now_monotonic(); const ldf now = us_get_now_monotonic();
if (frame->used > US_MEMSINK_MAX_DATA) { if (frame->used > sink->data_size) {
US_LOG_ERROR("%s-sink: Can't put frame: is too big (%zu > %zu)", US_LOG_ERROR("%s-sink: Can't put frame: is too big (%zu > %zu)",
sink->name, frame->used, US_MEMSINK_MAX_DATA); sink->name, frame->used, sink->data_size);
return 0; // -2 return 0; // -2
} }
@@ -177,7 +182,7 @@ int us_memsink_server_put(us_memsink_s *sink, const us_frame_s *frame, bool *key
*key_requested = sink->mem->key_requested; *key_requested = sink->mem->key_requested;
} }
memcpy(sink->mem->data, frame->data, frame->used); memcpy(us_memsink_get_data(sink->mem), frame->data, frame->used);
sink->mem->used = frame->used; sink->mem->used = frame->used;
US_FRAME_COPY_META(frame, sink->mem); US_FRAME_COPY_META(frame, sink->mem);
@@ -236,7 +241,7 @@ int us_memsink_client_get(us_memsink_s *sink, us_frame_s *frame, bool *key_reque
} }
sink->last_readed_id = sink->mem->id; sink->last_readed_id = sink->mem->id;
us_frame_set_data(frame, sink->mem->data, sink->mem->used); us_frame_set_data(frame, us_memsink_get_data(sink->mem), sink->mem->used);
US_FRAME_COPY_META(sink->mem, frame); US_FRAME_COPY_META(sink->mem, frame);
if (key_requested != NULL) { // We don't need it for non-H264 sinks if (key_requested != NULL) { // We don't need it for non-H264 sinks
*key_requested = sink->mem->key_requested; *key_requested = sink->mem->key_requested;

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -34,6 +34,7 @@
typedef struct { typedef struct {
const char *name; const char *name;
const char *obj; const char *obj;
uz data_size;
bool server; bool server;
bool rm; bool rm;
uint client_ttl; // Only for server uint client_ttl; // Only for server

72
src/libs/memsinksh.c Normal file
View File

@@ -0,0 +1,72 @@
/*****************************************************************************
# #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# #
# Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
*****************************************************************************/
#include "memsinksh.h"
#include <string.h>
#include <strings.h>
#include <assert.h>
#include <sys/mman.h>
#include "types.h"
us_memsink_shared_s *us_memsink_shared_map(int fd, uz data_size) {
us_memsink_shared_s *mem = mmap(
NULL,
sizeof(us_memsink_shared_s) + data_size,
PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
if (mem == MAP_FAILED) {
return NULL;
}
assert(mem != NULL);
return mem;
}
int us_memsink_shared_unmap(us_memsink_shared_s *mem, uz data_size) {
assert(mem != NULL);
return munmap(mem, sizeof(us_memsink_shared_s) + data_size);
}
uz us_memsink_calculate_size(const char *obj) {
const char *ptr = strrchr(obj, ':');
if (ptr == NULL) {
ptr = strrchr(obj, '.');
}
if (ptr != NULL) {
ptr += 1;
if (!strcasecmp(ptr, "jpeg")) {
return 4 * 1024 * 1024;
} else if (!strcasecmp(ptr, "h264")) {
return 2 * 1024 * 1024;
} else if (!strcasecmp(ptr, "raw")) {
return 1920 * 1200 * 3; // RGB
}
}
return 0;
}
u8 *us_memsink_get_data(us_memsink_shared_s *mem) {
return (u8*)(mem) + sizeof(us_memsink_shared_s);
}

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -22,18 +22,11 @@
#pragma once #pragma once
#include <sys/mman.h>
#include "types.h" #include "types.h"
#define US_MEMSINK_MAGIC ((u64)0xCAFEBABECAFEBABE) #define US_MEMSINK_MAGIC ((u64)0xCAFEBABECAFEBABE)
#define US_MEMSINK_VERSION ((u32)4) #define US_MEMSINK_VERSION ((u32)6)
#ifndef US_CFG_MEMSINK_MAX_DATA
# define US_CFG_MEMSINK_MAX_DATA 33554432
#endif
#define US_MEMSINK_MAX_DATA ((uz)(US_CFG_MEMSINK_MAX_DATA))
typedef struct { typedef struct {
@@ -57,28 +50,11 @@ typedef struct {
ldf last_client_ts; ldf last_client_ts;
bool key_requested; bool key_requested;
u8 data[US_MEMSINK_MAX_DATA];
} us_memsink_shared_s; } us_memsink_shared_s;
INLINE us_memsink_shared_s *us_memsink_shared_map(int fd) { us_memsink_shared_s *us_memsink_shared_map(int fd, uz data_size);
us_memsink_shared_s *mem = mmap( int us_memsink_shared_unmap(us_memsink_shared_s *mem, uz data_size);
NULL,
sizeof(us_memsink_shared_s),
PROT_READ | PROT_WRITE,
MAP_SHARED,
fd,
0
);
if (mem == MAP_FAILED) {
return NULL;
}
assert(mem != NULL);
return mem;
}
INLINE int us_memsink_shared_unmap(us_memsink_shared_s *mem) { uz us_memsink_calculate_size(const char *obj);
assert(mem != NULL); u8 *us_memsink_get_data(us_memsink_shared_s *mem);
return munmap(mem, sizeof(us_memsink_shared_s));
}

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -84,7 +84,7 @@ INLINE void us_thread_set_name(const char *name) {
# elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) # elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
pthread_set_name_np(pthread_self(), name); pthread_set_name_np(pthread_self(), name);
# elif defined(__NetBSD__) # elif defined(__NetBSD__)
pthread_setname_np(pthread_self(), "%s", (void *)name); pthread_setname_np(pthread_self(), "%s", (void*)name);
# else # else
# error us_thread_set_name() not implemented, you can disable it using WITH_PTHREAD_NP=0 # error us_thread_set_name() not implemented, you can disable it using WITH_PTHREAD_NP=0
# endif # endif

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -91,13 +91,13 @@ const char *us_encoder_type_to_string(us_encoder_type_e type) {
return _ENCODER_TYPES[0].name; return _ENCODER_TYPES[0].name;
} }
void us_encoder_open(us_encoder_s *enc, us_device_s *dev) { void us_encoder_open(us_encoder_s *enc, us_capture_s *cap) {
assert(enc->run->pool == NULL); assert(enc->run->pool == NULL);
# define DR(x_next) dev->run->x_next # define DR(x_next) cap->run->x_next
us_encoder_type_e type = (_ER(cpu_forced) ? US_ENCODER_TYPE_CPU : enc->type); us_encoder_type_e type = (_ER(cpu_forced) ? US_ENCODER_TYPE_CPU : enc->type);
unsigned quality = dev->jpeg_quality; unsigned quality = cap->jpeg_quality;
unsigned n_workers = US_MIN(enc->n_workers, DR(n_bufs)); unsigned n_workers = US_MIN(enc->n_workers, DR(n_bufs));
bool cpu_forced = false; bool cpu_forced = false;
@@ -139,7 +139,7 @@ void us_encoder_open(us_encoder_s *enc, us_device_s *dev) {
use_cpu: use_cpu:
type = US_ENCODER_TYPE_CPU; type = US_ENCODER_TYPE_CPU;
quality = dev->jpeg_quality; quality = cap->jpeg_quality;
ok: ok:
if (type == US_ENCODER_TYPE_NOOP) { if (type == US_ENCODER_TYPE_NOOP) {
@@ -159,14 +159,14 @@ void us_encoder_open(us_encoder_s *enc, us_device_s *dev) {
US_MUTEX_UNLOCK(_ER(mutex)); US_MUTEX_UNLOCK(_ER(mutex));
const long double desired_interval = ( const long double desired_interval = (
dev->desired_fps > 0 && (dev->desired_fps < dev->run->hw_fps || dev->run->hw_fps == 0) cap->desired_fps > 0 && (cap->desired_fps < cap->run->hw_fps || cap->run->hw_fps == 0)
? (long double)1 / dev->desired_fps ? (long double)1 / cap->desired_fps
: 0 : 0
); );
enc->run->pool = us_workers_pool_init( enc->run->pool = us_workers_pool_init(
"JPEG", "jw", n_workers, desired_interval, "JPEG", "jw", n_workers, desired_interval,
_worker_job_init, (void *)enc, _worker_job_init, (void*)enc,
_worker_job_destroy, _worker_job_destroy,
_worker_run_job); _worker_run_job);
@@ -188,19 +188,19 @@ void us_encoder_get_runtime_params(us_encoder_s *enc, us_encoder_type_e *type, u
static void *_worker_job_init(void *v_enc) { static void *_worker_job_init(void *v_enc) {
us_encoder_job_s *job; us_encoder_job_s *job;
US_CALLOC(job, 1); US_CALLOC(job, 1);
job->enc = (us_encoder_s *)v_enc; job->enc = (us_encoder_s*)v_enc;
job->dest = us_frame_init(); job->dest = us_frame_init();
return (void *)job; return (void*)job;
} }
static void _worker_job_destroy(void *v_job) { static void _worker_job_destroy(void *v_job) {
us_encoder_job_s *job = (us_encoder_job_s *)v_job; us_encoder_job_s *job = v_job;
us_frame_destroy(job->dest); us_frame_destroy(job->dest);
free(job); free(job);
} }
static bool _worker_run_job(us_worker_s *wr) { static bool _worker_run_job(us_worker_s *wr) {
us_encoder_job_s *job = (us_encoder_job_s *)wr->job; us_encoder_job_s *job = wr->job;
us_encoder_s *enc = job->enc; // Just for _ER() us_encoder_s *enc = job->enc; // Just for _ER()
const us_frame_s *src = &job->hw->raw; const us_frame_s *src = &job->hw->raw;
us_frame_s *dest = job->dest; us_frame_s *dest = job->dest;

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -35,7 +35,7 @@
#include "../libs/threading.h" #include "../libs/threading.h"
#include "../libs/logging.h" #include "../libs/logging.h"
#include "../libs/frame.h" #include "../libs/frame.h"
#include "../libs/device.h" #include "../libs/capture.h"
#include "workers.h" #include "workers.h"
#include "m2m.h" #include "m2m.h"
@@ -75,9 +75,9 @@ typedef struct {
} us_encoder_s; } us_encoder_s;
typedef struct { typedef struct {
us_encoder_s *enc; us_encoder_s *enc;
us_hw_buffer_s *hw; us_capture_hwbuf_s *hw;
us_frame_s *dest; us_frame_s *dest;
} us_encoder_job_s; } us_encoder_job_s;
@@ -87,7 +87,7 @@ void us_encoder_destroy(us_encoder_s *enc);
int us_encoder_parse_type(const char *str); int us_encoder_parse_type(const char *str);
const char *us_encoder_type_to_string(us_encoder_type_e type); const char *us_encoder_type_to_string(us_encoder_type_e type);
void us_encoder_open(us_encoder_s *enc, us_device_s *dev); void us_encoder_open(us_encoder_s *enc, us_capture_s *cap);
void us_encoder_close(us_encoder_s *enc); void us_encoder_close(us_encoder_s *enc);
void us_encoder_get_runtime_params(us_encoder_s *enc, us_encoder_type_e *type, unsigned *quality); void us_encoder_get_runtime_params(us_encoder_s *enc, us_encoder_type_e *type, unsigned *quality);

View File

@@ -7,7 +7,7 @@
# Copyright (C) 2005-2006 Laurent Pinchart & Michel Xhaard # # Copyright (C) 2005-2006 Laurent Pinchart & Michel Xhaard #
# Copyright (C) 2006 Gabriel A. Devenyi # # Copyright (C) 2006 Gabriel A. Devenyi #
# Copyright (C) 2007 Tom Stöveken # # Copyright (C) 2007 Tom Stöveken #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
@@ -29,8 +29,8 @@
typedef struct { typedef struct {
struct jpeg_destination_mgr mgr; // Default manager struct jpeg_destination_mgr mgr; // Default manager
JOCTET *buf; // Start of buffer JOCTET *buf; // Start of buffer
us_frame_s *frame; us_frame_s *frame;
} _jpeg_dest_manager_s; } _jpeg_dest_manager_s;
@@ -63,7 +63,12 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned q
jpeg.image_width = src->width; jpeg.image_width = src->width;
jpeg.image_height = src->height; jpeg.image_height = src->height;
jpeg.input_components = 3; jpeg.input_components = 3;
jpeg.in_color_space = ((src->format == V4L2_PIX_FMT_YUYV || src->format == V4L2_PIX_FMT_UYVY) ? JCS_YCbCr : JCS_RGB); 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;
default: jpeg.in_color_space = JCS_RGB; break;
}
jpeg_set_defaults(&jpeg); jpeg_set_defaults(&jpeg);
jpeg_set_quality(&jpeg, quality, TRUE); jpeg_set_quality(&jpeg, quality, TRUE);
@@ -89,12 +94,12 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned q
static void _jpeg_set_dest_frame(j_compress_ptr jpeg, us_frame_s *frame) { static void _jpeg_set_dest_frame(j_compress_ptr jpeg, us_frame_s *frame) {
if (jpeg->dest == NULL) { if (jpeg->dest == NULL) {
assert((jpeg->dest = (struct jpeg_destination_mgr *)(*jpeg->mem->alloc_small)( assert((jpeg->dest = (struct jpeg_destination_mgr*)(*jpeg->mem->alloc_small)(
(j_common_ptr) jpeg, JPOOL_PERMANENT, sizeof(_jpeg_dest_manager_s) (j_common_ptr) jpeg, JPOOL_PERMANENT, sizeof(_jpeg_dest_manager_s)
)) != NULL); )) != NULL);
} }
_jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s *)jpeg->dest; _jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s*)jpeg->dest;
dest->mgr.init_destination = _jpeg_init_destination; dest->mgr.init_destination = _jpeg_init_destination;
dest->mgr.empty_output_buffer = _jpeg_empty_output_buffer; dest->mgr.empty_output_buffer = _jpeg_empty_output_buffer;
dest->mgr.term_destination = _jpeg_term_destination; dest->mgr.term_destination = _jpeg_term_destination;
@@ -221,10 +226,10 @@ static void _jpeg_write_scanlines_bgr24(struct jpeg_compress_struct *jpeg, const
#define JPEG_OUTPUT_BUFFER_SIZE ((size_t)4096) #define JPEG_OUTPUT_BUFFER_SIZE ((size_t)4096)
static void _jpeg_init_destination(j_compress_ptr jpeg) { static void _jpeg_init_destination(j_compress_ptr jpeg) {
_jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s *)jpeg->dest; _jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s*)jpeg->dest;
// Allocate the output buffer - it will be released when done with image // Allocate the output buffer - it will be released when done with image
assert((dest->buf = (JOCTET *)(*jpeg->mem->alloc_small)( assert((dest->buf = (JOCTET*)(*jpeg->mem->alloc_small)(
(j_common_ptr) jpeg, JPOOL_IMAGE, JPEG_OUTPUT_BUFFER_SIZE * sizeof(JOCTET) (j_common_ptr) jpeg, JPOOL_IMAGE, JPEG_OUTPUT_BUFFER_SIZE * sizeof(JOCTET)
)) != NULL); )) != NULL);
@@ -235,7 +240,7 @@ static void _jpeg_init_destination(j_compress_ptr jpeg) {
static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg) { static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg) {
// Called whenever local jpeg buffer fills up // Called whenever local jpeg buffer fills up
_jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s *)jpeg->dest; _jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s*)jpeg->dest;
us_frame_append_data(dest->frame, dest->buf, JPEG_OUTPUT_BUFFER_SIZE); us_frame_append_data(dest->frame, dest->buf, JPEG_OUTPUT_BUFFER_SIZE);
@@ -249,7 +254,7 @@ static void _jpeg_term_destination(j_compress_ptr jpeg) {
// Called by jpeg_finish_compress after all data has been written. // Called by jpeg_finish_compress after all data has been written.
// Usually needs to flush buffer. // Usually needs to flush buffer.
_jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s *)jpeg->dest; _jpeg_dest_manager_s *const dest = (_jpeg_dest_manager_s*)jpeg->dest;
const size_t final = JPEG_OUTPUT_BUFFER_SIZE - dest->mgr.free_in_buffer; const size_t final = JPEG_OUTPUT_BUFFER_SIZE - dest->mgr.free_in_buffer;
// Write any data remaining in the buffer. // Write any data remaining in the buffer.

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -7,7 +7,7 @@
# Copyright (C) 2005-2006 Laurent Pinchart & Michel Xhaard # # Copyright (C) 2005-2006 Laurent Pinchart & Michel Xhaard #
# Copyright (C) 2006 Gabriel A. Devenyi # # Copyright (C) 2006 Gabriel A. Devenyi #
# Copyright (C) 2007 Tom Stöveken # # Copyright (C) 2007 Tom Stöveken #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -7,7 +7,7 @@
# Copyright (C) 2005-2006 Laurent Pinchart & Michel Xhaard # # Copyright (C) 2005-2006 Laurent Pinchart & Michel Xhaard #
# Copyright (C) 2006 Gabriel A. Devenyi # # Copyright (C) 2006 Gabriel A. Devenyi #
# Copyright (C) 2007 Tom Stöveken # # Copyright (C) 2007 Tom Stöveken #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

View File

@@ -2,7 +2,7 @@
# # # #
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # # uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
# # # #
# Copyright (C) 2018-2023 Maxim Devaev <mdevaev@gmail.com> # # Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #

Some files were not shown because too many files have changed in this diff Show More