Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab58ef64 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Sound trigger middleware service definition

These are the AIDL files that define the sound trigger middleware
interface.
This service is intended to replace the existing
frameworks/av/include/soundtrigger/ISoundTriggerHwService.h
using AIDL in order to avoid a large amount of hand-written
parceling code and other forms of boilerplate, and provide
cross-language support.

Change-Id: Ia783ba4f1ea7335a984396e7024cac0411699403
Bug: 142070343
parent d58b04ae
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -133,3 +133,41 @@ aidl_interface {
    },
}

aidl_interface {
    name: "soundtrigger_middleware-aidl",
    local_include_dir: "java",
    srcs: [
        "java/android/media/soundtrigger_middleware/ConfidenceLevel.aidl",
        "java/android/media/soundtrigger_middleware/ISoundTriggerCallback.aidl",
        "java/android/media/soundtrigger_middleware/ISoundTriggerMiddlewareService.aidl",
        "java/android/media/soundtrigger_middleware/ISoundTriggerModule.aidl",
        "java/android/media/soundtrigger_middleware/Phrase.aidl",
        "java/android/media/soundtrigger_middleware/PhraseRecognitionEvent.aidl",
        "java/android/media/soundtrigger_middleware/PhraseRecognitionExtra.aidl",
        "java/android/media/soundtrigger_middleware/PhraseSoundModel.aidl",
        "java/android/media/soundtrigger_middleware/RecognitionConfig.aidl",
        "java/android/media/soundtrigger_middleware/RecognitionEvent.aidl",
        "java/android/media/soundtrigger_middleware/RecognitionMode.aidl",
        "java/android/media/soundtrigger_middleware/RecognitionStatus.aidl",
        "java/android/media/soundtrigger_middleware/SoundModel.aidl",
        "java/android/media/soundtrigger_middleware/SoundModelType.aidl",
        "java/android/media/soundtrigger_middleware/SoundTriggerModuleDescriptor.aidl",
        "java/android/media/soundtrigger_middleware/SoundTriggerModuleProperties.aidl",
        "java/android/media/soundtrigger_middleware/Status.aidl",
    ],
    backend:
    {
        cpp: {
            enabled: true,
        },
        java: {
            // Already generated as part of the entire media java library.
            enabled: false,
        },
        ndk: {
            // Not currently needed, and disabled because of b/146172425
            enabled: false,
        },
    },
    imports: [ "audio_common-aidl" ],
}
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.media.soundtrigger_middleware;

/**
 * A recognition confidence level.
 * This type is used to represent either a threshold or an actual detection confidence level.
 *
 * {@hide}
 */
parcelable ConfidenceLevel {
    /** user ID. */
    int userId;
    /**
     * Confidence level in percent (0 - 100).
     * <ul>
     * <li>Min level for recognition configuration
     * <li>Detected level for recognition event.
     * </ul>
     */
    int levelPercent;
}
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.media.soundtrigger_middleware;

import android.media.soundtrigger_middleware.RecognitionEvent;
import android.media.soundtrigger_middleware.PhraseRecognitionEvent;

/**
 * Main interface for a client to get notifications of events coming from this module.
 *
 * {@hide}
 */
oneway interface ISoundTriggerCallback {
    /**
     * Invoked whenever a recognition event is triggered (typically, on recognition, but also in
     * case of external aborting of a recognition or a forced recognition event - see the status
     * code in the event for determining).
     */
    void onRecognition(int modelHandle, in RecognitionEvent event);
     /**
      * Invoked whenever a phrase recognition event is triggered (typically, on recognition, but
      * also in case of external aborting of a recognition or a forced recognition event - see the
      * status code in the event for determining).
      */
    void onPhraseRecognition(int modelHandle, in PhraseRecognitionEvent event);
    /**
     * Notifies the client the recognition has become available after previously having been
     * unavailable, or vice versa. This method will always be invoked once immediately after
     * attachment, and then every time there is a change in availability.
     * When availability changes from available to unavailable, all active recognitions are aborted,
     * and this event will be sent in addition to the abort event.
     */
    void onRecognitionAvailabilityChange(boolean available);
}
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.media.soundtrigger_middleware;

import android.media.soundtrigger_middleware.ISoundTriggerModule;
import android.media.soundtrigger_middleware.ISoundTriggerCallback;
import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor;

