/// <summary> /// Accesses the local video track, specified by /// this.selectedDevice and this.selectedProfile. /// MUST NOT BE CALLED FROM THE UI THREAD. /// </summary> /// <param name="factory"></param> /// <returns></returns> private IMediaStreamTrack getLocalVideo(IWebRtcFactory factory) { IReadOnlyList <IConstraint> mandatoryConstraints = new List <IConstraint>() { new Constraint("maxWidth", this.selectedProfile.Width.ToString()), new Constraint("minWidth", this.selectedProfile.Width.ToString()), new Constraint("maxHeight", this.selectedProfile.Height.ToString()), new Constraint("minHeight", this.selectedProfile.Height.ToString()), new Constraint("maxFrameRate", this.selectedProfile.FrameRate.ToString()), new Constraint("minFrameRate", this.selectedProfile.FrameRate.ToString()) }; IReadOnlyList <IConstraint> optionalConstraints = new List <IConstraint>(); var mediaConstraints = new MediaConstraints(mandatoryConstraints, optionalConstraints); // this will throw a very unhelpful exception if called from the UI thread var videoCapturer = VideoCapturer.Create(this.selectedDevice.Name, this.selectedDevice.Id, false); var options = new VideoOptions() { Factory = factory, Capturer = videoCapturer, Constraints = mediaConstraints }; var videoTrackSource = VideoTrackSource.Create(options); return(MediaStreamTrack.CreateVideoTrack("LocalVideo", videoTrackSource)); }
void SetupVideoTrack() { Logger.Debug("PeerChannel", "SetupVideoTrack"); var capability = mediaOption.VideoCaptureCapability; Logger.Debug("PeerChannel", "create video capturer"); var capturerParams = capability.CreationParameters(factory); var capturer = VideoCapturer.Create(capturerParams); if (capturer == null) { Logger.Debug("PeerChannel", "failed to create video capturer"); return; } Logger.Debug("PeerChannel", "create video track"); var track = MediaStreamTrack.CreateVideoTrack(factory, mediaOption.VideoTrackId, capturer); (capturer as IDisposable).Dispose(); Logger.Debug("PeerChannel", "add video track"); Conn.AddTrack(track); Logger.Debug("PeerChannel", "add track"); OnAddLocalVideoTrack?.Invoke(capturer, track); }
private void GetUserMedia() { Debug.WriteLine("Getting user media."); MediaDevice _selectedVideoDevice = (MediaDevice)Devices.Instance.VideoMediaDevicesList[0]; for (int i = 0; i < Devices.Instance.VideoMediaDevicesList.Count; i++) { if (Devices.Instance.VideoMediaDevicesList[i].DisplayName == (string)_localSettings.Values["SelectedCameraName"]) { _selectedVideoDevice = (MediaDevice)Devices.Instance.VideoMediaDevicesList[i]; } } List <int> widths = new List <int>(); List <int> heights = new List <int>(); List <int> frameRates = new List <int>(); foreach (var videoFormat in _selectedVideoDevice.VideoFormats) { widths.Add(videoFormat.Dimension.Width); heights.Add(videoFormat.Dimension.Height); foreach (var frameRate in videoFormat.FrameRates) { frameRates.Add(frameRate); } } // Maximum and minimum values for the selected camera IReadOnlyList <IConstraint> mandatoryConstraints = new List <IConstraint>() { new Constraint("maxWidth", widths.Max().ToString()), new Constraint("minWidth", widths.Min().ToString()), new Constraint("maxHeight", heights.Max().ToString()), new Constraint("minHeight", heights.Min().ToString()), new Constraint("maxFrameRate", frameRates.Max().ToString()), new Constraint("minFrameRate", frameRates.Min().ToString()) }; // Add optional constrains IReadOnlyList <IConstraint> optionalConstraints = new List <IConstraint>(); IMediaConstraints mediaConstraints = new MediaConstraints(mandatoryConstraints, optionalConstraints); var videoCapturer = VideoCapturer.Create(_selectedVideoDevice.DisplayName, _selectedVideoDevice.Id, false); var videoOptions = new VideoOptions(); videoOptions.Factory = _factory; videoOptions.Capturer = videoCapturer; videoOptions.Constraints = mediaConstraints; var videoTrackSource = VideoTrackSource.Create(videoOptions); _selfVideoTrack = MediaStreamTrack.CreateVideoTrack("SELF_VIDEO", videoTrackSource); var audioOptions = new AudioOptions(); audioOptions.Factory = _factory; var audioTrackSource = AudioTrackSource.Create(audioOptions); _selfAudioTrack = MediaStreamTrack.CreateAudioTrack("SELF_AUDIO", audioTrackSource); }