public void RefreshVideoProfiles(VideoCaptureDeviceInfo item, VideoProfileKind kind) { var videoProfiles = new CollectionViewModel <MediaCaptureVideoProfile>(); if (item != null) { IReadOnlyList <MediaCaptureVideoProfile> profiles; if (kind == VideoProfileKind.Unspecified) { profiles = MediaCapture.FindAllVideoProfiles(item.Id); } else { int index = (int)kind; profiles = MediaCapture.FindKnownVideoProfiles(item.Id, (KnownVideoProfile)index); } foreach (var profile in profiles) { videoProfiles.Add(profile); } } VideoProfiles = videoProfiles; // Select first item for convenience VideoProfiles.SelectFirstItemIfAny(); }
/// <summary> /// Constructor for creating a local video device initialization settings marshaling struct. /// </summary> /// <param name="settings">The settings to initialize the newly created marshaling struct.</param> /// <seealso cref="DeviceVideoTrackSource.CreateAsync(LocalVideoDeviceInitConfig)"/> public LocalVideoDeviceMarshalInitConfig(LocalVideoDeviceInitConfig settings) { if (settings != null) { VideoDeviceId = settings.videoDevice.id; VideoProfileId = settings.videoProfileId; VideoProfileKind = settings.videoProfileKind; Width = settings.width.GetValueOrDefault(0); Height = settings.height.GetValueOrDefault(0); Framerate = settings.framerate.GetValueOrDefault(0.0); EnableMixedRealityCapture = (mrsBool)settings.enableMrc; EnableMRCRecordingIndicator = (mrsBool)settings.enableMrcRecordingIndicator; } else { VideoDeviceId = string.Empty; VideoProfileId = string.Empty; VideoProfileKind = VideoProfileKind.Unspecified; Width = 0; Height = 0; Framerate = 0.0; EnableMixedRealityCapture = mrsBool.True; EnableMRCRecordingIndicator = mrsBool.True; } }
public void RefreshVideoProfiles(VideoCaptureDeviceInfo item, VideoProfileKind kind) { var videoProfiles = new CollectionViewModel <MediaCaptureVideoProfile>(); if (item != null) { IReadOnlyList <MediaCaptureVideoProfile> profiles; if (kind == VideoProfileKind.Unspecified) { profiles = MediaCapture.FindAllVideoProfiles(item.Id); } else { // VideoProfileKind and KnownVideoProfile are the same with the exception of // `Unspecified` that takes value 0. var profile = (KnownVideoProfile)((int)kind - 1); profiles = MediaCapture.FindKnownVideoProfiles(item.Id, profile); } foreach (var profile in profiles) { videoProfiles.Add(profile); } } VideoProfiles = videoProfiles; // Select first item for convenience VideoProfiles.SelectFirstItemIfAny(); }
/// <summary> /// Constructor for creating a local video track from a wrapper and some user settings. /// </summary> /// <param name="track">The newly created track wrapper.</param> /// <param name="settings">The settings to initialize the newly created native track.</param> /// <seealso cref="PeerConnection.AddLocalVideoTrackAsync(LocalVideoTrackSettings)"/> public LocalVideoTrackInteropInitConfig(LocalVideoTrack track, LocalVideoTrackSettings settings) { trackHandle = Utils.MakeWrapperRef(track); if (settings != null) { VideoDeviceId = settings.videoDevice.id; VideoProfileId = settings.videoProfileId; VideoProfileKind = settings.videoProfileKind; Width = settings.width.GetValueOrDefault(0); Height = settings.height.GetValueOrDefault(0); Framerate = settings.framerate.GetValueOrDefault(0.0); EnableMixedRealityCapture = (mrsBool)settings.enableMrc; EnableMRCRecordingIndicator = (mrsBool)settings.enableMrcRecordingIndicator; } else { VideoDeviceId = string.Empty; VideoProfileId = string.Empty; VideoProfileKind = VideoProfileKind.Unspecified; Width = 0; Height = 0; Framerate = 0.0; EnableMixedRealityCapture = mrsBool.True; EnableMRCRecordingIndicator = mrsBool.True; } }
private static Task <IReadOnlyList <VideoCaptureFormat> > GetCaptureFormatsAsyncImpl( string deviceId, string profileId, VideoProfileKind profileKind) { // Ensure the logging system is ready before using PInvoke. MainEventSource.Log.Initialize(); // Always call this on a background thread, this is possibly the first call to the library so needs // to initialize the global factory, and that cannot be done from the main UI thread on UWP. return(Task.Run(() => { var formats = new List <VideoCaptureFormat>(); var eventWaitHandle = new ManualResetEventSlim(initialState: false); Exception resultException = null; var wrapper = new DeviceVideoTrackSourceInterop.EnumVideoCaptureFormatsWrapper() { enumCallback = (in VideoCaptureFormat format) => formats.Add(format), completedCallback = (Exception ex) => { resultException = ex; // On enumeration end, signal the caller thread eventWaitHandle.Set(); }, // Keep delegates alive EnumTrampoline = DeviceVideoTrackSourceInterop.VideoCaptureFormat_EnumCallback, CompletedTrampoline = DeviceVideoTrackSourceInterop.VideoCaptureFormat_EnumCompletedCallback, }; // Prevent garbage collection of the wrapper delegates until the enumeration is completed. var handle = GCHandle.Alloc(wrapper, GCHandleType.Normal); IntPtr userData = GCHandle.ToIntPtr(handle); // Execute the native async callback. uint res = DeviceVideoTrackSourceInterop.EnumVideoCaptureFormatsAsync(deviceId, profileId, profileKind, wrapper.EnumTrampoline, userData, wrapper.CompletedTrampoline, userData); if (res != Utils.MRS_SUCCESS) { resultException = Utils.GetExceptionForErrorCode(res); } else { // Wait for end of enumerating eventWaitHandle.Wait(); } // Clean-up and release the wrapper delegates handle.Free(); if (resultException != null) { throw resultException; } return (IReadOnlyList <VideoCaptureFormat>)formats; })); }
public async void RefreshVideoProfiles(VideoCaptureDeviceInfo item, VideoProfileKind kind) { // Clear formats, which are profile-dependent. This ensures the former list doesn't // stay visible if the current profile kind is not supported (does not return any profile). VideoCaptureFormats.Clear(); var videoProfiles = new CollectionViewModel <VideoProfile>(); if (item != null) { IReadOnlyList <VideoProfile> profiles = await DeviceVideoTrackSource.GetCaptureProfilesAsync(item.Id, kind); foreach (var profile in profiles) { videoProfiles.Add(profile); } } VideoProfiles = videoProfiles; // Select first item for convenience VideoProfiles.SelectFirstItemIfAny(); }
/// <summary> /// Enumerate the video capture formats for the specified video capture device and video profile. /// </summary> /// <param name="deviceId">Unique identifier of the video capture device to enumerate the /// capture formats of, as retrieved from the <see cref="VideoCaptureDevice.id"/> field of /// a capture device enumerated with <see cref="GetCaptureDevicesAsync"/>.</param> /// <param name="profileKind">Kind of video profile to enumerate the capture formats of.</param> /// <returns>The list of available video capture formats for the specified video capture device.</returns> public static Task <IReadOnlyList <VideoCaptureFormat> > GetCaptureFormatsAsync( string deviceId, VideoProfileKind profileKind) { return(GetCaptureFormatsAsyncImpl(deviceId, string.Empty, profileKind)); }