diff --git a/balena-cam/Dockerfile.aarch64 b/balena-cam/Dockerfile.aarch64 index 1d9c772..ee3cb73 100644 --- a/balena-cam/Dockerfile.aarch64 +++ b/balena-cam/Dockerfile.aarch64 @@ -30,8 +30,8 @@ RUN apt-get update && \ # Enable the v4l2 driver for the Raspberry Pi camera #RUN printf "bcm2835-v4l2\n" >> /etc/modules RUN pip3 install --upgrade pip -RUN pip3 install async-timeout av==6.1.0 -RUN pip3 install aiohttp aiohttp_basicauth==0.1.3 aioice==0.6.10 aiortc==0.9.11 numpy==1.15.4 opencv-python==3.4.4.19 --index-url https://www.piwheels.org/simple +RUN pip3 install async-timeout av==8.0.0 +RUN pip3 install aiohttp aiohttp_basicauth==0.1.3 aioice==0.7.5 aiortc==1.1.2 numpy==1.15.4 opencv-python==3.4.4.19 --index-url https://www.piwheels.org/simple WORKDIR /usr/src/app diff --git a/balena-cam/Dockerfile.template b/balena-cam/Dockerfile.template index 1b5ed58..7947b71 100644 --- a/balena-cam/Dockerfile.template +++ b/balena-cam/Dockerfile.template @@ -30,8 +30,8 @@ RUN apt-get update && \ # Enable the v4l2 driver for the Raspberry Pi camera #RUN printf "bcm2835-v4l2\n" >> /etc/modules RUN pip3 install --upgrade pip -RUN pip3 install async-timeout av==6.1.0 -RUN pip3 install aiohttp aiohttp_basicauth==0.1.3 aioice==0.6.10 aiortc==0.9.11 numpy==1.15.4 opencv-python==3.4.4.19 --index-url https://www.piwheels.org/simple +RUN pip3 install async-timeout av==8.0.0 +RUN pip3 install aiohttp aiohttp_basicauth==0.1.3 aioice==0.7.5 aiortc==1.1.2 numpy==1.15.4 opencv-python==3.4.4.19 --index-url https://www.piwheels.org/simple WORKDIR /usr/src/app diff --git a/balena-cam/app/server.py b/balena-cam/app/server.py index ad1c55d..83d5583 100644 --- a/balena-cam/app/server.py +++ b/balena-cam/app/server.py @@ -3,6 +3,7 @@ from aiohttp import web from av import VideoFrame from aiortc import RTCPeerConnection, RTCSessionDescription, VideoStreamTrack, RTCIceServer, RTCConfiguration +from aiortc.mediastreams import MediaStreamError from aiohttp_basicauth import BasicAuthMiddleware class CameraDevice(): @@ -78,6 +79,8 @@ def __init__(self, camera_device): self.data_bgr = None async def recv(self): + if self.readyState != "live": + raise MediaStreamError self.data_bgr = await self.camera_device.get_latest_frame() frame = VideoFrame.from_ndarray(self.data_bgr, format='bgr24') pts, time_base = await self.next_timestamp() @@ -118,9 +121,9 @@ async def offer(request): # Add local media local_video = RTCVideoStream(camera_device) pc.addTrack(local_video) - @pc.on('iceconnectionstatechange') - async def on_iceconnectionstatechange(): - if pc.iceConnectionState == 'failed': + @pc.on("connectionstatechange") + async def on_connectionstatechange(): + if pc.connectionState == "failed": await pc.close() pcs.discard(pc) await pc.setRemoteDescription(offer)