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

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

Issue 1847193003: Convert Vp8 Rtp headers to frame references. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback fixes/ Created 4 years, 8 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 <cstring> 11 #include <cstring>
12 #include <limits> 12 #include <limits>
13 13
14 #include "webrtc/modules/video_coding/frame_object.h" 14 #include "webrtc/modules/video_coding/frame_object.h"
15 #include "webrtc/modules/video_coding/packet_buffer.h" 15 #include "webrtc/modules/video_coding/packet_buffer.h"
16 16
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/base/random.h" 18 #include "webrtc/base/random.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 namespace video_coding { 21 namespace video_coding {
22 22
23 class TestPacketBuffer : public ::testing::Test, 23 class TestPacketBuffer : public ::testing::Test,
24 public OnCompleteFrameCallback { 24 public OnCompleteFrameCallback {
25 protected: 25 protected:
26 TestPacketBuffer() 26 TestPacketBuffer()
27 : rand_(0x8739211), packet_buffer_(kStartSize, kMaxSize, this) {} 27 : rand_(0x8739211),
28 packet_buffer_(new PacketBuffer(kStartSize, kMaxSize, this)) {}
28 29
29 uint16_t Rand() { return rand_.Rand(std::numeric_limits<uint16_t>::max()); } 30 uint16_t Rand() { return rand_.Rand(std::numeric_limits<uint16_t>::max()); }
30 31
31 void OnCompleteFrame(std::unique_ptr<FrameObject> frame) override { 32 void OnCompleteFrame(std::unique_ptr<FrameObject> frame) override {
32 frames_from_callback_.emplace_back(std::move(frame)); 33 uint16_t pid = frame->picture_id;
34 auto frame_it = frames_from_callback_.find(pid);
35 if (frame_it != frames_from_callback_.end()) {
36 ADD_FAILURE() << "Already received frame with picture id: " << pid;
37 return;
38 }
39
40 frames_from_callback_.insert(
41 make_pair(frame->picture_id, std::move(frame)));
33 } 42 }
34 43
35 void TearDown() override { 44 void TearDown() override {
36 // All FrameObjects must be destroyed before the PacketBuffer since 45 // All frame objects must be destroyed before the packet buffer since
37 // a FrameObject will try to remove itself from the packet buffer 46 // a frame object will try to remove itself from the packet buffer
38 // upon destruction. 47 // upon destruction.
39 frames_from_callback_.clear(); 48 frames_from_callback_.clear();
40 } 49 }
41 50
51 // Insert a generic packet into the packet buffer.
52 void InsertGeneric(uint16_t seq_num, // packet sequence number
53 bool keyframe, // is keyframe
54 bool first, // is first packet of frame
55 bool last, // is last packet of frame
56 size_t data_size = 0, // size of data
57 uint8_t* data = nullptr) { // data pointer
58 VCMPacket packet;
59 packet.codec = kVideoCodecGeneric;
60 packet.seqNum = seq_num;
61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
62 packet.isFirstPacket = first;
63 packet.markerBit = last;
64 packet.sizeBytes = data_size;
65 packet.dataPtr = data;
66
67 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
68 }
69
70 // Insert a Vp8 packet into the packet buffer.
71 void InsertVp8(uint16_t seq_num, // packet sequence number
72 bool keyframe, // is keyframe
73 bool first, // is first packet of frame
74 bool last, // is last packet of frame
75 bool sync = false, // is sync frame
76 int32_t pid = kNoPictureId, // picture id
77 uint8_t tid = kNoTemporalIdx, // temporal id
78 int32_t tl0 = kNoTl0PicIdx, // tl0 pic index
79 size_t data_size = 0, // size of data
80 uint8_t* data = nullptr) { // data pointer
81 VCMPacket packet;
82 packet.codec = kVideoCodecVP8;
83 packet.seqNum = seq_num;
84 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
85 packet.isFirstPacket = first;
86 packet.markerBit = last;
87 packet.sizeBytes = data_size;
88 packet.dataPtr = data;
89 packet.codecSpecificHeader.codecHeader.VP8.pictureId = pid % (1 << 15);
90 packet.codecSpecificHeader.codecHeader.VP8.temporalIdx = tid;
91 packet.codecSpecificHeader.codecHeader.VP8.tl0PicIdx = tl0;
92 packet.codecSpecificHeader.codecHeader.VP8.layerSync = sync;
93
94 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
95 }
96
97 // Check if a frame with picture id |pid| has been delivered from the packet
98 // buffer, and if so, if it has the references specified by |refs|.
99 template <typename... T>
100 void CheckReferences(uint16_t pid, T... refs) const {
101 auto frame_it = frames_from_callback_.find(pid);
102 if (frame_it == frames_from_callback_.end()) {
103 ADD_FAILURE() << "Could not find frame with picture id " << pid;
104 return;
105 }
106
107 std::set<uint16_t> actual_refs;
108 for (uint8_t r = 0; r < frame_it->second->num_references; ++r) {
109 actual_refs.insert(frame_it->second->references[r]);
110 }
111
112 std::set<uint16_t> expected_refs;
113 RefsToSet(&expected_refs, refs...);
114
115 ASSERT_EQ(expected_refs, actual_refs);
116 }
117
118 template <typename... T>
119 void RefsToSet(std::set<uint16_t>* m, uint16_t ref, T... refs) const {
120 m->insert(ref);
121 RefsToSet(m, refs...);
122 }
123
124 void RefsToSet(std::set<uint16_t>* m) const {}
125
42 const int kStartSize = 16; 126 const int kStartSize = 16;
43 const int kMaxSize = 64; 127 const int kMaxSize = 64;
44 128
45 Random rand_; 129 Random rand_;
46 PacketBuffer packet_buffer_; 130 std::unique_ptr<PacketBuffer> packet_buffer_;
47 std::vector<std::unique_ptr<FrameObject>> frames_from_callback_; 131 std::map<uint16_t, std::unique_ptr<FrameObject>> frames_from_callback_;
48 }; 132 };
49 133
50 TEST_F(TestPacketBuffer, InsertOnePacket) { 134 TEST_F(TestPacketBuffer, InsertOnePacket) {
51 VCMPacket packet; 135 VCMPacket packet;
52 packet.seqNum = Rand(); 136 packet.seqNum = Rand();
53 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 137 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
54 } 138 }
55 139
56 TEST_F(TestPacketBuffer, InsertMultiplePackets) { 140 TEST_F(TestPacketBuffer, InsertMultiplePackets) {
57 VCMPacket packet; 141 VCMPacket packet;
58 packet.seqNum = Rand(); 142 packet.seqNum = Rand();
59 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 143 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
60 ++packet.seqNum; 144 ++packet.seqNum;
61 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 145 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
62 ++packet.seqNum; 146 ++packet.seqNum;
63 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 147 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
64 } 148 }
65 149
66 TEST_F(TestPacketBuffer, InsertDuplicatePacket) { 150 TEST_F(TestPacketBuffer, InsertDuplicatePacket) {
67 VCMPacket packet; 151 VCMPacket packet;
68 packet.seqNum = Rand(); 152 packet.seqNum = Rand();
69 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 153 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
70 ++packet.seqNum; 154 ++packet.seqNum;
71 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 155 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
72 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 156 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
73 ++packet.seqNum;
74 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
75 } 157 }
76 158
77 TEST_F(TestPacketBuffer, ExpandBuffer) { 159 TEST_F(TestPacketBuffer, ExpandBuffer) {
78 VCMPacket packet; 160 uint16_t seq_num = Rand();
79 packet.seqNum = Rand();
80 161
81 for (int i = 0; i < kStartSize + 1; ++i) { 162 for (int i = 0; i < kStartSize + 1; ++i) {
82 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 163 // seq_num , keyframe, first, last
83 ++packet.seqNum; 164 InsertGeneric(seq_num + i, true , true , true);
84 } 165 }
85 } 166 }
86 167
87 TEST_F(TestPacketBuffer, ExpandBufferOverflow) { 168 TEST_F(TestPacketBuffer, ExpandBufferOverflow) {
88 VCMPacket packet; 169 uint16_t seq_num = Rand();
89 packet.seqNum = Rand();
90 170
91 for (int i = 0; i < kMaxSize; ++i) { 171 for (int i = 0; i < kMaxSize; ++i) {
92 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 172 // seq_num , keyframe, first, last
93 ++packet.seqNum; 173 InsertGeneric(seq_num + i, true , true , true);
94 } 174 }
95 175
96 EXPECT_FALSE(packet_buffer_.InsertPacket(packet)); 176 VCMPacket packet;
177 packet.seqNum = seq_num + kMaxSize + 1;
178 packet.sizeBytes = 1;
179 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
97 } 180 }
98 181
99 TEST_F(TestPacketBuffer, OnePacketOneFrame) { 182 TEST_F(TestPacketBuffer, GenericOnePacketOneFrame) {
100 VCMPacket packet; 183 // seq_num, keyframe, first, last
101 packet.isFirstPacket = true; 184 InsertGeneric(Rand() , true , true , true);
102 packet.markerBit = true; 185 ASSERT_EQ(1UL, frames_from_callback_.size());
103 packet.seqNum = Rand(); 186 }
104 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 187
188 TEST_F(TestPacketBuffer, GenericTwoPacketsTwoFrames) {
189 uint16_t seq_num = Rand();
190
191 // seq_num , keyframe, first, last
192 InsertGeneric(seq_num , true , true , true);
193 InsertGeneric(seq_num + 1, true , true , true);
194
195 EXPECT_EQ(2UL, frames_from_callback_.size());
196 }
197
198 TEST_F(TestPacketBuffer, GenericTwoPacketsOneFrames) {
199 uint16_t seq_num = Rand();
200
201 // seq_num , keyframe, first, last
202 InsertGeneric(seq_num , true , true , false);
203 InsertGeneric(seq_num + 1, true , false, true);
204
105 EXPECT_EQ(1UL, frames_from_callback_.size()); 205 EXPECT_EQ(1UL, frames_from_callback_.size());
106 } 206 }
107 207
108 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) { 208 TEST_F(TestPacketBuffer, GenericThreePacketReorderingOneFrame) {
109 VCMPacket packet; 209 uint16_t seq_num = Rand();
110 packet.isFirstPacket = true;
111 packet.markerBit = true;
112 packet.seqNum = Rand();
113 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
114 ++packet.seqNum;
115 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
116 EXPECT_EQ(2UL, frames_from_callback_.size());
117 }
118 210
119 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) { 211 // seq_num , keyframe, first, last
120 VCMPacket packet; 212 InsertGeneric(seq_num , true , true , false);
121 packet.isFirstPacket = true; 213 InsertGeneric(seq_num + 2, true , false, true);
122 packet.seqNum = Rand(); 214 InsertGeneric(seq_num + 1, true , false, false);
123 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 215
124 packet.markerBit = true;
125 ++packet.seqNum;
126 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
127 EXPECT_EQ(1UL, frames_from_callback_.size()); 216 EXPECT_EQ(1UL, frames_from_callback_.size());
128 } 217 }
129 218
130 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) {
131 VCMPacket packet;
132 packet.isFirstPacket = true;
133 packet.seqNum = Rand();
134 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
135 EXPECT_EQ(0UL, frames_from_callback_.size());
136 packet.isFirstPacket = false;
137 packet.markerBit = true;
138 packet.seqNum += 2;
139 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
140 EXPECT_EQ(0UL, frames_from_callback_.size());
141 packet.markerBit = false;
142 packet.seqNum -= 1;
143 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
144 EXPECT_EQ(1UL, frames_from_callback_.size());
145 }
146
147 TEST_F(TestPacketBuffer, IndexWrapOneFrame) {
148 VCMPacket packet;
149 packet.isFirstPacket = true;
150 packet.seqNum = kStartSize - 1;
151 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
152 EXPECT_EQ(0UL, frames_from_callback_.size());
153 packet.isFirstPacket = false;
154 ++packet.seqNum;
155 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
156 EXPECT_EQ(0UL, frames_from_callback_.size());
157 ++packet.seqNum;
158 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
159 EXPECT_EQ(0UL, frames_from_callback_.size());
160 packet.markerBit = true;
161 ++packet.seqNum;
162 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
163 EXPECT_EQ(1UL, frames_from_callback_.size());
164 }
165
166 TEST_F(TestPacketBuffer, DiscardOldPacket) { 219 TEST_F(TestPacketBuffer, DiscardOldPacket) {
167 uint16_t seq_num = Rand(); 220 uint16_t seq_num = Rand();
168 VCMPacket packet; 221 VCMPacket packet;
169 packet.seqNum = Rand(); 222 packet.seqNum = Rand();
170 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 223 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
171 packet.seqNum += 2; 224 packet.seqNum += 2;
172 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 225 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
173 226
174 for (int i = 3; i < kMaxSize; ++i) { 227 for (int i = 3; i < kMaxSize; ++i) {
175 ++packet.seqNum; 228 ++packet.seqNum;
176 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 229 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
177 } 230 }
178 231
179 ++packet.seqNum; 232 ++packet.seqNum;
180 EXPECT_FALSE(packet_buffer_.InsertPacket(packet)); 233 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
181 packet_buffer_.ClearTo(seq_num + 1); 234 packet_buffer_->ClearTo(seq_num + 1);
182 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 235 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
183 } 236 }
184 237
185 TEST_F(TestPacketBuffer, DiscardMultipleOldPackets) { 238 TEST_F(TestPacketBuffer, DiscardMultipleOldPackets) {
186 uint16_t seq_num = Rand(); 239 uint16_t seq_num = Rand();
187 VCMPacket packet; 240 VCMPacket packet;
188 packet.seqNum = seq_num; 241 packet.seqNum = seq_num;
189 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 242 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
190 packet.seqNum += 2; 243 packet.seqNum += 2;
191 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 244 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
192 245
193 for (int i = 3; i < kMaxSize; ++i) { 246 for (int i = 3; i < kMaxSize; ++i) {
194 ++packet.seqNum; 247 ++packet.seqNum;
195 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 248 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
196 } 249 }
197 250
198 packet_buffer_.ClearTo(seq_num + 15); 251 packet_buffer_->ClearTo(seq_num + 15);
199 for (int i = 0; i < 15; ++i) { 252 for (int i = 0; i < 15; ++i) {
200 ++packet.seqNum; 253 ++packet.seqNum;
201 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 254 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
202 } 255 }
203 for (int i = 15; i < kMaxSize; ++i) { 256 for (int i = 15; i < kMaxSize; ++i) {
204 ++packet.seqNum; 257 ++packet.seqNum;
205 EXPECT_FALSE(packet_buffer_.InsertPacket(packet)); 258 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
206 } 259 }
207 } 260 }
208 261
209 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { 262 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) {
stefan-webrtc 2016/04/19 12:24:29 Can we have a test with at least 3 generic frames
philipel 2016/04/19 13:12:01 Done.
210 // "many bitstream, such data" with null termination. 263 // "many bitstream, such data" with null termination.
211 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; 264 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20};
212 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, 265 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72,
213 0x65, 0x61, 0x6d, 0x2c, 0x20}; 266 0x65, 0x61, 0x6d, 0x2c, 0x20};
214 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; 267 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20};
215 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; 268 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0};
216 uint8_t 269 uint8_t
217 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; 270 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)];
218 271
272 uint16_t seq_num = Rand();
273
274 // seq_num , keyf , first, last , data_size , data
275 InsertGeneric(seq_num , true , true , false, sizeof(many) , many);
276 InsertGeneric(seq_num + 1, false, false, false, sizeof(bitstream), bitstream);
277 InsertGeneric(seq_num + 2, false, false, false, sizeof(such) , such);
278 InsertGeneric(seq_num + 3, false, false, true , sizeof(data) , data);
279
280 ASSERT_EQ(1UL, frames_from_callback_.size());
281 CheckReferences(seq_num + 3);
282 EXPECT_TRUE(frames_from_callback_[seq_num + 3]->GetBitstream(result));
283 EXPECT_EQ(std::strcmp("many bitstream, such data",
284 reinterpret_cast<char*>(result)),
285 0);
286 }
287
288 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
289 uint16_t seq_num = Rand();
290
291 // seq_num , keyf , first, last
292 InsertGeneric(seq_num , true , true , false);
293 InsertGeneric(seq_num + 1, false, false, false);
294 InsertGeneric(seq_num + 2, false, false, true);
295 EXPECT_EQ(1UL, frames_from_callback_.size());
296
297 frames_from_callback_.clear();
298
299 // seq_num , keyf , first, last
300 InsertGeneric(seq_num , true , true , false);
301 InsertGeneric(seq_num + 1, false, false, false);
302 InsertGeneric(seq_num + 2, false, false, true);
303 EXPECT_EQ(1UL, frames_from_callback_.size());
304 }
305
306 TEST_F(TestPacketBuffer, Flush) {
307 uint16_t seq_num = Rand();
308
309 // seq_num , keyf , first, last
310 InsertGeneric(seq_num , true , true , false);
311 InsertGeneric(seq_num + 1, false, false, false);
312 InsertGeneric(seq_num + 2, false, false, true);
313 EXPECT_EQ(1UL, frames_from_callback_.size());
314
315 packet_buffer_->Flush();
316
317 // seq_num , keyf , first, last
318 InsertGeneric(seq_num + kStartSize , true , true , false);
319 InsertGeneric(seq_num + kStartSize + 1, false, false, false);
320 InsertGeneric(seq_num + kStartSize + 2, false, false, true);
321 EXPECT_EQ(2UL, frames_from_callback_.size());
322 }
323
324 TEST_F(TestPacketBuffer, InvalidateFrameByFlushing) {
219 VCMPacket packet; 325 VCMPacket packet;
220 packet.isFirstPacket = true; 326 packet.frameType = kVideoFrameKey;
221 packet.seqNum = 0xfffe;
222 packet.dataPtr = many;
223 packet.sizeBytes = sizeof(many);
224 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
225 packet.isFirstPacket = false;
226 ++packet.seqNum;
227 packet.dataPtr = bitstream;
228 packet.sizeBytes = sizeof(bitstream);
229 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
230 ++packet.seqNum;
231 packet.dataPtr = such;
232 packet.sizeBytes = sizeof(such);
233 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
234 packet.markerBit = true;
235 ++packet.seqNum;
236 packet.dataPtr = data;
237 packet.sizeBytes = sizeof(data);
238 EXPECT_EQ(0UL, frames_from_callback_.size());
239 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
240 ASSERT_EQ(1UL, frames_from_callback_.size());
241
242 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result));
243 EXPECT_EQ(
244 std::strcmp("many bitstream, such data", reinterpret_cast<char*>(result)),
245 0);
246 }
247
248 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
249 VCMPacket packet;
250 packet.isFirstPacket = true;
251 packet.seqNum = Rand();
252 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
253 EXPECT_EQ(0UL, frames_from_callback_.size());
254 packet.isFirstPacket = false;
255 ++packet.seqNum;
256 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
257 EXPECT_EQ(0UL, frames_from_callback_.size());
258 ++packet.seqNum;
259 packet.markerBit = true;
260 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
261 EXPECT_EQ(1UL, frames_from_callback_.size());
262
263 frames_from_callback_.clear();
264
265 packet.isFirstPacket = true;
266 packet.markerBit = false;
267 packet.seqNum = Rand();
268 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
269 EXPECT_EQ(0UL, frames_from_callback_.size());
270 packet.isFirstPacket = false;
271 ++packet.seqNum;
272 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
273 EXPECT_EQ(0UL, frames_from_callback_.size());
274 ++packet.seqNum;
275 packet.markerBit = true;
276 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
277 EXPECT_EQ(1UL, frames_from_callback_.size());
278 }
279
280 TEST_F(TestPacketBuffer, Flush) {
281 VCMPacket packet;
282 packet.isFirstPacket = true; 327 packet.isFirstPacket = true;
283 packet.markerBit = true; 328 packet.markerBit = true;
284 packet.seqNum = Rand(); 329 packet.seqNum = Rand();
285 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 330 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
286 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
287 packet_buffer_.Flush();
288 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
289 EXPECT_EQ(2UL, frames_from_callback_.size());
290 }
291
292 TEST_F(TestPacketBuffer, InvalidateFrameByFlushing) {
293 VCMPacket packet;
294 packet.isFirstPacket = true;
295 packet.markerBit = true;
296 packet.seqNum = Rand();
297 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
298 ASSERT_EQ(1UL, frames_from_callback_.size()); 331 ASSERT_EQ(1UL, frames_from_callback_.size());
299 332
300 packet_buffer_.Flush(); 333 packet_buffer_->Flush();
301 EXPECT_FALSE(frames_from_callback_[0]->GetBitstream(nullptr)); 334 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr));
335 }
336
337 TEST_F(TestPacketBuffer, Vp8NoPictureId) {
338 uint16_t seq_num = Rand();
339
340 // seq_num , keyf , first, last
341 InsertVp8(seq_num , true , true , false);
342 InsertVp8(seq_num + 1 , false, false, false);
343 InsertVp8(seq_num + 2 , false, false, true);
344 ASSERT_EQ(1UL, frames_from_callback_.size());
345
346 InsertVp8(seq_num + 3 , false, true , false);
347 InsertVp8(seq_num + 4 , false, false, true);
348 ASSERT_EQ(2UL, frames_from_callback_.size());
349
350 InsertVp8(seq_num + 5 , false, true , false);
351 InsertVp8(seq_num + 6 , false, false, false);
352 InsertVp8(seq_num + 7 , false, false, false);
353 InsertVp8(seq_num + 8 , false, false, true);
354 ASSERT_EQ(3UL, frames_from_callback_.size());
355
356 InsertVp8(seq_num + 9 , false, true , true);
357 ASSERT_EQ(4UL, frames_from_callback_.size());
358
359 InsertVp8(seq_num + 10, false, true , false);
360 InsertVp8(seq_num + 11, false, false, true);
361 ASSERT_EQ(5UL, frames_from_callback_.size());
362
363 InsertVp8(seq_num + 12, true , true , true);
364 ASSERT_EQ(6UL, frames_from_callback_.size());
365
366 InsertVp8(seq_num + 13, false, true , false);
367 InsertVp8(seq_num + 14, false, false, false);
368 InsertVp8(seq_num + 15, false, false, false);
369 InsertVp8(seq_num + 16, false, false, false);
370 InsertVp8(seq_num + 17, false, false, true);
371 ASSERT_EQ(7UL, frames_from_callback_.size());
372
373 InsertVp8(seq_num + 18, false, true , true);
374 ASSERT_EQ(8UL, frames_from_callback_.size());
375
376 InsertVp8(seq_num + 19, false, true , false);
377 InsertVp8(seq_num + 20, false, false, true);
378 ASSERT_EQ(9UL, frames_from_callback_.size());
379
380 InsertVp8(seq_num + 21, false, true , true);
381
382 ASSERT_EQ(10UL, frames_from_callback_.size());
383 CheckReferences(seq_num + 2);
384 CheckReferences(seq_num + 4, seq_num + 2);
385 CheckReferences(seq_num + 8, seq_num + 4);
386 CheckReferences(seq_num + 9, seq_num + 8);
387 CheckReferences(seq_num + 11, seq_num + 9);
388 CheckReferences(seq_num + 12);
389 CheckReferences(seq_num + 17, seq_num + 12);
390 CheckReferences(seq_num + 18, seq_num + 17);
391 CheckReferences(seq_num + 20, seq_num + 18);
392 CheckReferences(seq_num + 21, seq_num + 20);
393 }
394
395 TEST_F(TestPacketBuffer, Vp8NoPictureIdReordered) {
396 uint16_t seq_num = 0xfffa;
397
398 // seq_num , keyf , first, last
399 InsertVp8(seq_num + 1 , false, false, false);
400 InsertVp8(seq_num , true , true , false);
401 InsertVp8(seq_num + 2 , false, false, true);
402 InsertVp8(seq_num + 4 , false, false, true);
403 InsertVp8(seq_num + 6 , false, false, false);
404 InsertVp8(seq_num + 3 , false, true , false);
405 InsertVp8(seq_num + 7 , false, false, false);
406 InsertVp8(seq_num + 5 , false, true , false);
407 InsertVp8(seq_num + 9 , false, true , true);
408 InsertVp8(seq_num + 10, false, true , false);
409 InsertVp8(seq_num + 8 , false, false, true);
410 InsertVp8(seq_num + 13, false, true , false);
411 InsertVp8(seq_num + 14, false, false, false);
412 InsertVp8(seq_num + 12, true , true , true);
413 InsertVp8(seq_num + 11, false, false, true);
414 InsertVp8(seq_num + 16, false, false, false);
415 InsertVp8(seq_num + 19, false, true , false);
416 InsertVp8(seq_num + 15, false, false, false);
417 InsertVp8(seq_num + 17, false, false, true);
418 InsertVp8(seq_num + 20, false, false, true);
419 InsertVp8(seq_num + 21, false, true , true);
420 InsertVp8(seq_num + 18, false, true , true);
421
422 ASSERT_EQ(10UL, frames_from_callback_.size());
423 CheckReferences(seq_num + 2);
424 CheckReferences(seq_num + 4, seq_num + 2);
425 CheckReferences(seq_num + 8, seq_num + 4);
426 CheckReferences(seq_num + 9, seq_num + 8);
427 CheckReferences(seq_num + 11, seq_num + 9);
428 CheckReferences(seq_num + 12);
429 CheckReferences(seq_num + 17, seq_num + 12);
430 CheckReferences(seq_num + 18, seq_num + 17);
431 CheckReferences(seq_num + 20, seq_num + 18);
432 CheckReferences(seq_num + 21, seq_num + 20);
433 }
434
435
436 TEST_F(TestPacketBuffer, Vp8KeyFrameReferences) {
437 uint16_t pid = Rand();
438 // seq_num, keyf, first, last, sync , pid, tid, tl0
439 InsertVp8(Rand() , true, true , true, false, pid, 0 , 0);
440
441 ASSERT_EQ(1UL, frames_from_callback_.size());
442 CheckReferences(pid);
443 }
444
445 // Test with 1 temporal layer.
446 TEST_F(TestPacketBuffer, Vp8TemporalLayers_0) {
447 uint16_t pid = Rand();
448 uint16_t seq_num = Rand();
449
450 // seq_num , keyf , first, last, sync , pid , tid, tl0
451 InsertVp8(seq_num , true , true , true, false, pid , 0 , 1);
452 InsertVp8(seq_num + 1, false, true , true, false, pid + 1, 0 , 2);
453 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 3);
454 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 0 , 4);
455
456 ASSERT_EQ(4UL, frames_from_callback_.size());
457 CheckReferences(pid);
458 CheckReferences(pid + 1, pid);
459 CheckReferences(pid + 2, pid + 1);
460 CheckReferences(pid + 3, pid + 2);
461 }
462
463 // Test with 1 temporal layer.
464 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0) {
465 uint16_t pid = Rand();
466 uint16_t seq_num = Rand();
467
468 // seq_num , keyf , first, last, sync , pid , tid, tl0
469 InsertVp8(seq_num , true , true , true, false, pid , 0 , 1);
470 InsertVp8(seq_num + 1, false, true , true, false, pid + 1, 0 , 2);
471 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 0 , 4);
472 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 3);
473 InsertVp8(seq_num + 5, false, true , true, false, pid + 5, 0 , 6);
474 InsertVp8(seq_num + 6, false, true , true, false, pid + 6, 0 , 7);
475 InsertVp8(seq_num + 4, false, true , true, false, pid + 4, 0 , 5);
476
477 ASSERT_EQ(7UL, frames_from_callback_.size());
478 CheckReferences(pid);
479 CheckReferences(pid + 1, pid);
480 CheckReferences(pid + 2, pid + 1);
481 CheckReferences(pid + 3, pid + 2);
482 CheckReferences(pid + 4, pid + 3);
483 CheckReferences(pid + 5, pid + 4);
484 CheckReferences(pid + 6, pid + 5);
485 }
486
487 // Test with 2 temporal layers in a 01 pattern.
488 TEST_F(TestPacketBuffer, Vp8TemporalLayers_01) {
489 uint16_t pid = Rand();
490 uint16_t seq_num = Rand();
491
492 // seq_num , keyf , first, last, sync , pid , tid, tl0
493 InsertVp8(seq_num , true , true , true, false, pid , 0, 255);
494 InsertVp8(seq_num + 1, false, true , true, true , pid + 1, 1, 255);
495 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0, 0);
496 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 1, 0);
497
498 ASSERT_EQ(4UL, frames_from_callback_.size());
499 CheckReferences(pid);
500 CheckReferences(pid + 1, pid);
501 CheckReferences(pid + 2, pid);
502 CheckReferences(pid + 3, pid + 1, pid + 2);
503 }
504
505 // Test with 2 temporal layers in a 01 pattern.
506 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_01) {
507 uint16_t pid = Rand();
508 uint16_t seq_num = Rand();
509
510 // seq_num , keyf , first, last, sync , pid , tid, tl0
511 InsertVp8(seq_num + 1, false, true , true, true , pid + 1, 1 , 255);
512 InsertVp8(seq_num , true , true , true, false, pid , 0 , 255);
513 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 1 , 0);
514 InsertVp8(seq_num + 5, false, true , true, false, pid + 5, 1 , 1);
515 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 0);
516 InsertVp8(seq_num + 4, false, true , true, false, pid + 4, 0 , 1);
517 InsertVp8(seq_num + 6, false, true , true, false, pid + 6, 0 , 2);
518 InsertVp8(seq_num + 7, false, true , true, false, pid + 7, 1 , 2);
519
520 ASSERT_EQ(8UL, frames_from_callback_.size());
521 CheckReferences(pid);
522 CheckReferences(pid + 1, pid);
523 CheckReferences(pid + 2, pid);
524 CheckReferences(pid + 3, pid + 1, pid + 2);
525 CheckReferences(pid + 4, pid + 2);
526 CheckReferences(pid + 5, pid + 3, pid + 4);
527 CheckReferences(pid + 6, pid + 4);
528 CheckReferences(pid + 7, pid + 5, pid + 6);
529 }
530
531 // Test with 3 temporal layers in a 0212 pattern.
532 TEST_F(TestPacketBuffer, Vp8TemporalLayers_0212) {
533 uint16_t pid = Rand();
534 uint16_t seq_num = Rand();
535
536 // seq_num , keyf , first, last, sync , pid , tid, tl0
537 InsertVp8(seq_num , true , true , true , false, pid , 0 , 55);
538 InsertVp8(seq_num + 1 , false, true , true , true , pid + 1 , 2 , 55);
539 InsertVp8(seq_num + 2 , false, true , true , true , pid + 2 , 1 , 55);
540 InsertVp8(seq_num + 3 , false, true , true , false, pid + 3 , 2 , 55);
541 InsertVp8(seq_num + 4 , false, true , true , false, pid + 4 , 0 , 56);
542 InsertVp8(seq_num + 5 , false, true , true , false, pid + 5 , 2 , 56);
543 InsertVp8(seq_num + 6 , false, true , true , false, pid + 6 , 1 , 56);
544 InsertVp8(seq_num + 7 , false, true , true , false, pid + 7 , 2 , 56);
545 InsertVp8(seq_num + 8 , false, true , true , false, pid + 8 , 0 , 57);
546 InsertVp8(seq_num + 9 , false, true , true , true , pid + 9 , 2 , 57);
547 InsertVp8(seq_num + 10, false, true , true , true , pid + 10, 1 , 57);
548 InsertVp8(seq_num + 11, false, true , true , false, pid + 11, 2 , 57);
549
550 ASSERT_EQ(12UL, frames_from_callback_.size());
551 CheckReferences(pid);
552 CheckReferences(pid + 1 , pid);
553 CheckReferences(pid + 2 , pid);
554 CheckReferences(pid + 3 , pid, pid + 1, pid + 2);
555 CheckReferences(pid + 4 , pid);
556 CheckReferences(pid + 5 , pid + 2, pid + 3, pid + 4);
557 CheckReferences(pid + 6 , pid + 2, pid + 4);
558 CheckReferences(pid + 7 , pid + 4, pid + 5, pid + 6);
559 CheckReferences(pid + 8 , pid + 4);
560 CheckReferences(pid + 9 , pid + 8);
561 CheckReferences(pid + 10, pid + 8);
562 CheckReferences(pid + 11, pid + 8, pid + 9, pid + 10);
563 }
564
565 // Test with 3 temporal layers in a 0212 pattern.
566 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0212) {
567 uint16_t pid = 126;
568 uint16_t seq_num = Rand();
569
570 // seq_num , keyf , first, last, sync , pid , tid, tl0
571 InsertVp8(seq_num + 1 , false, true , true, true , pid + 1 , 2 , 55);
572 InsertVp8(seq_num , true , true , true, false, pid , 0 , 55);
573 InsertVp8(seq_num + 2 , false, true , true, true , pid + 2 , 1 , 55);
574 InsertVp8(seq_num + 4 , false, true , true, false, pid + 4 , 0 , 56);
575 InsertVp8(seq_num + 5 , false, true , true, false, pid + 5 , 2 , 56);
576 InsertVp8(seq_num + 3 , false, true , true, false, pid + 3 , 2 , 55);
577 InsertVp8(seq_num + 7 , false, true , true, false, pid + 7 , 2 , 56);
578 InsertVp8(seq_num + 9 , false, true , true, true , pid + 9 , 2 , 57);
579 InsertVp8(seq_num + 6 , false, true , true, false, pid + 6 , 1 , 56);
580 InsertVp8(seq_num + 8 , false, true , true, false, pid + 8 , 0 , 57);
581 InsertVp8(seq_num + 11, false, true , true, false, pid + 11, 2 , 57);
582 InsertVp8(seq_num + 10, false, true , true, true , pid + 10, 1 , 57);
583
584 ASSERT_EQ(12UL, frames_from_callback_.size());
585 CheckReferences(pid);
586 CheckReferences(pid + 1 , pid);
587 CheckReferences(pid + 2 , pid);
588 CheckReferences(pid + 3 , pid, pid + 1, pid + 2);
589 CheckReferences(pid + 4 , pid);
590 CheckReferences(pid + 5 , pid + 2, pid + 3, pid + 4);
591 CheckReferences(pid + 6 , pid + 2, pid + 4);
592 CheckReferences(pid + 7 , pid + 4, pid + 5, pid + 6);
593 CheckReferences(pid + 8 , pid + 4);
594 CheckReferences(pid + 9 , pid + 8);
595 CheckReferences(pid + 10, pid + 8);
596 CheckReferences(pid + 11, pid + 8, pid + 9, pid + 10);
597 }
598
599 TEST_F(TestPacketBuffer, Vp8InsertManyFrames_0212) {
600 uint16_t pid = Rand();
601 uint16_t seq_num = Rand();
602
603 const int keyframes_to_insert = 50;
604 const int frames_per_keyframe = 120; // Should be a multiple of 4.
605 uint8_t tl0 = 128;
606
607 for (int k = 0; k < keyframes_to_insert; ++k) {
608 // seq_num , keyf , first, last , sync , pid , tid, tl0
609 InsertVp8(seq_num , true , true , true , false, pid , 0 , tl0);
610 InsertVp8(seq_num + 1, false, true , true , true , pid + 1, 2 , tl0);
611 InsertVp8(seq_num + 2, false, true , true , true , pid + 2, 1 , tl0);
612 InsertVp8(seq_num + 3, false, true , true , false, pid + 3, 2 , tl0);
613 CheckReferences(pid);
614 CheckReferences(pid + 1, pid);
615 CheckReferences(pid + 2, pid);
616 CheckReferences(pid + 3, pid, pid + 1, pid + 2);
617 frames_from_callback_.clear();
618 ++tl0;
619
620 for (int f = 4; f < frames_per_keyframe; f += 4) {
621 uint16_t sf = seq_num + f;
622 uint16_t pidf = pid + f;
623
624 // seq_num, keyf , first, last, sync , pid , tid, tl0
625 InsertVp8(sf , false, true , true, false, pidf , 0 , tl0);
626 InsertVp8(sf + 1 , false, true , true, false, pidf + 1, 2 , tl0);
627 InsertVp8(sf + 2 , false, true , true, false, pidf + 2, 1 , tl0);
628 InsertVp8(sf + 3 , false, true , true, false, pidf + 3, 2 , tl0);
629 CheckReferences(pidf, pidf - 4);
630 CheckReferences(pidf + 1, pidf, pidf - 1, pidf - 2);
631 CheckReferences(pidf + 2, pidf, pidf - 2);
632 CheckReferences(pidf + 3, pidf, pidf + 1, pidf + 2);
633 frames_from_callback_.clear();
634 ++tl0;
635 }
636
637 pid += frames_per_keyframe;
638 seq_num += frames_per_keyframe;
639 }
640 }
641
642 TEST_F(TestPacketBuffer, Vp8LayerSync) {
643 uint16_t pid = Rand();
644 uint16_t seq_num = Rand();
645
646 // seq_num , keyf , first, last, sync , pid , tid, tl0
647 InsertVp8(seq_num , true , true , true, false, pid , 0 , 0);
648 InsertVp8(seq_num + 1 , false, true , true, true , pid + 1 , 1 , 0);
649 InsertVp8(seq_num + 2 , false, true , true, false, pid + 2 , 0 , 1);
650 ASSERT_EQ(3UL, frames_from_callback_.size());
651
652 InsertVp8(seq_num + 4 , false, true , true, false, pid + 4 , 0 , 2);
653 InsertVp8(seq_num + 5 , false, true , true, true , pid + 5 , 1 , 2);
654 InsertVp8(seq_num + 6 , false, true , true, false, pid + 6 , 0 , 3);
655 InsertVp8(seq_num + 7 , false, true , true, false, pid + 7 , 1 , 3);
656
657 ASSERT_EQ(7UL, frames_from_callback_.size());
658 CheckReferences(pid);
659 CheckReferences(pid + 1, pid);
660 CheckReferences(pid + 2, pid);
661 CheckReferences(pid + 4, pid + 2);
662 CheckReferences(pid + 5, pid + 4);
663 CheckReferences(pid + 6, pid + 4);
664 CheckReferences(pid + 7, pid + 6, pid + 5);
665 }
666
667 TEST_F(TestPacketBuffer, Vp8InsertLargeFrames) {
668 packet_buffer_.reset(new PacketBuffer(1 << 3, 1 << 12, this));
669 uint16_t pid = Rand();
670 uint16_t seq_num = Rand();
671
672 const uint16_t packets_per_frame = 1000;
673 uint16_t current = seq_num;
674 uint16_t end = current + packets_per_frame;
675
676 // seq_num , keyf , first, last , sync , pid, tid, tl0
677 InsertVp8(current++, true , true , false, false, pid, 0 , 0);
678 while (current != end)
679 InsertVp8(current++, false, false, false, false, pid, 0 , 0);
680 InsertVp8(current++, false, false, true , false, pid, 0 , 0);
681 end = current + packets_per_frame;
682
683 for (int f = 1; f < 4; ++f) {
684 InsertVp8(current++, false, true , false, false, pid + f, 0 , f);
685 while (current != end)
686 InsertVp8(current++, false, false, false, false, pid + f, 0 , f);
687 InsertVp8(current++, false, false, true , false, pid + f, 0 , f);
stefan-webrtc 2016/04/19 12:24:29 Remove some misplaced whitespaces here and above.
philipel 2016/04/19 13:12:01 Done.
688 end = current + packets_per_frame;
689 }
690
691 ASSERT_EQ(4UL, frames_from_callback_.size());
692 CheckReferences(pid);
693 CheckReferences(pid + 1, pid);
694 CheckReferences(pid + 2, pid + 1);
695 CheckReferences(pid + 3, pid + 2);
302 } 696 }
303 697
304 } // namespace video_coding 698 } // namespace video_coding
305 } // namespace webrtc 699 } // namespace webrtc
OLDNEW
« webrtc/modules/video_coding/packet_buffer.cc ('K') | « webrtc/modules/video_coding/packet_buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698