public VoIPMediaSession(
            MediaEndPoints mediaEndPoint,
            IPAddress bindAddress = null,
            int bindPort          = 0,
            VideoTestPatternSource testPatternSource = null)
            : base(false, false, false, bindAddress, bindPort)
        {
            if (mediaEndPoint == null)
            {
                throw new ArgumentNullException("mediaEndPoint", "The media end point parameter cannot be null.");
            }

            Media = mediaEndPoint;

            // The audio extras source is used for on-hold music.
            _audioExtrasSource = new AudioExtrasSource();
            _audioExtrasSource.OnAudioSourceEncodedSample += SendAudio;

            // Wire up the audio and video sample event handlers.
            if (Media.AudioSource != null)
            {
                var audioTrack = new MediaStreamTrack(mediaEndPoint.AudioSource.GetAudioSourceFormats());
                base.addTrack(audioTrack);
                Media.AudioSource.OnAudioSourceEncodedSample += base.SendAudio;
            }

            if (Media.VideoSource != null)
            {
                var videoTrack = new MediaStreamTrack(mediaEndPoint.VideoSource.GetVideoSourceFormats());
                base.addTrack(videoTrack);
                Media.VideoSource.OnVideoSourceEncodedSample += base.SendVideo;
                Media.VideoSource.OnVideoSourceError         += VideoSource_OnVideoSourceError;

                if (testPatternSource != null)
                {
                    // The test pattern source is used as failover if the webcam initialisation fails.
                    // It's also used as the video stream if the call is put on hold.
                    _videoTestPatternSource = testPatternSource;
                    _videoTestPatternSource.OnVideoSourceEncodedSample += base.SendVideo;
                    //_videoTestPatternSource.OnVideoSourceRawSample += Media.VideoSource.ExternalVideoSourceRawSample;
                }
            }

            if (Media.VideoSink != null)
            {
                Media.VideoSink.OnVideoSinkDecodedSample += VideoSinkSampleReady;
                base.OnVideoFrameReceived += Media.VideoSink.GotVideoFrame;
            }

            if (Media.AudioSink != null)
            {
                base.OnRtpPacketReceived += RtpMediaPacketReceived;
            }

            base.OnAudioFormatsNegotiated += AudioFormatsNegotiated;
            base.OnVideoFormatsNegotiated += VideoFormatsNegotiated;
        }
 public VoIPMediaSession(MediaEndPoints mediaEndPoint, VideoTestPatternSource testPatternSource)
     : this(mediaEndPoint, null, 0, testPatternSource)
 {
 }