Raspberry Pi Zero 2 WでWebRTC momoを動かしてみる

環境:RaspiOS Bullseye ( legacy cameraはdisable )

カメラ:

前回、libcamera経由でv4l2が使えるようになったようなので、 (前回: libcameraのv4l2 compatibleを通してraw streamを取得 - しゅれログ

今回はWebRTCのOSSである「momo」を動かしてみる。

github.com

これはlibcameraが言うところのNative V4L2 ApplicationのひとつであるのでV4L2 Compat.を効かせると 動くようになるはず。( Documentation — libcamera)

あらかじめ、libcameraをインストールしてあり(ソースからビルドした) 環境変数bashrcに

export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/v4l2-compat.so

を設定。

それより先はmomoのReadmeに記載のとおりである。

@raspberrypi:~/momo/momo $ ./momo --no-audio-device test
[5:24:58.823385711] [2070]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3777-69ae75b0
[5:24:58.893045982] [2071]  WARN RPI raspberrypi.cpp:1252 Mismatch between Unicam and CamHelper for embedded data usage!
[5:24:58.894332078] [2071]  INFO RPI raspberrypi.cpp:1368 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media3 and ISP device /dev/media0
[5:24:58.949636126] [2070]  INFO Camera camera.cpp:1029 configuring streams: (0) 640x480-YUV420
[5:24:58.950713055] [2071]  INFO RPI raspberrypi.cpp:759 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 640x480-SBGGR10_1X10 - Selected unicam format: 640x480-pBAA
[5:24:58.954716812] [2070]  INFO Camera camera.cpp:1029 configuring streams: (0) 640x480-YUV420
[5:24:58.955501865] [2071]  INFO RPI raspberrypi.cpp:759 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 640x480-SBGGR10_1X10 - Selected unicam format: 640x480-pBAA

IPアドレス:8080/html/test.htmlにアクセスしてConnect

H264でConnectしてるときのCPU使用率は40%程度(1論理CPUに対して、ということであるが)

raspberrypi:~ $ lscpu
Architecture:                    armv7l
Byte Order:                      Little Endian
CPU(s):                          4
...
top - 22:08:34 up  5:29,  3 users,  load average: 0.38, 0.28, 0.11
Tasks: 133 total,   1 running, 132 sleeping,   0 stopped,   0 zombie
%Cpu(s):  8.5 us,  2.1 sy,  0.0 ni, 89.4 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
MiB Mem :    364.7 total,    137.6 free,     87.7 used,    139.4 buff/cache
MiB Swap:   1024.0 total,   1007.7 free,     16.2 used.    225.7 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                      
 2070 heyanao+  20   0  174416  27948  14336 S  39.9   7.5   1:41.70 momo                                                         
  230 root       0 -20       0      0      0 I   1.3   0.0   2:03.06 kworker/u9:1-brcmf_wq/mmc1:0001:1                            
 2116 heyanao+  20   0   25144   9400   8216 R   1.3   2.5   0:00.43 top                                                          
   75 root       1 -19       0      0      0 S   1.0   0.0   0:58.30 vchiq-slot/0                                                 
 2095 root      20   0       0      0      0 I   0.7   0.0   0:00.80 kworker/0:0-events                                           
  177 root      10 -10       0      0      0 S   0.3   0.0   0:14.76 SMIO                                                         
  227 root      20   0       0      0      0 S   0.3   0.0   0:08.29 brcmf_wdog/mmc1                                              
 2114 root      20   0       0      0      0 I   0.3   0.0   0:00.03 kworker/2:1-events

繋いでないときは30%程度でした。