private void SetupAudioStream(AudioStreamSettings settings) { logger.Debug("StartAudioStream(...)"); if (audioStreamer != null) { audioStreamer.StateChanged -= AudioStreamer_StateChanged; } try { audioStreamer = new AudioStreamer(audioSource); audioStreamer.Setup(audioSettings.EncodingParams, audioSettings.NetworkParams); audioStreamer.StateChanged += AudioStreamer_StateChanged; } catch (Exception ex) { logger.Error(ex); if (audioStreamer != null) { audioStreamer.Close(); audioStreamer.StateChanged -= AudioStreamer_StateChanged; audioStreamer = null; } throw; } }
private void StartStreaming() { logger.Debug("ScreenStreamer::StartStreaming()"); var videoSettings = Session.VideoSettings; if (videoSettings.Enabled) { var captureDevice = (VideoCaptureDevice)videoSettings.CaptureDevice.Clone(); if (captureDevice.CaptureMode == CaptureMode.Screen) { var screenDevice = (ScreenCaptureDevice)captureDevice; if (screenDevice.CaptureRegion.Width > Config.MaxVideoEncoderWidth) { screenDevice.CaptureRegion.Width = Config.MaxVideoEncoderWidth; } if (screenDevice.CaptureRegion.Height > Config.MaxVideoEncoderHeight) { screenDevice.CaptureRegion.Height = Config.MaxVideoEncoderHeight; } screenDevice.Resolution = MediaToolkit.Utils.GraphicTools.DecreaseToEven(screenDevice.CaptureRegion.Size); } var videoEncoderSettings = (VideoEncoderSettings)videoSettings.EncoderSettings.Clone(); if (videoSettings.UseEncoderResoulutionFromSource) { videoEncoderSettings.Width = captureDevice.Resolution.Width; videoEncoderSettings.Height = captureDevice.Resolution.Height; } else { captureDevice.Resolution = videoEncoderSettings.Resolution; } if (captureDevice.CaptureMode == CaptureMode.UvcDevice) { videoSource = new VideoCaptureSource(); } else if (captureDevice.CaptureMode == CaptureMode.Screen) { videoSource = new ScreenSource(); } videoSource.Setup(captureDevice); videoSource.CaptureStarted += VideoSource_CaptureStarted; videoSource.CaptureStopped += VideoSource_CaptureStopped; if (Session.TransportMode == TransportMode.Tcp || Session.IsMulticast) { videoStreamer = new VideoStreamer(videoSource); videoStreamer.Setup(videoEncoderSettings, videoSettings.NetworkSettings); //videoStreamer.Setup(videoSettings.EncoderSettings, videoSettings.NetworkSettings); } else { // currently not supported... } } var audioSettings = Session.AudioSettings; if (audioSettings.Enabled) { audioSource = new AudioSource(); var captureDevice = audioSettings.CaptureDevice; var deviceId = captureDevice.DeviceId; var captureProps = captureDevice.Properties; audioSource.Setup(deviceId, captureProps); if (Session.TransportMode == TransportMode.Tcp || Session.IsMulticast) { audioStreamer = new AudioStreamer(audioSource); audioStreamer.Setup(audioSettings.EncoderSettings, audioSettings.NetworkSettings); audioStreamer.StateChanged += AudioStreamer_StateChanged; } else { // currently not supported... } } communicationService = new CommunicationService(this); communicationService.Open(); if (videoSettings.Enabled) { videoSource.Start(); videoStreamer.Start(); } if (audioSettings.Enabled) { audioSource.Start(); audioStreamer.Start(); } }