forked from BearWare/TeamTalk5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferencesDlg.cs
More file actions
337 lines (297 loc) · 13.5 KB
/
Copy pathPreferencesDlg.cs
File metadata and controls
337 lines (297 loc) · 13.5 KB
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
/*
* Copyright (c) 2005-2018, BearWare.dk
*
* Contact Information:
*
* Bjoern D. Rasmussen
* Kirketoften 5
* DK-8260 Viby J
* Denmark
* Email: contact@bearware.dk
* Phone: +45 20 20 54 59
* Web: http://www.bearware.dk
*
* This source code is part of the TeamTalk SDK owned by
* BearWare.dk. Use of this file, or its compiled unit, requires a
* TeamTalk SDK License Key issued by BearWare.dk.
*
* The TeamTalk SDK License Agreement along with its Terms and
* Conditions are outlined in the file License.txt included with the
* TeamTalk SDK distribution.
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using BearWare;
namespace TeamTalkApp.NET
{
struct ItemData
{
public string text;
public int id;
public ItemData(string text, int id)
{
this.text = text;
this.id = id;
}
public override string ToString()
{
return text;
}
}
public partial class PreferencesDlg : Form
{
TeamTalkBase ttclient;
Settings settings;
VideoCaptureDevice[] videodevs;
IntPtr soundloop;
public PreferencesDlg(TeamTalkBase tt, Settings settings)
{
ttclient = tt;
this.settings = settings;
InitializeComponent();
this.CenterToScreen();
dsoundRadioButton.Checked = settings.soundsystem == SoundSystem.SOUNDSYSTEM_DSOUND;
winmmRadioButton.Checked = settings.soundsystem == SoundSystem.SOUNDSYSTEM_WINMM;
UpdateSoundSystem(null, null);
vidcodecComboBox.SelectedIndex = 0;
this.vidbitrateNumericUpDown.Value = settings.codec.webm_vp8.nRcTargetBitrate;
UpdateVideoCaptureDevices();
fwCheckBox.Checked = WindowsFirewall.AppExceptionExists(Application.ExecutablePath);
}
void UpdateSoundSystem(object sender, EventArgs e)
{
sndinputComboBox.Items.Clear();
sndoutputComboBox.Items.Clear();
SoundDevice[] devs;
TeamTalkBase.GetSoundDevices(out devs);
SoundSystem soundsystem = SoundSystem.SOUNDSYSTEM_WASAPI;
if (dsoundRadioButton.Checked)
{
soundsystem = SoundSystem.SOUNDSYSTEM_DSOUND;
Debug.WriteLine("DirectSound devices");
}
else if (winmmRadioButton.Checked)
{
soundsystem = SoundSystem.SOUNDSYSTEM_WINMM;
Debug.WriteLine("WinMM devices");
}
else
Debug.WriteLine("WASAPI devices");
Debug.WriteLine("INPUT DEVICES");
foreach (SoundDevice dev in devs)
{
if (dev.nSoundSystem != soundsystem)
continue;
Debug.WriteLine("Name " + dev.szDeviceName);
Debug.WriteLine("\tID #" + dev.nDeviceID);
Debug.WriteLine("\tUnique ID #" + dev.szDeviceID);
Debug.WriteLine("\tWaveDeviceID #" + dev.nWaveDeviceID);
string tmp = "";
if (WindowsMixer.GetWaveInName(dev.nWaveDeviceID, ref tmp))
Debug.WriteLine("\tMixer name: " + tmp);
for (int i = 0; i < WindowsMixer.GetWaveInControlCount(dev.nWaveDeviceID); i++)
if (WindowsMixer.GetWaveInControlName(dev.nWaveDeviceID, i, ref tmp))
{
Debug.WriteLine("\t\tControl name: " + tmp);
Debug.WriteLine("\t\tSelected: " + WindowsMixer.GetWaveInControlSelected(dev.nWaveDeviceID, i));
}
if (dev.nMaxInputChannels > 0)
{
int index = sndinputComboBox.Items.Add(new ItemData(dev.szDeviceName, dev.nDeviceID));
if (dev.nDeviceID == settings.sndinputid)
sndinputComboBox.SelectedIndex = index;
}
if (dev.nMaxOutputChannels > 0)
{
int index = sndoutputComboBox.Items.Add(new ItemData(dev.szDeviceName, dev.nDeviceID));
if (dev.nDeviceID == settings.sndoutputid)
sndoutputComboBox.SelectedIndex = index;
}
}
if (sndinputComboBox.SelectedIndex < 0 && sndinputComboBox.Items.Count>0)
sndinputComboBox.SelectedIndex = 0;
if (sndoutputComboBox.SelectedIndex < 0 && sndoutputComboBox.Items.Count > 0)
sndoutputComboBox.SelectedIndex = 0;
}
private void UpdateSelectedSoundDevices(object sender, EventArgs e)
{
if (sndinputComboBox.SelectedItem == null ||
sndoutputComboBox.SelectedItem == null)
return;
int inputid = ((ItemData)sndinputComboBox.SelectedItem).id;
int outputid = ((ItemData)sndoutputComboBox.SelectedItem).id;
SoundDevice[] devs;
TeamTalkBase.GetSoundDevices(out devs);
int in_samplerate = 0, out_samplerate = 0;
foreach (SoundDevice dev in devs)
{
if(dev.nDeviceID == inputid)
in_samplerate = dev.nDefaultSampleRate;
if (dev.nDeviceID == outputid)
out_samplerate = dev.nDefaultSampleRate;
}
//for duplex mode both input and output sound device must support the same sample rate
duplexCheckBox.Enabled = in_samplerate == out_samplerate;
if (in_samplerate != out_samplerate)
{
duplexCheckBox.Checked = false;
echocancelCheckBox.Checked = false;
}
echocancelCheckBox.Enabled = duplexCheckBox.Checked;
}
private void sndTestCheckBox_CheckedChanged(object sender, EventArgs e)
{
ItemData input = (ItemData) sndinputComboBox.SelectedItem;
ItemData output = (ItemData)sndoutputComboBox.SelectedItem;
if (sndTestCheckBox.Checked)
{
//Extract input device and get its default samplerate.
//WASAPI devices only support one sample rate so it's important to use the correct one.
SoundDevice[] devs;
TeamTalkBase.GetSoundDevices(out devs);
int in_samplerate = 0;
foreach (SoundDevice dev in devs)
{
if (dev.nDeviceID == input.id)
in_samplerate = dev.nDefaultSampleRate;
}
SpeexDSP spxdsp = new SpeexDSP(true);
spxdsp.bEnableAGC = true;
spxdsp.bEnableDenoise = true;
spxdsp.bEnableEchoCancellation = echocancelCheckBox.Checked;
soundloop = TeamTalkBase.StartSoundLoopbackTest(input.id, output.id, in_samplerate, 1, duplexCheckBox.Checked, spxdsp);
if (soundloop == IntPtr.Zero)
{
MessageBox.Show("Failed to test selected device");
sndTestCheckBox.Checked = false;
}
}
else
TeamTalkBase.CloseSoundLoopbackTest(soundloop);
}
private void PreferencesDlg_FormClosing(object sender, FormClosingEventArgs e)
{
TeamTalkBase.CloseSoundLoopbackTest(soundloop);
}
private void UpdateVideoCaptureDevices()
{
if (!TeamTalkBase.GetVideoCaptureDevices(out videodevs) || videodevs.Length == 0)
return;
foreach (VideoCaptureDevice dev in videodevs)
{
int index = viddevComboBox.Items.Add(dev.szDeviceName);
if (dev.szDeviceID == settings.videoid)
viddevComboBox.SelectedIndex = index;
}
if(viddevComboBox.SelectedIndex<0)
viddevComboBox.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
ClientFlag flags = ttclient.GetFlags();
//Audio-tab
if ((ttclient.Flags & ClientFlag.CLIENT_SNDINOUTPUT_DUPLEX) ==
ClientFlag.CLIENT_SNDINOUTPUT_DUPLEX)
ttclient.CloseSoundDuplexDevices();
else
{
ttclient.CloseSoundInputDevice();
ttclient.CloseSoundOutputDevice();
}
ItemData inputItem = (ItemData)sndinputComboBox.SelectedItem;
ItemData outputItem = (ItemData)sndoutputComboBox.SelectedItem;
settings.sndinputid = inputItem.id;
settings.sndoutputid = outputItem.id;
if (duplexCheckBox.Checked)
{
if (!ttclient.InitSoundDuplexDevices(settings.sndinputid, settings.sndoutputid))
MessageBox.Show("Failed to init sound devices");
SpeexDSP spxdsp = new SpeexDSP(false);
ttclient.GetSoundInputPreprocess(ref spxdsp);
spxdsp.nEchoSuppress = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS;
spxdsp.nEchoSuppressActive = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS_ACTIVE;
spxdsp.bEnableEchoCancellation = echocancelCheckBox.Checked;
ttclient.SetSoundInputPreprocess(spxdsp);
}
else
{
if (!ttclient.InitSoundInputDevice(settings.sndinputid))
MessageBox.Show("Failed to init sound input device");
if (!ttclient.InitSoundOutputDevice(settings.sndoutputid))
MessageBox.Show("Failed to init sound output device");
}
if (wasapiRadioButton.Checked)
settings.soundsystem = SoundSystem.SOUNDSYSTEM_WASAPI;
else if (dsoundRadioButton.Checked)
settings.soundsystem = SoundSystem.SOUNDSYSTEM_DSOUND;
else if(winmmRadioButton.Checked)
settings.soundsystem = SoundSystem.SOUNDSYSTEM_WINMM;
//Video-tab
if (viddevComboBox.Items.Count > 0)
{
VideoCodec codec = new VideoCodec();
codec.nCodec = Codec.WEBM_VP8_CODEC;
codec.webm_vp8.nRcTargetBitrate = (int)vidbitrateNumericUpDown.Value;
codec.webm_vp8.nEncodeDeadline = WebMVP8CodecConstants.WEBM_VPX_DL_REALTIME;
VideoFormat capformat = videodevs[viddevComboBox.SelectedIndex].videoFormats[formatComboBox.SelectedIndex];
if (ttclient.Flags.HasFlag(ClientFlag.CLIENT_VIDEOCAPTURE_READY) &&
!(settings.videoid == videodevs[viddevComboBox.SelectedIndex].szDeviceID &&
Util.Equals(codec, settings.codec) &&
Util.Equals(capformat, settings.capformat)))
ttclient.CloseVideoCaptureDevice();
settings.codec.nCodec = Codec.WEBM_VP8_CODEC;
settings.codec.webm_vp8.nRcTargetBitrate = (int)vidbitrateNumericUpDown.Value;
settings.videoid = videodevs[viddevComboBox.SelectedIndex].szDeviceID;
settings.capformat = capformat;
if (!ttclient.Flags.HasFlag(ClientFlag.CLIENT_VIDEOCAPTURE_READY))
{
if(!ttclient.InitVideoCaptureDevice(settings.videoid, settings.capformat))
MessageBox.Show("Failed to initialize video capture device");
}
}
//Advanced-tab
if (fwCheckBox.Checked != WindowsFirewall.AppExceptionExists(Application.ExecutablePath))
{
if (fwCheckBox.Checked)
WindowsFirewall.AddAppException(Application.ProductName, Application.ExecutablePath);
else
WindowsFirewall.RemoveAppException(Application.ExecutablePath);
}
}
private void viddevComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
formatComboBox.Items.Clear();
for (int i = 0; i < videodevs[viddevComboBox.SelectedIndex].nVideoFormatsCount;i++ )
{
VideoFormat cap = videodevs[viddevComboBox.SelectedIndex].videoFormats[i];
int fps = cap.nFPS_Numerator / cap.nFPS_Denominator;
string imgfmt = "";
switch (cap.picFourCC)
{
case FourCC.FOURCC_I420:
imgfmt = "I420"; break;
case FourCC.FOURCC_YUY2:
imgfmt = "YUY2"; break;
case FourCC.FOURCC_RGB32:
imgfmt = "RGB32"; break;
}
int index = formatComboBox.Items.Add(cap.nWidth + "x" + cap.nHeight + " FPS: " + fps + " " + imgfmt);
if (Util.Equals(settings.capformat, cap))
formatComboBox.SelectedIndex = index;
}
if (formatComboBox.SelectedIndex < 0 && formatComboBox.Items.Count>0)
formatComboBox.SelectedIndex = 0;
}
private void duplexCheckBox_CheckedChanged(object sender, EventArgs e)
{
echocancelCheckBox.Enabled = duplexCheckBox.Checked;
}
}
}