def _callback_write(self, buf, key=PiVideoFrameType.frame):
"""
Overridden to strip alpha bytes when required.
"""
if self._strip_alpha:
s = ct.string_at(buf[0].data, buf[0].length)
s = bytearray(s)
del s[3::4]
# All this messing around with buffers is to work around some issue
# with MMAL or ctypes (I'm not sure which is at fault). Anyway, the
# upshot is that if you fiddle with buf[0].data in any way
# whatsoever (even if you make every attempt to restore its value
# afterward), mmal_port_disable locks up when we call it in stop()
new_buf = mmal.MMAL_BUFFER_HEADER_T.from_buffer_copy(buf[0])
new_buf.length = len(s)
new_buf.data = ct.pointer(ct.c_uint8.from_buffer(s))
return super(PiRawMixin, self)._callback_write(ct.pointer(new_buf), key)
else:
return super(PiRawMixin, self)._callback_write(buf, key)
评论列表
文章目录