Example #1
0
        public void Cancel()
        {
            log.DebugFormat("Cancelling thumbnail for {0}.", Alias);

            if (!baumerProvider.IsOpen)
            {
                return;
            }

            lock (locker)
            {
                baumerProvider.BufferProduced -= BaumerProducer_BufferProduced;
                baumerProvider.Stop();
                if (wasJpegEnabled)
                {
                    BaumerHelper.SetJPEG(baumerProvider.Device, true);
                }

                Close();

                cancelled = true;
            }

            waitHandle.Set();
        }
Example #2
0
        /// <summary>
        /// Configure device and report frame format that will be used during streaming.
        /// This method must return a proper ImageDescriptor so we can pre-allocate buffers.
        /// </summary>
        public ImageDescriptor Prepare()
        {
            Open();

            if (!baumerProvider.IsOpen)
            {
                return(ImageDescriptor.Invalid);
            }

            firstOpen = false;
            Device device = baumerProvider.Device;

            // Get the configured framerate for recording support.
            resultingFramerate = BaumerHelper.GetResultingFramerate(device);

            bool hasWidth                  = BaumerHelper.NodeIsReadable(device, "Width");
            bool hasHeight                 = BaumerHelper.NodeIsReadable(device, "Height");
            bool hasPixelFormat            = BaumerHelper.NodeIsReadable(device, "PixelFormat");
            bool canComputeImageDescriptor = hasWidth && hasHeight && hasPixelFormat;

            if (!canComputeImageDescriptor)
            {
                return(ImageDescriptor.Invalid);
            }

            int    width       = BaumerHelper.GetInteger(device, "Width");
            int    height      = BaumerHelper.GetInteger(device, "Height");
            string pixelFormat = BaumerHelper.GetString(device, "PixelFormat");

            // We output in three possible formats: Y800, RGB24 or JPEG.
            // The output format depends on the stream format and the options.
            // Mono or raw -> Y800, Otherwise -> RGB24.

            // Camera-side JPEG compression.
            compression = specific.Compression;
            if (BaumerHelper.SupportsJPEG(device))
            {
                if (BaumerHelper.FormatCanCompress(device, pixelFormat))
                {
                    BaumerHelper.SetJPEG(device, compression);
                }
                else
                {
                    BaumerHelper.SetJPEG(device, false);
                    compression = false;
                }
            }
            else
            {
                compression = false;
            }

            // Debayering.
            demosaicing = specific.Demosaicing;
            if (demosaicing)
            {
                if (imgProcessor.NodeList.GetNodePresent("DemosaicingMethod"))
                {
                    // Options: NearestNeighbor, Bilinear3x3, Baumer5x5
                    imgProcessor.NodeList["DemosaicingMethod"].Value = "NearestNeighbor";
                }
                else
                {
                    demosaicing = false;
                }
            }

            imageFormat     = BaumerHelper.ConvertImageFormat(pixelFormat, compression, demosaicing);
            frameBufferSize = ImageFormatHelper.ComputeBufferSize(width, height, imageFormat);
            frameBuffer     = new byte[frameBufferSize];

            finishline.Prepare(width, height, imageFormat, resultingFramerate);
            if (finishline.Enabled)
            {
                height             = finishline.Height;
                resultingFramerate = finishline.ResultingFramerate;
            }

            int  outgoingBufferSize = ImageFormatHelper.ComputeBufferSize(width, height, imageFormat);
            bool topDown            = true;

            return(new ImageDescriptor(imageFormat, width, height, topDown, outgoingBufferSize));
        }
Example #3
0
        /// <summary>
        /// Start the device for a frame grab, wait a bit and then return the result.
        /// This method MUST raise a CameraThumbnailProduced event, even in case of error.
        /// </summary>
        public void Run(object data)
        {
            log.DebugFormat("Starting {0} for thumbnail.", summary.Alias);

            SpecificInfo specific = summary.Specific as SpecificInfo;
            bool         opened   = baumerProvider.Open(specific.SystemKey, specific.InterfaceKey, specific.DeviceKey);

            if (!opened)
            {
                log.DebugFormat("Could not open {0} for thumbnail.", summary.Alias);
                if (CameraThumbnailProduced != null)
                {
                    CameraThumbnailProduced(this, new CameraThumbnailProducedEventArgs(summary, null, ImageDescriptor.Invalid, true, false));
                }

                return;
            }

            baumerProvider.BufferProduced += BaumerProducer_BufferProduced;

            // Do not use JPEG compression for the thumbnail.
            wasJpegEnabled = BaumerHelper.GetJPEG(baumerProvider.Device);
            if (wasJpegEnabled)
            {
                BaumerHelper.SetJPEG(baumerProvider.Device, false);
            }

            try
            {
                baumerProvider.AcquireOne();
            }
            catch (Exception e)
            {
                hadError = true;
                LogError(e, null);
            }

            if (!hadError)
            {
                waitHandle.WaitOne(timeoutGrabbing, false);
            }

            lock (locker)
            {
                if (!cancelled)
                {
                    baumerProvider.BufferProduced -= BaumerProducer_BufferProduced;
                    baumerProvider.Stop();
                    if (wasJpegEnabled)
                    {
                        BaumerHelper.SetJPEG(baumerProvider.Device, true);
                    }

                    Close();
                    log.DebugFormat("{0} closed.", summary.Alias);
                }
            }

            if (CameraThumbnailProduced != null)
            {
                CameraThumbnailProduced(this, new CameraThumbnailProducedEventArgs(summary, image, imageDescriptor, hadError, cancelled));
            }
        }