OSDN Git Service

TimestampVerifier: make jitter computation public
authorAndy Hung <hunga@google.com>
Fri, 22 Feb 2019 01:47:43 +0000 (17:47 -0800)
committerAndy Hung <hunga@google.com>
Fri, 22 Feb 2019 02:14:18 +0000 (18:14 -0800)
Tweak jitter computation so that it is (actual - expected), not the
other way around (expected - actual).

Test: timestampverifier_tests
Change-Id: I0e8b6dcc7284c91663349cc7e6447c98d3abbbba

audio_utils/include/audio_utils/TimestampVerifier.h

index 060ee98..968d046 100644 (file)
@@ -241,6 +241,16 @@ public:
     constexpr uint32_t getSampleRate() const { return mSampleRate; }
 
     constexpr FrameTime getLastCorrectedTimestamp() const { return mLastCorrectedTimestamp; }
+
+    // Inf+-, NaN is possible only if sampleRate is 0 (should not happen)
+    static constexpr double computeJitterMs(
+            const FrameTime &current, const FrameTime &last, uint32_t sampleRate) {
+        const auto diff = sub(current, last);
+        const double frameDifferenceNs = diff.first * 1e9 / sampleRate;
+        const double jitterNs = diff.second - frameDifferenceNs;  // actual - expected
+        return jitterNs * 1e-6;
+    }
+
 private:
     // our statistics have exponentially weighted history.
     // the defaults are here.
@@ -285,15 +295,6 @@ private:
                         left.mFrames - right.mFrames, left.mTimeNs - right.mTimeNs);
     }
 
-    // Inf+-, NaN is possible only if sampleRate is 0 (should not happen)
-    static constexpr double computeJitterMs(
-            const FrameTime &current, const FrameTime &last, uint32_t sampleRate) {
-        const auto diff = sub(current, last);
-        const double frameDifferenceNs = diff.first * 1e9 / sampleRate;
-        const double jitterNs = frameDifferenceNs - diff.second;
-        return jitterNs * 1e-6;
-    }
-
     // Inf+-, Nan possible depending on differences between current and last.
     static constexpr double computeRatio(
             const FrameTime &current, const FrameTime &last, uint32_t sampleRate) {