5d1eaedb38
Реализует subscriber-side wrapper над cuframes_subscriber_* и
cuframes_frame_* C API.
Что добавлено:
- CuframesFrame — owning RAII wrapper над cuframes_frame_t*
- properties: cuda_ptr, format, width, height, pitch_y, pitch_uv,
seq, pts_ns, released
- release() idempotent
- context manager (__enter__/__exit__) — release при выходе
- после release() property access бросает CuframesError
- CuframesSubscriber — owning RAII wrapper над cuframes_subscriber_t*
- конструктор с key/consumer_name/mode/cuda_device/connect_timeout_ms
- next_frame(timeout_ms) → CuframesFrame
- close() idempotent
- context manager
- GIL released на блокирующих вызовах (create, next_frame)
- subscribe() — module-level factory shortcut
Архитектурные решения:
- GIL release в py::gil_scoped_release на subscriber_create и _next —
чтобы другие Python потоки могли работать пока ждём frame
- consumer_stream передаётся как nullptr в Phase 0 (default stream);
per-subscriber stream в task #201
- Frame держит raw pointer на subscriber, refcount Python-стороной;
если subscriber уничтожен раньше, frame.release() становится no-op
Smoke tests расширены до 8 — добавлены проверки exposed API и
error mapping на subscribe к несуществующему publisher'у.
Verify: pytest tests/test_smoke.py — 8/8 passed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
cuframes — Python bindings
Status: WIP (Phase 0 skeleton — issue gx/cuframes#6)
Это пакет Python-обёрток над libcuframes (C ABI). Цель — позволить
downstream ML/CV пайплайнам (yolo-world-detector, zone-motion, custom
скриптам) подписываться на cuframes без CPU round-trip: получать NV12
frames прямо как CUDA pointer / torch.Tensor (DLPack export, zero-copy).
Текущий статус (что уже работает в этом skeleton)
- Module import:
import cuframesзагружает_native.so - Версия:
cuframes.version_string(),cuframes.protocol_version() - Enums:
PixelFormat,SubscriberMode - Иерархия исключений:
CuframesError+ 8 subclasses (publisher gone, frame timeout, device lost, и т. д.)
Что в работе (см. tasks #198-#202)
CuframesSubscriber+CuframesFramelifecycle- DLPack export →
torch.from_dlpack,cupy.from_dlpack - Context manager (
with cuframes.subscribe(key) as sub:) - Per-subscriber CUDA stream
- Health/stats properties (
ring_occupancy,drop_count) - Thread-safety contract документация
Build (dev)
Standalone wheel:
cd python/
pip install -e . --no-build-isolation
Через корневой CMake-проект (вместе с libcuframes):
cmake -B build -DBUILD_PYTHON_BINDINGS=ON
cmake --build build -j
Зависимости
libcuframes≥ 0.4 (линкуется из соседнего CMake target)- CUDA Toolkit 12+
pybind112.13+ (берётся через FetchContent при CMake-сборке)- Python 3.10+
- Опционально:
torch>=2.4илиcupy-cuda12x>=13для DLPack-потребителей
Лицензия
LGPL-2.1+ (как у libcuframes).