Skip to content

Commit

Permalink
Merge pull request #35 from tiagocoutinho/video-standards
Browse files Browse the repository at this point in the history
Video standards
  • Loading branch information
tiagocoutinho authored Aug 22, 2024
2 parents 71af39d + fbe57d0 commit 1cdbc41
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
5 changes: 5 additions & 0 deletions linuxpy/video/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,11 @@ def outputs(self):
def controls(self):
return list(iter_read_controls(self.device))

@property
def video_standards(self) -> list[Standard]:
"""List of video standards for the active input"""
return list(iter_read_video_standards(self.device))


class BufferManager(DeviceHelper):
def __init__(self, device: Device, buffer_type: BufferType, size: int = 2):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ show-slowest = 3
[tool.ward.plugins.coverage]
branch = true
omit = ["*test*"]
report_type = ["term", "html", "json", "xml"]
report_type = ["html", "json", "xml"]
report = {skip_empty = true, show_missing = true}


Expand Down
75 changes: 52 additions & 23 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Capability,
ControlClass,
Device,
InputCapabilities,
Memory,
PixelFormat,
Priority,
Expand Down Expand Up @@ -565,6 +566,7 @@ def _(display=hardware):


VIVID_TEST_DEVICES = [Path(f"/dev/video{i}") for i in range(190, 194)]
VIVID_CAPTURE_DEVICE, VIVID_OUTPUT_DEVICE, VIVID_META_CAPTURE_DEVICE, VIVID_META_OUTPUT_DEVICE = VIVID_TEST_DEVICES


@cache
Expand Down Expand Up @@ -597,16 +599,16 @@ def _():
@test_vivid_only("list vivid capture files")
def _():
video_files = list(iter_video_capture_files())
assert VIVID_TEST_DEVICES[0] in video_files
assert VIVID_CAPTURE_DEVICE in video_files
for video_file in VIVID_TEST_DEVICES[1:]:
assert video_file not in video_files


@test_vivid_only("list vivid output files")
def _():
video_files = list(iter_video_output_files())
assert VIVID_TEST_DEVICES[1] in video_files
assert VIVID_TEST_DEVICES[0] not in video_files
assert VIVID_OUTPUT_DEVICE in video_files
assert VIVID_CAPTURE_DEVICE not in video_files
for video_file in VIVID_TEST_DEVICES[2:]:
assert video_file not in video_files

Expand All @@ -623,7 +625,7 @@ def _():
def _():
devices = list(iter_video_capture_devices())
device_names = [dev.filename for dev in devices]
assert VIVID_TEST_DEVICES[0] in device_names
assert VIVID_CAPTURE_DEVICE in device_names
for video_file in VIVID_TEST_DEVICES[1:]:
assert video_file not in device_names

Expand All @@ -632,35 +634,36 @@ def _():
def _():
devices = list(iter_video_output_devices())
device_names = [dev.filename for dev in devices]
assert VIVID_TEST_DEVICES[1] in device_names
assert VIVID_TEST_DEVICES[0] not in device_names
assert VIVID_OUTPUT_DEVICE in device_names
assert VIVID_CAPTURE_DEVICE not in device_names
for video_file in VIVID_TEST_DEVICES[2:]:
assert video_file not in device_names


@test_vivid_only("controls with vivid")
def _():
with Device(VIVID_TEST_DEVICES[0]) as device:
with Device(VIVID_CAPTURE_DEVICE) as device:
controls = device.controls

# Brightness
assert controls.brightness is controls["brightness"]
current_value = controls.brightness.value
assert 0 <= current_value < 250
brightness = controls.brightness
assert brightness is controls["brightness"]
current_value = brightness.value
assert brightness.minimum <= current_value <= brightness.maximum
try:
controls.brightness.value = 100
assert controls.brightness.value == 100
brightness.value = 100
assert brightness.value == 100
finally:
controls.brightness.value = current_value
brightness.value = current_value

with raises(AttributeError):
_ = controls.unknown_field

assert ControlClass.USER in {ctrl.id - 1 for ctrl in controls.used_classes()}
assert controls.brightness in controls.with_class("user")
assert controls.brightness in controls.with_class(ControlClass.USER)
assert brightness in controls.with_class("user")
assert brightness in controls.with_class(ControlClass.USER)

