mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-27 12:16:31 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe86997d08 | ||
|
|
df39b824c6 | ||
|
|
db297db52e | ||
|
|
b304364af9 | ||
|
|
ddec4e8478 | ||
|
|
28ca658621 | ||
|
|
270d3ae3a9 | ||
|
|
c1f080f29f |
@@ -1,7 +1,7 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
current_version = 6.25
|
current_version = 6.28
|
||||||
parse = (?P<major>\d+)\.(?P<minor>\d+)
|
parse = (?P<major>\d+)\.(?P<minor>\d+)
|
||||||
serialize =
|
serialize =
|
||||||
{major}.{minor}
|
{major}.{minor}
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -6,6 +6,7 @@ MANPREFIX ?= $(PREFIX)/share/man
|
|||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
PY ?= python3
|
PY ?= python3
|
||||||
|
PKG_CONFIG ?= pkg-config
|
||||||
CFLAGS ?= -O3
|
CFLAGS ?= -O3
|
||||||
LDFLAGS ?=
|
LDFLAGS ?=
|
||||||
|
|
||||||
@@ -17,8 +18,8 @@ _LINTERS_IMAGE ?= ustreamer-linters
|
|||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
ifeq (__not_found__,$(shell which pkg-config 2>/dev/null || echo "__not_found__"))
|
ifeq (__not_found__,$(shell which $(PKG_CONFIG) 2>/dev/null || echo "__not_found__"))
|
||||||
$(error "No pkg-config found in $(PATH)")
|
$(error "No $(PKG_CONFIG) found in $(PATH)")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ R_DESTDIR ?=
|
|||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
|
PKG_CONFIG ?= pkg-config
|
||||||
CFLAGS ?= -O3
|
CFLAGS ?= -O3
|
||||||
LDFLAGS ?=
|
LDFLAGS ?=
|
||||||
|
|
||||||
@@ -9,8 +10,8 @@ LDFLAGS ?=
|
|||||||
# =====
|
# =====
|
||||||
_PLUGIN = libjanus_ustreamer.so
|
_PLUGIN = libjanus_ustreamer.so
|
||||||
|
|
||||||
_CFLAGS = -fPIC -MD -c -std=c17 -Wall -Wextra -D_GNU_SOURCE $(shell pkg-config --cflags glib-2.0) $(CFLAGS)
|
_CFLAGS = -fPIC -MD -c -std=c17 -Wall -Wextra -D_GNU_SOURCE $(shell $(PKG_CONFIG) --cflags glib-2.0) $(CFLAGS)
|
||||||
_LDFLAGS = -shared -lm -pthread -lrt -ljansson -lopus -lasound -lspeexdsp $(shell pkg-config --libs glib-2.0) $(LDFLAGS)
|
_LDFLAGS = -shared -lm -pthread -lrt -ljansson -lopus -lasound -lspeexdsp $(shell $(PKG_CONFIG) --libs glib-2.0) $(LDFLAGS)
|
||||||
|
|
||||||
_SRCS = $(shell ls src/uslibs/*.c src/*.c)
|
_SRCS = $(shell ls src/uslibs/*.c src/*.c)
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <janus/config.h>
|
#include <janus/config.h>
|
||||||
#include <janus/plugins/plugin.h>
|
#include <janus/plugins/plugin.h>
|
||||||
@@ -64,7 +65,16 @@ us_config_s *us_config_init(const char *config_dir_path) {
|
|||||||
US_JLOG_INFO("config", "Missing config value: acap.tc358743");
|
US_JLOG_INFO("config", "Missing config value: acap.tc358743");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
config->aplay_dev_name = _get_value(jcfg, "aplay", "device");
|
if ((config->aplay_dev_name = _get_value(jcfg, "aplay", "device")) != NULL) {
|
||||||
|
char *path = _get_value(jcfg, "aplay", "check");
|
||||||
|
if (path != NULL) {
|
||||||
|
if (access(path, F_OK) != 0) {
|
||||||
|
US_JLOG_INFO("config", "No check file found, aplay will be disabled");
|
||||||
|
US_DELETE(config->aplay_dev_name, free);
|
||||||
|
}
|
||||||
|
US_DELETE(path, free);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goto ok;
|
goto ok;
|
||||||
|
|||||||
@@ -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.25" "January 2021"
|
.TH USTREAMER-DUMP 1 "version 6.28" "January 2021"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
ustreamer-dump \- Dump uStreamer's memory sink to file
|
ustreamer-dump \- Dump uStreamer's memory sink to 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.25" "November 2020"
|
.TH USTREAMER 1 "version 6.28" "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
|
||||||
@@ -52,7 +52,7 @@ Initial image resolution. Default: 640x480.
|
|||||||
.TP
|
.TP
|
||||||
.BR \-m\ \fIfmt ", " \-\-format\ \fIfmt
|
.BR \-m\ \fIfmt ", " \-\-format\ \fIfmt
|
||||||
Image format.
|
Image format.
|
||||||
Available: YUYV, YVYU, UYVY, RGB565, RGB24, JPEG; default: YUYV.
|
Available: YUYV, YVYU, UYVY, YUV420, YVU420, RGB565, RGB24, JPEG; default: YUYV.
|
||||||
.TP
|
.TP
|
||||||
.BR \-a\ \fIstd ", " \-\-tv\-standard\ \fIstd
|
.BR \-a\ \fIstd ", " \-\-tv\-standard\ \fIstd
|
||||||
Force TV standard.
|
Force TV standard.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
pkgname=ustreamer
|
pkgname=ustreamer
|
||||||
pkgver=6.25
|
pkgver=6.28
|
||||||
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"
|
||||||
@@ -18,7 +18,7 @@ md5sums=(SKIP)
|
|||||||
_options="WITH_GPIO=1 WITH_SYSTEMD=1"
|
_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>=3.13" "python<3.14")
|
||||||
makedepends+=(python-setuptools python-pip python-build python-wheel)
|
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
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=ustreamer
|
PKG_NAME:=ustreamer
|
||||||
PKG_VERSION:=6.25
|
PKG_VERSION:=6.28
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_MAINTAINER:=Maxim Devaev <mdevaev@gmail.com>
|
PKG_MAINTAINER:=Maxim Devaev <mdevaev@gmail.com>
|
||||||
|
|
||||||
|
|||||||
@@ -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.25",
|
version="6.28",
|
||||||
description="uStreamer tools",
|
description="uStreamer tools",
|
||||||
author="Maxim Devaev",
|
author="Maxim Devaev",
|
||||||
author_email="mdevaev@gmail.com",
|
author_email="mdevaev@gmail.com",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ R_DESTDIR ?=
|
|||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
|
PKG_CONFIG ?= pkg-config
|
||||||
CFLAGS ?= -O3
|
CFLAGS ?= -O3
|
||||||
LDFLAGS ?=
|
LDFLAGS ?=
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ endef
|
|||||||
|
|
||||||
|
|
||||||
ifneq ($(call optbool,$(WITH_GPIO)),)
|
ifneq ($(call optbool,$(WITH_GPIO)),)
|
||||||
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)
|
||||||
override _USTR_LDFLAGS += -lgpiod
|
override _USTR_LDFLAGS += -lgpiod
|
||||||
override _USTR_SRCS += $(shell ls ustreamer/gpio/*.c)
|
override _USTR_SRCS += $(shell ls ustreamer/gpio/*.c)
|
||||||
endif
|
endif
|
||||||
@@ -83,10 +84,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 += -DWITH_V4P $(shell pkg-config --cflags libdrm)
|
override _CFLAGS += -DWITH_V4P $(shell $(PKG_CONFIG) --cflags libdrm)
|
||||||
override _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_SRCS += $(shell ls libs/drm/*.c)
|
||||||
override _USTR_LDFLAGS += $(shell pkg-config --libs libdrm)
|
override _USTR_LDFLAGS += $(shell $(PKG_CONFIG) --libs libdrm)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ static const struct {
|
|||||||
{"YUYV", V4L2_PIX_FMT_YUYV},
|
{"YUYV", V4L2_PIX_FMT_YUYV},
|
||||||
{"YVYU", V4L2_PIX_FMT_YVYU},
|
{"YVYU", V4L2_PIX_FMT_YVYU},
|
||||||
{"UYVY", V4L2_PIX_FMT_UYVY},
|
{"UYVY", V4L2_PIX_FMT_UYVY},
|
||||||
|
{"YUV420", V4L2_PIX_FMT_YUV420},
|
||||||
|
{"YVU420", V4L2_PIX_FMT_YVU420},
|
||||||
{"RGB565", V4L2_PIX_FMT_RGB565},
|
{"RGB565", V4L2_PIX_FMT_RGB565},
|
||||||
{"RGB24", V4L2_PIX_FMT_RGB24},
|
{"RGB24", V4L2_PIX_FMT_RGB24},
|
||||||
{"BGR24", V4L2_PIX_FMT_BGR24},
|
{"BGR24", V4L2_PIX_FMT_BGR24},
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
#define US_VIDEO_MAX_FPS ((uint)120)
|
#define US_VIDEO_MAX_FPS ((uint)120)
|
||||||
|
|
||||||
#define US_STANDARDS_STR "PAL, NTSC, SECAM"
|
#define US_STANDARDS_STR "PAL, NTSC, SECAM"
|
||||||
#define US_FORMATS_STR "YUYV, YVYU, UYVY, RGB565, RGB24, BGR24, MJPEG, JPEG"
|
#define US_FORMATS_STR "YUYV, YVYU, UYVY, YUV420, YVU420, RGB565, RGB24, BGR24, MJPEG, JPEG"
|
||||||
#define US_IO_METHODS_STR "MMAP, USERPTR"
|
#define US_IO_METHODS_STR "MMAP, USERPTR"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define US_VERSION_MAJOR 6
|
#define US_VERSION_MAJOR 6
|
||||||
#define US_VERSION_MINOR 25
|
#define US_VERSION_MINOR 28
|
||||||
|
|
||||||
#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)
|
||||||
|
|||||||
@@ -82,16 +82,31 @@ bool us_frame_compare(const us_frame_s *a, const us_frame_s *b) {
|
|||||||
uint us_frame_get_padding(const us_frame_s *frame) {
|
uint us_frame_get_padding(const us_frame_s *frame) {
|
||||||
uint bytes_per_pixel = 0;
|
uint bytes_per_pixel = 0;
|
||||||
switch (frame->format) {
|
switch (frame->format) {
|
||||||
|
case V4L2_PIX_FMT_YUV420:
|
||||||
|
case V4L2_PIX_FMT_YVU420:
|
||||||
|
bytes_per_pixel = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case V4L2_PIX_FMT_YUYV:
|
case V4L2_PIX_FMT_YUYV:
|
||||||
case V4L2_PIX_FMT_YVYU:
|
case V4L2_PIX_FMT_YVYU:
|
||||||
case V4L2_PIX_FMT_UYVY:
|
case V4L2_PIX_FMT_UYVY:
|
||||||
case V4L2_PIX_FMT_RGB565: bytes_per_pixel = 2; break;
|
case V4L2_PIX_FMT_RGB565:
|
||||||
|
bytes_per_pixel = 2;
|
||||||
|
break;
|
||||||
|
|
||||||
case V4L2_PIX_FMT_BGR24:
|
case V4L2_PIX_FMT_BGR24:
|
||||||
case V4L2_PIX_FMT_RGB24: bytes_per_pixel = 3; break;
|
case V4L2_PIX_FMT_RGB24:
|
||||||
|
bytes_per_pixel = 3;
|
||||||
|
break;
|
||||||
|
|
||||||
// case V4L2_PIX_FMT_H264:
|
// case V4L2_PIX_FMT_H264:
|
||||||
case V4L2_PIX_FMT_MJPEG:
|
case V4L2_PIX_FMT_MJPEG:
|
||||||
case V4L2_PIX_FMT_JPEG: bytes_per_pixel = 0; break;
|
case V4L2_PIX_FMT_JPEG:
|
||||||
default: assert(0 && "Unknown format");
|
bytes_per_pixel = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(0 && "Unknown format");
|
||||||
}
|
}
|
||||||
if (bytes_per_pixel > 0 && frame->stride > frame->width) {
|
if (bytes_per_pixel > 0 && frame->stride > frame->width) {
|
||||||
return (frame->stride - frame->width * bytes_per_pixel);
|
return (frame->stride - frame->width * bytes_per_pixel);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ typedef struct {
|
|||||||
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);
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||||
|
static void _jpeg_write_scanlines_yuv_planar(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||||
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||||
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame);
|
||||||
#ifndef JCS_EXTENSIONS
|
#ifndef JCS_EXTENSIONS
|
||||||
@@ -50,7 +51,7 @@ static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg);
|
|||||||
static void _jpeg_term_destination(j_compress_ptr jpeg);
|
static void _jpeg_term_destination(j_compress_ptr jpeg);
|
||||||
|
|
||||||
|
|
||||||
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned quality) {
|
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, uint quality) {
|
||||||
// This function based on compress_image_to_jpeg() from mjpg-streamer
|
// This function based on compress_image_to_jpeg() from mjpg-streamer
|
||||||
|
|
||||||
us_frame_encoding_begin(src, dest, V4L2_PIX_FMT_JPEG);
|
us_frame_encoding_begin(src, dest, V4L2_PIX_FMT_JPEG);
|
||||||
@@ -69,11 +70,19 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned q
|
|||||||
switch (src->format) {
|
switch (src->format) {
|
||||||
case V4L2_PIX_FMT_YUYV:
|
case V4L2_PIX_FMT_YUYV:
|
||||||
case V4L2_PIX_FMT_YVYU:
|
case V4L2_PIX_FMT_YVYU:
|
||||||
case V4L2_PIX_FMT_UYVY: jpeg.in_color_space = JCS_YCbCr; break;
|
case V4L2_PIX_FMT_UYVY:
|
||||||
|
case V4L2_PIX_FMT_YUV420:
|
||||||
|
case V4L2_PIX_FMT_YVU420:
|
||||||
|
jpeg.in_color_space = JCS_YCbCr;
|
||||||
|
break;
|
||||||
# ifdef JCS_EXTENSIONS
|
# ifdef JCS_EXTENSIONS
|
||||||
case V4L2_PIX_FMT_BGR24: jpeg.in_color_space = JCS_EXT_BGR; break;
|
case V4L2_PIX_FMT_BGR24:
|
||||||
|
jpeg.in_color_space = JCS_EXT_BGR;
|
||||||
|
break;
|
||||||
# endif
|
# endif
|
||||||
default: jpeg.in_color_space = JCS_RGB; break;
|
default:
|
||||||
|
jpeg.in_color_space = JCS_RGB;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_set_defaults(&jpeg);
|
jpeg_set_defaults(&jpeg);
|
||||||
@@ -85,9 +94,23 @@ void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned q
|
|||||||
// https://www.fourcc.org/yuv.php
|
// https://www.fourcc.org/yuv.php
|
||||||
case V4L2_PIX_FMT_YUYV:
|
case V4L2_PIX_FMT_YUYV:
|
||||||
case V4L2_PIX_FMT_YVYU:
|
case V4L2_PIX_FMT_YVYU:
|
||||||
case V4L2_PIX_FMT_UYVY: _jpeg_write_scanlines_yuv(&jpeg, src); break;
|
case V4L2_PIX_FMT_UYVY:
|
||||||
case V4L2_PIX_FMT_RGB565: _jpeg_write_scanlines_rgb565(&jpeg, src); break;
|
_jpeg_write_scanlines_yuv(&jpeg, src);
|
||||||
case V4L2_PIX_FMT_RGB24: _jpeg_write_scanlines_rgb24(&jpeg, src); break;
|
break;
|
||||||
|
|
||||||
|
case V4L2_PIX_FMT_YUV420:
|
||||||
|
case V4L2_PIX_FMT_YVU420:
|
||||||
|
_jpeg_write_scanlines_yuv_planar(&jpeg, src);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case V4L2_PIX_FMT_RGB565:
|
||||||
|
_jpeg_write_scanlines_rgb565(&jpeg, src);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case V4L2_PIX_FMT_RGB24:
|
||||||
|
_jpeg_write_scanlines_rgb24(&jpeg, src);
|
||||||
|
break;
|
||||||
|
|
||||||
case V4L2_PIX_FMT_BGR24:
|
case V4L2_PIX_FMT_BGR24:
|
||||||
# ifdef JCS_EXTENSIONS
|
# ifdef JCS_EXTENSIONS
|
||||||
_jpeg_write_scanlines_rgb24(&jpeg, src); // Use native JCS_EXT_BGR
|
_jpeg_write_scanlines_rgb24(&jpeg, src); // Use native JCS_EXT_BGR
|
||||||
@@ -121,19 +144,19 @@ static void _jpeg_set_dest_frame(j_compress_ptr jpeg, us_frame_s *frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||||
uint8_t *line_buf;
|
u8 *line_buf;
|
||||||
US_CALLOC(line_buf, frame->width * 3);
|
US_CALLOC(line_buf, frame->width * 3);
|
||||||
|
|
||||||
const unsigned padding = us_frame_get_padding(frame);
|
const uint padding = us_frame_get_padding(frame);
|
||||||
const uint8_t *data = frame->data;
|
const u8 *data = frame->data;
|
||||||
|
|
||||||
while (jpeg->next_scanline < frame->height) {
|
while (jpeg->next_scanline < frame->height) {
|
||||||
uint8_t *ptr = line_buf;
|
u8 *ptr = line_buf;
|
||||||
|
|
||||||
for (unsigned x = 0; x < frame->width; ++x) {
|
for (uint x = 0; x < frame->width; ++x) {
|
||||||
// See also: https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/pixfmt-uyvy.html
|
// See also: https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/pixfmt-uyvy.html
|
||||||
const bool is_odd_pixel = x & 1;
|
const bool is_odd_pixel = x & 1;
|
||||||
uint8_t y, u, v;
|
u8 y, u, v;
|
||||||
if (frame->format == V4L2_PIX_FMT_YUYV) {
|
if (frame->format == V4L2_PIX_FMT_YUYV) {
|
||||||
y = data[is_odd_pixel ? 2 : 0];
|
y = data[is_odd_pixel ? 2 : 0];
|
||||||
u = data[1];
|
u = data[1];
|
||||||
@@ -167,21 +190,80 @@ static void _jpeg_write_scanlines_yuv(struct jpeg_compress_struct *jpeg, const u
|
|||||||
free(line_buf);
|
free(line_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
static void _jpeg_write_scanlines_yuv_planar(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||||
uint8_t *line_buf;
|
u8 *line_buf;
|
||||||
US_CALLOC(line_buf, frame->width * 3);
|
US_CALLOC(line_buf, frame->width * 3);
|
||||||
|
|
||||||
const unsigned padding = us_frame_get_padding(frame);
|
const uint padding = us_frame_get_padding(frame);
|
||||||
const uint8_t *data = frame->data;
|
const uint image_size = frame->width * frame->height;
|
||||||
|
const uint chroma_array_size = (frame->used - image_size) / 2;
|
||||||
|
const uint chroma_matrix_order = (image_size / chroma_array_size) == 16 ? 4 : 2;
|
||||||
|
const u8 *data = frame->data;
|
||||||
|
const u8 *chroma1_data = frame->data + image_size;
|
||||||
|
const u8 *chroma2_data = frame->data + image_size + chroma_array_size;
|
||||||
|
|
||||||
|
//US_LOG_DEBUG("Planar data: Image Size %u, Chroma Array Size %u, Chroma Matrix Order %u",
|
||||||
|
// image_size, chroma_array_size, chroma_matrix_order);
|
||||||
|
|
||||||
while (jpeg->next_scanline < frame->height) {
|
while (jpeg->next_scanline < frame->height) {
|
||||||
uint8_t *ptr = line_buf;
|
u8 *ptr = line_buf;
|
||||||
|
|
||||||
for (unsigned x = 0; x < frame->width; ++x) {
|
for (uint x = 0; x < frame->width; ++x) {
|
||||||
const unsigned int two_byte = (data[1] << 8) + data[0];
|
// See also: https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/pixfmt-yuv420.html
|
||||||
|
u8 y = data[x];
|
||||||
|
u8 u;
|
||||||
|
u8 v;
|
||||||
|
uint chroma_position = x / chroma_matrix_order;
|
||||||
|
|
||||||
|
switch (frame->format) {
|
||||||
|
case V4L2_PIX_FMT_YUV420:
|
||||||
|
u = chroma1_data[chroma_position];
|
||||||
|
v = chroma2_data[chroma_position];
|
||||||
|
break;
|
||||||
|
case V4L2_PIX_FMT_YVU420:
|
||||||
|
u = chroma2_data[chroma_position];
|
||||||
|
v = chroma1_data[chroma_position];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0 && "Unsupported pixel format");
|
||||||
|
return; // Makes linter happy
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr[0] = y;
|
||||||
|
ptr[1] = u;
|
||||||
|
ptr[2] = v;
|
||||||
|
ptr += 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
data += frame->width + padding;
|
||||||
|
|
||||||
|
if (jpeg->next_scanline > 0 && jpeg->next_scanline % chroma_matrix_order == 0) {
|
||||||
|
chroma1_data += (frame->width + padding) / chroma_matrix_order;
|
||||||
|
chroma2_data += (frame->width + padding) / chroma_matrix_order;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSAMPROW scanlines[1] = {line_buf};
|
||||||
|
jpeg_write_scanlines(jpeg, scanlines, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(line_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||||
|
u8 *line_buf;
|
||||||
|
US_CALLOC(line_buf, frame->width * 3);
|
||||||
|
|
||||||
|
const uint padding = us_frame_get_padding(frame);
|
||||||
|
const u8 *data = frame->data;
|
||||||
|
|
||||||
|
while (jpeg->next_scanline < frame->height) {
|
||||||
|
u8 *ptr = line_buf;
|
||||||
|
|
||||||
|
for (uint x = 0; x < frame->width; ++x) {
|
||||||
|
const uint two_byte = (data[1] << 8) + data[0];
|
||||||
|
|
||||||
ptr[0] = data[1] & 248; // Red
|
ptr[0] = data[1] & 248; // Red
|
||||||
ptr[1] = (uint8_t)((two_byte & 2016) >> 3); // Green
|
ptr[1] = (u8)((two_byte & 2016) >> 3); // Green
|
||||||
ptr[2] = (data[0] & 31) * 8; // Blue
|
ptr[2] = (data[0] & 31) * 8; // Blue
|
||||||
ptr += 3;
|
ptr += 3;
|
||||||
|
|
||||||
@@ -197,8 +279,8 @@ static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||||
const unsigned padding = us_frame_get_padding(frame);
|
const uint padding = us_frame_get_padding(frame);
|
||||||
uint8_t *data = frame->data;
|
u8 *data = frame->data;
|
||||||
|
|
||||||
while (jpeg->next_scanline < frame->height) {
|
while (jpeg->next_scanline < frame->height) {
|
||||||
JSAMPROW scanlines[1] = {data};
|
JSAMPROW scanlines[1] = {data};
|
||||||
@@ -210,17 +292,17 @@ static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const
|
|||||||
|
|
||||||
#ifndef JCS_EXTENSIONS
|
#ifndef JCS_EXTENSIONS
|
||||||
static void _jpeg_write_scanlines_bgr24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
static void _jpeg_write_scanlines_bgr24(struct jpeg_compress_struct *jpeg, const us_frame_s *frame) {
|
||||||
uint8_t *line_buf;
|
u8 *line_buf;
|
||||||
US_CALLOC(line_buf, frame->width * 3);
|
US_CALLOC(line_buf, frame->width * 3);
|
||||||
|
|
||||||
const unsigned padding = us_frame_get_padding(frame);
|
const uint padding = us_frame_get_padding(frame);
|
||||||
uint8_t *data = frame->data;
|
u8 *data = frame->data;
|
||||||
|
|
||||||
while (jpeg->next_scanline < frame->height) {
|
while (jpeg->next_scanline < frame->height) {
|
||||||
uint8_t *ptr = line_buf;
|
u8 *ptr = line_buf;
|
||||||
|
|
||||||
// swap B and R values
|
// swap B and R values
|
||||||
for (unsigned x = 0; x < frame->width * 3; x += 3) {
|
for (uint x = 0; x < frame->width * 3; x += 3) {
|
||||||
ptr[0] = data[x + 2];
|
ptr[0] = data[x + 2];
|
||||||
ptr[1] = data[x + 1];
|
ptr[1] = data[x + 1];
|
||||||
ptr[2] = data[x];
|
ptr[2] = data[x];
|
||||||
|
|||||||
@@ -35,4 +35,4 @@
|
|||||||
#include "../../../libs/frame.h"
|
#include "../../../libs/frame.h"
|
||||||
|
|
||||||
|
|
||||||
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, unsigned quality);
|
void us_cpu_encoder_compress(const us_frame_s *src, us_frame_s *dest, uint quality);
|
||||||
|
|||||||
Reference in New Issue
Block a user