def _callback_write(self, buf): """ Performs output writing on behalf of the encoder callback function; return value determines whether writing has completed. """ if buf[0].length: mmal_check(mmal.mmal_buffer_header_mem_lock(buf), prefix="Unable to lock buffer header memory") try: with self.lock: if self.output: written = self.output.write(ct.string_at(buf[0].data, buf[0].length)) # Ignore None return value; most Python 2 streams have # no return value for write() if (written is not None) and (written != buf[0].length): raise PiCameraError("Unable to write buffer to file - aborting") finally: mmal.mmal_buffer_header_mem_unlock(buf) return bool(buf[0].flags & mmal.MMAL_BUFFER_HEADER_FLAG_EOS)
def _callback_write(self, buf): """ Performs output writing on behalf of the encoder callback function; return value determines whether writing has completed. """ if buf[0].length: mmal_check( mmal.mmal_buffer_header_mem_lock(buf), prefix="Unable to lock buffer header memory") try: with self.lock: if self.output and self.output.write( ct.string_at(buf[0].data, buf[0].length)) != buf[0].length: raise PiCameraError( "Unable to write buffer to file - aborting") finally: mmal.mmal_buffer_header_mem_unlock(buf) return False
def _callback_write(self, buf): # Overridden to strip alpha bytes when necessary, and manually # calculate the frame end if buf[0].length and self._image_size: mmal_check(mmal.mmal_buffer_header_mem_lock(buf), prefix="Unable to lock buffer header memory") try: s = ct.string_at(buf[0].data, buf[0].length) if self._strip_alpha: s = b"".join(s[i : i + 3] for i in range(0, len(s), 4)) with self.lock: if self.output: written = self.output.write(s) # Ignore None return value; most Python 2 streams have # no return value for write() if (written is not None) and (written != len(s)): raise PiCameraError("Unable to write buffer to file - aborting") self._image_size -= len(s) assert self._image_size >= 0 finally: mmal.mmal_buffer_header_mem_unlock(buf) return self._image_size <= 0
def _callback_write(self, buf): """ Performs output writing on behalf of the encoder callback function; return value determines whether writing has completed. """ if buf[0].length: mmal_check(mmal.mmal_buffer_header_mem_lock(buf), prefix="Unable to lock buffer header memory") try: with self.lock: if self.output: written = self.output.write( ct.string_at(buf[0].data, buf[0].length)) # Ignore None return value; most Python 2 streams have # no return value for write() if (written is not None) and (written != buf[0].length): raise PiCameraError( "Unable to write buffer to file - aborting") finally: mmal.mmal_buffer_header_mem_unlock(buf) return bool(buf[0].flags & mmal.MMAL_BUFFER_HEADER_FLAG_EOS)
def _callback_write(self, buf): # Overridden to strip alpha bytes when necessary, and manually # calculate the frame end if buf[0].length and self._image_size: mmal_check(mmal.mmal_buffer_header_mem_lock(buf), prefix="Unable to lock buffer header memory") try: s = ct.string_at(buf[0].data, buf[0].length) if self._strip_alpha: s = b''.join(s[i:i + 3] for i in range(0, len(s), 4)) with self.lock: if self.output: written = self.output.write(s) # Ignore None return value; most Python 2 streams have # no return value for write() if (written is not None) and (written != len(s)): raise PiCameraError( "Unable to write buffer to file - aborting") self._image_size -= len(s) assert self._image_size >= 0 finally: mmal.mmal_buffer_header_mem_unlock(buf) return self._image_size <= 0