public static void OnRenderVideoFrameRawHandler(uint userId, int width, int height, byte[] yBuffer, int rotation) { // we pick a un used VideoFrameRawHandlerParam item, convert yuv data to rgb frame, and init it's bitmap obj. VideoFrameRawHandlerParam sel_vfrp; mutexVideoFrameRawHandlerParam_.WaitOne(); if (unUseVideoFrameRawHandlerParam_.Count == 0) { if (usingVideoFrameRawHandlerParam_.Count > 20) { mutexVideoFrameRawHandlerParam_.ReleaseMutex(); return; // full } sel_vfrp = new VideoFrameRawHandlerParam(); sel_vfrp.width = 0; sel_vfrp.userId = 0; } else { sel_vfrp = unUseVideoFrameRawHandlerParam_[0]; unUseVideoFrameRawHandlerParam_.RemoveAt(0); } mutexVideoFrameRawHandlerParam_.ReleaseMutex(); if (sel_vfrp.width != width || sel_vfrp.height != height) { sel_vfrp.width = width; sel_vfrp.height = height; sel_vfrp.yBuffer = new byte[yBuffer.Length]; Array.Copy(yBuffer, sel_vfrp.yBuffer, yBuffer.Length); sel_vfrp.rotation = rotation; sel_vfrp.rgbFrame = new byte[width * height * 4]; sel_vfrp.bm = new Bitmap(width, height); } else { Array.Copy(yBuffer, sel_vfrp.yBuffer, yBuffer.Length); sel_vfrp.rotation = rotation; } sel_vfrp.userId = userId; ConvertYUV2RGB(sel_vfrp.bm, sel_vfrp.yBuffer, sel_vfrp.rgbFrame, width, height); mutexVideoFrameRawHandlerParam_.WaitOne(); usingVideoFrameRawHandlerParam_.Add(sel_vfrp); mutexVideoFrameRawHandlerParam_.ReleaseMutex(); // Send to main thread for display main_thread_sync_context_.Post( new SendOrPostCallback((object state) => { the_form.OnRenderVideoFrameRawHandlerUI(); }), null); }
public void OnRenderVideoFrameRawHandlerUI() { if (IsDisposed) { return; } // Pick a item in list to show. VideoFrameRawHandlerParam sel_vfrp; mutexVideoFrameRawHandlerParam_.WaitOne(); if (usingVideoFrameRawHandlerParam_.Count == 0) { mutexVideoFrameRawHandlerParam_.ReleaseMutex(); return; // full } sel_vfrp = usingVideoFrameRawHandlerParam_[0]; usingVideoFrameRawHandlerParam_.RemoveAt(0); mutexVideoFrameRawHandlerParam_.ReleaseMutex(); // Set bitmap to ui contorl if (sel_vfrp.bm != null) {// Find Which picbox to show IntPtr targPicbox = new IntPtr(); foreach (var pair in remote_video_map_) { if (sel_vfrp.userId == pair.Key) { targPicbox = pair.Value; } } if (panel3.Handle == targPicbox) { pictureBox3.Image = sel_vfrp.bm; } else { pictureBox2.Image = sel_vfrp.bm; } } mutexVideoFrameRawHandlerParam_.WaitOne(); // add last ui show item to unUsed list if (curUIUsingVideoFrameRawHandlerParam_ != null) { unUseVideoFrameRawHandlerParam_.Add(curUIUsingVideoFrameRawHandlerParam_); } mutexVideoFrameRawHandlerParam_.ReleaseMutex(); curUIUsingVideoFrameRawHandlerParam_ = sel_vfrp; }
public void OnCaptureVideoFrameRawHandlerUI() { if (IsDisposed) { return; } // Pick a item in list to show. VideoFrameRawHandlerParam sel_vfrp; mutexVideoFrameRawHandlerParam_.WaitOne(); if (usingVideoFrameRawHandlerParam_.Count == 0) { mutexVideoFrameRawHandlerParam_.ReleaseMutex(); return; // full } sel_vfrp = usingVideoFrameRawHandlerParam_[0]; usingVideoFrameRawHandlerParam_.RemoveAt(0); mutexVideoFrameRawHandlerParam_.ReleaseMutex(); // Set bitmap to ui contorl if (sel_vfrp.bm != null) { this.pictureBox1.Image = sel_vfrp.bm; } mutexVideoFrameRawHandlerParam_.WaitOne(); // add last ui show item to unUsed list if (curUIUsingVideoFrameRawHandlerParam_ != null) { unUseVideoFrameRawHandlerParam_.Add(curUIUsingVideoFrameRawHandlerParam_); } mutexVideoFrameRawHandlerParam_.ReleaseMutex(); curUIUsingVideoFrameRawHandlerParam_ = sel_vfrp; }