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

Commit bab55176 authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

audio spatializer: more resource usage optimizations am: 11094176

parents 064ca8f6 11094176
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -546,11 +546,13 @@ void AudioPolicyService::doOnCheckSpatializer()
    }
}

size_t AudioPolicyService::countActiveClientsOnOutput_l(audio_io_handle_t output) REQUIRES(mLock) {
size_t AudioPolicyService::countActiveClientsOnOutput_l(
        audio_io_handle_t output, bool spatializedOnly) {
    size_t count = 0;
    for (size_t i = 0; i < mAudioPlaybackClients.size(); i++) {
        auto client = mAudioPlaybackClients.valueAt(i);
        if (client->io == output && client->active) {
        if (client->io == output && client->active
                && (!spatializedOnly || client->isSpatialized)) {
            count++;
        }
    }
+10 −1
Original line number Diff line number Diff line
@@ -1008,7 +1008,16 @@ private:
    void loadAudioPolicyManager();
    void unloadAudioPolicyManager();

    size_t countActiveClientsOnOutput_l(audio_io_handle_t output) REQUIRES(mLock);
    /**
     * Returns the number of active audio tracks on the specified output mixer.
     * The query can be specified to only include spatialized audio tracks or consider
     * all tracks.
     * @param output the I/O handle of the output mixer to consider
     * @param spatializedOnly true if only spatialized tracks should be considered
     * @return the number of active tracks.
     */
    size_t countActiveClientsOnOutput_l(
        audio_io_handle_t output, bool spatializedOnly = true) REQUIRES(mLock);

    mutable Mutex mLock;    // prevents concurrent access to AudioPolicy manager functions changing
                            // device connection state  or routing
+29 −14
Original line number Diff line number Diff line
@@ -373,10 +373,8 @@ Status Spatializer::setDesiredHeadTrackingMode(SpatializerHeadTrackingMode mode)
            break;
    }

    if (mPoseController != nullptr) {
        mPoseController->setDesiredMode(mDesiredHeadTrackingMode);
    checkPoseController_l();
    checkSensorsState_l();
    }

    return Status::ok();
}
@@ -449,6 +447,7 @@ Status Spatializer::setHeadSensor(int sensorHandle) {
    }
    std::lock_guard lock(mLock);
    mHeadSensor = sensorHandle;
    checkPoseController_l();
    checkSensorsState_l();
    return Status::ok();
}
@@ -460,7 +459,9 @@ Status Spatializer::setScreenSensor(int sensorHandle) {
    }
    std::lock_guard lock(mLock);
    mScreenSensor = sensorHandle;
    checkSensorsState_l();
    if (mPoseController != nullptr) {
        mPoseController->setScreenSensor(mScreenSensor);
    }
    return Status::ok();
}

@@ -654,25 +655,20 @@ status_t Spatializer::attachOutput(audio_io_handle_t output, size_t numActiveTra
            return status;
        }

        checkEngineState_l();
        outputChanged = mOutput != output;
        mOutput = output;
        mNumActiveTracks = numActiveTracks;

        checkEngineState_l();
        if (mSupportsHeadTracking) {
            mPoseController = std::make_shared<SpatializerPoseController>(
                    static_cast<SpatializerPoseController::Listener*>(this), 10ms, 1000ms);
            LOG_ALWAYS_FATAL_IF(mPoseController == nullptr,
                                "%s could not allocate pose controller", __func__);

            mPoseController->setDesiredMode(mDesiredHeadTrackingMode);
            mNumActiveTracks = numActiveTracks;
            checkPoseController_l();
            checkSensorsState_l();
            mPoseController->setDisplayOrientation(mDisplayOrientation);
            poseController = mPoseController;
        }
        callback = mSpatializerCallback;
    }
    if (poseController != nullptr) {
        poseController->calculateAsync();
        poseController->waitUntilCalculated();
    }

@@ -747,6 +743,25 @@ void Spatializer::checkEngineState_l() {
    }
}

void Spatializer::checkPoseController_l() {
    bool isControllerNeeded = mDesiredHeadTrackingMode != HeadTrackingMode::STATIC
            && mHeadSensor != SpatializerPoseController::INVALID_SENSOR;

    if (isControllerNeeded && mPoseController == nullptr) {
        mPoseController = std::make_shared<SpatializerPoseController>(
                static_cast<SpatializerPoseController::Listener*>(this),
                10ms, std::chrono::microseconds::max());
        LOG_ALWAYS_FATAL_IF(mPoseController == nullptr,
                            "%s could not allocate pose controller", __func__);
        mPoseController->setDisplayOrientation(mDisplayOrientation);
    } else if (!isControllerNeeded && mPoseController != nullptr) {
        mPoseController.reset();
    }
    if (mPoseController != nullptr) {
        mPoseController->setDesiredMode(mDesiredHeadTrackingMode);
    }
}

void Spatializer::calculateHeadPose() {
    ALOGV("%s", __func__);
    std::lock_guard lock(mLock);
+6 −0
Original line number Diff line number Diff line
@@ -283,6 +283,12 @@ private:
     */
    void checkSensorsState_l() REQUIRES(mLock);

    /**
     * Checks if the head pose controller should be created or destroyed according
     * to desired head tracking mode.
     */
    void checkPoseController_l() REQUIRES(mLock);

    /**
     * Checks if the spatializer effect should be enabled based on
     * playback activity and requested level.