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

Commit 73f80c33 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7724743 from e9b34958 to sc-v2-release

Change-Id: Ic94ae3e536af103c17248e0f7eeedf90f3c84c62
parents a2ee559b e9b34958
Loading
Loading
Loading
Loading
+24 −22
Original line number Diff line number Diff line
@@ -61,31 +61,33 @@ static constexpr size_t kFrameCount = 1000;

/*
Pixel 4XL
$ adb shell /data/benchmarktest/downmix_benchmark/vendor/downmix_benchmark

--------------------------------------------------------
Benchmark              Time             CPU   Iterations
--------------------------------------------------------
BM_Downmix/0        2845 ns         2839 ns       246585 AUDIO_CHANNEL_OUT_MONO
BM_Downmix/1        2844 ns         2838 ns       246599
BM_Downmix/2        3727 ns         3719 ns       188227 AUDIO_CHANNEL_OUT_STEREO
BM_Downmix/3        4609 ns         4600 ns       152148 AUDIO_CHANNEL_OUT_2POINT1
BM_Downmix/4        3727 ns         3719 ns       188228 AUDIO_CHANNEL_OUT_2POINT0POINT2
BM_Downmix/5        1787 ns         1784 ns       392384 AUDIO_CHANNEL_OUT_QUAD
BM_Downmix/6        1787 ns         1783 ns       392527 AUDIO_CHANNEL_OUT_QUAD_SIDE
BM_Downmix/7        5493 ns         5481 ns       127740 AUDIO_CHANNEL_OUT_SURROUND
BM_Downmix/8        4610 ns         4600 ns       152168 AUDIO_CHANNEL_OUT_2POINT1POINT2
BM_Downmix/9        4610 ns         4600 ns       152162 AUDIO_CHANNEL_OUT_3POINT0POINT2
BM_Downmix/10       6377 ns         6362 ns       110042 AUDIO_CHANNEL_OUT_PENTA
BM_Downmix/11       5493 ns         5481 ns       127683 AUDIO_CHANNEL_OUT_3POINT1POINT2
BM_Downmix/12       2758 ns         2752 ns       251488 AUDIO_CHANNEL_OUT_5POINT1
BM_Downmix/13       2683 ns         2677 ns       261421 AUDIO_CHANNEL_OUT_5POINT1_SIDE
BM_Downmix/14       8141 ns         8124 ns        86157 AUDIO_CHANNEL_OUT_6POINT1
BM_Downmix/15       7265 ns         7249 ns        96554 AUDIO_CHANNEL_OUT_5POINT1POINT2
BM_Downmix/16       3158 ns         3151 ns       222188 AUDIO_CHANNEL_OUT_7POINT1
BM_Downmix/17       7291 ns         7276 ns        96226 AUDIO_CHANNEL_OUT_5POINT1POINT4
BM_Downmix/18       9050 ns         9031 ns        77512 AUDIO_CHANNEL_OUT_7POINT1POINT2
BM_Downmix/19       9056 ns         9036 ns        77467 AUDIO_CHANNEL_OUT_7POINT1POINT4
BM_Downmix/20       6426 ns         6412 ns       109164 AUDIO_CHANNEL_OUT_13POINT_360RA
BM_Downmix/21      11743 ns        11716 ns        59762 AUDIO_CHANNEL_OUT_22POINT2
BM_Downmix/0        3638 ns         3624 ns       197517 AUDIO_CHANNEL_OUT_MONO
BM_Downmix/1        4040 ns         4024 ns       178766
BM_Downmix/2        4759 ns         4740 ns       134741 AUDIO_CHANNEL_OUT_STEREO
BM_Downmix/3        6042 ns         6017 ns       129546 AUDIO_CHANNEL_OUT_2POINT1
BM_Downmix/4        6897 ns         6868 ns        96316 AUDIO_CHANNEL_OUT_2POINT0POINT2
BM_Downmix/5        2117 ns         2109 ns       331705 AUDIO_CHANNEL_OUT_QUAD
BM_Downmix/6        2097 ns         2088 ns       335421 AUDIO_CHANNEL_OUT_QUAD_SIDE
BM_Downmix/7        7291 ns         7263 ns        96256 AUDIO_CHANNEL_OUT_SURROUND
BM_Downmix/8        8246 ns         8206 ns        84318 AUDIO_CHANNEL_OUT_2POINT1POINT2
BM_Downmix/9        8341 ns         8303 ns        84298 AUDIO_CHANNEL_OUT_3POINT0POINT2
BM_Downmix/10       7549 ns         7517 ns        84293 AUDIO_CHANNEL_OUT_PENTA
BM_Downmix/11       9395 ns         9354 ns        75209 AUDIO_CHANNEL_OUT_3POINT1POINT2
BM_Downmix/12       3267 ns         3253 ns       215596 AUDIO_CHANNEL_OUT_5POINT1
BM_Downmix/13       3178 ns         3163 ns       220132 AUDIO_CHANNEL_OUT_5POINT1_SIDE
BM_Downmix/14      10245 ns        10199 ns        67486 AUDIO_CHANNEL_OUT_6POINT1
BM_Downmix/15      10975 ns        10929 ns        61359 AUDIO_CHANNEL_OUT_5POINT1POINT2
BM_Downmix/16       3796 ns         3780 ns       184728 AUDIO_CHANNEL_OUT_7POINT1
BM_Downmix/17      13562 ns        13503 ns        51823 AUDIO_CHANNEL_OUT_5POINT1POINT4
BM_Downmix/18      13573 ns        13516 ns        51800 AUDIO_CHANNEL_OUT_7POINT1POINT2
BM_Downmix/19      15502 ns        15435 ns        47147 AUDIO_CHANNEL_OUT_7POINT1POINT4
BM_Downmix/20      16693 ns        16624 ns        42109 AUDIO_CHANNEL_OUT_13POINT_360RA
BM_Downmix/21      28267 ns        28116 ns        24982 AUDIO_CHANNEL_OUT_22POINT2
*/

