Video input of a capture board.

The class is used to describe video input of devices like video capture boards, which usually provide several inputs.

        // Ok button clicked
        private void okButton_Click(object sender, EventArgs e)
        {
            videoDeviceMoniker = videoDevice.Source;

            // set video size
            if (videoCapabilitiesDictionary.Count != 0)
            {
                VideoCapabilities caps = videoCapabilitiesDictionary[(string)videoResolutionsCombo.SelectedItem];

                videoDevice.VideoResolution = caps;
                captureSize = caps.FrameSize;
            }

            if (configureSnapshots)
            {
                // set snapshots size
                if (snapshotCapabilitiesDictionary.Count != 0)
                {
                    VideoCapabilities caps = snapshotCapabilitiesDictionary[(string)snapshotResolutionsCombo.SelectedItem];

                    videoDevice.ProvideSnapshots   = true;
                    videoDevice.SnapshotResolution = caps;

                    snapshotSize = caps.FrameSize;
                }
            }

            if (availableVideoInputs.Length != 0)
            {
                videoInput = availableVideoInputs[videoInputsCombo.SelectedIndex];
                videoDevice.CrossbarVideoInput = videoInput;
            }
        }
Exemple #2
0
        // Token: 0x06000045 RID: 69 RVA: 0x00003694 File Offset: 0x00001894
        private void SetCurrentCrossbarInput(IAMCrossbar crossbar, VideoInput videoInput)
        {
            int num;
            int num2;

            if (videoInput.Type != PhysicalConnectorType.Default && crossbar.get_PinCounts(out num, out num2) == 0)
            {
                int num3 = -1;
                int num4 = -1;
                for (int i = 0; i < num; i++)
                {
                    int num5;
                    PhysicalConnectorType physicalConnectorType;
                    if (crossbar.get_CrossbarPinInfo(false, i, out num5, out physicalConnectorType) == 0 && physicalConnectorType == PhysicalConnectorType.VideoDecoder)
                    {
                        num3 = i;
                        break;
                    }
                }
                for (int j = 0; j < num2; j++)
                {
                    int num5;
                    PhysicalConnectorType physicalConnectorType;
                    if (crossbar.get_CrossbarPinInfo(true, j, out num5, out physicalConnectorType) == 0 && physicalConnectorType == videoInput.Type && j == videoInput.Index)
                    {
                        num4 = j;
                        break;
                    }
                }
                if (num4 != -1 && num3 != -1 && crossbar.CanRoute(num3, num4) == 0)
                {
                    crossbar.Route(num3, num4);
                }
            }
        }
Exemple #3
0
        // Token: 0x06000044 RID: 68 RVA: 0x00003620 File Offset: 0x00001820
        private VideoInput GetCurrentCrossbarInput(IAMCrossbar crossbar)
        {
            VideoInput result = VideoInput.Default1;
            int        num;
            int        num2;

            if (crossbar.get_PinCounts(out num, out num2) == 0)
            {
                int num3 = -1;
                for (int i = 0; i < num; i++)
                {
                    int num4;
                    PhysicalConnectorType physicalConnectorType;
                    if (crossbar.get_CrossbarPinInfo(false, i, out num4, out physicalConnectorType) == 0 && physicalConnectorType == PhysicalConnectorType.VideoDecoder)
                    {
                        num3 = i;
                        break;
                    }
                }
                int num5;
                if (num3 != -1 && crossbar.get_IsRoutedTo(num3, out num5) == 0)
                {
                    int num4;
                    PhysicalConnectorType type;
                    int num6 = crossbar.get_CrossbarPinInfo(true, num5, out num4, out type);
                    result = new VideoInput(num5, type);
                }
            }
            return(result);
        }
Exemple #4
0
        private VideoInput GetCurrentCrossbarInput(IAMCrossbar crossbar)
        {
            VideoInput result = VideoInput.Default;

            if (crossbar.get_PinCounts(out int outputPinCount, out int _) == 0)
            {
                int num = -1;
                int pinIndexRelated;
                for (int i = 0; i < outputPinCount; i++)
                {
                    if (crossbar.get_CrossbarPinInfo(isInputPin: false, i, out pinIndexRelated, out PhysicalConnectorType physicalType) == 0 && physicalType == PhysicalConnectorType.VideoDecoder)
                    {
                        num = i;
                        break;
                    }
                }
                if (num != -1 && crossbar.get_IsRoutedTo(num, out int inputPinIndex) == 0)
                {
                    crossbar.get_CrossbarPinInfo(isInputPin: true, inputPinIndex, out pinIndexRelated, out PhysicalConnectorType physicalType2);
                    result = new VideoInput(inputPinIndex, physicalType2);
                }
            }
            return(result);
        }
Exemple #5
0
        // Token: 0x06000043 RID: 67 RVA: 0x00003554 File Offset: 0x00001754
        private VideoInput[] ColletCrossbarVideoInputs(IAMCrossbar crossbar)
        {
            Dictionary <string, VideoInput[]> obj = VideoCaptureDevice.cacheCrossbarVideoInputs1;

            VideoInput[] result;
            lock (obj)
            {
                if (VideoCaptureDevice.cacheCrossbarVideoInputs1.ContainsKey(this.deviceMoniker1))
                {
                    result = VideoCaptureDevice.cacheCrossbarVideoInputs1[this.deviceMoniker1];
                }
                else
                {
                    List <VideoInput> list = new List <VideoInput>();
                    int num;
                    int num2;
                    if (crossbar != null && crossbar.get_PinCounts(out num, out num2) == 0)
                    {
                        for (int i = 0; i < num2; i++)
                        {
                            int num3;
                            PhysicalConnectorType physicalConnectorType;
                            if (crossbar.get_CrossbarPinInfo(true, i, out num3, out physicalConnectorType) == 0 && physicalConnectorType < PhysicalConnectorType.AudioTuner)
                            {
                                list.Add(new VideoInput(i, physicalConnectorType));
                            }
                        }
                    }
                    VideoInput[] array = new VideoInput[list.Count];
                    list.CopyTo(array);
                    VideoCaptureDevice.cacheCrossbarVideoInputs1.Add(this.deviceMoniker1, array);
                    result = array;
                }
            }
            return(result);
        }
