internal static void SetChangeEventRequest(this MMALControlPort controlPort, MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T value)
 {
     MMALCheck(MMALPort.mmal_port_parameter_set(controlPort.Ptr, &value.hdr), "Unable to set camera event request.");
 }
示例#2
0
        /// <summary>
        /// Commits all changes made to the configuration.
        /// </summary>
        /// <exception cref="MMALException"/>
        public unsafe void ConfigureRenderer()
        {
            if (this.Configuration != null)
            {
                int  fullScreen = 0, noAspect = 0, copyProtect = 0;
                uint displaySet = 0;

                MMAL_RECT_T?previewWindow = default(MMAL_RECT_T);

                if (!this.Configuration.FullScreen)
                {
                    previewWindow = new MMAL_RECT_T(
                        this.Configuration.PreviewWindow.X, this.Configuration.PreviewWindow.Y,
                        this.Configuration.PreviewWindow.Width, this.Configuration.PreviewWindow.Height);
                }

                displaySet  = (int)MMALParametersVideo.MMAL_DISPLAYSET_T.MMAL_DISPLAY_SET_LAYER;
                displaySet |= (int)MMALParametersVideo.MMAL_DISPLAYSET_T.MMAL_DISPLAY_SET_ALPHA;

                if (this.Configuration.FullScreen)
                {
                    displaySet |= (int)MMALParametersVideo.MMAL_DISPLAYSET_T.MMAL_DISPLAY_SET_FULLSCREEN;
                    fullScreen  = 1;
                }
                else
                {
                    displaySet |= (int)MMALParametersVideo.MMAL_DISPLAYSET_T.MMAL_DISPLAY_SET_DEST_RECT |
                                  (int)MMALParametersVideo.MMAL_DISPLAYSET_T.MMAL_DISPLAY_SET_FULLSCREEN;
                }

                if (this.Configuration.NoAspect)
                {
                    displaySet |= (int)MMALParametersVideo.MMAL_DISPLAYSET_T.MMAL_DISPLAY_SET_NOASPECT;
                    noAspect    = 1;
                }

                if (this.Configuration.CopyProtect)
                {
                    displaySet |= (int)MMALParametersVideo.MMAL_DISPLAYSET_T.MMAL_DISPLAY_SET_COPYPROTECT;
                    copyProtect = 1;
                }

                IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_DISPLAYREGION_T>());

                MMAL_DISPLAYREGION_T displayRegion = new MMAL_DISPLAYREGION_T(
                    new MMAL_PARAMETER_HEADER_T(
                        MMALParametersVideo.MMAL_PARAMETER_DISPLAYREGION,
                        Marshal.SizeOf <MMAL_DISPLAYREGION_T>()), displaySet, 0, fullScreen, this.Configuration.DisplayTransform, previewWindow ?? new MMAL_RECT_T(0, 0, 0, 0), new MMAL_RECT_T(0, 0, 0, 0), noAspect,
                    this.Configuration.DisplayMode, 0, 0, this.Configuration.Layer, copyProtect, this.Configuration.Opacity);

                Marshal.StructureToPtr(displayRegion, ptr, false);

                try
                {
                    MMALCheck(MMALPort.mmal_port_parameter_set(this.Inputs[0].Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), $"Unable to set preview renderer configuration");
                }
                finally
                {
                    Marshal.FreeHGlobal(ptr);
                }
            }
        }
 internal static void SetCameraConfig(this MMALCameraComponent camera, MMAL_PARAMETER_CAMERA_CONFIG_T value)
 {
     MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, &value.hdr), "Unable to set camera config.");
 }
示例#4
0
 /// <summary>
 /// Send a buffer header to a port.
 /// </summary>
 /// <param name="buffer"></param>
 internal void SendBuffer(MMALBufferImpl buffer)
 {
     MMALCheck(MMALPort.mmal_port_send_buffer(this.Ptr, buffer.Ptr), "Unable to send buffer header.");
 }
示例#5
0
        private void ConfigureRateControl(int outputPort)
        {
            MMAL_PARAMETER_VIDEO_RATECONTROL_T param = new MMAL_PARAMETER_VIDEO_RATECONTROL_T(new MMAL_PARAMETER_HEADER_T(MMALParametersVideo.MMAL_PARAMETER_RATECONTROL, Marshal.SizeOf <MMAL_PARAMETER_VIDEO_RATECONTROL_T>()), MMALCameraConfig.RateControl);

            MMALCheck(MMALPort.mmal_port_parameter_set(this.Outputs[outputPort].Ptr, param.HdrPtr), "Unable to set ratecontrol.");
        }
