Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: webrtc/modules/video_coding/frame_buffer2_unittest.cc

Issue 2682073003: Revert Make the new jitter buffer the default jitter buffer. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/video_coding/frame_buffer2.h" 11 #include "webrtc/modules/video_coding/frame_buffer2.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <cstring> 14 #include <cstring>
15 #include <limits> 15 #include <limits>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/platform_thread.h" 18 #include "webrtc/base/platform_thread.h"
19 #include "webrtc/base/random.h" 19 #include "webrtc/base/random.h"
20 #include "webrtc/modules/video_coding/frame_object.h" 20 #include "webrtc/modules/video_coding/frame_object.h"
21 #include "webrtc/modules/video_coding/jitter_estimator.h" 21 #include "webrtc/modules/video_coding/jitter_estimator.h"
22 #include "webrtc/modules/video_coding/sequence_number_util.h" 22 #include "webrtc/modules/video_coding/sequence_number_util.h"
23 #include "webrtc/modules/video_coding/timing.h" 23 #include "webrtc/modules/video_coding/timing.h"
24 #include "webrtc/system_wrappers/include/clock.h" 24 #include "webrtc/system_wrappers/include/clock.h"
25 #include "webrtc/test/gmock.h" 25 #include "webrtc/test/gmock.h"
26 #include "webrtc/test/gtest.h" 26 #include "webrtc/test/gtest.h"
27 27
28 using testing::_;
29 using testing::Return;
30
31 namespace webrtc { 28 namespace webrtc {
32 namespace video_coding { 29 namespace video_coding {
33 30
34 class VCMTimingFake : public VCMTiming { 31 class VCMTimingFake : public VCMTiming {
35 public: 32 public:
36 explicit VCMTimingFake(Clock* clock) : VCMTiming(clock) {} 33 explicit VCMTimingFake(Clock* clock) : VCMTiming(clock) {}
37 34
38 int64_t RenderTimeMs(uint32_t frame_timestamp, 35 int64_t RenderTimeMs(uint32_t frame_timestamp,
39 int64_t now_ms) const override { 36 int64_t now_ms) const override {
40 if (last_ms_ == -1) { 37 if (last_ms_ == -1) {
41 last_ms_ = now_ms + kDelayMs; 38 last_ms_ = now_ms + kDelayMs;
42 last_timestamp_ = frame_timestamp; 39 last_timestamp_ = frame_timestamp;
43 } 40 }
44 41
45 uint32_t diff = MinDiff(frame_timestamp, last_timestamp_); 42 uint32_t diff = MinDiff(frame_timestamp, last_timestamp_);
46 if (AheadOf(frame_timestamp, last_timestamp_)) 43 if (AheadOf(frame_timestamp, last_timestamp_))
47 last_ms_ += diff / 90; 44 last_ms_ += diff / 90;
48 else 45 else
49 last_ms_ -= diff / 90; 46 last_ms_ -= diff / 90;
50 47
51 last_timestamp_ = frame_timestamp; 48 last_timestamp_ = frame_timestamp;
52 return last_ms_; 49 return last_ms_;
53 } 50 }
54 51
55 uint32_t MaxWaitingTime(int64_t render_time_ms, 52 uint32_t MaxWaitingTime(int64_t render_time_ms,
56 int64_t now_ms) const override { 53 int64_t now_ms) const override {
57 return std::max<int>(0, render_time_ms - now_ms - kDecodeTime); 54 return std::max<int>(0, render_time_ms - now_ms - kDecodeTime);
58 } 55 }
59 56
60 bool GetTimings(int* decode_ms,
61 int* max_decode_ms,
62 int* current_delay_ms,
63 int* target_delay_ms,
64 int* jitter_buffer_ms,
65 int* min_playout_delay_ms,
66 int* render_delay_ms) const override {
67 return true;
68 }
69
70 private: 57 private:
71 static constexpr int kDelayMs = 50; 58 static constexpr int kDelayMs = 50;
72 static constexpr int kDecodeTime = kDelayMs / 2; 59 static constexpr int kDecodeTime = kDelayMs / 2;
73 mutable uint32_t last_timestamp_ = 0; 60 mutable uint32_t last_timestamp_ = 0;
74 mutable int64_t last_ms_ = -1; 61 mutable int64_t last_ms_ = -1;
75 }; 62 };
76 63
77 class VCMJitterEstimatorMock : public VCMJitterEstimator { 64 class VCMJitterEstimatorMock : public VCMJitterEstimator {
78 public: 65 public:
79 explicit VCMJitterEstimatorMock(Clock* clock) : VCMJitterEstimator(clock) {} 66 explicit VCMJitterEstimatorMock(Clock* clock) : VCMJitterEstimator(clock) {}
80 67
81 MOCK_METHOD1(UpdateRtt, void(int64_t rttMs)); 68 MOCK_METHOD1(UpdateRtt, void(int64_t rttMs));
82 MOCK_METHOD3(UpdateEstimate, 69 MOCK_METHOD3(UpdateEstimate,
83 void(int64_t frameDelayMs, 70 void(int64_t frameDelayMs,
84 uint32_t frameSizeBytes, 71 uint32_t frameSizeBytes,
85 bool incompleteFrame)); 72 bool incompleteFrame));
86 MOCK_METHOD1(GetJitterEstimate, int(double rttMultiplier)); 73 MOCK_METHOD1(GetJitterEstimate, int(double rttMultiplier));
87 }; 74 };
88 75
89 class FrameObjectFake : public FrameObject { 76 class FrameObjectFake : public FrameObject {
90 public: 77 public:
91 bool GetBitstream(uint8_t* destination) const override { return true; } 78 bool GetBitstream(uint8_t* destination) const override { return true; }
92 79
93 uint32_t Timestamp() const override { return timestamp; } 80 uint32_t Timestamp() const override { return timestamp; }
94 81
95 int64_t ReceivedTime() const override { return 0; } 82 int64_t ReceivedTime() const override { return 0; }
96 83
97 int64_t RenderTime() const override { return _renderTimeMs; } 84 int64_t RenderTime() const override { return _renderTimeMs; }
98
99 // In EncodedImage |_length| is used to descibe its size and |_size| to
100 // describe its capacity.
101 void SetSize(int size) { _length = size; }
102 };
103
104 class VCMReceiveStatisticsCallbackMock : public VCMReceiveStatisticsCallback {
105 public:
106 MOCK_METHOD2(OnReceiveRatesUpdated,
107 void(uint32_t bitRate, uint32_t frameRate));
108 MOCK_METHOD2(OnCompleteFrame, void(bool is_keyframe, size_t size_bytes));
109 MOCK_METHOD1(OnDiscardedPacketsUpdated, void(int discarded_packets));
110 MOCK_METHOD1(OnFrameCountsUpdated, void(const FrameCounts& frame_counts));
111 MOCK_METHOD7(OnFrameBufferTimingsUpdated,
112 void(int decode_ms,
113 int max_decode_ms,
114 int current_delay_ms,
115 int target_delay_ms,
116 int jitter_buffer_ms,
117 int min_playout_delay_ms,
118 int render_delay_ms));
119 }; 85 };
120 86
121 class TestFrameBuffer2 : public ::testing::Test { 87 class TestFrameBuffer2 : public ::testing::Test {
122 protected: 88 protected:
123 static constexpr int kMaxReferences = 5; 89 static constexpr int kMaxReferences = 5;
124 static constexpr int kFps1 = 1000; 90 static constexpr int kFps1 = 1000;
125 static constexpr int kFps10 = kFps1 / 10; 91 static constexpr int kFps10 = kFps1 / 10;
126 static constexpr int kFps20 = kFps1 / 20; 92 static constexpr int kFps20 = kFps1 / 20;
127 93
128 TestFrameBuffer2() 94 TestFrameBuffer2()
129 : clock_(0), 95 : clock_(0),
130 timing_(&clock_), 96 timing_(&clock_),
131 jitter_estimator_(&clock_), 97 jitter_estimator_(&clock_),
132 buffer_(&clock_, &jitter_estimator_, &timing_, &stats_callback_), 98 buffer_(&clock_, &jitter_estimator_, &timing_),
133 rand_(0x34678213), 99 rand_(0x34678213),
134 tear_down_(false), 100 tear_down_(false),
135 extract_thread_(&ExtractLoop, this, "Extract Thread"), 101 extract_thread_(&ExtractLoop, this, "Extract Thread"),
136 trigger_extract_event_(false, false), 102 trigger_extract_event_(false, false),
137 crit_acquired_event_(false, false) {} 103 crit_acquired_event_(false, false) {}
138 104
139 void SetUp() override { extract_thread_.Start(); } 105 void SetUp() override { extract_thread_.Start(); }
140 106
141 void TearDown() override { 107 void TearDown() override {
142 tear_down_ = true; 108 tear_down_ = true;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 183 }
218 184
219 uint32_t Rand() { return rand_.Rand<uint32_t>(); } 185 uint32_t Rand() { return rand_.Rand<uint32_t>(); }
220 186
221 SimulatedClock clock_; 187 SimulatedClock clock_;
222 VCMTimingFake timing_; 188 VCMTimingFake timing_;
223 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_; 189 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_;
224 FrameBuffer buffer_; 190 FrameBuffer buffer_;
225 std::vector<std::unique_ptr<FrameObject>> frames_; 191 std::vector<std::unique_ptr<FrameObject>> frames_;
226 Random rand_; 192 Random rand_;
227 ::testing::NiceMock<VCMReceiveStatisticsCallbackMock> stats_callback_;
228 193
229 int64_t max_wait_time_; 194 int64_t max_wait_time_;
230 bool tear_down_; 195 bool tear_down_;
231 rtc::PlatformThread extract_thread_; 196 rtc::PlatformThread extract_thread_;
232 rtc::Event trigger_extract_event_; 197 rtc::Event trigger_extract_event_;
233 rtc::Event crit_acquired_event_; 198 rtc::Event crit_acquired_event_;
234 rtc::CriticalSection crit_; 199 rtc::CriticalSection crit_;
235 }; 200 };
236 201
237 // Following tests are timing dependent. Either the timeouts have to 202 // Following tests are timing dependent. Either the timeouts have to
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 CheckFrame(0, pid, 0); 430 CheckFrame(0, pid, 0);
466 431
467 // Jump back in pid but increase ts. 432 // Jump back in pid but increase ts.
468 EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false)); 433 EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false));
469 ExtractFrame(); 434 ExtractFrame();
470 ExtractFrame(); 435 ExtractFrame();
471 CheckFrame(1, pid - 1, 0); 436 CheckFrame(1, pid - 1, 0);
472 CheckNoFrame(2); 437 CheckNoFrame(2);
473 } 438 }
474 439
475 TEST_F(TestFrameBuffer2, StatsCallback) {
476 uint16_t pid = Rand();
477 uint32_t ts = Rand();
478 const int kFrameSize = 5000;
479
480 EXPECT_CALL(stats_callback_, OnCompleteFrame(true, kFrameSize));
481 EXPECT_CALL(stats_callback_,
482 OnFrameBufferTimingsUpdated(_, _, _, _, _, _, _));
483
484 {
485 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
486 frame->SetSize(kFrameSize);
487 frame->picture_id = pid;
488 frame->spatial_layer = 0;
489 frame->timestamp = ts;
490 frame->num_references = 0;
491 frame->inter_layer_predicted = false;
492
493 EXPECT_EQ(buffer_.InsertFrame(std::move(frame)), pid);
494 }
495
496 ExtractFrame();
497 CheckFrame(0, pid, 0);
498 }
499
500 } // namespace video_coding 440 } // namespace video_coding
501 } // namespace webrtc 441 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/frame_buffer2.cc ('k') | webrtc/modules/video_coding/include/video_coding_defines.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698