/// <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; } }
public async Task AddVideoTrackFromDeviceAsync(string trackName) { await RequestMediaAccessAsync(StreamingCaptureMode.Video); VideoCaptureDeviceInfo deviceInfo = VideoCaptureDevices.SelectedItem; if (deviceInfo == null) { throw new InvalidOperationException("No video capture device selected"); } var settings = new LocalVideoTrackSettings { trackName = trackName, videoDevice = new VideoCaptureDevice { id = deviceInfo.Id }, }; VideoCaptureFormatViewModel formatInfo = VideoCaptureFormats.SelectedItem; if (formatInfo != null) { settings.width = formatInfo.Format.width; settings.height = formatInfo.Format.height; settings.framerate = formatInfo.Format.framerate; } var track = await LocalVideoTrack.CreateFromDeviceAsync(settings); SessionModel.Current.VideoTracks.Add(new VideoTrackViewModel { Track = track, TrackImpl = track, IsRemote = false, DeviceName = deviceInfo.DisplayName }); SessionModel.Current.LocalTracks.Add(new TrackViewModel(Symbol.Video) { DisplayName = deviceInfo.DisplayName }); }
protected override async Task CreateLocalVideoTrackAsync() { string videoProfileId = VideoProfileId; var videoProfileKind = VideoProfileKind; int width = Constraints.width; int height = Constraints.height; double framerate = Constraints.framerate; #if ENABLE_WINMD_SUPPORT if (FormatMode == LocalVideoSourceFormatMode.Automatic) { // Do not constrain resolution by default, unless the device calls for it (see below). width = 0; // auto height = 0; // auto // Avoid constraining the framerate; this is generally not necessary (formats are listed // with higher framerates first) and is error-prone as some formats report 30.0 FPS while // others report 29.97 FPS. framerate = 0; // auto // For HoloLens, use video profile to reduce resolution and save power/CPU/bandwidth if (global::Windows.Graphics.Holographic.HolographicSpace.IsAvailable) { if (!global::Windows.Graphics.Holographic.HolographicDisplay.GetDefault().IsOpaque) { if (global::Windows.ApplicationModel.Package.Current.Id.Architecture == global::Windows.System.ProcessorArchitecture.X86) { // Holographic AR (transparent) x86 platform - Assume HoloLens 1 videoProfileKind = WebRTC.VideoProfileKind.VideoRecording; // No profile in VideoConferencing width = 896; // Target 896 x 504 } else { // Holographic AR (transparent) non-x86 platform - Assume HoloLens 2 videoProfileKind = WebRTC.VideoProfileKind.VideoConferencing; width = 960; // Target 960 x 540 } } } } #endif // Force again PreferredVideoCodec right before starting the local capture, // so that modifications to the property done after OnPeerInitialized() are // accounted for. //< FIXME //PeerConnection.Peer.PreferredVideoCodec = PreferredVideoCodec; // Check H.264 requests on Desktop (not supported) #if !ENABLE_WINMD_SUPPORT if (PreferredVideoCodec == "H264") { Debug.LogError("H.264 encoding is not supported on Desktop platforms. Using VP8 instead."); PreferredVideoCodec = "VP8"; } #endif // Ensure the track has a valid name string trackName = TrackName; if (trackName.Length == 0) { trackName = Guid.NewGuid().ToString(); // Re-assign the generated track name for consistency TrackName = trackName; } SdpTokenAttribute.Validate(trackName, allowEmpty: false); // Create the track var trackSettings = new LocalVideoTrackSettings { trackName = trackName, videoDevice = WebcamDevice, videoProfileId = videoProfileId, videoProfileKind = videoProfileKind, width = (width > 0 ? (uint?)width : null), height = (height > 0 ? (uint?)height : null), framerate = (framerate > 0 ? (double?)framerate : null), enableMrc = EnableMixedRealityCapture, enableMrcRecordingIndicator = EnableMRCRecordingIndicator }; Track = await LocalVideoTrack.CreateFromDeviceAsync(trackSettings); if (Track == null) { throw new Exception("Failed ot create webcam video track."); } // Synchronize the track status with the Unity component status Track.Enabled = enabled; }