Exemplo n.º 1
0
    def __init__(self, name, interval, api, input_source, extra_arguments=None):
        """Init image processing."""
        from haffmpeg import ImageStream, ImageSingle

        super().__init__(name, interval, api)
        self._input_source = input_source
        self._extra_arguments = extra_arguments

        if self._interval > 0:
            self._ffmpeg = ImageStream(get_binary(), self._process_image)
        else:
            self._ffmpeg = ImageSingle(get_binary())

        self._start_ffmpeg()
Exemplo n.º 2
0
    def __init__(self, name, interval, api, input_source,
                 extra_arguments=None):
        """Init image processing."""
        from haffmpeg import ImageStream, ImageSingle

        super().__init__(name, interval, api)
        self._input_source = input_source
        self._extra_arguments = extra_arguments

        if self._interval > 0:
            self._ffmpeg = ImageStream(get_binary(), self._process_image)
        else:
            self._ffmpeg = ImageSingle(get_binary())

        self._start_ffmpeg()
Exemplo n.º 3
0
    def camera_image(self):
        """Return a still image response from the camera."""
        from haffmpeg import ImageSingle, IMAGE_JPEG
        ffmpeg = ImageSingle(get_binary())

        return ffmpeg.get_image(self._input, output_format=IMAGE_JPEG,
                                extra_cmd=self._extra_arguments)
Exemplo n.º 4
0
    def handle_async_mjpeg_stream(self, request):
        """Generate an HTTP MJPEG stream from the camera."""
        from haffmpeg import CameraMjpegAsync

        stream = CameraMjpegAsync(get_binary(), loop=self.hass.loop)
        yield from stream.open_camera(
            self._input, extra_cmd=self._extra_arguments)

        response = web.StreamResponse()
        response.content_type = 'multipart/x-mixed-replace;boundary=ffserver'

        yield from response.prepare(request)

        try:
            while True:
                data = yield from stream.read(102400)
                if not data:
                    break
                response.write(data)

        except asyncio.CancelledError:
            _LOGGER.debug("Close stream by frontend.")
            response = None

        finally:
            yield from stream.close()
            if response is not None:
                yield from response.write_eof()
Exemplo n.º 5
0
    def __init__(self, ffobj, config):
        """Constructor for binary sensor noise detection."""
        self._state = False
        self._config = config
        self._name = config.get(CONF_NAME)
        self._ffmpeg = ffobj(get_binary(), self._callback)

        self._start_ffmpeg(config)
Exemplo n.º 6
0
    def __init__(self, ffobj, config):
        """Constructor for binary sensor noise detection."""
        self._state = False
        self._config = config
        self._name = config.get(CONF_NAME)
        self._ffmpeg = ffobj(get_binary(), self._callback)

        self._start_ffmpeg(config)
Exemplo n.º 7
0
    def camera_image(self):
        """Return a still image response from the camera."""
        from haffmpeg import ImageSingle, IMAGE_JPEG
        ffmpeg = ImageSingle(get_binary())

        return ffmpeg.get_image(self._input,
                                output_format=IMAGE_JPEG,
                                extra_cmd=self._extra_arguments)
Exemplo n.º 8
0
    def async_camera_image(self):
        """Return a still image response from the camera."""
        from haffmpeg import ImageSingleAsync, IMAGE_JPEG
        ffmpeg = ImageSingleAsync(get_binary(), loop=self.hass.loop)

        image = yield from ffmpeg.get_image(
            self._input, output_format=IMAGE_JPEG,
            extra_cmd=self._extra_arguments)
        return image
Exemplo n.º 9
0
    def mjpeg_stream(self, response):
        """Generate an HTTP MJPEG stream from the camera."""
        from haffmpeg import CameraMjpeg

        stream = CameraMjpeg(get_binary())
        stream.open_camera(self._input, extra_cmd=self._extra_arguments)
        return response(stream,
                        mimetype='multipart/x-mixed-replace;boundary=ffserver',
                        direct_passthrough=True)
Exemplo n.º 10
0
    def mjpeg_stream(self, response):
        """Generate an HTTP MJPEG stream from the camera."""
        from haffmpeg import CameraMjpeg

        stream = CameraMjpeg(get_binary())
        stream.open_camera(self._input, extra_cmd=self._extra_arguments)
        return response(
            stream,
            mimetype='multipart/x-mixed-replace;boundary=ffserver',
            direct_passthrough=True
        )
Exemplo n.º 11
0
    def handle_async_mjpeg_stream(self, request):
        """Generate an HTTP MJPEG stream from the camera."""
        from haffmpeg import CameraMjpegAsync

        stream = CameraMjpegAsync(get_binary(), loop=self.hass.loop)
        yield from stream.open_camera(
            self._input, extra_cmd=self._extra_arguments)

        response = web.StreamResponse()
        response.content_type = 'multipart/x-mixed-replace;boundary=ffserver'

        yield from response.prepare(request)

        try:
            while True:
                data = yield from stream.read(102400)
                if not data:
                    break
                response.write(data)
        finally:
            self.hass.async_add_job(stream.close())
            yield from response.write_eof()