OLD | NEW |
---|---|
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 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 122 |
123 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake()); | 123 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake()); |
124 frame->picture_id = picture_id; | 124 frame->picture_id = picture_id; |
125 frame->spatial_layer = spatial_layer; | 125 frame->spatial_layer = spatial_layer; |
126 frame->timestamp = ts_ms * 90; | 126 frame->timestamp = ts_ms * 90; |
127 frame->num_references = references.size(); | 127 frame->num_references = references.size(); |
128 frame->inter_layer_predicted = inter_layer_predicted; | 128 frame->inter_layer_predicted = inter_layer_predicted; |
129 for (size_t r = 0; r < references.size(); ++r) | 129 for (size_t r = 0; r < references.size(); ++r) |
130 frame->references[r] = references[r]; | 130 frame->references[r] = references[r]; |
131 | 131 |
132 buffer_.InsertFrame(std::move(frame)); | 132 last_continuous_frames_.push_back(buffer_.InsertFrame(std::move(frame))); |
133 } | 133 } |
134 | 134 |
135 void ExtractFrame(int64_t max_wait_time = 0) { | 135 void ExtractFrame(int64_t max_wait_time = 0) { |
136 crit_.Enter(); | 136 crit_.Enter(); |
137 if (max_wait_time == 0) { | 137 if (max_wait_time == 0) { |
138 std::unique_ptr<FrameObject> frame; | 138 std::unique_ptr<FrameObject> frame; |
139 FrameBuffer::ReturnReason res = buffer_.NextFrame(0, &frame); | 139 FrameBuffer::ReturnReason res = buffer_.NextFrame(0, &frame); |
140 if (res != FrameBuffer::ReturnReason::kStopped) | 140 if (res != FrameBuffer::ReturnReason::kStopped) |
141 frames_.emplace_back(std::move(frame)); | 141 frames_.emplace_back(std::move(frame)); |
142 crit_.Leave(); | 142 crit_.Leave(); |
143 } else { | 143 } else { |
144 max_wait_time_ = max_wait_time; | 144 max_wait_time_ = max_wait_time; |
145 trigger_extract_event_.Set(); | 145 trigger_extract_event_.Set(); |
146 crit_.Leave(); | 146 crit_.Leave(); |
147 // Make sure |crit_| is aquired by |extract_thread_| before returning. | 147 // Make sure |crit_| is aquired by |extract_thread_| before returning. |
148 crit_acquired_event_.Wait(rtc::Event::kForever); | 148 crit_acquired_event_.Wait(rtc::Event::kForever); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 void CheckFrame(size_t index, int picture_id, int spatial_layer) { | 152 void CheckFrame(size_t index, int picture_id, int spatial_layer) { |
153 rtc::CritScope lock(&crit_); | 153 rtc::CritScope lock(&crit_); |
154 ASSERT_LT(index, frames_.size()); | 154 ASSERT_LT(index, frames_.size()); |
155 ASSERT_TRUE(frames_[index]); | 155 ASSERT_TRUE(frames_[index]); |
156 ASSERT_EQ(picture_id, frames_[index]->picture_id); | 156 ASSERT_EQ(picture_id, frames_[index]->picture_id); |
157 ASSERT_EQ(spatial_layer, frames_[index]->spatial_layer); | 157 ASSERT_EQ(spatial_layer, frames_[index]->spatial_layer); |
158 } | 158 } |
159 | 159 |
160 void CheckLastContinuousFrame(size_t index, int picture_id) { | |
161 rtc::CritScope lock(&crit_); | |
162 ASSERT_LT(index, last_continuous_frames_.size()); | |
163 ASSERT_EQ(picture_id, last_continuous_frames_[index]); | |
164 } | |
165 | |
160 void CheckNoFrame(size_t index) { | 166 void CheckNoFrame(size_t index) { |
161 rtc::CritScope lock(&crit_); | 167 rtc::CritScope lock(&crit_); |
162 ASSERT_LT(index, frames_.size()); | 168 ASSERT_LT(index, frames_.size()); |
163 ASSERT_FALSE(frames_[index]); | 169 ASSERT_FALSE(frames_[index]); |
164 } | 170 } |
165 | 171 |
166 static bool ExtractLoop(void* obj) { | 172 static bool ExtractLoop(void* obj) { |
167 TestFrameBuffer2* tfb = static_cast<TestFrameBuffer2*>(obj); | 173 TestFrameBuffer2* tfb = static_cast<TestFrameBuffer2*>(obj); |
168 while (true) { | 174 while (true) { |
169 tfb->trigger_extract_event_.Wait(rtc::Event::kForever); | 175 tfb->trigger_extract_event_.Wait(rtc::Event::kForever); |
(...skipping 12 matching lines...) Expand all Loading... | |
182 } | 188 } |
183 } | 189 } |
184 | 190 |
185 uint32_t Rand() { return rand_.Rand<uint32_t>(); } | 191 uint32_t Rand() { return rand_.Rand<uint32_t>(); } |
186 | 192 |
187 SimulatedClock clock_; | 193 SimulatedClock clock_; |
188 VCMTimingFake timing_; | 194 VCMTimingFake timing_; |
189 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_; | 195 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_; |
190 FrameBuffer buffer_; | 196 FrameBuffer buffer_; |
191 std::vector<std::unique_ptr<FrameObject>> frames_; | 197 std::vector<std::unique_ptr<FrameObject>> frames_; |
198 std::vector<int> last_continuous_frames_; | |
192 Random rand_; | 199 Random rand_; |
193 | 200 |
194 int64_t max_wait_time_; | 201 int64_t max_wait_time_; |
195 bool tear_down_; | 202 bool tear_down_; |
196 rtc::PlatformThread extract_thread_; | 203 rtc::PlatformThread extract_thread_; |
197 rtc::Event trigger_extract_event_; | 204 rtc::Event trigger_extract_event_; |
198 rtc::Event crit_acquired_event_; | 205 rtc::Event crit_acquired_event_; |
199 rtc::CriticalSection crit_; | 206 rtc::CriticalSection crit_; |
200 }; | 207 }; |
201 | 208 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(1.0)); | 358 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(1.0)); |
352 InsertFrame(pid, 0, ts, false); | 359 InsertFrame(pid, 0, ts, false); |
353 ExtractFrame(); | 360 ExtractFrame(); |
354 | 361 |
355 buffer_.SetProtectionMode(kProtectionNackFEC); | 362 buffer_.SetProtectionMode(kProtectionNackFEC); |
356 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(0.0)); | 363 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(0.0)); |
357 InsertFrame(pid + 1, 0, ts, false); | 364 InsertFrame(pid + 1, 0, ts, false); |
358 ExtractFrame(); | 365 ExtractFrame(); |
359 } | 366 } |
360 | 367 |
368 TEST_F(TestFrameBuffer2, LastContinuousFrameSingleStream) { | |
danilchap
2016/09/12 12:20:14
It helps when test name describes both scenario an
| |
369 uint16_t pid = Rand(); | |
370 uint32_t ts = Rand(); | |
371 | |
372 InsertFrame(pid, 0, ts, false); | |
373 InsertFrame(pid + 2, 0, ts, false, pid + 1); | |
374 InsertFrame(pid + 1, 0, ts, false, pid); | |
375 InsertFrame(pid + 4, 0, ts, false, pid + 3); | |
376 InsertFrame(pid + 5, 0, ts, false); | |
377 | |
378 CheckLastContinuousFrame(0, pid); | |
danilchap
2016/09/12 12:20:14
May be make InsertFrame return the result of buffe
philipel
2016/09/16 14:01:20
Done.
| |
379 CheckLastContinuousFrame(1, pid); | |
380 CheckLastContinuousFrame(2, pid + 2); | |
381 CheckLastContinuousFrame(3, pid + 2); | |
382 CheckLastContinuousFrame(4, pid + 5); | |
383 } | |
danilchap
2016/09/12 12:20:14
May be add a test case where InsertFrame return -1
philipel
2016/09/16 14:01:20
Done.
| |
384 | |
361 } // namespace video_coding | 385 } // namespace video_coding |
362 } // namespace webrtc | 386 } // namespace webrtc |
OLD | NEW |