You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

497 lines
19 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
  2. *
  3. * Use of this source code is governed by a BSD-style license
  4. * that can be found in the LICENSE file in the root of the source
  5. * tree. An additional intellectual property rights grant can be found
  6. * in the file PATENTS. All contributing project authors may
  7. * be found in the AUTHORS file in the root of the source tree.
  8. */
  9. #include "modules/video_coding/receiver.h"
  10. #include <string.h>
  11. #include <cstdint>
  12. #include <memory>
  13. #include <queue>
  14. #include <vector>
  15. #include "modules/video_coding/encoded_frame.h"
  16. #include "modules/video_coding/jitter_buffer_common.h"
  17. #include "modules/video_coding/packet.h"
  18. #include "modules/video_coding/test/stream_generator.h"
  19. #include "modules/video_coding/timing.h"
  20. #include "rtc_base/checks.h"
  21. #include "system_wrappers/include/clock.h"
  22. #include "test/gtest.h"
  23. namespace webrtc {
  24. class TestVCMReceiver : public ::testing::Test {
  25. protected:
  26. TestVCMReceiver()
  27. : clock_(new SimulatedClock(0)),
  28. timing_(clock_.get()),
  29. receiver_(&timing_, clock_.get()) {
  30. stream_generator_.reset(
  31. new StreamGenerator(0, clock_->TimeInMilliseconds()));
  32. }
  33. virtual void SetUp() {}
  34. int32_t InsertPacket(int index) {
  35. VCMPacket packet;
  36. bool packet_available = stream_generator_->GetPacket(&packet, index);
  37. EXPECT_TRUE(packet_available);
  38. if (!packet_available)
  39. return kGeneralError; // Return here to avoid crashes below.
  40. return receiver_.InsertPacket(packet);
  41. }
  42. int32_t InsertPacketAndPop(int index) {
  43. VCMPacket packet;
  44. bool packet_available = stream_generator_->PopPacket(&packet, index);
  45. EXPECT_TRUE(packet_available);
  46. if (!packet_available)
  47. return kGeneralError; // Return here to avoid crashes below.
  48. return receiver_.InsertPacket(packet);
  49. }
  50. int32_t InsertFrame(VideoFrameType frame_type, bool complete) {
  51. int num_of_packets = complete ? 1 : 2;
  52. stream_generator_->GenerateFrame(
  53. frame_type,
  54. (frame_type != VideoFrameType::kEmptyFrame) ? num_of_packets : 0,
  55. (frame_type == VideoFrameType::kEmptyFrame) ? 1 : 0,
  56. clock_->TimeInMilliseconds());
  57. int32_t ret = InsertPacketAndPop(0);
  58. if (!complete) {
  59. // Drop the second packet.
  60. VCMPacket packet;
  61. stream_generator_->PopPacket(&packet, 0);
  62. }
  63. clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
  64. return ret;
  65. }
  66. bool DecodeNextFrame() {
  67. VCMEncodedFrame* frame = receiver_.FrameForDecoding(0, false);
  68. if (!frame)
  69. return false;
  70. receiver_.ReleaseFrame(frame);
  71. return true;
  72. }
  73. std::unique_ptr<SimulatedClock> clock_;
  74. VCMTiming timing_;
  75. VCMReceiver receiver_;
  76. std::unique_ptr<StreamGenerator> stream_generator_;
  77. };
  78. TEST_F(TestVCMReceiver, NonDecodableDuration_Empty) {
  79. const size_t kMaxNackListSize = 1000;
  80. const int kMaxPacketAgeToNack = 1000;
  81. const int kMaxNonDecodableDuration = 500;
  82. const int kMinDelayMs = 500;
  83. receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
  84. kMaxNonDecodableDuration);
  85. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameKey, true), kNoError);
  86. // Advance time until it's time to decode the key frame.
  87. clock_->AdvanceTimeMilliseconds(kMinDelayMs);
  88. EXPECT_TRUE(DecodeNextFrame());
  89. bool request_key_frame = false;
  90. std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame);
  91. EXPECT_FALSE(request_key_frame);
  92. }
  93. TEST_F(TestVCMReceiver, NonDecodableDuration_NoKeyFrame) {
  94. const size_t kMaxNackListSize = 1000;
  95. const int kMaxPacketAgeToNack = 1000;
  96. const int kMaxNonDecodableDuration = 500;
  97. receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
  98. kMaxNonDecodableDuration);
  99. const int kNumFrames = kDefaultFrameRate * kMaxNonDecodableDuration / 1000;
  100. for (int i = 0; i < kNumFrames; ++i) {
  101. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, true), kNoError);
  102. }
  103. bool request_key_frame = false;
  104. std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame);
  105. EXPECT_TRUE(request_key_frame);
  106. }
  107. TEST_F(TestVCMReceiver, NonDecodableDuration_OneIncomplete) {
  108. const size_t kMaxNackListSize = 1000;
  109. const int kMaxPacketAgeToNack = 1000;
  110. const int kMaxNonDecodableDuration = 500;
  111. const int kMaxNonDecodableDurationFrames =
  112. (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000;
  113. const int kMinDelayMs = 500;
  114. receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
  115. kMaxNonDecodableDuration);
  116. timing_.set_min_playout_delay(kMinDelayMs);
  117. int64_t key_frame_inserted = clock_->TimeInMilliseconds();
  118. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameKey, true), kNoError);
  119. // Insert an incomplete frame.
  120. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, false), kNoError);
  121. // Insert enough frames to have too long non-decodable sequence.
  122. for (int i = 0; i < kMaxNonDecodableDurationFrames; ++i) {
  123. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, true), kNoError);
  124. }
  125. // Advance time until it's time to decode the key frame.
  126. clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
  127. key_frame_inserted);
  128. EXPECT_TRUE(DecodeNextFrame());
  129. // Make sure we get a key frame request.
  130. bool request_key_frame = false;
  131. std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame);
  132. EXPECT_TRUE(request_key_frame);
  133. }
  134. TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger) {
  135. const size_t kMaxNackListSize = 1000;
  136. const int kMaxPacketAgeToNack = 1000;
  137. const int kMaxNonDecodableDuration = 500;
  138. const int kMaxNonDecodableDurationFrames =
  139. (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000;
  140. const int kMinDelayMs = 500;
  141. receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
  142. kMaxNonDecodableDuration);
  143. timing_.set_min_playout_delay(kMinDelayMs);
  144. int64_t key_frame_inserted = clock_->TimeInMilliseconds();
  145. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameKey, true), kNoError);
  146. // Insert an incomplete frame.
  147. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, false), kNoError);
  148. // Insert all but one frame to not trigger a key frame request due to
  149. // too long duration of non-decodable frames.
  150. for (int i = 0; i < kMaxNonDecodableDurationFrames - 1; ++i) {
  151. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, true), kNoError);
  152. }
  153. // Advance time until it's time to decode the key frame.
  154. clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
  155. key_frame_inserted);
  156. EXPECT_TRUE(DecodeNextFrame());
  157. // Make sure we don't get a key frame request since we haven't generated
  158. // enough frames.
  159. bool request_key_frame = false;
  160. std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame);
  161. EXPECT_FALSE(request_key_frame);
  162. }
  163. TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger2) {
  164. const size_t kMaxNackListSize = 1000;
  165. const int kMaxPacketAgeToNack = 1000;
  166. const int kMaxNonDecodableDuration = 500;
  167. const int kMaxNonDecodableDurationFrames =
  168. (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000;
  169. const int kMinDelayMs = 500;
  170. receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
  171. kMaxNonDecodableDuration);
  172. timing_.set_min_playout_delay(kMinDelayMs);
  173. int64_t key_frame_inserted = clock_->TimeInMilliseconds();
  174. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameKey, true), kNoError);
  175. // Insert enough frames to have too long non-decodable sequence, except that
  176. // we don't have any losses.
  177. for (int i = 0; i < kMaxNonDecodableDurationFrames; ++i) {
  178. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, true), kNoError);
  179. }
  180. // Insert an incomplete frame.
  181. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, false), kNoError);
  182. // Advance time until it's time to decode the key frame.
  183. clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
  184. key_frame_inserted);
  185. EXPECT_TRUE(DecodeNextFrame());
  186. // Make sure we don't get a key frame request since the non-decodable duration
  187. // is only one frame.
  188. bool request_key_frame = false;
  189. std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame);
  190. EXPECT_FALSE(request_key_frame);
  191. }
  192. TEST_F(TestVCMReceiver, NonDecodableDuration_KeyFrameAfterIncompleteFrames) {
  193. const size_t kMaxNackListSize = 1000;
  194. const int kMaxPacketAgeToNack = 1000;
  195. const int kMaxNonDecodableDuration = 500;
  196. const int kMaxNonDecodableDurationFrames =
  197. (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000;
  198. const int kMinDelayMs = 500;
  199. receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
  200. kMaxNonDecodableDuration);
  201. timing_.set_min_playout_delay(kMinDelayMs);
  202. int64_t key_frame_inserted = clock_->TimeInMilliseconds();
  203. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameKey, true), kNoError);
  204. // Insert an incomplete frame.
  205. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, false), kNoError);
  206. // Insert enough frames to have too long non-decodable sequence.
  207. for (int i = 0; i < kMaxNonDecodableDurationFrames; ++i) {
  208. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameDelta, true), kNoError);
  209. }
  210. EXPECT_GE(InsertFrame(VideoFrameType::kVideoFrameKey, true), kNoError);
  211. // Advance time until it's time to decode the key frame.
  212. clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
  213. key_frame_inserted);
  214. EXPECT_TRUE(DecodeNextFrame());
  215. // Make sure we don't get a key frame request since we have a key frame
  216. // in the list.
  217. bool request_key_frame = false;
  218. std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame);
  219. EXPECT_FALSE(request_key_frame);
  220. }
  221. // A simulated clock, when time elapses, will insert frames into the jitter
  222. // buffer, based on initial settings.
  223. class SimulatedClockWithFrames : public SimulatedClock {
  224. public:
  225. SimulatedClockWithFrames(StreamGenerator* stream_generator,
  226. VCMReceiver* receiver)
  227. : SimulatedClock(0),
  228. stream_generator_(stream_generator),
  229. receiver_(receiver) {}
  230. virtual ~SimulatedClockWithFrames() {}
  231. // If |stop_on_frame| is true and next frame arrives between now and
  232. // now+|milliseconds|, the clock will be advanced to the arrival time of next
  233. // frame.
  234. // Otherwise, the clock will be advanced by |milliseconds|.
  235. //
  236. // For both cases, a frame will be inserted into the jitter buffer at the
  237. // instant when the clock time is timestamps_.front().arrive_time.
  238. //
  239. // Return true if some frame arrives between now and now+|milliseconds|.
  240. bool AdvanceTimeMilliseconds(int64_t milliseconds, bool stop_on_frame) {
  241. return AdvanceTimeMicroseconds(milliseconds * 1000, stop_on_frame);
  242. }
  243. bool AdvanceTimeMicroseconds(int64_t microseconds, bool stop_on_frame) {
  244. int64_t start_time = TimeInMicroseconds();
  245. int64_t end_time = start_time + microseconds;
  246. bool frame_injected = false;
  247. while (!timestamps_.empty() &&
  248. timestamps_.front().arrive_time <= end_time) {
  249. RTC_DCHECK_GE(timestamps_.front().arrive_time, start_time);
  250. SimulatedClock::AdvanceTimeMicroseconds(timestamps_.front().arrive_time -
  251. TimeInMicroseconds());
  252. GenerateAndInsertFrame((timestamps_.front().render_time + 500) / 1000);
  253. timestamps_.pop();
  254. frame_injected = true;
  255. if (stop_on_frame)
  256. return frame_injected;
  257. }
  258. if (TimeInMicroseconds() < end_time) {
  259. SimulatedClock::AdvanceTimeMicroseconds(end_time - TimeInMicroseconds());
  260. }
  261. return frame_injected;
  262. }
  263. // Input timestamps are in unit Milliseconds.
  264. // And |arrive_timestamps| must be positive and in increasing order.
  265. // |arrive_timestamps| determine when we are going to insert frames into the
  266. // jitter buffer.
  267. // |render_timestamps| are the timestamps on the frame.
  268. void SetFrames(const int64_t* arrive_timestamps,
  269. const int64_t* render_timestamps,
  270. size_t size) {
  271. int64_t previous_arrive_timestamp = 0;
  272. for (size_t i = 0; i < size; i++) {
  273. RTC_CHECK_GE(arrive_timestamps[i], previous_arrive_timestamp);
  274. timestamps_.push(TimestampPair(arrive_timestamps[i] * 1000,
  275. render_timestamps[i] * 1000));
  276. previous_arrive_timestamp = arrive_timestamps[i];
  277. }
  278. }
  279. private:
  280. struct TimestampPair {
  281. TimestampPair(int64_t arrive_timestamp, int64_t render_timestamp)
  282. : arrive_time(arrive_timestamp), render_time(render_timestamp) {}
  283. int64_t arrive_time;
  284. int64_t render_time;
  285. };
  286. void GenerateAndInsertFrame(int64_t render_timestamp_ms) {
  287. VCMPacket packet;
  288. stream_generator_->GenerateFrame(VideoFrameType::kVideoFrameKey,
  289. 1, // media packets
  290. 0, // empty packets
  291. render_timestamp_ms);
  292. bool packet_available = stream_generator_->PopPacket(&packet, 0);
  293. EXPECT_TRUE(packet_available);
  294. if (!packet_available)
  295. return; // Return here to avoid crashes below.
  296. receiver_->InsertPacket(packet);
  297. }
  298. std::queue<TimestampPair> timestamps_;
  299. StreamGenerator* stream_generator_;
  300. VCMReceiver* receiver_;
  301. };
  302. // Use a SimulatedClockWithFrames
  303. // Wait call will do either of these:
  304. // 1. If |stop_on_frame| is true, the clock will be turned to the exact instant
  305. // that the first frame comes and the frame will be inserted into the jitter
  306. // buffer, or the clock will be turned to now + |max_time| if no frame comes in
  307. // the window.
  308. // 2. If |stop_on_frame| is false, the clock will be turn to now + |max_time|,
  309. // and all the frames arriving between now and now + |max_time| will be
  310. // inserted into the jitter buffer.
  311. //
  312. // This is used to simulate the JitterBuffer getting packets from internet as
  313. // time elapses.
  314. class FrameInjectEvent : public EventWrapper {
  315. public:
  316. FrameInjectEvent(SimulatedClockWithFrames* clock, bool stop_on_frame)
  317. : clock_(clock), stop_on_frame_(stop_on_frame) {}
  318. bool Set() override { return true; }
  319. EventTypeWrapper Wait(unsigned long max_time) override { // NOLINT
  320. if (clock_->AdvanceTimeMilliseconds(max_time, stop_on_frame_) &&
  321. stop_on_frame_) {
  322. return EventTypeWrapper::kEventSignaled;
  323. } else {
  324. return EventTypeWrapper::kEventTimeout;
  325. }
  326. }
  327. private:
  328. SimulatedClockWithFrames* clock_;
  329. bool stop_on_frame_;
  330. };
  331. class VCMReceiverTimingTest : public ::testing::Test {
  332. protected:
  333. VCMReceiverTimingTest()
  334. : clock_(&stream_generator_, &receiver_),
  335. stream_generator_(0, clock_.TimeInMilliseconds()),
  336. timing_(&clock_),
  337. receiver_(
  338. &timing_,
  339. &clock_,
  340. std::unique_ptr<EventWrapper>(new FrameInjectEvent(&clock_, false)),
  341. std::unique_ptr<EventWrapper>(
  342. new FrameInjectEvent(&clock_, true))) {}
  343. virtual void SetUp() {}
  344. SimulatedClockWithFrames clock_;
  345. StreamGenerator stream_generator_;
  346. VCMTiming timing_;
  347. VCMReceiver receiver_;
  348. };
  349. // Test whether VCMReceiver::FrameForDecoding handles parameter
  350. // |max_wait_time_ms| correctly:
  351. // 1. The function execution should never take more than |max_wait_time_ms|.
  352. // 2. If the function exit before now + |max_wait_time_ms|, a frame must be
  353. // returned.
  354. TEST_F(VCMReceiverTimingTest, FrameForDecoding) {
  355. const size_t kNumFrames = 100;
  356. const int kFramePeriod = 40;
  357. int64_t arrive_timestamps[kNumFrames];
  358. int64_t render_timestamps[kNumFrames];
  359. // Construct test samples.
  360. // render_timestamps are the timestamps stored in the Frame;
  361. // arrive_timestamps controls when the Frame packet got received.
  362. for (size_t i = 0; i < kNumFrames; i++) {
  363. // Preset frame rate to 25Hz.
  364. // But we add a reasonable deviation to arrive_timestamps to mimic Internet
  365. // fluctuation.
  366. arrive_timestamps[i] =
  367. (i + 1) * kFramePeriod + (i % 10) * ((i % 2) ? 1 : -1);
  368. render_timestamps[i] = (i + 1) * kFramePeriod;
  369. }
  370. clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames);
  371. // Record how many frames we finally get out of the receiver.
  372. size_t num_frames_return = 0;
  373. const int64_t kMaxWaitTime = 30;
  374. // Ideally, we should get all frames that we input in InitializeFrames.
  375. // In the case that FrameForDecoding kills frames by error, we rely on the
  376. // build bot to kill the test.
  377. while (num_frames_return < kNumFrames) {
  378. int64_t start_time = clock_.TimeInMilliseconds();
  379. VCMEncodedFrame* frame = receiver_.FrameForDecoding(kMaxWaitTime, false);
  380. int64_t end_time = clock_.TimeInMilliseconds();
  381. // In any case the FrameForDecoding should not wait longer than
  382. // max_wait_time.
  383. // In the case that we did not get a frame, it should have been waiting for
  384. // exactly max_wait_time. (By the testing samples we constructed above, we
  385. // are sure there is no timing error, so the only case it returns with NULL
  386. // is that it runs out of time.)
  387. if (frame) {
  388. receiver_.ReleaseFrame(frame);
  389. ++num_frames_return;
  390. EXPECT_GE(kMaxWaitTime, end_time - start_time);
  391. } else {
  392. EXPECT_EQ(kMaxWaitTime, end_time - start_time);
  393. }
  394. }
  395. }
  396. // Test whether VCMReceiver::FrameForDecoding handles parameter
  397. // |prefer_late_decoding| and |max_wait_time_ms| correctly:
  398. // 1. The function execution should never take more than |max_wait_time_ms|.
  399. // 2. If the function exit before now + |max_wait_time_ms|, a frame must be
  400. // returned and the end time must be equal to the render timestamp - delay
  401. // for decoding and rendering.
  402. TEST_F(VCMReceiverTimingTest, FrameForDecodingPreferLateDecoding) {
  403. const size_t kNumFrames = 100;
  404. const int kFramePeriod = 40;
  405. int64_t arrive_timestamps[kNumFrames];
  406. int64_t render_timestamps[kNumFrames];
  407. int render_delay_ms;
  408. int max_decode_ms;
  409. int dummy;
  410. timing_.GetTimings(&max_decode_ms, &dummy, &dummy, &dummy, &dummy,
  411. &render_delay_ms);
  412. // Construct test samples.
  413. // render_timestamps are the timestamps stored in the Frame;
  414. // arrive_timestamps controls when the Frame packet got received.
  415. for (size_t i = 0; i < kNumFrames; i++) {
  416. // Preset frame rate to 25Hz.
  417. // But we add a reasonable deviation to arrive_timestamps to mimic Internet
  418. // fluctuation.
  419. arrive_timestamps[i] =
  420. (i + 1) * kFramePeriod + (i % 10) * ((i % 2) ? 1 : -1);
  421. render_timestamps[i] = (i + 1) * kFramePeriod;
  422. }
  423. clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames);
  424. // Record how many frames we finally get out of the receiver.
  425. size_t num_frames_return = 0;
  426. const int64_t kMaxWaitTime = 30;
  427. bool prefer_late_decoding = true;
  428. while (num_frames_return < kNumFrames) {
  429. int64_t start_time = clock_.TimeInMilliseconds();
  430. VCMEncodedFrame* frame =
  431. receiver_.FrameForDecoding(kMaxWaitTime, prefer_late_decoding);
  432. int64_t end_time = clock_.TimeInMilliseconds();
  433. if (frame) {
  434. EXPECT_EQ(frame->RenderTimeMs() - max_decode_ms - render_delay_ms,
  435. end_time);
  436. receiver_.ReleaseFrame(frame);
  437. ++num_frames_return;
  438. } else {
  439. EXPECT_EQ(kMaxWaitTime, end_time - start_time);
  440. }
  441. }
  442. }
  443. } // namespace webrtc