Example #1
0
        /// <inheritdoc />
        internal override void EnableOutputPort(bool sendBuffers = true)
        {
            if (!this.Enabled)
            {
                this.ManagedOutputCallback = OutputCallbackProvider.FindCallback(this);

                this.NativeCallback = this.NativeOutputPortCallback;

                IntPtr ptrCallback = Marshal.GetFunctionPointerForDelegate(this.NativeCallback);
                this.PtrCallback = ptrCallback;

                if (this.ManagedOutputCallback == null)
                {
                    MMALLog.Logger.Warn("Callback null");

                    this.EnablePort(IntPtr.Zero);
                }
                else
                {
                    this.EnablePort(ptrCallback);
                }

                if (this.ManagedOutputCallback != null)
                {
                    this.SendAllBuffers(sendBuffers);
                }
            }

            if (!this.Enabled)
            {
                throw new PiCameraError("Unknown error occurred whilst enabling port");
            }
        }
        /// <inheritdoc />
        public override unsafe MMALDownstreamComponent ConfigureOutputPort(int outputPort, MMALPortConfig config)
        {
            this.Outputs[outputPort].PortConfig = config;

            if (this.ProcessingPorts.ContainsKey(outputPort))
            {
                this.ProcessingPorts.Remove(outputPort);
            }

            this.ProcessingPorts.Add(outputPort, this.Outputs[outputPort]);

            if (config.EncodingType != null)
            {
                this.Outputs[outputPort].Ptr->Format->Encoding = config.EncodingType.EncodingVal;
            }

            if (config.ZeroCopy)
            {
                this.Outputs[outputPort].ZeroCopy = true;
                this.Outputs[outputPort].SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);
            }

            this.Outputs[outputPort].Resolution = new Resolution(config.Width, config.Height).Pad();
            this.Outputs[outputPort].Crop       = new Rectangle(0, 0, config.Width, config.Height);

            this.Outputs[outputPort].Commit();

            this.Outputs[outputPort].EncodingType = config.EncodingType;

            this.Outputs[outputPort].Ptr->BufferNum        = Math.Max(this.Outputs[outputPort].Ptr->BufferNumRecommended, this.Outputs[outputPort].Ptr->BufferNumMin);
            this.Outputs[outputPort].Ptr->BufferSize       = Math.Max(this.Outputs[outputPort].Ptr->BufferSizeRecommended, this.Outputs[outputPort].Ptr->BufferSizeMin);
            this.Outputs[outputPort].ManagedOutputCallback = OutputCallbackProvider.FindCallback(this.Outputs[outputPort]);

            return(this);
        }
        /// <summary>
        /// Call to configure changes on an Downstream component output port.
        /// </summary>
        /// <param name="outputPort">The output port we are configuring.</param>
        /// <param name="encodingType">The encoding type this output port will send data in.</param>
        /// <param name="pixelFormat">The pixel format this output port will send data in.</param>
        /// <param name="quality">The quality of our outputted data.</param>
        /// <param name="bitrate">The bitrate we are sending data at.</param>
        /// <param name="zeroCopy">Instruct MMAL to not copy buffers to ARM memory (useful for large buffers and handling raw data).</param>
        public virtual unsafe void ConfigureOutputPort(int outputPort, MMALEncoding encodingType, MMALEncoding pixelFormat, int quality, int bitrate = 0, bool zeroCopy = false)
        {
            this.InitialiseOutputPort(outputPort);
            this.ProcessingPorts.Add(outputPort);

            this.Inputs[0].ShallowCopy(this.Outputs[outputPort]);

            if (encodingType != null)
            {
                this.Outputs[outputPort].NativeEncodingType = encodingType.EncodingVal;
            }

            if (pixelFormat != null)
            {
                this.Outputs[outputPort].NativeEncodingSubformat = pixelFormat.EncodingVal;
            }

            MMAL_VIDEO_FORMAT_T tempVid = this.Outputs[outputPort].Ptr->Format->Es->Video;

            try
            {
                this.Outputs[outputPort].Commit();
            }
            catch
            {
                // If commit fails using new settings, attempt to reset using old temp MMAL_VIDEO_FORMAT_T.
                MMALLog.Logger.Warn("Commit of output port failed. Attempting to reset values.");
                this.Outputs[outputPort].Ptr->Format->Es->Video = tempVid;
                this.Outputs[outputPort].Commit();
            }

            if (encodingType == MMALEncoding.JPEG)
            {
                this.Outputs[outputPort].SetParameter(MMALParametersCamera.MMAL_PARAMETER_JPEG_Q_FACTOR, quality);
            }

            if (zeroCopy)
            {
                this.Outputs[outputPort].ZeroCopy = true;
                this.Outputs[outputPort].SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);
            }

            this.Outputs[outputPort].EncodingType = encodingType;
            this.Outputs[outputPort].PixelFormat  = pixelFormat;

            this.Outputs[outputPort].Resolution = new Resolution(this.Width, this.Height).Pad();
            this.Outputs[outputPort].Crop       = new Rectangle(0, 0, this.Width, this.Height);

            // It is important to re-commit changes to width and height.
            this.Outputs[outputPort].Commit();

            this.Outputs[outputPort].BufferNum  = Math.Max(this.Outputs[outputPort].Ptr->BufferNumRecommended, this.Outputs[outputPort].Ptr->BufferNumMin);
            this.Outputs[outputPort].BufferSize = Math.Max(this.Outputs[outputPort].Ptr->BufferSizeRecommended, this.Outputs[outputPort].Ptr->BufferSizeMin);

            this.Outputs[outputPort].ManagedOutputCallback = OutputCallbackProvider.FindCallback(this.Outputs[outputPort]);
        }
        /// <inheritdoc />
        public override unsafe MMALDownstreamComponent ConfigureOutputPort(int outputPort, MMALPortConfig config)
        {
            this.Outputs[outputPort].Ptr->Format->Es->Video.Par = new MMAL_RATIONAL_T(1, 1);

            if (this.ProcessingPorts.ContainsKey(outputPort))
            {
                this.ProcessingPorts.Remove(outputPort);
            }

            this.ProcessingPorts.Add(outputPort, this.Outputs[outputPort]);

            if (config.EncodingType != null)
            {
                this.Outputs[outputPort].Ptr->Format->Encoding = config.EncodingType.EncodingVal;
            }

            if (config.PixelFormat != null)
            {
                this.Outputs[outputPort].Ptr->Format->EncodingVariant = config.PixelFormat.EncodingVal;
            }

            if (config.ZeroCopy)
            {
                this.Outputs[outputPort].ZeroCopy = true;
                this.Outputs[outputPort].SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);
            }

            if (MMALCameraConfig.VideoColorSpace != null &&
                MMALCameraConfig.VideoColorSpace.EncType == MMALEncoding.EncodingType.ColorSpace)
            {
                this.Outputs[outputPort].VideoColorSpace = MMALCameraConfig.VideoColorSpace;
            }

            this.Outputs[outputPort].FrameRate            = new MMAL_RATIONAL_T(config.Framerate, 1);
            this.Outputs[outputPort].Resolution           = new Resolution(config.Width, config.Height).Pad();
            this.Outputs[outputPort].Crop                 = new Rectangle(0, 0, config.Width, config.Height);
            this.Outputs[outputPort].Ptr->Format->Bitrate = config.Bitrate;

            this.Outputs[outputPort].Commit();

            this.Outputs[outputPort].EncodingType = config.EncodingType;

            this.Outputs[outputPort].ManagedOutputCallback = OutputCallbackProvider.FindCallback(this.Outputs[outputPort]);

            this.Outputs[outputPort].Ptr->BufferNum  = Math.Max(this.Outputs[outputPort].Ptr->BufferNumMin, this.Outputs[outputPort].Ptr->BufferNumRecommended);
            this.Outputs[outputPort].Ptr->BufferSize = Math.Max(this.Outputs[outputPort].Ptr->BufferSizeMin, this.Outputs[outputPort].Ptr->BufferSizeRecommended);

            return(this);
        }
