Skip to content

Commit c927340

Browse files
committed
chore: run pulseaudio as linux service
1 parent 58f9e24 commit c927340

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Raspberry Pi 5 and other SBCs do not support v4l2 hardware encoding, please run
2424
* Install essential libs
2525
```bash
2626
sudo apt install libmosquitto1 pulseaudio libavformat59 libswscale6
27-
pulseaudio --start
2827
```
2928

3029
* Enable Raspberry Pi Hardware by adding below in `/boot/firmware/config.txt`
@@ -47,16 +46,53 @@ Raspberry Pi 5 and other SBCs do not support v4l2 hardware encoding, please run
4746

4847
## Running the Application
4948

50-
Running `pi_webrtc -h` will display all available options. To start the application, use the following command:
49+
### Run
50+
Running the binary file `pi_webrtc` with the `-h` flag will display all available options. Ensure that your MQTT server is ready before starting the application. To start the application, use the following command:
5151

5252
```bash
53+
# start pulseaudio service
54+
pulseaudio --start
55+
56+
# run main program
5357
/path/to/pi_webrtc --device=/dev/video0 --fps=30 --width=1280 --height=960 --v4l2_format=h264 --hw_accel --mqtt_host=example.s1.eu.hivemq.cloud --mqtt_port=8883 --mqtt_username=hakunamatata --mqtt_password=Wonderful --uid=home-pi-zero2w --record_path=/mnt/ext_disk/video/
5458
```
55-
**For Pi 5**, remove the `--hw_accel` option and set `--v4l2_format` to `mjpeg`. Video encoding will be handled by [OpenH264](https://github.com/cisco/openh264).
59+
60+
**For Pi 5**, remove the `--hw_accel` option and change `--v4l2_format` to `mjpeg`. Video encoding will be handled by [OpenH264](https://github.com/cisco/openh264).
5661

5762
### Run as Linux Service
5863

59-
In order to run `pi_webrtc` and ensure it starts automatically on reboot:
64+
#### 1. Run `pulseaudio` as system-wide daemon [[ref]](https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/):
65+
* create a file `/etc/systemd/system/pulseaudio.service`
66+
```ini
67+
[Unit]
68+
Description= Pulseaudio Daemon
69+
After=rtkit-daemon.service systemd-udevd.service dbus.service
70+
71+
[Service]
72+
Type=simple
73+
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading --log-target=journal
74+
Restart=always
75+
RestartSec=10
76+
77+
[Install]
78+
WantedBy=multi-user.target
79+
```
80+
* Run the cmd to add a `autospawn = no` in the client conf
81+
```bash
82+
echo 'autospawn = no' | sudo tee -a /etc/pulse/client.conf > /dev/null
83+
```
84+
* Add root to pulse group
85+
```bash
86+
sudo adduser root pulse-access
87+
```
88+
* Enable and Start the Service
89+
```bash
90+
sudo systemctl daemon-reload
91+
sudo systemctl enable pulseaudio.service
92+
sudo systemctl start pulseaudio.service
93+
```
94+
95+
#### 2. In order to run `pi_webrtc` and ensure it starts automatically on reboot:
6096
* Create a service file `/etc/systemd/system/pi-webrtc.service` with the following content:
6197
```ini
6298
[Unit]
@@ -66,8 +102,7 @@ In order to run `pi_webrtc` and ensure it starts automatically on reboot:
66102
[Service]
67103
Type=simple
68104
WorkingDirectory=/path/to
69-
ExecStart=/path/to/pi_webrtc --fps=30 --width=1280 --height=960 --v4l2_format=h264 --hw_accel --mqtt_host=example.s1.eu.hivemq.cloud --mqtt_port=8883 --mqtt_username=hakunamatata --mqtt_password=wonderful --record_path=/mnt/ext_disk/video/
70-
ExecStop=/bin/kill -s SIGTERM $MAINPID
105+
ExecStart=/path/to/pi_webrtc --device=/dev/video0 --fps=30 --width=1280 --height=960 --v4l2_format=h264 --hw_accel --mqtt_host=example.s1.eu.hivemq.cloud --mqtt_port=8883 --mqtt_username=hakunamatata --mqtt_password=wonderful --record_path=/mnt/ext_disk/video/
71106
Restart=always
72107
RestartSec=10
73108
@@ -76,6 +111,7 @@ In order to run `pi_webrtc` and ensure it starts automatically on reboot:
76111
```
77112
* Enable and Start the Service
78113
```bash
114+
sudo systemctl daemon-reload
79115
sudo systemctl enable pi-webrtc.service
80116
sudo systemctl start pi-webrtc.service
81117
```

0 commit comments

Comments
 (0)