Skip to content

Commit 3fd5e3f

Browse files
committed
feat: allow different send & receive ports
1 parent ed5b07c commit 3fd5e3f

File tree

7 files changed

+96
-26
lines changed

7 files changed

+96
-26
lines changed

linux/PwarController.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ PwarController::PwarController(QObject *parent)
1616

1717
// Initialize default config
1818
strcpy(m_config.stream_ip, "192.168.66.3");
19-
m_config.stream_port = 8321;
19+
m_config.connect_port = 8321;
20+
m_config.listen_port = 8321;
2021
m_config.passthrough_test = 0;
2122
m_config.oneshot_mode = 0;
2223
m_config.buffer_size = 64;
@@ -71,14 +72,28 @@ void PwarController::setStreamIp(const QString &ip) {
7172
}
7273
}
7374

74-
int PwarController::streamPort() const {
75-
return m_config.stream_port;
75+
int PwarController::connectPort() const {
76+
return m_config.connect_port;
7677
}
7778

78-
void PwarController::setStreamPort(int port) {
79-
if (m_config.stream_port != port) {
80-
m_config.stream_port = port;
81-
emit streamPortChanged();
79+
void PwarController::setConnectPort(int port) {
80+
if (m_config.connect_port != port) {
81+
m_config.connect_port = port;
82+
emit connectPortChanged();
83+
if (pwar_is_running()) {
84+
setStatus("Port changed - stop and start to apply");
85+
}
86+
}
87+
}
88+
89+
int PwarController::listenPort() const {
90+
return m_config.listen_port;
91+
}
92+
93+
void PwarController::setListenPort(int port) {
94+
if (m_config.listen_port != port) {
95+
m_config.listen_port = port;
96+
emit listenPortChanged();
8297
if (pwar_is_running()) {
8398
setStatus("Port changed - stop and start to apply");
8499
}
@@ -249,8 +264,8 @@ void PwarController::loadSettings() {
249264
QString savedIp = m_settings->value("network/streamIp", QString(m_config.stream_ip)).toString();
250265
setStreamIp(savedIp);
251266

252-
int savedPort = m_settings->value("network/streamPort", m_config.stream_port).toInt();
253-
setStreamPort(savedPort);
267+
int savedPort = m_settings->value("network/connectPort", m_config.connect_port).toInt();
268+
setConnectPort(savedPort);
254269

255270
// Load audio settings
256271
bool savedPassthrough = m_settings->value("audio/passthroughTest", m_config.passthrough_test).toBool();
@@ -278,7 +293,7 @@ void PwarController::saveSettings() {
278293

279294
// Save network settings
280295
m_settings->setValue("network/streamIp", streamIp());
281-
m_settings->setValue("network/streamPort", streamPort());
296+
m_settings->setValue("network/connectPort", connectPort());
282297

283298
// Save audio settings
284299
m_settings->setValue("audio/passthroughTest", passthroughTest());

linux/PwarController.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class PwarController : public QObject {
99
Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged)
1010
Q_PROPERTY(bool isRunning READ isRunning NOTIFY isRunningChanged)
1111
Q_PROPERTY(QString streamIp READ streamIp WRITE setStreamIp NOTIFY streamIpChanged)
12-
Q_PROPERTY(int streamPort READ streamPort WRITE setStreamPort NOTIFY streamPortChanged)
12+
Q_PROPERTY(int connectPort READ connectPort WRITE setConnectPort NOTIFY connectPortChanged)
13+
Q_PROPERTY(int listenPort READ listenPort WRITE setListenPort NOTIFY listenPortChanged)
1314
Q_PROPERTY(bool passthroughTest READ passthroughTest WRITE setPassthroughTest NOTIFY passthroughTestChanged)
1415
Q_PROPERTY(bool oneshotMode READ oneshotMode WRITE setOneshotMode NOTIFY oneshotModeChanged)
1516
Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged)
@@ -44,8 +45,10 @@ class PwarController : public QObject {
4445
bool isRunning() const;
4546
QString streamIp() const;
4647
void setStreamIp(const QString &ip);
47-
int streamPort() const;
48-
void setStreamPort(int port);
48+
int connectPort() const;
49+
void setConnectPort(int port);
50+
int listenPort() const;
51+
void setListenPort(int port);
4952
bool passthroughTest() const;
5053
void setPassthroughTest(bool enabled);
5154
bool oneshotMode() const;
@@ -91,7 +94,8 @@ class PwarController : public QObject {
9194
void statusChanged();
9295
void isRunningChanged();
9396
void streamIpChanged();
94-
void streamPortChanged();
97+
void connectPortChanged();
98+
void listenPortChanged();
9599
void passthroughTestChanged();
96100
void oneshotModeChanged();
97101
void bufferSizeChanged();

linux/libpwar.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ static void *pipewire_thread_func(void *userdata) {
302302
static int init_data_structure(struct data *data, const pwar_config_t *config) {
303303
memset(data, 0, sizeof(struct data));
304304

305-
setup_socket(data, config->stream_ip, config->stream_port);
306-
setup_recv_socket(data, DEFAULT_STREAM_PORT);
305+
setup_socket(data, config->stream_ip, config->connect_port);
306+
setup_recv_socket(data, config->listen_port);
307307
pthread_mutex_init(&data->packet_mutex, NULL);
308308
pthread_cond_init(&data->packet_cond, NULL);
309309
data->packet_available = 0;
@@ -382,7 +382,7 @@ static int create_pipewire_filter(struct data *data) {
382382
int pwar_requires_restart(const pwar_config_t *old_config, const pwar_config_t *new_config) {
383383
if (old_config->buffer_size != new_config->buffer_size ||
384384
strcmp(old_config->stream_ip, new_config->stream_ip) != 0 ||
385-
old_config->stream_port != new_config->stream_port) {
385+
old_config->connect_port != new_config->connect_port) {
386386
return 1;
387387
}
388388
return 0;

linux/libpwar.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ extern "C" {
1212

1313
typedef struct {
1414
char stream_ip[PWAR_MAX_IP_LEN];
15-
int stream_port;
15+
int connect_port;
16+
int listen_port;
1617
int passthrough_test;
1718
int oneshot_mode;
1819
int buffer_size;

linux/pwar_cli.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
1818
pwar_config_t config;
1919
memset(&config, 0, sizeof(config));
2020
strncpy(config.stream_ip, DEFAULT_STREAM_IP, sizeof(config.stream_ip) - 1);
21-
config.stream_port = DEFAULT_STREAM_PORT;
21+
config.listen_port = config.connect_port = DEFAULT_STREAM_PORT;
2222
config.passthrough_test = 0;
2323
config.oneshot_mode = 0;
2424
config.buffer_size = DEFAULT_BUFFER_SIZE;
@@ -27,8 +27,10 @@ int main(int argc, char *argv[]) {
2727
if ((strcmp(argv[i], "--ip") == 0 || strcmp(argv[i], "-i") == 0) && i + 1 < argc) {
2828
strncpy(config.stream_ip, argv[++i], sizeof(config.stream_ip) - 1);
2929
config.stream_ip[sizeof(config.stream_ip) - 1] = '\0';
30-
} else if ((strcmp(argv[i], "--port") == 0 || (strcmp(argv[i], "-p") == 0)) && i + 1 < argc) {
31-
config.stream_port = atoi(argv[++i]);
30+
} else if ((strcmp(argv[i], "--connect-port") == 0 || (strcmp(argv[i], "-p") == 0)) && i + 1 < argc) {
31+
config.connect_port = atoi(argv[++i]);
32+
} else if ((strcmp(argv[i], "--listen-port") == 0 || (strcmp(argv[i], "-l") == 0)) && i + 1 < argc) {
33+
config.listen_port = atoi(argv[++i]);
3234
} else if ((strcmp(argv[i], "--passthrough_test") == 0) || (strcmp(argv[i], "-pt") == 0)) {
3335
config.passthrough_test = 1;
3436
} else if ((strcmp(argv[i], "--oneshot") == 0)) {
@@ -40,7 +42,7 @@ int main(int argc, char *argv[]) {
4042

4143
printf("Starting PWAR with config:\n");
4244
printf(" Stream IP: %s\n", config.stream_ip);
43-
printf(" Stream Port: %d\n", config.stream_port);
45+
printf(" Stream Port: %d\n", config.connect_port);
4446
printf(" Passthrough Test: %s\n", config.passthrough_test ? "Enabled" : "Disabled");
4547
printf(" Oneshot Mode: %s\n", config.oneshot_mode ? "Enabled" : "Disabled");
4648
printf(" Buffer Size: %d\n", config.buffer_size);

linux/pwar_gui.qml

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ ApplicationWindow {
306306
}
307307

308308
Label {
309-
text: "Port"
309+
text: "Connect Port"
310310
color: textPrimary
311311
font.bold: true
312312
}
@@ -319,11 +319,58 @@ ApplicationWindow {
319319
color: textPrimary
320320
placeholderTextColor: textSecondary
321321
selectByMouse: true
322-
text: pwarController.streamPort.toString()
322+
text: pwarController.connectPort.toString()
323323
onTextChanged: {
324324
var portNumber = parseInt(text);
325-
if (!isNaN(portNumber) && portNumber !== pwarController.streamPort) {
326-
pwarController.streamPort = portNumber;
325+
if (!isNaN(portNumber) && portNumber !== pwarController.connectPort) {
326+
pwarController.connectPort = portNumber;
327+
}
328+
}
329+
330+
background: Rectangle {
331+
color: graphiteMedium
332+
radius: 4
333+
border.color: parent.activeFocus ? orangeAccent : (parent.hovered ? orangeHover : "#555555")
334+
border.width: parent.activeFocus ? 2 : 1
335+
336+
Behavior on border.color { ColorAnimation { duration: 150 } }
337+
Behavior on border.width { NumberAnimation { duration: 150 } }
338+
339+
// Subtle glow when focused
340+
Rectangle {
341+
anchors.fill: parent
342+
anchors.margins: -2
343+
radius: parent.radius + 2
344+
color: "transparent"
345+
border.color: orangeAccent
346+
border.width: parent.parent.activeFocus ? 1 : 0
347+
opacity: parent.parent.activeFocus ? 0.3 : 0
348+
349+
Behavior on opacity { NumberAnimation { duration: 150 } }
350+
Behavior on border.width { NumberAnimation { duration: 150 } }
351+
}
352+
}
353+
}
354+
355+
Label {
356+
text: "Listen Port"
357+
color: textPrimary
358+
font.bold: true
359+
}
360+
TextField {
361+
id: listenPortField
362+
Layout.fillWidth: true
363+
placeholderText: "e.g. 5600"
364+
inputMethodHints: Qt.ImhDigitsOnly
365+
validator: IntValidator { bottom: 1; top: 65535 }
366+
color: textPrimary
367+
placeholderTextColor: textSecondary
368+
selectByMouse: true
369+
text: pwarController.listenPort.toString()
370+
onTextChanged: {
371+
var portNumber = parseInt(text);
372+
if (!isNaN(portNumber) && portNumber !== pwarController.listenPort) {
373+
pwarController.listenPort = portNumber;
327374
}
328375
}
329376

linux/windows_sim.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static void setup_recv_socket(int port) {
4949
recv_addr.sin_family = AF_INET;
5050
recv_addr.sin_addr.s_addr = INADDR_ANY;
5151
recv_addr.sin_port = htons(port);
52+
printf("about to bind on local port %d...\n", port);
5253
if (bind(recv_sockfd, (struct sockaddr *)&recv_addr, sizeof(recv_addr)) < 0) {
5354
perror("recv socket bind failed");
5455
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)