assert "<IntegerControl brightness" in repr(controls.brightness)
assert "<IntegerControl brightness" in repr(brightness)

# String
assert controls.string is controls["string"]
Expand Down Expand Up @@ -694,7 +697,7 @@ def _():

@test_vivid_only("info with vivid")
def _():
with Device(VIVID_TEST_DEVICES[0]) as capture_dev:
with Device(VIVID_CAPTURE_DEVICE) as capture_dev:
dev_caps = capture_dev.info.device_capabilities
assert Capability.VIDEO_CAPTURE in dev_caps
assert Capability.STREAMING in dev_caps
Expand All @@ -705,6 +708,8 @@ def _():
text = repr(capture_dev.info)
assert "driver = " in text

capture_dev.set_input(0)

assert len(capture_dev.info.frame_sizes) > 10
assert len(capture_dev.info.formats) > 10

Expand All @@ -717,8 +722,15 @@ def _():

crop = capture_dev.info.crop_capabilities
assert not crop
for inp in inputs:
capture_dev.set_input(inp.index)
video_standards = capture_dev.info.video_standards
if InputCapabilities.STD in inp.capabilities:
assert video_standards
else:
assert not video_standards

with Device(VIVID_TEST_DEVICES[1]) as output_dev:
with Device(VIVID_OUTPUT_DEVICE) as output_dev:
crop = output_dev.info.crop_capabilities
assert crop
assert BufferType.VIDEO_OUTPUT in crop
Expand All @@ -742,10 +754,27 @@ def _():
outputs = output_dev.info.outputs
assert len(outputs) > 0

with Device(VIVID_META_CAPTURE_DEVICE) as meta_capture_dev:
dev_caps = meta_capture_dev.info.device_capabilities
assert Capability.VIDEO_CAPTURE not in dev_caps
assert Capability.STREAMING in dev_caps
assert Capability.READWRITE in dev_caps
assert Capability.VIDEO_OUTPUT not in dev_caps
assert Capability.META_CAPTURE in dev_caps
assert Capability.META_OUTPUT not in dev_caps

text = repr(meta_capture_dev.info)
assert "driver = " in text

meta_capture_dev.set_input(0)

assert len(meta_capture_dev.info.frame_sizes) == 0
assert len(meta_capture_dev.info.formats) > 0


@test_vivid_only("vivid inputs")
def _():
with Device(VIVID_TEST_DEVICES[0]) as capture_dev:
with Device(VIVID_CAPTURE_DEVICE) as capture_dev:
inputs = capture_dev.info.inputs
assert len(inputs) > 0
active_input = capture_dev.get_input()
Expand Down Expand Up @@ -780,7 +809,7 @@ def test_frame(frame, width, height, pixel_format, source):

@test_vivid_only(f"vivid capture ({iname})")
def _(source=input_type):
with Device(VIVID_TEST_DEVICES[0]) as capture_dev:
with Device(VIVID_CAPTURE_DEVICE) as capture_dev:
capture_dev.set_input(0)
width, height, pixel_format = 640, 480, PixelFormat.RGB24
capture = VideoCapture(capture_dev, source=source)
Expand All @@ -802,7 +831,7 @@ def _(source=input_type):

@test_vivid_only(f"vivid async capture ({iname})")
async def _(source=input_type):
with Device(VIVID_TEST_DEVICES[0]) as capture_dev:
with Device(VIVID_CAPTURE_DEVICE) as capture_dev:
capture_dev.set_input(0)
width, height, pixel_format = 640, 480, PixelFormat.RGB24
capture = VideoCapture(capture_dev, source=source)
Expand All @@ -827,15 +856,15 @@ async def _(source=input_type):

@test_vivid_only("vivid capture no capability")
def _():
with Device(VIVID_TEST_DEVICES[1]) as output_dev:
with Device(VIVID_OUTPUT_DEVICE) as output_dev:
stream = iter(output_dev)
with raises(V4L2Error):
next(stream)


@test_vivid_only("vivid output")
def _():
with Device(VIVID_TEST_DEVICES[1]) as output_dev:
with Device(VIVID_OUTPUT_DEVICE) as output_dev:
width, height, pixel_format = 640, 480, PixelFormat.RGB24
size = width * height * 3
out = VideoOutput(output_dev)
Expand Down

0 comments on commit 1cdbc41

Please sign in to comment.