1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
|
From d3c1abb3bc1e81069892fa6ba3eff9b8692d5504 Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 14 Sep 2023 11:25:31 +0200
Subject: [PATCH 1/5] Revert "UI: Fix IP settings order"
---
UI/forms/OBSBasicSettings.ui | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/UI/forms/OBSBasicSettings.ui b/UI/forms/OBSBasicSettings.ui
index 267f4a3a4c5b79..9c780d6ddbe69a 100644
--- a/UI/forms/OBSBasicSettings.ui
+++ b/UI/forms/OBSBasicSettings.ui
@@ -8239,30 +8239,30 @@
</widget>
</item>
<item row="1" column="0">
- <widget class="QLabel" name="ipFamilyLabel">
+ <widget class="QLabel" name="bindToIPLabel">
<property name="text">
- <string>Basic.Settings.Advanced.Network.IPFamily</string>
+ <string>Basic.Settings.Advanced.Network.BindToIP</string>
</property>
<property name="buddy">
- <cstring>ipFamily</cstring>
+ <cstring>bindToIP</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
- <widget class="QComboBox" name="ipFamily"/>
+ <widget class="QComboBox" name="bindToIP"/>
</item>
<item row="2" column="0">
- <widget class="QLabel" name="bindToIPLabel">
+ <widget class="QLabel" name="ipFamilyLabel">
<property name="text">
- <string>Basic.Settings.Advanced.Network.BindToIP</string>
+ <string>Basic.Settings.Advanced.Network.IPFamily</string>
</property>
<property name="buddy">
- <cstring>bindToIP</cstring>
+ <cstring>ipFamily</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
- <widget class="QComboBox" name="bindToIP"/>
+ <widget class="QComboBox" name="ipFamily"/>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="enableNewSocketLoop">
From f0c14f484469cb13054bcd6cd0b7cc01f5e0b4d7 Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 14 Sep 2023 11:25:50 +0200
Subject: [PATCH 2/5] Revert "UI: Add IPv4 / IPv6 selection setting"
This reverts commit 488a96bc4b0c27749b1ef143ed76a71c1830fe0a.
---
UI/data/locale/en-US.ini | 1 -
UI/forms/OBSBasicSettings.ui | 21 ++++-----------------
UI/window-basic-auto-config-test.cpp | 3 ---
UI/window-basic-main-outputs.cpp | 4 ----
UI/window-basic-main.cpp | 3 +--
UI/window-basic-settings.cpp | 17 -----------------
6 files changed, 5 insertions(+), 44 deletions(-)
diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini
index 572b15f15117fb..13da7f1b53346f 100644
--- a/UI/data/locale/en-US.ini
+++ b/UI/data/locale/en-US.ini
@@ -1285,7 +1285,6 @@ Basic.Settings.Advanced.StreamDelay.MemoryUsage="Estimated Memory Usage: %1 MB"
Basic.Settings.Advanced.Network="Network"
Basic.Settings.Advanced.Network.Disabled="The currently selected streaming protocol does not support changing network settings."
Basic.Settings.Advanced.Network.BindToIP="Bind to IP"
-Basic.Settings.Advanced.Network.IPFamily="IP Family"
Basic.Settings.Advanced.Network.EnableNewSocketLoop="Enable network optimizations"
Basic.Settings.Advanced.Network.EnableLowLatencyMode="Enable TCP pacing"
Basic.Settings.Advanced.Network.TCPPacing.Tooltip="Attempts to make RTMP output friendlier to other latency sensitive applications on the network by regulating the rate of transmission.\nIt may increase the risk of dropped frames on unstable connections."
diff --git a/UI/forms/OBSBasicSettings.ui b/UI/forms/OBSBasicSettings.ui
index 9c780d6ddbe69a..a4effbcd0797a4 100644
--- a/UI/forms/OBSBasicSettings.ui
+++ b/UI/forms/OBSBasicSettings.ui
@@ -8251,27 +8251,14 @@
<item row="1" column="1">
<widget class="QComboBox" name="bindToIP"/>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="ipFamilyLabel">
- <property name="text">
- <string>Basic.Settings.Advanced.Network.IPFamily</string>
- </property>
- <property name="buddy">
- <cstring>ipFamily</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QComboBox" name="ipFamily"/>
- </item>
- <item row="4" column="1">
+ <item row="3" column="1">
<widget class="QCheckBox" name="enableNewSocketLoop">
<property name="text">
<string>Basic.Settings.Advanced.Network.EnableNewSocketLoop</string>
</property>
</widget>
</item>
- <item row="5" column="1">
+ <item row="4" column="1">
<widget class="QCheckBox" name="enableLowLatencyMode">
<property name="enabled">
<bool>false</bool>
@@ -8281,7 +8268,7 @@
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="3" column="0">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -8294,7 +8281,7 @@
</property>
</spacer>
</item>
- <item row="3" column="1">
+ <item row="2" column="1">
<widget class="QCheckBox" name="dynBitrate">
<property name="toolTip">
<string>Basic.Settings.Output.DynamicBitrate.TT</string>
diff --git a/UI/window-basic-auto-config-test.cpp b/UI/window-basic-auto-config-test.cpp
index b53f37aa25417d..380d85450e4888 100644
--- a/UI/window-basic-auto-config-test.cpp
+++ b/UI/window-basic-auto-config-test.cpp
@@ -234,9 +234,6 @@ void AutoConfigTestPage::TestBandwidthThread()
const char *bind_ip = config_get_string(main->Config(), "Output", "BindIP");
obs_data_set_string(output_settings, "bind_ip", bind_ip);
- const char *ip_family = config_get_string(main->Config(), "Output", "IPFamily");
- obs_data_set_string(output_settings, "ip_family", ip_family);
-
/* -----------------------------------*/
/* determine which servers to test */
diff --git a/UI/window-basic-main-outputs.cpp b/UI/window-basic-main-outputs.cpp
index 30d2031747dd5a..e2953dbed946af 100644
--- a/UI/window-basic-main-outputs.cpp
+++ b/UI/window-basic-main-outputs.cpp
@@ -1156,7 +1156,6 @@ bool SimpleOutput::StartStreaming(obs_service_t *service)
int delaySec = config_get_int(main->Config(), "Output", "DelaySec");
bool preserveDelay = config_get_bool(main->Config(), "Output", "DelayPreserve");
const char *bindIP = config_get_string(main->Config(), "Output", "BindIP");
- const char *ipFamily = config_get_string(main->Config(), "Output", "IPFamily");
#ifdef _WIN32
bool enableNewSocketLoop = config_get_bool(main->Config(), "Output", "NewSocketLoopEnable");
bool enableLowLatencyMode = config_get_bool(main->Config(), "Output", "LowLatencyEnable");
@@ -1174,7 +1173,6 @@ bool SimpleOutput::StartStreaming(obs_service_t *service)
OBSDataAutoRelease settings = obs_data_create();
obs_data_set_string(settings, "bind_ip", bindIP);
- obs_data_set_string(settings, "ip_family", ipFamily);
#ifdef _WIN32
obs_data_set_bool(settings, "new_socket_loop_enabled", enableNewSocketLoop);
obs_data_set_bool(settings, "low_latency_mode_enabled", enableLowLatencyMode);
@@ -2116,7 +2114,6 @@ bool AdvancedOutput::StartStreaming(obs_service_t *service)
int delaySec = config_get_int(main->Config(), "Output", "DelaySec");
bool preserveDelay = config_get_bool(main->Config(), "Output", "DelayPreserve");
const char *bindIP = config_get_string(main->Config(), "Output", "BindIP");
- const char *ipFamily = config_get_string(main->Config(), "Output", "IPFamily");
#ifdef _WIN32
bool enableNewSocketLoop = config_get_bool(main->Config(), "Output", "NewSocketLoopEnable");
bool enableLowLatencyMode = config_get_bool(main->Config(), "Output", "LowLatencyEnable");
@@ -2142,7 +2139,6 @@ bool AdvancedOutput::StartStreaming(obs_service_t *service)
OBSDataAutoRelease settings = obs_data_create();
obs_data_set_string(settings, "bind_ip", bindIP);
- obs_data_set_string(settings, "ip_family", ipFamily);
#ifdef _WIN32
obs_data_set_bool(settings, "new_socket_loop_enabled", enableNewSocketLoop);
obs_data_set_bool(settings, "low_latency_mode_enabled", enableLowLatencyMode);
diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp
index 47cac8dccfe7cc..ba1886cce19751 100644
--- a/UI/window-basic-main.cpp
+++ b/UI/window-basic-main.cpp
@@ -1804,7 +1804,6 @@ bool OBSBasic::InitBasicConfigDefaults()
config_set_default_uint(activeConfiguration, "Output", "MaxRetries", 25);
config_set_default_string(activeConfiguration, "Output", "BindIP", "default");
- config_set_default_string(activeConfiguration, "Output", "IPFamily", "IPv4+IPv6");
config_set_default_bool(activeConfiguration, "Output", "NewSocketLoopEnable", false);
config_set_default_bool(activeConfiguration, "Output", "LowLatencyEnable", false);
@@ -2105,7 +2104,7 @@ void OBSBasic::OBSInit()
}
/* Modules can access frontend information (i.e. profile and scene collection data) during their initialization, and some modules (e.g. obs-websockets) are known to use the filesystem location of the current profile in their own code.
-
+
Thus the profile and scene collection discovery needs to happen before any access to that information (but after intializing global settings) to ensure legacy code gets valid path information.
*/
RefreshSceneCollections(true);
diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp
index d8a35501b79ceb..dc1525ef9941f8 100644
--- a/UI/window-basic-settings.cpp
+++ b/UI/window-basic-settings.cpp
@@ -567,7 +567,6 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
HookWidget(ui->processPriority, COMBO_CHANGED, ADV_CHANGED);
HookWidget(ui->confirmOnExit, CHECK_CHANGED, ADV_CHANGED);
HookWidget(ui->bindToIP, COMBO_CHANGED, ADV_CHANGED);
- HookWidget(ui->ipFamily, COMBO_CHANGED, ADV_CHANGED);
HookWidget(ui->enableNewSocketLoop, CHECK_CHANGED, ADV_CHANGED);
HookWidget(ui->enableLowLatencyMode, CHECK_CHANGED, ADV_CHANGED);
HookWidget(ui->hotkeyFocusType, COMBO_CHANGED, ADV_CHANGED);
@@ -820,17 +819,6 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
ui->bindToIP->addItem(QT_UTF8(name), val);
}
- // Add IP Family options
- p = obs_properties_get(ppts, "ip_family");
-
- count = obs_property_list_item_count(p);
- for (size_t i = 0; i < count; i++) {
- const char *name = obs_property_list_item_name(p, i);
- const char *val = obs_property_list_item_string(p, i);
-
- ui->ipFamily->addItem(QT_UTF8(name), val);
- }
-
obs_properties_destroy(ppts);
ui->multitrackVideoNoticeBox->setVisible(false);
@@ -2546,7 +2534,6 @@ void OBSBasicSettings::LoadAdvancedSettings()
bool autoRemux = config_get_bool(main->Config(), "Video", "AutoRemux");
const char *hotkeyFocusType = config_get_string(App()->GetUserConfig(), "General", "HotkeyFocusType");
bool dynBitrate = config_get_bool(main->Config(), "Output", "DynamicBitrate");
- const char *ipFamily = config_get_string(main->Config(), "Output", "IPFamily");
bool confirmOnExit = config_get_bool(App()->GetUserConfig(), "General", "ConfirmOnExit");
loading = true;
@@ -2583,7 +2570,6 @@ void OBSBasicSettings::LoadAdvancedSettings()
ui->sdrWhiteLevel->setValue(sdrWhiteLevel);
ui->hdrNominalPeakLevel->setValue(hdrNominalPeakLevel);
- SetComboByValue(ui->ipFamily, ipFamily);
if (!SetComboByValue(ui->bindToIP, bindIP))
SetInvalidValue(ui->bindToIP, bindIP, bindIP);
@@ -3213,7 +3199,6 @@ void OBSBasicSettings::SaveAdvancedSettings()
SaveSpinBox(ui->reconnectRetryDelay, "Output", "RetryDelay");
SaveSpinBox(ui->reconnectMaxRetries, "Output", "MaxRetries");
SaveComboData(ui->bindToIP, "Output", "BindIP");
- SaveComboData(ui->ipFamily, "Output", "IPFamily");
SaveCheckBox(ui->autoRemux, "Video", "AutoRemux");
SaveCheckBox(ui->dynBitrate, "Output", "DynamicBitrate");
@@ -5584,8 +5569,6 @@ void OBSBasicSettings::UpdateAdvNetworkGroup()
ui->bindToIPLabel->setVisible(enabled);
ui->bindToIP->setVisible(enabled);
ui->dynBitrate->setVisible(enabled);
- ui->ipFamilyLabel->setVisible(enabled);
- ui->ipFamily->setVisible(enabled);
#ifdef _WIN32
ui->enableNewSocketLoop->setVisible(enabled);
ui->enableLowLatencyMode->setVisible(enabled);
From 583a0ce8507f54a9e87a6b140155fcb4f18bc41b Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:29:08 +0100
Subject: [PATCH 3/5] happy-eyeballs,librtmp: Add interface binding for Linux
---
plugins/obs-outputs/librtmp/rtmp.c | 3 +++
plugins/obs-outputs/librtmp/rtmp.h | 1 +
shared/happy-eyeballs/happy-eyeballs.c | 37 ++++++++++++++++++++++++--
shared/happy-eyeballs/happy-eyeballs.h | 9 +++++++
4 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/plugins/obs-outputs/librtmp/rtmp.c b/plugins/obs-outputs/librtmp/rtmp.c
index 1898558f51927a..540e062b42ea35 100644
--- a/plugins/obs-outputs/librtmp/rtmp.c
+++ b/plugins/obs-outputs/librtmp/rtmp.c
@@ -1063,6 +1063,9 @@ RTMP_Connect(RTMP *r, RTMPPacket *cp)
port = r->Link.port;
}
+ /* Set local bind interface (if present) */
+ happy_eyeballs_set_bind_iface(happy_ctx, r->m_bindInterface.av_len, r->m_bindInterface.av_val);
+
/* Set local bind address (if present) */
happy_eyeballs_set_bind_addr(happy_ctx, r->m_bindIP.addrLen, &r->m_bindIP.addr);
diff --git a/plugins/obs-outputs/librtmp/rtmp.h b/plugins/obs-outputs/librtmp/rtmp.h
index c1b8d906175111..13646bd70a92a8 100644
--- a/plugins/obs-outputs/librtmp/rtmp.h
+++ b/plugins/obs-outputs/librtmp/rtmp.h
@@ -422,6 +422,7 @@ extern "C"
void* m_customSendParam;
CUSTOMSEND m_customSendFunc;
+ AVal m_bindInterface;
RTMP_BINDINFO m_bindIP;
uint8_t m_bSendChunkSizeInfo;
diff --git a/shared/happy-eyeballs/happy-eyeballs.c b/shared/happy-eyeballs/happy-eyeballs.c
index ab5cfcb0720d61..a76b8bf25d7b85 100644
--- a/shared/happy-eyeballs/happy-eyeballs.c
+++ b/shared/happy-eyeballs/happy-eyeballs.c
@@ -101,12 +101,22 @@ struct happy_eyeballs_ctx {
const char *error_message;
/**
- * Set along with bind_addr to hint which interface to use.
+ * Set along with bind_iface to hint which interface to use.
+ */
+ int bind_iface_len;
+
+ /**
+ * Set along with bind_iface_len to hint which interface to use.
+ */
+ char *bind_iface;
+
+ /**
+ * Set along with bind_addr to hint which address to use.
*/
socklen_t bind_addr_len;
/**
- * Set along with bind_addr_len to hint which interface to use.
+ * Set along with bind_addr_len to hint which address to use.
*/
struct sockaddr_storage bind_addr;
@@ -343,6 +353,13 @@ static void *happy_connect_worker(void *arg)
#if !defined(_WIN32) && defined(SO_NOSIGPIPE)
setsockopt(args->sockfd, SOL_SOCKET, SO_NOSIGPIPE, &(int){1}, sizeof(int));
#endif
+
+#ifdef __linux__
+ if (setsockopt(args->sockfd, SOL_SOCKET, SO_BINDTODEVICE, context->bind_iface, context->bind_iface_len) < 0) {
+ goto failure;
+ }
+#endif
+
if (context->bind_addr.ss_family != 0 &&
bind(args->sockfd, (const struct sockaddr *)&context->bind_addr, context->bind_addr_len) < 0) {
goto failure;
@@ -663,6 +680,7 @@ static void *destroy_thread(void *param)
freeaddrinfo(context->addresses);
da_free(context->candidates);
+ bfree(context->bind_iface);
free(context);
return NULL;
@@ -685,6 +703,21 @@ int happy_eyeballs_destroy(struct happy_eyeballs_ctx *context)
/* ------------------------------------------------------------------------- */
/* Setters & Getters */
+int happy_eyeballs_set_bind_iface(struct happy_eyeballs_ctx *context, int iface_len, const char *iface)
+{
+ if (!context)
+ return STATUS_INVALID_ARGUMENT;
+
+ if (iface && iface_len > 0) {
+ context->bind_iface = bstrdup(iface);
+ context->bind_iface_len = iface_len;
+ } else {
+ context->bind_iface_len = 0;
+ context->bind_iface = NULL;
+ }
+ return STATUS_SUCCESS;
+}
+
int happy_eyeballs_set_bind_addr(struct happy_eyeballs_ctx *context, socklen_t addr_len,
struct sockaddr_storage *addr_storage)
{
diff --git a/shared/happy-eyeballs/happy-eyeballs.h b/shared/happy-eyeballs/happy-eyeballs.h
index 7bf68e70ea6512..d7a84eabeed1ff 100644
--- a/shared/happy-eyeballs/happy-eyeballs.h
+++ b/shared/happy-eyeballs/happy-eyeballs.h
@@ -81,6 +81,15 @@ int happy_eyeballs_create(struct happy_eyeballs_ctx **context);
*/
int happy_eyeballs_connect(struct happy_eyeballs_ctx *context, const char *hostname, int port);
+/**
+ * Optionally set the interface. You may pass 0 and NULL for these
+ * parameters, respectively, to clear this setting. This must be called before
+ * happy_eyeballs_connect.
+ *
+ * Returns 0 on success or -EINVAL if context is not set.
+ */
+int happy_eyeballs_set_bind_iface(struct happy_eyeballs_ctx *context, int iface_len, const char *iface);
+
/**
* Optionally set the interface address. You may pass 0 and NULL for these
* parameters, respectively, to clear this setting. This must be called before
From c6294ce69458f12744ca80d6e969fe1191e6dcab Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:47:45 +0100
Subject: [PATCH 4/5] obs-outputs: Add RTMP iface binding for Linux
---
plugins/obs-outputs/net-if.c | 32 +++++++++++++++++++++++++++++++
plugins/obs-outputs/net-if.h | 15 +++++++++++++++
plugins/obs-outputs/rtmp-stream.c | 28 +++++++++++++++++++++++++++
plugins/obs-outputs/rtmp-stream.h | 2 ++
4 files changed, 77 insertions(+)
diff --git a/plugins/obs-outputs/net-if.c b/plugins/obs-outputs/net-if.c
index 43ad31691fdcf0..dd556e2442c509 100644
--- a/plugins/obs-outputs/net-if.c
+++ b/plugins/obs-outputs/net-if.c
@@ -140,6 +140,38 @@ static inline bool is_loopback(struct ifaddrs *ifa)
return n && (strcmp(n, "lo") == 0 || strcmp(n, "lo0") == 0);
}
+#ifdef __linux__
+void netif_get_ifaces(struct netif_siface_data *ifaces)
+{
+ da_init(ifaces->ifaces);
+
+ struct ifaddrs *ifaddr, *ifa;
+ unsigned int family;
+
+ if (getifaddrs(&ifaddr) == -1) {
+ warn("getifaddrs() failed");
+ return;
+ }
+
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL || is_loopback(ifa))
+ continue;
+ family = ifa->ifa_addr->sa_family;
+
+ if ((family == AF_INET) || (family == AF_INET6)) {
+ char *item;
+ char *iface_dup = bstrdup(ifa->ifa_name);
+
+ item = iface_dup;
+
+ da_push_back(ifaces->ifaces, &item);
+ }
+ }
+
+ freeifaddrs(ifaddr);
+}
+#endif
+
static inline void netif_get_addrs_nix(struct netif_saddr_data *ifaddrs)
{
struct ifaddrs *ifaddr, *ifa;
diff --git a/plugins/obs-outputs/net-if.h b/plugins/obs-outputs/net-if.h
index ff428fcaad23c6..7f4cd343a4be94 100644
--- a/plugins/obs-outputs/net-if.h
+++ b/plugins/obs-outputs/net-if.h
@@ -53,6 +53,21 @@
#endif
+#ifdef __linux__
+struct netif_siface_data {
+ DARRAY(char *) ifaces;
+};
+
+static inline void netif_siface_data_free(struct netif_siface_data *data)
+{
+ for (size_t i = 0; i < data->ifaces.num; i++)
+ bfree(data->ifaces.array[i]);
+ da_free(data->ifaces);
+}
+
+extern void netif_get_ifaces(struct netif_siface_data *ifaces);
+#endif
+
struct netif_saddr_item {
char *name;
char *addr;
diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c
index 2f722fc39a626c..64084fd5e2b6e3 100644
--- a/plugins/obs-outputs/rtmp-stream.c
+++ b/plugins/obs-outputs/rtmp-stream.c
@@ -126,6 +126,7 @@ static void rtmp_stream_destroy(void *data)
dstr_free(&stream->username);
dstr_free(&stream->password);
dstr_free(&stream->encoder_name);
+ dstr_free(&stream->bind_interface);
dstr_free(&stream->bind_ip);
os_event_destroy(stream->stop_event);
os_sem_destroy(stream->send_sem);
@@ -1184,6 +1185,13 @@ static int try_connect(struct rtmp_stream *stream)
set_rtmp_dstr(&stream->rtmp.Link.flashVer, &stream->encoder_name);
stream->rtmp.Link.swfUrl = stream->rtmp.Link.tcUrl;
+ if (dstr_is_empty(&stream->bind_interface) || dstr_cmp(&stream->bind_interface, "default") == 0) {
+ memset(&stream->rtmp.m_bindInterface, 0, sizeof(stream->rtmp.m_bindInterface));
+ } else {
+ set_rtmp_dstr(&stream->rtmp.m_bindInterface, &stream->bind_interface);
+ info("Binding to interface %s", stream->rtmp.m_bindInterface.av_val);
+ }
+
if (dstr_is_empty(&stream->bind_ip) || dstr_cmp(&stream->bind_ip, "default") == 0) {
memset(&stream->rtmp.m_bindIP, 0, sizeof(stream->rtmp.m_bindIP));
} else {
@@ -1229,6 +1237,7 @@ static bool init_connect(struct rtmp_stream *stream)
{
obs_service_t *service;
obs_data_t *settings;
+ const char *bind_interface;
const char *bind_ip;
const char *ip_family;
int64_t drop_p;
@@ -1318,6 +1327,9 @@ static bool init_connect(struct rtmp_stream *stream)
stream->drop_threshold_usec = 1000 * drop_b;
stream->pframe_drop_threshold_usec = 1000 * drop_p;
+ bind_interface = obs_data_get_string(settings, OPT_BIND_INTERFACE);
+ dstr_copy(&stream->bind_interface, bind_interface);
+
bind_ip = obs_data_get_string(settings, OPT_BIND_IP);
dstr_copy(&stream->bind_ip, bind_ip);
@@ -1728,12 +1740,28 @@ static obs_properties_t *rtmp_stream_properties(void *unused)
UNUSED_PARAMETER(unused);
obs_properties_t *props = obs_properties_create();
+#ifdef __linux__
+ struct netif_siface_data ifaces = {0};
+#endif
struct netif_saddr_data addrs = {0};
obs_property_t *p;
p = obs_properties_add_int(props, OPT_DROP_THRESHOLD, obs_module_text("RTMPStream.DropThreshold"), 200, 10000,
100);
obs_property_int_set_suffix(p, " ms");
+#ifdef __linux__
+ p = obs_properties_add_list(props, OPT_BIND_INTERFACE, obs_module_text("RTMPStream.BindInterface"),
+ OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
+
+ obs_property_list_add_string(p, obs_module_text("Default"), "default");
+
+ netif_get_ifaces(&ifaces);
+ for (size_t i = 0; i < ifaces.ifaces.num; i++) {
+ char *item = ifaces.ifaces.array[i];
+ obs_property_list_add_string(p, item, item);
+ }
+ netif_siface_data_free(&ifaces);
+#endif
p = obs_properties_add_list(props, OPT_IP_FAMILY, obs_module_text("IPFamily"), OBS_COMBO_TYPE_LIST,
OBS_COMBO_FORMAT_STRING);
diff --git a/plugins/obs-outputs/rtmp-stream.h b/plugins/obs-outputs/rtmp-stream.h
index d5bf60616ba102..c37f6becc79ad3 100644
--- a/plugins/obs-outputs/rtmp-stream.h
+++ b/plugins/obs-outputs/rtmp-stream.h
@@ -26,6 +26,7 @@
#define OPT_DROP_THRESHOLD "drop_threshold_ms"
#define OPT_PFRAME_DROP_THRESHOLD "pframe_drop_threshold_ms"
#define OPT_MAX_SHUTDOWN_TIME_SEC "max_shutdown_time_sec"
+#define OPT_BIND_INTERFACE "bind_interface"
#define OPT_BIND_IP "bind_ip"
#define OPT_IP_FAMILY "ip_family"
#define OPT_NEWSOCKETLOOP_ENABLED "new_socket_loop_enabled"
@@ -80,6 +81,7 @@ struct rtmp_stream {
struct dstr path, key;
struct dstr username, password;
struct dstr encoder_name;
+ struct dstr bind_interface;
struct dstr bind_ip;
socklen_t addrlen_hint; /* hint IPv4 vs IPv6 */
From 87dfd9f08b0fd8b9494f6bc995bd8c85512ef57b Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:51:42 +0100
Subject: [PATCH 5/5] UI: Add interface binding property for Linux
---
UI/data/locale/en-US.ini | 1 +
UI/forms/OBSBasicSettings.ui | 24 ++++++--
UI/window-basic-auto-config-test.cpp | 2 +
UI/window-basic-main-outputs.cpp | 4 ++
UI/window-basic-main.cpp | 1 +
UI/window-basic-settings.cpp | 86 +++++++++++++++++++++++++++-
UI/window-basic-settings.hpp | 3 +
7 files changed, 114 insertions(+), 7 deletions(-)
diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini
index 13da7f1b53346f..8fab710ed41e3e 100644
--- a/UI/data/locale/en-US.ini
+++ b/UI/data/locale/en-US.ini
@@ -1284,6 +1284,7 @@ Basic.Settings.Advanced.StreamDelay.Preserve="Preserve cutoff point (increase de
Basic.Settings.Advanced.StreamDelay.MemoryUsage="Estimated Memory Usage: %1 MB"
Basic.Settings.Advanced.Network="Network"
Basic.Settings.Advanced.Network.Disabled="The currently selected streaming protocol does not support changing network settings."
+Basic.Settings.Advanced.Network.BindToInterface="Bind to interface"
Basic.Settings.Advanced.Network.BindToIP="Bind to IP"
Basic.Settings.Advanced.Network.EnableNewSocketLoop="Enable network optimizations"
Basic.Settings.Advanced.Network.EnableLowLatencyMode="Enable TCP pacing"
diff --git a/UI/forms/OBSBasicSettings.ui b/UI/forms/OBSBasicSettings.ui
index a4effbcd0797a4..02a546841c6bbd 100644
--- a/UI/forms/OBSBasicSettings.ui
+++ b/UI/forms/OBSBasicSettings.ui
@@ -8239,6 +8239,19 @@
</widget>
</item>
<item row="1" column="0">
+ <widget class="QLabel" name="bindToIfaceLabel">
+ <property name="text">
+ <string>Basic.Settings.Advanced.Network.BindToInterface</string>
+ </property>
+ <property name="buddy">
+ <cstring>bindToInterface</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="bindToInterface"/>
+ </item>
+ <item row="2" column="0">
<widget class="QLabel" name="bindToIPLabel">
<property name="text">
<string>Basic.Settings.Advanced.Network.BindToIP</string>
@@ -8248,17 +8261,17 @@
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="1">
<widget class="QComboBox" name="bindToIP"/>
</item>
- <item row="3" column="1">
+ <item row="4" column="1">
<widget class="QCheckBox" name="enableNewSocketLoop">
<property name="text">
<string>Basic.Settings.Advanced.Network.EnableNewSocketLoop</string>
</property>
</widget>
</item>
- <item row="4" column="1">
+ <item row="5" column="1">
<widget class="QCheckBox" name="enableLowLatencyMode">
<property name="enabled">
<bool>false</bool>
@@ -8268,7 +8281,7 @@
</property>
</widget>
</item>
- <item row="3" column="0">
+ <item row="4" column="0">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -8281,7 +8294,7 @@
</property>
</spacer>
</item>
- <item row="2" column="1">
+ <item row="3" column="1">
<widget class="QCheckBox" name="dynBitrate">
<property name="toolTip">
<string>Basic.Settings.Output.DynamicBitrate.TT</string>
@@ -8644,6 +8657,7 @@
<tabstop>reconnectRetryDelay</tabstop>
<tabstop>reconnectMaxRetries</tabstop>
<tabstop>bindToIP</tabstop>
+ <tabstop>bindToInterface</tabstop>
<tabstop>dynBitrate</tabstop>
<tabstop>enableNewSocketLoop</tabstop>
<tabstop>enableLowLatencyMode</tabstop>
diff --git a/UI/window-basic-auto-config-test.cpp b/UI/window-basic-auto-config-test.cpp
index 380d85450e4888..022c38a82f9e5c 100644
--- a/UI/window-basic-auto-config-test.cpp
+++ b/UI/window-basic-auto-config-test.cpp
@@ -231,7 +231,9 @@ void AutoConfigTestPage::TestBandwidthThread()
obs_data_set_int(aencoder_settings, "bitrate", 32);
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
+ const char *bind_interface = config_get_string(main->Config(), "Output", "BindInterface");
const char *bind_ip = config_get_string(main->Config(), "Output", "BindIP");
+ obs_data_set_string(output_settings, "bind_interface", bind_interface);
obs_data_set_string(output_settings, "bind_ip", bind_ip);
/* -----------------------------------*/
diff --git a/UI/window-basic-main-outputs.cpp b/UI/window-basic-main-outputs.cpp
index e2953dbed946af..7739ebabea9fd3 100644
--- a/UI/window-basic-main-outputs.cpp
+++ b/UI/window-basic-main-outputs.cpp
@@ -1155,6 +1155,7 @@ bool SimpleOutput::StartStreaming(obs_service_t *service)
bool useDelay = config_get_bool(main->Config(), "Output", "DelayEnable");
int delaySec = config_get_int(main->Config(), "Output", "DelaySec");
bool preserveDelay = config_get_bool(main->Config(), "Output", "DelayPreserve");
+ const char *bindInterface = config_get_string(main->Config(), "Output", "BindInterface");
const char *bindIP = config_get_string(main->Config(), "Output", "BindIP");
#ifdef _WIN32
bool enableNewSocketLoop = config_get_bool(main->Config(), "Output", "NewSocketLoopEnable");
@@ -1172,6 +1173,7 @@ bool SimpleOutput::StartStreaming(obs_service_t *service)
}
OBSDataAutoRelease settings = obs_data_create();
+ obs_data_set_string(settings, "bind_interface", bindInterface);
obs_data_set_string(settings, "bind_ip", bindIP);
#ifdef _WIN32
obs_data_set_bool(settings, "new_socket_loop_enabled", enableNewSocketLoop);
@@ -2113,6 +2115,7 @@ bool AdvancedOutput::StartStreaming(obs_service_t *service)
bool useDelay = config_get_bool(main->Config(), "Output", "DelayEnable");
int delaySec = config_get_int(main->Config(), "Output", "DelaySec");
bool preserveDelay = config_get_bool(main->Config(), "Output", "DelayPreserve");
+ const char *bindInterface = config_get_string(main->Config(), "Output", "BindInterface");
const char *bindIP = config_get_string(main->Config(), "Output", "BindIP");
#ifdef _WIN32
bool enableNewSocketLoop = config_get_bool(main->Config(), "Output", "NewSocketLoopEnable");
@@ -2138,6 +2141,7 @@ bool AdvancedOutput::StartStreaming(obs_service_t *service)
}
OBSDataAutoRelease settings = obs_data_create();
+ obs_data_set_string(settings, "bind_interface", bindInterface);
obs_data_set_string(settings, "bind_ip", bindIP);
#ifdef _WIN32
obs_data_set_bool(settings, "new_socket_loop_enabled", enableNewSocketLoop);
diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp
index ba1886cce19751..df8cb48b9233ee 100644
--- a/UI/window-basic-main.cpp
+++ b/UI/window-basic-main.cpp
@@ -1803,6 +1803,7 @@ bool OBSBasic::InitBasicConfigDefaults()
config_set_default_uint(activeConfiguration, "Output", "RetryDelay", 2);
config_set_default_uint(activeConfiguration, "Output", "MaxRetries", 25);
+ config_set_default_string(activeConfiguration, "Output", "BindInterface", "default");
config_set_default_string(activeConfiguration, "Output", "BindIP", "default");
config_set_default_bool(activeConfiguration, "Output", "NewSocketLoopEnable", false);
config_set_default_bool(activeConfiguration, "Output", "LowLatencyEnable", false);
diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp
index dc1525ef9941f8..6c37a97658024a 100644
--- a/UI/window-basic-settings.cpp
+++ b/UI/window-basic-settings.cpp
@@ -566,6 +566,9 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
HookWidget(ui->reconnectMaxRetries, SCROLL_CHANGED, ADV_CHANGED);
HookWidget(ui->processPriority, COMBO_CHANGED, ADV_CHANGED);
HookWidget(ui->confirmOnExit, CHECK_CHANGED, ADV_CHANGED);
+#ifdef __linux__
+ HookWidget(ui->bindToInterface, COMBO_CHANGED, ADV_CHANGED);
+#endif
HookWidget(ui->bindToIP, COMBO_CHANGED, ADV_CHANGED);
HookWidget(ui->enableNewSocketLoop, CHECK_CHANGED, ADV_CHANGED);
HookWidget(ui->enableLowLatencyMode, CHECK_CHANGED, ADV_CHANGED);
@@ -667,6 +670,13 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
ui->resetOSXVSync = nullptr;
#endif
+#ifndef __linux__
+ delete ui->bindToIfaceLabel;
+ delete ui->bindToInterface;
+ ui->bindToIfaceLabel = nullptr;
+ ui->bindToInterface = nullptr;
+#endif
+
connect(ui->streamDelaySec, &QSpinBox::valueChanged, this, &OBSBasicSettings::UpdateStreamDelayEstimate);
connect(ui->outputMode, &QComboBox::currentIndexChanged, this, &OBSBasicSettings::UpdateStreamDelayEstimate);
connect(ui->simpleOutputVBitrate, &QSpinBox::valueChanged, this, &OBSBasicSettings::UpdateStreamDelayEstimate);
@@ -807,8 +817,35 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
connectScaleFilter(ui->advOutRescaleFilter, ui->advOutRescale);
connectScaleFilter(ui->advOutRecRescaleFilter, ui->advOutRecRescale);
- // Get Bind to IP Addresses
+#ifdef __linux__
+ connect(ui->bindToInterface, &QComboBox::currentIndexChanged, this, &OBSBasicSettings::UpdateAddrList);
+ ui->bindToIP->setEnabled(false);
+#endif
+
+ // Get Bind to interfaces Interfaces (Linux only)
+ // Get Bind to IP Addresses (Others)
obs_properties_t *ppts = obs_get_output_properties("rtmp_output");
+#ifdef __linux__
+ obs_property_t *p_iface = obs_properties_get(ppts, "bind_interface");
+ QStringList dedup_iface = {};
+
+ ui->bindToInterface->blockSignals(true);
+
+ size_t count_iface = obs_property_list_item_count(p_iface);
+ for (size_t i = 0; i < count_iface; i++) {
+ const char *name = obs_property_list_item_name(p_iface, i);
+ const char *val = obs_property_list_item_string(p_iface, i);
+
+ // Add interfaces without duplicates
+ if (!dedup_iface.contains(QT_UTF8(name))) {
+ dedup_iface.append(QT_UTF8(name));
+ ui->bindToInterface->addItem(QT_UTF8(name), val);
+ }
+ }
+
+ UpdateAddrList();
+ ui->bindToInterface->blockSignals(false);
+#else
obs_property_t *p = obs_properties_get(ppts, "bind_ip");
size_t count = obs_property_list_item_count(p);
@@ -818,7 +855,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
ui->bindToIP->addItem(QT_UTF8(name), val);
}
-
+#endif
obs_properties_destroy(ppts);
ui->multitrackVideoNoticeBox->setVisible(false);
@@ -2525,6 +2562,9 @@ void OBSBasicSettings::LoadAdvancedSettings()
int maxRetries = config_get_int(main->Config(), "Output", "MaxRetries");
const char *filename = config_get_string(main->Config(), "Output", "FilenameFormatting");
bool overwriteIfExists = config_get_bool(main->Config(), "Output", "OverwriteIfExists");
+#ifdef __linux__
+ const char *bindInterface = config_get_string(main->Config(), "Output", "BindInterface");
+#endif
const char *bindIP = config_get_string(main->Config(), "Output", "BindIP");
const char *rbPrefix = config_get_string(main->Config(), "SimpleOutput", "RecRBPrefix");
const char *rbSuffix = config_get_string(main->Config(), "SimpleOutput", "RecRBSuffix");
@@ -2570,6 +2610,11 @@ void OBSBasicSettings::LoadAdvancedSettings()
ui->sdrWhiteLevel->setValue(sdrWhiteLevel);
ui->hdrNominalPeakLevel->setValue(hdrNominalPeakLevel);
+#ifdef __linux__
+ if (!SetComboByValue(ui->bindToInterface, bindInterface))
+ SetInvalidValue(ui->bindToInterface, bindInterface, bindInterface);
+#endif
+
if (!SetComboByValue(ui->bindToIP, bindIP))
SetInvalidValue(ui->bindToIP, bindIP, bindIP);
@@ -3198,6 +3243,9 @@ void OBSBasicSettings::SaveAdvancedSettings()
SaveCheckBox(ui->reconnectEnable, "Output", "Reconnect");
SaveSpinBox(ui->reconnectRetryDelay, "Output", "RetryDelay");
SaveSpinBox(ui->reconnectMaxRetries, "Output", "MaxRetries");
+#ifdef __linux__
+ SaveComboData(ui->bindToInterface, "Output", "BindInterface");
+#endif
SaveComboData(ui->bindToIP, "Output", "BindIP");
SaveCheckBox(ui->autoRemux, "Video", "AutoRemux");
SaveCheckBox(ui->dynBitrate, "Output", "DynamicBitrate");
@@ -5572,6 +5620,9 @@ void OBSBasicSettings::UpdateAdvNetworkGroup()
#ifdef _WIN32
ui->enableNewSocketLoop->setVisible(enabled);
ui->enableLowLatencyMode->setVisible(enabled);
+#elif defined(__linux__)
+ ui->bindToIfaceLabel->setVisible(enabled);
+ ui->bindToInterface->setVisible(enabled);
#endif
}
@@ -5806,3 +5857,34 @@ void OBSBasicSettings::AdvAudioEncodersChanged()
ui->advOutTrack4Bitrate, ui->advOutTrack5Bitrate, ui->advOutTrack6Bitrate},
320);
}
+
+#ifdef __linux__
+void OBSBasicSettings::UpdateAddrList()
+{
+ ui->bindToIP->clear();
+
+ // Get Bind to IP Addresses (Linux only)
+ obs_properties_t *ppts = obs_get_output_properties("rtmp_output");
+ obs_property_t *p = obs_properties_get(ppts, "bind_ip");
+
+ size_t count_addr = obs_property_list_item_count(p);
+ for (size_t i = 0; i < count_addr; i++) {
+ const char *name = obs_property_list_item_name(p, i);
+ const char *val = obs_property_list_item_string(p, i);
+
+ //Put only the addresses from the selected interface
+ if (QT_UTF8(name).contains(ui->bindToInterface->currentText()) || QT_UTF8(val).contains("default"))
+ ui->bindToIP->addItem(QT_UTF8(name), val);
+ }
+
+ obs_properties_destroy(ppts);
+
+ if (ui->bindToInterface->currentIndex() > 0) {
+ ui->bindToIP->setEnabled(true);
+ } else {
+ ui->bindToIP->setEnabled(false);
+ if (!SetComboByValue(ui->bindToIP, "default"))
+ SetInvalidValue(ui->bindToIP, "default", "default");
+ }
+}
+#endif
diff --git a/UI/window-basic-settings.hpp b/UI/window-basic-settings.hpp
index 05d46fd41486d7..9c8445fec755d0 100644
--- a/UI/window-basic-settings.hpp
+++ b/UI/window-basic-settings.hpp
@@ -470,6 +470,9 @@ private slots:
void SetHotkeysIcon(const QIcon &icon);
void SetAccessibilityIcon(const QIcon &icon);
void SetAdvancedIcon(const QIcon &icon);
+#ifdef __linux__
+ void UpdateAddrList();
+#endif
void UseStreamKeyAdvClicked();
|