Skip to main content
Version: 20 Mar 2024

NativeBindings

This class defines the C# interface to the C functions/structures in "ml_camera.h".

Inherits from:
MagicLeapNativeBindings

Public Methods

delegate void DeviceAvailabilityStatusDelegate

public delegate void DeviceAvailabilityStatusDelegate(
ref MLCameraDeviceAvailabilityInfo info
)

Parameters

TypeNameDescription
ref MLCameraDeviceAvailabilityInfoinfo

MLResult.Code MLCameraCaptureImage

The output image will be returned in capture callback on_image_buffer_available

public MLResult.Code MLCameraCaptureImage(
ulong contextHandle,
uint numImages
)

Parameters

TypeNameDescription
ulongcontextHandleContext obtained from MLCameraConnect.
uintnumImagesno of images to capture valid range is 1-10.

Returns: MLResult.Result will be MLResult.Code.Ok if image was captured successfully. MLResult.Result will be MLResult.Code.MediaGenericInvalidOperation if failed to capture image due to on-going video recording. MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to capture image due to null pointer. MLResult.Result will be MLResult.Code.InvalidParam if failed to capture image due to an invalid parameter. MLResult.Result will be MLResult.Code.Timeout if failed to capture image due to timeout. MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing.


MLResult.Code MLCameraCaptureVideoStart

Start video capture and save output to a file. The captured video and audio streams will be encoded with AVC and AAC codecs and packed in mp4 container format and stored into the file specified by the file path.The library is responsible for opening and closing the file.The current supported video resolution is 1080p. If this function is invoked before the camera sensor has locked AE and AWB, it will be blocked till AE, AWB is locked and then starts to capture. MLCameraCaptureVideoStop() needs to be called to stop the capture.

public MLResult.Code MLCameraCaptureVideoStart(
ulong contextHandle
)

Parameters

TypeNameDescription
ulongpathFile path to store the output video.

Returns: MLResult.Result will be MLResult.Code.Ok if started video recording successfully. MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to start video recording due to null pointer. MLResult.Result will be MLResult.Code.InvalidParam if failed to start video recording due to invalid input parameter. MLResult.Result will be MLResult.Code.Timeout if failed to start video recording image due to timeout. MLResult.Result will be MLResult.Code.AllocFailed if failed to allocate memory. MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing.


MLResult.Code MLCameraCaptureVideoStop

Stop video capture. User should allow some time, i.e., >500ms, after MLCameraCaptureVideoStart and before calling this API, as captured frames are being encoded.Otherwise, MLResult_UnspecifiedFailure will be returned.

public MLResult.Code MLCameraCaptureVideoStop(
ulong contextHandle
)

Parameters

TypeNameDescription
ulongcontextHandle

Returns: MLResult.Result will be MLResult.Code.Ok if stopped video recording successfully. MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to stop video recording due to null pointer. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing.


MLResult.Code MLCameraConnect

public MLResult.Code MLCameraConnect(
ref MLCameraConnectContext inputContext,
out ulong handle
)

Parameters

TypeNameDescription
ref MLCameraConnectContextinputContextStructure to encapsulate context for a CameraConnect Request.
out ulonghandle

MLResult.Code MLCameraDeInit

public MLResult.Code MLCameraDeInit()

MLResult.Code MLCameraDisconnect

Disconnect from camera device.

public MLResult.Code MLCameraDisconnect(
ulong contextHandle
)

Parameters

TypeNameDescription
ulongcontextHandleCapture operation type.

Returns: MLResult.Result will be MLResult.Code.Ok if disconnected from camera device successfully. MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing.


MLResult.Code MLCameraGetCameraCharacteristics

Obtain handle for retrieving camera characteristics. This API provides the handle for retrieving camera characteristics via APIs defined in ml_camera_metadata.h.

public MLResult.Code MLCameraGetCameraCharacteristics(
ulong contextHandle,
out ulong outMetadataHandle
)

Parameters

TypeNameDescription
ulongoutHandleHandle to access camera characteristic metadata.
out ulongoutMetadataHandle

Returns: MLResult.Result will be MLResult.Code.Ok if obtained camera characteristic handle successfully. MLResult.Result will be MLResult.Code.InvalidParam if failed to obtain camera characteristic handle due to invalid input parameter. MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to capture raw image due to null pointer. MLResult.Result will be MLResult.Code.AllocFailed if failed to allocate memory. MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing.


MLResult.Code MLCameraGetDeviceStatus

Poll camera device status. Use #MLCamera.DeviceStatusFlag to view specific status bit. Call MLCameraGetErrorCode() to obtain the error code if MLCamera.DeviceStatusFlag.Error bit is set. Note: This API can still be used even if MLCameraSetDeviceStatusCallbacks() has been called.

