virtual public void Close()
        {
            if (_component != null)
            {
                //# ensure we free any pools associated with input/output ports
                foreach (var output in Outputs)
                {
                    output.Disable();
                }
                foreach (var input in Inputs)
                {
                    input.Disable();
                }

                MMal.MMAL_STATUS_T status = MMal.mmal_component_destroy(_component);
                if (status != MMal.MMAL_STATUS_T.MMAL_SUCCESS)
                {
                    throw new Exception(String.Format("Unable to destroy component {0}, status {1}. Is it enabled ?", ComponentType, status));
                }

                _component = null;

                Inputs  = null;
                Outputs = null;
                Control = null;
            }
        }
示例#2
0
        //Get the next buffer from the queue.If* block* is ``True`` (the default)
        //and* timeout* is ``None`` (the default) then the method will block
        //until a buffer is available.Otherwise* timeout* is the maximum time to
        //wait(in seconds) for a buffer to become available.If a buffer is not
        //available before the timeout expires, the method returns ``None``.
        //Likewise, if *block* is ``False`` and no buffer is immediately
        //available then ``None`` is returned.
        public MMalBuffer Get(bool block = true, int timeout = 0)
        {
            MMal.MMAL_BUFFER_HEADER_T *buf = null;

            if (block && timeout == 0)
            {
                buf = MMal.mmal_queue_wait(_queue);
            }

            else if (block && timeout != 0)
            {
                buf = MMal.mmal_queue_timedwait(_queue, (uint)(timeout * 1000));
            }
            else
            {
                buf = MMal.mmal_queue_get(_queue);
            }

            if (buf != null)
            {
                return(new MMalBuffer(buf));
            }
            else
            {
                return(null);
            }
        }
示例#3
0
 public void SetParam(MMal.MMAL_PARAMETER_IDS value, bool param)
 {
     MMal.MMAL_STATUS_T status = MMal.mmal_port_parameter_set_boolean(_port, (uint)value, param ? 1 : 0);
     if (status != MMal.MMAL_STATUS_T.MMAL_SUCCESS)
     {
         throw new Exception(String.Format("Could not set parameter {0}, value {1}: error {2}", value, param, status));
     }
 }
示例#4
0
 public void Close()
 {
     if (_created)
     {
         MMal.mmal_queue_destroy(_queue);
     }
     _queue = null;
 }
示例#5
0
 public virtual void Close()
 {
     if (_pool != null)
     {
         MMal.mmal_pool_destroy(_pool);
     }
     _pool = null;
 }
 // Disables the component.
 public void Disable()
 {
     MMal.MMAL_STATUS_T status = MMal.mmal_component_disable(_component);
     if (status != MMal.MMAL_STATUS_T.MMAL_SUCCESS)
     {
         throw new Exception(String.Format("Unable to disable component {0}, status {1}. Is it enabled ?", ComponentType, status));
     }
 }
示例#7
0
 public MMalPortPool(MMalPort port)
 {
     MMal.MMAL_POOL_T *pool = MMal.mmal_port_pool_create(port.Pointer, port.Pointer->buffer_num, port.Pointer->buffer_size);
     if (pool == null)
     {
         throw new Exception(String.Format("failed to create buffer header pool for port {0}", port.Name));
     }
     Port = port;
     base.Initialize(pool);
 }
示例#8
0
 public virtual void Enable(UserCallback callback = null)
 {
     if (_logger.IsDebugEnabled)
     {
         _logger.Debug("Enabling port : {0}", Name);
     }
     MMal.MMAL_STATUS_T status = MMal.mmal_port_enable(_port, null);
     if (status != MMal.MMAL_STATUS_T.MMAL_SUCCESS)
     {
         throw new Exception(String.Format("Unable to enable port {0} : {1}", Name, status));
     }
 }
示例#9
0
        public virtual void SendAllBuffers(MMalPort port = null, bool block = true, int timeout = 0)
        {
            int num = (int)MMal.mmal_queue_length(_pool->queue);

            if (num == 0)
            {
                throw new Exception("Pool queue is empty");
            }
            for (int i = 0; i < num; i++)
            {
                SendBuffer(port, block, timeout);
            }
        }
