pyobs-v4l 2.0.0.dev7__tar.gz → 2.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyobs_v4l-2.1.1/CHANGELOG.md +49 -0
- pyobs_v4l-2.1.1/CONTRIBUTING.md +35 -0
- pyobs_v4l-2.1.1/PKG-INFO +78 -0
- pyobs_v4l-2.1.1/pyobs_v4l/v4lcamera.py +193 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/pyproject.toml +10 -3
- pyobs_v4l-2.1.1/tests/test_v4lcamera.py +127 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/uv.lock +40 -40
- pyobs_v4l-2.0.0.dev7/PKG-INFO +0 -12
- pyobs_v4l-2.0.0.dev7/pyobs_v4l/v4lcamera.py +0 -131
- pyobs_v4l-2.0.0.dev7/tests/test_v4lcamera.py +0 -45
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.github/dependabot.yml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.github/workflows/dependabot-automerge.yml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.github/workflows/pypi.yml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.github/workflows/pyrefly.yml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.github/workflows/pytest.yml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.github/workflows/ruff.yml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.pre-commit-config.yaml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/.readthedocs.yml +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/LICENSE +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/README.md +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/docs/Makefile +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/docs/make.bat +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/docs/requirements.txt +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/docs/source/conf.py +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/docs/source/index.rst +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/pyobs_v4l/__init__.py +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/pyobs_v4l/gui.py +0 -0
- {pyobs_v4l-2.0.0.dev7 → pyobs_v4l-2.1.1}/tests/test_import.py +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
Entries for releases before this file existed were generated from commit subjects.
|
|
9
|
+
|
|
10
|
+
## [2.1.0] - 2026-09-29
|
|
11
|
+
|
|
12
|
+
- Move v4lCamera to the BaseVideo frames() contract
|
|
13
|
+
- Deliver every frame to _set_image() instead of throttling in _capture()
|
|
14
|
+
|
|
15
|
+
## [2.0.0] - 2026-08-26
|
|
16
|
+
|
|
17
|
+
- Require stable pyobs-core>=2.0.0
|
|
18
|
+
- Gate auto-merge on the PR author, not the event actor
|
|
19
|
+
- Enable Dependabot auto-merge for patch/minor updates
|
|
20
|
+
- Camera driver/GUI split: fix capture/handle leaks, read race, sync open (#19)
|
|
21
|
+
- Remove upper bound on Python version
|
|
22
|
+
- pyrefly: exclude gui.py from type checking
|
|
23
|
+
- Add baseline test suite and CI (pytest, pyrefly), grouped Dependabot
|
|
24
|
+
- Upgrade uv.lock to clear open Dependabot alerts
|
|
25
|
+
- Require pyobs-core>=2.0.0.dev48
|
|
26
|
+
- Add dependabot.yml, targeting develop for PRs
|
|
27
|
+
- Run cv2/V4L2 camera calls through a background thread
|
|
28
|
+
- Add Sphinx documentation
|
|
29
|
+
- Rewrite README for uv-based install, config docs, and GUI
|
|
30
|
+
- remove `DEVELOPMENT.md` documentation file detailing the pyobs migration guide
|
|
31
|
+
- remove `pyobs-v4l` package and its dependencies
|
|
32
|
+
- added `gui.py` for V4L camera control with live preview and exposure management
|
|
33
|
+
- added `uv.lock` to track dependencies and Python compatibility for the project
|
|
34
|
+
- migrate to pyproject.toml with PEP 621, add support for pyobs 2.0 and Python 3.11, and configure GitHub Actions for Ruff and PyPI publishing
|
|
35
|
+
- added DEVELOPMENT.md with migration guide for pyobs 2.0
|
|
36
|
+
|
|
37
|
+
## [1.0.0] - 2024-06-05
|
|
38
|
+
|
|
39
|
+
- python 3.12
|
|
40
|
+
- added license
|
|
41
|
+
- added black and pre-commit to dev dependencies
|
|
42
|
+
- added .pre-commit-config.yaml
|
|
43
|
+
- running black
|
|
44
|
+
- added pyproject.toml
|
|
45
|
+
- removed self.closing in all Modules
|
|
46
|
+
- asyncio
|
|
47
|
+
- renamed IWebcam->IVideo and BaseWebcam->BaseVideo
|
|
48
|
+
- changed order
|
|
49
|
+
- initial commit
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Contributing to pyobs-v4l
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing. Bug reports, questions and pull requests are welcome.
|
|
4
|
+
|
|
5
|
+
## Reporting issues
|
|
6
|
+
|
|
7
|
+
Please use the [issue tracker](https://github.com/pyobs/pyobs-v4l/issues). For a bug, include what you did, what you expected, what happened instead, and the version you are running. For larger changes, open an issue first so we can agree on the approach before you spend time on code.
|
|
8
|
+
|
|
9
|
+
## Development setup
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uv sync
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Making a change
|
|
16
|
+
|
|
17
|
+
1. Fork the repository and create a branch from `develop`.
|
|
18
|
+
2. Keep the change focused. Unrelated cleanups belong in a separate pull request.
|
|
19
|
+
3. Add or update tests and documentation where it makes sense.
|
|
20
|
+
4. Run the checks before you push:
|
|
21
|
+
|
|
22
|
+
- `uv run ruff check .`
|
|
23
|
+
- `uv run black --check .`
|
|
24
|
+
- `uv run pyrefly check`
|
|
25
|
+
- `uv run pytest`
|
|
26
|
+
|
|
27
|
+
5. Open a pull request against `develop`, not `main`. CI runs on every pull request.
|
|
28
|
+
|
|
29
|
+
## Releases
|
|
30
|
+
|
|
31
|
+
Releases are cut by the maintainers from `main`. Notable changes are listed in [CHANGELOG.md](CHANGELOG.md).
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
By contributing, you agree that your contributions are licensed under the MIT License of this project.
|
pyobs_v4l-2.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyobs-v4l
|
|
3
|
+
Version: 2.1.1
|
|
4
|
+
Summary: pyobs module for V4L cameras
|
|
5
|
+
Project-URL: Homepage, https://www.pyobs.org
|
|
6
|
+
Project-URL: Documentation, https://docs.pyobs.org
|
|
7
|
+
Project-URL: Repository, https://github.com/pyobs/pyobs-v4l
|
|
8
|
+
Project-URL: Issues, https://github.com/pyobs/pyobs-v4l/issues
|
|
9
|
+
Author-email: Tim-Oliver Husser <thusser@uni-goettingen.de>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Requires-Dist: opencv-python<6,>=4.0
|
|
14
|
+
Requires-Dist: pyobs-core<3,>=2.13.1
|
|
15
|
+
Provides-Extra: gui
|
|
16
|
+
Requires-Dist: pyobs-core[gui]<3,>=2.13.1; extra == 'gui'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
*pyobs* module for Video4Linux cameras
|
|
20
|
+
=======================================
|
|
21
|
+
|
|
22
|
+
This is a [pyobs](https://www.pyobs.org) module for USB webcams and other Video4Linux cameras.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
System dependencies
|
|
26
|
+
--------------------
|
|
27
|
+
On Debian/Ubuntu:
|
|
28
|
+
|
|
29
|
+
sudo apt install libv4l-dev
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Install *pyobs-v4l*
|
|
33
|
+
---------------------
|
|
34
|
+
Clone the repository:
|
|
35
|
+
|
|
36
|
+
git clone https://github.com/pyobs/pyobs-v4l.git
|
|
37
|
+
cd pyobs-v4l
|
|
38
|
+
|
|
39
|
+
Install it with [uv](https://docs.astral.sh/uv/):
|
|
40
|
+
|
|
41
|
+
uv sync
|
|
42
|
+
|
|
43
|
+
Alternatively, with plain `venv`/`pip`:
|
|
44
|
+
|
|
45
|
+
python3 -m venv .venv
|
|
46
|
+
source .venv/bin/activate
|
|
47
|
+
pip install .
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
Configuration
|
|
51
|
+
-------------
|
|
52
|
+
The *v4lCamera* class is derived from *BaseVideo* (see *pyobs* documentation) and adds a single new parameter:
|
|
53
|
+
|
|
54
|
+
device:
|
|
55
|
+
Index of the /dev/videoN device to use (default: 0).
|
|
56
|
+
|
|
57
|
+
A basic module configuration would look like this:
|
|
58
|
+
|
|
59
|
+
class: pyobs_v4l.v4lCamera
|
|
60
|
+
name: V4L camera
|
|
61
|
+
device: 0
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
GUI
|
|
65
|
+
---
|
|
66
|
+
For testing a camera without a full *pyobs* setup, install the optional `gui` extra:
|
|
67
|
+
|
|
68
|
+
uv sync --extra gui
|
|
69
|
+
|
|
70
|
+
and run:
|
|
71
|
+
|
|
72
|
+
uv run v4l-gui
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Dependencies
|
|
76
|
+
------------
|
|
77
|
+
* [pyobs-core](https://github.com/pyobs/pyobs-core) for the core functionality.
|
|
78
|
+
* [OpenCV](https://github.com/opencv/opencv-python) for accessing the camera.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
import threading
|
|
4
|
+
from collections.abc import AsyncGenerator, Callable
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import cv2
|
|
8
|
+
from pyobs.modules.camera import BaseVideo, Frame
|
|
9
|
+
|
|
10
|
+
log = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
# cv2's V4L2 backend calls are blocking and are made directly on the event loop thread (see
|
|
13
|
+
# _run_blocking). If the camera has gone unresponsive, they can hang indefinitely, so they're
|
|
14
|
+
# bounded with a timeout rather than let a single dead camera freeze the whole module.
|
|
15
|
+
_SDK_CALL_TIMEOUT = 5.0
|
|
16
|
+
|
|
17
|
+
# frames() warns if no frame arrived for this long. Frames legitimately take up to the camera's
|
|
18
|
+
# own frame interval, so this is much more generous than _SDK_CALL_TIMEOUT.
|
|
19
|
+
_FRAME_WAIT_TIMEOUT = 30.0
|
|
20
|
+
|
|
21
|
+
# frames queued between the reader thread and the event loop; latest wins beyond that
|
|
22
|
+
_QUEUE_SIZE = 5
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class v4lCamera(BaseVideo):
|
|
26
|
+
"""A pyobs module for V4L2 cameras, e.g. webcams.
|
|
27
|
+
|
|
28
|
+
The device is opened while the module is active and released when it goes to sleep. V4L2
|
|
29
|
+
gives no reliable exposure time or exposure start via OpenCV, so frames carry neither and
|
|
30
|
+
DATE-OBS is the frame's arrival time.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
__module__ = "pyobs_v4l"
|
|
34
|
+
|
|
35
|
+
def __init__(self, device: int = 0, color: bool = False, **kwargs: Any):
|
|
36
|
+
"""Initializes a new v4lCamera.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
device: Index of the V4L2 device, i.e. N in /dev/videoN.
|
|
40
|
+
color: Keep colour frames (RGB, colour as last axis) instead of converting them to
|
|
41
|
+
greyscale. Colour frames work for the live view, but not for grab_stack(), and
|
|
42
|
+
are stored as 3D FITS files.
|
|
43
|
+
"""
|
|
44
|
+
BaseVideo.__init__(self, **kwargs)
|
|
45
|
+
|
|
46
|
+
# store
|
|
47
|
+
self._device = device
|
|
48
|
+
self._color = color
|
|
49
|
+
|
|
50
|
+
async def open(self) -> None:
|
|
51
|
+
"""Open module."""
|
|
52
|
+
await BaseVideo.open(self)
|
|
53
|
+
|
|
54
|
+
# start streaming
|
|
55
|
+
await self.activate_camera()
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
async def _run_blocking(func: Callable[[], None], timeout: float = _SDK_CALL_TIMEOUT) -> bool:
|
|
59
|
+
"""Run a blocking cv2/V4L2 call in a daemon thread, so a hung call can't freeze the module.
|
|
60
|
+
|
|
61
|
+
A plain executor isn't used here, since its worker threads are non-daemon and Python joins
|
|
62
|
+
them on interpreter shutdown -- a hung call would then just move the freeze to process exit.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
True if func completed within timeout, False if it's still running in the background.
|
|
66
|
+
"""
|
|
67
|
+
loop = asyncio.get_running_loop()
|
|
68
|
+
future: asyncio.Future[None] = loop.create_future()
|
|
69
|
+
|
|
70
|
+
def _finish() -> None:
|
|
71
|
+
# wait_for cancels the future on timeout, so guard set_result to avoid an
|
|
72
|
+
# InvalidStateError from the loop thread once the orphaned call finally ends.
|
|
73
|
+
if not future.done():
|
|
74
|
+
future.set_result(None)
|
|
75
|
+
|
|
76
|
+
def _wrapper() -> None:
|
|
77
|
+
try:
|
|
78
|
+
func()
|
|
79
|
+
finally:
|
|
80
|
+
try:
|
|
81
|
+
loop.call_soon_threadsafe(_finish)
|
|
82
|
+
except RuntimeError:
|
|
83
|
+
# event loop closed (shutdown)
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
threading.Thread(target=_wrapper, daemon=True).start()
|
|
87
|
+
try:
|
|
88
|
+
await asyncio.wait_for(future, timeout=timeout)
|
|
89
|
+
return True
|
|
90
|
+
except TimeoutError:
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
async def _open_camera(self) -> Any:
|
|
94
|
+
"""Open the V4L2 camera device, without blocking the event loop.
|
|
95
|
+
|
|
96
|
+
Raises:
|
|
97
|
+
TimeoutError: If opening didn't finish in time.
|
|
98
|
+
RuntimeError: If the device could not be opened.
|
|
99
|
+
"""
|
|
100
|
+
result: list[Any] = []
|
|
101
|
+
lock = threading.Lock()
|
|
102
|
+
timed_out = False
|
|
103
|
+
|
|
104
|
+
def _open() -> None:
|
|
105
|
+
camera = cv2.VideoCapture(self._device)
|
|
106
|
+
with lock:
|
|
107
|
+
if timed_out:
|
|
108
|
+
# timed out while still opening; release the handle nobody will use
|
|
109
|
+
camera.release()
|
|
110
|
+
else:
|
|
111
|
+
result.append(camera)
|
|
112
|
+
|
|
113
|
+
if not await self._run_blocking(_open):
|
|
114
|
+
with lock:
|
|
115
|
+
timed_out = True
|
|
116
|
+
if result:
|
|
117
|
+
result.pop().release()
|
|
118
|
+
raise TimeoutError(f"Timed out opening camera device after {_SDK_CALL_TIMEOUT}s.")
|
|
119
|
+
|
|
120
|
+
# VideoCapture() doesn't raise for a missing/busy device, it just isn't opened
|
|
121
|
+
camera = result[0]
|
|
122
|
+
if not camera.isOpened():
|
|
123
|
+
camera.release()
|
|
124
|
+
raise RuntimeError(f"Could not open camera device {self._device}.")
|
|
125
|
+
return camera
|
|
126
|
+
|
|
127
|
+
def _convert(self, frame: Any) -> Any:
|
|
128
|
+
"""Convert a frame from OpenCV's BGR to greyscale, or to RGB if colour is kept."""
|
|
129
|
+
if frame.ndim != 3:
|
|
130
|
+
return frame
|
|
131
|
+
return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB if self._color else cv2.COLOR_BGR2GRAY)
|
|
132
|
+
|
|
133
|
+
async def frames(self) -> AsyncGenerator[Frame, None]:
|
|
134
|
+
"""Open the device and yield frames until BaseVideo closes the iterator.
|
|
135
|
+
|
|
136
|
+
A single reader thread owns the device for the whole activation, reads frames and hands
|
|
137
|
+
them to the event loop, and releases the device when it's told to stop. A failed read ends
|
|
138
|
+
the iterator with an error, so BaseVideo restarts it with a back-off.
|
|
139
|
+
"""
|
|
140
|
+
loop = asyncio.get_running_loop()
|
|
141
|
+
queue: asyncio.Queue[Frame | BaseException] = asyncio.Queue(maxsize=_QUEUE_SIZE)
|
|
142
|
+
stop = threading.Event()
|
|
143
|
+
camera = await self._open_camera()
|
|
144
|
+
|
|
145
|
+
def _put(item: Frame | BaseException) -> None:
|
|
146
|
+
# latest wins: a stalled event loop mustn't grow memory
|
|
147
|
+
if queue.full():
|
|
148
|
+
queue.get_nowait()
|
|
149
|
+
queue.put_nowait(item)
|
|
150
|
+
|
|
151
|
+
def _read() -> None:
|
|
152
|
+
try:
|
|
153
|
+
while not stop.is_set():
|
|
154
|
+
item: Frame | BaseException
|
|
155
|
+
try:
|
|
156
|
+
# read() returns a fresh array per call, so no copy needed
|
|
157
|
+
ok, frame = camera.read()
|
|
158
|
+
if ok and frame is not None:
|
|
159
|
+
item = Frame(data=self._convert(frame))
|
|
160
|
+
else:
|
|
161
|
+
item = RuntimeError(f"Could not read frame from camera device {self._device}.")
|
|
162
|
+
except Exception as e:
|
|
163
|
+
item = e
|
|
164
|
+
if stop.is_set():
|
|
165
|
+
return
|
|
166
|
+
try:
|
|
167
|
+
loop.call_soon_threadsafe(_put, item)
|
|
168
|
+
except RuntimeError:
|
|
169
|
+
# event loop closed (shutdown)
|
|
170
|
+
return
|
|
171
|
+
if isinstance(item, BaseException):
|
|
172
|
+
return
|
|
173
|
+
finally:
|
|
174
|
+
camera.release()
|
|
175
|
+
|
|
176
|
+
threading.Thread(target=_read, daemon=True).start()
|
|
177
|
+
try:
|
|
178
|
+
while True:
|
|
179
|
+
try:
|
|
180
|
+
item = await asyncio.wait_for(queue.get(), timeout=_FRAME_WAIT_TIMEOUT)
|
|
181
|
+
except TimeoutError:
|
|
182
|
+
log.warning("No frame from camera for %.1fs.", _FRAME_WAIT_TIMEOUT)
|
|
183
|
+
continue
|
|
184
|
+
if isinstance(item, BaseException):
|
|
185
|
+
raise item
|
|
186
|
+
yield item
|
|
187
|
+
finally:
|
|
188
|
+
# don't join the reader: if it hangs in read(), it must not block deactivation; it
|
|
189
|
+
# releases the device itself once read() returns
|
|
190
|
+
stop.set()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
__all__ = ["v4lCamera"]
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyobs-v4l"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.1.1"
|
|
4
4
|
description = "pyobs module for V4L cameras"
|
|
5
5
|
authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }]
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
7
|
license = "MIT"
|
|
8
|
+
readme = "README.md"
|
|
8
9
|
dependencies = [
|
|
9
10
|
"opencv-python>=4.0,<6",
|
|
10
|
-
"pyobs-core>=2.
|
|
11
|
+
"pyobs-core>=2.13.1,<3",
|
|
11
12
|
]
|
|
12
13
|
|
|
14
|
+
[project.urls]
|
|
15
|
+
Homepage = "https://www.pyobs.org"
|
|
16
|
+
Documentation = "https://docs.pyobs.org"
|
|
17
|
+
Repository = "https://github.com/pyobs/pyobs-v4l"
|
|
18
|
+
Issues = "https://github.com/pyobs/pyobs-v4l/issues"
|
|
19
|
+
|
|
13
20
|
[project.optional-dependencies]
|
|
14
21
|
gui = [
|
|
15
|
-
"pyobs-core[gui]>=2.
|
|
22
|
+
"pyobs-core[gui]>=2.13.1,<3",
|
|
16
23
|
]
|
|
17
24
|
|
|
18
25
|
[project.scripts]
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Unit tests for the non-hardware logic in v4lCamera: constructor state, the _run_blocking
|
|
2
|
+
timeout wrapper, device opening and frames(). cv2.VideoCapture is replaced by a fake.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import threading
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import cv2
|
|
10
|
+
import numpy as np
|
|
11
|
+
import numpy.typing as npt
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from pyobs_v4l import v4lCamera
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class FakeCapture:
|
|
18
|
+
"""Stands in for cv2.VideoCapture: frames come from a list, a failed read once it's empty."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, frames: list[npt.NDArray[Any]] | None = None, opened: bool = True) -> None:
|
|
21
|
+
self.frames = [] if frames is None else frames
|
|
22
|
+
self.opened = opened
|
|
23
|
+
self.released = threading.Event()
|
|
24
|
+
|
|
25
|
+
def isOpened(self) -> bool:
|
|
26
|
+
return self.opened
|
|
27
|
+
|
|
28
|
+
def read(self) -> tuple[bool, npt.NDArray[Any] | None]:
|
|
29
|
+
if self.frames:
|
|
30
|
+
return True, self.frames.pop(0)
|
|
31
|
+
return False, None
|
|
32
|
+
|
|
33
|
+
def release(self) -> None:
|
|
34
|
+
self.released.set()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _bgr(b: int, g: int, r: int) -> npt.NDArray[Any]:
|
|
38
|
+
frame = np.zeros((2, 3, 3), dtype=np.uint8)
|
|
39
|
+
frame[:, :] = (b, g, r)
|
|
40
|
+
return frame
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_constructor_defaults() -> None:
|
|
44
|
+
camera = v4lCamera()
|
|
45
|
+
assert camera._device == 0
|
|
46
|
+
assert camera._color is False
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_constructor_device() -> None:
|
|
50
|
+
camera = v4lCamera(device=3)
|
|
51
|
+
assert camera._device == 3
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.mark.asyncio
|
|
55
|
+
async def test_run_blocking_runs_func_and_returns_true() -> None:
|
|
56
|
+
ran: list[bool] = []
|
|
57
|
+
|
|
58
|
+
def fast() -> None:
|
|
59
|
+
ran.append(True)
|
|
60
|
+
|
|
61
|
+
assert await v4lCamera._run_blocking(fast) is True
|
|
62
|
+
assert ran == [True]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.mark.asyncio
|
|
66
|
+
async def test_run_blocking_times_out() -> None:
|
|
67
|
+
done = threading.Event()
|
|
68
|
+
|
|
69
|
+
def slow() -> None:
|
|
70
|
+
done.wait()
|
|
71
|
+
|
|
72
|
+
assert await v4lCamera._run_blocking(slow, timeout=0.01) is False
|
|
73
|
+
done.set()
|
|
74
|
+
await asyncio.sleep(0.05) # let the daemon thread drain before the loop closes
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.mark.asyncio
|
|
78
|
+
async def test_open_camera_raises_if_not_opened(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
79
|
+
fake = FakeCapture(opened=False)
|
|
80
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
81
|
+
|
|
82
|
+
with pytest.raises(RuntimeError, match="Could not open"):
|
|
83
|
+
await v4lCamera()._open_camera()
|
|
84
|
+
assert fake.released.is_set()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.asyncio
|
|
88
|
+
async def test_frames_yields_greyscale_and_releases_on_close(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
89
|
+
fake = FakeCapture([_bgr(0, 0, 255), _bgr(255, 0, 0)] + [_bgr(0, 0, 0)] * 100)
|
|
90
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
91
|
+
camera = v4lCamera()
|
|
92
|
+
|
|
93
|
+
iterator = camera.frames()
|
|
94
|
+
first, second = await anext(iterator), await anext(iterator)
|
|
95
|
+
await iterator.aclose()
|
|
96
|
+
|
|
97
|
+
assert first.data.shape == (2, 3) and second.data.shape == (2, 3)
|
|
98
|
+
# BGR, not RGB: pure red is brighter than pure blue in greyscale
|
|
99
|
+
assert int(first.data[0, 0]) > int(second.data[0, 0])
|
|
100
|
+
assert first.start is None and first.exposure_time is None
|
|
101
|
+
assert fake.released.wait(1.0)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@pytest.mark.asyncio
|
|
105
|
+
async def test_frames_keeps_colour_as_rgb(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
106
|
+
fake = FakeCapture([_bgr(1, 2, 3)] * 10)
|
|
107
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
108
|
+
camera = v4lCamera(color=True)
|
|
109
|
+
|
|
110
|
+
iterator = camera.frames()
|
|
111
|
+
frame = await anext(iterator)
|
|
112
|
+
await iterator.aclose()
|
|
113
|
+
|
|
114
|
+
assert frame.data.shape == (2, 3, 3)
|
|
115
|
+
assert tuple(frame.data[0, 0]) == (3, 2, 1)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@pytest.mark.asyncio
|
|
119
|
+
async def test_frames_raises_on_failed_read(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
120
|
+
fake = FakeCapture([])
|
|
121
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
122
|
+
camera = v4lCamera()
|
|
123
|
+
|
|
124
|
+
iterator = camera.frames()
|
|
125
|
+
with pytest.raises(RuntimeError, match="Could not read frame"):
|
|
126
|
+
await anext(iterator)
|
|
127
|
+
assert fake.released.wait(1.0)
|
|
@@ -2340,7 +2340,7 @@ wheels = [
|
|
|
2340
2340
|
|
|
2341
2341
|
[[package]]
|
|
2342
2342
|
name = "pyobs-core"
|
|
2343
|
-
version = "2.
|
|
2343
|
+
version = "2.13.1"
|
|
2344
2344
|
source = { registry = "https://pypi.org/simple" }
|
|
2345
2345
|
dependencies = [
|
|
2346
2346
|
{ name = "aiohttp" },
|
|
@@ -2372,9 +2372,9 @@ dependencies = [
|
|
|
2372
2372
|
{ name = "tenacity" },
|
|
2373
2373
|
{ name = "typing-extensions" },
|
|
2374
2374
|
]
|
|
2375
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2375
|
+
sdist = { url = "https://files.pythonhosted.org/packages/b2/43/99e30a5a0e42bc49396b876b945ff8c0b8320141f5dcaea959a329c42eaf/pyobs_core-2.13.1.tar.gz", hash = "sha256:54001d7e096dfec2ab1a90cad5d45d35b0d74a28c679266eb88feb1c4045a34f", size = 450687, upload-time = "2026-09-29T08:48:42.267Z" }
|
|
2376
2376
|
wheels = [
|
|
2377
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2377
|
+
{ url = "https://files.pythonhosted.org/packages/6a/18/c9eab05e2e78ec6554c4166f1decde3f6274ab6529c9459ee796acff9bfc/pyobs_core-2.13.1-py3-none-any.whl", hash = "sha256:3afd1de36f35d87f49baca1ab0360d1a2f36cd313e29027fdb5679c4f52df897", size = 689504, upload-time = "2026-09-29T08:48:40.59Z" },
|
|
2378
2378
|
]
|
|
2379
2379
|
|
|
2380
2380
|
[package.optional-dependencies]
|
|
@@ -2386,7 +2386,7 @@ gui = [
|
|
|
2386
2386
|
|
|
2387
2387
|
[[package]]
|
|
2388
2388
|
name = "pyobs-v4l"
|
|
2389
|
-
version = "2.
|
|
2389
|
+
version = "2.1.1"
|
|
2390
2390
|
source = { editable = "." }
|
|
2391
2391
|
dependencies = [
|
|
2392
2392
|
{ name = "opencv-python" },
|
|
@@ -2411,8 +2411,8 @@ dev = [
|
|
|
2411
2411
|
[package.metadata]
|
|
2412
2412
|
requires-dist = [
|
|
2413
2413
|
{ name = "opencv-python", specifier = ">=4.0,<6" },
|
|
2414
|
-
{ name = "pyobs-core", specifier = ">=2.
|
|
2415
|
-
{ name = "pyobs-core", extras = ["gui"], marker = "extra == 'gui'", specifier = ">=2.
|
|
2414
|
+
{ name = "pyobs-core", specifier = ">=2.13.1,<3" },
|
|
2415
|
+
{ name = "pyobs-core", extras = ["gui"], marker = "extra == 'gui'", specifier = ">=2.13.1,<3" },
|
|
2416
2416
|
]
|
|
2417
2417
|
provides-extras = ["gui"]
|
|
2418
2418
|
|
|
@@ -2437,21 +2437,21 @@ wheels = [
|
|
|
2437
2437
|
|
|
2438
2438
|
[[package]]
|
|
2439
2439
|
name = "pyrefly"
|
|
2440
|
-
version = "1.
|
|
2440
|
+
version = "1.3.1"
|
|
2441
2441
|
source = { registry = "https://pypi.org/simple" }
|
|
2442
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2442
|
+
sdist = { url = "https://files.pythonhosted.org/packages/4c/7e/082cc1b392318bacfbc087732524f3e089e9e7fe45b7645c4649b6f1f1e9/pyrefly-1.3.1.tar.gz", hash = "sha256:b774f1dfac82867fc16fe2175d80a630e2a72a6835d5b7e492568d6bfb6b05e7", size = 6679145, upload-time = "2026-09-15T05:09:34.49Z" }
|
|
2443
2443
|
wheels = [
|
|
2444
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2445
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2446
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2447
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2448
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2449
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2450
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2451
|
-
{ url = "https://files.pythonhosted.org/packages/5d/
|
|
2452
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2453
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2454
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2444
|
+
{ url = "https://files.pythonhosted.org/packages/6b/bc/f09b5bd7eed796349bd93627aa2c3086df7ed0a114dafc3d2b2841599ee7/pyrefly-1.3.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:0a2a7dfed824fb066aa8a7c8d856c152b98e998fb84b954d5f892fb9834c0bd1", size = 15090117, upload-time = "2026-09-15T05:08:58.477Z" },
|
|
2445
|
+
{ url = "https://files.pythonhosted.org/packages/78/24/a31e7de8e0f310c9f0753826d0df8b6a8ff86793941a6bd88ba24b735633/pyrefly-1.3.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:37a1a1fb41e7190fe3964a877875dd809d6ee2887809e2c3d6e5f25a69805bfd", size = 14430773, upload-time = "2026-09-15T05:09:01.67Z" },
|
|
2446
|
+
{ url = "https://files.pythonhosted.org/packages/75/e1/022352beb186f36d6213a95a975c42676ee418ff5e730629378d25564c5e/pyrefly-1.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:45b7650bc651a5a784701f2fb4f579da9a421c4d1b5fd91f9048f4529e46093c", size = 14877762, upload-time = "2026-09-15T05:09:04.767Z" },
|
|
2447
|
+
{ url = "https://files.pythonhosted.org/packages/19/2c/d62a1b445aad1fd46375b83393b8a67da53883aeeba73d269ce71b3e8fd1/pyrefly-1.3.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ad57f38bc73679c14a5f62995a2bd3bc43649b7270c858487e2eab78a6f95362", size = 16118225, upload-time = "2026-09-15T05:09:07.828Z" },
|
|
2448
|
+
{ url = "https://files.pythonhosted.org/packages/32/67/3c3fa8a13e3ce8d8322ffb3627255a41a52261f17793e1a24e9214f10857/pyrefly-1.3.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3506b1252e9f5d755d0693c5a46d46b85579d36534f6e22a41eb8e098d0dde90", size = 16051197, upload-time = "2026-09-15T05:09:10.81Z" },
|
|
2449
|
+
{ url = "https://files.pythonhosted.org/packages/19/d1/84f81b9e32288b5d11c75e006f67e0f6b78b85da575673bd1a21524c8172/pyrefly-1.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:39d5a17c1ad655e5f93a6e8e0be90b8db28c6015fe07d6ed4e054891c9e14ef8", size = 15440062, upload-time = "2026-09-15T05:09:14.641Z" },
|
|
2450
|
+
{ url = "https://files.pythonhosted.org/packages/46/3c/2aa0c5ad6a2957a728bb38cfab70d1e9cafad21b0b1c1d92df74a3cf22bd/pyrefly-1.3.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:c61e9dcf888beb81ca0e0c60ea4442640fdcf2f1f65bfe3d9f5d89b85516eb03", size = 14898534, upload-time = "2026-09-15T05:09:17.823Z" },
|
|
2451
|
+
{ url = "https://files.pythonhosted.org/packages/03/5d/2974f249fb2e285f966485719d977c5a2248cc4866403af94d935775ff15/pyrefly-1.3.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a78eed1c53f37807f0e2997be8edbe833b91eb9915f2cb553a1bdcd599e7105c", size = 15477758, upload-time = "2026-09-15T05:09:20.964Z" },
|
|
2452
|
+
{ url = "https://files.pythonhosted.org/packages/68/79/d31f8f0abf5b0610ec24183286ee8a1ee5b76c9aaaa91091399d7e1aaf60/pyrefly-1.3.1-py3-none-win32.whl", hash = "sha256:ea0d0349f1bc80fe8e00a7b3640e40db7486398b685f87b9bd5d2207063668f0", size = 14133005, upload-time = "2026-09-15T05:09:25.03Z" },
|
|
2453
|
+
{ url = "https://files.pythonhosted.org/packages/3f/23/1859f47f536314755d80c4ec2a76d2698435ae8b73604bcd1dfa57ecb39b/pyrefly-1.3.1-py3-none-win_amd64.whl", hash = "sha256:4c24e7d99df9237916c33be23714219a7c8eaf22bad2ac0c3e1d45adcf7df8fb", size = 15066557, upload-time = "2026-09-15T05:09:28.265Z" },
|
|
2454
|
+
{ url = "https://files.pythonhosted.org/packages/92/2a/73e3721921c2bb2c950a9f8c362ee5e2367556b5d4416eb4f8f88503e66f/pyrefly-1.3.1-py3-none-win_arm64.whl", hash = "sha256:1ed85e2b957a78e93353125d890ce3668ce450e49b74025a15c87b6e8ec7f3d1", size = 14348209, upload-time = "2026-09-15T05:09:31.422Z" },
|
|
2455
2455
|
]
|
|
2456
2456
|
|
|
2457
2457
|
[[package]]
|
|
@@ -2734,27 +2734,27 @@ wheels = [
|
|
|
2734
2734
|
|
|
2735
2735
|
[[package]]
|
|
2736
2736
|
name = "ruff"
|
|
2737
|
-
version = "0.16.
|
|
2738
|
-
source = { registry = "https://pypi.org/simple" }
|
|
2739
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2740
|
-
wheels = [
|
|
2741
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2742
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2743
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2744
|
-
{ url = "https://files.pythonhosted.org/packages/24/
|
|
2745
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2746
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2747
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2748
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2749
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2750
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2751
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2752
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2753
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2754
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2755
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2756
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2757
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2737
|
+
version = "0.16.9"
|
|
2738
|
+
source = { registry = "https://pypi.org/simple" }
|
|
2739
|
+
sdist = { url = "https://files.pythonhosted.org/packages/96/bf/c935ca98e73fe8ce65b87ef08a280c0c1e85295d569228c15e87d8fdfaf1/ruff-0.16.9.tar.gz", hash = "sha256:12b625c6cfba78d285d9f48eda5f053374f1e53cb10ef17342a383750db99161", size = 4948764, upload-time = "2026-09-24T20:37:49.416Z" }
|
|
2740
|
+
wheels = [
|
|
2741
|
+
{ url = "https://files.pythonhosted.org/packages/0d/26/df51322b52ee1ada7eff2d071ea09d11d5c2d1dcc9f02594f5785c4d1635/ruff-0.16.9-py3-none-linux_armv6l.whl", hash = "sha256:95e6f022090368ab3b824c36276839c53b2adf1a3f4c09fefc33dfc400f6da96", size = 10082922, upload-time = "2026-09-24T20:37:13.045Z" },
|
|
2742
|
+
{ url = "https://files.pythonhosted.org/packages/a5/27/7bf51f5a7aa375e9f339280a303aab44ca75dc1525f1cdc5991761685b0f/ruff-0.16.9-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:a5f27be168556594a86d2f415db0cf43f5291917849318f873c7e2791f7a8c67", size = 10236360, upload-time = "2026-09-24T20:37:16.049Z" },
|
|
2743
|
+
{ url = "https://files.pythonhosted.org/packages/b6/63/09659283f92f02dff45809da194a70da2f688d87c55d8875c4fae3536072/ruff-0.16.9-py3-none-macosx_11_0_arm64.whl", hash = "sha256:1632eb1d6197f33bd00b1acbc5b71009e89a8895c158e2d2b03a834fac964ab6", size = 9892940, upload-time = "2026-09-24T20:37:17.957Z" },
|
|
2744
|
+
{ url = "https://files.pythonhosted.org/packages/24/58/98de1b72ec172f5f8f1731236fe21585b3998bf7dfe9fcc44ae9ba626012/ruff-0.16.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b3f951b14d865d5952c89d40a5ca07e87abe24fa5453299878411e127748fb1c", size = 10032114, upload-time = "2026-09-24T20:37:19.942Z" },
|
|
2745
|
+
{ url = "https://files.pythonhosted.org/packages/c8/7d/f1e17c54ab59d4bad1dce8ee3e22a7a1d0ef4745240decacdcf3832b5bb2/ruff-0.16.9-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:447fc07e1573afff7cb02803462b12b6c8ece7cf10e2cd78565fa6d7a1c0bf8d", size = 9910227, upload-time = "2026-09-24T20:37:21.872Z" },
|
|
2746
|
+
{ url = "https://files.pythonhosted.org/packages/34/19/436f647a65075bbd3bab2668b3bdaa5120559b294694018cdcefabbbf30b/ruff-0.16.9-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8a3e039a6a40ed976c491722b60e0ae4a4aa1a86057f540ee7a37a5d19ae9120", size = 10547484, upload-time = "2026-09-24T20:37:24.229Z" },
|
|
2747
|
+
{ url = "https://files.pythonhosted.org/packages/03/59/38430a6bc2f6d8095447ac39625cf8b6e9344a47e6c26225c8ba1bff3ffb/ruff-0.16.9-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4684dded7db60aa57cb118fa158630f5feade4af5782903b6053484bdf9bd129", size = 11412367, upload-time = "2026-09-24T20:37:26.307Z" },
|
|
2748
|
+
{ url = "https://files.pythonhosted.org/packages/c8/bd/bbb6d7fc7f208c8b8c50dd5dc8206e4cfdb1e7a8fb852606a3adf370c880/ruff-0.16.9-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d29c934357e45642fda2f34c0b1f4025b4a6c01e15e4bf0016879d60078a142c", size = 10869787, upload-time = "2026-09-24T20:37:28.35Z" },
|
|
2749
|
+
{ url = "https://files.pythonhosted.org/packages/bc/b8/9c543074918061abbefc3bd139bee22de35abedb00dde0f2d27288838962/ruff-0.16.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a21713e629d3e5bdb2f5c2def1cc7f04f47fa8e1a7eb0571b4a28e1da64bc728", size = 10406494, upload-time = "2026-09-24T20:37:30.624Z" },
|
|
2750
|
+
{ url = "https://files.pythonhosted.org/packages/35/7a/5a8851bd146e7ccf8fd4b003f6c75c11f8fbdb0e60673b45097986b6bf41/ruff-0.16.9-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:7baa24ef5fc8e77aa93879e1d3f43754a01ae488e869f1ae30cf431afd4d2452", size = 10590083, upload-time = "2026-09-24T20:37:32.439Z" },
|
|
2751
|
+
{ url = "https://files.pythonhosted.org/packages/87/f0/4c3467188f23f806960b46fa76575a7cd0514c9ba90562650b71efc96980/ruff-0.16.9-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:a41aac6230aadfaa133bdfa1614488531ffa3e0837567ae04c0da2058a9c0f9e", size = 10119151, upload-time = "2026-09-24T20:37:34.581Z" },
|
|
2752
|
+
{ url = "https://files.pythonhosted.org/packages/15/34/5a4def5adea572ce6aea0bb64f21f928ee317b80e0db747d7979b01d7261/ruff-0.16.9-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:c2529fb5896d49115b0e9aa8f887490b34bbe76baf879ec2264ac59406869ce7", size = 9911544, upload-time = "2026-09-24T20:37:36.796Z" },
|
|
2753
|
+
{ url = "https://files.pythonhosted.org/packages/62/5d/d15ebea7499eef9373318c0ee6ca127832927c6529731f6d48e18dce7ca9/ruff-0.16.9-py3-none-musllinux_1_2_i686.whl", hash = "sha256:41e3870277694177429b56406d65dfbdb2c2802c52b715edaf6a0b829c69d4ee", size = 10269884, upload-time = "2026-09-24T20:37:38.857Z" },
|
|
2754
|
+
{ url = "https://files.pythonhosted.org/packages/d1/56/c5d3cd119ded7a3c7aba0e961b69cb3df701c91662c98ad694467d060ce1/ruff-0.16.9-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:8adbe4e58af167f767d7b2ba5e83c42e878350796cf78c2f5e14ab9903a92588", size = 10749366, upload-time = "2026-09-24T20:37:41.042Z" },
|
|
2755
|
+
{ url = "https://files.pythonhosted.org/packages/ac/fe/734ec7527029ac757ecf821f143c9f3fcf69149c21f53a044a899b430f5a/ruff-0.16.9-py3-none-win32.whl", hash = "sha256:0e1dbc2073624dee6618d41d0098690a7244654af746704b64759e12b6b6b385", size = 10152355, upload-time = "2026-09-24T20:37:43.025Z" },
|
|
2756
|
+
{ url = "https://files.pythonhosted.org/packages/14/21/26e4643629b3ebb44f0a06f9c9a53058d63d989415f63a9a3c28e2ee7f22/ruff-0.16.9-py3-none-win_amd64.whl", hash = "sha256:6bd40fec8cd4c8a3d4dd589bd8ad4e6320c13c29234159bfd959a40d529d597b", size = 10592965, upload-time = "2026-09-24T20:37:44.944Z" },
|
|
2757
|
+
{ url = "https://files.pythonhosted.org/packages/51/60/5fb1a39dbb5ae314d5f59bc7348a63c1d5c20f3cd83914c4b5cb0be31d2d/ruff-0.16.9-py3-none-win_arm64.whl", hash = "sha256:ed1a252039200f57a59eebc063b54beabea67bfbaaca0eeaa7f54b5fbcda2284", size = 10458649, upload-time = "2026-09-24T20:37:46.882Z" },
|
|
2758
2758
|
]
|
|
2759
2759
|
|
|
2760
2760
|
[[package]]
|
pyobs_v4l-2.0.0.dev7/PKG-INFO
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: pyobs-v4l
|
|
3
|
-
Version: 2.0.0.dev7
|
|
4
|
-
Summary: pyobs module for V4L cameras
|
|
5
|
-
Author-email: Tim-Oliver Husser <thusser@uni-goettingen.de>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Requires-Python: >=3.11
|
|
9
|
-
Requires-Dist: opencv-python<6,>=4.0
|
|
10
|
-
Requires-Dist: pyobs-core<3,>=2.0.0.dev48
|
|
11
|
-
Provides-Extra: gui
|
|
12
|
-
Requires-Dist: pyobs-core[gui]<3,>=2.0.0.dev48; extra == 'gui'
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import logging
|
|
3
|
-
import threading
|
|
4
|
-
import time
|
|
5
|
-
from collections.abc import Callable
|
|
6
|
-
from typing import Any
|
|
7
|
-
|
|
8
|
-
import cv2
|
|
9
|
-
from pyobs.modules.camera import BaseVideo
|
|
10
|
-
|
|
11
|
-
log = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
# cv2's V4L2 backend calls are blocking and are made directly on the event loop thread (see
|
|
14
|
-
# _run_blocking). If the camera has gone unresponsive, they can hang indefinitely, so they're
|
|
15
|
-
# bounded with a timeout rather than let a single dead camera freeze the whole module.
|
|
16
|
-
_SDK_CALL_TIMEOUT = 5.0
|
|
17
|
-
|
|
18
|
-
# read() waits for the next frame, which can legitimately take a while depending on the camera's
|
|
19
|
-
# own frame rate -- a more generous timeout than _SDK_CALL_TIMEOUT so normal operation never trips it.
|
|
20
|
-
_FRAME_WAIT_TIMEOUT = 30.0
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class v4lCamera(BaseVideo):
|
|
24
|
-
def __init__(self, device: int = 0, **kwargs: Any):
|
|
25
|
-
BaseVideo.__init__(self, **kwargs)
|
|
26
|
-
|
|
27
|
-
# store
|
|
28
|
-
self._device = device
|
|
29
|
-
|
|
30
|
-
# thread
|
|
31
|
-
self.add_background_task(self._capture)
|
|
32
|
-
|
|
33
|
-
@staticmethod
|
|
34
|
-
async def _run_blocking(func: Callable[[], None], timeout: float = _SDK_CALL_TIMEOUT) -> bool:
|
|
35
|
-
"""Run a blocking cv2/V4L2 call in a daemon thread, so a hung call can't freeze the module.
|
|
36
|
-
|
|
37
|
-
A plain executor isn't used here, since its worker threads are non-daemon and Python joins
|
|
38
|
-
them on interpreter shutdown -- a hung call would then just move the freeze to process exit.
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
True if func completed within timeout, False if it's still running in the background.
|
|
42
|
-
"""
|
|
43
|
-
loop = asyncio.get_running_loop()
|
|
44
|
-
future: asyncio.Future[None] = loop.create_future()
|
|
45
|
-
|
|
46
|
-
def _finish() -> None:
|
|
47
|
-
# wait_for cancels the future on timeout, so guard set_result to avoid an
|
|
48
|
-
# InvalidStateError from the loop thread once the orphaned call finally ends.
|
|
49
|
-
if not future.done():
|
|
50
|
-
future.set_result(None)
|
|
51
|
-
|
|
52
|
-
def _wrapper() -> None:
|
|
53
|
-
try:
|
|
54
|
-
func()
|
|
55
|
-
finally:
|
|
56
|
-
loop.call_soon_threadsafe(_finish)
|
|
57
|
-
|
|
58
|
-
threading.Thread(target=_wrapper, daemon=True).start()
|
|
59
|
-
try:
|
|
60
|
-
await asyncio.wait_for(future, timeout=timeout)
|
|
61
|
-
return True
|
|
62
|
-
except TimeoutError:
|
|
63
|
-
return False
|
|
64
|
-
|
|
65
|
-
async def _open_camera(self) -> Any:
|
|
66
|
-
"""Open the V4L2 camera device, without blocking the event loop."""
|
|
67
|
-
result: list[Any] = []
|
|
68
|
-
lock = threading.Lock()
|
|
69
|
-
timed_out = False
|
|
70
|
-
|
|
71
|
-
def _open() -> None:
|
|
72
|
-
camera = cv2.VideoCapture(self._device)
|
|
73
|
-
with lock:
|
|
74
|
-
if timed_out:
|
|
75
|
-
# timed out while still opening; release the handle nobody will use
|
|
76
|
-
camera.release()
|
|
77
|
-
else:
|
|
78
|
-
result.append(camera)
|
|
79
|
-
|
|
80
|
-
if not await self._run_blocking(_open):
|
|
81
|
-
with lock:
|
|
82
|
-
timed_out = True
|
|
83
|
-
if result:
|
|
84
|
-
result.pop().release()
|
|
85
|
-
raise TimeoutError(f"Timed out opening camera device after {_SDK_CALL_TIMEOUT}s.")
|
|
86
|
-
return result[0]
|
|
87
|
-
|
|
88
|
-
async def _read_frame(self, camera: Any) -> Any:
|
|
89
|
-
"""Read the next frame from the camera, without blocking the event loop.
|
|
90
|
-
|
|
91
|
-
Returns:
|
|
92
|
-
The next frame, or None if the read timed out.
|
|
93
|
-
"""
|
|
94
|
-
result: list[Any] = []
|
|
95
|
-
|
|
96
|
-
def _read() -> None:
|
|
97
|
-
_, frame = camera.read()
|
|
98
|
-
result.append(frame)
|
|
99
|
-
|
|
100
|
-
if not await self._run_blocking(_read, timeout=_FRAME_WAIT_TIMEOUT):
|
|
101
|
-
log.error("Timed out reading frame after %.1fs.", _FRAME_WAIT_TIMEOUT)
|
|
102
|
-
return None
|
|
103
|
-
return result[0]
|
|
104
|
-
|
|
105
|
-
async def _capture(self) -> None:
|
|
106
|
-
# open camera
|
|
107
|
-
camera = await self._open_camera()
|
|
108
|
-
|
|
109
|
-
# loop until the background task is cancelled on close
|
|
110
|
-
last = time.time()
|
|
111
|
-
try:
|
|
112
|
-
while True:
|
|
113
|
-
# read frame
|
|
114
|
-
frame = await self._read_frame(camera)
|
|
115
|
-
if frame is None:
|
|
116
|
-
continue
|
|
117
|
-
|
|
118
|
-
# if time since last image is too short, wait a little
|
|
119
|
-
if time.time() - last < self._interval:
|
|
120
|
-
await asyncio.sleep(0.01)
|
|
121
|
-
continue
|
|
122
|
-
last = time.time()
|
|
123
|
-
|
|
124
|
-
# process it
|
|
125
|
-
await self._set_image(frame)
|
|
126
|
-
finally:
|
|
127
|
-
# release camera
|
|
128
|
-
camera.release()
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
__all__ = ["v4lCamera"]
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"""Unit tests for the non-hardware logic in v4lCamera: constructor state and the
|
|
2
|
-
_run_blocking timeout wrapper.
|
|
3
|
-
|
|
4
|
-
Opening the V4L2 device and reading frames is out of scope here.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import asyncio
|
|
8
|
-
import threading
|
|
9
|
-
|
|
10
|
-
import pytest
|
|
11
|
-
|
|
12
|
-
from pyobs_v4l import v4lCamera
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def test_constructor_defaults() -> None:
|
|
16
|
-
camera = v4lCamera()
|
|
17
|
-
assert camera._device == 0
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def test_constructor_device() -> None:
|
|
21
|
-
camera = v4lCamera(device=3)
|
|
22
|
-
assert camera._device == 3
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@pytest.mark.asyncio
|
|
26
|
-
async def test_run_blocking_runs_func_and_returns_true() -> None:
|
|
27
|
-
ran: list[bool] = []
|
|
28
|
-
|
|
29
|
-
def fast() -> None:
|
|
30
|
-
ran.append(True)
|
|
31
|
-
|
|
32
|
-
assert await v4lCamera._run_blocking(fast) is True
|
|
33
|
-
assert ran == [True]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
@pytest.mark.asyncio
|
|
37
|
-
async def test_run_blocking_times_out() -> None:
|
|
38
|
-
done = threading.Event()
|
|
39
|
-
|
|
40
|
-
def slow() -> None:
|
|
41
|
-
done.wait()
|
|
42
|
-
|
|
43
|
-
assert await v4lCamera._run_blocking(slow, timeout=0.01) is False
|
|
44
|
-
done.set()
|
|
45
|
-
await asyncio.sleep(0.05) # let the daemon thread drain before the loop closes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|