Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 19 | #include "Scheduler.h" |
| 20 | |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 21 | #include <algorithm> |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 22 | #include <cinttypes> |
| 23 | #include <cstdint> |
| 24 | #include <memory> |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 25 | #include <numeric> |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 26 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 27 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 28 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 29 | #include <android/hardware/configstore/1.2/ISurfaceFlingerConfigs.h> |
| 30 | #include <configstore/Utils.h> |
| 31 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 32 | #include <gui/ISurfaceComposer.h> |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 33 | #include <ui/DisplayStatInfo.h> |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 34 | #include <utils/Timers.h> |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 35 | #include <utils/Trace.h> |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 36 | |
| 37 | #include "DispSync.h" |
| 38 | #include "DispSyncSource.h" |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 39 | #include "EventControlThread.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 40 | #include "EventThread.h" |
| 41 | #include "InjectVSyncSource.h" |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 42 | #include "SchedulerUtils.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 43 | |
| 44 | namespace android { |
| 45 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 46 | using namespace android::hardware::configstore; |
| 47 | using namespace android::hardware::configstore::V1_0; |
| 48 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 49 | #define RETURN_VALUE_IF_INVALID(value) \ |
| 50 | if (handle == nullptr || mConnections.count(handle->id) == 0) return value |
| 51 | #define RETURN_IF_INVALID() \ |
| 52 | if (handle == nullptr || mConnections.count(handle->id) == 0) return |
| 53 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 54 | std::atomic<int64_t> Scheduler::sNextId = 0; |
| 55 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 56 | Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function) |
| 57 | : mHasSyncFramework( |
| 58 | getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(true)), |
| 59 | mDispSyncPresentTimeOffset( |
| 60 | getInt64<ISurfaceFlingerConfigs, |
| 61 | &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(0)), |
| 62 | mPrimaryHWVsyncEnabled(false), |
| 63 | mHWVsyncAvailable(false) { |
| 64 | // Note: We create a local temporary with the real DispSync implementation |
| 65 | // type temporarily so we can initialize it with the configured values, |
| 66 | // before storing it for more generic use using the interface type. |
| 67 | auto primaryDispSync = std::make_unique<impl::DispSync>("SchedulerDispSync"); |
| 68 | primaryDispSync->init(mHasSyncFramework, mDispSyncPresentTimeOffset); |
| 69 | mPrimaryDispSync = std::move(primaryDispSync); |
| 70 | mEventControlThread = std::make_unique<impl::EventControlThread>(function); |
| 71 | } |
| 72 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 73 | Scheduler::~Scheduler() = default; |
| 74 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 75 | sp<Scheduler::ConnectionHandle> Scheduler::createConnection( |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 76 | const std::string& connectionName, int64_t phaseOffsetNs, |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 77 | impl::EventThread::ResyncWithRateLimitCallback resyncCallback, |
| 78 | impl::EventThread::InterceptVSyncsCallback interceptCallback) { |
| 79 | const int64_t id = sNextId++; |
| 80 | ALOGV("Creating a connection handle with ID: %" PRId64 "\n", id); |
| 81 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 82 | std::unique_ptr<EventThread> eventThread = |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 83 | makeEventThread(connectionName, mPrimaryDispSync.get(), phaseOffsetNs, resyncCallback, |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 84 | interceptCallback); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 85 | auto connection = std::make_unique<Connection>(new ConnectionHandle(id), |
| 86 | eventThread->createEventConnection(), |
| 87 | std::move(eventThread)); |
| 88 | mConnections.insert(std::make_pair(id, std::move(connection))); |
| 89 | return mConnections[id]->handle; |
| 90 | } |
| 91 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 92 | std::unique_ptr<EventThread> Scheduler::makeEventThread( |
Ana Krulec | 1f02791 | 2018-09-10 21:36:25 +0000 | [diff] [blame] | 93 | const std::string& connectionName, DispSync* dispSync, int64_t phaseOffsetNs, |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 94 | impl::EventThread::ResyncWithRateLimitCallback resyncCallback, |
| 95 | impl::EventThread::InterceptVSyncsCallback interceptCallback) { |
Ana Krulec | 1f02791 | 2018-09-10 21:36:25 +0000 | [diff] [blame] | 96 | const std::string sourceName = connectionName + "Source"; |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 97 | std::unique_ptr<VSyncSource> eventThreadSource = |
Ana Krulec | 1f02791 | 2018-09-10 21:36:25 +0000 | [diff] [blame] | 98 | std::make_unique<DispSyncSource>(dispSync, phaseOffsetNs, true, sourceName.c_str()); |
| 99 | const std::string threadName = connectionName + "Thread"; |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 100 | return std::make_unique<impl::EventThread>(std::move(eventThreadSource), resyncCallback, |
Ana Krulec | 1f02791 | 2018-09-10 21:36:25 +0000 | [diff] [blame] | 101 | interceptCallback, threadName.c_str()); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 104 | sp<IDisplayEventConnection> Scheduler::createDisplayEventConnection( |
| 105 | const sp<Scheduler::ConnectionHandle>& handle) { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 106 | RETURN_VALUE_IF_INVALID(nullptr); |
| 107 | return mConnections[handle->id]->thread->createEventConnection(); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | EventThread* Scheduler::getEventThread(const sp<Scheduler::ConnectionHandle>& handle) { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 111 | RETURN_VALUE_IF_INVALID(nullptr); |
| 112 | return mConnections[handle->id]->thread.get(); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | sp<BnDisplayEventConnection> Scheduler::getEventConnection(const sp<ConnectionHandle>& handle) { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 116 | RETURN_VALUE_IF_INVALID(nullptr); |
| 117 | return mConnections[handle->id]->eventConnection; |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void Scheduler::hotplugReceived(const sp<Scheduler::ConnectionHandle>& handle, |
| 121 | EventThread::DisplayType displayType, bool connected) { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 122 | RETURN_IF_INVALID(); |
| 123 | mConnections[handle->id]->thread->onHotplugReceived(displayType, connected); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void Scheduler::onScreenAcquired(const sp<Scheduler::ConnectionHandle>& handle) { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 127 | RETURN_IF_INVALID(); |
| 128 | mConnections[handle->id]->thread->onScreenAcquired(); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void Scheduler::onScreenReleased(const sp<Scheduler::ConnectionHandle>& handle) { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 132 | RETURN_IF_INVALID(); |
| 133 | mConnections[handle->id]->thread->onScreenReleased(); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame^] | 136 | void Scheduler::dump(const sp<Scheduler::ConnectionHandle>& handle, std::string& result) const { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 137 | RETURN_IF_INVALID(); |
| 138 | mConnections.at(handle->id)->thread->dump(result); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void Scheduler::setPhaseOffset(const sp<Scheduler::ConnectionHandle>& handle, nsecs_t phaseOffset) { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 142 | RETURN_IF_INVALID(); |
| 143 | mConnections[handle->id]->thread->setPhaseOffset(phaseOffset); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 144 | } |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 145 | |
| 146 | void Scheduler::getDisplayStatInfo(DisplayStatInfo* stats) { |
| 147 | stats->vsyncTime = mPrimaryDispSync->computeNextRefresh(0); |
| 148 | stats->vsyncPeriod = mPrimaryDispSync->getPeriod(); |
| 149 | } |
| 150 | |
| 151 | void Scheduler::enableHardwareVsync() { |
| 152 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 153 | if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) { |
| 154 | mPrimaryDispSync->beginResync(); |
| 155 | mEventControlThread->setVsyncEnabled(true); |
| 156 | mPrimaryHWVsyncEnabled = true; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | void Scheduler::disableHardwareVsync(bool makeUnavailable) { |
| 161 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 162 | if (mPrimaryHWVsyncEnabled) { |
| 163 | mEventControlThread->setVsyncEnabled(false); |
| 164 | mPrimaryDispSync->endResync(); |
| 165 | mPrimaryHWVsyncEnabled = false; |
| 166 | } |
| 167 | if (makeUnavailable) { |
| 168 | mHWVsyncAvailable = false; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | void Scheduler::setVsyncPeriod(const nsecs_t period) { |
| 173 | mPrimaryDispSync->reset(); |
| 174 | mPrimaryDispSync->setPeriod(period); |
| 175 | enableHardwareVsync(); |
| 176 | } |
| 177 | |
| 178 | void Scheduler::addResyncSample(const nsecs_t timestamp) { |
| 179 | bool needsHwVsync = false; |
| 180 | { // Scope for the lock |
| 181 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 182 | if (mPrimaryHWVsyncEnabled) { |
| 183 | needsHwVsync = mPrimaryDispSync->addResyncSample(timestamp); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if (needsHwVsync) { |
| 188 | enableHardwareVsync(); |
| 189 | } else { |
| 190 | disableHardwareVsync(false); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void Scheduler::addPresentFence(const std::shared_ptr<FenceTime>& fenceTime) { |
| 195 | if (mPrimaryDispSync->addPresentFence(fenceTime)) { |
| 196 | enableHardwareVsync(); |
| 197 | } else { |
| 198 | disableHardwareVsync(false); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void Scheduler::setIgnorePresentFences(bool ignore) { |
| 203 | mPrimaryDispSync->setIgnorePresentFences(ignore); |
| 204 | } |
| 205 | |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 206 | void Scheduler::makeHWSyncAvailable(bool makeAvailable) { |
| 207 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 208 | mHWVsyncAvailable = makeAvailable; |
| 209 | } |
| 210 | |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 211 | void Scheduler::addFramePresentTimeForLayer(const nsecs_t framePresentTime, bool isAutoTimestamp, |
| 212 | const std::string layerName) { |
| 213 | // This is V1 logic. It calculates the average FPS based on the timestamp frequency |
| 214 | // regardless of which layer the timestamp came from. |
| 215 | // For now, the averages and FPS are recorded in the systrace. |
| 216 | determineTimestampAverage(isAutoTimestamp, framePresentTime); |
| 217 | |
| 218 | // This is V2 logic. It calculates the average and median timestamp difference based on the |
| 219 | // individual layer history. The results are recorded in the systrace. |
| 220 | determineLayerTimestampStats(layerName, framePresentTime); |
| 221 | } |
| 222 | |
| 223 | void Scheduler::incrementFrameCounter() { |
| 224 | mLayerHistory.incrementCounter(); |
| 225 | } |
| 226 | |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 227 | void Scheduler::updateFrameSkipping(const int64_t skipCount) { |
| 228 | ATRACE_INT("FrameSkipCount", skipCount); |
| 229 | if (mSkipCount != skipCount) { |
| 230 | // Only update DispSync if it hasn't been updated yet. |
| 231 | mPrimaryDispSync->setRefreshSkipCount(skipCount); |
| 232 | mSkipCount = skipCount; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | void Scheduler::determineLayerTimestampStats(const std::string layerName, |
| 237 | const nsecs_t framePresentTime) { |
| 238 | mLayerHistory.insert(layerName, framePresentTime); |
| 239 | std::vector<int64_t> differencesMs; |
| 240 | |
| 241 | // Traverse through the layer history, and determine the differences in present times. |
| 242 | nsecs_t newestPresentTime = framePresentTime; |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 243 | std::string differencesText = ""; |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 244 | for (int i = 1; i < mLayerHistory.getSize(); i++) { |
| 245 | std::unordered_map<std::string, nsecs_t> layers = mLayerHistory.get(i); |
| 246 | for (auto layer : layers) { |
| 247 | if (layer.first != layerName) { |
| 248 | continue; |
| 249 | } |
| 250 | int64_t differenceMs = (newestPresentTime - layer.second) / 1000000; |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 251 | // Dismiss noise. |
| 252 | if (differenceMs > 10 && differenceMs < 60) { |
| 253 | differencesMs.push_back(differenceMs); |
| 254 | } |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 255 | IF_ALOGV() { differencesText += (std::to_string(differenceMs) + " "); } |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 256 | newestPresentTime = layer.second; |
| 257 | } |
| 258 | } |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 259 | ALOGV("Layer %s timestamp intervals: %s", layerName.c_str(), differencesText.c_str()); |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 260 | |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 261 | if (!differencesMs.empty()) { |
| 262 | // Mean/Average is a good indicator for when 24fps videos are playing, because the frames |
| 263 | // come in 33, and 49 ms intervals with occasional 41ms. |
| 264 | const int64_t meanMs = scheduler::calculate_mean(differencesMs); |
| 265 | const auto tagMean = "TimestampMean_" + layerName; |
| 266 | ATRACE_INT(tagMean.c_str(), meanMs); |
| 267 | |
| 268 | // Mode and median are good indicators for 30 and 60 fps videos, because the majority of |
| 269 | // frames come in 16, or 33 ms intervals. |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 270 | const auto tagMedian = "TimestampMedian_" + layerName; |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 271 | ATRACE_INT(tagMedian.c_str(), scheduler::calculate_median(&differencesMs)); |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 272 | |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 273 | const auto tagMode = "TimestampMode_" + layerName; |
| 274 | ATRACE_INT(tagMode.c_str(), scheduler::calculate_mode(differencesMs)); |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 275 | } |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void Scheduler::determineTimestampAverage(bool isAutoTimestamp, const nsecs_t framePresentTime) { |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 279 | ATRACE_INT("AutoTimestamp", isAutoTimestamp); |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 280 | |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 281 | // Video does not have timestamp automatically set, so we discard timestamps that are |
| 282 | // coming in from other sources for now. |
| 283 | if (isAutoTimestamp) { |
| 284 | return; |
| 285 | } |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 286 | int64_t differenceMs = (framePresentTime - mPreviousFrameTimestamp) / 1000000; |
| 287 | mPreviousFrameTimestamp = framePresentTime; |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 288 | |
| 289 | if (differenceMs < 10 || differenceMs > 100) { |
| 290 | // Dismiss noise. |
| 291 | return; |
| 292 | } |
| 293 | ATRACE_INT("TimestampDiff", differenceMs); |
| 294 | |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 295 | mTimeDifferences[mCounter % scheduler::ARRAY_SIZE] = differenceMs; |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 296 | mCounter++; |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 297 | int64_t mean = scheduler::calculate_mean(mTimeDifferences); |
| 298 | ATRACE_INT("AutoTimestampMean", mean); |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 299 | |
| 300 | // TODO(b/113612090): This are current numbers from trial and error while running videos |
| 301 | // from YouTube at 24, 30, and 60 fps. |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 302 | if (mean > 14 && mean < 18) { |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 303 | ATRACE_INT("FPS", 60); |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 304 | } else if (mean > 31 && mean < 34) { |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 305 | ATRACE_INT("FPS", 30); |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 306 | return; |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 307 | } else if (mean > 39 && mean < 42) { |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 308 | ATRACE_INT("FPS", 24); |
| 309 | } |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 312 | } // namespace android |