Example #5
0
        /// <summary>
        /// Enables processing on an output port.
        /// </summary>
        /// <param name="sendBuffers">Indicates whether we want to send all the buffers in the port pool or simply create the pool.</param>
        internal override void EnableOutputPort(bool sendBuffers = true)
        {
            if (!this.Enabled)
            {
                this.ManagedOutputCallback = OutputCallbackProvider.FindCallback(this);

                this.NativeCallback = this.NativeOutputPortCallback;

                IntPtr ptrCallback = IntPtr.Zero;
                if (sendBuffers)
                {
                    ptrCallback      = Marshal.GetFunctionPointerForDelegate(this.NativeCallback);
                    this.PtrCallback = ptrCallback;
                }
                else
                {
                    ptrCallback = this.PtrCallback;
                }

                MMALLog.Logger.Debug("Enabling port.");

                if (this.ManagedOutputCallback == null)
                {
                    MMALLog.Logger.Warn("Callback null");

                    MMALCheck(MMALPort.mmal_port_enable(this.Ptr, IntPtr.Zero), "Unable to enable port.");
                }
                else
                {
                    MMALCheck(MMALPort.mmal_port_enable(this.Ptr, ptrCallback), "Unable to enable port.");
                }

                base.EnableOutputPort(sendBuffers);
            }

            if (!this.Enabled)
            {
                throw new PiCameraError("Unknown error occurred whilst enabling port");
            }
        }