/**
 * Main entry point into this module.
 *
 * Allows the client to enumerate the available soundtrigger devices and their capabilities, then
 * attach to either one of them in order to use it.
 *
 * {@hide}
 */
interface ISoundTriggerMiddlewareService {
    /**
     * Query the available modules and their capabilities.
     */
    SoundTriggerModuleDescriptor[] listModules();

    /**
     * Attach to one of the available modules.
     * listModules() must be called prior to calling this method and the provided handle must be
     * one of the handles from the returned list.
     */
    ISoundTriggerModule attach(int handle, ISoundTriggerCallback callback);

    /**
     * Notify the service that external input capture is taking place. This may cause some of the
     * active recognitions to be aborted.
     */
    void setExternalCaptureState(boolean active);
}
 No newline at end of file
+105 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.media.soundtrigger_middleware;

import android.media.soundtrigger_middleware.SoundModel;
import android.media.soundtrigger_middleware.PhraseSoundModel;
import android.media.soundtrigger_middleware.RecognitionConfig;

/**
 * A sound-trigger module.
 *
 * This interface allows a client to operate a sound-trigger device, intended for low-power
 * detection of various sound patterns, represented by a "sound model".
 *
 * Basic operation is to load a sound model (either a generic one or a "phrase" model), then
 * initiate recognition on this model. A trigger will be delivered asynchronously via a callback
 * provided by the caller earlier, when attaching to this interface.
 *
 * In additon to recognition events, this module will also produce abort events in cases where
 * recognition has been externally preempted.
 *
 * {@hide}
 */
interface ISoundTriggerModule {
    /**
     * Load a sound model. Will return a handle to the model on success or will throw a
     * ServiceSpecificException with one of the {@link Status} error codes upon a recoverable error
     * (for example, lack of resources of loading a model at the time of call.
     * Model must eventually be unloaded using {@link #unloadModel(int)} prior to detaching.
     *
     * May throw a ServiceSpecificException with an RESOURCE_CONTENTION status to indicate that
     * resources required for loading the model are currently consumed by other clients.
     */
    int loadModel(in SoundModel model);

    /**
     * Load a phrase sound model. Will return a handle to the model on success or will throw a
     * ServiceSpecificException with one of the {@link Status} error codes upon a recoverable error
     * (for example, lack of resources of loading a model at the time of call.
     * Model must eventually be unloaded using unloadModel prior to detaching.
     *
     * May throw a ServiceSpecificException with an RESOURCE_CONTENTION status to indicate that
     * resources required for loading the model are currently consumed by other clients.
     */
    int loadPhraseModel(in PhraseSoundModel model);

    /**
     * Unload a model, previously loaded with loadModel or loadPhraseModel. After unloading, model
     * can no longer be used for recognition and the resources occupied by it are released.
     * Model must not be active at the time of unloading. Cient may call stopRecognition to ensure
     * that.
     */
    void unloadModel(int modelHandle);

    /**
     * Initiate recognition on a previously loaded model.
     * Recognition event would eventually be delivered via the client-provided callback, typically
     * supplied during attachment to this interface.
     *
     * Once a recognition event is passed to the client, the recognition automatically become
     * inactive, unless the event is of the RecognitionStatus.FORCED kind. Client can also shut down
     * the recognition explicitly, via stopRecognition.
     */
    void startRecognition(int modelHandle, in RecognitionConfig config);

    /**
     * Stop a recognition of a previously active recognition. Will NOT generate a recognition event.
     * This call is idempotent - calling it on an inactive model has no effect. However, it must
     * only be used with a loaded model handle.
     */
    void stopRecognition(int modelHandle);

    /**
     * Force generation of a recognition event. Handle must be that of a loaded model. If
     * recognition is inactive, will do nothing. If recognition is active, will asynchronously
     * deliever an event with RecognitionStatus.FORCED status and leave recognition in active state.
     * To avoid any race conditions, once an event signalling the automatic stopping of recognition
     * is sent, no more forced events will get sent (even if previously requested) until recognition
     * is explicitly started again.
     *
     * Since not all module implementations support this feature, may throw a
     * ServiceSpecificException with an OPERATION_NOT_SUPPORTED status.
     */
    void forceRecognitionEvent(int modelHandle);

    /**
     * Detach from the module, releasing any active resources.
     * This will ensure the client callback is no longer called after this call returns.
     * All models must have been unloaded prior to calling this method.
     */
    void detach();
}
 No newline at end of file
Loading