new ustreamer and fps max

This commit is contained in:
Devaev Maxim 2019-07-13 04:52:19 +03:00
parent dfe58d81ef
commit ad97aecaf4
14 changed files with 46 additions and 26 deletions

View File

@ -5,6 +5,10 @@ TESTENV_HID ?= /dev/ttyS10
TESTENV_VIDEO ?= /dev/video0
TESTENV_LOOP ?= /dev/loop7
USTREAMER_VERSION = $(shell curl --silent "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=ustreamer" \
| grep "^pkgver=" \
| grep -Po "\d+\.\d+[^\"']*")
# =====
all:
@ -28,7 +32,12 @@ all:
testenv:
docker build $(if $(NC),--no-cache,) --rm --tag $(TESTENV_IMAGE) -f testenv/Dockerfile .
docker build \
$(if $(NC),--no-cache,) \
--rm \
--tag $(TESTENV_IMAGE) \
--build-arg USTREAMER_VERSION=$(USTREAMER_VERSION) \
-f testenv/Dockerfile .
tox: testenv

View File

@ -36,6 +36,7 @@ kvmd:
- "--dv-timings"
- "--format=uyvy"
- "--encoder=omx"
- "--glitched-resolutions=720x480,720x576"
- "--workers=3"
- "--quality={quality}"
- "--desired-fps={desired_fps}"

View File

@ -37,10 +37,8 @@ kvmd:
- "--encoder=cpu"
- "--quality={quality}"
- "--desired-fps={desired_fps}"
- "--width=720"
- "--height=576"
- "--fake-width=800"
- "--fake-height=600"
- "--resolution=720x756"
- "--fake-resolution=800x600"
- "--unix={unix}"
- "--unix-rm"
- "--unix-mode=0660"

View File

@ -38,6 +38,7 @@ kvmd:
- "--dv-timings"
- "--format=uyvy"
- "--encoder=omx"
- "--glitched-resolutions=720x480,720x576"
- "--workers=3"
- "--quality={quality}"
- "--desired-fps={desired_fps}"

View File

@ -42,10 +42,8 @@ kvmd:
- "--encoder=cpu"
- "--quality={quality}"
- "--desired-fps={desired_fps}"
- "--width=720"
- "--height=576"
- "--fake-width=800"
- "--fake-height=600"
- "--resolution=720x576"
- "--fake-resolution=800x600"
- "--unix={unix}"
- "--unix-rm"
- "--unix-mode=0660"

View File

@ -228,8 +228,9 @@ def _get_config_scheme(sections: List[str]) -> Dict:
"shutdown_delay": Option(10.0, type=valid_float_f01),
"state_poll": Option(1.0, type=valid_float_f01),
"quality": Option(80, type=valid_stream_quality),
"desired_fps": Option(0, type=valid_stream_fps),
"quality": Option(80, type=valid_stream_quality),
"desired_fps": Option(0, type=valid_stream_fps),
"max_fps": Option(120, type=valid_stream_fps),
"host": Option("localhost", type=valid_ip_or_host),
"port": Option(0, type=valid_port),

View File

@ -55,6 +55,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
quality: int,
desired_fps: int,
max_fps: int,
host: str,
port: int,
@ -77,6 +78,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
"quality": quality,
"desired_fps": desired_fps,
}
self.__max_fps = max_fps
assert port or unix_path
self.__host = host
@ -95,9 +97,13 @@ class Streamer: # pylint: disable=too-many-instance-attributes
logger = get_logger()
logger.info("Starting streamer ...")
self.__params = {key: params[key] for key in self.__params} # Only known params
assert 1 <= self.__params["quality"] <= 100
assert 0 <= self.__params["desired_fps"] <= 30
self.__params = {
key: min(max(params.get(key, self.__params[key]), a), b)
for (key, a, b) in [
("quality", 0, 100),
("desired_fps", 0, self.__max_fps),
]
}
await self.__inner_start()
if self.__init_restart_after > 0.0 and not no_init_restart:
@ -134,6 +140,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
except Exception:
get_logger().exception("Invalid streamer response from /state")
return {
"limits": {"max_fps": self.__max_fps},
"params": self.get_params(),
"state": state,
}

View File

