OSDN Git Service

Track max latency in WifiDisplaySink
authorAndreas Huber <andih@google.com>
Thu, 4 Apr 2013 17:53:34 +0000 (10:53 -0700)
committerAndreas Huber <andih@google.com>
Thu, 4 Apr 2013 17:53:34 +0000 (10:53 -0700)
also unbreak non-special-mode by choosing a proper time offset based
on arrival time of the first access unit even when no time synchronization
is present.

Change-Id: I133050afc6f70d4639ca45de68a31d5bc3594e96

media/libstagefright/wifi-display/sink/WifiDisplaySink.cpp
media/libstagefright/wifi-display/sink/WifiDisplaySink.h

index 1a08bf5..5db2099 100644 (file)
@@ -57,7 +57,8 @@ WifiDisplaySink::WifiDisplaySink(
       mSetupDeferred(false),
       mLatencyCount(0),
       mLatencySumUs(0ll),
-      mLatencyMaxUs(0ll) {
+      mLatencyMaxUs(0ll),
+      mMaxDelayMs(-1ll) {
     // We support any and all resolutions, but prefer 720p30
     mSinkSupportedVideoFormats.setNativeResolution(
             VideoFormats::RESOLUTION_CEA, 5);  // 1280 x 720 p30
@@ -296,9 +297,13 @@ void WifiDisplaySink::onMessageReceived(const sp<AMessage> &msg) {
     }
 }
 
-static void dumpDelay(size_t trackIndex, int64_t timeUs) {
+void WifiDisplaySink::dumpDelay(size_t trackIndex, int64_t timeUs) {
     int64_t delayMs = (ALooper::GetNowUs() - timeUs) / 1000ll;
 
+    if (delayMs > mMaxDelayMs) {
+        mMaxDelayMs = delayMs;
+    }
+
     static const int64_t kMinDelayMs = 0;
     static const int64_t kMaxDelayMs = 300;
 
@@ -314,9 +319,10 @@ static void dumpDelay(size_t trackIndex, int64_t timeUs) {
         n = kPatternSize;
     }
 
-    ALOGI("[%lld]: (%4lld ms) %s",
+    ALOGI("[%lld]: (%4lld ms / %4lld ms) %s",
           timeUs / 1000,
           delayMs,
+          mMaxDelayMs,
           kPattern + kPatternSize - n);
 }
 
@@ -350,14 +356,19 @@ void WifiDisplaySink::onMediaReceiverNotify(const sp<AMessage> &msg) {
                 looper()->registerHandler(mRenderer);
             }
 
-            CHECK(mTimeOffsetValid);
-
             sp<ABuffer> accessUnit;
             CHECK(msg->findBuffer("accessUnit", &accessUnit));
 
             int64_t timeUs;
             CHECK(accessUnit->meta()->findInt64("timeUs", &timeUs));
 
+            if (!mTimeOffsetValid && !(mFlags & FLAG_SPECIAL_MODE)) {
+                mTimeOffsetUs = timeUs - ALooper::GetNowUs();
+                mTimeOffsetValid = true;
+            }
+
+            CHECK(mTimeOffsetValid);
+
             // We are the timesync _client_,
             // client time = server time - time offset.
             timeUs -= mTimeOffsetUs;
index 7c62057..adb9d89 100644 (file)
@@ -132,6 +132,8 @@ private:
     int64_t mLatencySumUs;
     int64_t mLatencyMaxUs;
 
+    int64_t mMaxDelayMs;
+
     status_t sendM2(int32_t sessionID);
     status_t sendSetup(int32_t sessionID, const char *uri);
     status_t sendPlay(int32_t sessionID, const char *uri);
@@ -184,6 +186,8 @@ private:
             const char *url, AString *host, int32_t *port, AString *path,
             AString *user, AString *pass);
 
+    void dumpDelay(size_t trackIndex, int64_t timeUs);
+
     DISALLOW_EVIL_CONSTRUCTORS(WifiDisplaySink);
 };