public void Destory() { if (Video != IntPtr.Zero) { LibMWCapture.MWDestoryVideoCapture(Video); Video = IntPtr.Zero; } if (Audio != IntPtr.Zero) { LibMWCapture.MWDestoryAudioCapture(Audio); Audio = IntPtr.Zero; } if (VideoChannel != IntPtr.Zero) { LibMWCapture.MWCloseChannel(VideoChannel); VideoChannel = IntPtr.Zero; } if (D3DRenderer != IntPtr.Zero) { LibMWMedia.MWDestroyD3DRenderer(D3DRenderer); D3DRenderer = IntPtr.Zero; } if (AudioRender != IntPtr.Zero) { LibMWMedia.MWDestroyDSoundRenderer(AudioRender); AudioRender = IntPtr.Zero; } }
public static void audio_callback_sub(IntPtr pbFrame, int cbFrame, ulong u64TimeStamp, IntPtr pParam) { try { LibMWMedia.MWDSoundRendererPushFrame(pParam, pbFrame, cbFrame); } catch (Exception ex) { } }
private bool InitAudioCapture() { audio_callback = new LibMWCapture.AUDIO_CAPTURE_STDCALLBACK(audio_callback_sub); AudioRender = LibMWMedia.MWCreateDSoundRenderer(48000, 2, 480, 10); if (AudioRender == IntPtr.Zero) { return(false); } Audio = LibMWCapture.MWCreateAudioCaptureWithStdCallBack(VideoChannel, LibMWCapture.MWCAP_AUDIO_CAPTURE_NODE.MWCAP_AUDIO_CAPTURE_NODE_DEFAULT, 48000, 16, 2, audio_callback, AudioRender); if (Audio == IntPtr.Zero) { return(false); } return(true); }
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) { } }