/// <summary> /// Update the MLCamera characteristics. /// </summary> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if obtained camera characteristic handle successfully. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed to obtain camera characteristic handle due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.MediaGenericUnexpectedNull</c> if failed to capture raw image due to null pointer. /// MLResult.Result will be <c>MLResult.Code.AllocFailed</c> if failed to allocate memory. /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if a required permission is missing. /// </returns> internal MLResult PopulateCharacteristics() { MLResult.Code resultCode; ulong cameraCharacteristicsHandle = MagicLeapNativeBindings.InvalidHandle; resultCode = MLCameraNativeBindings.MLCameraGetCameraCharacteristics(ref cameraCharacteristicsHandle); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get camera characteristics for MLCamera. Reason: {0}", result); return(result); } ulong controlAEModeCount = 0; IntPtr controlAEAvailableModesData = IntPtr.Zero; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAEAvailableModes(cameraCharacteristicsHandle, ref controlAEAvailableModesData, ref controlAEModeCount); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get camera control AE available modes for MLCamera. Reason: {0}", result); return(result); } this.ControlAEModesAvailable = new List <MLCamera.MetadataControlAEMode>(); int[] controlAEModeArray = new int[controlAEModeCount]; Marshal.Copy(controlAEAvailableModesData, controlAEModeArray, 0, (int)controlAEModeCount); for (int i = 0; i < controlAEModeArray.Length; ++i) { this.ControlAEModesAvailable.Add((MLCamera.MetadataControlAEMode)controlAEModeArray[i]); } ulong colorCorrectionAberrationModeCount = 0; IntPtr colorCorrectionAberrationModesData = IntPtr.Zero; resultCode = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionAvailableAberrationModes(cameraCharacteristicsHandle, ref colorCorrectionAberrationModesData, ref colorCorrectionAberrationModeCount); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get color correction aberration modes available for MLCamera. Reason: {0}", result); return(result); } this.ColorCorrectionAberrationModesAvailable = new List <MLCamera.MetadataColorCorrectionAberrationMode>((int)colorCorrectionAberrationModeCount); int[] aberrationModeArray = new int[colorCorrectionAberrationModeCount]; Marshal.Copy(colorCorrectionAberrationModesData, aberrationModeArray, 0, (int)colorCorrectionAberrationModeCount); for (int i = 0; i < aberrationModeArray.Length; ++i) { this.ColorCorrectionAberrationModesAvailable.Add((MLCamera.MetadataColorCorrectionAberrationMode)aberrationModeArray[i]); } int[] compensationRange = new int[2]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAECompensationRange(cameraCharacteristicsHandle, compensationRange); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get control AE compensation range. Reason: {0}", result); return(result); } this.AECompensationRange = new AECompensationRangeValues(compensationRange[0], compensationRange[1]); MLCameraNativeBindings.MLCameraMetadataRationalNative rational = new MLCameraNativeBindings.MLCameraMetadataRationalNative(); resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAECompensationStep(cameraCharacteristicsHandle, ref rational); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get control AE compensation step. Reason: {0}", result); return(result); } this.AECompensationStepNumerator = rational.Numerator; this.AECompensationStepDenominator = rational.Denominator; this.AECompensationStep = (float)this.AECompensationStepNumerator / (float)this.AECompensationStepDenominator; float availableMaxDigitalZoom = 0.0f; resultCode = MLCameraNativeBindings.MLCameraMetadataGetScalerAvailableMaxDigitalZoom(cameraCharacteristicsHandle, ref availableMaxDigitalZoom); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get max available digital zoom. Reason: {0}", result); return(result); } this.AvailableMaxDigitalZoom = availableMaxDigitalZoom; int sensorOrientation = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorOrientation(cameraCharacteristicsHandle, ref sensorOrientation); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get sensor orientation. Reason: {0}", result); return(result); } this.SensorOrientation = sensorOrientation; MLCamera.MetadataControlAELock controlAELockAvailable = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAELockAvailable(cameraCharacteristicsHandle, ref controlAELockAvailable); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get control AE lock available. Reason: {0}", result); return(result); } this.ControlAELockAvailable = controlAELockAvailable; ulong controlAWBModeCount = 0; IntPtr controlAWBAvailableModesData = IntPtr.Zero; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAWBAvailableModes(cameraCharacteristicsHandle, ref controlAWBAvailableModesData, ref controlAWBModeCount); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get camera control ABW available modes for MLCamera. Reason: {0}", result); return(result); } this.ControlAWBModesAvailable = new List <MLCamera.MetadataControlAWBMode>(); int[] awbModeArray = new int[controlAWBModeCount]; Marshal.Copy(controlAWBAvailableModesData, awbModeArray, 0, (int)controlAWBModeCount); for (int i = 0; i < awbModeArray.Length; ++i) { this.ControlAWBModesAvailable.Add((MLCamera.MetadataControlAWBMode)awbModeArray[i]); } MLCamera.MetadataControlAWBLock controlAWBLockAvailable = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAWBLockAvailable(cameraCharacteristicsHandle, ref controlAWBLockAvailable); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get control AWB lock available. Reason: {0}", result); return(result); } this.ControlAWBLockAvailable = controlAWBLockAvailable; int[] sensorInfoActiveArraySize = new int[4]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorInfoActiveArraySize(cameraCharacteristicsHandle, sensorInfoActiveArraySize); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get sensor info active array size. Reason: {0}", result); return(result); } this.SensorInfoActiveArraySize = new SensorInfoActiveArraySizeValues( sensorInfoActiveArraySize[0], sensorInfoActiveArraySize[1], sensorInfoActiveArraySize[2], sensorInfoActiveArraySize[3]); ulong scalerProcessedSizesCount = 0; IntPtr scalerProcessedSizesData = IntPtr.Zero; resultCode = MLCameraNativeBindings.MLCameraMetadataGetScalerProcessedSizes(cameraCharacteristicsHandle, ref scalerProcessedSizesData, ref scalerProcessedSizesCount); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get scaler processed sizes. Reason: {0}", result); return(result); } int[] scalerProcessedSizesDataArray = new int[scalerProcessedSizesCount]; Marshal.Copy(scalerProcessedSizesData, scalerProcessedSizesDataArray, 0, (int)scalerProcessedSizesCount); this.ScalerProcessedSizes = new List <ScalerProcessedSize>((int)scalerProcessedSizesCount); for (int i = 0; i < (int)scalerProcessedSizesCount; i += 2) { int width = scalerProcessedSizesDataArray[i]; int height = scalerProcessedSizesDataArray[i + 1]; ScalerProcessedSize newSize = new ScalerProcessedSize(width, height); this.ScalerProcessedSizes.Add(newSize); } ulong streamConfigurationsCount = 0; IntPtr streamConfigurationsData = IntPtr.Zero; resultCode = MLCameraNativeBindings.MLCameraMetadataGetScalerAvailableStreamConfigurations(cameraCharacteristicsHandle, ref streamConfigurationsData, ref streamConfigurationsCount); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get scaler available stream configurations. Reason: {0}", result); return(result); } int[] streamConfigurationsDataArray = new int[streamConfigurationsCount]; Marshal.Copy(streamConfigurationsData, streamConfigurationsDataArray, 0, (int)streamConfigurationsCount); this.ScalerAvailableStreamConfigurations = new List <StreamConfiguration>(); for (int i = 0; i < (int)streamConfigurationsCount; i += 4) { StreamConfiguration config = new StreamConfiguration( (MLCamera.MetadataScalerAvailableFormats)streamConfigurationsDataArray[i], streamConfigurationsDataArray[i + 1], streamConfigurationsDataArray[i + 2], (MLCamera.MetadataScalerAvailableStreamConfigurations)streamConfigurationsDataArray[i + 3]); this.ScalerAvailableStreamConfigurations.Add(config); } int[] sensorInfoSensitivityRange = new int[2]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorInfoSensitivityRange(cameraCharacteristicsHandle, sensorInfoSensitivityRange); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get sensor info sensitivity range. Reason: {0}", result); return(result); } this.SensorInfoSensitivityRange = new SensorInfoSensitivityRangeValues(sensorInfoSensitivityRange[0], sensorInfoSensitivityRange[1]); long[] sensorInfoExposureTimeRange = new long[2]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorInfoExposureTimeRange(cameraCharacteristicsHandle, sensorInfoExposureTimeRange); if (!MLResult.IsOK(resultCode)) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLCamera.GeneralSettings.PopulateCharacteristics failed to get sensor info exposure time range. Reason: {0}", result); return(result); } this.SensorInfoExposureTimeRange = new SensorInfoExposureTimeRangeValues(sensorInfoExposureTimeRange[0], sensorInfoExposureTimeRange[1]); return(MLResult.Create(MLResult.Code.Ok)); }
/// <summary> /// Apply the settings. /// </summary> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if the request completed successfully. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if an invalid parameter was provided. /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if a required permission is missing. /// </returns> internal MLResult.Code ApplySettings() { MLResult.Code result = MLResult.Code.Ok; if (this.IsDirty) { result = MLCameraNativeBindings.MLCameraMetadataSetColorCorrectionMode(this.prepareHandle, ref this.colorCorrectionMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set color correction mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetColorCorrectionAberrationMode(this.prepareHandle, ref this.colorCorrectionAberrationMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set color correction aberration mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetControlAEAntibandingMode(this.prepareHandle, ref this.controlAEAntibandingMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set control AE antibanding mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetControlAEExposureCompensation(this.prepareHandle, ref this.controlAECompensation); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set AE exposure compensation. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetControlAELock(this.prepareHandle, ref this.controlAELock); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set control AE lock. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetControlAEMode(this.prepareHandle, ref this.controlAEMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set control AE mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetControlAWBLock(this.prepareHandle, ref this.controlAWBLock); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set control AWB lock. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetControlAWBMode(this.prepareHandle, ref this.controlAWBMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set control AWB mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetSensorExposureTime(this.prepareHandle, ref this.sensorExposureTime); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set sensor exposure time. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataSetSensorSensitivity(this.prepareHandle, ref this.sensorSensitivity); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set sensor sensitivity. Reason: {0}", result); return(result); } this.IsDirty = false; } if (this.ColorCorrectionTransform.IsDirty) { MLCameraNativeBindings.MLCameraMetadataRationalNative[] colorcorrectiontransform = new MLCameraNativeBindings.MLCameraMetadataRationalNative[9]; colorcorrectiontransform[0].FromFloat(this.ColorCorrectionTransform.X0, 1000); colorcorrectiontransform[1].FromFloat(this.ColorCorrectionTransform.X1, 1000); colorcorrectiontransform[2].FromFloat(this.ColorCorrectionTransform.X2, 1000); colorcorrectiontransform[3].FromFloat(this.ColorCorrectionTransform.Y0, 1000); colorcorrectiontransform[4].FromFloat(this.ColorCorrectionTransform.Y1, 1000); colorcorrectiontransform[5].FromFloat(this.ColorCorrectionTransform.Y2, 1000); colorcorrectiontransform[6].FromFloat(this.ColorCorrectionTransform.Z0, 1000); colorcorrectiontransform[7].FromFloat(this.ColorCorrectionTransform.Z1, 1000); colorcorrectiontransform[8].FromFloat(this.ColorCorrectionTransform.Z2, 1000); result = MLCameraNativeBindings.MLCameraMetadataSetColorCorrectionTransform(this.prepareHandle, colorcorrectiontransform); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set color correction transform. Reason: {0}", result); return(result); } this.ColorCorrectionTransform.IsDirty = false; } if (this.ColorCorrectionGains.IsDirty) { // The order of this, red, greenEven, greenOdd, blue, was taken from the android developer site for the color corrections gain vector // https://developer.android.com/reference/android/hardware/camera2/params/RggbChannelVector float[] gains = new float[4]; gains[0] = this.ColorCorrectionGains.Red; gains[1] = this.ColorCorrectionGains.GreenEven; gains[2] = this.ColorCorrectionGains.GreenOdd; gains[3] = this.ColorCorrectionGains.Blue; result = MLCameraNativeBindings.MLCameraMetadataSetColorCorrectionGains(this.prepareHandle, gains); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set color correction gains. Reason: {0}", result); return(result); } this.ColorCorrectionGains.IsDirty = false; } if (this.ControlAETargetFPSRange.IsDirty) { int[] fpsrange = new int[2]; fpsrange[0] = this.ControlAETargetFPSRange.Minimum; fpsrange[1] = this.ControlAETargetFPSRange.Maximum; result = MLCameraNativeBindings.MLCameraMetadataSetControlAETargetFPSRange(this.prepareHandle, fpsrange); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set Control AE Target FPS range. Reason: {0}", result); return(result); } this.ControlAETargetFPSRange.IsDirty = false; } if (this.ScalerCropRegion.IsDirty) { int[] cropRegion = new int[4]; cropRegion[0] = this.ScalerCropRegion.Left; cropRegion[1] = this.ScalerCropRegion.Top; cropRegion[2] = this.ScalerCropRegion.Right; cropRegion[3] = this.ScalerCropRegion.Bottom; result = MLCameraNativeBindings.MLCameraMetadataSetScalerCropRegion(this.prepareHandle, cropRegion); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.ApplySettings failed to set scaler crop region. Reason: {0}", result); return(result); } this.ScalerCropRegion.IsDirty = false; } return(result); }
/// <summary> /// Populate the camera result settings. /// </summary> /// <param name="prepareHandle">A pointer to the camera prepare handle.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if completed successfully. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if an invalid parameter was provided. /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if a required permission is missing. /// </returns> internal MLResult.Code PopulateSettings(ulong prepareHandle) { MLResult.Code resultCode = MLResult.Code.Ok; MLCamera.MetadataColorCorrectionMode colorCorrectionMode = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionModeResultMetadata(prepareHandle, ref colorCorrectionMode); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get color correction mode for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ColorCorrectionMode = colorCorrectionMode; MLCameraNativeBindings.MLCameraMetadataRationalNative[] colorCorrectionTransform = new MLCameraNativeBindings.MLCameraMetadataRationalNative[9]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionTransformResultMetadata(prepareHandle, colorCorrectionTransform); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get color correction transform matrix for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ColorCorrectionTransform = new MLCamera.ColorCorrectionTransform( colorCorrectionTransform[0].ToFloat(), colorCorrectionTransform[1].ToFloat(), colorCorrectionTransform[2].ToFloat(), colorCorrectionTransform[3].ToFloat(), colorCorrectionTransform[4].ToFloat(), colorCorrectionTransform[5].ToFloat(), colorCorrectionTransform[6].ToFloat(), colorCorrectionTransform[7].ToFloat(), colorCorrectionTransform[8].ToFloat()); MLCamera.MetadataColorCorrectionAberrationMode colorCorrectionAberrationMode = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionAberrationModeResultMetadata(prepareHandle, ref colorCorrectionAberrationMode); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get color correction aberration mode for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ColorCorrectionAberrationMode = colorCorrectionAberrationMode; float[] colorCorrectionGains = new float[4]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionGainsResultMetadata(prepareHandle, colorCorrectionGains); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get color correction gains for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } // The order of this, red, greenEven, greenOdd, blue, was taken from the android developer site for the color corrections gain vector // https://developer.android.com/reference/android/hardware/camera2/params/RggbChannelVector this.ColorCorrectionGains = new MLCamera.ColorCorrectionGains(colorCorrectionGains[0], colorCorrectionGains[1], colorCorrectionGains[2], colorCorrectionGains[3]); MLCamera.MetadataControlAEAntibandingMode controlAEAntiBandingMode = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAEAntibandingModeResultMetadata(prepareHandle, ref controlAEAntiBandingMode); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control AE antibanding mode for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ControlAEAntibandingMode = controlAEAntiBandingMode; int controlAEExposureCompensation = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAEExposureCompensationResultMetadata(prepareHandle, ref controlAEExposureCompensation); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control AE exposure compensation for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.AEExposureCompensation = controlAEExposureCompensation; MLCamera.MetadataControlAELock controlAELock = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAELockResultMetadata(prepareHandle, ref controlAELock); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control AE lock for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ControlAELock = controlAELock; MLCamera.MetadataControlAEMode controlAEMode = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAEModeResultMetadata(prepareHandle, ref controlAEMode); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control ae mode for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ControlAEMode = controlAEMode; int[] controlAETargetFPSRangeArray = new int[2]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAETargetFPSRangeResultMetadata(prepareHandle, controlAETargetFPSRangeArray); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control AE target fps for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ControlAETargetFPSRange = new MLCamera.ControlAETargetFPSRange(controlAETargetFPSRangeArray[0], controlAETargetFPSRangeArray[1]); MLCamera.MetadataControlAEState controlAEState = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAEStateResultMetadata(prepareHandle, ref controlAEState); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control AE state for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ControlAEState = controlAEState; MLCamera.MetadataControlAWBLock controlAWBLock = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAWBLockResultMetadata(prepareHandle, ref controlAWBLock); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control AWB lock for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ControlAWBLock = controlAWBLock; MLCamera.MetadataControlAWBState controlAWBState = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetControlAWBStateResultMetadata(prepareHandle, ref controlAWBState); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get control AWB state for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ControlAWBState = controlAWBState; long sensorExposureTime = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorExposureTimeResultMetadata(prepareHandle, ref sensorExposureTime); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get sensor exposure time for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.SensorExposureTime = sensorExposureTime; int sensorySensitivity = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorSensitivityResultMetadata(prepareHandle, ref sensorySensitivity); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get sensor sensitivity for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.SensorSensitivity = sensorySensitivity; long sensorTimestamp = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorTimestampResultMetadata(prepareHandle, ref sensorTimestamp); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get sensor time stamp for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.SensorTimestamp = sensorTimestamp; int[] scalerCropRegionArray = new int[4]; resultCode = MLCameraNativeBindings.MLCameraMetadataGetScalerCropRegionResultMetadata(prepareHandle, scalerCropRegionArray); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get scaler crop region for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.ScalerCropRegion = new MLCamera.ScalerCropRegion(scalerCropRegionArray[0], scalerCropRegionArray[1], scalerCropRegionArray[2], scalerCropRegionArray[3]); long sensorFrameDuration = 0; resultCode = MLCameraNativeBindings.MLCameraMetadataGetSensorFrameDurationResultMetadata(prepareHandle, ref sensorFrameDuration); if (!MLResult.IsOK(resultCode)) { MLPluginLog.ErrorFormat("MLCamera.ResultSettings.PopulateSettings failed to get sensor frame duration for prepare handle {0}. Reason: {1}", prepareHandle, resultCode); return(resultCode); } this.SensorFrameDuration = sensorFrameDuration; return(resultCode); }
/// <summary> /// Populate the settings. /// </summary> /// <param name="prepareHandle">A handle to the prepare capture camera.</param> /// <param name="captureType">The capture type</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if the request completed successfully. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if an invalid parameter was provided. /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if a required permission is missing. /// </returns> internal MLResult.Code PopulateSettings(ulong prepareHandle, MLCamera.CaptureType captureType) { MLResult.Code result = MLResult.Code.Ok; this.prepareHandle = prepareHandle; this.CaptureType = captureType; result = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionModeRequestMetadata(this.prepareHandle, ref this.colorCorrectionMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get color correction mode. Reason: {0}", result); return(result); } MLCameraNativeBindings.MLCameraMetadataRationalNative[] colorCorrectionTransform = new MLCameraNativeBindings.MLCameraMetadataRationalNative[9]; result = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionTransformRequestMetadata(this.prepareHandle, colorCorrectionTransform); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get color correction transform matrix. Reason: {0}", result); return(result); } this.ColorCorrectionTransform = new MLCamera.ColorCorrectionTransform( colorCorrectionTransform[0].ToFloat(), colorCorrectionTransform[1].ToFloat(), colorCorrectionTransform[2].ToFloat(), colorCorrectionTransform[3].ToFloat(), colorCorrectionTransform[4].ToFloat(), colorCorrectionTransform[5].ToFloat(), colorCorrectionTransform[6].ToFloat(), colorCorrectionTransform[7].ToFloat(), colorCorrectionTransform[8].ToFloat()); float[] colorCorrectionGains = new float[4]; result = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionGainsRequestMetadata(this.prepareHandle, colorCorrectionGains); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get color correction gains vector. Reason: {0}", result); return(result); } // The order of this, red, greenEven, greenOdd, blue, was taken from the android developer site for the color corrections gain vector // https://developer.android.com/reference/android/hardware/camera2/params/RggbChannelVector this.ColorCorrectionGains = new MLCamera.ColorCorrectionGains(colorCorrectionGains[0], colorCorrectionGains[1], colorCorrectionGains[2], colorCorrectionGains[3]); result = MLCameraNativeBindings.MLCameraMetadataGetColorCorrectionAberrationModeRequestMetadata(this.prepareHandle, ref this.colorCorrectionAberrationMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get color correction aberration mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataGetControlAEAntibandingModeRequestMetadata(this.prepareHandle, ref this.controlAEAntibandingMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get control AE antibanding mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataGetControlAEExposureCompensationRequestMetadata(this.prepareHandle, ref this.controlAECompensation); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get AE exposure compensation. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataGetControlAELockRequestMetadata(this.prepareHandle, ref this.controlAELock); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get control AE lock. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataGetControlAEModeRequestMetadata(this.prepareHandle, ref this.controlAEMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get control AE mode. Reason: {0}", result); return(result); } int[] controlAETargetFPSRangeArray = new int[2]; result = MLCameraNativeBindings.MLCameraMetadataGetControlAETargetFPSRangeRequestMetadata(this.prepareHandle, controlAETargetFPSRangeArray); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get control AE Target FPS Range. Reason: {0}", result); return(result); } this.ControlAETargetFPSRange = new MLCamera.ControlAETargetFPSRange(controlAETargetFPSRangeArray[0], controlAETargetFPSRangeArray[1]); result = MLCameraNativeBindings.MLCameraMetadataGetControlAWBLockRequestMetadata(this.prepareHandle, ref this.controlAWBLock); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get control AWB Lock. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataGetControlAWBModeRequestMetadata(this.prepareHandle, ref this.controlAWBMode); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get control AWB mode. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataGetSensorExposureTimeRequestMetadata(this.prepareHandle, ref this.sensorExposureTime); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get sensor exposure time. Reason: {0}", result); return(result); } result = MLCameraNativeBindings.MLCameraMetadataGetSensorSensitivityRequestMetadata(this.prepareHandle, ref this.sensorSensitivity); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get sensor sensitivity. Reason: {0}", result); return(result); } int[] scalerCropRegionArray = new int[4]; result = MLCameraNativeBindings.MLCameraMetadataGetScalerCropRegionRequestMetadata(this.prepareHandle, scalerCropRegionArray); if (!MLResult.IsOK(result)) { MLPluginLog.ErrorFormat("MLCamera.CaptureSettings.PopulateSettings failed to get scaler crop region. Reason: {0}", result); return(result); } this.ScalerCropRegion = new MLCamera.ScalerCropRegion(scalerCropRegionArray[0], scalerCropRegionArray[1], scalerCropRegionArray[2], scalerCropRegionArray[3]); return(result); }