Skip to content

Commit b111dec

Browse files
committed
refactor: use enable ipc flag
1 parent 1e412cf commit b111dec

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

src/args.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ struct Args {
103103
int file_duration = 60;
104104

105105
// ipc
106-
std::string ipc_channel = "none";
107-
int ipc_channel_mode = -1;
106+
bool enable_ipc = false;
108107
std::string socket_path = "/tmp/pi-webrtc-ipc.sock";
109108

110109
// webrtc

src/parser.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ static const std::unordered_map<std::string, int> v4l2_fmt_table = {
1515
{"i420", V4L2_PIX_FMT_YUV420},
1616
};
1717

18-
static const std::unordered_map<std::string, int> ipc_mode_table = {
19-
{"none", -1},
20-
{"lossy", ChannelMode::Lossy},
21-
{"reliable", ChannelMode::Reliable},
22-
};
23-
2418
static const std::unordered_map<std::string, int> ae_metering_table = {
2519
{"centre", libcamera::controls::MeteringCentreWeighted},
2620
{"spot", libcamera::controls::MeteringSpot},
@@ -147,8 +141,8 @@ void Parser::ParseArgs(int argc, char *argv[], Args &args) {
147141
("no-adaptive", bpo::bool_switch(&args.no_adaptive)->default_value(args.no_adaptive),
148142
"Disable WebRTC's adaptive resolution scaling. When enabled, "
149143
"the output resolution will remain fixed regardless of network or device conditions.")
150-
("ipc-channel-mode", bpo::value<std::string>(&args.ipc_channel)->default_value(args.ipc_channel),
151-
"Set the WebRTC DataChannel mode for IPC relay: none, lossy, reliable.")
144+
("enable-ipc", bpo::bool_switch(&args.enable_ipc)->default_value(args.enable_ipc),
145+
"Enable IPC relay using a WebRTC DataChannel, lossy (UDP-like) or reliable (TCP-like) based on client preference.")
152146
("socket-path", bpo::value<std::string>(&args.socket_path)->default_value(args.socket_path),
153147
"Specifies the Unix domain socket path used to bridge messages between "
154148
"the WebRTC DataChannel and local IPC applications.")
@@ -242,7 +236,6 @@ void Parser::ParseArgs(int argc, char *argv[], Args &args) {
242236
args.af_mode = ParseEnum(afMode_table, args.autofocus_mode);
243237
args.af_range_mode = ParseEnum(afRange_table, args.af_range);
244238
args.af_speed_mode = ParseEnum(afSpeed_table, args.af_speed);
245-
args.ipc_channel_mode = ParseEnum(ipc_mode_table, args.ipc_channel);
246239

247240
if (sscanf(args.af_window.c_str(), "%f,%f,%f,%f", &args.af_window_x, &args.af_window_y,
248241
&args.af_window_width, &args.af_window_height) != 4) {

src/rtc/conductor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Conductor::Conductor(Args args)
3939
: args(args) {}
4040

4141
Conductor::~Conductor() {
42-
if (args.ipc_channel_mode > 0) {
42+
if (ipc_server_) {
4343
ipc_server_->Stop();
4444
}
4545
audio_track_ = nullptr;
@@ -143,9 +143,8 @@ rtc::scoped_refptr<RtcPeer> Conductor::CreatePeerConnection(PeerConfig config) {
143143
}
144144
peer->CreateDataChannel(ChannelMode::Lossy);
145145
peer->CreateDataChannel(ChannelMode::Reliable);
146-
} else if (args.ipc_channel_mode == ChannelMode::Lossy) {
146+
} else if (args.enable_ipc) {
147147
SetupIpcDataChannel(peer, ChannelMode::Lossy);
148-
} else if (args.ipc_channel_mode == ChannelMode::Reliable) {
149148
SetupIpcDataChannel(peer, ChannelMode::Reliable);
150149
}
151150

@@ -313,7 +312,7 @@ void Conductor::InitializePeerConnectionFactory() {
313312
}
314313

315314
void Conductor::InitializeIpcServer() {
316-
if (args.ipc_channel_mode > 0) {
315+
if (args.enable_ipc) {
317316
ipc_server_ = UnixSocketServer::Create(args.socket_path);
318317
ipc_server_->Start();
319318
}

0 commit comments

Comments
 (0)