Loading media/libheadtracking/SensorPoseProvider.cpp +27 −13 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ using android::base::StringAppendF; // Identifier to use for our event queue on the loop. // The number 19 is arbitrary, only useful if using multiple objects on the same looper. // Note: Instead of a fixed number, the SensorEventQueue's fd could be used instead. constexpr int kIdent = 19; static inline Looper* ALooper_to_Looper(ALooper* alooper) { Loading @@ -60,7 +61,8 @@ class EventQueueGuard { EventQueueGuard(const sp<SensorEventQueue>& queue, Looper* looper) : mQueue(queue) { mQueue->looper = Looper_to_ALooper(looper); mQueue->requestAdditionalInfo = false; looper->addFd(mQueue->getFd(), kIdent, ALOOPER_EVENT_INPUT, nullptr, nullptr); looper->addFd(mQueue->getFd(), kIdent, ALOOPER_EVENT_INPUT, nullptr /* callback */, nullptr /* data */); } ~EventQueueGuard() { Loading @@ -75,7 +77,7 @@ class EventQueueGuard { [[nodiscard]] SensorEventQueue* get() const { return mQueue.get(); } private: sp<SensorEventQueue> mQueue; const sp<SensorEventQueue> mQueue; }; /** Loading @@ -95,10 +97,7 @@ class SensorEnableGuard { } } SensorEnableGuard(const SensorEnableGuard&) = delete; SensorEnableGuard& operator=(const SensorEnableGuard&) = delete; // Enable moving. // Enable move and delete default copy-ctor/copy-assignment. SensorEnableGuard(SensorEnableGuard&& other) : mQueue(other.mQueue), mSensor(other.mSensor) { other.mSensor = SensorPoseProvider::INVALID_HANDLE; } Loading Loading @@ -131,7 +130,7 @@ class SensorPoseProviderImpl : public SensorPoseProvider { // Figure out the sensor's data format. DataFormat format = getSensorFormat(sensor); if (format == DataFormat::kUnknown) { ALOGE("Unknown format for sensor %" PRId32, sensor); ALOGE("%s: Unknown format for sensor %" PRId32, __func__, sensor); return false; } Loading @@ -145,17 +144,19 @@ class SensorPoseProviderImpl : public SensorPoseProvider { // Enable the sensor. if (mQueue->enableSensor(sensor, samplingPeriod.count(), 0, 0)) { ALOGE("Failed to enable sensor"); ALOGE("%s: Failed to enable sensor %" PRId32, __func__, sensor); std::lock_guard lock(mMutex); mEnabledSensorsExtra.erase(sensor); return false; } mEnabledSensors.emplace(sensor, SensorEnableGuard(mQueue.get(), sensor)); mEnabledSensors.emplace(sensor, SensorEnableGuard(mQueue, sensor)); ALOGD("%s: Sensor %" PRId32 " started", __func__, sensor); return true; } void stopSensor(int handle) override { ALOGD("%s: Sensor %" PRId32 " stopped", __func__, handle); mEnabledSensors.erase(handle); std::lock_guard lock(mMutex); mEnabledSensorsExtra.erase(handle); Loading Loading @@ -223,9 +224,9 @@ class SensorPoseProviderImpl : public SensorPoseProvider { Listener* const mListener; SensorManager* const mSensorManager; std::timed_mutex mMutex; sp<SensorEventQueue> mQueue; std::map<int32_t, SensorEnableGuard> mEnabledSensors; std::map<int32_t, SensorExtra> mEnabledSensorsExtra GUARDED_BY(mMutex); sp<SensorEventQueue> 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 Loading @@ -246,7 +247,13 @@ class SensorPoseProviderImpl : public SensorPoseProvider { bool waitInitFinished() { return mInitPromise.get_future().get(); } void threadFunc() { // Obtain looper. // Name our std::thread to help identification. As is, canCallJava == false. androidSetThreadName("SensorPoseProvider-looper"); // Run at the highest non-realtime priority. androidSetThreadPriority(gettid(), PRIORITY_URGENT_AUDIO); // The looper is started on the created std::thread. mLooper = Looper::prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); // Create event queue. Loading @@ -263,7 +270,8 @@ class SensorPoseProviderImpl : public SensorPoseProvider { initFinished(true); while (!mQuit) { int ret = mLooper->pollOnce(-1 /* no timeout */, nullptr, nullptr, nullptr); const int ret = mLooper->pollOnce(-1 /* no timeout */, nullptr /* outFd */, nullptr /* outEvents */, nullptr /* outData */); switch (ret) { case ALOOPER_POLL_WAKE: Loading @@ -276,7 +284,13 @@ class SensorPoseProviderImpl : public SensorPoseProvider { break; default: ALOGE("Unexpected status out of Looper::pollOnce: %d", ret); // Besides WAKE and kIdent, there should be no timeouts, callbacks, // ALOOPER_POLL_ERROR, or other events. // Exit now to avoid high frequency log spam on error, // e.g. if the fd becomes invalid (b/31093485). ALOGE("%s: Unexpected status out of Looper::pollOnce: %d", __func__, ret); mQuit = true; continue; } // Process an event. Loading services/audiopolicy/service/Spatializer.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -263,7 +263,7 @@ void Spatializer::onFirstRef() { mLooper->start( /*runOnCallingThread*/false, /*canCallJava*/ false, PRIORITY_AUDIO); PRIORITY_URGENT_AUDIO); mHandler = new EngineCallbackHandler(this); mLooper->registerHandler(mHandler); Loading Loading
media/libheadtracking/SensorPoseProvider.cpp +27 −13 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ using android::base::StringAppendF; // Identifier to use for our event queue on the loop. // The number 19 is arbitrary, only useful if using multiple objects on the same looper. // Note: Instead of a fixed number, the SensorEventQueue's fd could be used instead. constexpr int kIdent = 19; static inline Looper* ALooper_to_Looper(ALooper* alooper) { Loading @@ -60,7 +61,8 @@ class EventQueueGuard { EventQueueGuard(const sp<SensorEventQueue>& queue, Looper* looper) : mQueue(queue) { mQueue->looper = Looper_to_ALooper(looper); mQueue->requestAdditionalInfo = false; looper->addFd(mQueue->getFd(), kIdent, ALOOPER_EVENT_INPUT, nullptr, nullptr); looper->addFd(mQueue->getFd(), kIdent, ALOOPER_EVENT_INPUT, nullptr /* callback */, nullptr /* data */); } ~EventQueueGuard() { Loading @@ -75,7 +77,7 @@ class EventQueueGuard { [[nodiscard]] SensorEventQueue* get() const { return mQueue.get(); } private: sp<SensorEventQueue> mQueue; const sp<SensorEventQueue> mQueue; }; /** Loading @@ -95,10 +97,7 @@ class SensorEnableGuard { } } SensorEnableGuard(const SensorEnableGuard&) = delete; SensorEnableGuard& operator=(const SensorEnableGuard&) = delete; // Enable moving. // Enable move and delete default copy-ctor/copy-assignment. SensorEnableGuard(SensorEnableGuard&& other) : mQueue(other.mQueue), mSensor(other.mSensor) { other.mSensor = SensorPoseProvider::INVALID_HANDLE; } Loading Loading @@ -131,7 +130,7 @@ class SensorPoseProviderImpl : public SensorPoseProvider { // Figure out the sensor's data format. DataFormat format = getSensorFormat(sensor); if (format == DataFormat::kUnknown) { ALOGE("Unknown format for sensor %" PRId32, sensor); ALOGE("%s: Unknown format for sensor %" PRId32, __func__, sensor); return false; } Loading @@ -145,17 +144,19 @@ class SensorPoseProviderImpl : public SensorPoseProvider { // Enable the sensor. if (mQueue->enableSensor(sensor, samplingPeriod.count(), 0, 0)) { ALOGE("Failed to enable sensor"); ALOGE("%s: Failed to enable sensor %" PRId32, __func__, sensor); std::lock_guard lock(mMutex); mEnabledSensorsExtra.erase(sensor); return false; } mEnabledSensors.emplace(sensor, SensorEnableGuard(mQueue.get(), sensor)); mEnabledSensors.emplace(sensor, SensorEnableGuard(mQueue, sensor)); ALOGD("%s: Sensor %" PRId32 " started", __func__, sensor); return true; } void stopSensor(int handle) override { ALOGD("%s: Sensor %" PRId32 " stopped", __func__, handle); mEnabledSensors.erase(handle); std::lock_guard lock(mMutex); mEnabledSensorsExtra.erase(handle); Loading Loading @@ -223,9 +224,9 @@ class SensorPoseProviderImpl : public SensorPoseProvider { Listener* const mListener; SensorManager* const mSensorManager; std::timed_mutex mMutex; sp<SensorEventQueue> mQueue; std::map<int32_t, SensorEnableGuard> mEnabledSensors; std::map<int32_t, SensorExtra> mEnabledSensorsExtra GUARDED_BY(mMutex); sp<SensorEventQueue> 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 Loading @@ -246,7 +247,13 @@ class SensorPoseProviderImpl : public SensorPoseProvider { bool waitInitFinished() { return mInitPromise.get_future().get(); } void threadFunc() { // Obtain looper. // Name our std::thread to help identification. As is, canCallJava == false. androidSetThreadName("SensorPoseProvider-looper"); // Run at the highest non-realtime priority. androidSetThreadPriority(gettid(), PRIORITY_URGENT_AUDIO); // The looper is started on the created std::thread. mLooper = Looper::prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); // Create event queue. Loading @@ -263,7 +270,8 @@ class SensorPoseProviderImpl : public SensorPoseProvider { initFinished(true); while (!mQuit) { int ret = mLooper->pollOnce(-1 /* no timeout */, nullptr, nullptr, nullptr); const int ret = mLooper->pollOnce(-1 /* no timeout */, nullptr /* outFd */, nullptr /* outEvents */, nullptr /* outData */); switch (ret) { case ALOOPER_POLL_WAKE: Loading @@ -276,7 +284,13 @@ class SensorPoseProviderImpl : public SensorPoseProvider { break; default: ALOGE("Unexpected status out of Looper::pollOnce: %d", ret); // Besides WAKE and kIdent, there should be no timeouts, callbacks, // ALOOPER_POLL_ERROR, or other events. // Exit now to avoid high frequency log spam on error, // e.g. if the fd becomes invalid (b/31093485). ALOGE("%s: Unexpected status out of Looper::pollOnce: %d", __func__, ret); mQuit = true; continue; } // Process an event. Loading
services/audiopolicy/service/Spatializer.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -263,7 +263,7 @@ void Spatializer::onFirstRef() { mLooper->start( /*runOnCallingThread*/false, /*canCallJava*/ false, PRIORITY_AUDIO); PRIORITY_URGENT_AUDIO); mHandler = new EngineCallbackHandler(this); mLooper->registerHandler(mHandler); Loading