Example #1
0
    def start(self, output):
        """
        Starts the encoder object writing to the specified output
        """
        self.event.clear()
        self.stopped = False
        self.exception = None
        self._open_output(output)
        self.output_port[0].userdata = ct.cast(ct.pointer(ct.py_object(self)),
                                               ct.c_void_p)
        mmal_check(mmal.mmal_port_enable(self.output_port, _encoder_callback),
                   prefix="Failed to enable encoder output port")

        for q in range(mmal.mmal_queue_length(self.pool[0].queue)):
            buf = mmal.mmal_queue_get(self.pool[0].queue)
            if not buf:
                raise PiCameraRuntimeError(
                    "Unable to get a required buffer from pool queue")
            mmal_check(mmal.mmal_port_send_buffer(self.output_port, buf),
                       prefix="Unable to send a buffer to encoder output port")
        b = mmal.MMAL_BOOL_T()
        mmal_check(mmal.mmal_port_parameter_get_boolean(
            self.camera_port, mmal.MMAL_PARAMETER_CAPTURE, b),
                   prefix="Failed to query capture status")
        self.started_capture = not bool(b)
        if self.started_capture:
            mmal_check(mmal.mmal_port_parameter_set_boolean(
                self.camera_port, mmal.MMAL_PARAMETER_CAPTURE, mmal.MMAL_TRUE),
                       prefix="Failed to start capture")
Example #2
0
    def update(self, source):
        """
        Update the overlay with a new source of data.

        The new *source* buffer must have the same size as the original buffer
        used to create the overlay. There is currently no method for changing
        the size of an existing overlay (remove and recreate the overlay if you
        require this).
        """
        port = self.renderer[0].input[0]
        fmt = port[0].format
        bp = ct.c_uint8 * (fmt[0].es[0].video.width *
                           fmt[0].es[0].video.height * 3)
        try:
            sp = bp.from_buffer(source)
        except TypeError:
            sp = bp.from_buffer_copy(source)
        buf = mmal.mmal_queue_get(self.pool[0].queue)
        if not buf:
            raise PiCameraRuntimeError(
                "Couldn't get a buffer from the overlay's pool")
        ct.memmove(buf[0].data, sp, buf[0].alloc_size)
        buf[0].length = buf[0].alloc_size
        mmal_check(mmal.mmal_port_send_buffer(port, buf),
                   prefix="Unable to send a buffer to the overlay's port")
Example #3
0
    def start(self, output):
        """
        Starts the encoder object writing to the specified output
        """
        self.event.clear()
        self.stopped = False
        self.exception = None
        self._open_output(output)
        self.output_port[0].userdata = ct.cast(ct.pointer(ct.py_object(self)), ct.c_void_p)
        mmal_check(
            mmal.mmal_port_enable(self.output_port, _encoder_callback), prefix="Failed to enable encoder output port"
        )

        for q in range(mmal.mmal_queue_length(self.pool[0].queue)):
            buf = mmal.mmal_queue_get(self.pool[0].queue)
            if not buf:
                raise PiCameraRuntimeError("Unable to get a required buffer from pool queue")
            mmal_check(
                mmal.mmal_port_send_buffer(self.output_port, buf),
                prefix="Unable to send a buffer to encoder output port",
            )
        b = mmal.MMAL_BOOL_T()
        mmal_check(
            mmal.mmal_port_parameter_get_boolean(self.camera_port, mmal.MMAL_PARAMETER_CAPTURE, b),
            prefix="Failed to query capture status",
        )
        self.started_capture = not bool(b)
        if self.started_capture:
            mmal_check(
                mmal.mmal_port_parameter_set_boolean(self.camera_port, mmal.MMAL_PARAMETER_CAPTURE, mmal.MMAL_TRUE),
                prefix="Failed to start capture",
            )
Example #4
0
    def update(self, source):
        """
        Update the overlay with a new source of data.

        The new *source* buffer must have the same size as the original buffer
        used to create the overlay. There is currently no method for changing
        the size of an existing overlay (remove and recreate the overlay if you
        require this).
        """
        port = self.renderer[0].input[0]
        fmt = port[0].format
        bp = ct.c_uint8 * (fmt[0].es[0].video.width * fmt[0].es[0].video.height * 3)
        try:
            sp = bp.from_buffer(source)
        except TypeError:
            sp = bp.from_buffer_copy(source)
        buf = mmal.mmal_queue_get(self.pool[0].queue)
        if not buf:
            raise PiCameraRuntimeError(
                "Couldn't get a buffer from the overlay's pool")
        ct.memmove(buf[0].data, sp, buf[0].alloc_size)
        buf[0].length = buf[0].alloc_size
        mmal_check(
            mmal.mmal_port_send_buffer(port, buf),
            prefix="Unable to send a buffer to the overlay's port")
Example #5
0
 def _callback_recycle(self, port, buf):
     """
     Recycles the buffer on behalf of the encoder callback function
     """
     new_buf = mmal.mmal_queue_get(self.pool[0].queue)
     if not new_buf:
         raise PiCameraError("Unable to get a buffer to return to the encoder port")
     mmal_check(mmal.mmal_port_send_buffer(port, new_buf), prefix="Unable to return a buffer to the encoder port")
Example #6
0
 def _callback_recycle(self, port, buf):
     """
     Recycles the buffer on behalf of the encoder callback function
     """
     new_buf = mmal.mmal_queue_get(self.pool[0].queue)
     if not new_buf:
         raise PiCameraError(
             "Unable to get a buffer to return to the encoder port")
     mmal_check(mmal.mmal_port_send_buffer(port, new_buf),
                prefix="Unable to return a buffer to the encoder port")
Example #7
0
    def start(self, output):
        """
        Starts the encoder object writing to the specified output
        """
        self.event.clear()
        self.stopped = False
        self.exception = None
        self._open_output(output)
        self.output_port[0].userdata = ct.cast(ct.pointer(ct.py_object(self)),
                                               ct.c_void_p)
        mmal_check(mmal.mmal_port_enable(self.output_port, _encoder_callback),
                   prefix="Failed to enable encoder output port")

        for q in range(mmal.mmal_queue_length(self.pool[0].queue)):
            buf = mmal.mmal_queue_get(self.pool[0].queue)
            if not buf:
                raise PiCameraRuntimeError(
                    "Unable to get a required buffer from pool queue")
            mmal_check(mmal.mmal_port_send_buffer(self.output_port, buf),
                       prefix="Unable to send a buffer to encoder output port")
Example #8
0
    def start(self, output):
        """
        Starts the encoder object writing to the specified output
        """
        self.event.clear()
        self.stopped = False
        self.exception = None
        self._open_output(output)
        self.output_port[0].userdata = ct.cast(
            ct.pointer(ct.py_object(self)),
            ct.c_void_p)
        mmal_check(
            mmal.mmal_port_enable(self.output_port, _encoder_callback),
            prefix="Failed to enable encoder output port")

        for q in range(mmal.mmal_queue_length(self.pool[0].queue)):
            buf = mmal.mmal_queue_get(self.pool[0].queue)
            if not buf:
                raise PiCameraRuntimeError(
                    "Unable to get a required buffer from pool queue")
            mmal_check(
                mmal.mmal_port_send_buffer(self.output_port, buf),
                prefix="Unable to send a buffer to encoder output port")