Skip to content

Commit

Permalink
Tests passing on hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbaker committed Mar 24, 2022
1 parent ccaf5e3 commit 5743253
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
6 changes: 4 additions & 2 deletions mwcapture/libmwcapture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import platform
from ctypes import *
from pathlib import Path

MW_SUCCEEDED = 0
MW_FAILED = 1
Expand Down Expand Up @@ -698,9 +700,9 @@ def __init__(self):
t_bits,t_linkage = platform.architecture()
if platform.system() == "Windows":
if t_bits == '64bit':
self.m_lib_path = "mwcapture\\bin\\x64\\LibMWCapture.dll"
self.m_lib_path = str(Path(os.path.abspath(__file__)).parent.joinpath("bin/x64/LibMWCapture.dll"))
elif t_bits == '32bit':
self.m_lib_path = "mwcapture\\bin\\x86\\LibMWCapture.dll"
self.m_lib_path = str(Path(os.path.abspath(__file__)).parent.joinpath("bin/x86/LibMWCapture.dll"))
else:
raise AssertionError("ERROR:unsupported architecture - %s\n"%(t_bits))
try:
Expand Down
4 changes: 4 additions & 0 deletions pymagewell/events/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ def get_status(self, mw_capture: mw_capture) -> NotificationStatus:
if res != MW_SUCCEEDED:
raise IOError("Could not read status of notification")
return NotificationStatus(status)

@property
def handle(self) -> int:
return self._handle
2 changes: 1 addition & 1 deletion pymagewell/pro_capture_device/device_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def from_mw_video_signal_status(cls, status: mw_video_signal_status) -> "SignalS
image_dimensions=ImageSizeInPixels(cols=status.cx, rows=status.cy),
total_dimensions=ImageSizeInPixels(cols=status.cxTotal, rows=status.cyTotal),
interlaced=bool(status.bInterlaced),
frame_period_s=float(status.dwFrameDuration * 1e-3),
frame_period_s=float(status.dwFrameDuration * 1e-7), # why 1e-7?
aspect_ratio=AspectRatio(ver=status.nAspectY, hor=status.nAspectX),
segmented=bool(status.bSegmentedFrame),
)
Expand Down
2 changes: 1 addition & 1 deletion pymagewell/pro_capture_device/mock_pro_capture_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

MOCK_RESOLUTION = ImageSizeInPixels(cols=1920, rows=1080)
MOCK_ASPECT_RATIO = AspectRatio(hor=16, ver=9)
MOCK_FRAME_RATE_HZ = 60.0
MOCK_FRAME_RATE_HZ = 2


class MockProCaptureDevice(ProCaptureDeviceImpl):
Expand Down
6 changes: 4 additions & 2 deletions pymagewell/pro_capture_device/pro_capture_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,14 @@ def schedule_timer_event(self, device_time_now: mw_device_time) -> None:

if self._frame_expire_time is None:
self._frame_expire_time = device_time_now
self._frame_expire_time.m_ll_device_time.value += int(1e3 * self._device.signal_status.frame_period_s)
self._frame_expire_time.m_ll_device_time.value += int(
1e7 * self._device.signal_status.frame_period_s
) # why 1e7

if self._timer_event.is_registered:
result = self._device.mw_schedule_timer(
self._channel,
self._timer_event.notification, # type: ignore
self._timer_event.notification.handle, # type: ignore
self._frame_expire_time.m_ll_device_time,
)
else:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_capture_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pymagewell.pro_capture_controller import ProCaptureController
from pymagewell.pro_capture_device import ProCaptureDevice
from pymagewell.pro_capture_device.device_interface import ProCaptureDeviceInterface
from pymagewell.pro_capture_device.device_settings import ProCaptureSettings, TransferMode
from pymagewell.pro_capture_device.mock_pro_capture_device import MockProCaptureDevice
from tests.config import MOCK_TEST_MODE
Expand All @@ -15,7 +16,7 @@ def setUp(self) -> None:
device_settings = ProCaptureSettings()
device_settings.transfer_mode = TransferMode.TIMER
if MOCK_TEST_MODE:
self._device = MockProCaptureDevice(device_settings)
self._device: ProCaptureDeviceInterface = MockProCaptureDevice(device_settings)
else:
self._device = ProCaptureDevice(device_settings)

Expand All @@ -37,8 +38,8 @@ def test_frame_size(self) -> None:

def test_frame_period(self) -> None:
times_frames_received = []
for n in range(10):
for _ in range(10):
_ = self._controller.transfer_when_ready(timeout_ms=1000)
times_frames_received.append(perf_counter())
mean_frame_period = diff(array(times_frames_received)).mean()
self.assertAlmostEqual(self._device.signal_status.frame_period_s, mean_frame_period, 2)
self.assertAlmostEqual(self._device.signal_status.frame_period_s, mean_frame_period, 1)
11 changes: 4 additions & 7 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,16 @@ def test_timer_mode_event_registration(self) -> None:
def test_schedule_timer_event(self) -> None:
expected_wait_time = self._device.signal_status.frame_period_s

# First timer event happens immediately
start_time = perf_counter()
# First timer event not necessarily occurring after one frame period, so use second
self._device.schedule_timer_event()
wait_for_event(self._device.events.timer_event, timeout_ms=1000)
time_waited = perf_counter() - start_time
self.assertTrue(time_waited < 0.0015)

# Seconds one happens after 1 frame period
start_time = perf_counter()
second_frame_start_time = perf_counter()
self._device.schedule_timer_event()
wait_for_event(self._device.events.timer_event, timeout_ms=1000)
time_waited = perf_counter() - start_time
self.assertTrue((time_waited > expected_wait_time) and (time_waited < expected_wait_time * 2))
time_waited = perf_counter() - second_frame_start_time
self.assertAlmostEqual(time_waited, expected_wait_time, 2)

def test_frame_transfer(self) -> None:
transfer_buffer = create_string_buffer(3840 * 2160 * 4)
Expand Down

0 comments on commit 5743253

Please sign in to comment.