Example #6
0
        /// <summary>
        /// Enables processing on a port.
        /// </summary>
        internal override void EnableControlPort()
        {
            if (!this.Enabled)
            {
                this.ManagedControlCallback = OutputCallbackProvider.FindCallback(this);

                this.NativeCallback = new MMALPort.MMAL_PORT_BH_CB_T(this.NativeControlPortCallback);

                IntPtr ptrCallback = Marshal.GetFunctionPointerForDelegate(this.NativeCallback);

                MMALLog.Logger.Debug("Enabling control port.");

                if (this.ManagedControlCallback == null)
                {
                    MMALLog.Logger.Debug("Callback null");

                    MMALCheck(MMALPort.mmal_port_enable(this.Ptr, IntPtr.Zero), "Unable to enable port.");
                }
                else
                {
                    MMALCheck(MMALPort.mmal_port_enable(this.Ptr, ptrCallback), "Unable to enable port.");
                }
            }
        }
Example #7
0
        public override unsafe void ConfigureOutputPort(int outputPort, MMALEncoding encodingType, MMALEncoding pixelFormat, int quality, int bitrate = 0, bool zeroCopy = false)
        {
            this.InitialiseOutputPort(outputPort);
            this.ProcessingPorts.Add(outputPort);

            if (encodingType != null)
            {
                this.Outputs[outputPort].Ptr->Format->Encoding = encodingType.EncodingVal;
            }

            if (zeroCopy)
            {
                this.Outputs[outputPort].ZeroCopy = true;
                this.Outputs[outputPort].SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);
            }

            this.Outputs[outputPort].Commit();

            this.Outputs[outputPort].EncodingType = encodingType;

            this.Outputs[outputPort].Ptr->BufferNum        = Math.Max(this.Outputs[outputPort].Ptr->BufferNumRecommended, this.Outputs[outputPort].Ptr->BufferNumMin);
            this.Outputs[outputPort].Ptr->BufferSize       = Math.Max(this.Outputs[outputPort].Ptr->BufferSizeRecommended, this.Outputs[outputPort].Ptr->BufferSizeMin);
            this.Outputs[outputPort].ManagedOutputCallback = OutputCallbackProvider.FindCallback(this.Outputs[outputPort]);
        }