示例#10
0
        public virtual void Disable()
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Disabling port : {0}", Name);
            }

            if (Enabled)
            {
                MMal.MMAL_STATUS_T status = MMal.mmal_port_disable(_port);
                if (status != MMal.MMAL_STATUS_T.MMAL_SUCCESS)
                {
                    throw new Exception(String.Format("Unable to disable port {0} : {1}", Name, status));
                }
            }
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Port disabled : {0}", Name);
            }
        }
示例#11
0
        /// <summary>
        /// Default settings used:
        ///	bitrate=17000000, intra_period=None, profile='high',
        ///	level='4', quantization=0, quality=0, inline_headers=True,
        /// sei=False, sps_timing=False, motion_output=None,
        ///	intra_refresh=None
        //	Max bitrate we allow for recording
        /// </summary>

        public unsafe override void CreateEncoder(ImageFormat format, int resize, params string[] options)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("CreateEncoder {0}", format);
            }


            int  bitrate       = 17000000;
            bool inlineHeaders = true;
            bool sei           = false;
            bool sps_timing    = false;
            int  quality       = 23;


            uint mmalFormat;

            if (format == ImageFormat.h264)
            {
                mmalFormat = MMal.MMAL_ENCODING_H264;
            }
            else if (format == ImageFormat.mpeg)
            {
                mmalFormat = MMal.MMAL_ENCODING_MJPEG;
            }
            else
            {
                throw new Exception(String.Format("Invalid video format {0}", format));
            }

            _outputPort.Format = (uint)mmalFormat;

            if (format == ImageFormat.h264)
            {
                //MMal.MMAL_VIDEO_PROFILE_T _profile = MMal.MMAL_VIDEO_PROFILE_T.MMAL_VIDEO_PROFILE_H264_HIGH;
                //MMal.MMAL_VIDEO_LEVEL_T _level = MMal.MMAL_VIDEO_LEVEL_T.MMAL_VIDEO_LEVEL_H264_4;
                MMal.MMAL_VIDEO_PROFILE_T profile = GetProfile(options);
                MMal.MMAL_VIDEO_LEVEL_T   level   = GetLevel(options);

                MMal.MMAL_PARAMETER_VIDEO_PROFILE_T param = new MMal.MMAL_PARAMETER_VIDEO_PROFILE_T();
                param.hdr.id          = (uint)MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_PROFILE;
                param.hdr.size        = (uint)Marshal.SizeOf(param);
                param.profile         = new MMal.VIDEO_PROFILE();
                param.profile.profile = profile;
                param.profile.level   = level;

                MMal.MMAL_STATUS_T status = MMal.mmal_port_parameter_set(_outputPort.Pointer, &param.hdr);
                if (status != MMal.MMAL_STATUS_T.MMAL_SUCCESS)
                {
                    throw new Exception(String.Format("Cannot set parameter on port {0} {1}", _outputPort.Name, status));
                }

                bitrate = GetBitrate(level, bitrate, options);
                // We need to set the frame rate on output to 0, to ensure it gets
                // updated correctly from the input framerate when port connected
                _outputPort.Framerate = (0, 1);

                _outputPort.BitRate = (uint)bitrate;
                _outputPort.Commit();
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Port Commited");
                }

                if (inlineHeaders)
                {
                    _outputPort.SetParam(MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER, true);
                }
                if (sei)
                {
                    _outputPort.SetParam(MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_VIDEO_ENCODE_SEI_ENABLE, true);
                }
                if (sps_timing)
                {
                    _outputPort.SetParam(MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_VIDEO_ENCODE_SPS_TIMING, true);
                }

                // other H264 parameters must be set here
            }
            else
            {
                _outputPort.BitRate = 1;
                _outputPort.Commit();
            }
            if (quality != 0)
            {
                _outputPort.SetParam(MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT, quality);
                _outputPort.SetParam(MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT, quality);
                _outputPort.SetParam(MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT, quality);
            }

            Encoder.Inputs[0].SetParam(MMal.MMAL_PARAMETER_IDS.MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT, true);
            Encoder.Enable();

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("PiVideoEncoder.CreateEncoder done Output port {0}", _outputPort.ToString());
            }

            base.CreateEncoder(format, resize, options);
        }
