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

Fix balena cam #97

Open
wants to merge 3 commits 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
14 changes: 8 additions & 6 deletions balena-cam/Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM balenalib/raspberrypi3-debian:stretch-20190612
FROM balenalib/raspberrypi3-debian:buster

# Install dependencies
RUN apt-get update && \
Expand All @@ -16,8 +16,8 @@ RUN apt-get update && \
libatlas3-base \
libatlas-base-dev \
libjasper-dev \
libilmbase12 \
libopenexr22 \
libilmbase23 \
libopenexr23 \
libavformat-dev \
libswscale-dev \
libqtgui4 \
Expand All @@ -29,9 +29,11 @@ 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 pyee==8.2.2 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 python3 -m pip install --upgrade pip setuptools wheel
RUN python3 -m pip install async-timeout av --index-url https://www.piwheels.org/simple
RUN python3 -m pip install -U aiohttp[speedups] aiohttp_basicauth aioice aiortc numpy opencv-python-headless --index-url https://www.piwheels.org/simple


WORKDIR /usr/src/app

Expand Down
13 changes: 7 additions & 6 deletions balena-cam/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch-20190612
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:buster

# Install dependencies
RUN apt-get update && \
Expand All @@ -16,8 +16,8 @@ RUN apt-get update && \
libatlas3-base \
libatlas-base-dev \
libjasper-dev \
libilmbase12 \
libopenexr22 \
libilmbase23 \
libopenexr23 \
libavformat-dev \
libswscale-dev \
libqtgui4 \
Expand All @@ -29,9 +29,10 @@ 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 pyee==8.2.2 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 python3 -m pip install --upgrade pip setuptools wheel
RUN python3 -m pip install async-timeout av --index-url https://www.piwheels.org/simple
RUN python3 -m pip install -U aiohttp[speedups] aiohttp_basicauth aioice aiortc numpy opencv-python-headless --index-url https://www.piwheels.org/simple

WORKDIR /usr/src/app

Expand Down
13 changes: 10 additions & 3 deletions balena-cam/app/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio, json, os, cv2, platform, sys
import asyncio, json, os, cv2, platform, subprocess, sys
from time import sleep
from aiohttp import web
from av import VideoFrame
Expand Down Expand Up @@ -165,10 +165,17 @@ async def on_shutdown(app):
await asyncio.gather(*coros)

def checkDeviceReadiness():
# TODO : check user is in video group !
# TODO : check if we are on a RPI
if not os.path.exists('/dev/video0') and platform.system() == 'Linux':
print('Video device is not ready')
print('Trying to load bcm2835-v4l2 driver...')
os.system('bash -c "modprobe bcm2835-v4l2"')
try:
subprocess.run(['modprobe', 'bcm2835-v4l2'], check=True)
except FileNotFoundError:
print("Cannot modeprobe bcm2835-v4l2, not a Raspberry-Pi ?")
except subprocess.CalledProcessError as err:
print(err)
sleep(1)
sys.exit()
else:
Expand Down Expand Up @@ -202,7 +209,7 @@ def checkDeviceReadiness():
print('Set the username and password environment variables \nto enable authorization.')
print('For more info visit: \nhttps://github.com/balena-io-playground/balena-cam')
print('#############################################################\n')

# Factory to create peerConnections depending on the iceServers set by user
pc_factory = PeerConnectionFactory()

Expand Down