public MLResult.Code MLCameraGetDeviceStatus(
ulong contextHandle,
out uint outDeviceStatus
)

Parameters

TypeNameDescription
ulongcontextHandleContext obtained from MLCameraConnect.
out uintoutDeviceStatusDevice status.

Returns: MLResult.Result will be MLResult.Code.Ok if obtained device status successfully. MLResult.Result will be MLResult.Code.InvalidParam if failed to obtain device status due to invalid input parameter.


MLResult.Code MLCameraGetErrorCode

Obtain device error code.

public MLResult.Code MLCameraGetErrorCode(
ulong contextHandle,
out MLCamera.ErrorType outErrorCode
)

Parameters

TypeNameDescription
ulongoutErrorCodeDevice error code.
out MLCamera.ErrorTypeoutErrorCodeCamera errors

Returns: MLResult.Result will be MLResult.Code.Ok if obtained device error code successfully. MLResult.Result will be MLResult.Code.InvalidParam if failed to obtain device error code due to invalid input parameter.


MLResult.Code MLCameraGetNumSupportedStreams

public MLResult.Code MLCameraGetNumSupportedStreams(
ulong handle,
out uint numSupportedStreams
)

Parameters

TypeNameDescription
ulonghandle
out uintnumSupportedStreams

MLResult.Code MLCameraInit

public MLResult.Code MLCameraInit(
ref MLCameraDeviceAvailabilityStatusCallbacks deviceAvailabilityStatusCallback,
IntPtr userData
)

Parameters

TypeNameDescription
ref MLCameraDeviceAvailabilityStatusCallbacksdeviceAvailabilityStatusCallbackDevice availability status callbacks to be implemented by client to receive device availability status.
IntPtruserData

MLResult.Code MLCameraPrepareCapture

Prepare for capture. This API prepares capture per specified MLCamera.CaptureType by creating a capture request, and a handle to which is returned to the user, who can choose to manipulate the request data(metadata) via APIs defined in ml_camera_metadata.h before performing the capture. Shall be called after MLCameraConnect().

public MLResult.Code MLCameraPrepareCapture(
ulong contextHandle,
ref MLCameraCaptureConfig config,
out ulong metadataHandle
)

Parameters

TypeNameDescription
ulongcontextHandleContext obtained from MLCameraConnect.
ref MLCameraCaptureConfigconfigCapture configuration.
out ulongmetadataHandleHandle to the capture metadata. Only valid if result is MLResult_Ok.

Returns: MLResult.Result will be MLResult.Code.Ok if prepared for capture successfully. MLResult.Result will be MLResult.Code.InvalidParam if failed to prepare for capture due to an invalid parameter. MLResult.Result will be MLResult.Code.MediaGenericUnexpectedNull if failed to prepare for capture due to null pointer. MLResult.Result will be MLResult.Code.BadType if failed to prepare for capture due to null pointer. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. MLResult.Result will be MLResult.Code.AllocFailed if failed to allocate memory. MLResult.Result will be MLResult.Code.PermissionDenied if a required permission is missing.


MLResult.Code MLCameraSetDeviceStatusCallbacks

Set the client-implemented callbacks to convey camera device status. Client needs to implement the callbacks defined by MLCameraDeviceStatusCallbacks. The library passes the camera device status to the client via those callbacks. Shall be called before MLCameraConnect().

public MLResult.Code MLCameraSetDeviceStatusCallbacks(
ulong contextHandle,
ref MLCameraDeviceStatusCallbacks deviceStatusCallbacks,
IntPtr data
)

Parameters

TypeNameDescription
ulongdeviceStatusCallbacksCapture status callbacks.
ref MLCameraDeviceStatusCallbacksdataUser metadata.
IntPtrdata

Returns: MLResult.Result will be MLResult.Code.Ok if callbacks were set successfully. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error.


delegate void OnCaptureAbortedDelegate

public delegate void OnCaptureAbortedDelegate(
IntPtr data
)

Parameters

TypeNameDescription
IntPtrdata

delegate void OnCaptureCompletedDelegate

public delegate void OnCaptureCompletedDelegate(
ulong metadataHandle,
ref MLCameraResultExtras extra,
IntPtr data
)

Parameters

TypeNameDescription
ulongmetadataHandle
ref MLCameraResultExtrasextraResultExtras is a structure to encapsulate various indices for a capture result.
IntPtrdata

delegate void OnCaptureFailedDelegate

public delegate void OnCaptureFailedDelegate(
ref MLCameraResultExtras extra,
IntPtr data
)

Parameters

