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

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

Issue 2652043005: Reland of Make the new jitter buffer the default jitter buffer. (Closed)
Patch Set: Rebase Created 3 years, 11 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
28 namespace webrtc { 31 namespace webrtc {
29 namespace video_coding { 32 namespace video_coding {
30 33
31 class VCMTimingFake : public VCMTiming { 34 class VCMTimingFake : public VCMTiming {
32 public: 35 public:
33 explicit VCMTimingFake(Clock* clock) : VCMTiming(clock) {} 36 explicit VCMTimingFake(Clock* clock) : VCMTiming(clock) {}
34 37
35 int64_t RenderTimeMs(uint32_t frame_timestamp, 38 int64_t RenderTimeMs(uint32_t frame_timestamp,
36 int64_t now_ms) const override { 39 int64_t now_ms) const override {
37 if (last_ms_ == -1) { 40 if (last_ms_ == -1) {
38 last_ms_ = now_ms + kDelayMs; 41 last_ms_ = now_ms + kDelayMs;
39 last_timestamp_ = frame_timestamp; 42 last_timestamp_ = frame_timestamp;
40 } 43 }
41 44
42 uint32_t diff = MinDiff(frame_timestamp, last_timestamp_); 45 uint32_t diff = MinDiff(frame_timestamp, last_timestamp_);
43 if (AheadOf(frame_timestamp, last_timestamp_)) 46 if (AheadOf(frame_timestamp, last_timestamp_))
44 last_ms_ += diff / 90; 47 last_ms_ += diff / 90;
45 else 48 else
46 last_ms_ -= diff / 90; 49 last_ms_ -= diff / 90;
47 50
48 last_timestamp_ = frame_timestamp; 51 last_timestamp_ = frame_timestamp;
49 return last_ms_; 52 return last_ms_;
50 } 53 }
51 54
52 uint32_t MaxWaitingTime(int64_t render_time_ms, 55 uint32_t MaxWaitingTime(int64_t render_time_ms,
53 int64_t now_ms) const override { 56 int64_t now_ms) const override {
54 return std::max<int>(0, render_time_ms - now_ms - kDecodeTime); 57 return std::max<int>(0, render_time_ms - now_ms - kDecodeTime);
55 } 58 }
56 59
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
57 private: 70 private:
58 static constexpr int kDelayMs = 50; 71 static constexpr int kDelayMs = 50;
59 static constexpr int kDecodeTime = kDelayMs / 2; 72 static constexpr int kDecodeTime = kDelayMs / 2;
60 mutable uint32_t last_timestamp_ = 0; 73 mutable uint32_t last_timestamp_ = 0;
61 mutable int64_t last_ms_ = -1; 74 mutable int64_t last_ms_ = -1;
62 }; 75 };
63 76
64 class VCMJitterEstimatorMock : public VCMJitterEstimator { 77 class VCMJitterEstimatorMock : public VCMJitterEstimator {
65 public: 78 public:
66 explicit VCMJitterEstimatorMock(Clock* clock) : VCMJitterEstimator(clock) {} 79 explicit VCMJitterEstimatorMock(Clock* clock) : VCMJitterEstimator(clock) {}
67 80
68 MOCK_METHOD1(UpdateRtt, void(int64_t rttMs)); 81 MOCK_METHOD1(UpdateRtt, void(int64_t rttMs));
69 MOCK_METHOD3(UpdateEstimate, 82 MOCK_METHOD3(UpdateEstimate,
70 void(int64_t frameDelayMs, 83 void(int64_t frameDelayMs,
71 uint32_t frameSizeBytes, 84 uint32_t frameSizeBytes,
72 bool incompleteFrame)); 85 bool incompleteFrame));
73 MOCK_METHOD1(GetJitterEstimate, int(double rttMultiplier)); 86 MOCK_METHOD1(GetJitterEstimate, int(double rttMultiplier));
74 }; 87 };
75 88
76 class FrameObjectFake : public FrameObject { 89 class FrameObjectFake : public FrameObject {
77 public: 90 public:
78 bool GetBitstream(uint8_t* destination) const override { return true; } 91 bool GetBitstream(uint8_t* destination) const override { return true; }
79 92
80 uint32_t Timestamp() const override { return timestamp; } 93 uint32_t Timestamp() const override { return timestamp; }
81 94
82 int64_t ReceivedTime() const override { return 0; } 95 int64_t ReceivedTime() const override { return 0; }
83 96
84 int64_t RenderTime() const override { return _renderTimeMs; } 97 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));
85 }; 119 };
86 120
87 class TestFrameBuffer2 : public ::testing::Test { 121 class TestFrameBuffer2 : public ::testing::Test {
88 protected: 122 protected:
89 static constexpr int kMaxReferences = 5; 123 static constexpr int kMaxReferences = 5;
90 static constexpr int kFps1 = 1000; 124 static constexpr int kFps1 = 1000;
91 static constexpr int kFps10 = kFps1 / 10; 125 static constexpr int kFps10 = kFps1 / 10;
92 static constexpr int kFps20 = kFps1 / 20; 126 static constexpr int kFps20 = kFps1 / 20;
93 127
94 TestFrameBuffer2() 128 TestFrameBuffer2()
95 : clock_(0), 129 : clock_(0),
96 timing_(&clock_), 130 timing_(&clock_),
97 jitter_estimator_(&clock_), 131 jitter_estimator_(&clock_),
98 buffer_(&clock_, &jitter_estimator_, &timing_), 132 buffer_(&clock_, &jitter_estimator_, &timing_, &stats_callback_),
99 rand_(0x34678213), 133 rand_(0x34678213),
100 tear_down_(false), 134 tear_down_(false),
101 extract_thread_(&ExtractLoop, this, "Extract Thread"), 135 extract_thread_(&ExtractLoop, this, "Extract Thread"),
102 trigger_extract_event_(false, false), 136 trigger_extract_event_(false, false),
103 crit_acquired_event_(false, false) {} 137 crit_acquired_event_(false, false) {}
104 138
105 void SetUp() override { extract_thread_.Start(); } 139 void SetUp() override { extract_thread_.Start(); }
106 140
107 void TearDown() override { 141 void TearDown() override {
108 tear_down_ = true; 142 tear_down_ = true;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 217 }
184 218
185 uint32_t Rand() { return rand_.Rand<uint32_t>(); } 219 uint32_t Rand() { return rand_.Rand<uint32_t>(); }
186 220
187 SimulatedClock clock_; 221 SimulatedClock clock_;
188 VCMTimingFake timing_; 222 VCMTimingFake timing_;
189 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_; 223 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_;
190 FrameBuffer buffer_; 224 FrameBuffer buffer_;
191 std::vector<std::unique_ptr<FrameObject>> frames_; 225 std::vector<std::unique_ptr<FrameObject>> frames_;
192 Random rand_; 226 Random rand_;
227 ::testing::NiceMock<VCMReceiveStatisticsCallbackMock> stats_callback_;
193 228
194 int64_t max_wait_time_; 229 int64_t max_wait_time_;
195 bool tear_down_; 230 bool tear_down_;
196 rtc::PlatformThread extract_thread_; 231 rtc::PlatformThread extract_thread_;
197 rtc::Event trigger_extract_event_; 232 rtc::Event trigger_extract_event_;
198 rtc::Event crit_acquired_event_; 233 rtc::Event crit_acquired_event_;
199 rtc::CriticalSection crit_; 234 rtc::CriticalSection crit_;
200 }; 235 };
201 236
202 // Following tests are timing dependent. Either the timeouts have to 237 // Following tests are timing dependent. Either the timeouts have to
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 CheckFrame(0, pid, 0); 464 CheckFrame(0, pid, 0);
430 465
431 // Jump back in pid but increase ts. 466 // Jump back in pid but increase ts.
432 EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false)); 467 EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false));
433 ExtractFrame(); 468 ExtractFrame();
434 ExtractFrame(); 469 ExtractFrame();
435 CheckFrame(1, pid - 1, 0); 470 CheckFrame(1, pid - 1, 0);
436 CheckNoFrame(2); 471 CheckNoFrame(2);
437 } 472 }
438 473
474 TEST_F(TestFrameBuffer2, StatsCallback) {
475 uint16_t pid = Rand();
476 uint32_t ts = Rand();
477 const int kFrameSize = 5000;
478
479 EXPECT_CALL(stats_callback_, OnCompleteFrame(true, kFrameSize));
480 EXPECT_CALL(stats_callback_,
481 OnFrameBufferTimingsUpdated(_, _, _, _, _, _, _));
482
483 {
484 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
485 frame->SetSize(kFrameSize);
486 frame->picture_id = pid;
487 frame->spatial_layer = 0;
488 frame->timestamp = ts;
489 frame->num_references = 0;
490 frame->inter_layer_predicted = false;
491
492 EXPECT_EQ(buffer_.InsertFrame(std::move(frame)), pid);
493 }
494
495 ExtractFrame();
496 CheckFrame(0, pid, 0);
497 }
498
439 } // namespace video_coding 499 } // namespace video_coding
440 } // namespace webrtc 500 } // 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