DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (cdf352f02ac4)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include "modules/video_coding/include/video_coding.h"
#include "modules/video_coding/internal_defines.h"
#include "modules/video_coding/timing.h"
#include "system_wrappers/include/clock.h"
#include "test/gtest.h"
#include "test/testsupport/fileutils.h"

namespace webrtc {

TEST(ReceiverTiming, Tests) {
  SimulatedClock clock(0);
  VCMTiming timing(&clock);
  uint32_t waitTime = 0;
  uint32_t jitterDelayMs = 0;
  uint32_t requiredDecodeTimeMs = 0;
  uint32_t timeStamp = 0;

  timing.Reset();

  timing.UpdateCurrentDelay(timeStamp);

  timing.Reset();

  timing.IncomingTimestamp(timeStamp, clock.TimeInMilliseconds());
  jitterDelayMs = 20;
  timing.SetJitterDelay(jitterDelayMs);
  timing.UpdateCurrentDelay(timeStamp);
  timing.set_render_delay(0);
  waitTime = timing.MaxWaitingTime(
      timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()),
      clock.TimeInMilliseconds());
  // First update initializes the render time. Since we have no decode delay
  // we get waitTime = renderTime - now - renderDelay = jitter.
  EXPECT_EQ(jitterDelayMs, waitTime);

  jitterDelayMs += VCMTiming::kDelayMaxChangeMsPerS + 10;
  timeStamp += 90000;
  clock.AdvanceTimeMilliseconds(1000);
  timing.SetJitterDelay(jitterDelayMs);
  timing.UpdateCurrentDelay(timeStamp);
  waitTime = timing.MaxWaitingTime(
      timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()),
      clock.TimeInMilliseconds());
  // Since we gradually increase the delay we only get 100 ms every second.
  EXPECT_EQ(jitterDelayMs - 10, waitTime);

  timeStamp += 90000;
  clock.AdvanceTimeMilliseconds(1000);
  timing.UpdateCurrentDelay(timeStamp);
  waitTime = timing.MaxWaitingTime(
      timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()),
      clock.TimeInMilliseconds());
  EXPECT_EQ(waitTime, jitterDelayMs);

  // 300 incoming frames without jitter, verify that this gives the exact wait
  // time.
  for (int i = 0; i < 300; i++) {
    clock.AdvanceTimeMilliseconds(1000 / 25);
    timeStamp += 90000 / 25;
    timing.IncomingTimestamp(timeStamp, clock.TimeInMilliseconds());
  }
  timing.UpdateCurrentDelay(timeStamp);
  waitTime = timing.MaxWaitingTime(
      timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()),
      clock.TimeInMilliseconds());
  EXPECT_EQ(waitTime, jitterDelayMs);

  // Add decode time estimates.
  for (int i = 0; i < 10; i++) {
    int64_t startTimeMs = clock.TimeInMilliseconds();
    clock.AdvanceTimeMilliseconds(10);
    timing.StopDecodeTimer(
        timeStamp, clock.TimeInMilliseconds() - startTimeMs,
        clock.TimeInMilliseconds(),
        timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()));
    timeStamp += 90000 / 25;
    clock.AdvanceTimeMilliseconds(1000 / 25 - 10);
    timing.IncomingTimestamp(timeStamp, clock.TimeInMilliseconds());
  }
  requiredDecodeTimeMs = 10;
  timing.SetJitterDelay(jitterDelayMs);
  clock.AdvanceTimeMilliseconds(1000);
  timeStamp += 90000;
  timing.UpdateCurrentDelay(timeStamp);
  waitTime = timing.MaxWaitingTime(
      timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()),
      clock.TimeInMilliseconds());
  EXPECT_EQ(waitTime, jitterDelayMs);

  int minTotalDelayMs = 200;
  timing.set_min_playout_delay(minTotalDelayMs);
  clock.AdvanceTimeMilliseconds(5000);
  timeStamp += 5 * 90000;
  timing.UpdateCurrentDelay(timeStamp);
  const int kRenderDelayMs = 10;
  timing.set_render_delay(kRenderDelayMs);
  waitTime = timing.MaxWaitingTime(
      timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()),
      clock.TimeInMilliseconds());
  // We should at least have minTotalDelayMs - decodeTime (10) - renderTime
  // (10) to wait.
  EXPECT_EQ(waitTime, minTotalDelayMs - requiredDecodeTimeMs - kRenderDelayMs);
  // The total video delay should be equal to the min total delay.
  EXPECT_EQ(minTotalDelayMs, timing.TargetVideoDelay());

  // Reset playout delay.
  timing.set_min_playout_delay(0);
  clock.AdvanceTimeMilliseconds(5000);
  timeStamp += 5 * 90000;
  timing.UpdateCurrentDelay(timeStamp);
}

TEST(ReceiverTiming, WrapAround) {
  const int kFramerate = 25;
  SimulatedClock clock(0);
  VCMTiming timing(&clock);
  // Provoke a wrap-around. The forth frame will have wrapped at 25 fps.
  uint32_t timestamp = 0xFFFFFFFFu - 3 * 90000 / kFramerate;
  for (int i = 0; i < 4; ++i) {
    timing.IncomingTimestamp(timestamp, clock.TimeInMilliseconds());
    clock.AdvanceTimeMilliseconds(1000 / kFramerate);
    timestamp += 90000 / kFramerate;
    int64_t render_time =
        timing.RenderTimeMs(0xFFFFFFFFu, clock.TimeInMilliseconds());
    EXPECT_EQ(3 * 1000 / kFramerate, render_time);
    render_time = timing.RenderTimeMs(89u,  // One second later in 90 kHz.
                                      clock.TimeInMilliseconds());
    EXPECT_EQ(3 * 1000 / kFramerate + 1, render_time);
  }
}

}  // namespace webrtc