Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/webrtc/modules/video_coding/main/source/receiver_unittest.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 13.2 KB
Line 
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
10#include <string.h>
11
12#include <list>
13
14#include "testing/gtest/include/gtest/gtest.h"
15#include "webrtc/modules/video_coding/main/source/packet.h"
16#include "webrtc/modules/video_coding/main/source/receiver.h"
17#include "webrtc/modules/video_coding/main/source/test/stream_generator.h"
18#include "webrtc/modules/video_coding/main/source/timing.h"
19#include "webrtc/modules/video_coding/main/test/test_util.h"
20#include "webrtc/system_wrappers/interface/clock.h"
21#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
22
23namespace webrtc {
24
25class TestVCMReceiver : public ::testing::Test {
26 protected:
27  enum { kDataBufferSize = 10 };
28  enum { kWidth = 640 };
29  enum { kHeight = 480 };
30
31  TestVCMReceiver()
32      : clock_(new SimulatedClock(0)),
33        timing_(clock_.get()),
34        receiver_(&timing_, clock_.get(), &event_factory_, 1, 1, true) {
35    stream_generator_.reset(new
36        StreamGenerator(0, 0, clock_->TimeInMilliseconds()));
37    memset(data_buffer_, 0, kDataBufferSize);
38  }
39
40  virtual void SetUp() {
41    receiver_.Reset();
42  }
43
44  int32_t InsertPacket(int index) {
45    VCMPacket packet;
46    packet.dataPtr = data_buffer_;
47    bool packet_available = stream_generator_->GetPacket(&packet, index);
48    EXPECT_TRUE(packet_available);
49    if (!packet_available)
50      return kGeneralError;  // Return here to avoid crashes below.
51    // Arbitrary width and height.
52    return receiver_.InsertPacket(packet, 640, 480);
53  }
54
55  int32_t InsertPacketAndPop(int index) {
56    VCMPacket packet;
57    packet.dataPtr = data_buffer_;
58    bool packet_available = stream_generator_->PopPacket(&packet, index);
59    EXPECT_TRUE(packet_available);
60    if (!packet_available)
61      return kGeneralError;  // Return here to avoid crashes below.
62    return receiver_.InsertPacket(packet, kWidth, kHeight);
63  }
64
65  int32_t InsertFrame(FrameType frame_type, bool complete) {
66    int num_of_packets = complete ? 1 : 2;
67    stream_generator_->GenerateFrame(
68        frame_type,
69        (frame_type != kFrameEmpty) ? num_of_packets : 0,
70        (frame_type == kFrameEmpty) ? 1 : 0,
71        clock_->TimeInMilliseconds());
72    int32_t ret = InsertPacketAndPop(0);
73    if (!complete) {
74      // Drop the second packet.
75      VCMPacket packet;
76      stream_generator_->PopPacket(&packet, 0);
77    }
78    clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
79    return ret;
80  }
81
82  bool DecodeNextFrame() {
83    int64_t render_time_ms = 0;
84    VCMEncodedFrame* frame = receiver_.FrameForDecoding(0, render_time_ms,
85                                                        false, NULL);
86    if (!frame)
87      return false;
88    receiver_.ReleaseFrame(frame);
89    return true;
90  }
91
92  scoped_ptr<SimulatedClock> clock_;
93  VCMTiming timing_;
94  NullEventFactory event_factory_;
95  VCMReceiver receiver_;
96  scoped_ptr<StreamGenerator> stream_generator_;
97  uint8_t data_buffer_[kDataBufferSize];
98};
99
100TEST_F(TestVCMReceiver, RenderBufferSize_AllComplete) {
101  EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
102  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
103  int num_of_frames = 10;
104  for (int i = 0; i < num_of_frames; ++i) {
105    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
106  }
107  EXPECT_EQ(num_of_frames * kDefaultFramePeriodMs,
108            receiver_.RenderBufferSizeMs());
109}
110
111TEST_F(TestVCMReceiver, RenderBufferSize_SkipToKeyFrame) {
112  EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
113  const int kNumOfNonDecodableFrames = 2;
114  for (int i = 0; i < kNumOfNonDecodableFrames; ++i) {
115    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
116  }
117  const int kNumOfFrames = 10;
118  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
119  for (int i = 0; i < kNumOfFrames - 1; ++i) {
120    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
121  }
122  EXPECT_EQ((kNumOfFrames - 1) * kDefaultFramePeriodMs,
123      receiver_.RenderBufferSizeMs());
124}
125
126TEST_F(TestVCMReceiver, RenderBufferSize_NotAllComplete) {
127  EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
128  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
129  int num_of_frames = 10;
130  for (int i = 0; i < num_of_frames; ++i) {
131    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
132  }
133  num_of_frames++;
134  EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
135  for (int i = 0; i < num_of_frames; ++i) {
136    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
137  }
138  EXPECT_EQ((num_of_frames - 1) * kDefaultFramePeriodMs,
139      receiver_.RenderBufferSizeMs());
140}
141
142TEST_F(TestVCMReceiver, RenderBufferSize_NoKeyFrame) {
143  EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
144  int num_of_frames = 10;
145  for (int i = 0; i < num_of_frames; ++i) {
146    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
147  }
148  int64_t next_render_time_ms = 0;
149  VCMEncodedFrame* frame = receiver_.FrameForDecoding(10, next_render_time_ms);
150  EXPECT_TRUE(frame == NULL);
151  receiver_.ReleaseFrame(frame);
152  EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
153  for (int i = 0; i < num_of_frames; ++i) {
154    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
155  }
156  EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
157}
158
159TEST_F(TestVCMReceiver, NonDecodableDuration_Empty) {
160  // Enable NACK and with no RTT thresholds for disabling retransmission delay.
161  receiver_.SetNackMode(kNack, -1, -1);
162  const size_t kMaxNackListSize = 1000;
163  const int kMaxPacketAgeToNack = 1000;
164  const int kMaxNonDecodableDuration = 500;
165  const int kMinDelayMs = 500;
166  receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
167      kMaxNonDecodableDuration);
168  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
169  // Advance time until it's time to decode the key frame.
170  clock_->AdvanceTimeMilliseconds(kMinDelayMs);
171  EXPECT_TRUE(DecodeNextFrame());
172  uint16_t nack_list[kMaxNackListSize];
173  uint16_t nack_list_length = 0;
174  VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
175                                         &nack_list_length);
176  EXPECT_EQ(kNackOk, ret);
177}
178
179TEST_F(TestVCMReceiver, NonDecodableDuration_NoKeyFrame) {
180  // Enable NACK and with no RTT thresholds for disabling retransmission delay.
181  receiver_.SetNackMode(kNack, -1, -1);
182  const size_t kMaxNackListSize = 1000;
183  const int kMaxPacketAgeToNack = 1000;
184  const int kMaxNonDecodableDuration = 500;
185  receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
186      kMaxNonDecodableDuration);
187  const int kNumFrames = kDefaultFrameRate * kMaxNonDecodableDuration / 1000;
188  for (int i = 0; i < kNumFrames; ++i) {
189    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
190  }
191  uint16_t nack_list[kMaxNackListSize];
192  uint16_t nack_list_length = 0;
193  VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
194                                         &nack_list_length);
195  EXPECT_EQ(kNackKeyFrameRequest, ret);
196}
197
198TEST_F(TestVCMReceiver, NonDecodableDuration_OneIncomplete) {
199  // Enable NACK and with no RTT thresholds for disabling retransmission delay.
200  receiver_.SetNackMode(kNack, -1, -1);
201  const size_t kMaxNackListSize = 1000;
202  const int kMaxPacketAgeToNack = 1000;
203  const int kMaxNonDecodableDuration = 500;
204  const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate *
205      kMaxNonDecodableDuration + 500) / 1000;
206  const int kMinDelayMs = 500;
207  receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
208      kMaxNonDecodableDuration);
209  receiver_.SetMinReceiverDelay(kMinDelayMs);
210  int64_t key_frame_inserted = clock_->TimeInMilliseconds();
211  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
212  // Insert an incomplete frame.
213  EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
214  // Insert enough frames to have too long non-decodable sequence.
215  for (int i = 0; i < kMaxNonDecodableDurationFrames;
216       ++i) {
217    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
218  }
219  // Advance time until it's time to decode the key frame.
220  clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
221      key_frame_inserted);
222  EXPECT_TRUE(DecodeNextFrame());
223  // Make sure we get a key frame request.
224  uint16_t nack_list[kMaxNackListSize];
225  uint16_t nack_list_length = 0;
226  VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
227                                         &nack_list_length);
228  EXPECT_EQ(kNackKeyFrameRequest, ret);
229}
230
231TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger) {
232  // Enable NACK and with no RTT thresholds for disabling retransmission delay.
233  receiver_.SetNackMode(kNack, -1, -1);
234  const size_t kMaxNackListSize = 1000;
235  const int kMaxPacketAgeToNack = 1000;
236  const int kMaxNonDecodableDuration = 500;
237  const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate *
238      kMaxNonDecodableDuration + 500) / 1000;
239  const int kMinDelayMs = 500;
240  receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
241      kMaxNonDecodableDuration);
242  receiver_.SetMinReceiverDelay(kMinDelayMs);
243  int64_t key_frame_inserted = clock_->TimeInMilliseconds();
244  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
245  // Insert an incomplete frame.
246  EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
247  // Insert all but one frame to not trigger a key frame request due to
248  // too long duration of non-decodable frames.
249  for (int i = 0; i < kMaxNonDecodableDurationFrames - 1;
250       ++i) {
251    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
252  }
253  // Advance time until it's time to decode the key frame.
254  clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
255      key_frame_inserted);
256  EXPECT_TRUE(DecodeNextFrame());
257  // Make sure we don't get a key frame request since we haven't generated
258  // enough frames.
259  uint16_t nack_list[kMaxNackListSize];
260  uint16_t nack_list_length = 0;
261  VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
262                                         &nack_list_length);
263  EXPECT_EQ(kNackOk, ret);
264}
265
266TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger2) {
267  // Enable NACK and with no RTT thresholds for disabling retransmission delay.
268  receiver_.SetNackMode(kNack, -1, -1);
269  const size_t kMaxNackListSize = 1000;
270  const int kMaxPacketAgeToNack = 1000;
271  const int kMaxNonDecodableDuration = 500;
272  const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate *
273      kMaxNonDecodableDuration + 500) / 1000;
274  const int kMinDelayMs = 500;
275  receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
276      kMaxNonDecodableDuration);
277  receiver_.SetMinReceiverDelay(kMinDelayMs);
278  int64_t key_frame_inserted = clock_->TimeInMilliseconds();
279  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
280  // Insert enough frames to have too long non-decodable sequence, except that
281  // we don't have any losses.
282  for (int i = 0; i < kMaxNonDecodableDurationFrames;
283       ++i) {
284    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
285  }
286  // Insert an incomplete frame.
287  EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
288  // Advance time until it's time to decode the key frame.
289  clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
290      key_frame_inserted);
291  EXPECT_TRUE(DecodeNextFrame());
292  // Make sure we don't get a key frame request since the non-decodable duration
293  // is only one frame.
294  uint16_t nack_list[kMaxNackListSize];
295  uint16_t nack_list_length = 0;
296  VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
297                                         &nack_list_length);
298  EXPECT_EQ(kNackOk, ret);
299}
300
301TEST_F(TestVCMReceiver, NonDecodableDuration_KeyFrameAfterIncompleteFrames) {
302  // Enable NACK and with no RTT thresholds for disabling retransmission delay.
303  receiver_.SetNackMode(kNack, -1, -1);
304  const size_t kMaxNackListSize = 1000;
305  const int kMaxPacketAgeToNack = 1000;
306  const int kMaxNonDecodableDuration = 500;
307  const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate *
308      kMaxNonDecodableDuration + 500) / 1000;
309  const int kMinDelayMs = 500;
310  receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
311      kMaxNonDecodableDuration);
312  receiver_.SetMinReceiverDelay(kMinDelayMs);
313  int64_t key_frame_inserted = clock_->TimeInMilliseconds();
314  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
315  // Insert an incomplete frame.
316  EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
317  // Insert enough frames to have too long non-decodable sequence.
318  for (int i = 0; i < kMaxNonDecodableDurationFrames;
319       ++i) {
320    EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
321  }
322  EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
323  // Advance time until it's time to decode the key frame.
324  clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
325      key_frame_inserted);
326  EXPECT_TRUE(DecodeNextFrame());
327  // Make sure we don't get a key frame request since we have a key frame
328  // in the list.
329  uint16_t nack_list[kMaxNackListSize];
330  uint16_t nack_list_length = 0;
331  VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
332                                         &nack_list_length);
333  EXPECT_EQ(kNackOk, ret);
334}
335}  // namespace webrtc
Note: See TracBrowser for help on using the repository browser.