Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include "SpatializerPoseController.h" |
| 17 | |
Ytai Ben-Tsvi | e9b3495 | 2021-09-10 12:48:27 -0700 | [diff] [blame] | 18 | #define LOG_TAG "SpatializerPoseController" |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 20 | #include <sensor/Sensor.h> |
Andy Hung | a461a00 | 2022-05-17 10:36:02 -0700 | [diff] [blame] | 21 | #include <media/MediaMetricsItem.h> |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 22 | #include <utils/Log.h> |
| 23 | #include <utils/SystemClock.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | using media::createHeadTrackingProcessor; |
| 28 | using media::HeadTrackingMode; |
| 29 | using media::HeadTrackingProcessor; |
| 30 | using media::Pose3f; |
| 31 | using media::SensorPoseProvider; |
| 32 | using media::Twist3f; |
| 33 | |
| 34 | using namespace std::chrono_literals; |
| 35 | |
| 36 | namespace { |
| 37 | |
| 38 | // This is how fast, in m/s, we allow position to shift during rate-limiting. |
Ytai Ben-Tsvi | c2d2840 | 2022-01-14 14:55:16 -0800 | [diff] [blame] | 39 | constexpr float kMaxTranslationalVelocity = 2; |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 40 | |
| 41 | // This is how fast, in rad/s, we allow rotation angle to shift during rate-limiting. |
Ytai Ben-Tsvi | c2d2840 | 2022-01-14 14:55:16 -0800 | [diff] [blame] | 42 | constexpr float kMaxRotationalVelocity = 8; |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 43 | |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 44 | // This is how far into the future we predict the head pose, using linear extrapolation based on |
| 45 | // twist (velocity). It should be set to a value that matches the characteristic durations of moving |
| 46 | // one's head. The higher we set this, the more latency we are able to reduce, but setting this too |
| 47 | // high will result in high prediction errors whenever the head accelerates (changes velocity). |
Ytai Ben-Tsvi | 3c234b1 | 2022-01-31 11:15:17 -0800 | [diff] [blame] | 48 | constexpr auto kPredictionDuration = 50ms; |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 49 | |
Ytai Ben-Tsvi | e235684 | 2022-04-14 11:30:32 -0700 | [diff] [blame] | 50 | // After not getting a pose sample for this long, we would treat the measurement as stale. |
| 51 | constexpr auto kFreshnessTimeout = 50ms; |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 52 | |
Ytai Ben-Tsvi | 44e7c3d | 2021-12-15 16:04:01 -0800 | [diff] [blame] | 53 | // Auto-recenter kicks in after the head has been still for this long. |
Ytai Ben-Tsvi | cdc0306 | 2022-01-10 15:57:52 -0800 | [diff] [blame] | 54 | constexpr auto kAutoRecenterWindowDuration = 6s; |
Ytai Ben-Tsvi | 44e7c3d | 2021-12-15 16:04:01 -0800 | [diff] [blame] | 55 | |
| 56 | // Auto-recenter considers head not still if translated by this much (in meters, approx). |
| 57 | constexpr float kAutoRecenterTranslationThreshold = 0.1f; |
| 58 | |
| 59 | // Auto-recenter considers head not still if rotated by this much (in radians, approx). |
Ytai Ben-Tsvi | 237012c | 2022-02-16 15:54:31 -0800 | [diff] [blame] | 60 | constexpr float kAutoRecenterRotationThreshold = 10.5f / 180 * M_PI; |
Ytai Ben-Tsvi | 44e7c3d | 2021-12-15 16:04:01 -0800 | [diff] [blame] | 61 | |
Ytai Ben-Tsvi | c7e8a48 | 2021-12-20 13:26:34 -0800 | [diff] [blame] | 62 | // Screen is considered to be unstable (not still) if it has moved significantly within the last |
| 63 | // time window of this duration. |
Ytai Ben-Tsvi | cdc0306 | 2022-01-10 15:57:52 -0800 | [diff] [blame] | 64 | constexpr auto kScreenStillnessWindowDuration = 3s; |
Ytai Ben-Tsvi | c7e8a48 | 2021-12-20 13:26:34 -0800 | [diff] [blame] | 65 | |
| 66 | // Screen is considered to have moved significantly if translated by this much (in meter, approx). |
| 67 | constexpr float kScreenStillnessTranslationThreshold = 0.1f; |
| 68 | |
| 69 | // Screen is considered to have moved significantly if rotated by this much (in radians, approx). |
Ytai Ben-Tsvi | cdc0306 | 2022-01-10 15:57:52 -0800 | [diff] [blame] | 70 | constexpr float kScreenStillnessRotationThreshold = 7.0f / 180 * M_PI; |
Ytai Ben-Tsvi | c7e8a48 | 2021-12-20 13:26:34 -0800 | [diff] [blame] | 71 | |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 72 | // Time units for system clock ticks. This is what the Sensor Framework timestamps represent and |
| 73 | // what we use for pose filtering. |
| 74 | using Ticks = std::chrono::nanoseconds; |
| 75 | |
| 76 | // How many ticks in a second. |
| 77 | constexpr auto kTicksPerSecond = Ticks::period::den; |
| 78 | |
Andy Hung | a461a00 | 2022-05-17 10:36:02 -0700 | [diff] [blame] | 79 | std::string getSensorMetricsId(int32_t sensorId) { |
| 80 | return std::string(AMEDIAMETRICS_KEY_PREFIX_AUDIO_SENSOR).append(std::to_string(sensorId)); |
| 81 | } |
| 82 | |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 83 | } // namespace |
| 84 | |
| 85 | SpatializerPoseController::SpatializerPoseController(Listener* listener, |
Eric Laurent | e51f80e | 2022-04-14 10:20:38 +0200 | [diff] [blame] | 86 | std::chrono::microseconds sensorPeriod, |
| 87 | std::optional<std::chrono::microseconds> maxUpdatePeriod) |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 88 | : mListener(listener), |
| 89 | mSensorPeriod(sensorPeriod), |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 90 | mProcessor(createHeadTrackingProcessor(HeadTrackingProcessor::Options{ |
| 91 | .maxTranslationalVelocity = kMaxTranslationalVelocity / kTicksPerSecond, |
| 92 | .maxRotationalVelocity = kMaxRotationalVelocity / kTicksPerSecond, |
Ytai Ben-Tsvi | e235684 | 2022-04-14 11:30:32 -0700 | [diff] [blame] | 93 | .freshnessTimeout = Ticks(kFreshnessTimeout).count(), |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 94 | .predictionDuration = Ticks(kPredictionDuration).count(), |
Ytai Ben-Tsvi | 44e7c3d | 2021-12-15 16:04:01 -0800 | [diff] [blame] | 95 | .autoRecenterWindowDuration = Ticks(kAutoRecenterWindowDuration).count(), |
| 96 | .autoRecenterTranslationalThreshold = kAutoRecenterTranslationThreshold, |
| 97 | .autoRecenterRotationalThreshold = kAutoRecenterRotationThreshold, |
Ytai Ben-Tsvi | c7e8a48 | 2021-12-20 13:26:34 -0800 | [diff] [blame] | 98 | .screenStillnessWindowDuration = Ticks(kScreenStillnessWindowDuration).count(), |
| 99 | .screenStillnessTranslationalThreshold = kScreenStillnessTranslationThreshold, |
| 100 | .screenStillnessRotationalThreshold = kScreenStillnessRotationThreshold, |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 101 | })), |
Ytai Ben-Tsvi | 8b6fe3a | 2021-09-13 15:55:44 -0700 | [diff] [blame] | 102 | mPoseProvider(SensorPoseProvider::create("headtracker", this)), |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 103 | mThread([this, maxUpdatePeriod] { |
| 104 | while (true) { |
Ytai Ben-Tsvi | 7c2acd1 | 2021-09-09 15:50:00 -0700 | [diff] [blame] | 105 | Pose3f headToStage; |
| 106 | std::optional<HeadTrackingMode> modeIfChanged; |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 107 | { |
| 108 | std::unique_lock lock(mMutex); |
Eric Laurent | e51f80e | 2022-04-14 10:20:38 +0200 | [diff] [blame] | 109 | if (maxUpdatePeriod.has_value()) { |
| 110 | mCondVar.wait_for(lock, maxUpdatePeriod.value(), |
| 111 | [this] { return mShouldExit || mShouldCalculate; }); |
| 112 | } else { |
| 113 | mCondVar.wait(lock, [this] { return mShouldExit || mShouldCalculate; }); |
| 114 | } |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 115 | if (mShouldExit) { |
| 116 | ALOGV("Exiting thread"); |
| 117 | return; |
| 118 | } |
Ytai Ben-Tsvi | 7c2acd1 | 2021-09-09 15:50:00 -0700 | [diff] [blame] | 119 | |
| 120 | // Calculate. |
| 121 | std::tie(headToStage, modeIfChanged) = calculate_l(); |
| 122 | } |
| 123 | |
| 124 | // Invoke the callbacks outside the lock. |
| 125 | mListener->onHeadToStagePose(headToStage); |
| 126 | if (modeIfChanged) { |
| 127 | mListener->onActualModeChange(modeIfChanged.value()); |
| 128 | } |
| 129 | |
| 130 | { |
| 131 | std::lock_guard lock(mMutex); |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 132 | if (!mCalculated) { |
| 133 | mCalculated = true; |
| 134 | mCondVar.notify_all(); |
| 135 | } |
| 136 | mShouldCalculate = false; |
| 137 | } |
| 138 | } |
| 139 | }) {} |
| 140 | |
| 141 | SpatializerPoseController::~SpatializerPoseController() { |
| 142 | { |
| 143 | std::unique_lock lock(mMutex); |
| 144 | mShouldExit = true; |
| 145 | mCondVar.notify_all(); |
| 146 | } |
| 147 | mThread.join(); |
| 148 | } |
| 149 | |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 150 | void SpatializerPoseController::setHeadSensor(int32_t sensor) { |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 151 | std::lock_guard lock(mMutex); |
Andy Hung | ba2a61a | 2022-05-20 12:00:28 -0700 | [diff] [blame^] | 152 | if (sensor == mHeadSensor) return; |
| 153 | ALOGV("%s: new sensor:%d mHeadSensor:%d mScreenSensor:%d", |
| 154 | __func__, sensor, mHeadSensor, mScreenSensor); |
| 155 | |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 156 | // Stop current sensor, if valid and different from the other sensor. |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 157 | if (mHeadSensor != INVALID_SENSOR && mHeadSensor != mScreenSensor) { |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 158 | mPoseProvider->stopSensor(mHeadSensor); |
Andy Hung | a461a00 | 2022-05-17 10:36:02 -0700 | [diff] [blame] | 159 | mediametrics::LogItem(getSensorMetricsId(mHeadSensor)) |
| 160 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_STOP) |
| 161 | .record(); |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 162 | } |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 163 | |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 164 | if (sensor != INVALID_SENSOR) { |
| 165 | if (sensor != mScreenSensor) { |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 166 | // Start new sensor. |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 167 | mHeadSensor = |
| 168 | mPoseProvider->startSensor(sensor, mSensorPeriod) ? sensor : INVALID_SENSOR; |
Andy Hung | a461a00 | 2022-05-17 10:36:02 -0700 | [diff] [blame] | 169 | if (mHeadSensor != INVALID_SENSOR) { |
| 170 | auto sensor = mPoseProvider->getSensorByHandle(mHeadSensor); |
| 171 | std::string stringType = sensor ? sensor->getStringType().c_str() : ""; |
| 172 | mediametrics::LogItem(getSensorMetricsId(mHeadSensor)) |
| 173 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_START) |
| 174 | .set(AMEDIAMETRICS_PROP_MODE, AMEDIAMETRICS_PROP_MODE_VALUE_HEAD) |
| 175 | .set(AMEDIAMETRICS_PROP_TYPE, stringType) |
| 176 | .record(); |
| 177 | } |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 178 | } else { |
| 179 | // Sensor is already enabled. |
| 180 | mHeadSensor = mScreenSensor; |
| 181 | } |
| 182 | } else { |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 183 | mHeadSensor = INVALID_SENSOR; |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Andy Hung | ba2a61a | 2022-05-20 12:00:28 -0700 | [diff] [blame^] | 186 | mProcessor->recenter(true /* recenterHead */, false /* recenterScreen */); |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 189 | void SpatializerPoseController::setScreenSensor(int32_t sensor) { |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 190 | std::lock_guard lock(mMutex); |
Andy Hung | ba2a61a | 2022-05-20 12:00:28 -0700 | [diff] [blame^] | 191 | if (sensor == mScreenSensor) return; |
| 192 | ALOGV("%s: new sensor:%d mHeadSensor:%d mScreenSensor:%d", |
| 193 | __func__, sensor, mHeadSensor, mScreenSensor); |
| 194 | |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 195 | // Stop current sensor, if valid and different from the other sensor. |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 196 | if (mScreenSensor != INVALID_SENSOR && mScreenSensor != mHeadSensor) { |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 197 | mPoseProvider->stopSensor(mScreenSensor); |
Andy Hung | a461a00 | 2022-05-17 10:36:02 -0700 | [diff] [blame] | 198 | mediametrics::LogItem(getSensorMetricsId(mScreenSensor)) |
| 199 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_STOP) |
| 200 | .record(); |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 201 | } |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 202 | |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 203 | if (sensor != INVALID_SENSOR) { |
| 204 | if (sensor != mHeadSensor) { |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 205 | // Start new sensor. |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 206 | mScreenSensor = |
| 207 | mPoseProvider->startSensor(sensor, mSensorPeriod) ? sensor : INVALID_SENSOR; |
Andy Hung | a461a00 | 2022-05-17 10:36:02 -0700 | [diff] [blame] | 208 | auto sensor = mPoseProvider->getSensorByHandle(mScreenSensor); |
| 209 | std::string stringType = sensor ? sensor->getStringType().c_str() : ""; |
| 210 | mediametrics::LogItem(getSensorMetricsId(mScreenSensor)) |
| 211 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_START) |
| 212 | .set(AMEDIAMETRICS_PROP_MODE, AMEDIAMETRICS_PROP_MODE_VALUE_SCREEN) |
| 213 | .set(AMEDIAMETRICS_PROP_TYPE, stringType) |
| 214 | .record(); |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 215 | } else { |
| 216 | // Sensor is already enabled. |
| 217 | mScreenSensor = mHeadSensor; |
| 218 | } |
| 219 | } else { |
Ytai Ben-Tsvi | 9f12f17 | 2021-09-23 16:47:25 -0700 | [diff] [blame] | 220 | mScreenSensor = INVALID_SENSOR; |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Andy Hung | ba2a61a | 2022-05-20 12:00:28 -0700 | [diff] [blame^] | 223 | mProcessor->recenter(false /* recenterHead */, true /* recenterScreen */); |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void SpatializerPoseController::setDesiredMode(HeadTrackingMode mode) { |
| 227 | std::lock_guard lock(mMutex); |
| 228 | mProcessor->setDesiredMode(mode); |
| 229 | } |
| 230 | |
| 231 | void SpatializerPoseController::setScreenToStagePose(const Pose3f& screenToStage) { |
| 232 | std::lock_guard lock(mMutex); |
| 233 | mProcessor->setScreenToStagePose(screenToStage); |
| 234 | } |
| 235 | |
| 236 | void SpatializerPoseController::setDisplayOrientation(float physicalToLogicalAngle) { |
| 237 | std::lock_guard lock(mMutex); |
| 238 | mProcessor->setDisplayOrientation(physicalToLogicalAngle); |
| 239 | } |
| 240 | |
| 241 | void SpatializerPoseController::calculateAsync() { |
| 242 | std::lock_guard lock(mMutex); |
| 243 | mShouldCalculate = true; |
| 244 | mCondVar.notify_all(); |
| 245 | } |
| 246 | |
| 247 | void SpatializerPoseController::waitUntilCalculated() { |
| 248 | std::unique_lock lock(mMutex); |
| 249 | mCondVar.wait(lock, [this] { return mCalculated; }); |
| 250 | } |
| 251 | |
Ytai Ben-Tsvi | 7c2acd1 | 2021-09-09 15:50:00 -0700 | [diff] [blame] | 252 | std::tuple<media::Pose3f, std::optional<media::HeadTrackingMode>> |
| 253 | SpatializerPoseController::calculate_l() { |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 254 | Pose3f headToStage; |
| 255 | HeadTrackingMode mode; |
Ytai Ben-Tsvi | 7c2acd1 | 2021-09-09 15:50:00 -0700 | [diff] [blame] | 256 | std::optional<media::HeadTrackingMode> modeIfChanged; |
| 257 | |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 258 | mProcessor->calculate(elapsedRealtimeNano()); |
| 259 | headToStage = mProcessor->getHeadToStagePose(); |
| 260 | mode = mProcessor->getActualMode(); |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 261 | if (!mActualMode.has_value() || mActualMode.value() != mode) { |
| 262 | mActualMode = mode; |
Ytai Ben-Tsvi | 7c2acd1 | 2021-09-09 15:50:00 -0700 | [diff] [blame] | 263 | modeIfChanged = mode; |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 264 | } |
Ytai Ben-Tsvi | 7c2acd1 | 2021-09-09 15:50:00 -0700 | [diff] [blame] | 265 | return std::make_tuple(headToStage, modeIfChanged); |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void SpatializerPoseController::recenter() { |
| 269 | std::lock_guard lock(mMutex); |
| 270 | mProcessor->recenter(); |
| 271 | } |
| 272 | |
| 273 | void SpatializerPoseController::onPose(int64_t timestamp, int32_t sensor, const Pose3f& pose, |
Ytai Ben-Tsvi | 2c694be | 2021-10-06 17:12:49 -0700 | [diff] [blame] | 274 | const std::optional<Twist3f>& twist, bool isNewReference) { |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 275 | std::lock_guard lock(mMutex); |
| 276 | if (sensor == mHeadSensor) { |
Ytai Ben-Tsvi | 3c234b1 | 2022-01-31 11:15:17 -0800 | [diff] [blame] | 277 | mProcessor->setWorldToHeadPose(timestamp, pose, |
| 278 | twist.value_or(Twist3f()) / kTicksPerSecond); |
Ytai Ben-Tsvi | 2c694be | 2021-10-06 17:12:49 -0700 | [diff] [blame] | 279 | if (isNewReference) { |
| 280 | mProcessor->recenter(true, false); |
| 281 | } |
Ytai Ben-Tsvi | 9bae742 | 2021-08-27 16:13:19 -0700 | [diff] [blame] | 282 | } |
| 283 | if (sensor == mScreenSensor) { |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 284 | mProcessor->setWorldToScreenPose(timestamp, pose); |
Ytai Ben-Tsvi | 2c694be | 2021-10-06 17:12:49 -0700 | [diff] [blame] | 285 | if (isNewReference) { |
| 286 | mProcessor->recenter(false, true); |
| 287 | } |
Ytai Ben-Tsvi | d83c42d | 2021-08-25 14:19:34 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| 291 | } // namespace android |