public VoiceChannelStatusViewModel(Models.DiscordContext discordContext, Models.AudioPlaybackManager audioManager, INavigationService navService) { DiscordContext = discordContext; AudioManager = audioManager; NavigationService = navService; IsSpeakerMute_Internal = AudioManager.ToReactivePropertyAsSynchronized(x => x.IsSpeakerMute); IsMicMute_Internal = AudioManager.ToReactivePropertyAsSynchronized(x => x.IsMicMute); IsSpeakerMute = IsSpeakerMute_Internal .ToReadOnlyReactiveProperty(); // リアルスピーカーミュートまたは内部マイクミュートの場合、 // リアルマイクミュートがオンになる IsMicMute = Observable.CombineLatest( IsSpeakerMute, IsMicMute_Internal ) .Select(x => x.Any(y => y)) .ToReadOnlyReactiveProperty(); IsConnectVoiceChannel = DiscordContext .ObserveProperty(x => x.CurrentVoiceChannel) .Select(x => x != null) .ToReadOnlyReactiveProperty(); CurrentVoiceChannelName = DiscordContext .ObserveProperty(x => x.CurrentVoiceChannel) .Select(x => x?.Name ?? "") .ToReadOnlyReactiveProperty(); CurrentServerName = DiscordContext .ObserveProperty(x => x.CurrentVoiceChannel) .Select(x => x?.Guild.Name ?? "") .ToReadOnlyReactiveProperty(); InputDeviceState = AudioManager.ObserveProperty(x => x.InputDeviceState) .ToReadOnlyReactiveProperty(); HasMicError = InputDeviceState .Select(x => x != Models.InputDeviceState.Avairable) .ToReadOnlyReactiveProperty(); }
private (LocalVideoSourceCapability[] caps, InputDeviceState state) GetCapabilities(DsDevice device) { if (_initialLogging) { Log.Information($"Caps {device.Name}: getting"); } var list = new List <LocalVideoSourceCapability>(); IntPtr pCaps = IntPtr.Zero; IFilterGraph2 filterGraph2 = null; IBaseFilter sourceFilter = null; IAMStreamConfig streamConfig = null; object pin = null; InputDeviceState state = InputDeviceState.Ready; try { filterGraph2 = new FilterGraph() as IFilterGraph2; if (filterGraph2 == null) { throw new NotSupportedException("filter2 is null"); } LocalVideoSourceManager.AddCaptureFilter(filterGraph2, device, out sourceFilter); pin = DsFindPin.ByCategory(sourceFilter, PinCategory.Capture, 0); if (pin == null) { pin = sourceFilter; } streamConfig = pin as IAMStreamConfig; if (streamConfig == null) { throw new NotSupportedException("pin is null"); } int count = 0; int size = 0; Checked(() => streamConfig.GetNumberOfCapabilities(out count, out size), "GetNumberOfCapabilities", null); if (count <= 0) { throw new NotSupportedException("This video source does not report capabilities."); } if (size != Marshal.SizeOf(typeof(VideoStreamConfigCaps))) { throw new NotSupportedException("Unable to retrieve video source capabilities. This video source requires a larger VideoStreamConfigCaps structure."); } // Alloc memory for structure pCaps = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VideoStreamConfigCaps))); for (int i = 0; i < count; i++) { AMMediaType mediaType = null; Checked(() => streamConfig.GetStreamCaps(i, out mediaType, pCaps), "GetStreamCaps", null); VideoStreamConfigCaps caps = (VideoStreamConfigCaps)Marshal.PtrToStructure(pCaps, typeof(VideoStreamConfigCaps)); var format = GetMediaTypeInfo(mediaType, out var height, out var width, out var compression, out var videoInfoHeader, out var videoInfoHeader2); var result = new LocalVideoSourceCapability() { MaxF = GetFps(caps.MinFrameInterval), MinF = GetFps(caps.MaxFrameInterval), Fmt = format, W = width, H = height, }; list.Add(result); } } catch (UnauthorizedAccessException e) { Log.Warning(e, $"Error during retreiving caps for '{device.Name}' (Locked)"); state = InputDeviceState.Locked; } catch (Exception e) { Log.Error(e, $"Error during retreiving caps for '{device.Name}'"); state = InputDeviceState.Failed; } finally { if (pCaps != IntPtr.Zero) { Marshal.FreeCoTaskMem(pCaps); } } try { ReleaseComObject(sourceFilter); ReleaseComObject(filterGraph2); ReleaseComObject(streamConfig); ReleaseComObject(pin); } catch (Exception e) { Log.Error(e, $"ReleaseComObject('{device.Name}') failed"); } if (_initialLogging) { Log.Information($"Caps {device.Name}: {string.Join("; ", list.Select(s => s.ToString()))}"); } return(list.ToArray(), state); }
private void Input_InputDeviceStateChanged(InputDeviceState obj) { InputDeviceState = obj; }