Beispiel #1
0
        public void Connect(ImageDescriptor imageDescriptor, IFrameProducer producer, ConsumerDisplay consumerDisplay, ConsumerMJPEGRecorder consumerRecord)
        {
            // At that point the consumer threads are already started.
            // But only the display thread (actually the UI main thread) should be "active".
            // The producer thread is not started yet, it will be started outside the pipeline manager.
            this.producer        = producer;
            this.consumerDisplay = consumerDisplay;
            this.consumerRecord  = consumerRecord;

            consumerDisplay.SetImageDescriptor(imageDescriptor);
            consumerRecord.SetImageDescriptor(imageDescriptor);

            consumers.Clear();
            consumers.Add(consumerDisplay as IFrameConsumer);
            consumers.Add(consumerRecord as IFrameConsumer);

            int buffers = 8;

            pipeline = new FramePipeline(producer, consumers, buffers, imageDescriptor.BufferSize);
            pipeline.SetBenchmarkMode(BenchmarkMode.None);

            if (pipeline.Allocated)
            {
                producer.FrameProduced += producer_FrameProduced;
                connected = true;
            }
        }
Beispiel #2
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;
        }