private async Task SelectFallbackSourceGroupAsync() { #if USE_INFRARED var devices = await DeviceInformation.FindAllAsync(MediaFrameSourceGroup.GetDeviceSelector()); foreach (var deviceInformation in devices) { var sourceGroup = await MediaFrameSourceGroup.FromIdAsync(deviceInformation.Id); var colorSourceInfos = sourceGroup.SourceInfos.Where(sourceInfo => sourceInfo.SourceKind == MediaFrameSourceKind.Color); var enclosureLocation = colorSourceInfos.Select(sourceInfo => sourceInfo?.DeviceInformation?.EnclosureLocation).FirstOrDefault(enclosure => enclosure != null); if (colorSourceInfos.Any() && enclosureLocation.Panel == InfraredEnclosureLocation.Panel) { FallbackSourceGroup = sourceGroup; ExclusiveRgbSourceInfo = colorSourceInfos.OrderByDescending(sourceInfo => sourceInfo?.MediaStreamType == ExclusiveIrSourceInfo.MediaStreamType).First(); ColorEnclosureLocation = enclosureLocation; break; } } #else SharedSourceInfo = ExclusiveRgbSourceInfo; SharedSourceGroup = ExclusiveSourceGroup; #endif }
public void Initialize() { string fsselector = MediaFrameSourceGroup.GetDeviceSelector(); // string dis = MediaFrameSourceGroup.GetDeviceSelector(). _watcher = DeviceInformation.CreateWatcher(fsselector); _watcher.Added += async(sender, devInfo) => { await _AddAcceptableSourceGroupAsync(devInfo.Id); Debug.WriteLine("Watcher Added " + devInfo.Name); }; _watcher.Removed += (sender, devInfo) => { _sourceGroups.Remove(devInfo.Id); }; _watcher.Updated += async(sender, devInfo) => { _sourceGroups.Remove(devInfo.Id); await _AddAcceptableSourceGroupAsync(devInfo.Id); }; _watcher.EnumerationCompleted += (sender, sourceGroup) => { // Update UI. }; _watcher.Start(); }
public SourceGroupCollection(CoreDispatcher uiDispatcher) { _dispatcher = uiDispatcher; _sourceCollection = new ObservableCollection <FrameSourceGroupModel>(); var deviceSelector = MediaFrameSourceGroup.GetDeviceSelector(); _watcher = DeviceInformation.CreateWatcher(deviceSelector); _watcher.Added += Watcher_Added; _watcher.Removed += Watcher_Removed; _watcher.Updated += Watcher_Updated; _watcher.Start(); }
private async Task SelectExclusiveSourceGroupAsync() { #if USE_INFRARED var devices = await DeviceInformation.FindAllAsync(MediaFrameSourceGroup.GetDeviceSelector()); foreach (var deviceInformation in devices) { var sourceGroup = await MediaFrameSourceGroup.FromIdAsync(deviceInformation.Id); var current = new DefaultDictionary <MediaFrameSourceKind, Dictionary <MediaStreamType, MediaFrameSourceInfo> >(); ulong currentIrCapability = 0u; foreach (var sourceInfo in sourceGroup.SourceInfos) { var originSourceGroupId = sourceInfo.Id.Split('@').ElementAtOrDefault(1) ?? sourceInfo.Id; EnclosureLocations[originSourceGroupId] = EnclosureLocations[originSourceGroupId] ?? deviceInformation.EnclosureLocation; if (sourceInfo.MediaStreamType != MediaStreamType.VideoPreview && sourceInfo.MediaStreamType != MediaStreamType.VideoRecord) { continue; } switch (sourceInfo.SourceKind) { case MediaFrameSourceKind.Color: current[sourceInfo.SourceKind][sourceInfo.MediaStreamType] = sourceInfo; break; case MediaFrameSourceKind.Infrared: if (sourceInfo.Properties.TryGetValue(MF._DEVICESTREAM_ATTRIBUTE_FACEAUTH_CAPABILITY, out var capability)) { if (capability is ulong ulCapability && (ulCapability & ( KS.CAMERA_EXTENDEDPROP_FACEAUTH_MODE_ALTERNATIVE_FRAME_ILLUMINATION | KS.CAMERA_EXTENDEDPROP_FACEAUTH_MODE_BACKGROUND_SUBTRACTION)) != 0) { currentIrCapability = ulCapability; current[sourceInfo.SourceKind][sourceInfo.MediaStreamType] = sourceInfo; } } break; } } if (current[MediaFrameSourceKind.Infrared].Any()) { var score = GetSourceGroupScore(current); if (score <= ExclusiveSourceGroupScore) { continue; } var preferredMediaStreamType = current[MediaFrameSourceKind.Infrared].Keys .Intersect(current[MediaFrameSourceKind.Color].Keys) .DefaultIfEmpty(MediaStreamType.VideoPreview) .OrderByDescending(mediaStreamType => mediaStreamType == MediaStreamType.VideoPreview) .First(); ExclusiveIrSourceInfo = current[MediaFrameSourceKind.Infrared].OrderByDescending(kvp => kvp.Key == preferredMediaStreamType).First().Value; ExclusiveRgbSourceInfo = current[MediaFrameSourceKind.Color].OrderByDescending(kvp => kvp.Key == ExclusiveIrSourceInfo.MediaStreamType).Select(kvp => kvp.Value).FirstOrDefault(); ExclusiveSourceGroup = sourceGroup; ExclusiveIrCapability = currentIrCapability; ExclusiveSourceGroupScore = score; if ((ExclusiveRgbSourceInfo != null) && deviceInformation.EnclosureLocation != null) { break; } } } if (ExclusiveIrSourceInfo != null) { EnclosureLocations.TryGetValue(ExclusiveIrSourceInfo.Id.Split('@').ElementAtOrDefault(1) ?? ExclusiveIrSourceInfo.Id, out InfraredEnclosureLocation); } if (ExclusiveRgbSourceInfo != null) { EnclosureLocations.TryGetValue(ExclusiveRgbSourceInfo.Id.Split('@').ElementAtOrDefault(1) ?? ExclusiveRgbSourceInfo.Id, out ColorEnclosureLocation); } #else var sourceGroups = await MediaFrameSourceGroup.FindAllAsync(); if (sourceGroups.Any() && sourceGroups.First() is MediaFrameSourceGroup sourceGroup) { ExclusiveRgbSourceInfo = sourceGroup.SourceInfos.OrderByDescending(si => si.MediaStreamType == MediaStreamType.VideoPreview).First(); ExclusiveSourceGroup = sourceGroup; } #endif if (ExclusiveRgbSourceInfo == null) { UseFallbackSourceGroup = true; } }
private static async Task <Tuple <MediaFrameSourceGroup, MediaFrameSourceInfo> > EnumFrameSourcesAsync() { MediaFrameSourceInfo result_info = null; MediaFrameSourceGroup result_group = null; var sourcegroups = await AsyncHelper.AsAsync(MediaFrameSourceGroup.FindAllAsync()); Log.WriteLine("found {0} Source Groups", sourcegroups.Count); if (sourcegroups.Count == 0) { var dinfos = await AsyncHelper.AsAsync(DeviceInformation.FindAllAsync(MediaFrameSourceGroup.GetDeviceSelector())); Log.WriteLine("found {0} devices from MediaFrameSourceGroup selector", dinfos.Count); foreach (var info in dinfos) { Log.WriteLine(info.Name); } if (dinfos.Count == 0) { dinfos = await AsyncHelper.AsAsync(DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)); Log.WriteLine("found {0} devices from Video Capture DeviceClass", dinfos.Count); foreach (var info in dinfos) { Log.WriteLine(info.Name); } } } foreach (var g in sourcegroups) { var sourceinfos = g.SourceInfos; Log.WriteLine("Source Group {0}", g.Id); Log.WriteLine(" {0}", g.DisplayName); Log.WriteLine(" with {0} Sources:", sourceinfos.Count); foreach (var s in sourceinfos) { var d = s.DeviceInformation; Log.WriteLine("\t{0}", s.Id); Log.WriteLine("\t\tKind {0}", s.SourceKind); Log.WriteLine("\t\tDevice {0}", d.Id); Log.WriteLine("\t\t {0}", d.Name); Log.WriteLine("\t\t Kind {0}", d.Kind); if (result_info == null) { result_info = s; // for now just pick the first thing we find } } Log.EndLine(); if (result_group == null) { result_group = g; // for now just pick the first thing we find } } return(new Tuple <MediaFrameSourceGroup, MediaFrameSourceInfo>(result_group, result_info)); }