Beispiel #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")
Beispiel #2
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",
            )
Beispiel #3
0
    def __init__(self,
                 parent,
                 source,
                 size=None,
                 layer=0,
                 alpha=255,
                 fullscreen=True,
                 window=None,
                 crop=None,
                 rotation=0,
                 vflip=False,
                 hflip=False):
        super(PiOverlayRenderer,
              self).__init__(parent, layer, alpha, fullscreen, window, crop,
                             rotation, vflip, hflip)

        # Copy format from camera's preview port, then adjust the encoding to
        # RGB888 and optionally adjust the resolution and size
        port = self.renderer[0].input[0]
        fmt = port[0].format
        mmal.mmal_format_copy(
            fmt,
            parent._camera[0].output[parent.CAMERA_PREVIEW_PORT][0].format)
        fmt[0].encoding = mmal.MMAL_ENCODING_RGB24
        fmt[0].encoding_variant = mmal.MMAL_ENCODING_RGB24
        if size is not None:
            w, h = size
            fmt[0].es[0].video.width = mmal.VCOS_ALIGN_UP(w, 32)
            fmt[0].es[0].video.height = mmal.VCOS_ALIGN_UP(h, 16)
            fmt[0].es[0].video.crop.width = w
            fmt[0].es[0].video.crop.height = h
        mmal_check(mmal.mmal_port_format_commit(port),
                   prefix="Overlay format couldn't be set")
        port[0].buffer_num = port[0].buffer_num_min
        port[0].buffer_size = port[0].buffer_size_recommended

        mmal_check(mmal.mmal_component_enable(self.renderer),
                   prefix="Overlay couldn't be enabled")

        mmal_check(mmal.mmal_port_enable(port, _overlay_callback),
                   prefix="Overlay input port couldn't be enabled")

        self.pool = mmal.mmal_port_pool_create(port, port[0].buffer_num,
                                               port[0].buffer_size)
        if not self.pool:
            raise PiCameraRuntimeError("Couldn't create pool for overlay")

        self.update(source)
Beispiel #4
0
    def __init__(
            self, parent, source, size=None, layer=0, alpha=255,
            fullscreen=True, window=None, crop=None, rotation=0, vflip=False,
            hflip=False):
        super(PiOverlayRenderer, self).__init__(
            parent, layer, alpha, fullscreen, window, crop,
            rotation, vflip, hflip)

        # Copy format from camera's preview port, then adjust the encoding to
        # RGB888 and optionally adjust the resolution and size
        port = self.renderer[0].input[0]
        fmt = port[0].format
        mmal.mmal_format_copy(
            fmt, parent._camera[0].output[parent.CAMERA_PREVIEW_PORT][0].format)
        fmt[0].encoding = mmal.MMAL_ENCODING_RGB24
        fmt[0].encoding_variant = mmal.MMAL_ENCODING_RGB24
        if size is not None:
            w, h = size
            fmt[0].es[0].video.width = mmal.VCOS_ALIGN_UP(w, 32)
            fmt[0].es[0].video.height = mmal.VCOS_ALIGN_UP(h, 16)
            fmt[0].es[0].video.crop.width = w
            fmt[0].es[0].video.crop.height = h
        mmal_check(
            mmal.mmal_port_format_commit(port),
            prefix="Overlay format couldn't be set")
        port[0].buffer_num = port[0].buffer_num_min
        port[0].buffer_size = port[0].buffer_size_recommended

        mmal_check(
            mmal.mmal_component_enable(self.renderer),
            prefix="Overlay couldn't be enabled")

        mmal_check(
            mmal.mmal_port_enable(port, _overlay_callback),
            prefix="Overlay input port couldn't be enabled")

        self.pool = mmal.mmal_port_pool_create(
            port, port[0].buffer_num, port[0].buffer_size)
        if not self.pool:
            raise PiCameraRuntimeError("Couldn't create pool for overlay")

        self.update(source)
Beispiel #5
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")
Beispiel #6
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")