예제 #1
0
        public MMALPoolImpl(MMALPortBase port)
        {
            MMALLog.Logger.Debug($"Creating buffer pool with {port.BufferNum} buffers of size {port.BufferSize}");

            this.Ptr   = MMALUtil.mmal_port_pool_create(port.Ptr, port.BufferNum, port.BufferSize);
            this.Queue = new MMALQueueImpl((*this.Ptr).Queue);
        }
예제 #2
0
        /// <summary>
        /// Enable the port specified.
        /// </summary>
        /// <param name="port">The output port.</param>
        internal void Start(MMALPortBase port)
        {
            switch (port.PortType)
            {
            case PortType.Input:
                port.EnableInputPort();
                break;

            case PortType.Output:
                if (this.Handler != null && this.Handler.GetType().GetTypeInfo().IsSubclassOf(typeof(FileStreamCaptureHandler)))
                {
                    ((FileStreamCaptureHandler)this.Handler).NewFile();
                }
                port.EnableOutputPort();
                break;

            case PortType.Control:
                port.EnableControlPort();
                break;

            default:
                port.EnableOutputPort();
                break;
            }
        }
예제 #3
0
        /// <summary>
        /// Facility to create a connection between two port objects
        /// </summary>
        /// <param name="output">The output port of the connection</param>
        /// <param name="input">The input port of the connection</param>
        /// <returns></returns>
        internal static MMALConnectionImpl CreateConnection(MMALPortBase output, MMALPortBase input, MMALDownstreamComponent inputComponent)
        {
            IntPtr ptr = IntPtr.Zero;

            MMALCheck(MMALConnection.mmal_connection_create(&ptr, output.Ptr, input.Ptr, MMALConnection.MMAL_CONNECTION_FLAG_TUNNELLING | MMALConnection.MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT), "Unable to create connection");

            return(new MMALConnectionImpl((MMAL_CONNECTION_T *)ptr, output, input, inputComponent, output.ComponentReference));
        }
        /// <summary>
        /// Enable the port specified.
        /// </summary>
        /// <param name="port">The output port</param>
        /// <param name="managedCallback">The managed method to callback to from the native callback</param>
        internal void Start(MMALPortBase port, Action <MMALBufferImpl, MMALPortBase> managedCallback)
        {
            if (this.Handler != null && this.Handler.GetType().GetTypeInfo().IsSubclassOf(typeof(StreamCaptureHandler)))
            {
                ((StreamCaptureHandler)this.Handler).NewFile();
            }

            port.EnablePort(managedCallback);
        }
예제 #5
0
 protected MMALConnectionImpl(MMAL_CONNECTION_T *ptr, MMALPortBase output, MMALPortBase input, MMALDownstreamComponent inputComponent, MMALComponentBase outputComponent)
 {
     this.Ptr                 = ptr;
     this.OutputPort          = output;
     this.InputPort           = input;
     this.DownstreamComponent = inputComponent;
     this.UpstreamComponent   = outputComponent;
     this.Enable();
 }