@ -51,7 +51,7 @@ def valid_stream_quality(arg: Any) -> int:
def valid_stream_fps(arg: Any) -> int:
return int(valid_number(arg, min=0, max=30, name="stream FPS"))
return int(valid_number(arg, min=0, max=120, name="stream FPS"))
# =====

View File

@ -13,27 +13,30 @@ RUN pacman -Syu --noconfirm \
RUN useradd -r -c "Packer build user" -m -d /var/packer -s /sbin/nologin packer \
&& cd /tmp \
&& sudo -u packer git clone https://aur.archlinux.org/packer-kit.git \
&& sudo -u packer git clone https://github.com/pi-kvm/packer-kit.git \
&& cd packer-kit \
&& sudo -u packer makepkg \
&& pacman --noconfirm -U packer-kit-*.pkg.tar.xz \
&& cd - \
&& rm -rf /tmp/packer-kit
RUN pkg-install \
RUN pkg-install -S \
python \
python-pip \
python-tox \
python-systemd \
python-dbus \
python-mako \
libevent-patched \
nginx-mainline \
ustreamer \
socat \
htmlhint \
eslint
ARG USTREAMER_VERSION
ENV USTREAMER_VERSION $USTREAMER_VERSION
RUN echo $USTREAMER_VERSION
RUN pkg-install -S ustreamer
COPY testenv/requirements.txt requirements.txt
RUN pip install -r requirements.txt

View File

@ -26,14 +26,15 @@ kvmd:
cap_pin: 17
conv_pin: 18
init_restart_after: 1
desired_fps: 30
max_fps: 40
unix: /run/kvmd/ustreamer.sock
cmd:
- "/usr/bin/ustreamer"
- "--device=/dev/kvmd-video"
- "--quality={quality}"
- "--desired-fps={desired_fps}"
- "--width=800"
- "--height=600"
- "--resolution=800x600"
- "--unix={unix}"
- "--unix-rm"
- "--unix-mode=0666"

View File

@ -104,14 +104,14 @@ def test_fail__valid_stream_quality(arg: Any) -> None:
# =====
@pytest.mark.parametrize("arg", ["1 ", 30])
@pytest.mark.parametrize("arg", ["1 ", 120])
def test_ok__valid_stream_fps(arg: Any) -> None:
value = valid_stream_fps(arg)
assert type(value) == int # pylint: disable=unidiomatic-typecheck
assert value == int(str(arg).strip())
@pytest.mark.parametrize("arg", ["test", "", None, 31, 1.1])
@pytest.mark.parametrize("arg", ["test", "", None, 121, 1.1])
def test_fail__valid_stream_fps(arg: Any) -> None:
with pytest.raises(ValidatorError):
print(valid_stream_fps(arg))

View File

@ -54,7 +54,7 @@ deps =
[testenv:eslint]
whitelist_externals = eslint
commands = eslint --config=testenv/linters/eslintrc.yaml --color --ext .js web/share/js
commands = eslint --cache-location=/tmp --config=testenv/linters/eslintrc.yaml --color --ext .js web/share/js
[testenv:htmlhint]
whitelist_externals = htmlhint

View File

@ -100,7 +100,7 @@
</div>
<hr>
<div class="menu-item-content-text">
Stream FPS: <span id="stream-desired-fps-value">30</span>
Stream FPS: <span id="stream-desired-fps-value">0</span>
<div class="stream-slider-box">
<input disabled type="range" id="stream-desired-fps-slider" class="slider" />
</div>

View File

@ -42,7 +42,7 @@ function Streamer() {
tools.setOnUpSlider($("stream-quality-slider"), 1000, __updateQualityValue, (value) => __sendParam("quality", value));
$("stream-desired-fps-slider").min = 0;
$("stream-desired-fps-slider").max = 30;
$("stream-desired-fps-slider").max = 120;
$("stream-desired-fps-slider").step = 1;
$("stream-desired-fps-slider").value = 0;
tools.setOnUpSlider($("stream-desired-fps-slider"), 1000, __updateDesiredFpsValue, (value) => __sendParam("desired_fps", value));
@ -80,6 +80,7 @@ function Streamer() {
}
if (!$("stream-desired-fps-slider").activated) {
$("stream-desired-fps-slider").max = state.limits.max_fps;
wm.switchDisabled($("stream-desired-fps-slider"), false);
if ($("stream-desired-fps-slider").value !== source.desired_fps) {
$("stream-desired-fps-slider").value = source.desired_fps;