Exemple #6
0
        private void VideoSource_Load(object sender, EventArgs e)
        {
            cmbJPEGURL.Text = iSpyServer.Default.JPEGURL;
            cmbMJPEGURL.Text = iSpyServer.Default.MJPEGURL;
            txtLogin.Text = txtLogin2.Text = CameraControl.Camobject.settings.login;
            txtPassword.Text = txtPassword2.Text = CameraControl.Camobject.settings.password;
            txtUserAgent.Text = txtUserAgent2.Text = CameraControl.Camobject.settings.useragent;
            txtResizeWidth.Value = CameraControl.Camobject.settings.desktopresizewidth;
            txtResizeHeight.Value = CameraControl.Camobject.settings.desktopresizeheight;
            chkNoResize.Checked = !CameraControl.Camobject.settings.resize;
            VideoSourceString = CameraControl.Camobject.settings.videosourcestring;
            SourceIndex = CameraControl.Camobject.settings.sourceindex;
            txtFrameInterval.Text = txtFrameInterval2.Text = CameraControl.Camobject.settings.frameinterval.ToString();
            chkMousePointer.Checked = CameraControl.Camobject.settings.desktopmouse;
            txtEncodeKey.Text = CameraControl.Camobject.encodekey;

            switch (SourceIndex)
            {
                case 0:
                    cmbJPEGURL.Text = VideoSourceString;
                    txtFrameInterval.Text = CameraControl.Camobject.settings.frameinterval.ToString();
                    break;
                case 1:
                    cmbMJPEGURL.Text = VideoSourceString;
                    break;
            }

            if (SourceIndex == 3)
            {
                VideoDeviceMoniker = VideoSourceString;
                string[] wh = CameraControl.Camobject.resolution.Split('x');
                CaptureSize = new Size(Convert.ToInt32(wh[0]), Convert.ToInt32(wh[1]));
            }

            cmbJPEGURL.Items.AddRange(iSpyServer.Default.RecentJPGList.Split('|'));
            cmbMJPEGURL.Items.AddRange(iSpyServer.Default.RecentMJPGList.Split('|'));

            int selectedCameraIndex = 0;

            for (int i = 0; i < videoDevices.Count; i++)
            {
                if (videoDeviceMoniker == videoDevices[i].MonikerString)
                {
                    selectedCameraIndex = i;
                    break;
                }
            }

            devicesCombo.SelectedIndex = selectedCameraIndex;

            ddlScreen.SuspendLayout();
            foreach (Screen s in Screen.AllScreens)
            {
                ddlScreen.Items.Add(s.DeviceName);
            }
            ddlScreen.Items.Insert(0, LocRM.GetString("PleaseSelect"));
            if (SourceIndex == 4)
            {
                ddlScreen.SelectedIndex = Convert.ToInt32(VideoSourceString) + 1;
            }
            else
                ddlScreen.SelectedIndex = 0;
            ddlScreen.ResumeLayout();

            tcSource.SelectedIndex = SourceIndex;

            if (CameraControl.Camera != null && CameraControl.Camera.VideoSource is VideoCaptureDevice)
            {
                videoDevice = (VideoCaptureDevice)CameraControl.Camera.VideoSource;
                videoInput = videoDevice.CrossbarVideoInput;
                EnumeratedSupportedFrameSizes(videoDevice);
            }

            int deviceCount = 0;
            try
            {
                foreach (var potentialSensor in KinectSensor.KinectSensors)
                {
                    if (potentialSensor.Status == KinectStatus.Connected)
                    {
                        deviceCount++;
                        ddlKinectDevice.Items.Add(potentialSensor.UniqueKinectId);

                        if (NV("type") == "kinect")
                        {
                            if (NV("UniqueKinectId") == potentialSensor.UniqueKinectId)
                            {
                                ddlKinectDevice.SelectedIndex = ddlKinectDevice.Items.Count - 1;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Type error if not installed
                MainForm.LogMessageToFile("Kinect supporting libraries not installed. (" + ex.Message + ")");
            }
            if (deviceCount > 0)
            {
                if (ddlKinectDevice.SelectedIndex == -1)
                    ddlKinectDevice.SelectedIndex = 0;
            }
            else
            {
                pnlKinect.Enabled = false;
            }

            if (NV("type") == "kinect")
            {
                try
                {
                    chkKinectSkeletal.Checked = Convert.ToBoolean(NV("KinectSkeleton"));
                }
                catch { }
            }
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            iSpyServer.Default.JPEGURL = cmbJPEGURL.Text.Trim();
            iSpyServer.Default.MJPEGURL = cmbMJPEGURL.Text.Trim();

            if (!iSpyServer.Default.RecentFileList.Contains(iSpyServer.Default.AVIFileName) &&
                iSpyServer.Default.AVIFileName != "")
            {
                iSpyServer.Default.RecentFileList =
                    (iSpyServer.Default.RecentFileList + "|" + iSpyServer.Default.AVIFileName).Trim('|');
            }
            if (!iSpyServer.Default.RecentJPGList.Contains(iSpyServer.Default.JPEGURL) &&
                iSpyServer.Default.JPEGURL != "")
            {
                iSpyServer.Default.RecentJPGList =
                    (iSpyServer.Default.RecentJPGList + "|" + iSpyServer.Default.JPEGURL).Trim('|');
            }
            if (!iSpyServer.Default.RecentMJPGList.Contains(iSpyServer.Default.MJPEGURL) &&
                iSpyServer.Default.MJPEGURL != "")
            {
                iSpyServer.Default.RecentMJPGList =
                    (iSpyServer.Default.RecentMJPGList + "|" + iSpyServer.Default.MJPEGURL).Trim('|');
            }
            SourceIndex = tcSource.SelectedIndex;
            CameraLogin = txtLogin.Text;
            CameraPassword = txtPassword.Text;
            UserAgent = txtUserAgent.Text;
            string nv = "";
            switch (SourceIndex)
            {
                case 0:
                    int _frameinterval = 0;
                    if (!Int32.TryParse(txtFrameInterval.Text, out _frameinterval))
                    {
                        MessageBox.Show(LocRM.GetString("Validate_FrameInterval"));
                        return;
                    }
                    VideoSourceString = cmbJPEGURL.Text.Trim();
                    CameraControl.Camobject.settings.frameinterval = _frameinterval;
                    FriendlyName = VideoSourceString;
                    break;
                case 1:
                    VideoSourceString = cmbMJPEGURL.Text.Trim();
                    FriendlyName = VideoSourceString;
                    CameraLogin = txtLogin2.Text;
                    CameraPassword = txtPassword2.Text;
                    UserAgent = txtUserAgent2.Text;
                    break;
                case 2:
                    MessageBox.Show(LocRM.GetString("Validate_SelectCamera"), LocRM.GetString("Note"));
                    break;
                case 3:
                    if (!devicesCombo.Enabled)
                    {
                        MessageBox.Show(LocRM.GetString("Validate_SelectCamera"), LocRM.GetString("Note"));
                        return;
                    }

                    videoDeviceMoniker = videoDevice.Source;
                    if (videoCapabilitiesDictionary.Count > 0)
                    {
                        VideoCapabilities caps =
                            videoCapabilitiesDictionary[(string) videoResolutionsCombo.SelectedItem];
                        captureSize = caps.FrameSize;
                        FrameRate = caps.FrameRate;
                        captureSize = new Size(captureSize.Width, captureSize.Height);
                    }

                    if ( configureSnapshots )
                    {
                        // set snapshots size
                        if ( snapshotCapabilitiesDictionary.Count != 0 )
                        {
                            VideoCapabilities caps2 = snapshotCapabilitiesDictionary[(string) snapshotResolutionsCombo.SelectedItem];
                            snapshotSize = caps2.FrameSize;
                        }
                    }

                    if ( availableVideoInputs.Length != 0 )
                    {
                        videoInput = availableVideoInputs[videoInputsCombo.SelectedIndex];
                    }

                    VideoSourceString = videoDeviceMoniker;
                    FriendlyName = videoDevice.Source;
                    break;
                case 4:
                    int _frameinterval2 = 0;
                    if (!Int32.TryParse(txtFrameInterval2.Text, out _frameinterval2))
                    {
                        MessageBox.Show(LocRM.GetString("Validate_FrameInterval"));
                        return;
                    }
                    if (ddlScreen.SelectedIndex < 1)
                    {
                        MessageBox.Show(LocRM.GetString("Validate_SelectCamera"), LocRM.GetString("Note"));
                        return;
                    }
                    VideoSourceString = (ddlScreen.SelectedIndex - 1).ToString();
                    FriendlyName = ddlScreen.SelectedItem.ToString();
                    CameraControl.Camobject.settings.frameinterval = _frameinterval2;
                    CameraControl.Camobject.settings.desktopresizewidth = Convert.ToInt32(txtResizeWidth.Value);
                    CameraControl.Camobject.settings.desktopresizeheight = Convert.ToInt32(txtResizeHeight.Value);
                    break;
                case 5:
                    if (!pnlKinect.Enabled)
                    {
                        MessageBox.Show(LocRM.GetString("Validate_SelectCamera"), LocRM.GetString("Note"));
                        return;
                    }
                    nv = "type=kinect";
                    nv += ",UniqueKinectId=" + ddlKinectDevice.SelectedItem;
                    nv += ",KinectSkeleton=" + chkKinectSkeletal.Checked;

                    VideoSourceString = nv;
                    CameraControl.Camobject.settings.namevaluesettings = nv;
                    break;
            }

            if (VideoSourceString.Trim() == "")
            {
                MessageBox.Show(LocRM.GetString("Validate_SelectCamera"), LocRM.GetString("Note"));
                return;
            }

            CameraControl.Camobject.settings.desktopmouse = chkMousePointer.Checked;
            CameraControl.Camobject.encodekey = txtEncodeKey.Text;
            CameraControl.Camobject.settings.resize = !chkNoResize.Checked;
            DialogResult = DialogResult.OK;
            Close();
        }
        private void WorkerThread( bool runGraph )
        {
            ReasonToFinishPlaying reasonToStop = ReasonToFinishPlaying.StoppedByUser;
            bool isSapshotSupported = false;

            // grabber
            Grabber videoGrabber = new Grabber( this, false );
            Grabber snapshotGrabber = new Grabber( this, true );

            // objects
            object captureGraphObject = null;
            object graphObject = null;
            object videoGrabberObject = null;
            object snapshotGrabberObject = null;
            object crossbarObject = null;

            // interfaces
            ICaptureGraphBuilder2 captureGraph = null;
            IFilterGraph2   graph = null;
            IBaseFilter     sourceBase = null;
            IBaseFilter     videoGrabberBase = null;
            IBaseFilter     snapshotGrabberBase = null;
            ISampleGrabber  videoSampleGrabber = null;
            ISampleGrabber  snapshotSampleGrabber = null;
            IMediaControl   mediaControl = null;
            IAMVideoControl videoControl = null;
            IMediaEventEx   mediaEvent = null;
            IPin            pinStillImage = null;
            IAMCrossbar     crossbar = null;

            try
            {
                // get type of capture graph builder
                Type type = Type.GetTypeFromCLSID( Clsid.CaptureGraphBuilder2 );
                if ( type == null )
                    throw new ApplicationException( "Failed creating capture graph builder" );

                // create capture graph builder
                captureGraphObject = Activator.CreateInstance( type );
                captureGraph = (ICaptureGraphBuilder2) captureGraphObject;

                // get type of filter graph
                type = Type.GetTypeFromCLSID( Clsid.FilterGraph );
                if ( type == null )
                    throw new ApplicationException( "Failed creating filter graph" );

                // create filter graph
                graphObject = Activator.CreateInstance( type );
                graph = (IFilterGraph2) graphObject;

                // set filter graph to the capture graph builder
                captureGraph.SetFiltergraph( (IGraphBuilder) graph );

                // create source device's object
                sourceObject = FilterInfo.CreateFilter( deviceMoniker );
                if ( sourceObject == null )
                    throw new ApplicationException( "Failed creating device object for moniker" );

                // get base filter interface of source device
                sourceBase = (IBaseFilter) sourceObject;

                // get video control interface of the device
                try
                {
                    videoControl = (IAMVideoControl) sourceObject;
                }
                catch
                {
                    // some camera drivers may not support IAMVideoControl interface
                }

                // get type of sample grabber
                type = Type.GetTypeFromCLSID( Clsid.SampleGrabber );
                if ( type == null )
                    throw new ApplicationException( "Failed creating sample grabber" );

                // create sample grabber used for video capture
                videoGrabberObject = Activator.CreateInstance( type );
                videoSampleGrabber = (ISampleGrabber) videoGrabberObject;
                videoGrabberBase = (IBaseFilter) videoGrabberObject;
                // create sample grabber used for snapshot capture
                snapshotGrabberObject = Activator.CreateInstance( type );
                snapshotSampleGrabber = (ISampleGrabber) snapshotGrabberObject;
                snapshotGrabberBase = (IBaseFilter) snapshotGrabberObject;

                // add source and grabber filters to graph
                graph.AddFilter( sourceBase, "source" );
                graph.AddFilter( videoGrabberBase, "grabber_video" );
                graph.AddFilter( snapshotGrabberBase, "grabber_snapshot" );

                // set media type
                AMMediaType mediaType = new AMMediaType( );
                mediaType.MajorType = MediaType.Video;
                mediaType.SubType   = MediaSubType.RGB24;

                videoSampleGrabber.SetMediaType( mediaType );
                snapshotSampleGrabber.SetMediaType( mediaType );

                // get crossbar object to to allows configuring pins of capture card
                captureGraph.FindInterface( FindDirection.UpstreamOnly, Guid.Empty, sourceBase, typeof( IAMCrossbar ).GUID, out crossbarObject );
                if ( crossbarObject != null )
                {
                    crossbar = (IAMCrossbar) crossbarObject;
                }
                isCrossbarAvailable = ( crossbar != null );
                crossbarVideoInputs = ColletCrossbarVideoInputs( crossbar );

                if ( videoControl != null )
                {
                    // find Still Image output pin of the vedio device
                    captureGraph.FindPin( sourceObject, PinDirection.Output,
                        PinCategory.StillImage, MediaType.Video, false, 0, out pinStillImage );
                    // check if it support trigger mode
                    if ( pinStillImage != null )
                    {
                        VideoControlFlags caps;
                        videoControl.GetCaps( pinStillImage, out caps );
                        isSapshotSupported = ( ( caps & VideoControlFlags.ExternalTriggerEnable ) != 0 );
                    }
                }

                // configure video sample grabber
                videoSampleGrabber.SetBufferSamples( false );
                videoSampleGrabber.SetOneShot( false );
                videoSampleGrabber.SetCallback( videoGrabber, 1 );

                // configure snapshot sample grabber
                snapshotSampleGrabber.SetBufferSamples( true );
                snapshotSampleGrabber.SetOneShot( false );
                snapshotSampleGrabber.SetCallback( snapshotGrabber, 1 );

                // configure pins
                GetPinCapabilitiesAndConfigureSizeAndRate( captureGraph, sourceBase,
                    PinCategory.Capture, desiredFrameSize, desiredFrameRate, ref videoCapabilities );
                if ( isSapshotSupported )
                {
                    GetPinCapabilitiesAndConfigureSizeAndRate( captureGraph, sourceBase,
                        PinCategory.StillImage, desiredSnapshotSize, 0, ref snapshotCapabilities );
                }
                else
                {
                    snapshotCapabilities = new VideoCapabilities[0];
                }

                // put video/snapshot capabilities into cache
                lock ( cacheVideoCapabilities )
                {
                    if ( ( videoCapabilities != null ) && ( !cacheVideoCapabilities.ContainsKey( deviceMoniker ) ) )
                    {
                        cacheVideoCapabilities.Add( deviceMoniker, videoCapabilities );
                    }
                }
                lock ( cacheSnapshotCapabilities )
                {
                    if ( ( snapshotCapabilities != null ) && ( !cacheSnapshotCapabilities.ContainsKey( deviceMoniker ) ) )
                    {
                        cacheSnapshotCapabilities.Add( deviceMoniker, snapshotCapabilities );
                    }
                }

                if ( runGraph )
                {
                    // render capture pin
                    captureGraph.RenderStream( PinCategory.Capture, MediaType.Video, sourceBase, null, videoGrabberBase );

                    if ( videoSampleGrabber.GetConnectedMediaType( mediaType ) == 0 )
                    {
                        VideoInfoHeader vih = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) );

                        videoGrabber.Width = vih.BmiHeader.Width;
                        videoGrabber.Height = vih.BmiHeader.Height;
                        
                        mediaType.Dispose( );
                    }

                    if ( ( isSapshotSupported ) && ( provideSnapshots ) )
                    {
                        // render snapshot pin
                        captureGraph.RenderStream( PinCategory.StillImage, MediaType.Video, sourceBase, null, snapshotGrabberBase );

                        if ( snapshotSampleGrabber.GetConnectedMediaType( mediaType ) == 0 )
                        {
                            VideoInfoHeader vih = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) );

                            snapshotGrabber.Width  = vih.BmiHeader.Width;
                            snapshotGrabber.Height = vih.BmiHeader.Height;

                            mediaType.Dispose( );
                        }
                    }

                    // get media control
                    mediaControl = (IMediaControl) graphObject;

                    // get media events' interface
                    mediaEvent = (IMediaEventEx) graphObject;
                    IntPtr p1, p2;
                    DsEvCode code;

                    // run
                    mediaControl.Run( );

                    if ( ( isSapshotSupported ) && ( provideSnapshots ) )
                    {
                        startTime = DateTime.Now;
                        videoControl.SetMode( pinStillImage, VideoControlFlags.ExternalTriggerEnable );
                    }

                    do
                    {
                        if ( mediaEvent != null )
                        {
                            if ( mediaEvent.GetEvent( out code, out p1, out p2, 0 ) >= 0 )
                            {
                                mediaEvent.FreeEventParams( code, p1, p2 );

                                if ( code == DsEvCode.DeviceLost )
                                {
                                    reasonToStop = ReasonToFinishPlaying.DeviceLost;
                                    break;
                                }
                            }
                        }

                        if ( needToSetVideoInput )
                        {
                            needToSetVideoInput = false;
                            // set/check current input type of a video card (frame grabber)
                            if ( isCrossbarAvailable.Value )
                            {
                                SetCurrentCrossbarInput( crossbar, crossbarVideoInput );
                                crossbarVideoInput = GetCurrentCrossbarInput( crossbar );
                            }
                        }

                        if ( needToSimulateTrigger )
                        {
                            needToSimulateTrigger = false;

                            if ( ( isSapshotSupported ) && ( provideSnapshots ) )
                            {
                                videoControl.SetMode( pinStillImage, VideoControlFlags.Trigger );
                            }
                        }

                        if ( needToDisplayPropertyPage )
                        {
                            needToDisplayPropertyPage = false;
                            DisplayPropertyPage( parentWindowForPropertyPage, sourceObject );

                            if ( crossbar != null )
                            {
                                crossbarVideoInput = GetCurrentCrossbarInput( crossbar );
                            }
                        }

                        if ( needToDisplayCrossBarPropertyPage )
                        {
                            needToDisplayCrossBarPropertyPage = false;

                            if ( crossbar != null )
                            {
                                DisplayPropertyPage( parentWindowForPropertyPage, crossbar );
                                crossbarVideoInput = GetCurrentCrossbarInput( crossbar );
                            }
                        }
                    }
                    while ( !stopEvent.WaitOne( 100, false ) );

                    mediaControl.Stop( );
                }
            }
            catch ( Exception exception )
            {
                // provide information to clients
                if ( VideoSourceError != null )
                {
                    VideoSourceError( this, new VideoSourceErrorEventArgs( exception.Message ) );
                }
            }
            finally
            {
                // release all objects
                captureGraph    = null;
                graph           = null;
                sourceBase      = null;
                mediaControl    = null;
                videoControl    = null;
                mediaEvent      = null;
                pinStillImage   = null;
                crossbar        = null;

                videoGrabberBase      = null;
                snapshotGrabberBase   = null;
                videoSampleGrabber    = null;
                snapshotSampleGrabber = null;

                if ( graphObject != null )
                {
                    Marshal.ReleaseComObject( graphObject );
                    graphObject = null;
                }
                if ( sourceObject != null )
                {
                    Marshal.ReleaseComObject( sourceObject );
                    sourceObject = null;
                }
                if ( videoGrabberObject != null )
                {
                    Marshal.ReleaseComObject( videoGrabberObject );
                    videoGrabberObject = null;
                }
                if ( snapshotGrabberObject != null )
                {
                    Marshal.ReleaseComObject( snapshotGrabberObject );
                    snapshotGrabberObject = null;
                }
                if ( captureGraphObject != null )
                {
                    Marshal.ReleaseComObject( captureGraphObject );
                    captureGraphObject = null;
                }
                if ( crossbarObject != null )
                {
                    Marshal.ReleaseComObject( crossbarObject );
                    crossbarObject = null;
                }
            }

            if ( PlayingFinished != null )
            {
                PlayingFinished( this, reasonToStop );
            }
        }
        // Set type of input connected to video output of the crossbar
        private void SetCurrentCrossbarInput( IAMCrossbar crossbar, VideoInput videoInput )
        {
            if ( videoInput.Type != PhysicalConnectorType.Default )
            {
                int inPinsCount, outPinsCount;

                // gen number of pins in the crossbar
                if ( crossbar.get_PinCounts( out outPinsCount, out inPinsCount ) == 0 )
                {
                    int videoOutputPinIndex = -1;
                    int videoInputPinIndex = -1;
                    int pinIndexRelated;
                    PhysicalConnectorType type;

                    // find index of the video output pin
                    for ( int i = 0; i < outPinsCount; i++ )
                    {
                        if ( crossbar.get_CrossbarPinInfo( false, i, out pinIndexRelated, out type ) != 0 )
                            continue;

                        if ( type == PhysicalConnectorType.VideoDecoder )
                        {
                            videoOutputPinIndex = i;
                            break;
                        }
                    }

                    // find index of the required input pin
                    for ( int i = 0; i < inPinsCount; i++ )
                    {
                        if ( crossbar.get_CrossbarPinInfo( true, i, out pinIndexRelated, out type ) != 0 )
                            continue;

                        if ( ( type == videoInput.Type ) && ( i == videoInput.Index ) )
                        {
                            videoInputPinIndex = i;
                            break;
                        }
                    }

                    // try connecting pins
                    if ( ( videoInputPinIndex != -1 ) && ( videoOutputPinIndex != -1 ) &&
                         ( crossbar.CanRoute( videoOutputPinIndex, videoInputPinIndex ) == 0 ) )
                    {
                        crossbar.Route( videoOutputPinIndex, videoInputPinIndex );
                    }
                }
            }
        }
        // Get type of input connected to video output of the crossbar
        private VideoInput GetCurrentCrossbarInput( IAMCrossbar crossbar )
        {
            VideoInput videoInput = VideoInput.Default;

            int inPinsCount, outPinsCount;

            // gen number of pins in the crossbar
            if ( crossbar.get_PinCounts( out outPinsCount, out inPinsCount ) == 0 )
            {
                int videoOutputPinIndex = -1;
                int pinIndexRelated;
                PhysicalConnectorType type;

                // find index of the video output pin
                for ( int i = 0; i < outPinsCount; i++ )
                {
                    if ( crossbar.get_CrossbarPinInfo( false, i, out pinIndexRelated, out type ) != 0 )
                        continue;

                    if ( type == PhysicalConnectorType.VideoDecoder )
                    {
                        videoOutputPinIndex = i;
                        break;
                    }
                }

                if ( videoOutputPinIndex != -1 )
                {
                    int videoInputPinIndex;

                    // get index of the input pin connected to the output
                    if ( crossbar.get_IsRoutedTo( videoOutputPinIndex, out videoInputPinIndex ) == 0 )
                    {
                        PhysicalConnectorType inputType;

                        crossbar.get_CrossbarPinInfo( true, videoInputPinIndex, out pinIndexRelated, out inputType );

                        videoInput = new VideoInput( videoInputPinIndex, inputType );
                    }
                }
            }

            return videoInput;
        }
        // Collect all video inputs of the specified crossbar
        private VideoInput[] ColletCrossbarVideoInputs( IAMCrossbar crossbar )
        {
            lock ( cacheCrossbarVideoInputs )
            {
                if ( cacheCrossbarVideoInputs.ContainsKey( deviceMoniker ) )
                {
                    return cacheCrossbarVideoInputs[deviceMoniker];
                }

                List<VideoInput> videoInputsList = new List<VideoInput>( );

                if ( crossbar != null )
                {
                    int inPinsCount, outPinsCount;

                    // gen number of pins in the crossbar
                    if ( crossbar.get_PinCounts( out outPinsCount, out inPinsCount ) == 0 )
                    {
                        // collect all video inputs
                        for ( int i = 0; i < inPinsCount; i++ )
                        {
                            int pinIndexRelated;
                            PhysicalConnectorType type;

                            if ( crossbar.get_CrossbarPinInfo( true, i, out pinIndexRelated, out type ) != 0 )
                                continue;

                            if ( type < PhysicalConnectorType.AudioTuner )
                            {
                                videoInputsList.Add( new VideoInput( i, type ) );
                            }
                        }
                    }
                }

                VideoInput[] videoInputs = new VideoInput[videoInputsList.Count];
                videoInputsList.CopyTo( videoInputs );

                cacheCrossbarVideoInputs.Add( deviceMoniker, videoInputs );

                return videoInputs;
            }
        }
