/// <summary> /// Creates asynchronously the Media Capture which will process the depth stream images /// </summary> /// <param name="clbk">The Callback object to call when the hand detection status changes.</param> /// <returns>The asynchronous task</returns> public async Task InitializeAsync(IHDMediaSinkClbk clbk) { //Create the media capture Debug.WriteLine("Creating a media capture..."); m_mediaCapture = new MediaCapture(); await m_mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings() { VideoDeviceId = m_mediaInfo.DeviceInformation.Id, SharingMode = MediaCaptureSharingMode.SharedReadOnly, MemoryPreference = MediaCaptureMemoryPreference.Auto, //For the Hololens, MediaCaptureMemoryPreference.CPU does not work StreamingCaptureMode = StreamingCaptureMode.Video }); //Find a correct video profile with the best capabilities (resolution) Debug.WriteLine("Search a video profile..."); VideoEncodingProperties videoProfile = null; var mediaProperties = m_mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); UInt32 maxHeight = 0; foreach (var mediaProp in mediaProperties) { VideoEncodingProperties videoProp = mediaProp as VideoEncodingProperties; Debug.WriteLine($"VideoProp : {videoProp.Type}:{videoProp.Subtype} {videoProp.Width}x{videoProp.Height}"); if (videoProp.Subtype == "ARGB32" || videoProp.Subtype == "L8" || videoProp.Subtype == "D16" || videoProp.Subtype == "D8" || videoProp.Subtype == "L16" || videoProp.Subtype == "RGB24") { if (maxHeight < videoProp.Height) { videoProfile = videoProp; maxHeight = videoProp.Height; } } } if (videoProfile == null) { Debug.WriteLine("No video profile found..."); await Task.FromResult <Windows.Foundation.IAsyncAction>(null); } else { Debug.WriteLine($"Starting to preview {m_mediaInfo.DeviceInformation.Name} : {m_mediaInfo.DeviceInformation.Id} at {videoProfile.Width}x{videoProfile.Height}: {videoProfile.Subtype}"); //Create the video encoding MediaEncodingProfile profile = new MediaEncodingProfile(); profile.Video = videoProfile; profile.Audio = null; //Create and start preview in the MediaSink Debug.WriteLine(m_mediaInfo.DeviceInformation.Name); m_mediaSink = new HDMediaSinkProxy(); IMediaExtension ext = await m_mediaSink.InitializeAsync(clbk, profile.Video); await m_mediaCapture.StartPreviewToCustomSinkAsync(profile, ext); } Debug.WriteLine("End of Create media capture async"); }
public async Task StartAsync() { var profile = new MediaEncodingProfile { Audio = null, Video = VideoEncodingProperties.CreateUncompressed(MediaEncodingSubtypes.Rgb32, m_width, m_height), Container = null }; await m_capture.StartPreviewToCustomSinkAsync(profile, (IMediaExtension)m_preview.MediaSink); }
public async Task StartPreview(IMediaExtension previewSink, double desiredPreviewArea) { // List of supported video preview formats to be used by the default preview format selector. var supportedVideoFormats = new List <string> { "nv12", "rgb32" }; // Find the supported preview size that's closest to the desired size var availableMediaStreamProperties = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview) .OfType <VideoEncodingProperties>() .Where(p => p != null && !String.IsNullOrEmpty(p.Subtype) && supportedVideoFormats.Contains(p.Subtype.ToLower())) .OrderBy(p => Math.Abs(p.Height * p.Width - desiredPreviewArea)) .ToList(); var previewFormat = availableMediaStreamProperties.FirstOrDefault(); // Start Preview stream await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, previewFormat); await mediaCapture.StartPreviewToCustomSinkAsync(new MediaEncodingProfile { Video = previewFormat }, previewSink); }