示例#12
0
 public void Create()
 {
     MMal.mmal_queue_create();
     _created = true;
 }
示例#13
0
 public void Unlock()
 {
     MMal.mmal_buffer_header_mem_unlock(_buf);
 }
示例#14
0
 public void Lock()
 {
     MMal.mmal_buffer_header_mem_lock(_buf);
 }
示例#15
0
 //def release(self):
 //Release a reference to the buffer.This is the opposing call to
 //:meth:`acquire`. Once all references have been released, the buffer
 //will be recycled.
 public void Release()
 {
     MMal.mmal_buffer_header_release(_buf);
 }
        public MMalBaseComponent()
        {
            //	mmal_check(
            //	mmal.mmal_component_create(self.component_type, self._component),
            //	prefix = "Failed to create MMAL component %s" % self.component_type)

            //if self._component[0].input_num != len(self.opaque_input_subformats):
            //          raise PiCameraRuntimeError(

            //		'Expected %d inputs but found %d on component %s' % (
            //			len(self.opaque_input_subformats),
            //			self._component[0].input_num,
            //			self.component_type))
            //      if self._component[0].output_num != len(self.opaque_output_subformats):
            //          raise PiCameraRuntimeError(

            //		'Expected %d outputs but found %d on component %s' % (
            //			len(self.opaque_output_subformats),
            //			self._component[0].output_num,
            //			self.component_type))
            MMal.MMAL_STATUS_T     status;
            MMal.MMAL_COMPONENT_T *component = null;

            status = MMal.mmal_component_create(ComponentType, &component);
            if (status != MMal.MMAL_STATUS_T.MMAL_SUCCESS)
            {
                throw new Exception(String.Format("Unable to create component {0}, status {1}. Is it enabled ?", ComponentType, status));
            }
            _component = component;
#if !_WIN32_
            if (_component->input_num != OpaqueInputSubformats.Length)
            {
                throw new Exception(String.Format("Expected {0} inputs but found {1} on component {2}",
                                                  OpaqueInputSubformats.Length,
                                                  _component->input_num,
                                                  ComponentType));
            }
            if (_component->output_num != OpaqueOutputSubformats.Length)
            {
                throw new Exception(String.Format("Expected {0} outputs but found {1} on component {2}",
                                                  OpaqueOutputSubformats.Length,
                                                  _component->output_num,
                                                  ComponentType));
            }
#endif
            Control = new MMalControlPort(_component->control);

            MMal.MMAL_PORT_T **ports = _component->output;
            Outputs = CreatePorts(ports, _component->output_num, OpaqueOutputSubformats);
            ports   = _component->input;
            Inputs  = CreatePorts(ports, _component->input_num, OpaqueInputSubformats);

            //port_class = {
            //	mmal.MMAL_ES_TYPE_UNKNOWN:    MMALPort,
            //         mmal.MMAL_ES_TYPE_CONTROL:    MMALControlPort,
            //         mmal.MMAL_ES_TYPE_VIDEO:      MMALVideoPort,
            //         mmal.MMAL_ES_TYPE_AUDIO:      MMALAudioPort,
            //         mmal.MMAL_ES_TYPE_SUBPICTURE: MMALSubPicturePort,
            //         }
            //self._inputs = tuple(
            //	port_class[self._component[0].input[n][0].format[0].type](
            //		self._component[0].input[n], opaque_subformat)

            //for n, opaque_subformat in enumerate(self.opaque_input_subformats))
            //	self._outputs = tuple(
            //		port_class[self._component[0].output[n][0].format[0].type](
            //			self._component[0].output[n], opaque_subformat)

            //for n, opaque_subformat in enumerate(self.opaque_output_subformats))


            //Outputs = new MMalPort[_component->output_num];
            //MMal.MMAL_PORT_T** ports = _component->output;
            //for (int i = 0; i < _component->output_num; i++)
            //	Outputs[i] = new MMalPort(ports[i]);

            //Inputs = new MMalPort[_component->input_num];
            //ports = _component->input;
            //for (int i = 0; i < _component->input_num; i++)
            //	Inputs[i] = new MMalPort(ports[i]);
        }