Exemple #12
0
        private void WorkerThread(bool runGraph)
        {
            ReasonToFinishPlaying reason = ReasonToFinishPlaying.StoppedByUser;
            bool    flag         = false;
            Grabber grabber      = new Grabber(this, snapshotMode: false);
            Grabber grabber2     = new Grabber(this, snapshotMode: true);
            object  obj          = null;
            object  obj2         = null;
            object  obj3         = null;
            object  obj4         = null;
            object  retInterface = null;
            ICaptureGraphBuilder2 captureGraphBuilder = null;
            IFilterGraph2         filterGraph         = null;
            IBaseFilter           baseFilter          = null;
            IBaseFilter           baseFilter2         = null;
            IBaseFilter           baseFilter3         = null;
            ISampleGrabber        sampleGrabber       = null;
            ISampleGrabber        sampleGrabber2      = null;
            IMediaControl         mediaControl        = null;
            IAMVideoControl       iAMVideoControl     = null;
            IMediaEventEx         mediaEventEx        = null;
            IPin        pin         = null;
            IAMCrossbar iAMCrossbar = null;

            try
            {
                Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.CaptureGraphBuilder2);
                if (typeFromCLSID == null)
                {
                    throw new ApplicationException("Failed creating capture graph builder");
                }
                obj = Activator.CreateInstance(typeFromCLSID);
                captureGraphBuilder = (ICaptureGraphBuilder2)obj;
                typeFromCLSID       = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (typeFromCLSID == null)
                {
                    throw new ApplicationException("Failed creating filter graph");
                }
                obj2        = Activator.CreateInstance(typeFromCLSID);
                filterGraph = (IFilterGraph2)obj2;
                captureGraphBuilder.SetFiltergraph((IGraphBuilder)filterGraph);
                sourceObject = FilterInfo.CreateFilter(deviceMoniker);
                if (sourceObject == null)
                {
                    throw new ApplicationException("Failed creating device object for moniker");
                }
                baseFilter = (IBaseFilter)sourceObject;
                try
                {
                    iAMVideoControl = (IAMVideoControl)sourceObject;
                }
                catch
                {
                }
                typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
                if (typeFromCLSID == null)
                {
                    throw new ApplicationException("Failed creating sample grabber");
                }
                obj3           = Activator.CreateInstance(typeFromCLSID);
                sampleGrabber  = (ISampleGrabber)obj3;
                baseFilter2    = (IBaseFilter)obj3;
                obj4           = Activator.CreateInstance(typeFromCLSID);
                sampleGrabber2 = (ISampleGrabber)obj4;
                baseFilter3    = (IBaseFilter)obj4;
                filterGraph.AddFilter(baseFilter, "source");
                filterGraph.AddFilter(baseFilter2, "grabber_video");
                filterGraph.AddFilter(baseFilter3, "grabber_snapshot");
                AMMediaType aMMediaType = new AMMediaType();
                aMMediaType.MajorType = MediaType.Video;
                aMMediaType.SubType   = MediaSubType.RGB24;
                sampleGrabber.SetMediaType(aMMediaType);
                sampleGrabber2.SetMediaType(aMMediaType);
                captureGraphBuilder.FindInterface(FindDirection.UpstreamOnly, Guid.Empty, baseFilter, typeof(IAMCrossbar).GUID, out retInterface);
                if (retInterface != null)
                {
                    iAMCrossbar = (IAMCrossbar)retInterface;
                }
                isCrossbarAvailable = (iAMCrossbar != null);
                crossbarVideoInputs = ColletCrossbarVideoInputs(iAMCrossbar);
                if (iAMVideoControl != null)
                {
                    captureGraphBuilder.FindPin(sourceObject, PinDirection.Output, PinCategory.StillImage, MediaType.Video, unconnected: false, 0, out pin);
                    if (pin != null)
                    {
                        iAMVideoControl.GetCaps(pin, out VideoControlFlags flags);
                        flag = ((flags & VideoControlFlags.ExternalTriggerEnable) != 0);
                    }
                }
                sampleGrabber.SetBufferSamples(bufferThem: false);
                sampleGrabber.SetOneShot(oneShot: false);
                sampleGrabber.SetCallback(grabber, 1);
                sampleGrabber2.SetBufferSamples(bufferThem: true);
                sampleGrabber2.SetOneShot(oneShot: false);
                sampleGrabber2.SetCallback(grabber2, 1);
                GetPinCapabilitiesAndConfigureSizeAndRate(captureGraphBuilder, baseFilter, PinCategory.Capture, videoResolution, ref videoCapabilities);
                if (flag)
                {
                    GetPinCapabilitiesAndConfigureSizeAndRate(captureGraphBuilder, baseFilter, PinCategory.StillImage, snapshotResolution, ref snapshotCapabilities);
                }
                else
                {
                    snapshotCapabilities = new VideoCapabilities[0];
                }
                lock (cacheVideoCapabilities)
                {
                    if (videoCapabilities != null && !cacheVideoCapabilities.ContainsKey(deviceMoniker))
                    {
                        cacheVideoCapabilities.Add(deviceMoniker, videoCapabilities);
                    }
                }
                lock (cacheSnapshotCapabilities)
                {
                    if (snapshotCapabilities != null && !cacheSnapshotCapabilities.ContainsKey(deviceMoniker))
                    {
                        cacheSnapshotCapabilities.Add(deviceMoniker, snapshotCapabilities);
                    }
                }
                if (runGraph)
                {
                    captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, baseFilter, null, baseFilter2);
                    if (sampleGrabber.GetConnectedMediaType(aMMediaType) == 0)
                    {
                        VideoInfoHeader videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(aMMediaType.FormatPtr, typeof(VideoInfoHeader));
                        grabber.Width  = videoInfoHeader.BmiHeader.Width;
                        grabber.Height = videoInfoHeader.BmiHeader.Height;
                        aMMediaType.Dispose();
                    }
                    if (flag && provideSnapshots)
                    {
                        captureGraphBuilder.RenderStream(PinCategory.StillImage, MediaType.Video, baseFilter, null, baseFilter3);
                        if (sampleGrabber2.GetConnectedMediaType(aMMediaType) == 0)
                        {
                            VideoInfoHeader videoInfoHeader2 = (VideoInfoHeader)Marshal.PtrToStructure(aMMediaType.FormatPtr, typeof(VideoInfoHeader));
                            grabber2.Width  = videoInfoHeader2.BmiHeader.Width;
                            grabber2.Height = videoInfoHeader2.BmiHeader.Height;
                            aMMediaType.Dispose();
                        }
                    }
                    mediaControl = (IMediaControl)obj2;
                    mediaEventEx = (IMediaEventEx)obj2;
                    mediaControl.Run();
                    if (flag && provideSnapshots)
                    {
                        startTime = DateTime.Now;
                        iAMVideoControl.SetMode(pin, VideoControlFlags.ExternalTriggerEnable);
                    }
                    do
                    {
                        if (mediaEventEx != null && mediaEventEx.GetEvent(out DsEvCode lEventCode, out IntPtr lParam, out IntPtr lParam2, 0) >= 0)
                        {
                            mediaEventEx.FreeEventParams(lEventCode, lParam, lParam2);
                            if (lEventCode == DsEvCode.DeviceLost)
                            {
                                reason = ReasonToFinishPlaying.DeviceLost;
                                break;
                            }
                        }
                        if (needToSetVideoInput)
                        {
                            needToSetVideoInput = false;
                            if (isCrossbarAvailable.Value)
                            {
                                SetCurrentCrossbarInput(iAMCrossbar, crossbarVideoInput);
                                crossbarVideoInput = GetCurrentCrossbarInput(iAMCrossbar);
                            }
                        }
                        if (needToSimulateTrigger)
                        {
                            needToSimulateTrigger = false;
                            if (flag && provideSnapshots)
                            {
                                iAMVideoControl.SetMode(pin, VideoControlFlags.Trigger);
                            }
                        }
                        if (needToDisplayPropertyPage)
                        {
                            needToDisplayPropertyPage = false;
                            DisplayPropertyPage(parentWindowForPropertyPage, sourceObject);
                            if (iAMCrossbar != null)
                            {
                                crossbarVideoInput = GetCurrentCrossbarInput(iAMCrossbar);
                            }
                        }
                        if (needToDisplayCrossBarPropertyPage)
                        {
                            needToDisplayCrossBarPropertyPage = false;
                            if (iAMCrossbar != null)
                            {
                                DisplayPropertyPage(parentWindowForPropertyPage, iAMCrossbar);
                                crossbarVideoInput = GetCurrentCrossbarInput(iAMCrossbar);
                            }
                        }
                    }while (!stopEvent.WaitOne(100, exitContext: false));
                    mediaControl.Stop();
                }
            }
            catch (Exception ex)
            {
                if (this.VideoSourceError != null)
                {
                    this.VideoSourceError(this, new VideoSourceErrorEventArgs(ex.Message));
                }
            }
            finally
            {
                captureGraphBuilder = null;
                filterGraph         = null;
                baseFilter          = null;
                mediaControl        = null;
                iAMVideoControl     = null;
                mediaEventEx        = null;
                pin            = null;
                iAMCrossbar    = null;
                baseFilter2    = null;
                baseFilter3    = null;
                sampleGrabber  = null;
                sampleGrabber2 = null;
                if (obj2 != null)
                {
                    Marshal.ReleaseComObject(obj2);
                    obj2 = null;
                }
                if (sourceObject != null)
                {
                    Marshal.ReleaseComObject(sourceObject);
                    sourceObject = null;
                }
                if (obj3 != null)
                {
                    Marshal.ReleaseComObject(obj3);
                    obj3 = null;
                }
                if (obj4 != null)
                {
                    Marshal.ReleaseComObject(obj4);
                    obj4 = null;
                }
                if (obj != null)
                {
                    Marshal.ReleaseComObject(obj);
                    obj = null;
                }
                if (retInterface != null)
                {
                    Marshal.ReleaseComObject(retInterface);
                    retInterface = null;
                }
            }
            if (this.PlayingFinished != null)
            {
                this.PlayingFinished(this, reason);
            }
        }
