private void GenerateTestPattern(object state) { lock (_sendTestPatternTimer) { if (!_isClosed && OnVideoSourceRawSample != null) { _frameCount++; //var stampedTestPattern = _testPattern.Clone() as System.Drawing.Image; //AddTimeStampAndLocation(stampedTestPattern, DateTime.UtcNow.ToString("dd MMM yyyy HH:mm:ss:fff"), "Test Pattern"); //// This event handler could get removed while the timestamp text is being added. //OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, _testPattern.Width, _testPattern.Height, BitmapToBGR24(stampedTestPattern as Bitmap), VideoPixelFormatsEnum.Bgr); //stampedTestPattern?.Dispose(); //OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, _testPatternWidth, _testPatternHeight, _testPatternI420, VideoPixelFormatsEnum.I420); StampI420Buffer(_testI420Buffer, TEST_PATTERN_WIDTH, TEST_PATTERN_HEIGHT, _frameCount); OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, TEST_PATTERN_WIDTH, TEST_PATTERN_HEIGHT, _testI420Buffer, VideoPixelFormatsEnum.I420); if (_frameCount == int.MaxValue) { _frameCount = 0; } } } }
private void GenerateTestPattern(object state) { lock (_sendTestPatternTimer) { if (!_isClosed && OnVideoSourceRawSample != null) { var stampedTestPattern = _testPattern.Clone() as System.Drawing.Image; AddTimeStampAndLocation(stampedTestPattern, DateTime.UtcNow.ToString("dd MMM yyyy HH:mm:ss:fff"), "Test Pattern"); // This event handler could get removed while the timestamp text is being added. OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, _testPattern.Width, _testPattern.Height, BitmapToBGR24(stampedTestPattern as Bitmap), VideoPixelFormatsEnum.Bgr); stampedTestPattern?.Dispose(); } } }
private void GenerateTestPattern(object state) { lock (_sendTestPatternTimer) { if (!_isClosed && (OnVideoSourceRawSample != null || OnVideoSourceEncodedSample != null)) { _frameCount++; //var stampedTestPattern = _testPattern.Clone() as System.Drawing.Image; //AddTimeStampAndLocation(stampedTestPattern, DateTime.UtcNow.ToString("dd MMM yyyy HH:mm:ss:fff"), "Test Pattern"); //// This event handler could get removed while the timestamp text is being added. //OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, _testPattern.Width, _testPattern.Height, BitmapToBGR24(stampedTestPattern as Bitmap), VideoPixelFormatsEnum.Bgr); //stampedTestPattern?.Dispose(); //OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, _testPatternWidth, _testPatternHeight, _testPatternI420, VideoPixelFormatsEnum.I420); StampI420Buffer(_testI420Buffer, TEST_PATTERN_WIDTH, TEST_PATTERN_HEIGHT, _frameCount); OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, TEST_PATTERN_WIDTH, TEST_PATTERN_HEIGHT, _testI420Buffer, VideoPixelFormatsEnum.I420); if (_videoEncoder != null && OnVideoSourceEncodedSample != null) { var encodedBuffer = _videoEncoder.EncodeVideo(TEST_PATTERN_WIDTH, TEST_PATTERN_HEIGHT, _testI420Buffer, VideoPixelFormatsEnum.I420, VideoCodecsEnum.VP8); if (encodedBuffer != null) { uint fps = (_frameSpacing > 0) ? 1000 / (uint)_frameSpacing : DEFAULT_FRAMES_PER_SECOND; uint durationRtpTS = VIDEO_SAMPLING_RATE / fps; OnVideoSourceEncodedSample.Invoke(durationRtpTS, encodedBuffer); } } if (_frameCount == int.MaxValue) { _frameCount = 0; } } } }
/// <summary> /// Consumers subscribing to the <seealso cref="OnVideoSourceRawSample"/> will most likely want bitmap samples. /// This method takes the I420 buffer for the test patten frame, converts it to BGR and fire the event. /// </summary> /// <param name="i420Buffer">The I420 buffer representing the test pattern.</param> private void GenerateRawSample(int width, int height, byte[] i420Buffer) { var bgr = PixelConverter.I420toBGR(i420Buffer, width, height, out _); OnVideoSourceRawSample?.Invoke((uint)_frameSpacing, width, height, bgr, VideoPixelFormatsEnum.Bgr); }