private void OnStreamerStarted()
 {
     if (syncContext != null)
     {
         syncContext.Post(_ => StreamerStarted?.Invoke(), null);
     }
     else
     {
         StreamerStarted?.Invoke();
     }
 }
示例#2
0
        public void Start()
        {
            logger.Debug("MJpegOverHttpStreamer::Start(...)");

            if (running)
            {
                throw new InvalidOperationException();
            }

            streamTask = Task.Run(() =>
            {
                if (!(State == MediaState.Initialized || State == MediaState.Stopped))
                {
                    throw new InvalidOperationException("Invalid state " + State);
                }

                screenSource.BufferUpdated += ScreenSource_BufferUpdated;
                try
                {
                    logger.Debug("Start main streaming loop...");
                    StreamerStarted?.Invoke();

                    state = MediaState.Started;

                    DoStream(networkParams);
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                    errorCode = 100502;
                }
                finally
                {
                    logger.Debug("Stop main streaming loop...");

                    state = MediaState.Stopped;
                    StreamerStopped?.Invoke(null);
                }
            });
        }