Skip to content

Commit 6f3638d

Browse files
committed
feat: run multi-signaling service simutaniously
1 parent 837dcf6 commit 6f3638d

File tree

15 files changed

+67
-76
lines changed

15 files changed

+67
-76
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ name: Build
22
on:
33
push:
44
tags:
5-
- 'v**-ubuntu'
5+
- 'v**'
66

77
jobs:
88
build:
99
runs-on: ubuntu-24.04-arm
1010

1111
strategy:
1212
matrix:
13-
signaling: [MQTT, HTTP]
1413
build_type: [Debug, Release]
1514

1615
steps:
@@ -47,17 +46,17 @@ jobs:
4746
- name: Build project
4847
run: |
4948
mkdir build && cd build
50-
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_${{ matrix.signaling }}_SIGNALING=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
49+
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
5150
make -j$(nproc)
5251
5352
- name: Zip binary
5453
id: zip-binary
5554
run: |
5655
cd build
5756
if [ "${{ matrix.build_type }}" == "Release" ]; then
58-
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_ubuntu-24.04-arm64.tar.gz"
57+
FILENAME="pi_webrtc-${{ github.ref_name }}_ubuntu-24.04-arm64.tar.gz"
5958
else
60-
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_ubuntu-24.04-arm64_debug.tar.gz"
59+
FILENAME="pi_webrtc-${{ github.ref_name }}_ubuntu-24.04-arm64_debug.tar.gz"
6160
fi
6261
tar -czvf $FILENAME pi_webrtc
6362
echo "filename=$FILENAME" >> $GITHUB_OUTPUT

.github/workflows/docker_build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ jobs:
8181
needs: prepare-env
8282
strategy:
8383
matrix:
84-
signaling: [MQTT, HTTP]
8584
build_type: [Debug, Release]
8685

8786
steps:
@@ -105,7 +104,7 @@ jobs:
105104
cd /app &&
106105
mkdir -p build &&
107106
cd build &&
108-
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_${{ matrix.signaling }}_SIGNALING=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} &&
107+
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} &&
109108
make -j$(nproc)
110109
"
111110
@@ -114,9 +113,9 @@ jobs:
114113
run: |
115114
cd build
116115
if [ "${{ matrix.build_type }}" == "Release" ]; then
117-
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-env.outputs.raspios_version }}.tar.gz"
116+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ needs.prepare-env.outputs.raspios_version }}.tar.gz"
118117
else
119-
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-env.outputs.raspios_version }}_debug.tar.gz"
118+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ needs.prepare-env.outputs.raspios_version }}_debug.tar.gz"
120119
fi
121120
sudo tar -czvf $FILENAME pi_webrtc
122121
echo "filename=$FILENAME" >> $GITHUB_OUTPUT

.github/workflows/qemu_build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ jobs:
130130
needs: prepare-image
131131
strategy:
132132
matrix:
133-
signaling: [MQTT, HTTP]
134133
build_type: [Debug, Release]
135134

136135
steps:
@@ -171,7 +170,7 @@ jobs:
171170
cd project && \
172171
mkdir build && \
173172
cd build && \
174-
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_${{ matrix.signaling }}_SIGNALING=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} && \
173+
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} && \
175174
make -j$(nproc)
176175
"
177176
sshpass -p "raspberry" scp -P 5555 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null pi@localhost:~/project/build/pi_webrtc .
@@ -180,9 +179,9 @@ jobs:
180179
id: zip-binary
181180
run: |
182181
if [ "${{ matrix.build_type }}" == "Release" ]; then
183-
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-image.outputs.raspios_version }}.tar.gz"
182+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ needs.prepare-image.outputs.raspios_version }}.tar.gz"
184183
else
185-
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-image.outputs.raspios_version }}_debug.tar.gz"
184+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ needs.prepare-image.outputs.raspios_version }}_debug.tar.gz"
186185
fi
187186
sudo tar -czvf $FILENAME pi_webrtc
188187
echo "filename=$FILENAME" >> $GITHUB_OUTPUT

CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ project(pi_webrtc)
33

44
set(CMAKE_CXX_STANDARD 20)
55
set(BUILD_TEST "" CACHE STRING "test")
6-
set(USE_HTTP_SIGNALING OFF CACHE BOOL "Enable HTTP signaling")
7-
set(USE_MQTT_SIGNALING OFF CACHE BOOL "Enable MQTT signaling")
86

