public void RenderFrame(VideoFrame frame) { // WritableBitmap has to be accessed from a STA thread Dispatcher.BeginInvoke(new Action(() => { try { if (frame.Width != FrameWidth || frame.Height != FrameHeight) { FrameWidth = frame.Width; FrameHeight = frame.Height; VideoBitmap = new WriteableBitmap(FrameWidth, FrameHeight, 96, 96, PixelFormats.Bgr32, null); if (Background is ImageBrush) { ImageBrush b = (ImageBrush)Background; b.ImageSource = VideoBitmap; } else { throw new Exception("Please use an ImageBrush as background in the SampleVideoRenderer control"); } } if (VideoBitmap != null) { VideoBitmap.Lock(); { IntPtr[] buffer = { VideoBitmap.BackBuffer }; int[] stride = { VideoBitmap.BackBufferStride }; frame.ConvertInPlace(OpenTok.PixelFormat.FormatArgb32, buffer, stride); if (EnableBlueFilter) { // This is a very slow filter just for demonstration purposes IntPtr p = VideoBitmap.BackBuffer; for (int y = 0; y < FrameHeight; y++) { for (int x = 0; x < FrameWidth; x++, p += 4) { Marshal.WriteInt32(p, Marshal.ReadInt32(p) & 0xff); } p += stride[0] - FrameWidth * 4; } } } VideoBitmap.AddDirtyRect(new Int32Rect(0, 0, FrameWidth, FrameHeight)); VideoBitmap.Unlock(); } } finally { frame.Dispose(); } })); }
public void RenderFrame(VideoFrame frame) { // WritableBitmap has to be accessed from a STA thread Dispatcher.BeginInvoke(new Action(() => { try { if (frame.Width != FrameWidth || frame.Height != FrameHeight) { FrameWidth = frame.Width; FrameHeight = frame.Height; VideoBitmap = new WriteableBitmap(FrameWidth, FrameHeight, 96, 96, PixelFormats.Bgr32, null); if (Background is ImageBrush) { ImageBrush b = (ImageBrush)Background; b.ImageSource = VideoBitmap; } else { throw new Exception("Please use an ImageBrush as background in the SampleVideoRenderer control"); } } if (VideoBitmap != null) { VideoBitmap.Lock(); { IntPtr[] buffer = { VideoBitmap.BackBuffer }; int[] stride = { VideoBitmap.BackBufferStride }; frame.ConvertInPlace(OpenTok.PixelFormat.FormatArgb32, buffer, stride); if (DetectingFaces) { using (var image = new Image <Bgr, byte>(frame.Width, frame.Height, stride[0], buffer[0])) { if (_watch.ElapsedMilliseconds > INTERVAL) { var reduced = image.Resize(1.0 / SCALE_FACTOR, Emgu.CV.CvEnum.Inter.Linear); _watch.Restart(); _images.Add(reduced); } } DrawRectanglesOnBitmap(VideoBitmap, _faces); } } VideoBitmap.AddDirtyRect(new Int32Rect(0, 0, FrameWidth, FrameHeight)); VideoBitmap.Unlock(); } } finally { frame.Dispose(); } })); }
public void RenderFrame(VideoFrame frame) { if (frame.Metadata != null) { Trace.WriteLine(StreamSourceType + " video frame metadata: " + Encoding.ASCII.GetString(frame.Metadata)); } // WritableBitmap has to be accessed from a STA thread Dispatcher.BeginInvoke(new Action(() => { try { if (frame.Width != FrameWidth || frame.Height != FrameHeight) { FrameWidth = frame.Width; FrameHeight = frame.Height; VideoBitmap = new WriteableBitmap(FrameWidth, FrameHeight, 96, 96, PixelFormats.Bgr32, null); if (Background is ImageBrush) { ImageBrush b = (ImageBrush)Background; b.ImageSource = VideoBitmap; } else { throw new Exception("Please use an ImageBrush as background in the SampleVideoRenderer control"); } } if (VideoBitmap != null) { VideoBitmap.Lock(); { IntPtr[] buffer = { VideoBitmap.BackBuffer }; int[] stride = { VideoBitmap.BackBufferStride }; frame.ConvertInPlace(OpenTok.PixelFormat.FormatArgb32, buffer, stride); } VideoBitmap.AddDirtyRect(new Int32Rect(0, 0, FrameWidth, FrameHeight)); VideoBitmap.Unlock(); } } finally { frame.Dispose(); } })); }
public void RenderFrame(VideoFrame frame) { if (w != frame.Width || h != frame.Height) { Debug.LogFormat("Size changed!, ({0},{1}) => ({2},{3})", w, h, frame.Width, frame.Height); w = frame.Width; h = frame.Height; if (buffer[0] != IntPtr.Zero) { Marshal.FreeHGlobal(buffer[0]); } buffer[0] = Marshal.AllocHGlobal(frame.Width * frame.Height * 4); strides[0] = frame.Width * 4; } frame.ConvertInPlace(PixelFormat.FormatArgb32, buffer, strides); RenderPlugin.SetRendererFrame(rendererId, buffer[0], frame.Width, frame.Height); frame.Dispose(); }