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

Commit 67816e34 authored by Eric Laurent's avatar Eric Laurent
Browse files

Spatializer: Add head tracking callback

Split head tracking related events from main INativeSpatializerCallback
to a dedicated callback ISpatializerHeadTrackingCallback that can
be registerred and unregistered independently.

Bug: 188502620
Test: manual test with mock spatializer
Change-Id: I09eefb0911f557a6faa6cf0b6c1afe7eaf71ca84
parent 780be4ad
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -502,6 +502,7 @@ aidl_interface {
    srcs: [
        "aidl/android/media/INativeSpatializerCallback.aidl",
        "aidl/android/media/ISpatializer.aidl",
        "aidl/android/media/ISpatializerHeadTrackingCallback.aidl",
    ],
    imports: [
        "audiopolicy-types-aidl",
+0 −11
Original line number Diff line number Diff line
@@ -31,15 +31,4 @@ oneway interface INativeSpatializerCallback {
     * (e.g. when the spatializer is enabled or disabled)
     */
    void onLevelChanged(SpatializationLevel level);

    /** Called when the head tracking mode has changed
     */
    void onHeadTrackingModeChanged(SpatializerHeadTrackingMode mode);

    /** Called when the head to stage pose hase been updated
     * The head to stage pose is conveyed as a vector of 6 elements,
     * where the first three are a translation vector and
     * the last three are a rotation vector.
     */
    void onHeadToSoundStagePoseUpdated(in float[] headToStage);
}
+10 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.media;

import android.media.ISpatializerHeadTrackingCallback;
import android.media.SpatializationLevel;
import android.media.SpatializationMode;
import android.media.SpatializerHeadTrackingMode;
@@ -103,4 +104,13 @@ interface ISpatializer {
     * retrieved with IAudioPolicyService.getSpatializer().
     */
    SpatializationMode[] getSupportedModes();

    /**
     * Registers a callback to monitor head tracking functions.
     * Only one callback can be registered on a Spatializer.
     * The last callback registered wins and passing a nullptr unregisters
     * last registered callback.
     */
    void registerHeadTrackingCallback(ISpatializerHeadTrackingCallback callback);

}
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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;

import android.media.SpatializationLevel;
import android.media.SpatializerHeadTrackingMode;

/**
 * The ISpatializerHeadTrackingCallback interface is a callback associated to the
 * Spatializer head tracking function. It can be registered via the ISpatializer
 * interface to monitor head tracking related states.
 * {@hide}
 */
oneway interface ISpatializerHeadTrackingCallback {
    /** Called when the head tracking mode has changed
     */
    void onHeadTrackingModeChanged(SpatializerHeadTrackingMode mode);

    /** Called when the head to stage pose hase been updated
     * The head to stage pose is conveyed as a vector of 6 elements,
     * where the first three are a translation vector and
     * the last three are a rotation vector.
     */
    void onHeadToSoundStagePoseUpdated(in float[] headToStage);
}
+15 −4
Original line number Diff line number Diff line
@@ -506,6 +506,17 @@ Status Spatializer::getSupportedModes(std::vector<SpatializationMode> *modes) {
    return Status::ok();
}

Status Spatializer::registerHeadTrackingCallback(
        const sp<media::ISpatializerHeadTrackingCallback>& callback) {
    ALOGV("%s callback %p", __func__, callback.get());
    std::lock_guard lock(mLock);
    if (!mSupportsHeadTracking) {
        return binderStatusFromStatusT(INVALID_OPERATION);
    }
    mHeadTrackingCallback = callback;
    return Status::ok();
}

// SpatializerPoseController::Listener
void Spatializer::onHeadToStagePose(const Pose3f& headToStage) {
    ALOGV("%s", __func__);
@@ -526,10 +537,10 @@ void Spatializer::onHeadToStagePose(const Pose3f& headToStage) {

void Spatializer::onHeadToStagePoseMsg(const std::vector<float>& headToStage) {
    ALOGV("%s", __func__);
    sp<media::INativeSpatializerCallback> callback;
    sp<media::ISpatializerHeadTrackingCallback> callback;
    {
        std::lock_guard lock(mLock);
        callback = mSpatializerCallback;
        callback = mHeadTrackingCallback;
        if (mEngine != nullptr) {
            setEffectParameter_l(SPATIALIZER_PARAM_HEAD_TO_STAGE, headToStage);
        }
@@ -550,7 +561,7 @@ void Spatializer::onActualModeChange(HeadTrackingMode mode) {

void Spatializer::onActualModeChangeMsg(HeadTrackingMode mode) {
    ALOGV("%s(%d)", __func__, (int) mode);
    sp<media::INativeSpatializerCallback> callback;
    sp<media::ISpatializerHeadTrackingCallback> callback;
    SpatializerHeadTrackingMode spatializerMode;
    {
        std::lock_guard lock(mLock);
@@ -572,7 +583,7 @@ void Spatializer::onActualModeChangeMsg(HeadTrackingMode mode) {
            }
        }
        mActualHeadTrackingMode = spatializerMode;
        callback = mSpatializerCallback;
        callback = mHeadTrackingCallback;
    }
    if (callback != nullptr) {
        callback->onHeadTrackingModeChanged(spatializerMode);
Loading