static void BM_Downmix(benchmark::State& state) {
+76 −37
Original line number Diff line number Diff line
@@ -52,34 +52,63 @@ static constexpr audio_channel_mask_t kChannelPositionMasks[] = {
    AUDIO_CHANNEL_OUT_22POINT2,
};

static constexpr audio_channel_mask_t kConsideredChannels =
    (audio_channel_mask_t)(AUDIO_CHANNEL_OUT_7POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER);
constexpr float COEF_25 = 0.2508909536f;
constexpr float COEF_35 = 0.3543928915f;
constexpr float COEF_36 = 0.3552343859f;
constexpr float COEF_61 = 0.6057043428f;

constexpr inline float kScaleFromChannelIdx[] = {
constexpr inline float kScaleFromChannelIdxLeft[] = {
    1.f,       // AUDIO_CHANNEL_OUT_FRONT_LEFT            = 0x1u,
    1.f,       // AUDIO_CHANNEL_OUT_FRONT_RIGHT           = 0x2u,
    0.f,       // AUDIO_CHANNEL_OUT_FRONT_RIGHT           = 0x2u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_FRONT_CENTER          = 0x4u,
    0.5f,      // AUDIO_CHANNEL_OUT_LOW_FREQUENCY         = 0x8u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_BACK_LEFT             = 0x10u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_BACK_RIGHT            = 0x20u,
    0,         // AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER  = 0x40u,
    0,         // AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80u,
    0.f,       // AUDIO_CHANNEL_OUT_BACK_RIGHT            = 0x20u,
    COEF_61,   // AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER  = 0x40u,
    COEF_25,   // AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80u,
    0.5f,      // AUDIO_CHANNEL_OUT_BACK_CENTER           = 0x100u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_SIDE_LEFT             = 0x200u,
    0.f,       // AUDIO_CHANNEL_OUT_SIDE_RIGHT            = 0x400u,
    COEF_36,   // AUDIO_CHANNEL_OUT_TOP_CENTER            = 0x800u,
    1.f,       // AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT        = 0x1000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER      = 0x2000u,
    0.f,       // AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT       = 0x4000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_TOP_BACK_LEFT         = 0x8000u,
    COEF_35,   // AUDIO_CHANNEL_OUT_TOP_BACK_CENTER       = 0x10000u,
    0.f,       // AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT        = 0x20000u,
    COEF_61,   // AUDIO_CHANNEL_OUT_TOP_SIDE_LEFT         = 0x40000u,
    0.f,       // AUDIO_CHANNEL_OUT_TOP_SIDE_RIGHT        = 0x80000u,
    1.f,       // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_LEFT     = 0x100000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_CENTER   = 0x200000u,
    0.f, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_RIGHT    = 0x400000u,
    0.f, // AUDIO_CHANNEL_OUT_LOW_FREQUENCY_2       = 0x800000u,
};

constexpr inline float kScaleFromChannelIdxRight[] = {
    0.f,       // AUDIO_CHANNEL_OUT_FRONT_LEFT            = 0x1u,
    1.f,       // AUDIO_CHANNEL_OUT_FRONT_RIGHT           = 0x2u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_FRONT_CENTER          = 0x4u,
    0.5f,      // AUDIO_CHANNEL_OUT_LOW_FREQUENCY         = 0x8u,
    0.f,       // AUDIO_CHANNEL_OUT_BACK_LEFT             = 0x10u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_BACK_RIGHT            = 0x20u,
    COEF_25,   // AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER  = 0x40u,
    COEF_61,   // AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80u,
    0.5f,      // AUDIO_CHANNEL_OUT_BACK_CENTER           = 0x100u,
    0.f,       // AUDIO_CHANNEL_OUT_SIDE_LEFT             = 0x200u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_SIDE_RIGHT            = 0x400u,
    0, // AUDIO_CHANNEL_OUT_TOP_CENTER            = 0x800u,
    0, // AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT        = 0x1000u,
    0, // AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER      = 0x2000u,
    0, // AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT       = 0x4000u,
    0, // AUDIO_CHANNEL_OUT_TOP_BACK_LEFT         = 0x8000u,
    0, // AUDIO_CHANNEL_OUT_TOP_BACK_CENTER       = 0x10000u,
    0, // AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT        = 0x20000u,
    0, // AUDIO_CHANNEL_OUT_TOP_SIDE_LEFT         = 0x40000u,
    0, // AUDIO_CHANNEL_OUT_TOP_SIDE_RIGHT        = 0x80000u,
    0, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_LEFT     = 0x100000u,
    0, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_CENTER   = 0x200000u,
    0, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_RIGHT    = 0x400000u,
    0, // AUDIO_CHANNEL_OUT_LOW_FREQUENCY_2       = 0x800000u,
    COEF_36,   // AUDIO_CHANNEL_OUT_TOP_CENTER            = 0x800u,
    0.f,       // AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT        = 0x1000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER      = 0x2000u,
    1.f,       // AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT       = 0x4000u,
    0.f,       // AUDIO_CHANNEL_OUT_TOP_BACK_LEFT         = 0x8000u,
    COEF_35,   // AUDIO_CHANNEL_OUT_TOP_BACK_CENTER       = 0x10000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT        = 0x20000u,
    0.f,       // AUDIO_CHANNEL_OUT_TOP_SIDE_LEFT         = 0x40000u,
    COEF_61,   // AUDIO_CHANNEL_OUT_TOP_SIDE_RIGHT        = 0x80000u,
    0.f,       // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_LEFT     = 0x100000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_CENTER   = 0x200000u,
    1.f,       // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_RIGHT    = 0x400000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_LOW_FREQUENCY_2       = 0x800000u,
};

// Downmix doesn't change with sample rate
@@ -155,30 +184,40 @@ public:
            savedPower[index][0] = power[0];
            savedPower[index][1] = power[1];

            // Confirm exactly the mix amount prescribed by the existing downmix effect.
            // For future changes to the downmix effect, the nearness needs to be relaxed
            // to compare behavior S or earlier.
            if ((channelBit & kConsideredChannels) == 0) {
                // for channels not considered, expect 0 power for legacy downmix
                EXPECT_EQ(0.f, power[0]);
                EXPECT_EQ(0.f, power[1]);
                continue;
            }

            constexpr float POWER_TOLERANCE = 0.001;
            const float expectedPower = kScaleFromChannelIdx[index] * kScaleFromChannelIdx[index];
            const float expectedPower =
                    kScaleFromChannelIdxLeft[index] * kScaleFromChannelIdxLeft[index]
                    + kScaleFromChannelIdxRight[index] * kScaleFromChannelIdxRight[index];
            EXPECT_NEAR(expectedPower, power[0] + power[1], POWER_TOLERANCE);
            switch (side) {
            case AUDIO_GEOMETRY_SIDE_LEFT:
                EXPECT_EQ(0.f, power[1]); // always true
                EXPECT_NEAR(expectedPower, power[0], POWER_TOLERANCE);
                if (channelBit == AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER) {
                    break;
                }
                EXPECT_EQ(0.f, power[1]);
                break;
            case AUDIO_GEOMETRY_SIDE_RIGHT:
                EXPECT_EQ(0.f, power[0]); // always true
                EXPECT_NEAR(expectedPower, power[1], POWER_TOLERANCE);
                if (channelBit == AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER) {
                    break;
                }
                EXPECT_EQ(0.f, power[0]);
                break;
            case AUDIO_GEOMETRY_SIDE_CENTER:
                if (channelBit == AUDIO_CHANNEL_OUT_LOW_FREQUENCY) {
                    if (channelMask & AUDIO_CHANNEL_OUT_LOW_FREQUENCY_2) {
                        EXPECT_EQ(0.f, power[1]);
                        break;
                    } else {
                        EXPECT_NEAR_EPSILON(power[0], power[1]); // always true
                EXPECT_NEAR(expectedPower, power[0], POWER_TOLERANCE);
                        EXPECT_NEAR(expectedPower, power[0] + power[1], POWER_TOLERANCE);
                        break;
                    }
                } else if (channelBit == AUDIO_CHANNEL_OUT_LOW_FREQUENCY_2) {
                    EXPECT_EQ(0.f, power[0]);
                    EXPECT_NEAR(expectedPower, power[1], POWER_TOLERANCE);
                    break;
                }
                EXPECT_NEAR_EPSILON(power[0], power[1]);
                break;
            }
        }
+10 −8
Original line number Diff line number Diff line
@@ -101,6 +101,8 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
    }

    ~SensorPoseProviderImpl() override {
        // Disable all active sensors.
        mEnabledSensors.clear();
        ALooper_wake(mLooper);
        mThread.join();
    }