Exemple #13
0
        private void VideoSourceLoad(object sender, EventArgs e)
        {
            UISync.Init(this);

            //tcSource.Controls.RemoveAt(5);
            tlpVLC.Enabled = VlcHelper.VlcInstalled;
            linkLabel3.Visible = lblInstallVLC.Visible = !tlpVLC.Enabled;

            cmbJPEGURL.Text = MainForm.Conf.JPEGURL;
            cmbMJPEGURL.Text = MainForm.Conf.MJPEGURL;
            cmbVLCURL.Text = MainForm.Conf.VLCURL;
            cmbFile.Text = MainForm.Conf.AVIFileName;

            txtLogin.Text = txtLogin2.Text = CameraControl.Camobject.settings.login;
            txtPassword.Text = txtPassword2.Text = CameraControl.Camobject.settings.password;
            txtUserAgent.Text = txtUserAgent2.Text = CameraControl.Camobject.settings.useragent;
            txtResizeWidth.Value = CameraControl.Camobject.settings.desktopresizewidth;
            txtResizeHeight.Value = CameraControl.Camobject.settings.desktopresizeheight;
            chkNoResize.Checked = !CameraControl.Camobject.settings.resize;
            chkUseHttp10.Checked = chkUseHttp102.Checked = CameraControl.Camobject.settings.usehttp10;

            VideoSourceString = CameraControl.Camobject.settings.videosourcestring;

            SourceIndex = CameraControl.Camobject.settings.sourceindex;
            if (SourceIndex == 3)
            {
                VideoDeviceMoniker = VideoSourceString;
                string[] wh= CameraControl.Camobject.resolution.Split('x');
                CaptureSize = new Size(Convert.ToInt32(wh[0]), Convert.ToInt32(wh[1]));
            }
            txtFrameInterval.Text = txtFrameInterval2.Text = CameraControl.Camobject.settings.frameinterval.ToString(CultureInfo.InvariantCulture);
            chkForceBasic1.Checked = chkForceBasic.Checked = CameraControl.Camobject.settings.forcebasic;
            txtVLCArgs.Text = CameraControl.Camobject.settings.vlcargs.Replace("\r\n","\n").Replace("\n\n","\n").Replace("\n", Environment.NewLine);
            txtReconnect.Value = CameraControl.Camobject.settings.reconnectinterval;
            txtCookies.Text = txtCookies1.Text = CameraControl.Camobject.settings.cookies;

            ddlCustomProvider.SelectedIndex = 0;
            switch (SourceIndex)
            {
                case 0:
                    cmbJPEGURL.Text = VideoSourceString;
                    txtFrameInterval.Text = CameraControl.Camobject.settings.frameinterval.ToString(CultureInfo.InvariantCulture);
                    break;
                case 1:
                    cmbMJPEGURL.Text = VideoSourceString;
                    break;
                case 2:
                    cmbFile.Text = VideoSourceString;
                    break;
                case 5:
                    cmbVLCURL.Text = VideoSourceString;
                    break;
                case 8:
                    txtCustomURL.Text = VideoSourceString;
                    switch (NV("custom"))
                    {
                        default:
                            ddlCustomProvider.SelectedIndex = 0;
                            break;
                    }
                    break;
            }

            if (!String.IsNullOrEmpty(CameraControl.Camobject.decodekey))
                txtDecodeKey.Text = CameraControl.Camobject.decodekey;

            chkMousePointer.Checked = CameraControl.Camobject.settings.desktopmouse;
            numBorderTimeout.Value = CameraControl.Camobject.settings.bordertimeout;

            cmbJPEGURL.Items.AddRange(MainForm.Conf.RecentJPGList.Split('|'));
            cmbMJPEGURL.Items.AddRange(MainForm.Conf.RecentMJPGList.Split('|'));
            cmbFile.Items.AddRange(MainForm.Conf.RecentFileList.Split('|'));
            cmbVLCURL.Items.AddRange(MainForm.Conf.RecentVLCList.Split('|'));

            int selectedCameraIndex = 0;

            for (int i = 0; i < _videoDevices.Count; i++)
            {
                if (_videoDeviceMoniker == _videoDevices[i].MonikerString)
                {
                    selectedCameraIndex = i;
                    break;
                }
            }

            devicesCombo.SelectedIndex = selectedCameraIndex;
            ddlScreen.SuspendLayout();
            foreach (Screen s in Screen.AllScreens)
            {
                ddlScreen.Items.Add(s.DeviceName);
            }
            ddlScreen.Items.Insert(0, LocRm.GetString("PleaseSelect"));
            if (SourceIndex == 4)
            {
                int screenIndex = Convert.ToInt32(VideoSourceString) + 1;
                ddlScreen.SelectedIndex = ddlScreen.Items.Count>screenIndex ? screenIndex : 1;
            }
            else
                ddlScreen.SelectedIndex = 0;
            ddlScreen.ResumeLayout();

            tcSource.SelectedIndex = SourceIndex;

            if (CameraControl != null && CameraControl.Camera != null && CameraControl.Camera.VideoSource is VideoCaptureDevice)
            {
                _videoCaptureDevice = (VideoCaptureDevice)CameraControl.Camera.VideoSource;
                _videoInput = _videoCaptureDevice.CrossbarVideoInput;
                EnumeratedSupportedFrameSizes();
            }

            //ximea

            int deviceCount = 0;

            try
            {
                deviceCount = XimeaCamera.CamerasCount;
            }
            catch(Exception)
            {
                //Ximea DLL not installed
                //Log.Info("This is not a XIMEA device");
            }

            pnlXimea.Enabled = deviceCount>0;

            if (pnlXimea.Enabled)
            {
                for (int i = 0; i < deviceCount; i++)
                {
                    ddlXimeaDevice.Items.Add("Device " + i);
                }
                if (NV("type")=="ximea")
                {
                    int deviceIndex = Convert.ToInt32(NV("device"));
                    ddlXimeaDevice.SelectedIndex = ddlXimeaDevice.Items.Count > deviceIndex?deviceIndex:0;
                    numXimeaWidth.Text = NV("width");
                    numXimeaHeight.Text = NV("height");
                    numXimeaOffsetX.Value = Convert.ToInt32(NV("x"));
                    numXimeaOffestY.Value = Convert.ToInt32(NV("y"));

                    decimal gain;
                    decimal.TryParse(NV("gain"), out gain);
                    numXimeaGain.Value =  gain;

                    decimal exp;
                    decimal.TryParse(NV("exposure"), out exp);
                    if (exp == 0)
                        exp = 100;
                    numXimeaExposure.Value = exp;

                    combo_dwnsmpl.SelectedItem  = NV("downsampling");
                }
            }
            else
            {
                ddlXimeaDevice.Items.Add(LocRm.GetString("NoDevicesFound"));
                ddlXimeaDevice.SelectedIndex = 0;
            }

            deviceCount = 0;
            try
            {
                foreach (var potentialSensor in KinectSensor.KinectSensors)
                {
                    if (potentialSensor.Status == KinectStatus.Connected)
                    {
                        deviceCount++;
                        ddlKinectDevice.Items.Add(potentialSensor.UniqueKinectId);

                        if (NV("type") == "kinect")
                        {
                            if (NV("UniqueKinectId") == potentialSensor.UniqueKinectId)
                            {
                                ddlKinectDevice.SelectedIndex = ddlKinectDevice.Items.Count - 1;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Type error if not installed
                Log.Error("Kinect supporting libraries not installed.",ex);
            }
            if (deviceCount>0)
            {
                if (ddlKinectDevice.SelectedIndex == -1)
                    ddlKinectDevice.SelectedIndex = 0;
            }
            else
            {
                pnlKinect.Enabled = false;
            }

            if (NV("type") == "kinect")
            {
                try
                {
                    chkKinectSkeletal.Checked = Convert.ToBoolean(NV("KinectSkeleton"));
                    chkTripWires.Checked = Convert.ToBoolean(NV("TripWires"));
                }
                catch {}
            }

            _loaded = true;
            if (StartWizard) Wizard();
        }
Exemple #14
0
        private void VideoSourceLoad(object sender, EventArgs e)
        {
            UISync.Init(this);
            tlpVLC.Enabled = VlcHelper.VlcInstalled;
            linkLabel3.Visible = !tlpVLC.Enabled;

            cmbJPEGURL.Text = MainForm.Conf.JPEGURL;
            cmbMJPEGURL.Text = MainForm.Conf.MJPEGURL;
            cmbVLCURL.Text = MainForm.Conf.VLCURL;
            cmbFile.Text = MainForm.Conf.AVIFileName;
            ConfigureSnapshots = true;

            txtOnvifUsername.Text = txtLogin.Text = txtLogin2.Text = CameraControl.Camobject.settings.login;
            txtOnvifPassword.Text = txtPassword.Text = txtPassword2.Text = CameraControl.Camobject.settings.password;

            VideoSourceString = CameraControl.Camobject.settings.videosourcestring;

            SourceIndex = CameraControl.Camobject.settings.sourceindex;
            if (SourceIndex == 3)
            {
                VideoDeviceMoniker = VideoSourceString;
                string[] wh= CameraControl.Camobject.resolution.Split('x');
                CaptureSize = new Size(Convert.ToInt32(wh[0]), Convert.ToInt32(wh[1]));
            }
            txtFrameInterval.Text = txtFrameInterval2.Text = CameraControl.Camobject.settings.frameinterval.ToString(CultureInfo.InvariantCulture);

            txtVLCArgs.Text = CameraControl.Camobject.settings.vlcargs.Replace("\r\n","\n").Replace("\n\n","\n").Replace("\n", Environment.NewLine);

            foreach (var cam in MainForm.Cameras)
            {
                if (cam.id != CameraControl.Camobject.id && cam.settings.sourceindex!=10) //dont allow a clone of a clone as the events get too complicated (and also it's pointless)
                    ddlCloneCamera.Items.Add(new MainForm.ListItem2(cam.name, cam.id));
            }

            ddlCustomProvider.SelectedIndex = 0;
            switch (SourceIndex)
            {
                case 0:
                    cmbJPEGURL.Text = VideoSourceString;
                    txtFrameInterval.Text = CameraControl.Camobject.settings.frameinterval.ToString(CultureInfo.InvariantCulture);
                    break;
                case 1:
                    cmbMJPEGURL.Text = VideoSourceString;
                    break;
                case 2:
                    cmbFile.Text = VideoSourceString;
                    break;
                case 3:
                    chkAutoImageSettings.Checked = NV("manual") != "true";
                    break;
                case 5:
                    cmbVLCURL.Text = VideoSourceString;
                    break;
                case 8:
                    txtCustomURL.Text = VideoSourceString;
                    switch (NV("custom"))
                    {
                        default:
                            ddlCustomProvider.SelectedIndex = 0;
                            break;
                    }
                    break;
                case 10:
                    int id;
                    if (Int32.TryParse(VideoSourceString, out id))
                    {
                        foreach (MainForm.ListItem2 li in ddlCloneCamera.Items)
                        {
                            if (li.Value == id)
                            {
                                ddlCloneCamera.SelectedItem = li;
                                break;
                            }
                        }
                    }
                    break;
            }

            if (!String.IsNullOrEmpty(CameraControl.Camobject.decodekey))
                txtDecodeKey.Text = CameraControl.Camobject.decodekey;

            chkMousePointer.Checked = CameraControl.Camobject.settings.desktopmouse;
            numBorderTimeout.Value = CameraControl.Camobject.settings.bordertimeout;

            cmbJPEGURL.Items.AddRange(ObjectList(MainForm.Conf.RecentJPGList));
            cmbMJPEGURL.Items.AddRange(ObjectList(MainForm.Conf.RecentMJPGList));
            cmbFile.Items.AddRange(ObjectList(MainForm.Conf.RecentFileList));
            cmbVLCURL.Items.AddRange(ObjectList(MainForm.Conf.RecentVLCList));

            numAnalyseDuration.Value = CameraControl.Camobject.settings.analyseduration;

            int selectedCameraIndex = 0;

            for (int i = 0; i < _videoDevices.Count; i++)
            {
                if (_videoDeviceMoniker == _videoDevices[i].MonikerString)
                {
                    selectedCameraIndex = i;
                    break;
                }
            }

            devicesCombo.SelectedIndex = selectedCameraIndex;
            ddlScreen.SuspendLayout();
            foreach (Screen s in Screen.AllScreens)
            {
                ddlScreen.Items.Add(s.DeviceName);
            }
            ddlScreen.Items.Insert(0, LocRm.GetString("PleaseSelect"));
            if (SourceIndex == 4)
            {
                int screenIndex = Convert.ToInt32(VideoSourceString) + 1;
                ddlScreen.SelectedIndex = ddlScreen.Items.Count>screenIndex ? screenIndex : 1;
            }
            else
                ddlScreen.SelectedIndex = 0;
            ddlScreen.ResumeLayout();

            SetSourceIndex(SourceIndex);

            if (CameraControl != null && CameraControl.Camera != null && CameraControl.Camera.VideoSource is VideoCaptureDevice)
            {
                _videoCaptureDevice = (VideoCaptureDevice)CameraControl.Camera.VideoSource;
                _videoInput = _videoCaptureDevice.CrossbarVideoInput;
                EnumeratedSupportedFrameSizes();
            }

            //ximea

            int deviceCount = 0;

            try
            {
                deviceCount = XimeaCamera.CamerasCount;
            }
            catch(Exception)
            {
                //Ximea DLL not installed
                //MainForm.LogMessageToFile("This is not a XIMEA device");
            }

            pnlXimea.Enabled = deviceCount>0;

            if (pnlXimea.Enabled)
            {
                for (int i = 0; i < deviceCount; i++)
                {
                    ddlXimeaDevice.Items.Add("Device " + i);
                }
                if (NV("type")=="ximea")
                {
                    int deviceIndex = Convert.ToInt32(NV("device"));
                    ddlXimeaDevice.SelectedIndex = ddlXimeaDevice.Items.Count > deviceIndex?deviceIndex:0;
                    numXimeaWidth.Text = NV("width");
                    numXimeaHeight.Text = NV("height");
                    numXimeaOffsetX.Value = Convert.ToInt32(NV("x"));
                    numXimeaOffestY.Value = Convert.ToInt32(NV("y"));

                    decimal gain;
                    decimal.TryParse(NV("gain"), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out gain);
                    numXimeaGain.Value =  gain;

                    decimal exp;
                    decimal.TryParse(NV("exposure"), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out exp);
                    if (exp == 0)
                        exp = 100;
                    numXimeaExposure.Value = exp;

                    combo_dwnsmpl.SelectedItem  = NV("downsampling");
                }
            }
            else
            {
                ddlXimeaDevice.Items.Add(LocRm.GetString("NoDevicesFound"));
                ddlXimeaDevice.SelectedIndex = 0;
            }

            deviceCount = 0;

            try
            {
                foreach (var potentialSensor in KinectSensor.KinectSensors)
                {
                    if (potentialSensor.Status == KinectStatus.Connected)
                    {
                        deviceCount++;
                        ddlKinectDevice.Items.Add(potentialSensor.UniqueKinectId);

                        if (NV("type") == "kinect")
                        {
                            if (NV("UniqueKinectId") == potentialSensor.UniqueKinectId)
                            {
                                ddlKinectDevice.SelectedIndex = ddlKinectDevice.Items.Count - 1;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //Type error if not installed
                MainForm.LogMessageToFile("Kinect is not installed");
            }
            if (deviceCount>0)
            {
                if (ddlKinectDevice.SelectedIndex == -1)
                    ddlKinectDevice.SelectedIndex = 0;
            }
            else
            {
                pnlKinect.Enabled = false;
            }

            ddlKinectVideoMode.SelectedIndex = 0;
            if (NV("type") == "kinect")
            {
                try
                {
                    chkKinectSkeletal.Checked = Convert.ToBoolean(NV("KinectSkeleton"));
                    chkTripWires.Checked = Convert.ToBoolean(NV("TripWires"));
                    if (NV("StreamMode")!="")
                        ddlKinectVideoMode.SelectedIndex = Convert.ToInt32(NV("StreamMode"));
                }
                catch {}
            }

            ddlTransport.Items.AddRange(_transports);
            ddlTransport.SelectedIndex = 0;
            ddlRTSP.SelectedIndex = CameraControl.Camobject.settings.rtspmode;

            chkConnectVLC.Enabled = chkConnectVLC.Checked = VlcHelper.VlcInstalled;

            int j = 0;
            foreach(var dev in MainForm.ONVIFDevices)
            {
                string n = dev.Name;
                if (!String.IsNullOrEmpty(dev.Location))
                    n += " (" + dev.Location + ")";
                lbONVIFDevices.Items.Add(new MainForm.ListItem2(n,j));
                j++;
            }

            _loaded = true;
            if (StartWizard) Wizard();
        }
        // Ok button clicked
        private void okButton_Click(object sender, EventArgs e)
        {
            videoDeviceMoniker = videoDevice.Source;

            // set video size
            if (videoCapabilitiesDictionary.Count != 0)
            {
                VideoCapabilities caps = videoCapabilitiesDictionary[(string)videoResolutionsCombo.SelectedItem];

                videoDevice.VideoResolution = caps;
                captureSize = caps.FrameSize;
            }

            if (configureSnapshots)
            {
                // set snapshots size
                if (snapshotCapabilitiesDictionary.Count != 0)
                {
                    VideoCapabilities caps = snapshotCapabilitiesDictionary[(string)snapshotResolutionsCombo.SelectedItem];

                    videoDevice.ProvideSnapshots = true;
                    videoDevice.SnapshotResolution = caps;

                    snapshotSize = caps.FrameSize;
                }
            }

            if (availableVideoInputs.Length != 0)
            {
                videoInput = availableVideoInputs[videoInputsCombo.SelectedIndex];
                videoDevice.CrossbarVideoInput = videoInput;
            }
        }