示例#6
0
 /// <summary>
 /// Ask a port to release all the buffer headers it currently has. This is an asynchronous operation and the
 /// flush call will return before all the buffer headers are returned to the client.
 /// </summary>
 internal void Flush()
 {
     MMALCheck(MMALPort.mmal_port_flush(this.Ptr), "Unable to flush port.");
 }
示例#7
0
 /// <summary>
 /// Commit format changes on this port.
 /// </summary>
 internal void Commit()
 {
     MMALCheck(MMALPort.mmal_port_format_commit(this.Ptr), "Unable to commit port changes.");
 }
        internal static void SetAnnotateSettings(this MMALCameraComponent camera)
        {
            if (MMALCameraConfig.Annotate != null)
            {
                MMALLog.Logger.LogDebug("Setting annotate");

                var sb = new StringBuilder();

                var showShutter           = 0;
                var showAnalogGain        = 0;
                var showLens              = 0;
                var showCaf               = 0;
                var showMotion            = 0;
                var showFrame             = 0;
                var enableTextBackground  = 0;
                var textSize              = (byte)0;
                var customTextColor       = 0;
                var customTextY           = (byte)0;
                var customTextU           = (byte)0;
                var customTextV           = (byte)0;
                var customBackgroundColor = 0;
                var customBackgroundY     = (byte)0;
                var customBackgroundU     = (byte)0;
                var customBackgroundV     = (byte)0;
                var justify               = MMALCameraConfig.Annotate.Justify;
                var xOffset               = MMALCameraConfig.Annotate.XOffset;
                var yOffset               = MMALCameraConfig.Annotate.YOffset;

                if (!string.IsNullOrEmpty(MMALCameraConfig.Annotate.CustomText))
                {
                    sb.Append(MMALCameraConfig.Annotate.CustomText + " ");
                }

                if (MMALCameraConfig.Annotate.ShowTimeText)
                {
                    sb.Append(DateTime.Now.ToString(MMALCameraConfig.Annotate.TimeFormat) + " ");
                }

                if (MMALCameraConfig.Annotate.ShowDateText)
                {
                    sb.Append(DateTime.Now.ToString(MMALCameraConfig.Annotate.DateFormat) + " ");
                }

                if (MMALCameraConfig.Annotate.ShowShutterSettings)
                {
                    showShutter = 1;
                }

                if (MMALCameraConfig.Annotate.ShowGainSettings)
                {
                    showAnalogGain = 1;
                }

                if (MMALCameraConfig.Annotate.ShowLensSettings)
                {
                    showLens = 1;
                }

                if (MMALCameraConfig.Annotate.ShowCafSettings)
                {
                    showCaf = 1;
                }

                if (MMALCameraConfig.Annotate.ShowMotionSettings)
                {
                    showMotion = 1;
                }

                if (MMALCameraConfig.Annotate.ShowFrameNumber)
                {
                    showFrame = 1;
                }

                if (MMALCameraConfig.Annotate.AllowCustomBackgroundColour)
                {
                    enableTextBackground = 1;
                }

                textSize = Convert.ToByte(MMALCameraConfig.Annotate.TextSize);

                if (MMALCameraConfig.Annotate.TextColour != Color.Empty)
                {
                    customTextColor = 1;

                    var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.TextColour);
                    customTextY = yuv.Item1;
                    customTextU = yuv.Item2;
                    customTextV = yuv.Item3;
                }

                if (MMALCameraConfig.Annotate.BgColour != Color.Empty)
                {
                    customBackgroundColor = 1;
                    var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.BgColour);
                    customBackgroundY = yuv.Item1;
                    customBackgroundU = yuv.Item2;
                    customBackgroundV = yuv.Item3;
                }

                // .NET Core has an issue with marshalling arrays "ByValArray". The array being passed MUST equal the size
                // specified in the "SizeConst" field or you will receive an exception. Mono does not have this restriction
                // and is quite happy to pass an array of a lower size if asked. In order to get around this, I am creating
                // an array equaling "SizeConst" and copying the contents of the annotation text into it, minus the EOL character.
                var text  = sb.ToString() + char.MinValue;
                var arr   = new byte[MMALParametersCamera.MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3];
                var bytes = Encoding.ASCII.GetBytes(text);

                Array.Copy(bytes, arr, bytes.Length);

                var strV4 = new MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T(
                    new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T>() + (arr.Length - 1)),
                    1, showShutter, showAnalogGain, showLens,
                    showCaf, showMotion, showFrame, enableTextBackground,
                    customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, 0, customTextColor,
                    customTextY, customTextU, customTextV, textSize, arr, (int)justify, xOffset, yOffset);

                var ptrV4 = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T>() + (arr.Length - 1));
                Marshal.StructureToPtr(strV4, ptrV4, false);

                try
                {
                    MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptrV4),
                              "Unable to set annotate");
                }
                catch
                {
                    Marshal.FreeHGlobal(ptrV4);
                    ptrV4 = IntPtr.Zero;

                    MMALLog.Logger.LogWarning("Unable to set V4 annotation structure. Trying V3. Please update firmware to latest version.");

                    var str = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T(
                        new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + (arr.Length - 1)),
                        1, showShutter, showAnalogGain, showLens,
                        showCaf, showMotion, showFrame, enableTextBackground,
                        customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, 0, customTextColor,
                        customTextY, customTextU, customTextV, textSize, arr);

                    var ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + (arr.Length - 1));
                    Marshal.StructureToPtr(str, ptr, false);

                    try
                    {
                        MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), "Unable to set annotate V3.");
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(ptr);
                    }
                }
                finally
                {
                    if (ptrV4 != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(ptrV4);
                    }
                }
            }
        }
        internal static void SetAnnotateSettings(this MMALCameraComponent camera)
        {
            if (MMALCameraConfig.Annotate != null)
            {
                MMALLog.Logger.Debug("Setting annotate");

                var sb = new StringBuilder();

                var showShutter           = 0;
                var showAnalogGain        = 0;
                var showLens              = 0;
                var showCaf               = 0;
                var showMotion            = 0;
                var showFrame             = 0;
                var enableTextBackground  = 0;
                var textSize              = (byte)0;
                var customTextColor       = 0;
                var customTextY           = (byte)0;
                var customTextU           = (byte)0;
                var customTextV           = (byte)0;
                var customBackgroundColor = 0;
                var customBackgroundY     = (byte)0;
                var customBackgroundU     = (byte)0;
                var customBackgroundV     = (byte)0;

                if (!string.IsNullOrEmpty(MMALCameraConfig.Annotate.CustomText))
                {
                    sb.Append(MMALCameraConfig.Annotate.CustomText + " ");
                }

                if (MMALCameraConfig.Annotate.ShowTimeText)
                {
                    sb.Append(DateTime.Now.ToString("HH:mm") + " ");
                }

                if (MMALCameraConfig.Annotate.ShowDateText)
                {
                    sb.Append(DateTime.Now.ToString("dd/MM/yyyy") + " ");
                }

                if (MMALCameraConfig.Annotate.ShowShutterSettings)
                {
                    showShutter = 1;
                }

                if (MMALCameraConfig.Annotate.ShowGainSettings)
                {
                    showAnalogGain = 1;
                }

                if (MMALCameraConfig.Annotate.ShowLensSettings)
                {
                    showLens = 1;
                }

                if (MMALCameraConfig.Annotate.ShowCafSettings)
                {
                    showCaf = 1;
                }

                if (MMALCameraConfig.Annotate.ShowMotionSettings)
                {
                    showMotion = 1;
                }

                if (MMALCameraConfig.Annotate.ShowFrameNumber)
                {
                    showFrame = 1;
                }

                if (MMALCameraConfig.Annotate.ShowBlackBackground)
                {
                    enableTextBackground = 1;
                }

                textSize = Convert.ToByte(MMALCameraConfig.Annotate.TextSize);

                if (MMALCameraConfig.Annotate.TextColour != Color.Empty)
                {
                    customTextColor = 1;

                    var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.TextColour);
                    customTextY = yuv.Item1;
                    customTextU = yuv.Item2;
                    customTextV = yuv.Item3;
                }

                if (MMALCameraConfig.Annotate.BgColour != Color.Empty)
                {
                    customBackgroundColor = 1;
                    var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.BgColour);
                    customBackgroundY = yuv.Item1;
                    customBackgroundU = yuv.Item2;
                    customBackgroundV = yuv.Item3;
                }

                string t = sb.ToString() + char.MinValue;

                var text = Encoding.ASCII.GetBytes(t);

                var str = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T(
                    new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + t.Length),
                    1, showShutter, showAnalogGain, showLens,
                    showCaf, showMotion, showFrame, enableTextBackground,
                    customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, 0, customTextColor,
                    customTextY, customTextU, customTextV, textSize, text);

                var ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>());
                Marshal.StructureToPtr(str, ptr, false);

                try
                {
                    MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), "Unable to set annotate");
                }
                finally
                {
                    Marshal.FreeHGlobal(ptr);
                }
            }
        }
        /// <summary>
        /// Annotates the image with various text as specified in the MMALCameraConfig class.
        /// </summary>
        internal unsafe void AnnotateImage()
        {
            if (MMALCameraConfig.Annotate != null)
            {
                MMALLog.Logger.Debug("Setting annotate");

                var sb = new StringBuilder();

                var showShutter           = 0;
                var showAnalogGain        = 0;
                var showLens              = 0;
                var showCaf               = 0;
                var showMotion            = 0;
                var showFrame             = 0;
                var enableTextBackground  = 0;
                var textSize              = (byte)0;
                var customTextColor       = 0;
                var customTextY           = (byte)0;
                var customTextU           = (byte)0;
                var customTextV           = (byte)0;
                var customBackgroundColor = 0;
                var customBackgroundY     = (byte)0;
                var customBackgroundU     = (byte)0;
                var customBackgroundV     = (byte)0;

                if (!string.IsNullOrEmpty(MMALCameraConfig.Annotate.CustomText))
                {
                    sb.Append(MMALCameraConfig.Annotate.CustomText + " ");
                }

                if (MMALCameraConfig.Annotate.ShowTimeText)
                {
                    sb.Append(DateTime.Now.ToString("HH:mm") + " ");
                }

                if (MMALCameraConfig.Annotate.ShowDateText)
                {
                    sb.Append(DateTime.Now.ToString("dd/MM/yyyy") + " ");
                }

                if (MMALCameraConfig.Annotate.ShowShutterSettings)
                {
                    showShutter = 1;
                }

                if (MMALCameraConfig.Annotate.ShowGainSettings)
                {
                    showAnalogGain = 1;
                }

                if (MMALCameraConfig.Annotate.ShowLensSettings)
                {
                    showLens = 1;
                }

                if (MMALCameraConfig.Annotate.ShowCafSettings)
                {
                    showCaf = 1;
                }

                if (MMALCameraConfig.Annotate.ShowMotionSettings)
                {
                    showMotion = 1;
                }

                if (MMALCameraConfig.Annotate.ShowFrameNumber)
                {
                    showFrame = 1;
                }

                if (MMALCameraConfig.Annotate.ShowBlackBackground)
                {
                    enableTextBackground = 1;
                }

                textSize = System.Convert.ToByte(MMALCameraConfig.Annotate.TextSize);

                if (MMALCameraConfig.Annotate.TextColour != -1)
                {
                    customTextColor = 1;
                    customTextY     = System.Convert.ToByte((MMALCameraConfig.Annotate.TextColour & 0xff));
                    customTextU     = System.Convert.ToByte(((MMALCameraConfig.Annotate.TextColour >> 8) & 0xff));
                    customTextV     = System.Convert.ToByte(((MMALCameraConfig.Annotate.TextColour >> 16) & 0xff));
                }

                if (MMALCameraConfig.Annotate.BgColour != -1)
                {
                    customBackgroundColor = 1;
                    customBackgroundY     = System.Convert.ToByte((MMALCameraConfig.Annotate.BgColour & 0xff));
                    customBackgroundU     = System.Convert.ToByte(((MMALCameraConfig.Annotate.BgColour >> 8) & 0xff));
                    customBackgroundV     = System.Convert.ToByte(((MMALCameraConfig.Annotate.BgColour >> 16) & 0xff));
                }

                string t = sb.ToString() + char.MinValue;

                var text = Encoding.ASCII.GetBytes(t);

                var str = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T(new MMAL_PARAMETER_HEADER_T(MMALParametersCamera.MMAL_PARAMETER_ANNOTATE, (Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + (t.Length))),
                                                                  1, showShutter, showAnalogGain, showLens,
                                                                  showCaf, showMotion, showFrame, enableTextBackground,
                                                                  customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, (byte)0, customTextColor,
                                                                  customTextY, customTextU, customTextV, textSize, text);

                var ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>());
                Marshal.StructureToPtr(str, ptr, false);

                MMALCheck(MMALPort.mmal_port_parameter_set(MMALCamera.Instance.Camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), "Unable to set annotate");

                Marshal.FreeHGlobal(ptr);
            }
        }