@@ -109,12 +111,12 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
        int32_t handle = ASensor_getHandle(sensor);

        // Enable the sensor.
        if (ASensorEventQueue_registerSensor(mQueue->get(), sensor, samplingPeriod.count(), 0)) {
        if (ASensorEventQueue_registerSensor(mQueue, sensor, samplingPeriod.count(), 0)) {
            ALOGE("Failed to enable sensor");
            return INVALID_HANDLE;
        }

        mEnabledSensors.emplace(handle, SensorEnableGuard(mQueue->get(), sensor));
        mEnabledSensors.emplace(handle, SensorEnableGuard(mQueue, sensor));
        return handle;
    }

@@ -123,9 +125,10 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
  private:
    ALooper* mLooper;
    Listener* const mListener;

    std::thread mThread;
    std::map<int32_t, SensorEnableGuard> mEnabledSensors;
    std::unique_ptr<EventQueueGuard> mQueue;
    ASensorEventQueue* mQueue;

    // We must do some of the initialization operations on the worker thread, because the API relies
    // on the thread-local looper. In addition, as a matter of convenience, we store some of the
@@ -159,16 +162,15 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
        }

        // Create event queue.
        ASensorEventQueue* queue =
                ASensorManager_createEventQueue(sensor_manager, mLooper, kIdent, nullptr, nullptr);
        mQueue = ASensorManager_createEventQueue(sensor_manager, mLooper, kIdent, nullptr, nullptr);

        if (queue == nullptr) {
        if (mQueue == nullptr) {
            ALOGE("Failed to create a sensor event queue");
            initFinished(false);
            return;
        }

        mQueue.reset(new EventQueueGuard(sensor_manager, queue));
        EventQueueGuard eventQueueGuard(sensor_manager, mQueue);

        initFinished(true);

@@ -190,7 +192,7 @@ class SensorPoseProviderImpl : public SensorPoseProvider {

            // Process an event.
            ASensorEvent event;
            ssize_t size = ASensorEventQueue_getEvents(queue, &event, 1);
            ssize_t size = ASensorEventQueue_getEvents(mQueue, &event, 1);
            if (size < 0 || size > 1) {
                ALOGE("Unexpected return value from ASensorEventQueue_getEvents: %zd", size);
                break;
+27 −10
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
 */
#include "SpatializerPoseController.h"

#define LOG_TAG "VirtualizerStageController"
#define LOG_TAG "SpatializerPoseController"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
#include <utils/SystemClock.h>
@@ -88,6 +88,8 @@ SpatializerPoseController::SpatializerPoseController(Listener* listener,
      })),
      mThread([this, maxUpdatePeriod] {
          while (true) {
              Pose3f headToStage;
              std::optional<HeadTrackingMode> modeIfChanged;
              {
                  std::unique_lock lock(mMutex);
                  mCondVar.wait_for(lock, maxUpdatePeriod,
@@ -96,7 +98,19 @@ SpatializerPoseController::SpatializerPoseController(Listener* listener,
                      ALOGV("Exiting thread");
                      return;
                  }
                  calculate_l();

                  // Calculate.
                  std::tie(headToStage, modeIfChanged) = calculate_l();
              }

              // Invoke the callbacks outside the lock.
              mListener->onHeadToStagePose(headToStage);
              if (modeIfChanged) {
                  mListener->onActualModeChange(modeIfChanged.value());
              }

              {
                  std::lock_guard lock(mMutex);
                  if (!mCalculated) {
                      mCalculated = true;
                      mCondVar.notify_all();
@@ -185,17 +199,20 @@ void SpatializerPoseController::waitUntilCalculated() {
    mCondVar.wait(lock, [this] { return mCalculated; });
}

void SpatializerPoseController::calculate_l() {
std::tuple<media::Pose3f, std::optional<media::HeadTrackingMode>>
SpatializerPoseController::calculate_l() {
    Pose3f headToStage;
    HeadTrackingMode mode;
    std::optional<media::HeadTrackingMode> modeIfChanged;

    mProcessor->calculate(elapsedRealtimeNano());
    headToStage = mProcessor->getHeadToStagePose();
    mode = mProcessor->getActualMode();
    mListener->onHeadToStagePose(headToStage);
    if (!mActualMode.has_value() || mActualMode.value() != mode) {
        mActualMode = mode;
        mListener->onActualModeChange(mode);
        modeIfChanged = mode;
    }
    return std::make_tuple(headToStage, modeIfChanged);
}

void SpatializerPoseController::recenter() {
+8 −6
Original line number Diff line number Diff line
@@ -38,15 +38,13 @@ namespace android {
 * - By setting a timeout in the ctor, a calculation will be triggered after the timeout elapsed
 *   from the last calculateAsync() call.
 *
 * This class is thread-safe. Callbacks are invoked with the lock held, so it is illegal to call
 * into this module from the callbacks.
 * This class is thread-safe.
 */
class SpatializerPoseController : private media::SensorPoseProvider::Listener {
  public:
    /**
     * Listener interface for getting pose and mode updates.
     * Methods will always be invoked from a designated thread. Calling into the parent class from
     * within the callbacks is disallowed (will result in a deadlock).
     * Methods will always be invoked from a designated thread.
     */
    class Listener {
      public:
@@ -109,7 +107,7 @@ class SpatializerPoseController : private media::SensorPoseProvider::Listener {

    /**
     * Blocks until calculation and invocation of the respective callbacks has happened at least
     * once.
     * once. Do not call from within callbacks.
     */
    void waitUntilCalculated();

@@ -131,7 +129,11 @@ class SpatializerPoseController : private media::SensorPoseProvider::Listener {
    void onPose(int64_t timestamp, int32_t sensor, const media::Pose3f& pose,
                const std::optional<media::Twist3f>& twist) override;

    void calculate_l();
    /**
     * Calculates the new outputs and updates internal state. Must be called with the lock held.
     * Returns values that should be passed to the respective callbacks.
     */
    std::tuple<media::Pose3f, std::optional<media::HeadTrackingMode>> calculate_l();
};

}  // namespace android