Example #1
0
 //------------------------------------------------------------------------------------------------------------------------
 public void AddNewFeed(string mjpegtoken, IVideoSink videofeed)
 {
     lock (this)
     {
         try
         {
             //add to dictionary
             videofeeds.Add(mjpegtoken, videofeed);
         }
         catch (Exception ex)
         {
             DebugEx.TraceErrorException(ex);
         }
     }
 }
Example #2
0
        //------------------------------------------------------------------------------------------------------------------------
        public void AddNewFeed(string mjpegtoken, IVideoSink videofeed)
        {
            lock (this)
            {
                try
                {
                    //add to dictionary
                    videofeeds.Add(mjpegtoken, videofeed);
                }
                catch (Exception ex)
                {
                    DebugEx.TraceErrorException(ex);
                }
            }

        }
Example #3
0
        public void CreatePeerConnection(IVideoSink localVideoSink, IVideoSink remoteVideoSink,
                                         IVideoCapturer videoCapturer)
        {
            _localVideoSink  = localVideoSink;
            _removeVideoSink = remoteVideoSink;

            _videoCapturer = videoCapturer;

            Executor.Execute(new Runnable(() =>
            {
                try
                {
                    CreateMediaConstraintsInternal();
                    CreatePeerConnectionInternal();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Failed to create peer connection:{ex.Message}");
                }
            }));
        }
Example #4
0
        private static Task <RTCPeerConnection> CreatePeerConnection(IVideoSource videoSource, IVideoSink videoSink)
        {
            var pc = new RTCPeerConnection(null);

            MediaStreamTrack videoTrack = new MediaStreamTrack(videoSink.GetVideoSinkFormats(), MediaStreamStatusEnum.SendRecv);

            pc.addTrack(videoTrack);

            videoSource.OnVideoSourceEncodedSample += pc.SendVideo;
            pc.OnVideoFrameReceived     += videoSink.GotVideoFrame;
            pc.OnVideoFormatsNegotiated += (formats) =>
            {
                videoSink.SetVideoSinkFormat(formats.First());
                videoSource.SetVideoSourceFormat(formats.First());
            };

            pc.OnTimeout += (mediaType) => logger.LogDebug($"Timeout on media {mediaType}.");
            pc.oniceconnectionstatechange += (state) => logger.LogDebug($"ICE connection state changed to {state}.");
            pc.onconnectionstatechange    += async(state) =>
            {
                logger.LogDebug($"Peer connection connected changed to {state}.");

                if (state == RTCPeerConnectionState.closed || state == RTCPeerConnectionState.failed)
                {
                    await videoSource.CloseVideo().ConfigureAwait(false);
                }
            };

            return(Task.FromResult(pc));
        }