Example #1
0
        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;
            }
        }
Example #2
0
        public static LibMWCapture.MWCAP_VIDEO_SIGNAL_STATUS?GetSignalStatus(int channelIndex, out LibMWCapture.MWCAP_AUDIO_VOLUME? audioStatus)
        {
            audioStatus = null;
            ushort[] wpath  = new ushort[512];
            IntPtr   pwpath = GCHandle.Alloc(wpath, GCHandleType.Pinned).AddrOfPinnedObject();

            LibMWCapture.MWGetDevicePath(channelIndex, pwpath);

            var videoChannel = LibMWCapture.MWOpenChannelByPath(pwpath);

            if (videoChannel == IntPtr.Zero)
            {
                return(null);
            }
            try
            {
                audioStatus = PInvokeTools.ReadStruct <LibMWCapture.MWCAP_AUDIO_VOLUME>(ptr =>
                                                                                        LibMWCapture.MWGetAudioVolume(videoChannel, LibMWCapture.MWCAP_AUDIO_NODE.MWCAP_AUDIO_EMBEDDED_CAPTURE, ptr));

                return(PInvokeTools.ReadStruct <LibMWCapture.MWCAP_VIDEO_SIGNAL_STATUS>(
                           ptr =>
                           LibMWCapture.MWGetVideoSignalStatus(videoChannel, ptr)));
            }
            finally
            {
                LibMWCapture.MWCloseChannel(videoChannel);
            }
        }
Example #3
0
 public static void SetMute(this LibMWCapture.MWCAP_AUDIO_VOLUME audioStatus, IntPtr videoChannel, bool mute)
 {
     for (int i = 0; i < audioStatus.abMute.Length; i++)
     {
         audioStatus.abMute[i] = mute;
     }
     PInvokeTools.WriteStruct(audioStatus, ptr =>
                              LibMWCapture.MWSetAudioVolume(videoChannel, LibMWCapture.MWCAP_AUDIO_NODE.MWCAP_AUDIO_EMBEDDED_CAPTURE, ptr));
 }
Example #4
0
        public static Boolean RefreshDevices()
        {
            LibMWCapture.MW_RESULT mr;
            mr = LibMWCapture.MWRefreshDevice();
            if (mr != LibMWCapture.MW_RESULT.MW_SUCCEEDED)
            {
                return(false);
            }

            return(true);
        }
Example #5
0
        public static void SetAudioVolume(this LibMWCapture.MWCAP_AUDIO_VOLUME audioStatus, IntPtr videoChannel, int percent)
        {
            var volumeIndex = (int)(AudioVolumes.Length / 100.0 * percent);

            volumeIndex = Math.Min(Math.Max(volumeIndex, 0), AudioVolumes.Length - 1);
            var volume = AudioVolumes[volumeIndex];

            for (int i = 0; i < audioStatus.asVolume.Length; i++)
            {
                audioStatus.asVolume[i] = volume;
            }
            PInvokeTools.WriteStruct(audioStatus, ptr =>
                                     LibMWCapture.MWSetAudioVolume(videoChannel, LibMWCapture.MWCAP_AUDIO_NODE.MWCAP_AUDIO_EMBEDDED_CAPTURE, ptr));
        }
Example #6
0
 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);
 }
Example #7
0
        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);
        }
Example #8
0
 public static int GetChannelCount()
 {
     return(LibMWCapture.MWGetChannelCount());
 }
Example #9
0
 public static void Exit()
 {
     LibMWCapture.MWCaptureExitInstance();
 }
Example #10
0
 public static bool Init()
 {
     return(LibMWCapture.MWCaptureInitInstance() > 0);
 }
Example #11
0
 public LibMWCapture.MWCAP_AUDIO_VOLUME GetMWAudioVolume()
 {
     return(PInvokeTools.ReadStruct <LibMWCapture.MWCAP_AUDIO_VOLUME>(ptr =>
                                                                      LibMWCapture.MWGetAudioVolume(VideoChannel, LibMWCapture.MWCAP_AUDIO_NODE.MWCAP_AUDIO_EMBEDDED_CAPTURE, ptr)));
 }
Example #12
0
 public LibMWCapture.MWCAP_VIDEO_SIGNAL_STATUS GetVideoSignalStatus()
 {
     return(PInvokeTools.ReadStruct <LibMWCapture.MWCAP_VIDEO_SIGNAL_STATUS>(ptr =>
                                                                             LibMWCapture.MWGetVideoSignalStatus(VideoChannel, ptr)));
 }
Example #13
0
 public static void GetChannelInfobyIndex(int nChannelIndex, ref LibMWCapture.MWCAP_CHANNEL_INFO channelInfo)
 {
     channelInfo = PInvokeTools.ReadStruct <LibMWCapture.MWCAP_CHANNEL_INFO>(ptr =>
                                                                             LibMWCapture.MWGetChannelInfoByIndex(nChannelIndex, ptr));
 }