-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMainForm.cs
1196 lines (930 loc) · 42 KB
/
MainForm.cs
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
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using System.Globalization;
using opentuner.MediaSources;
using opentuner.MediaSources.Minitiouner;
using opentuner.MediaSources.Longmynd;
using opentuner.MediaSources.Winterhill;
using opentuner.MediaPlayers;
using opentuner.MediaPlayers.MPV;
using opentuner.MediaPlayers.FFMPEG;
using opentuner.MediaPlayers.VLC;
using opentuner.Utilities;
using opentuner.Transmit;
using opentuner.ExtraFeatures.BATCSpectrum;
using opentuner.ExtraFeatures.BATCWebchat;
using opentuner.ExtraFeatures.MqttClient;
using opentuner.ExtraFeatures.QuickTuneControl;
using opentuner.ExtraFeatures.DATVReporter;
using Serilog;
using System.Runtime.CompilerServices;
using System.Drawing;
using opentuner.SettingsManagement;
namespace opentuner
{
delegate void updateNimStatusGuiDelegate(MainForm gui, TunerStatus new_status);
delegate void updateTSStatusGuiDelegate(int device, MainForm gui, TSStatus new_status);
delegate void updateMediaStatusGuiDelegate(int tuner, MainForm gui, MediaStatus new_status);
delegate void UpdateLBDelegate(ListBox LB, Object obj);
delegate void UpdateLabelDelegate(Label LB, Object obj);
delegate void updateRecordingStatusDelegate(MainForm gui, bool recording_status, string id);
delegate void UpdateInfoDelegate(StreamInfoContainer info_object, OTSourceData info);
public partial class MainForm : Form, IMessageFilter
{
// extras
MqttManager mqtt_client;
F5OEOPlutoControl pluto_client;
BATCSpectrum batc_spectrum;
BATCChat batc_chat;
QuickTuneControl quickTune_control;
DATVReporter datv_reporter = new DATVReporter();
private static List<OTMediaPlayer> _mediaPlayers;
private static List<OTSource> _availableSources = new List<OTSource>();
private static List<TSRecorder> _ts_recorders = new List<TSRecorder>();
private static List<TSUdpStreamer> _ts_streamers = new List<TSUdpStreamer>();
private static OTSource videoSource;
private MainSettings _settings;
private SettingsManager<MainSettings> _settingsManager;
private bool _settings_save = true;
SettingsManager<List<StoredFrequency>> frequenciesManager;
List<StoredFrequency> stored_frequencies = new List<StoredFrequency>();
List<ExternalTool> external_tools = new List<ExternalTool>();
List<VolumeInfoContainer> volume_display = new List<VolumeInfoContainer>();
List<StreamInfoContainer> info_display = new List<StreamInfoContainer>();
private bool source_connected = false;
SplitterPanel[] video_panels = new SplitterPanel[4];
bool properties_hidden = false;
public void UpdateInfo(StreamInfoContainer info_object, OTSourceData info)
{
if (info_object == null)
return;
if (info == null)
return;
if (info_object.InvokeRequired)
{
UpdateInfoDelegate ulb = new UpdateInfoDelegate(UpdateInfo);
info_object?.Invoke(ulb, new object[] { info_object, info });
}
else
{
info_object.UpdateInfo(info);
}
}
void ParseCommandLineOptions(string[] args)
{
int i = 0;
while ( i < args.Length )
{
switch (args[i])
{
case "--nosave":
_settings_save = false;
break;
case "--autoconnect":
_settings.auto_connect = true;
break;
case "--noconnect":
_settings.auto_connect = false;
break;
case "--enablebatcspectrum":
_settings.enable_spectrum_checkbox = true;
break;
case "--disablebatcspectrum":
_settings.enable_spectrum_checkbox = false;
break;
case "--enablebatcchat":
_settings.enable_chatform_checkbox = true;
break;
case "--disablebatcchat":
_settings.enable_chatform_checkbox = false;
break;
case "--enablemqtt":
_settings.enable_mqtt_checkbox = true;
break;
case "--disablemqtt":
_settings.enable_mqtt_checkbox = false;
break;
case "--enablequicktune":
_settings.enable_quicktune_checkbox = true;
break;
case "--disablequicktune":
_settings.enable_quicktune_checkbox = false;
break;
case "--enabledatvreporter":
_settings.enable_datvreporter_checkbox = true;
break;
case "--disabledatvreporter":
_settings.enable_datvreporter_checkbox = false;
break;
case "--hideproperties":
_settings.hide_properties = true;
break;
case "--showproperties":
_settings.hide_properties = false;
break;
case "--hidevideoinfo":
_settings.show_video_overlay = false;
break;
case "--showvideoinfo":
_settings.show_video_overlay = true;
break;
case "--windowwidth":
int new_window_width = 0;
if (int.TryParse(args[i+1], out new_window_width))
{
_settings.gui_window_width = new_window_width;
}
else
{
Log.Error(args[i + 1] + " is not a valid window width. Integer Expected");
}
i += 1;
break;
case "--windowheight":
int new_window_height = 0;
if (int.TryParse(args[i + 1], out new_window_height))
{
_settings.gui_window_height = new_window_height;
}
else
{
Log.Error(args[i + 1] + " is not a valid window height. Integer Expected");
}
i += 1;
break;
case "--windowx":
int new_window_x = 0;
if (int.TryParse(args[i + 1], out new_window_x))
{
_settings.gui_window_x = new_window_x;
}
else
{
Log.Error(args[i + 1] + " is not a valid window x. Integer Expected");
}
i += 1;
break;
case "--windowy":
int new_window_y = 0;
if (int.TryParse(args[i + 1], out new_window_y))
{
_settings.gui_window_y = new_window_y;
}
else
{
Log.Error(args[i + 1] + " is not a valid window y. Integer Expected");
}
i += 1;
break;
case "--defaultsource":
int new_default_source = 0;
if (int.TryParse(args[i + 1], out new_default_source))
{
if (new_default_source < 3 && new_default_source >= 0)
{
_settings.default_source = new_default_source;
}
else
{
Log.Error(args[i + 1] + " is not a valid default source parameter. 0-2 Expected");
}
}
else
{
Log.Error(args[i + 1] + " is not a valid default source parameter. 0-2 Expected");
}
i += 1;
break;
default:
Log.Warning("Unknown command line param: " + args[i]);
break;
}
// grab next param
i += 1;
}
}
public MainForm(string[] args)
{
ThreadPool.GetMinThreads(out int workers, out int ports);
ThreadPool.SetMinThreads(workers + 6, ports + 6);
InitializeComponent();
Application.AddMessageFilter(this);
_settings = new MainSettings();
//SettingsFormBuilder test = new SettingsFormBuilder(_settings);
_settingsManager = new SettingsManager<MainSettings>("open_tuner_settings");
_settings = (_settingsManager.LoadSettings(_settings));
// parse command line options
ParseCommandLineOptions(args);
//setup
splitContainer2.Panel2Collapsed = true;
splitContainer2.Panel2.Enabled = false;
checkBatcSpectrum.Checked = _settings.enable_spectrum_checkbox;
checkBatcChat.Checked = _settings.enable_chatform_checkbox;
checkMqttClient.Checked = _settings.enable_mqtt_checkbox;
checkQuicktune.Checked = _settings.enable_quicktune_checkbox;
checkDATVReporter.Checked = _settings.enable_datvreporter_checkbox;
// load available sources
_availableSources.Add(new MinitiounerSource());
_availableSources.Add(new LongmyndSource());
_availableSources.Add(new WinterhillSource());
comboAvailableSources.Items.Clear();
for (int c = 0; c < _availableSources.Count; c++)
{
comboAvailableSources.Items.Add(_availableSources[c].GetName());
}
comboAvailableSources.SelectedIndex = _settings.default_source;
sourceInfo.Text = _availableSources[_settings.default_source].GetDescription();
// load stored presets
frequenciesManager = new SettingsManager<List<StoredFrequency>>("frequency_presets");
stored_frequencies = frequenciesManager.LoadSettings(stored_frequencies);
Text = "Open Tuner (ZR6TG) - Version " + GlobalDefines.Version + " - Build: " + opentuner.Properties.Resources.BuildDate;
}
/// <summary>
/// Connect to Media Source and configure Media Players + extra's based on Media Source initialization.
/// </summary>
/// <param name="MediaSource"></param>
private bool SourceConnect(OTSource MediaSource)
{
Log.Information("Connecting to " + MediaSource.GetName());
videoSource = MediaSource;
int video_players_required = videoSource.Initialize(ChangeVideo, PropertiesPage);
if (video_players_required < 0)
{
Log.Error("Error Connecting MediaSource: " + videoSource.GetName());
MessageBox.Show("Error Connecting MediaSource: " + videoSource.GetName());
return false;
}
this.Text = this.Text += " - " + videoSource.GetDeviceName();
// preferred player to use for each video view
// 0 = vlc, 1 = ffmpeg, 2 = mpv
Log.Information("Configuring Media Players");
_mediaPlayers = ConfigureMediaPlayers(videoSource.GetVideoSourceCount(), _settings.mediaplayer_preferences, _settings.mediaplayer_windowed );
videoSource.ConfigureVideoPlayers(_mediaPlayers);
videoSource.ConfigureMediaPath(_settings.media_path);
// set recorders
_ts_recorders = ConfigureTSRecorders(videoSource, _settings.media_path);
videoSource.ConfigureTSRecorders(_ts_recorders);
// set udp streamers
_ts_streamers = ConfigureTSStreamers(videoSource, _settings.streamer_udp_hosts, _settings.streamer_udp_ports);
videoSource.ConfigureTSStreamers(_ts_streamers);
// update gui
SourcePage.Hide();
tabControl1.TabPages.Remove(SourcePage);
videoSource.OnSourceData += VideoSource_OnSourceData;
return true;
}
private void VideoSource_OnSourceData(int video_nr, OTSourceData properties, string description)
{
if (video_nr < info_display.Count && video_nr >= 0)
{
if (info_display[video_nr] != null)
UpdateInfo(info_display[video_nr], properties);
}
else
{
Log.Error("info_display count does not fit video_nr");
}
if (datv_reporter != null)
{
if (properties.demod_locked)
{
bool result = datv_reporter.SendISawMessage(new ISawMessage(
properties.service_name,
properties.db_margin,
properties.mer,
properties.frequency,
properties.symbol_rate,
videoSource.GetDeviceName()
));
/*
if (!result)
{
if (!datv_reporter.Connected)
{
datv_reporter.Connect();
}
}
*/
}
}
if (batc_spectrum != null)
{
float freq = properties.frequency;
float sr = properties.symbol_rate;
string callsign = properties.service_name;
//Log.Information(callsign.ToString() + "," + freq.ToString() + "," + sr.ToString());
batc_spectrum.updateSignalCallsign(callsign, freq/1000, sr/1000);
}
if (mqtt_client != null)
{
// send mqtt data
mqtt_client.SendProperties(properties, videoSource.GetName() + "/" + description);
}
}
public static void UpdateLB(ListBox LB, Object obj)
{
if (LB == null)
return;
if (LB.InvokeRequired)
{
UpdateLBDelegate ulb = new UpdateLBDelegate(UpdateLB);
if (LB != null)
{
LB?.Invoke(ulb, new object[] { LB, obj });
}
}
else
{
if (LB.Items.Count > 1000)
{
LB.Items.Remove(0);
}
int i = LB.Items.Add(DateTime.Now.ToShortTimeString() + " : " + obj);
LB.TopIndex = i;
}
}
private void debug(string msg)
{
UpdateLB(dbgListBox, msg);
}
public void start_video(int video_number)
{
if (_mediaPlayers == null)
{
Log.Debug("Media player is still null");
return;
}
if (video_number < _mediaPlayers.Count)
{
if (video_number == 0)
{
Log.Information("Ping");
}
videoSource.StartStreaming(video_number);
_mediaPlayers[video_number].Play();
// Start with volume "muted".
// The real audio volume is set later.
// Reason for muting here:
// If audio is muted for the tuner and stream
// we start with Volume 100 or so here and get an annoying audio glitch.
// (detected with MPV player)
_mediaPlayers[video_number].SetVolume(0);
}
}
public void stop_video(int video_number)
{
if (_mediaPlayers == null)
{
return;
}
if (video_number < _mediaPlayers.Count)
{
videoSource.StopStreaming(video_number);
_mediaPlayers[video_number].Stop();
}
}
private void ChangeVideo(int video_number, bool start)
{
Log.Information("Change Video " + video_number.ToString());
if (start)
start_video(video_number-1);
else
stop_video(video_number-1);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Log.Information("Exiting...");
Application.RemoveMessageFilter(this);
Log.Information("* Saving Settings");
// save current windows properties
_settings.gui_window_width = this.Width;
_settings.gui_window_height = this.Height;
_settings.gui_window_x = this.Left;
_settings.gui_window_y = this.Top;
_settings.gui_main_splitter_position = splitContainer1.SplitterDistance;
if (_settings_save)
_settingsManager.SaveSettings(_settings);
try
{
/*
if (mqtt_client != null)
{
mqtt_client.Disconnect();
}
*/
if (batc_spectrum != null)
batc_spectrum.Close();
if (batc_chat != null)
batc_chat.Close();
if (quickTune_control != null)
quickTune_control.Close();
if (datv_reporter != null)
datv_reporter.Close();
Log.Information("* Stopping Playing Video");
if (videoSource != null)
{
for (int i = 0; i < videoSource.GetVideoSourceCount(); i++)
{
ChangeVideo(i+1, false);
}
}
Log.Information("* Closing Extra TS Threads");
// close ts streamers
for (int c = 0; c < _ts_streamers.Count; c++)
{
_ts_streamers[c].Close();
}
// close ts recorders
for (int c = 0; c < _ts_recorders.Count; c++)
{
_ts_recorders[c].Close();
}
// close available media sources
for (int c = 0; c < _availableSources.Count; c++)
{
_availableSources[c].Close();
}
}
catch ( Exception Ex)
{
// we are closing, we don't really care about exceptions at this point
Log.Error( Ex, "Closing Exception");
}
Log.Information("Bye!");
}
private void Form1_Load(object sender, EventArgs e)
{
if (_settings.media_path.Length == 0)
_settings.media_path = AppDomain.CurrentDomain.BaseDirectory;
if (_settings.gui_window_width != -1)
{
Log.Information("Restoring Window Positions:");
Log.Information(" Size: (" + _settings.gui_window_height.ToString() + "," + _settings.gui_window_width.ToString() + ")");
Log.Information(" Position: (" + _settings.gui_window_x.ToString() + "," + _settings.gui_window_y.ToString() + ")");
this.Height = _settings.gui_window_height;
this.Width = _settings.gui_window_width;
this.Left = _settings.gui_window_x;
this.Top = _settings.gui_window_y;
}
// auto connect if specified
if (_settings.auto_connect)
{
source_connected = ConnectSelectedSource();
}
// hide/show video overlay
}
private void Batc_spectrum_OnSignalSelected(int Receiver, uint Freq, uint SymbolRate)
{
videoSource.SetFrequency(Receiver, Freq, SymbolRate, true);
}
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
settingsForm settings_form = new settingsForm(ref _settings);
if (settings_form.ShowDialog() == DialogResult.OK)
{
_settingsManager.SaveSettings(_settings);
}
}
private void qO100WidebandChatToolStripMenuItem_Click(object sender, EventArgs e)
{
if (batc_chat != null)
batc_chat.Show();
}
private void manualToolStripMenuItem_Click(object sender, EventArgs e)
{
batc_spectrum.changeTuneMode(0);
manualToolStripMenuItem.Checked = true;
autoHoldToolStripMenuItem.Checked = false;
autoTimedToolStripMenuItem.Checked = false;
}
private void autoTimedToolStripMenuItem_Click(object sender, EventArgs e)
{
batc_spectrum.changeTuneMode(2);
manualToolStripMenuItem.Checked = false;
autoHoldToolStripMenuItem.Checked = false;
autoTimedToolStripMenuItem.Checked = true;
}
private void autoHoldToolStripMenuItem_Click(object sender, EventArgs e)
{
batc_spectrum.changeTuneMode(3);
manualToolStripMenuItem.Checked = false;
autoHoldToolStripMenuItem.Checked = true;
autoTimedToolStripMenuItem.Checked = false;
}
private void configureCallsignToolStripMenuItem_Click(object sender, EventArgs e)
{
pluto_client.ConfigureCallsignAndReboot("ZR6TG");
}
private void LoadSeperateWindow(Control VideoControl, string Title, int Nr, Control[] extraControls)
{
var external_video_form = new VideoViewForm(VideoControl, Title, Nr, videoSource, extraControls);
external_video_form.Show();
}
private OTMediaPlayer ConfigureVideoPlayer(int nr, int preference, bool seperate_window)
{
OTMediaPlayer player = null;
VolumeInfoContainer video_volume_display = null;
StreamInfoContainer video_info_display = null;
video_volume_display = new VolumeInfoContainer();
video_volume_display.Tag = nr;
video_info_display = new StreamInfoContainer(_settings.show_video_overlay);
video_info_display.Tag = nr;
switch (preference)
{
case 0: // vlc
Log.Information(nr.ToString() + " - " + "VLC");
var vlc_video_player = new LibVLCSharp.WinForms.VideoView();
vlc_video_player.Dock = DockStyle.Fill;
vlc_video_player.MouseClick += video_player_MouseClick;
vlc_video_player.MouseWheel += video_player_MouseWheel;
vlc_video_player.Tag = nr;
if (seperate_window)
{
LoadSeperateWindow(vlc_video_player, "VLC - " + (nr + 1).ToString(), nr, new Control[] {video_volume_display, video_info_display});
}
else
{
video_panels[nr].Controls.Add(video_volume_display);
video_panels[nr].Controls.Add(video_info_display);
video_panels[nr].Controls.Add(vlc_video_player);
}
player = new VLCMediaPlayer(vlc_video_player);
player.Initialize(videoSource.GetVideoDataQueue(nr), nr);
break;
case 1: // ffmpeg
Log.Information(nr.ToString() + " - " + "FFMPEG");
var ffmpeg_video_player = new FlyleafLib.Controls.WinForms.FlyleafHost();
ffmpeg_video_player.Dock = DockStyle.Fill;
ffmpeg_video_player.MouseClick += video_player_MouseClick;
ffmpeg_video_player.MouseWheel += video_player_MouseWheel;
ffmpeg_video_player.Tag = nr;
if (seperate_window)
{
LoadSeperateWindow(ffmpeg_video_player, "FFMPEG - " + (nr + 1).ToString(), nr, new Control[] { video_volume_display, video_info_display });
}
else
{
video_panels[nr].Controls.Add(video_volume_display);
video_panels[nr].Controls.Add(video_info_display);
video_panels[nr].Controls.Add(ffmpeg_video_player);
}
player = new FFMPEGMediaPlayer(ffmpeg_video_player);
player.Initialize(videoSource.GetVideoDataQueue(nr), nr);
break;
case 2: // mpv
Log.Information(nr.ToString() + " - " + "MPV");
var mpv_video_player = new PictureBox();
mpv_video_player.Dock = DockStyle.Fill;
mpv_video_player.MouseClick += video_player_MouseClick;
mpv_video_player.MouseWheel += video_player_MouseWheel;
mpv_video_player.Tag = nr;
if (seperate_window)
{
LoadSeperateWindow(mpv_video_player, "MPV - " + (nr + 1).ToString(), nr, new Control[] { video_volume_display, video_info_display});
}
else
{
video_panels[nr].Controls.Add(video_volume_display);
video_panels[nr].Controls.Add(video_info_display);
video_panels[nr].Controls.Add(mpv_video_player);
}
player = new MPVMediaPlayer(mpv_video_player.Handle.ToInt64());
player.Initialize(videoSource.GetVideoDataQueue(nr), nr);
break;
}
if (video_volume_display != null)
volume_display.Add(video_volume_display);
if (video_info_display != null)
info_display.Add(video_info_display);
return player;
}
private void video_player_MouseWheel(object sender, MouseEventArgs e)
{
int wheel_volume_rate = 10; // todo, maybe turn this into a setting
int video_nr = (int)((Control)sender).Tag;
if (e.Delta < 0)
{
videoSource.UpdateVolume(video_nr, -1 * wheel_volume_rate);
}
if (e.Delta > 0)
{
videoSource.UpdateVolume(video_nr, wheel_volume_rate);
}
if (volume_display.Count > video_nr)
{
volume_display[video_nr].UpdateVolume(videoSource.GetVolume(video_nr));
}
}
private void video_player_MouseClick(object sender, MouseEventArgs e)
{
int video_nr = (int)((Control)sender).Tag;
if (info_display.Count > video_nr)
{
if (info_display[video_nr] != null)
info_display[video_nr].Visible = !info_display[video_nr].Visible;
}
}
// configure TS recorders
private List<TSRecorder> ConfigureTSRecorders(OTSource video_source, string video_path)
{
List<TSRecorder> tSRecorders = new List<TSRecorder>();
for (int c = 0; c < video_source.GetVideoSourceCount(); c++)
{
var ts_recorder = new TSRecorder(video_path, c, video_source);
tSRecorders.Add(ts_recorder);
}
return tSRecorders;
}
// configure TS streamers
private List<TSUdpStreamer> ConfigureTSStreamers(OTSource video_source, string[] udpHosts, int[] udpPorts )
{
List<TSUdpStreamer> tsStreamers = new List<TSUdpStreamer>();
for (int c= 0; c < videoSource.GetVideoSourceCount(); c++)
{
var ts_streamer = new TSUdpStreamer(udpHosts[c], udpPorts[c], c, video_source);
tsStreamers.Add(ts_streamer);
}
return tsStreamers;
}
// configure media players
private List<OTMediaPlayer> ConfigureMediaPlayers(int amount, int[] playerPreference, bool[] windowed)
{
List<OTMediaPlayer> mediaPlayers = new List<OTMediaPlayer>();
if (amount == 4)
{
video_panels[0] = splitContainer4.Panel1;
video_panels[2] = splitContainer5.Panel1;
video_panels[1] = splitContainer4.Panel2;
video_panels[3] = splitContainer5.Panel2;
}
else
{
video_panels[0] = splitContainer4.Panel1;
video_panels[1] = splitContainer5.Panel1;
video_panels[2] = splitContainer4.Panel2;
video_panels[3] = splitContainer5.Panel2;
}
for (int c = 0; c < amount; c++)
{
var media_player = ConfigureVideoPlayer(c, playerPreference[c], windowed[c]);
mediaPlayers.Add(media_player);
}
ConfigureVideoLayout(amount);
return mediaPlayers;
}
// configure video layout - only for 1, 2 or 4 video players
// todo: reset for changing sources
private void ConfigureVideoLayout(int amount)
{
splitContainer3.Visible = true;
splitContainer4.Visible = true;
splitContainer5.Visible = true;
switch (amount)
{
case 1:
splitContainer4.Panel2Collapsed = true;
splitContainer4.Panel2.Hide();
splitContainer3.Panel2Collapsed = true;
splitContainer3.Panel2.Hide();
break;
case 2:
splitContainer4.Panel2Collapsed = true;
splitContainer4.Panel2.Hide();
splitContainer5.Panel2Collapsed = true;
splitContainer5.Panel2.Hide();
break;
}
}
private void DisconnectCurrentSource()
{
toolstripConnectToggle.Text = "Connect Source";
}
private bool ConnectSelectedSource()
{
if (!SourceConnect(_availableSources[comboAvailableSources.SelectedIndex]))
return false;
if (checkBatcSpectrum.Checked)
{
// show spectrum
splitContainer2.Panel2Collapsed = false;
splitContainer2.Panel2.Enabled = true;
this.DoubleBuffered = true;
batc_spectrum = new BATCSpectrum(spectrum, videoSource.GetVideoSourceCount());
batc_spectrum.OnSignalSelected += Batc_spectrum_OnSignalSelected;
}
if (checkBatcChat.Checked)
{
qO100WidebandChatToolStripMenuItem.Visible = true;
batc_chat = new BATCChat(videoSource);
}
if (checkQuicktune.Checked)
{
quickTune_control = new QuickTuneControl(videoSource);
}
if (checkMqttClient.Checked)
{
mqtt_client = new MqttManager();
}
if (checkDATVReporter.Checked)
{
if (!datv_reporter.Connect())
{
Log.Error("DATV Reporter can't connect - check your settings");
}
}
if (_settings.mute_at_startup)
{
_availableSources[comboAvailableSources.SelectedIndex].OverrideDefaultMuted(_settings.mute_at_startup);
}
splitContainer1.SplitterDistance = _settings.gui_main_splitter_position;
videoSource.UpdateFrequencyPresets(stored_frequencies);
//toolstripConnectToggle.Text = "Disconnect Source";
toolstripConnectToggle.Visible = false;
// hide/show panel
TogglePropertiesPanel(_settings.hide_properties);
return true;
}
private void btnSourceConnect_Click(object sender, EventArgs e)
{
source_connected = ConnectSelectedSource();
}
private void btnSourceSettings_Click(object sender, EventArgs e)
{
_availableSources[comboAvailableSources.SelectedIndex].ShowSettings();
sourceInfo.Text = _availableSources[comboAvailableSources.SelectedIndex].GetDescription();
}
private void comboAvailableSources_SelectedIndexChanged(object sender, EventArgs e)
{
sourceInfo.Text = _availableSources[comboAvailableSources.SelectedIndex].GetDescription();
}
private void checkMqttClient_CheckedChanged(object sender, EventArgs e)
{
_settings.enable_mqtt_checkbox = checkMqttClient.Checked;
}
private void checkQuicktune_CheckedChanged(object sender, EventArgs e)
{
_settings.enable_quicktune_checkbox = checkQuicktune.Checked;
}
private void checkBatcSpectrum_CheckedChanged(object sender, EventArgs e)
{
_settings.enable_spectrum_checkbox = checkBatcSpectrum.Checked;