Exemple #1
0
        private void OnStreamStarted()
        {
            this.Cursor = Cursors.Default;

            infoButton.Enabled = true;

            networkSettingsLayoutPanel.Enabled     = false;
            videoSourceSettingsLayoutPanel.Enabled = false;
            audioSourceSettingsLayoutPanel.Enabled = false;

            switchStreamingStateButton.Enabled = true;
            switchStreamingStateButton.Text    = "Stop Streaming";

            contextMenu.Enabled         = true;
            startToolStripMenuItem.Text = "Stop";

            var ex = mediaStreamer.ExceptionObj;

            if (ex != null)
            {
                captureStatusLabel.Text = "Streaming attempt has failed";

                var errorMessage = ex.Message;
                var iex          = ex.InnerException;
                if (iex != null)
                {
                    errorMessage = iex.Message;
                }

                MessageBox.Show(errorMessage);


                return;
            }

            var videoSettings = currentSession.VideoSettings;

            if (videoSettings.Enabled)
            {
                var captureDescr = videoSettings?.CaptureDevice;
                if (captureDescr.CaptureMode == CaptureMode.Screen)
                {
                    var screenDescr = (ScreenCaptureDevice)captureDescr;

                    if (screenDescr.Properties.ShowDebugBorder)
                    {
                        debugBorderForm         = new RegionForm(screenDescr.CaptureRegion);
                        debugBorderForm.Visible = true;
                    }

                    if (screenDescr.Properties.ShowDebugInfo)
                    {
                        if (statisticForm == null)
                        {
                            statisticForm = new StatisticForm();
                        }
                        statisticForm.Location = screenDescr.CaptureRegion.Location;

                        var stats = mediaStreamer.Stats;

                        statisticForm.Start(stats);
                    }

                    //if (selectAreaForm != null)
                    //{
                    //    selectAreaForm.Capturing = true;
                    //}
                }
            }

            captureStatusLabel.Text = "";
            var statusDescription = "";
            var _port             = currentSession.CommunicationPort;

            if (currentSession.CommunicationPort >= 0)
            {
                var listenUri = mediaStreamer.ListenUri;
                statusDescription = "Stream running on: " + listenUri.Host + ":" + listenUri.Port;
            }

            //"Waiting for connection at " + _port + " port";
            captureStatusDescriptionLabel.Text = statusDescription;
        }
        private void startButton_Click(object sender, EventArgs e)
        {
            logger.Debug("startButton_Click(...) ");

            try
            {
                UpdateSettings();

                mainForm.Cursor = Cursors.WaitCursor;
                this.Enabled    = false;

                Task.Run(() =>
                {
                    try
                    {
                        SetupStreaming(communicationAddress);

                        StartStreaming();
                    }
                    catch (Exception ex)
                    {
                        StopStreaming();
                        throw;
                    }
                }).ContinueWith(t =>
                {
                    UpdateControls();

                    mainForm.Cursor = Cursors.Default;
                    this.Enabled    = true;

                    var ex = t.Exception;
                    if (ex != null)
                    {
                        var iex = ex.InnerException;
                        MessageBox.Show(iex.Message);
                    }
                    else
                    {
                        if (videoSettings.Enabled)
                        {
                            var captureDescr = videoSettings?.CaptureDescription;
                            if (captureDescr.CaptureMode == CaptureMode.Screen)
                            {
                                var screenDescr = (ScreenCaptureDeviceDescription)captureDescr;

                                regionForm         = new RegionForm(screenDescr.CaptureRegion);
                                regionForm.Visible = true;

                                statisticForm.Location = screenDescr.CaptureRegion.Location;
                                if (showStatistic)
                                {
                                    statisticForm.Start();
                                }
                            }
                        }
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                logger.Error(ex);

                MessageBox.Show(ex.Message);
            }
        }