Ejemplo n.º 1
0
        private void Connect2()
        {
            // Second part of Connect function.
            // The function is split because the first part might need to be run repeatedly and from non UI thread,
            // while this part must run on the UI thread.

            metadata.ImageSize = new Size(imageDescriptor.Width, imageDescriptor.Height);
            metadata.PostSetupCapture();

            AllocateDelayer();

            // Start recorder thread.
            // It will be dormant until recording is started but it has the same lifetime as the pipeline.
            consumerRecord = new ConsumerMJPEGRecorder();
            recorderThread = new Thread(consumerRecord.Run)
            {
                IsBackground = true
            };
            recorderThread.Name = consumerRecord.GetType().Name;
            recorderThread.Start();

            // Make sure the viewport will not use the bitmap allocated by the consumerDisplay as it is about to be disposed.
            viewportController.ForgetBitmap();
            viewportController.InitializeDisplayRectangle(cameraSummary.DisplayRectangle, new Size(imageDescriptor.Width, imageDescriptor.Height));

            // Initialize pipeline.
            pipelineManager.Connect(imageDescriptor, (IFrameProducer)cameraGrabber, consumerDisplay, consumerRecord);

            nonGrabbingInteractionTimer.Enabled = false;

            if (!PreferencesManager.CapturePreferences.UseCameraSignalSynchronization)
            {
                double framerate = PreferencesManager.CapturePreferences.DisplaySynchronizationFramerate;
                if (framerate == 0)
                {
                    framerate = 25;
                }

                grabTimer.Interval = (int)(1000.0 / framerate);
                grabTimer.Enabled  = true;
            }

            cameraGrabber.GrabbingStatusChanged += Grabber_GrabbingStatusChanged;
            cameraGrabber.Start();

            UpdateTitle();
            cameraConnected = true;
        }