예제 #6
0
        /// <summary>
        /// Provides a facility to get data from the port using the native helper functions.
        /// </summary>
        /// <param name="port">The port to get the parameter from.</param>
        /// <param name="key">The unique key for the parameter.</param>
        /// <returns>Dynamic parameter based on key parameter.</returns>
        public static unsafe dynamic GetParameter(this MMALPortBase port, int key)
        {
            var t = MMALParameterHelpers.ParameterHelper.Where(c => c.ParamValue == key).FirstOrDefault();

            if (t == null)
            {
                throw new PiCameraError($"Could not find parameter {key}");
            }

            MMALLog.Logger.Debug($"Getting parameter {t.ParamName}");

            try
            {
                switch (t.ParamType.Name)
                {
                case "MMAL_PARAMETER_BOOLEAN_T":
                    int boolVal = 0;
                    MMALCheck(MMALUtil.mmal_port_parameter_get_boolean(port.Ptr, (uint)key, ref boolVal), "Unable to get boolean value");
                    return(boolVal == 1);

                case "MMAL_PARAMETER_UINT64_T":
                    ulong ulongVal = 0UL;
                    MMALCheck(MMALUtil.mmal_port_parameter_get_uint64(port.Ptr, (uint)key, ref ulongVal), "Unable to get ulong value");
                    return(ulongVal);

                case "MMAL_PARAMETER_INT64_T":
                    long longVal = 0U;
                    MMALCheck(MMALUtil.mmal_port_parameter_get_int64(port.Ptr, (uint)key, ref longVal), "Unable to get long value");
                    return(longVal);

                case "MMAL_PARAMETER_UINT32_T":
                    uint uintVal = 0U;
                    MMALCheck(MMALUtil.mmal_port_parameter_get_uint32(port.Ptr, (uint)key, ref uintVal), "Unable to get uint value");
                    return(uintVal);

                case "MMAL_PARAMETER_INT32_T":
                    int intVal = 0;
                    MMALCheck(MMALUtil.mmal_port_parameter_get_int32(port.Ptr, (uint)key, ref intVal), "Unable to get int value");
                    return(intVal);

                case "MMAL_PARAMETER_RATIONAL_T":
                    MMAL_RATIONAL_T ratVal = default(MMAL_RATIONAL_T);
                    MMALCheck(MMALUtil.mmal_port_parameter_get_rational(port.Ptr, (uint)key, ref ratVal), "Unable to get rational value");
                    return((double)ratVal.Num / ratVal.Den);

                default:
                    throw new NotSupportedException();
                }
            }
            catch
            {
                MMALLog.Logger.Warn($"Unable to get port parameter {t.ParamName}");
                throw;
            }
        }
        /// <summary>
        /// Provides a facility to set data on the port using the native helper functions
        /// </summary>
        /// <param name="port">The port we want to set the parameter on</param>
        /// <param name="key">The unique key of the parameter</param>
        /// <param name="value">The value of the parameter</param>
        public static unsafe void SetParameter(this MMALPortBase port, int key, dynamic value)
        {
            var t = MMALParameterHelpers.ParameterHelper.Where(c => c.ParamValue == key).FirstOrDefault();

            if (t == null)
            {
                throw new PiCameraError($"Could not find parameter {key}");
            }

            MMALLog.Logger.Debug($"Setting parameter {t.ParamName}");

            try
            {
                switch (t.ParamType.Name)
                {
                case "MMAL_PARAMETER_BOOLEAN_T":
                    int i = (bool)value ? 1 : 0;
                    MMALCheck(MMALUtil.mmal_port_parameter_set_boolean(port.Ptr, (uint)key, i), "Unable to set boolean value");
                    break;

                case "MMAL_PARAMETER_UINT64_T":
                    MMALCheck(MMALUtil.mmal_port_parameter_set_uint64(port.Ptr, (uint)key, (ulong)value), "Unable to set ulong value");
                    break;

                case "MMAL_PARAMETER_INT64_T":
                    MMALCheck(MMALUtil.mmal_port_parameter_set_int64(port.Ptr, (uint)key, (long)value), "Unable to set long value");
                    break;

                case "MMAL_PARAMETER_UINT32_T":
                    MMALCheck(MMALUtil.mmal_port_parameter_set_uint32(port.Ptr, (uint)key, (uint)value), "Unable to set uint value");
                    break;

                case "MMAL_PARAMETER_INT32_T":
                    MMALCheck(MMALUtil.mmal_port_parameter_set_int32(port.Ptr, (uint)key, (int)value), "Unable to set int value");
                    break;

                case "MMAL_PARAMETER_RATIONAL_T":
                    MMALCheck(MMALUtil.mmal_port_parameter_set_rational(port.Ptr, (uint)key, (MMAL_RATIONAL_T)value), "Unable to set rational value");
                    break;

                case "MMAL_PARAMETER_STRING_T":
                    MMALCheck(MMALUtil.mmal_port_parameter_set_string(port.Ptr, (uint)key, (string)value), "Unable to set rational value");
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            catch
            {
                MMALLog.Logger.Warn($"Unable to set port parameter {t.ParamName}");
                throw;
            }
        }
예제 #8
0
        private void ConfigureConnectionCallback(MMALPortBase output, MMALPortBase input)
        {
            output.SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);
            input.SetParameter(MMALParametersCommon.MMAL_PARAMETER_ZERO_COPY, true);

            this.NativeCallback = new MMALConnection.MMAL_CONNECTION_CALLBACK_T(this.NativeConnectionCallback);
            IntPtr ptrCallback = Marshal.GetFunctionPointerForDelegate(this.NativeCallback);

            this.Ptr->Callback = ptrCallback;

            this.ConnectionPool = new MMALPoolImpl(this.Ptr->Pool);
        }
예제 #9
0
        protected MMALConnectionImpl(MMAL_CONNECTION_T *ptr, MMALPortBase output, MMALPortBase input, MMALDownstreamComponent inputComponent, MMALComponentBase outputComponent, bool useCallback)
        {
            this.Ptr                 = ptr;
            this.OutputPort          = output;
            this.InputPort           = input;
            this.DownstreamComponent = inputComponent;
            this.UpstreamComponent   = outputComponent;

            if (useCallback)
            {
                this.ConfigureConnectionCallback(output, input);
            }

            this.Enable();

            if (useCallback)
            {
                this.OutputPort.SendAllBuffers(this.ConnectionPool);
            }
        }
 /// <summary>
 /// Disable the specified port
 /// </summary>
 /// <param name="port">The output port</param>
 internal void Stop(MMALPortBase port)
 {
     port.DisablePort();
 }
 /// <summary>
 /// Enable the port specified.
 /// </summary>
 /// <param name="port">The output port</param>
 /// <param name="managedCallback">The managed method to callback to from the native callback</param>
 internal void Start(MMALPortBase port, Func <MMALBufferImpl, MMALPortBase, ProcessResult> managedCallback)
 {
     port.EnablePort(managedCallback);
 }
        /// <summary>
        /// Delegate to process the buffer header containing image data
        /// </summary>
        /// <param name="buffer">The current buffer header being processed</param>
        /// <param name="port">The port we're currently processing on</param>
        public virtual void ManagedOutputCallback(MMALBufferImpl buffer, MMALPortBase port)
        {
            var data = buffer.GetBufferData();

            this.Handler?.Process(data);
        }
 /// <summary>
 /// Delegate to process the buffer header containing image data
 /// </summary>
 /// <param name="buffer">The current buffer header being processed</param>
 /// <param name="port">The port we're currently processing on</param>
 public virtual ProcessResult ManagedInputCallback(MMALBufferImpl buffer, MMALPortBase port)
 {
     return(this.Handler?.Process());
 }
예제 #14
0
 /// <summary>
 /// Fully copy a format structure, including the extradata buffer.
 /// </summary>
 /// <param name="destination">The destination port we're copying to</param>
 internal void FullCopy(MMALPortBase destination)
 {
     MMALFormat.mmal_format_full_copy(destination.Ptr->Format, this.Ptr->Format);
 }
예제 #15
0
 /// <summary>
 /// Shallow copy a format structure. It is worth noting that the extradata buffer will not be copied in the new format.
 /// </summary>
 /// <param name="destination">The destination port we're copying to</param>
 internal void ShallowCopy(MMALPortBase destination)
 {
     MMALFormat.mmal_format_copy(destination.Ptr->Format, this.Ptr->Format);
 }