aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormorefigs <morefigs@gmail.com>2019-02-09 15:58:11 +1100
committermorefigs <morefigs@gmail.com>2019-02-09 15:58:11 +1100
commit367295804b27d3eeef27bb85826426828a6bda03 (patch)
tree646b75ee748bd09f97f01cd0ce773a4b3c4ab543
parentec95851f68d24e4201d4698a2657d90a174c05fa (diff)
downloadpymba-367295804b27d3eeef27bb85826426828a6bda03.tar.gz
pymba-367295804b27d3eeef27bb85826426828a6bda03.zip
remove memory block class
-rw-r--r--pymba/frame.py45
1 files changed, 15 insertions, 30 deletions
diff --git a/pymba/frame.py b/pymba/frame.py
index 7a4bb3b..b7803aa 100644
--- a/pymba/frame.py
+++ b/pymba/frame.py
@@ -7,23 +7,6 @@ from .vimba_exception import VimbaException
from . import vimba_c
-class MemoryBlock:
- """
- A memory block object for dealing neatly with C memory allocations.
- """
-
- @property
- def block(self):
- return c_void_p(addressof(self._block))
-
- def __init__(self, block_size):
- self._block = create_string_buffer(block_size)
-
- # this seems to be None if too much memory is requested
- if self._block is None:
- raise VimbaException(VimbaException.ERR_FRAME_BUFFER_MEMORY)
-
-
class Frame:
"""
A Vimba frame.
@@ -34,7 +17,7 @@ class Frame:
self._vmb_frame = vimba_c.VmbFrame()
- self._c_mem = None
+ self._c_memory = None
self._frame_callback = None
self._frame_callback_wrapper_c = None
@@ -47,18 +30,20 @@ class Frame:
Announce frames to the API that may be queued for frame capturing later. Should be called after the frame is
created. Call startCapture after this method.
"""
- # keep this reference to keep block alive for life of frame
- self._c_mem = MemoryBlock(self._camera.PayloadSize)
-
- # set buffer to have length of expected payload size
- self._vmb_frame.buffer = self._c_mem.block
+ # allocate memory for the frame and keep a reference to keep alive
+ self._c_memory = create_string_buffer(self._camera.PayloadSize)
+ address = c_void_p(addressof(self._c_memory))
+ if address is None:
+ # this seems to be None if too much memory is requested
+ raise VimbaException(VimbaException.ERR_FRAME_BUFFER_MEMORY)
- # set buffer size to expected payload size
- self._vmb_frame.bufferSize = self._camera.PayloadSize
+ # tell the frame about the memory
+ self.data.buffer = address
+ self.data.bufferSize = self._camera.PayloadSize
error = vimba_c.vmb_frame_announce(self._camera.handle,
- byref(self._vmb_frame),
- sizeof(self._vmb_frame))
+ byref(self.data),
+ sizeof(self.data))
if error:
raise VimbaException(error)
@@ -67,7 +52,7 @@ class Frame:
Revoke a frame from the API.
"""
error = vimba_c.vmb_frame_revoke(self._camera.handle,
- byref(self._vmb_frame))
+ byref(self.data))
if error:
raise VimbaException(error)
@@ -92,7 +77,7 @@ class Frame:
self._frame_callback_wrapper_c = vimba_c.vmb_frame_callback_func(frame_callback_wrapper)
error = vimba_c.vmb_capture_frame_queue(self._camera.handle,
- byref(self._vmb_frame),
+ byref(self.data),
self._frame_callback_wrapper_c)
if error:
raise VimbaException(error)
@@ -103,7 +88,7 @@ class Frame:
:param timeout_ms: time out in milliseconds.
"""
error = vimba_c.vmb_capture_frame_wait(self._camera.handle,
- byref(self._vmb_frame),
+ byref(self.data),
timeout_ms)
if error:
raise VimbaException(error)