Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 17 | #define LOG_TAG "IsochronousClockModel" |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Tom Cherry | 357552e | 2017-07-12 13:48:26 -0700 | [diff] [blame] | 19 | #include <log/log.h> |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 20 | |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 21 | #define __STDC_FORMAT_MACROS |
| 22 | #include <inttypes.h> |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 23 | #include <stdint.h> |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 24 | #include <algorithm> |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 25 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 26 | #include "utility/AudioClock.h" |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 27 | #include "utility/AAudioUtilities.h" |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 28 | #include "IsochronousClockModel.h" |
| 29 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 30 | using namespace aaudio; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 31 | |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 32 | using namespace android::audio_utils; |
| 33 | |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 34 | #ifndef ICM_LOG_DRIFT |
| 35 | #define ICM_LOG_DRIFT 0 |
| 36 | #endif // ICM_LOG_DRIFT |
| 37 | |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 38 | // To enable the timestamp histogram, enter this before opening the stream: |
| 39 | // adb root |
| 40 | // adb shell setprop aaudio.log_mask 1 |
| 41 | // A histogram of the lateness of the timestamps will be cleared when the stream is started. |
| 42 | // It will be updated when the model is stable and receives a timestamp, |
| 43 | // and dumped to the log when the stream is stopped. |
| 44 | |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 45 | IsochronousClockModel::IsochronousClockModel() |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 46 | : mMarkerFramePosition(0) |
| 47 | , mMarkerNanoTime(0) |
| 48 | , mSampleRate(48000) |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 49 | , mFramesPerBurst(48) |
Phil Burk | 9e1f44b | 2020-04-08 16:02:05 -0700 | [diff] [blame] | 50 | , mBurstPeriodNanos(0) // this will be updated before use |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 51 | , mMaxMeasuredLatenessNanos(0) |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 52 | , mLatenessForDriftNanos(kInitialLatenessForDriftNanos) |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 53 | , mState(STATE_STOPPED) |
| 54 | { |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 55 | if ((AAudioProperty_getLogMask() & AAUDIO_LOG_CLOCK_MODEL_HISTOGRAM) != 0) { |
| 56 | mHistogramMicros = std::make_unique<Histogram>(kHistogramBinCount, |
| 57 | kHistogramBinWidthMicros); |
| 58 | } |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 61 | void IsochronousClockModel::setPositionAndTime(int64_t framePosition, int64_t nanoTime) { |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 62 | ALOGV("setPositionAndTime, %lld, %lld", (long long) framePosition, (long long) nanoTime); |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 63 | mMarkerFramePosition = framePosition; |
| 64 | mMarkerNanoTime = nanoTime; |
| 65 | } |
| 66 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 67 | void IsochronousClockModel::start(int64_t nanoTime) { |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 68 | ALOGV("start(nanos = %lld)\n", (long long) nanoTime); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 69 | mMarkerNanoTime = nanoTime; |
| 70 | mState = STATE_STARTING; |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 71 | if (mHistogramMicros) { |
| 72 | mHistogramMicros->clear(); |
| 73 | } |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 76 | void IsochronousClockModel::stop(int64_t nanoTime) { |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 77 | ALOGD("stop(nanos = %lld) max lateness = %d micros\n", |
| 78 | (long long) nanoTime, |
| 79 | (int) (mMaxMeasuredLatenessNanos / 1000)); |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 80 | setPositionAndTime(convertTimeToPosition(nanoTime), nanoTime); |
| 81 | // TODO should we set position? |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 82 | mState = STATE_STOPPED; |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 83 | if (mHistogramMicros) { |
| 84 | dumpHistogram(); |
| 85 | } |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Phil Burk | 377c1c2 | 2018-12-12 16:06:54 -0800 | [diff] [blame] | 88 | bool IsochronousClockModel::isStarting() const { |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 89 | return mState == STATE_STARTING; |
| 90 | } |
| 91 | |
Phil Burk | 377c1c2 | 2018-12-12 16:06:54 -0800 | [diff] [blame] | 92 | bool IsochronousClockModel::isRunning() const { |
| 93 | return mState == STATE_RUNNING; |
| 94 | } |
| 95 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 96 | void IsochronousClockModel::processTimestamp(int64_t framePosition, int64_t nanoTime) { |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 97 | mTimestampCount++; |
| 98 | // Log position and time in CSV format so we can import it easily into spreadsheets. |
| 99 | //ALOGD("%s() CSV, %d, %lld, %lld", __func__, |
| 100 | //mTimestampCount, (long long)framePosition, (long long)nanoTime); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 101 | int64_t framesDelta = framePosition - mMarkerFramePosition; |
| 102 | int64_t nanosDelta = nanoTime - mMarkerNanoTime; |
| 103 | if (nanosDelta < 1000) { |
| 104 | return; |
| 105 | } |
| 106 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 107 | // ALOGD("processTimestamp() - mMarkerFramePosition = %lld at mMarkerNanoTime %llu", |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 108 | // (long long)mMarkerFramePosition, |
| 109 | // (long long)mMarkerNanoTime); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 110 | |
| 111 | int64_t expectedNanosDelta = convertDeltaPositionToTime(framesDelta); |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 112 | // ALOGD("processTimestamp() - expectedNanosDelta = %lld, nanosDelta = %llu", |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 113 | // (long long)expectedNanosDelta, |
| 114 | // (long long)nanosDelta); |
| 115 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 116 | // ALOGD("processTimestamp() - mSampleRate = %d", mSampleRate); |
| 117 | // ALOGD("processTimestamp() - mState = %d", mState); |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 118 | int64_t latenessNanos = nanosDelta - expectedNanosDelta; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 119 | switch (mState) { |
| 120 | case STATE_STOPPED: |
| 121 | break; |
| 122 | case STATE_STARTING: |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 123 | setPositionAndTime(framePosition, nanoTime); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 124 | mState = STATE_SYNCING; |
| 125 | break; |
| 126 | case STATE_SYNCING: |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 127 | // This will handle a burst of rapid transfer at the beginning. |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 128 | if (latenessNanos < 0) { |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 129 | setPositionAndTime(framePosition, nanoTime); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 130 | } else { |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 131 | // ALOGD("processTimestamp() - advance to STATE_RUNNING"); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 132 | mState = STATE_RUNNING; |
| 133 | } |
| 134 | break; |
| 135 | case STATE_RUNNING: |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 136 | if (mHistogramMicros) { |
| 137 | mHistogramMicros->add(latenessNanos / AAUDIO_NANOS_PER_MICROSECOND); |
| 138 | } |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 139 | // Modify estimated position based on lateness. |
| 140 | // This affects the "early" side of the window, which controls output glitches. |
| 141 | if (latenessNanos < 0) { |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 142 | // Earlier than expected timestamp. |
Phil Burk | 1815a76 | 2019-05-24 08:52:27 -0700 | [diff] [blame] | 143 | // This data is probably more accurate, so use it. |
| 144 | // Or we may be drifting due to a fast HW clock. |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 145 | setPositionAndTime(framePosition, nanoTime); |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 146 | #if ICM_LOG_DRIFT |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 147 | int earlyDeltaMicros = (int) ((expectedNanosDelta - nanosDelta)/ 1000); |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 148 | ALOGD("%s() - STATE_RUNNING - #%d, %4d micros EARLY", |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 149 | __func__, mTimestampCount, earlyDeltaMicros); |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 150 | #endif |
| 151 | } else if (latenessNanos > mLatenessForDriftNanos) { |
| 152 | // When we are on the late side, it may be because of preemption in the kernel, |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 153 | // or timing jitter caused by resampling in the DSP, |
| 154 | // or we may be drifting due to a slow HW clock. |
| 155 | // We add slight drift value just in case there is actual long term drift |
| 156 | // forward caused by a slower clock. |
| 157 | // If the clock is faster than the model will get pushed earlier |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 158 | // by the code in the earlier branch. |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 159 | // The two opposing forces should allow the model to track the real clock |
| 160 | // over a long time. |
| 161 | int64_t driftingTime = mMarkerNanoTime + expectedNanosDelta + kDriftNanos; |
| 162 | setPositionAndTime(framePosition, driftingTime); |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 163 | #if ICM_LOG_DRIFT |
| 164 | ALOGD("%s() - STATE_RUNNING - #%d, DRIFT, lateness = %d micros", |
| 165 | __func__, |
| 166 | mTimestampCount, |
| 167 | (int) (latenessNanos / 1000)); |
| 168 | #endif |
| 169 | } |
| 170 | |
| 171 | // Modify mMaxMeasuredLatenessNanos. |
| 172 | // This affects the "late" side of the window, which controls input glitches. |
| 173 | if (latenessNanos > mMaxMeasuredLatenessNanos) { // increase |
| 174 | #if ICM_LOG_DRIFT |
| 175 | ALOGD("%s() - STATE_RUNNING - #%d, newmax %d - oldmax %d = %4d micros LATE", |
| 176 | __func__, |
| 177 | mTimestampCount, |
| 178 | (int) (latenessNanos / 1000), |
| 179 | mMaxMeasuredLatenessNanos / 1000, |
| 180 | (int) ((latenessNanos - mMaxMeasuredLatenessNanos) / 1000) |
| 181 | ); |
| 182 | #endif |
| 183 | mMaxMeasuredLatenessNanos = (int32_t) latenessNanos; |
| 184 | // Calculate upper region that will trigger a drift forwards. |
| 185 | mLatenessForDriftNanos = mMaxMeasuredLatenessNanos - (mMaxMeasuredLatenessNanos >> 4); |
| 186 | } else { // decrease |
Phil Burk | 9e1f44b | 2020-04-08 16:02:05 -0700 | [diff] [blame] | 187 | // If this is an outlier in lateness then mMaxMeasuredLatenessNanos can go high |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 188 | // and stay there. So we slowly reduce mMaxMeasuredLatenessNanos for better |
| 189 | // long term stability. The two opposing forces will keep mMaxMeasuredLatenessNanos |
| 190 | // within a reasonable range. |
| 191 | mMaxMeasuredLatenessNanos -= kDriftNanos; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 192 | } |
| 193 | break; |
| 194 | default: |
| 195 | break; |
| 196 | } |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void IsochronousClockModel::setSampleRate(int32_t sampleRate) { |
| 200 | mSampleRate = sampleRate; |
| 201 | update(); |
| 202 | } |
| 203 | |
| 204 | void IsochronousClockModel::setFramesPerBurst(int32_t framesPerBurst) { |
| 205 | mFramesPerBurst = framesPerBurst; |
| 206 | update(); |
| 207 | } |
| 208 | |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 209 | // Update expected lateness based on sampleRate and framesPerBurst |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 210 | void IsochronousClockModel::update() { |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 211 | mBurstPeriodNanos = convertDeltaPositionToTime(mFramesPerBurst); // uses mSampleRate |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 214 | int64_t IsochronousClockModel::convertDeltaPositionToTime(int64_t framesDelta) const { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 215 | return (AAUDIO_NANOS_PER_SECOND * framesDelta) / mSampleRate; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 218 | int64_t IsochronousClockModel::convertDeltaTimeToPosition(int64_t nanosDelta) const { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 219 | return (mSampleRate * nanosDelta) / AAUDIO_NANOS_PER_SECOND; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 222 | int64_t IsochronousClockModel::convertPositionToTime(int64_t framePosition) const { |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 223 | if (mState == STATE_STOPPED) { |
| 224 | return mMarkerNanoTime; |
| 225 | } |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 226 | int64_t nextBurstIndex = (framePosition + mFramesPerBurst - 1) / mFramesPerBurst; |
| 227 | int64_t nextBurstPosition = mFramesPerBurst * nextBurstIndex; |
| 228 | int64_t framesDelta = nextBurstPosition - mMarkerFramePosition; |
| 229 | int64_t nanosDelta = convertDeltaPositionToTime(framesDelta); |
Phil Burk | fd34a93 | 2017-07-19 07:03:52 -0700 | [diff] [blame] | 230 | int64_t time = mMarkerNanoTime + nanosDelta; |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 231 | // ALOGD("convertPositionToTime: pos = %llu --> time = %llu", |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 232 | // (unsigned long long)framePosition, |
| 233 | // (unsigned long long)time); |
| 234 | return time; |
| 235 | } |
| 236 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 237 | int64_t IsochronousClockModel::convertTimeToPosition(int64_t nanoTime) const { |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 238 | if (mState == STATE_STOPPED) { |
| 239 | return mMarkerFramePosition; |
| 240 | } |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 241 | int64_t nanosDelta = nanoTime - mMarkerNanoTime; |
| 242 | int64_t framesDelta = convertDeltaTimeToPosition(nanosDelta); |
| 243 | int64_t nextBurstPosition = mMarkerFramePosition + framesDelta; |
| 244 | int64_t nextBurstIndex = nextBurstPosition / mFramesPerBurst; |
| 245 | int64_t position = nextBurstIndex * mFramesPerBurst; |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 246 | // ALOGD("convertTimeToPosition: time = %llu --> pos = %llu", |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 247 | // (unsigned long long)nanoTime, |
| 248 | // (unsigned long long)position); |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 249 | // ALOGD("convertTimeToPosition: framesDelta = %llu, mFramesPerBurst = %d", |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 250 | // (long long) framesDelta, mFramesPerBurst); |
| 251 | return position; |
| 252 | } |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 253 | |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 254 | int32_t IsochronousClockModel::getLateTimeOffsetNanos() const { |
Phil Burk | 34e2d2d | 2019-09-26 12:46:10 -0700 | [diff] [blame] | 255 | return mMaxMeasuredLatenessNanos + kExtraLatenessNanos; |
Phil Burk | fceeee7 | 2019-06-14 11:18:45 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | int64_t IsochronousClockModel::convertPositionToLatestTime(int64_t framePosition) const { |
| 259 | return convertPositionToTime(framePosition) + getLateTimeOffsetNanos(); |
| 260 | } |
| 261 | |
| 262 | int64_t IsochronousClockModel::convertLatestTimeToPosition(int64_t nanoTime) const { |
| 263 | return convertTimeToPosition(nanoTime - getLateTimeOffsetNanos()); |
| 264 | } |
| 265 | |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 266 | void IsochronousClockModel::dump() const { |
Phil Burk | ef34be5 | 2019-09-26 13:45:25 -0700 | [diff] [blame] | 267 | ALOGD("mMarkerFramePosition = %" PRIu64, mMarkerFramePosition); |
| 268 | ALOGD("mMarkerNanoTime = %" PRIu64, mMarkerNanoTime); |
| 269 | ALOGD("mSampleRate = %6d", mSampleRate); |
| 270 | ALOGD("mFramesPerBurst = %6d", mFramesPerBurst); |
| 271 | ALOGD("mMaxMeasuredLatenessNanos = %6d", mMaxMeasuredLatenessNanos); |
| 272 | ALOGD("mState = %6d", mState); |
| 273 | } |
| 274 | |
| 275 | void IsochronousClockModel::dumpHistogram() const { |
| 276 | if (!mHistogramMicros) return; |
| 277 | std::istringstream istr(mHistogramMicros->dump()); |
| 278 | std::string line; |
| 279 | while (std::getline(istr, line)) { |
| 280 | ALOGD("lateness, %s", line.c_str()); |
| 281 | } |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 282 | } |