Automatic Processing Configuration Mode

The Automatic Processing Configuration, introduced in MSDK 11.0.0, offers a new mechanism to configure the MimiProcessingSession for compatible Mimi Processor devices.

Note: Automatic Processing Configuration is not compatible with older existing Mimi Processors; if you need to support both types of Processors, then your application should use appropriate heuristics to determine which mode to use for each device.

Overview

Automatic Processing Configuration allows the capabilities and state of the Processor to be automatically detected by the MSDK, and used to initialize the MimiProcessingSession. In other words, Processor configuration values such as Tech-Level or Personalization Mode which were required in the Basic Processing Configuration are now “automatically” determined by the Automatic Processing Configuration simplifying the activation step significantly.

Session Activation with a MimiAutomaticProcessingConfiguration

The definition of the MimiAutomaticProcessingConfiguration simply includes the Applicator configuration to allow the MSDK to communicate with the Processor.

An example MimiProcessingSession with an Applicator with an (optional) timeout of 2 seconds can be activated as follows:

do {
    let configuration = try MimiAutomaticProcessingConfiguration {
        Processor {
            Applicator(timeout: 2.0) { value in
                // Send value to Processor and return response Data object from Processor.
            }
        }
    }

    return try await processing.activate(configuration: configuration)
} catch {
    // Handle activation failure
}

Application timeout

It is also possible to set a timeout for the application of a value in the Applicator. If the value application exceeds this timeout, it will cause the entire value application sequence to fail.

When the timeout elapses the SDK throws MimiProcessingParameterError.applyTimeoutExceeded, stops waiting for the Applicator and moves on to the next operation on that parameter. The parameter’s value is left unchanged and its updateState reports the failure. The value may nevertheless have reached the device just as the timeout fired.

The Applicator’s task is cancelled, but the SDK cannot abort code that does not observe cancellation: an Applicator that is waiting for a device reply through a continuation keeps waiting. The SDK does not invoke the Applicator again for the same parameter while such an invocation is still running. That parameter’s next application waits for it to return first, so its values reach the device in the order they were applied, and that wait counts towards the next application’s own timeout: while the Applicator does not return, every further application of that parameter fails with applyTimeoutExceeded without invoking it. Other parameters are not held back: in this mode they share the one Applicator, which can therefore be invoked for another parameter in the meantime. If the timed-out invocation eventually succeeds, the SDK takes note that the device holds its value, although the application was reported as failed, and a later application of any other value, including the parameter’s current one, is sent to the device rather than skipped as already applied.

An Applicator that never returns for a parameter therefore keeps that parameter from being applied. To avoid this, an Applicator should stop its own work when its task is cancelled: resume its continuation from the onCancel block of withTaskCancellationHandler, guarding the continuation so that it is resumed only once because the device reply may still arrive afterwards, or bound the transport call with a timeout of its own that is no longer than the Applicator timeout. Cancelling the task that called apply also returns at once, with CancellationError, whether or not a timeout is set, and is subject to the same rules: the invocation that is already running is waited for by the next application. If the Applicator was already running for the cancelled call, the parameter’s updateState stays .applying rather than reporting a failure; a call cancelled before the Applicator was invoked for it still reports .failed at once. Once the Applicator returns it reports .applied and value is updated, or it reports .failed with the Applicator’s error; if another operation on the parameter has started in the meantime, only value is updated. An application that timed out is followed up as well: it has already reported .failed with applyTimeoutExceeded, and if the Applicator then returns successfully value is updated and .applied is reported under the same conditions; if the Applicator throws, the reported timeout stands.

Once there is an activated MimiProcessingSession, it is possible to access the processing parameters and configure them appropriately.

  • Activating a session will set the session property on the MimiProcessingController allowing the session to be easily referenced.
  • Only a single session can be activated at one time.
  • MimiProcessingController.sessionPublisher is a AnyPublisher and can be subscribed for changes that occur during the activation & deactivation of a session.

Tip: Most partner integrations will only need to use a single MimiProcessingSession that roughly aligns with the headphone connectivity lifecycle.