internal AudioDevice(Audio audio, Imports.PjAudioDeviceInfo audioDeviceInfo, int index) { Audio = audio; Index = index; Name = audioDeviceInfo.Name; PlaybackSupport = audioDeviceInfo.OutputCount > 0; RecordingSupport = audioDeviceInfo.InputCount > 0; }
private void ReloadAudioDevices() { var audioDevices = new List <AudioDevice>(); var cnt = (uint)Imports.dll_enumerateSoundDevicesCount(); IntPtr ptr = IntPtr.Zero; try { var sz = Marshal.SizeOf(new Imports.PjAudioDeviceInfo()); ptr = Marshal.AllocCoTaskMem((int)(sz * cnt)); cnt = (uint)Imports.dll_enumerateSoundDevices(ptr, cnt); var devices = new Imports.PjAudioDeviceInfo[cnt]; var longPtr = ptr.ToInt64(); for (int i = 0; i < cnt; i++) { var currentPtr = new IntPtr(longPtr); devices[i] = (Imports.PjAudioDeviceInfo)Marshal.PtrToStructure(currentPtr, typeof(Imports.PjAudioDeviceInfo)); longPtr += sz; if (devices[i].IsNull == 0 && i > 0) // 0-item is default mapper. Let's hide it from users eyes. { lock (_audioDevicesWatcher.Devices) { audioDevices.Add(new AudioDevice(this, devices[i], i) { AudioDeviceDescriptor = _audioDevicesWatcher.Devices.FirstOrDefault(x => x.Name.StartsWith(devices[i].Name)) }); } } } AudioDevices = audioDevices; } finally { if (ptr != IntPtr.Zero) { Marshal.FreeCoTaskMem(ptr); } } }