/// <summary> /// Disable processing on a component /// </summary> public void Disable() { var status = MmalNativeMethods.ComponentDisable(this.m_handle); if (status != MMAL_STATUS_T.MMAL_SUCCESS) { throw new MMALException(status); } }
private /*MMAL_COMPONENT_T*/ IntPtr CreateComponentHandle(MMALComponentName componentName) { Console.WriteLine("Creating component " + componentName.Value); //var status = MmalNativeMethods.ComponentCreate(componentName.Value, out MMAL_COMPONENT_T handle); //if (status != MMAL_STATUS_T.MMAL_SUCCESS) // throw new MMALException(status); //handle.DumpFields(); //return handle; var status = MmalNativeMethods.ComponentCreate(componentName.Value, out IntPtr handle); if (status != MMAL_STATUS_T.MMAL_SUCCESS) { throw new MMALException(status); } return(handle); //Console.WriteLine($"Ptr={handle}"); //for (int i = 1; i <= 100; i++) //{ // byte b = Marshal.ReadByte(handle, i - 1); // Console.Write("{0:X2} ", b); // if (i % 16 == 0) // Console.WriteLine(); // else if (i % 8 == 0) // Console.Write(" "); //} //IntPtr namePtr = Marshal.ReadIntPtr(handle, Marshal.SizeOf<IntPtr>() * 2); //Console.WriteLine($"namePtr={namePtr}"); //string name = Marshal.PtrToStringAnsi(namePtr); //Console.WriteLine($"name={name}"); //MMAL_COMPONENT_T comp = Marshal.PtrToStructure<MMAL_COMPONENT_T>(handle); //comp.DumpFields(); ////throw new NotImplementedException(); //return comp; }
public CameraInfo GetCameraInfo(int cameraNum) { if (this.m_infoCache.ContainsKey(cameraNum)) { return(this.m_infoCache[cameraNum]); } MMAL_PARAMETER_CAMERA_INFO_T param = new MMAL_PARAMETER_CAMERA_INFO_T(); param.hdr = new MMAL_PARAMETER_HEADER_T(); param.hdr.id = MMALParameterId.MMAL_PARAMETER_CAMERA_INFO; //param.hdr.size = (uint)(Marshal.SizeOf<MMAL_PARAMETER_CAMERA_INFO_T>(param) - 4); // Deliberately undersize to check firmware veresion param.hdr.size = 152 - 4; MMAL_STATUS_T status = MmalNativeMethods.PortParameterGet(this.Handle.control, param.hdr); CameraInfo info = new CameraInfo(); if (status != MMAL_STATUS_T.MMAL_SUCCESS) { // Running on newer firmware //param.hdr.size = (uint)(Marshal.SizeOf<MMAL_PARAMETER_CAMERA_INFO_T>(param)); param.hdr.size = 152; status = MmalNativeMethods.PortParameterGet(this.Handle.control, param.hdr); if (status == MMAL_STATUS_T.MMAL_SUCCESS && param.num_cameras > cameraNum) { info.Width = param.cameras[cameraNum].max_width; info.Height = param.cameras[cameraNum].max_height; info.Name = param.cameras[cameraNum].camera_name; info.DumpProperties(); } else { Console.WriteLine($"Cannot read camera info, keeping the defaults for OV5647. status={status} param.num_cameras={param.num_cameras}"); //vcos_log_error("Cannot read camera info, keeping the defaults for OV5647"); } } else { // Older firmware // Nothing to do here, keep the defaults for OV5647 Console.WriteLine("Older firmware, keeping the defaults for OV5647"); } //Assume defaults if (string.IsNullOrEmpty(info.Name)) { info.Name = "OV5647"; } if (info.Width == 0) { info.Width = 2592; } if (info.Height == 0) { info.Height = 1944; } this.m_infoCache.Add(cameraNum, info); return(info); }
/// <summary> /// Destroy a previously created component /// Release an acquired reference on a component. Only actually destroys the component when /// the last reference is being released. /// </summary> public void Dispose() { MmalNativeMethods.ComponentDestroy(this.m_handle); }
/// <summary> /// Acquire a reference on a component. /// Acquiring a reference on a component will prevent a component from being destroyed until /// the acquired reference is released(by a call to Dispose). /// References are internally counted so all acquired references need a matching call to /// release them. /// </summary> public void Acquire() { MmalNativeMethods.ComponentAcquire(this.m_handle); }