Example #8
0
        /// <summary>
        /// Call to configure changes on a downstream component output port.
        /// </summary>
        /// <param name="outputPort">The output port number to configure.</param>
        /// <param name="config">User provided port configuration object.</param>
        /// <returns>This <see cref="MMALDownstreamComponent"/>.</returns>
        public virtual unsafe MMALDownstreamComponent ConfigureOutputPort(int outputPort, MMALPortConfig config)
        {
            this.Outputs[outputPort].PortConfig = config;

            if (this.ProcessingPorts.ContainsKey(outputPort))
            {
                this.ProcessingPorts.Remove(outputPort);
            }

            this.ProcessingPorts.Add(outputPort, this.Outputs[outputPort]);

            this.Inputs[0].ShallowCopy(this.Outputs[outputPort]);

            if (config.EncodingType != null)
            {
                this.Outputs[outputPort].NativeEncodingType = config.EncodingType.EncodingVal;
            }

            if (config.PixelFormat != null)
            {
                this.Outputs[outputPort].NativeEncodingSubformat = config.PixelFormat.EncodingVal;
            }

            MMAL_VIDEO_FORMAT_T tempVid = this.Outputs[outputPort].Ptr->Format->Es->Video;

            try
            {
                this.Outputs[outputPort].Commit();
            }
            catch
            {
                // If commit fails using new settings, attempt to reset using old temp MMAL_VIDEO_FORMAT_T.
                MMALLog.Logger.Warn("Commit of output port failed. Attempting to reset values.");
                this.Outputs[outputPort].Ptr->Format->Es->Video = tempVid;
                this.Outputs[outputPort].Commit();
            }

            if (config.EncodingType == MMALEncoding.JPEG)
            {
                this.Outputs[outputPort].SetParameter(MMALParametersCamera.MMAL_PARAMETER_JPEG_Q_FACTOR, config.Quality);
            }

            if (config.ZeroCopy)
            {
                this.Outputs[outputPort].ZeroCopy = true;
                this.Outputs[outputPort].SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);
            }

            if (MMALCameraConfig.VideoColorSpace != null &&
                MMALCameraConfig.VideoColorSpace.EncType == MMALEncoding.EncodingType.ColorSpace)
            {
                this.Outputs[outputPort].VideoColorSpace = MMALCameraConfig.VideoColorSpace;
            }

            if (config.Bitrate > 0)
            {
                this.Outputs[outputPort].Bitrate = config.Bitrate;
            }

            this.Outputs[outputPort].EncodingType = config.EncodingType;
            this.Outputs[outputPort].PixelFormat  = config.PixelFormat;

            if (config.Width > 0 && config.Height > 0)
            {
                this.Outputs[outputPort].Resolution = new Resolution(config.Width, config.Height).Pad();
                this.Outputs[outputPort].Crop       = new Rectangle(0, 0, this.Outputs[outputPort].Resolution.Width, this.Outputs[outputPort].Resolution.Height);
            }
            else
            {
                // Use config or don't set depending on port type.
                this.Outputs[outputPort].Resolution = new Resolution(0, 0);

                if (this.Outputs[outputPort].Resolution.Width > 0 && this.Outputs[outputPort].Resolution.Height > 0)
                {
                    this.Outputs[outputPort].Crop = new Rectangle(0, 0, this.Outputs[outputPort].Resolution.Width, this.Outputs[outputPort].Resolution.Height);
                }
            }

            // It is important to re-commit changes to width and height.
            this.Outputs[outputPort].Commit();

            this.Outputs[outputPort].BufferNum  = Math.Max(this.Outputs[outputPort].Ptr->BufferNumRecommended, this.Outputs[outputPort].Ptr->BufferNumMin);
            this.Outputs[outputPort].BufferSize = Math.Max(this.Outputs[outputPort].Ptr->BufferSizeRecommended, this.Outputs[outputPort].Ptr->BufferSizeMin);

            this.Outputs[outputPort].ManagedOutputCallback = OutputCallbackProvider.FindCallback(this.Outputs[outputPort]);

            return(this);
        }
        /// <inheritdoc />
        public override unsafe MMALDownstreamComponent ConfigureOutputPort(int outputPort, MMALPortConfig config)
        {
            // The splitter component should not have its resolution set on the output port so override method accordingly.
            this.Outputs[outputPort].PortConfig = config;

            if (this.ProcessingPorts.ContainsKey(outputPort))
            {
                this.ProcessingPorts.Remove(outputPort);
            }

            this.ProcessingPorts.Add(outputPort, this.Outputs[outputPort]);

            this.Inputs[0].ShallowCopy(this.Outputs[outputPort]);

            if (config.EncodingType != null)
            {
                this.Outputs[outputPort].NativeEncodingType = config.EncodingType.EncodingVal;
            }

            if (config.PixelFormat != null)
            {
                this.Outputs[outputPort].NativeEncodingSubformat = config.PixelFormat.EncodingVal;
            }

            MMAL_VIDEO_FORMAT_T tempVid = this.Outputs[outputPort].Ptr->Format->Es->Video;

            try
            {
                this.Outputs[outputPort].Commit();
            }
            catch
            {
                // If commit fails using new settings, attempt to reset using old temp MMAL_VIDEO_FORMAT_T.
                MMALLog.Logger.Warn("Commit of output port failed. Attempting to reset values.");
                this.Outputs[outputPort].Ptr->Format->Es->Video = tempVid;
                this.Outputs[outputPort].Commit();
            }

            if (config.EncodingType == MMALEncoding.JPEG)
            {
                this.Outputs[outputPort].SetParameter(MMALParametersCamera.MMAL_PARAMETER_JPEG_Q_FACTOR, config.Quality);
            }

            if (config.ZeroCopy)
            {
                this.Outputs[outputPort].ZeroCopy = true;
                this.Outputs[outputPort].SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);
            }

            if (MMALCameraConfig.VideoColorSpace != null &&
                MMALCameraConfig.VideoColorSpace.EncType == MMALEncoding.EncodingType.ColorSpace)
            {
                this.Outputs[outputPort].VideoColorSpace = MMALCameraConfig.VideoColorSpace;
            }

            this.Outputs[outputPort].EncodingType = config.EncodingType;
            this.Outputs[outputPort].PixelFormat  = config.PixelFormat;

            // It is important to re-commit changes to width and height.
            this.Outputs[outputPort].Commit();

            this.Outputs[outputPort].BufferNum  = Math.Max(this.Outputs[outputPort].Ptr->BufferNumRecommended, this.Outputs[outputPort].Ptr->BufferNumMin);
            this.Outputs[outputPort].BufferSize = Math.Max(this.Outputs[outputPort].Ptr->BufferSizeRecommended, this.Outputs[outputPort].Ptr->BufferSizeMin);

            this.Outputs[outputPort].ManagedOutputCallback = OutputCallbackProvider.FindCallback(this.Outputs[outputPort]);

            return(this);
        }