示例#1
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()
示例#2
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()