lockForConfiguration method

Future<bool> lockForConfiguration()

Requests exclusive access to the device’s hardware properties.

You must call this method before attempting to configure the hardware related properties of the device. This method returns true when it successfully locks the device for configuration by your code. After configuring the device properties, call unlockForConfiguration to release the configuration lock and allow other apps to make changes.

You may hold onto a lock (instead of releasing it) if you require the device properties to remain unchanged. However, holding the device lock unnecessarily may degrade capture quality in other apps sharing the device.

Note: In iOS, directly configuring a capture device’s activeFormat property changes the capture session’s preset to CaptureSessionPreset.inputPriority. Upon making this change, the capture session no longer automatically configures the capture format when you call the CaptureSession.startRunning method or call the CaptureSession.commitConfiguration method after changing the session topology (that is, adding, removing, or rearranging capture inputs and outputs). In macOS, a capture session can still automatically configure the capture format after you make changes. To prevent automatic changes to the capture format in macOS, follow these steps:

1. Lock the device with the [lockForConfiguration] method.

2. Change the device’s [activeFormat] property.

3. Begin capture with the session’s `startRunning` method.

4. Unlock the device with the [unlockForConfiguration] method.

Or, to prevent automatic changes after modifying session topology in macOS:

1. Lock the device with the [lockForConfiguration] method.

2. Call the session’s `beginConfiguration` method, change topology,
then call the `commitConfiguration` method.

3. Unlock the device with the `unlockForConfiguration` method.

Implementation

Future<bool> lockForConfiguration() async {
  return await _channel.$lockForConfiguration(this) as bool;
}