97
string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE_LOWER)
108
if(NOT BUILD_TYPE_LOWER OR BUILD_TYPE_LOWER STREQUAL "debug")
@@ -22,18 +20,6 @@ else()
2220
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
2321
endif()
2422

25-
if(USE_HTTP_SIGNALING AND USE_MQTT_SIGNALING)
26-
message(FATAL_ERROR "Please enable only one signaling method (HTTP or MQTT).")
27-
endif()
28-
29-
if(USE_HTTP_SIGNALING)
30-
add_definitions(-DUSE_HTTP_SIGNALING)
31-
message(STATUS "SIGNALING: HTTP(WHEP)")
32-
elseif(USE_MQTT_SIGNALING)
33-
add_definitions(-DUSE_MQTT_SIGNALING)
34-
message(STATUS "SIGNALING: MQTT")
35-
endif()
36-
3723
set(WEBRTC_INCLUDE_DIR /usr/local/include/webrtc)
3824
set(WEBRTC_LIBRARY /usr/local/lib/libwebrtc.a)
3925
set(WEBRTC_LINK_LIBS dl)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ You can use a free cloud MQTT service like [HiveMQ](https://www.hivemq.com) or
9292
--fps=30 \
9393
--width=1280 \
9494
--height=960 \
95+
--use_mqtt \
9596
--mqtt_host=your.mqtt.cloud \
9697
--mqtt_port=8883 \
9798
--mqtt_username=hakunamatata \

doc/BUILD.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,18 @@
2020

2121
| <div style="width:200px">Command line</div> | Default | Valid values |
2222
| --------------------------------------------| ----------- | ------------ |
23-
| -DUSE_MQTT_SIGNALING | OFF | (ON, OFF). Build the project by using MOSQUITTO as signaling. |
24-
| -DUSE_HTTP_SIGNALING | OFF | (ON, OFF). Build the project by using HTTP as signaling. (WHEP) |
2523
| -DBUILD_TEST | | (http_server, recorder, mqtt, v4l2_capture, v4l2_encoder, v4l2_decoder, v4l2_scaler). Build the test codes |
2624
| -DCMAKE_BUILD_TYPE | Debug | (Debug, Release) |
2725

2826
Build on raspberry pi and it'll output a `pi_webrtc` file in `/build`.
2927
```bash
3028
mkdir build
3129
cd build
32-
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DUSE_MQTT_SIGNALING=ON -DCMAKE_BUILD_TYPE=Release
30+
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_BUILD_TYPE=Release
3331
make -j
3432
```
3533
3634
Run `pi_webrtc` to start the service.
3735
```bash
38-
./pi_webrtc --device=/dev/video0 --fps=30 --width=1280 --height=720 --v4l2_format=mjpeg --mqtt_host=<hostname> --mqtt_port=1883 --mqtt_username=<username> --mqtt_password=<password> --hw_accel
36+
./pi_webrtc --camera=libcamera:0 --fps=30 --width=1280 --height=720 --use_mqtt --mqtt_host=<hostname> --mqtt_port=1883 --mqtt_username=<username> --mqtt_password=<password> --hw_accel
3937
```

doc/USE_GPERFTOOLS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sudo apt-get install ghostscript graphviz
2929
## 3. Run the Program and Generate Performance Data
3030
Execute program and output the performance data to a specified file, for example:
3131
```bash
32-
CPUPROFILE=./prof.out CPUPROFILESIGNAL=12 ./pi_webrtc --device=/dev/video0 --fps=30 --width=1280 --height=960 --v4l2_format=h264 --hw_accel --uid=home-pi-3b
32+
CPUPROFILE=./prof.out CPUPROFILESIGNAL=12 ./pi_webrtc --camera=v4l2:0 --fps=30 --width=1280 --height=960 --v4l2_format=h264 --hw_accel --uid=home-pi-3b
3333
```
3434

3535
Send a signal to the process to start/stop collect performance data:

src/args.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct Args {
1919
bool no_audio = false;
2020
bool hw_accel = false;
2121
bool use_libcamera = false;
22+
bool use_mqtt = false;
23+
bool use_whep = false;
2224
bool fixed_resolution = false;
2325
uint32_t format = V4L2_PIX_FMT_MJPEG;
2426
std::string v4l2_format = "mjpeg";

src/main.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
#include "conductor.h"
77
#include "parser.h"
88
#include "recorder/recorder_manager.h"
9-
#include "signaling/signaling_service.h"
10-
#if USE_MQTT_SIGNALING
11-
#include "signaling/mqtt_service.h"
12-
#elif USE_HTTP_SIGNALING
139
#include "signaling/http_service.h"
14-
#endif
10+
#include "signaling/mqtt_service.h"
1511

1612
int main(int argc, char *argv[]) {
1713
Args args;
@@ -28,21 +24,29 @@ int main(int argc, char *argv[]) {
2824
DEBUG_PRINT("Recorder is not started!");
2925
}
3026

31-
auto signaling_service = ([args, conductor]() -> std::shared_ptr<SignalingService> {
32-
#if USE_MQTT_SIGNALING
33-
return MqttService::Create(args, conductor);
34-
#elif USE_HTTP_SIGNALING
35-
return HttpService::Create(args, conductor);
36-
#else
37-
return nullptr;
38-
#endif
39-
})();
40-
41-
if (signaling_service) {
42-
signaling_service->Start();
43-
} else {
44-
INFO_PRINT("There is no any signaling service found!");
27+
boost::asio::io_context ioc_;
28+
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_guard(
29+
ioc_.get_executor());
30+
std::vector<std::shared_ptr<SignalingService>> services;
31+
32+
if (args.use_whep) {
33+
services.push_back(HttpService::Create(args, conductor, ioc_));
34+
}
35+
36+
if (args.use_mqtt) {
37+
services.push_back(MqttService::Create(args, conductor));
4538
}
4639

40+
if (services.empty()) {
41+
ERROR_PRINT("No signaling service is running.");
42+
work_guard.reset();
43+
}
44+
45+
for (auto &service : services) {
46+
service->Start();
47+
}
48+
49+
ioc_.run();
50+
4751
return 0;
4852
}

src/parser.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,22 @@ void Parser::ParseArgs(int argc, char *argv[], Args &args) {
5151
"Turn server username")
5252
("turn_password", bpo::value<std::string>()->default_value(args.turn_password),
5353
"Turn server password")
54-
#if USE_MQTT_SIGNALING
5554
("mqtt_port", bpo::value<int>()->default_value(args.mqtt_port), "Mqtt server port")
5655
("mqtt_host", bpo::value<std::string>()->default_value(args.mqtt_host),
5756
"Mqtt server host")
5857
("mqtt_username", bpo::value<std::string>()->default_value(args.mqtt_username),
5958
"Mqtt server username")
6059
("mqtt_password", bpo::value<std::string>()->default_value(args.mqtt_password),
6160
"Mqtt server password")
62-
#elif USE_HTTP_SIGNALING
6361
("http_port", bpo::value<uint16_t>()->default_value(args.http_port), "Http server port")
64-
#endif
6562
("record_path", bpo::value<std::string>()->default_value(args.record_path),
6663
"The path to save the recording video files. The recorder won't start if it's empty")
6764
("hw_accel", bpo::bool_switch()->default_value(args.hw_accel),
6865
"Share DMA buffers between decoder/scaler/encoder, which can decrease cpu usage")
66+
("use_mqtt", bpo::bool_switch()->default_value(args.use_mqtt),
67+
"Use mqtt to exchange sdp and ice candidates")
68+
("use_whep", bpo::bool_switch()->default_value(args.use_whep),
69+
"Use whep to exchange sdp and ice candidates")
6970
("v4l2_format", bpo::value<std::string>()->default_value(args.v4l2_format),
7071
"Set v4l2 camera capture format to `i420`, `mjpeg`, `h264`. The `h264` can pass "
7172
"packets into mp4 without encoding to reduce cpu usage."
@@ -110,6 +111,8 @@ void Parser::ParseArgs(int argc, char *argv[], Args &args) {
110111
args.fixed_resolution = vm["fixed_resolution"].as<bool>();
111112
args.no_audio = vm["no_audio"].as<bool>();
112113
args.hw_accel = vm["hw_accel"].as<bool>();
114+
args.use_mqtt = vm["use_mqtt"].as<bool>();
115+
args.use_whep = vm["use_whep"].as<bool>();
113116

114117
if (!args.stun_url.empty() && args.stun_url.substr(0, 4) != "stun") {
115118
std::cout << "Stun url should not be empty and start with \"stun:\"" << std::endl;

0 commit comments

Comments
 (0)