Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Update balenacam to comply with new version of aiortc and aioice #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions balena-cam/Dockerfile.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions balena-cam/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions balena-cam/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down