public bool OpenVideoChannel(LibMWCapture.MWCAP_CHANNEL_INFO channelInfo, UInt32 dwFourcc, int cx, int cy, UInt32 nFrameDuration, IntPtr hWnd) { // open video device ushort[] wpath = new ushort[512]; IntPtr pwpath = GCHandle.Alloc(wpath, GCHandleType.Pinned).AddrOfPinnedObject(); LibMWCapture.MWGetDevicePath(channelInfo.byChannelIndex, pwpath); Board = channelInfo.byBoardIndex; ChannelIndex = channelInfo.byChannelIndex; VideoChannel = LibMWCapture.MWOpenChannelByPath(pwpath); if (VideoChannel == IntPtr.Zero) { return(false); } video_callback = new LibMWCapture.VIDEO_CAPTURE_STDCALLBACK(video_callback_sub); // create video renderer bool reverse = dwFourcc == MWCap_FOURCC.MWCAP_FOURCC_BGR24 || dwFourcc == MWCap_FOURCC.MWCAP_FOURCC_BGRA; D3DRenderer = LibMWMedia.MWCreateD3DRenderer(cx, cy, dwFourcc, reverse, hWnd); if (D3DRenderer == IntPtr.Zero) { return(false); } llCount = 0; CurrentTime = RefTime = Libkernel32.GetTickCount(); uint fourcc = (uint)dwFourcc; int frameduration = (int)nFrameDuration; Video = LibMWCapture.MWCreateVideoCaptureWithStdCallBack(VideoChannel, cx, cy, fourcc, frameduration, video_callback, D3DRenderer); if (Video == IntPtr.Zero) { return(false); } if (!InitAudioCapture()) { // может быть без аудио если этот источник уже открыт //return false; } return(true); }
public static void video_callback_sub(IntPtr pbFrame, int cbFrame, ulong u64TimeStamp, IntPtr pParam) { try { LibMWMedia.MWD3DRendererPushFrame(pParam, pbFrame, 720 * 4); llCount += 1; if (llCount >= 10) { CurrentTime = Libkernel32.GetTickCount(); unchecked { Fps = (llCount * 1000) / (CurrentTime - RefTime); } RefTime = CurrentTime; llCount = 0; } } catch (Exception ex) { } }