TypeNameDescription
ref MLCameraResultExtrasextraResultExtras is a structure to encapsulate various indices for a capture result.
IntPtrdata

delegate void OnDataCallback

A generic delegate for camera events.

public delegate void OnDataCallback(
IntPtr data
)

Parameters

TypeNameDescription
IntPtrdataCustom data returned when the callback is triggered, user metadata.

delegate void OnDeviceDisconnectedDelegate

public delegate void OnDeviceDisconnectedDelegate(
MLCamera.DisconnectReason reason,
IntPtr data
)

Parameters

TypeNameDescription
MLCamera.DisconnectReasonreasonCamera Disconnect Reason.
IntPtrdata

delegate void OnDeviceErrorDelegate

public delegate void OnDeviceErrorDelegate(
MLCamera.ErrorType error,
IntPtr data
)

Parameters

TypeNameDescription
MLCamera.ErrorTypeerrorCamera errors
IntPtrdata

delegate void OnDeviceIdleDelegate

public delegate void OnDeviceIdleDelegate(
IntPtr data
)

Parameters

TypeNameDescription
IntPtrdata

delegate void OnDeviceStreamingDelegate

public delegate void OnDeviceStreamingDelegate(
IntPtr data
)

Parameters

TypeNameDescription
IntPtrdata

delegate void OnErrorDataCallback

A delegate for camera error events.

public delegate void OnErrorDataCallback(
MLCamera.ErrorType error,
IntPtr data
)

Parameters

TypeNameDescription
MLCamera.ErrorTypeerrorThe type of error that was reported.
IntPtrdataCustom data returned when the callback is triggered, user metadata.

delegate void OnHandleAndResultExtrasRefDataCallback

A delegate for camera capture events with additional information.

public delegate void OnHandleAndResultExtrasRefDataCallback(
MLCamera.Metadata metadataHandle,
ref MLCameraResultExtras extra,
IntPtr data
)

Parameters

TypeNameDescription
MLCamera.MetadatametadataHandleA handle to the metadata.
ref MLCameraResultExtrasextraA structure containing extra result information.
IntPtrdataCustom data returned when the callback is triggered, user metadata.

delegate void OnHandleDataCallback

A delegate for camera preview events.

public delegate void OnHandleDataCallback(
ulong metadataHandle,
IntPtr data
)

Parameters

TypeNameDescription
ulongmetadataHandleA handle to the metadata.
IntPtrdataCustom data returned when the callback is triggered, user metadata.

delegate void OnImageBufferAvailableDelegate

public delegate void OnImageBufferAvailableDelegate(
ref MLCameraOutput output,
ulong metadataHandle,
ref MLCameraResultExtras extra,
IntPtr data
)

Parameters

TypeNameDescription
ref MLCameraOutputoutputCaptured output
ulongmetadataHandle
ref MLCameraResultExtrasextraResultExtras is a structure to encapsulate various indices for a capture result.
IntPtrdata

delegate void OnOutputRefDataCallback

A delegate for image buffer events.

public delegate void OnOutputRefDataCallback(
ref MLCameraOutput output,
IntPtr data
)

Parameters

TypeNameDescription
ref MLCameraOutputoutputThe camera output type.
IntPtrdataCustom data returned when the callback is triggered, user metadata.

delegate void OnPreviewBufferAvailableDelegate

public delegate void OnPreviewBufferAvailableDelegate(
ulong bufferHandle,
ulong metadataHandle,
ref MLCameraResultExtras extra,
IntPtr data
)

Parameters

TypeNameDescription
ulongbufferHandle
ulongmetadataHandle
ref MLCameraResultExtrasextraResultExtras is a structure to encapsulate various indices for a capture result.
IntPtrdata

delegate void OnResultExtrasRefDataCallback

A delegate for camera capture events.

public delegate void OnResultExtrasRefDataCallback(
ref MLCameraResultExtras extra,
IntPtr data
)

Parameters

TypeNameDescription
ref MLCameraResultExtrasextraA structure containing extra result information.
IntPtrdataCustom data returned when the callback is triggered, user metadata.

delegate void OnVideoBufferAvailableDelegate

public delegate void OnVideoBufferAvailableDelegate(
ref MLCameraOutput output,
ulong metadataHandle,
ref MLCameraResultExtras extra,
IntPtr data
)

Parameters

TypeNameDescription
ref MLCameraOutputoutputCaptured output
ulongmetadataHandle
ref MLCameraResultExtrasextraResultExtras is a structure to encapsulate various indices for a capture result.
IntPtrdata

Public Attributes

MLCameraMaxImagePlanes

Number of MLCamera image planes.


public const int MLCameraMaxImagePlanes = 3;