async Task CreateMediaCaptureAndReadersAsync() { var frameSourceKinds = new MediaFrameSourceKind[] { MediaFrameSourceKind.Depth, MediaFrameSourceKind.Infrared, MediaFrameSourceKind.Color }; // Get me the first source group that does Depth+Infrared. var firstSourceGroupWithSourceKinds = await MediaSourceFinder.FindGroupsWithAllSourceKindsAsync(frameSourceKinds); if (firstSourceGroupWithSourceKinds != null) { this.mediaCapture = new MediaCapture(); // Note: This will blow up unless I have the restricted capability named // 'perceptionSensorsExperimental' in my .appx manifest and I think that // being a 'restricted' capability means that any app using it could not // go into store. // Note2: I've gone with Cpu here rather than Gpu because I ultimately // want a byte[] that I can send down a socket. If I go with Gpu then // I get an IDirect3DSurface but (AFAIK) there's not much of a way // to get to a byte[] from that other than to copy it into a // SoftwareBitmap and then to copy that SoftwareBitmap into a byte[] // which I don't really want to do. Hence - Cpu choice here. await this.mediaCapture.InitializeAsync( new MediaCaptureInitializationSettings() { SourceGroup = firstSourceGroupWithSourceKinds, MemoryPreference = MediaCaptureMemoryPreference.Cpu, StreamingCaptureMode = StreamingCaptureMode.Video } ); var sources = this.mediaCapture.FrameSources .Where(fs => frameSourceKinds.Contains(fs.Value.Info.SourceKind)) .Select(fs => fs.Value); // Build a description of what we have for our client to receive. this.BuildFrameSourceDescriptionMessageBuffer(sources); // Note: I originally wanted to open a multi source frame reader with all frame // sources specified but that blew up on me and so, for the moment, I am making // multiple readers. foreach (var source in sources) { var reader = new MediaFrameReaderHelper(source.Info, this.mediaCapture); this.readers.Add(reader); await reader.StartAsync(); } this.currentReaderIndex = 0; } }
public async Task GetDataSources() { // If pose is supported and selected add pose source //var ver = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily; //if (ver == "Windows.Holographic") //{ // bool isSelected; // Config.SourceSelectionDictionary.TryGetValue(Config.Pose, out isSelected); // if (isSelected) // { // DataSources.Add(new PoseSource(ref RosConnector, ref SharedTimer) // { // SourceName = Config.Pose, // PublishPeriod = 1 / Config.HololensPoseFPS // }); // } //} // Check for any available cameras var possibleSourceKinds = new MediaFrameSourceKind[] { MediaFrameSourceKind.Depth, MediaFrameSourceKind.Infrared, MediaFrameSourceKind.Color }; var groups = await MediaFrameSourceGroup.FindAllAsync(); // Find the group that exposes all of the sensors for streaming foreach (var g in groups) { if (g.DisplayName == "Sensor Streaming") { Debug.WriteLine("Found Sensor Streaming Source Group"); var mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync( new MediaCaptureInitializationSettings() { SourceGroup = g, MemoryPreference = MediaCaptureMemoryPreference.Cpu, StreamingCaptureMode = StreamingCaptureMode.Video } ); var sources = mediaCapture.FrameSources.Where(fs => possibleSourceKinds.Contains(fs.Value.Info.SourceKind)).Select(fs => fs.Value); foreach (var source in sources) { string originalSourceName = source.Info.Id.Substring(source.Info.Id.IndexOf("Source#"), 8); string assignedSourceName; Config.DataSourceDictionary.TryGetValue(originalSourceName, out assignedSourceName); bool isSelected; Config.SourceSelectionDictionary.TryGetValue(assignedSourceName, out isSelected); if (isSelected) { double assignedFrameRate; Config.FrameRateDictionary.TryGetValue(assignedSourceName, out assignedFrameRate); double assignedPublishPeriod = 1.0 / (double)assignedFrameRate; int originalFPS = (int)source.Info.VideoProfileMediaDescription[0].FrameRate; CameraHandler handler = new CameraHandler(source.Info, mediaCapture, assignedPublishPeriod); await handler.SetupReaderAsync(); DataSources.Add(new CameraSource(ref RosConnector, handler, assignedSourceName, assignedPublishPeriod) { Resolution = $"{ source.Info.VideoProfileMediaDescription[0].Width } x { source.Info.VideoProfileMediaDescription[0].Height }", OriginalFPS = originalFPS, SourceName = assignedSourceName }); } } break; } } }